More cheating! (For developing purposes, of course ;) )

This commit is contained in:
Timothy Warren 2022-01-14 09:44:01 -05:00
parent 93a1c30b4a
commit 022a7921ce
6 changed files with 116 additions and 11 deletions

View File

@ -275,6 +275,7 @@ pub struct Pools {
pub total_weight: f32, pub total_weight: f32,
pub total_initiative_penalty: f32, pub total_initiative_penalty: f32,
pub gold: f32, pub gold: f32,
pub god_mode: bool,
} }
#[derive(Serialize, Deserialize, Clone)] #[derive(Serialize, Deserialize, Clone)]

View File

@ -45,21 +45,20 @@ impl<'a> System<'a> for DamageSystem {
let mut gold_gain = 0.0_f32; let mut gold_gain = 0.0_f32;
for (entity, mut stats, damage) in (&entities, &mut stats, &damage).join() { for (entity, mut stats, damage) in (&entities, &mut stats, &damage).join() {
let pos = positions.get(entity); gold_gain += stats.gold;
for dmg in damage.amount.iter() { for dmg in damage.amount.iter() {
stats.hit_points.current -= dmg.0; if !stats.god_mode {
if let Some(pos) = pos { stats.hit_points.current -= dmg.0;
}
if let Some(pos) = positions.get(entity) {
let idx = map.xy_idx(pos.x, pos.y); let idx = map.xy_idx(pos.x, pos.y);
map.bloodstains.insert(idx); map.bloodstains.insert(idx);
spatial::remove_entity(entity, idx);
} }
if stats.hit_points.current < 1 && dmg.1 { if stats.hit_points.current < 1 && dmg.1 {
xp_gain += stats.level * 100; 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);
}
} }
} }
} }

View File

@ -926,11 +926,14 @@ pub enum CheatMenuResult {
NoResponse, NoResponse,
Cancel, Cancel,
TeleportToExit, TeleportToExit,
Heal,
Reveal,
GodMode,
} }
pub fn show_cheat_mode(_gs: &mut State, ctx: &mut Rltk) -> CheatMenuResult { pub fn show_cheat_mode(_gs: &mut State, ctx: &mut Rltk) -> CheatMenuResult {
let count = 2; let count = 4;
let y = (25 - (count / 2)) as i32; let mut y = (25 - (count / 2)) as i32;
ctx.draw_box( ctx.draw_box(
15, 15,
y - 2, y - 2,
@ -976,12 +979,87 @@ pub fn show_cheat_mode(_gs: &mut State, ctx: &mut Rltk) -> CheatMenuResult {
rltk::to_cp437(')'), rltk::to_cp437(')'),
); );
ctx.print(21, y, "Teleport to exit"); ctx.print(21, y, "Teleport to next level");
y += 1;
ctx.set(
17,
y,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK),
rltk::to_cp437('('),
);
ctx.set(
18,
y,
RGB::named(rltk::YELLOW),
RGB::named(rltk::BLACK),
rltk::to_cp437('H'),
);
ctx.set(
19,
y,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK),
rltk::to_cp437(')'),
);
ctx.print(21, y, "Heal all wounds");
y += 1;
ctx.set(
17,
y,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK),
rltk::to_cp437('('),
);
ctx.set(
18,
y,
RGB::named(rltk::YELLOW),
RGB::named(rltk::BLACK),
rltk::to_cp437('R'),
);
ctx.set(
19,
y,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK),
rltk::to_cp437(')'),
);
ctx.print(21, y, "Reveal the map");
y += 1;
ctx.set(
17,
y,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK),
rltk::to_cp437('('),
);
ctx.set(
18,
y,
RGB::named(rltk::YELLOW),
RGB::named(rltk::BLACK),
rltk::to_cp437('G'),
);
ctx.set(
19,
y,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK),
rltk::to_cp437(')'),
);
ctx.print(21, y, "God Mode (No Death)");
match ctx.key { match ctx.key {
None => CheatMenuResult::NoResponse, None => CheatMenuResult::NoResponse,
Some(key) => match key { Some(key) => match key {
VirtualKeyCode::T => CheatMenuResult::TeleportToExit, VirtualKeyCode::T => CheatMenuResult::TeleportToExit,
VirtualKeyCode::H => CheatMenuResult::Heal,
VirtualKeyCode::R => CheatMenuResult::Reveal,
VirtualKeyCode::G => CheatMenuResult::GodMode,
VirtualKeyCode::Escape => CheatMenuResult::Cancel, VirtualKeyCode::Escape => CheatMenuResult::Cancel,
_ => CheatMenuResult::NoResponse, _ => CheatMenuResult::NoResponse,
}, },

View File

@ -400,8 +400,33 @@ impl GameState for State {
CheatMenuResult::TeleportToExit => { CheatMenuResult::TeleportToExit => {
self.goto_level(1); self.goto_level(1);
self.mapgen_next_state = Some(RunState::PreRun); self.mapgen_next_state = Some(RunState::PreRun);
newrunstate = RunState::MapGeneration newrunstate = RunState::MapGeneration
} }
CheatMenuResult::Heal => {
let player = self.ecs.fetch::<Entity>();
let mut pools = self.ecs.write_storage::<Pools>();
let mut player_pools = pools.get_mut(*player).unwrap();
player_pools.hit_points.current = player_pools.hit_points.max;
newrunstate = RunState::AwaitingInput;
}
CheatMenuResult::Reveal => {
let mut map = self.ecs.fetch_mut::<Map>();
for v in map.revealed_tiles.iter_mut() {
*v = true;
}
newrunstate = RunState::AwaitingInput;
}
CheatMenuResult::GodMode => {
let player = self.ecs.fetch::<Entity>();
let mut pools = self.ecs.write_storage::<Pools>();
let mut player_pools = pools.get_mut(*player).unwrap();
player_pools.god_mode = true;
newrunstate = RunState::AwaitingInput;
}
}, },
RunState::ShowVendor { vendor, mode } => { RunState::ShowVendor { vendor, mode } => {
let result = gui::show_vendor_menu(self, ctx, vendor, mode); let result = gui::show_vendor_menu(self, ctx, vendor, mode);

View File

@ -425,6 +425,7 @@ pub fn spawn_named_mob(
} else { } else {
0.0 0.0
}, },
god_mode: false,
}; };
eb = eb.with(pools); eb = eb.with(pools);

View File

@ -46,6 +46,7 @@ pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
total_weight: 0., total_weight: 0.,
total_initiative_penalty: 0., total_initiative_penalty: 0.,
gold: 0., gold: 0.,
god_mode: false,
}) })
.with(LightSource { .with(LightSource {
color: RGB::from_f32(1.0, 1.0, 0.5), color: RGB::from_f32(1.0, 1.0, 0.5),