From c1b72b22a142cddc557f9bc97ae62698506684c1 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 28 Jan 2022 12:05:49 -0500 Subject: [PATCH] Increase player strength to decrease difficulty somewhat, complete section 5.25 --- src/effects/damage.rs | 41 +++++++++++++++++++++++++++++++++++++---- src/gamesystem.rs | 4 ++-- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/effects/damage.rs b/src/effects/damage.rs index a6b06cb..cdca4a3 100644 --- a/src/effects/damage.rs +++ b/src/effects/damage.rs @@ -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::(); - let attributes = ecs.read_storage::(); + let mut attributes = ecs.write_storage::(); let map = ecs.fetch::(); 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::(); 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::(); + 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::(); + let player_skills = skills.get_mut(*ecs.fetch::()).unwrap(); + for sk in player_skills.skills.iter_mut() { + *sk.1 += 1; + } + + ecs.write_storage::() + .insert(*ecs.fetch::(), 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, diff --git a/src/gamesystem.rs b/src/gamesystem.rs index 9632f81..3e4648a 100644 --- a/src/gamesystem.rs +++ b/src/gamesystem.rs @@ -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 {