Increase player strength to decrease difficulty somewhat, complete section 5.25

This commit is contained in:
Timothy Warren 2022-01-28 12:05:49 -05:00
parent 830b721548
commit c1b72b22a1
2 changed files with 39 additions and 6 deletions

View File

@ -1,10 +1,10 @@
use ::rltk::Point;
use ::rltk::{Point, RandomNumberGenerator};
use ::specs::prelude::*;
use ::specs::saveload::{MarkedBuilder, SimpleMarker};
use super::{add_effect, entity_position, EffectSpawner, EffectType, Targets};
use crate::components::{
Attributes, Confusion, DamageOverTime, Duration, Name, Player, Pools, SerializeMe, Slow,
Attributes, Confusion, DamageOverTime, Duration, Name, Player, Pools, SerializeMe, Skills, Slow,
};
use crate::gamesystem::{mana_at_level, player_hp_at_level};
use crate::{colors, EquipmentChanged, GameLog, Map, StatusEffect};
@ -54,7 +54,7 @@ pub fn death(ecs: &mut World, effect: &EffectSpawner, target: Entity) {
let mut gold_gain = 0.0f32;
let mut pools = ecs.write_storage::<Pools>();
let attributes = ecs.read_storage::<Attributes>();
let mut attributes = ecs.write_storage::<Attributes>();
let map = ecs.fetch::<Map>();
if let Some(pos) = entity_position(ecs, target) {
@ -71,7 +71,7 @@ pub fn death(ecs: &mut World, effect: &EffectSpawner, target: Entity) {
if xp_gain != 0 || gold_gain != 0.0 {
let mut log = ecs.fetch_mut::<GameLog>();
let mut player_stats = pools.get_mut(source).unwrap();
let player_attributes = attributes.get(source).unwrap();
let mut player_attributes = attributes.get_mut(source).unwrap();
player_stats.xp += xp_gain;
player_stats.gold += gold_gain;
if player_stats.xp >= player_stats.level * 1000 {
@ -81,6 +81,39 @@ pub fn death(ecs: &mut World, effect: &EffectSpawner, target: Entity) {
"Congratulations, you are now level {}",
player_stats.level
));
// Improve a random attribute
let mut rng = ecs.fetch_mut::<RandomNumberGenerator>();
match rng.roll_dice(1, 4) {
1 => {
player_attributes.might.base += 1;
log.append("You feel stronger!");
}
2 => {
player_attributes.fitness.base += 1;
log.append("You feel healthier!");
}
3 => {
player_attributes.quickness.base += 1;
log.append("You feel quicker!");
}
_ => {
player_attributes.intelligence.base += 1;
log.append("You feel smarter!");
}
}
// Improve all skills
let mut skills = ecs.write_storage::<Skills>();
let player_skills = skills.get_mut(*ecs.fetch::<Entity>()).unwrap();
for sk in player_skills.skills.iter_mut() {
*sk.1 += 1;
}
ecs.write_storage::<EquipmentChanged>()
.insert(*ecs.fetch::<Entity>(), EquipmentChanged {})
.expect("Failed to insert EquipmentChanged tag");
player_stats.hit_points.max = player_hp_at_level(
player_attributes.fitness.base + player_attributes.fitness.modifiers,
player_stats.level,

View File

@ -5,11 +5,11 @@ pub fn attr_bonus(value: i32) -> i32 {
}
pub fn player_hp_per_level(fitness: i32) -> i32 {
10 + attr_bonus(fitness)
15 + attr_bonus(fitness)
}
pub fn player_hp_at_level(fitness: i32, level: i32) -> i32 {
10 + player_hp_per_level(fitness) * level
15 + player_hp_per_level(fitness) * level
}
pub fn npc_hp(fitness: i32, level: i32) -> i32 {