Skip to content

Commit f96180d

Browse files
authored
Drop tombstone when dead by status effect (#136)
* add failing test * fix
1 parent 2327136 commit f96180d

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/command.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,46 @@ mod tests {
262262
let result = run(Some(cmd), &mut game);
263263

264264
assert!(result.is_err());
265+
265266
// game reset
266267
assert_eq!(game.player.max_hp(), game.player.current_hp);
267268
assert_eq!(0, game.gold);
268269
assert_eq!(0, game.player.xp);
270+
assert!(!game.tombstones.is_empty());
271+
}
272+
273+
#[test]
274+
fn status_effect_dead() {
275+
let mut game = Game::new();
276+
277+
// using force prevents battle but effects should apply anyway
278+
let cmd = Command::ChangeDir {
279+
destination: "~/..".to_string(),
280+
run: false,
281+
bribe: false,
282+
force: true,
283+
};
284+
285+
// reduce stats to ensure loss
286+
let weak_class = character::class::Class {
287+
hp: character::class::Stat(1, 1),
288+
speed: character::class::Stat(1, 1),
289+
..game.player.class
290+
};
291+
game.player = character::Character::new(weak_class, 1);
292+
game.player.status_effect = Some(character::StatusEffect::Burn);
293+
game.gold = 100;
294+
game.player.xp = 100;
295+
296+
let result = run(Some(cmd), &mut game);
297+
298+
assert!(result.is_err());
299+
300+
// game reset
301+
assert_eq!(game.player.max_hp(), game.player.current_hp);
302+
assert_eq!(0, game.gold);
303+
assert_eq!(0, game.player.xp);
304+
assert!(!game.tombstones.is_empty());
269305
}
270306

271307
#[test]

src/game.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,13 @@ impl Game {
122122
}
123123

124124
// In location is home, already healed of negative status
125-
self.player.apply_status_effects()
125+
let result = self.player.apply_status_effects();
126+
127+
if let Err(character::Dead) = result {
128+
// drops tombstone
129+
self.battle_lost();
130+
}
131+
result
126132
}
127133

128134
/// Look for chests and tombstones at the current location.

0 commit comments

Comments
 (0)