Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Shadow quest #86

Merged
merged 4 commits into from
Aug 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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