Skip to content

Commit

Permalink
Shadow quest (#86)
Browse files Browse the repository at this point in the history
* maybe find shadow

* shadow dimmed font

* add quest

* changelog
  • Loading branch information
facundoolano authored Aug 7, 2021
1 parent aad913e commit 5e94240
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Unreleased

### Added
* Quest to beat your own shadow #86

### Fixed
* Reach level 50 and 100 unlock and reward 4128f75

## [0.6.0](https://github.com/facundoolano/rpg-cli/releases/tag/0.6.0) - 2021-08-04
### Added
* Customizable classes file #76
Expand Down
22 changes: 18 additions & 4 deletions src/character/enemy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,33 @@ use super::{class::Category, class::Class, Character};
use crate::location;
use crate::randomizer::{random, Randomizer};
use rand::prelude::SliceRandom;
use rand::Rng;

pub fn at(location: &location::Location, player: &Character) -> Character {
let distance = location.distance_from_home();
let level = level(player.level, distance.len());
let category = weighted_choice(distance);
Character::new(Class::random(category).clone(), level)
let (class, level) = if should_find_shadow(location) {
let mut class = player.class.clone();
class.name = String::from("shadow");
(class, player.level + 3)
} else {
let distance = location.distance_from_home();
let level = level(player.level, distance.len());
let category = weighted_choice(distance);
(Class::random(category).clone(), level)
};

Character::new(class, level)
}

fn level(player_level: i32, distance_from_home: i32) -> i32 {
let level = std::cmp::max(player_level / 2 + distance_from_home - 1, 1);
random().enemy_level(level)
}

fn should_find_shadow(location: &location::Location) -> bool {
let mut rng = rand::thread_rng();
location.is_home() && rng.gen_ratio(1, 10)
}

/// Choose an enemy randomly, with higher chance to difficult enemies the further from home.
fn weighted_choice(distance: location::Distance) -> Category {
// the weights for each group of enemies are different depending on the distance
Expand Down
4 changes: 3 additions & 1 deletion src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ fn battle_log(character: &Character, suffix: &str) {

fn format_character(character: &Character) -> String {
let name = format!("{:>8}", character.name());
let name = if character.is_player() {
let name = if character.name() == "shadow" {
name.dimmed()
} else if character.is_player() {
name.bold()
} else {
name.yellow().bold()
Expand Down
11 changes: 11 additions & 0 deletions src/quest/beat_enemy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ pub fn of_class(category: class::Category, description: &str) -> Box<dyn Quest>
})
}

pub fn shadow() -> Box<dyn Quest> {
let mut to_beat = HashSet::new();
to_beat.insert(String::from("shadow"));

Box::new(BeatEnemyClass {
to_beat,
total: 1,
description: String::from("Beat your own shadow."),
})
}

pub fn at_distance(distance: i32) -> Box<dyn Quest> {
Box::new(BeatEnemyDistance { distance })
}
Expand Down
8 changes: 5 additions & 3 deletions src/quest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,18 @@ impl QuestList {
beat_enemy::of_class(class::Category::Legendary, "beat all legendary creatures"),
));

self.todo
.push((10, 10000, Box::new(level::ReachLevel::new(50))));

for name in class::Class::names(class::Category::Player) {
self.todo
.push((10, 5000, Box::new(level::RaiseClassLevels::new(&name))));
}

self.todo
.push((2, 500, Box::new(level::ReachLevel::new(50))));
self.todo.push((15, 20000, beat_enemy::shadow()));

self.todo
.push((2, 500, Box::new(level::ReachLevel::new(100))));
.push((50, 100000, Box::new(level::ReachLevel::new(100))));
}

/// Pass the event to each of the quests, moving the completed ones to DONE.
Expand Down

0 comments on commit 5e94240

Please # to comment.