Skip to content

Commit 7bc28b6

Browse files
committed
monster-specific modifiers; difficulty tweaks
1 parent 9ee70dc commit 7bc28b6

File tree

2 files changed

+41
-21
lines changed

2 files changed

+41
-21
lines changed

src/player.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,6 @@ impl KeyBindings {
131131
.expect("DEFAULT_KEY_BINDINGS not initialized")
132132
}
133133

134-
// TODO: wrap State in OnceCell so we can have a static reference to it
135-
// Update: does not seem to work well as State needs to be &mut
136-
// Alternatively may need to try FnMut(gs: &mut State) -> RunState
137134
pub fn _make_default() -> KeyBindings {
138135
let action_by_id: IndexMap<PlayerAction, ActionAndKeys> = [
139136
(

src/spawner.rs

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ pub fn room_table(map_depth: i32) -> RandomTable {
253253
.add(fireball_scroll, 30)
254254
.add(magic_missile_scroll, 40)
255255
.add(confusion_scroll, 30)
256-
.add(random_monster, 50 + 2 * map_depth.unsigned_abs() as u16) // TODO: split out separate monster spawners
256+
.add(random_monster, 120 + 2 * map_depth.unsigned_abs() as u16)
257257
.add(iron_dagger, 10)
258258
.add(iron_shield, 10)
259259
}
@@ -278,6 +278,7 @@ pub fn random_item(ecs: &mut World, position: Position) -> Entity {
278278
}
279279

280280
pub fn random_monster(ecs: &mut World, position: Position) -> Entity {
281+
let map_depth = ecs.fetch::<Map>().depth;
281282
let pos_ix = {
282283
let map = ecs.read_resource::<Map>();
283284
map.pos_idx(position)
@@ -289,24 +290,33 @@ pub fn random_monster(ecs: &mut World, position: Position) -> Entity {
289290

290291
let roll = {
291292
let mut rng = ecs.write_resource::<RandomNumberGenerator>();
292-
rng.range(0, 4) // TODO: refactor monsters as an ADT?
293-
// Some possibilities listed here: https://stackoverflow.com/questions/41637978/how-to-get-the-number-of-elements-variants-in-an-enum-as-a-constant-value
293+
rng.range(0, 100) // TODO: refactor monsters as an ADT?
294+
// Some possibilities listed here: https://stackoverflow.com/questions/41637978/how-to-get-the-number-of-elements-variants-in-an-enum-as-a-constant-value
294295
};
295-
match roll {
296-
0 => goblin(ecs, position),
297-
1 => orc(ecs, position),
298-
2 => tarrasque(ecs, position),
299-
_ => troll(ecs, position),
296+
match roll + 2 * map_depth {
297+
0..=60 => goblin(ecs, position),
298+
61..=80 => orc(ecs, position),
299+
81..=95 => troll(ecs, position),
300+
_ => tarrasque(ecs, position),
300301
}
301302
}
302303

304+
struct MonsterModifiers {
305+
pub damage: u16,
306+
pub defense: u16,
307+
}
308+
303309
fn goblin(ecs: &mut World, position: Position) -> Entity {
304310
monster(
305311
ecs,
306312
position,
307313
bracket_lib::prelude::to_cp437('g'),
308314
"Goblin",
309315
RGB::named(RED),
316+
MonsterModifiers {
317+
damage: 0,
318+
defense: 0,
319+
},
310320
)
311321
}
312322

@@ -317,26 +327,38 @@ fn orc(ecs: &mut World, position: Position) -> Entity {
317327
bracket_lib::prelude::to_cp437('o'),
318328
"Orc",
319329
RGB::named(GREEN),
330+
MonsterModifiers {
331+
damage: 0,
332+
defense: 1,
333+
},
320334
)
321335
}
322336

323-
fn tarrasque(ecs: &mut World, position: Position) -> Entity {
337+
fn troll(ecs: &mut World, position: Position) -> Entity {
324338
monster(
325339
ecs,
326340
position,
327-
bracket_lib::prelude::to_cp437('T'),
328-
"Tarrasque",
329-
RGB::named(YELLOW),
341+
bracket_lib::prelude::to_cp437('t'),
342+
"Troll",
343+
RGB::named(BLUE),
344+
MonsterModifiers {
345+
damage: 1,
346+
defense: 1,
347+
},
330348
)
331349
}
332350

333-
fn troll(ecs: &mut World, position: Position) -> Entity {
351+
fn tarrasque(ecs: &mut World, position: Position) -> Entity {
334352
monster(
335353
ecs,
336354
position,
337-
bracket_lib::prelude::to_cp437('t'),
338-
"Troll",
339-
RGB::named(BLUE),
355+
bracket_lib::prelude::to_cp437('T'),
356+
"Tarrasque",
357+
RGB::named(YELLOW),
358+
MonsterModifiers {
359+
damage: 2,
360+
defense: 1,
361+
},
340362
)
341363
}
342364

@@ -346,6 +368,7 @@ fn monster<S: ToString>(
346368
glyph: FontCharType,
347369
name: S,
348370
fg: RGB,
371+
mods: MonsterModifiers,
349372
) -> Entity {
350373
combat_entity(
351374
ecs,
@@ -363,8 +386,8 @@ fn monster<S: ToString>(
363386
CombatStats {
364387
max_hp: 16,
365388
hp: 16,
366-
defense: 1,
367-
power: 4,
389+
defense: 1 + mods.defense,
390+
power: 4 + mods.damage,
368391
},
369392
)
370393
.with(Monster {})

0 commit comments

Comments
 (0)