This commit is contained in:
Timothy Warren 2022-01-13 10:42:02 -05:00
parent 847a577c3e
commit 6d4f87b184
6 changed files with 23 additions and 1 deletions

View File

@ -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)]

View File

@ -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;

View File

@ -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;

View File

@ -22,6 +22,7 @@ pub struct Mob {
pub loot_table: Option<String>,
pub light: Option<MobLight>,
pub faction: Option<String>,
pub gold: Option<String>,
}
#[derive(Deserialize, Debug)]

View File

@ -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);

View File

@ -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),