From 6d4f87b1848bc465c03b97a87f9f005c40641de9 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 13 Jan 2022 10:42:02 -0500 Subject: [PATCH] Add gold --- src/components.rs | 1 + src/damage_system.rs | 7 ++++++- src/gui.rs | 7 +++++++ src/raws/mob_structs.rs | 1 + src/raws/rawmaster.rs | 7 +++++++ src/spawner.rs | 1 + 6 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/components.rs b/src/components.rs index e0472c9..1625fbe 100644 --- a/src/components.rs +++ b/src/components.rs @@ -274,6 +274,7 @@ pub struct Pools { pub level: i32, pub total_weight: f32, pub total_initiative_penalty: f32, + pub gold: f32, } #[derive(Serialize, Deserialize, Clone)] diff --git a/src/damage_system.rs b/src/damage_system.rs index f4ecd1d..955134c 100644 --- a/src/damage_system.rs +++ b/src/damage_system.rs @@ -42,6 +42,7 @@ impl<'a> System<'a> for DamageSystem { player_pos, ) = data; let mut xp_gain = 0; + let mut gold_gain = 0.0_f32; for (entity, mut stats, damage) in (&entities, &mut stats, &damage).join() { let pos = positions.get(entity); @@ -54,6 +55,7 @@ impl<'a> System<'a> for DamageSystem { if stats.hit_points.current < 1 && dmg.1 { xp_gain += stats.level * 100; + gold_gain += stats.gold; if let Some(pos) = pos { let idx = map.xy_idx(pos.x, pos.y); spatial::remove_entity(entity, idx); @@ -62,10 +64,13 @@ impl<'a> System<'a> for DamageSystem { } } - if xp_gain != 0 { + if xp_gain != 0 || gold_gain != 0.0 { let mut player_stats = stats.get_mut(*player).unwrap(); let player_attributes = attributes.get(*player).unwrap(); + player_stats.xp += xp_gain; + player_stats.gold += gold_gain; + if player_stats.xp >= player_stats.level * 1000 { // We've gone up a level! player_stats.level += 1; diff --git a/src/gui.rs b/src/gui.rs index 260ee0c..b7b6a3a 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -145,6 +145,13 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { player_pools.total_initiative_penalty ), ); + ctx.print_color( + 50, + 11, + RGB::named(rltk::GOLD), + black, + &format!("Gold: {:.1}", player_pools.gold), + ); // Equipped let mut y = 13; diff --git a/src/raws/mob_structs.rs b/src/raws/mob_structs.rs index e1517b8..552f066 100644 --- a/src/raws/mob_structs.rs +++ b/src/raws/mob_structs.rs @@ -22,6 +22,7 @@ pub struct Mob { pub loot_table: Option, pub light: Option, pub faction: Option, + pub gold: Option, } #[derive(Deserialize, Debug)] diff --git a/src/raws/rawmaster.rs b/src/raws/rawmaster.rs index d039dc4..3347970 100644 --- a/src/raws/rawmaster.rs +++ b/src/raws/rawmaster.rs @@ -404,6 +404,13 @@ pub fn spawn_named_mob( mana: Pool::new(mob_mana), total_weight: 0., total_initiative_penalty: 0., + gold: if let Some(gold) = &mob_template.gold { + let mut rng = RandomNumberGenerator::new(); + let (n, d, b) = parse_dice_string(&gold); + (rng.roll_dice(n, d) + b) as f32 + } else { + 0.0 + }, }; eb = eb.with(pools); diff --git a/src/spawner.rs b/src/spawner.rs index 3def57e..0efc5b6 100644 --- a/src/spawner.rs +++ b/src/spawner.rs @@ -45,6 +45,7 @@ pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity { level: 1, total_weight: 0., total_initiative_penalty: 0., + gold: 0., }) .with(LightSource { color: RGB::from_f32(1.0, 1.0, 0.5),