From 43e9ebd52b343a177bf9f7e6134b5a1154185c55 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 15 Nov 2021 11:48:01 -0500 Subject: [PATCH] Add some better equipment --- src/random_table.rs | 6 ++++-- src/spawner.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/random_table.rs b/src/random_table.rs index c6344e4..e7a7cd8 100644 --- a/src/random_table.rs +++ b/src/random_table.rs @@ -29,8 +29,10 @@ impl RandomTable { } pub fn add(mut self, name: S, weight: i32) -> Self { - self.total_weight += weight; - self.entries.push(RandomEntry::new(name, weight)); + if weight > 0 { + self.total_weight += weight; + self.entries.push(RandomEntry::new(name, weight)); + } self } diff --git a/src/spawner.rs b/src/spawner.rs index 62d71f9..5c4afce 100644 --- a/src/spawner.rs +++ b/src/spawner.rs @@ -47,6 +47,8 @@ fn room_table(map_depth: i32) -> RandomTable { .add("Magic Missile Scroll", 4) .add("Dagger", 3) .add("Shield", 3) + .add("Longsword", map_depth - 1) + .add("Tower Shield", map_depth - 1) } /// fills a room with stuff! @@ -93,6 +95,8 @@ pub fn spawn_room(ecs: &mut World, room: &Rect, map_depth: i32) { "Magic Missile Scroll" => magic_missile_scroll(ecs, x, y), "Dagger" => dagger(ecs, x, y), "Shield" => shield(ecs, x, y), + "Longsword" => longsword(ecs, x, y), + "Tower Shield" => tower_shield(ecs, x, y), _ => {} } } @@ -237,3 +241,41 @@ fn shield(ecs: &mut World, x: i32, y: i32) { .marked::>() .build(); } + +fn longsword(ecs: &mut World, x: i32, y: i32) { + ecs.create_entity() + .with(Position { x, y }) + .with(Renderable { + glyph: rltk::to_cp437('/'), + fg: RGB::named(rltk::CYAN), + bg: RGB::named(rltk::BLACK), + render_order: 2, + }) + .with(Name::new("Longsword")) + .with(Item {}) + .with(Equippable { + slot: EquipmentSlot::Melee, + }) + .with(MeleePowerBonus { power: 4 }) + .marked::>() + .build(); +} + +fn tower_shield(ecs: &mut World, x: i32, y: i32) { + ecs.create_entity() + .with(Position { x, y }) + .with(Renderable { + glyph: rltk::to_cp437('('), + fg: RGB::named(rltk::CYAN), + bg: RGB::named(rltk::BLACK), + render_order: 2, + }) + .with(Name::new("Tower Shield")) + .with(Item {}) + .with(Equippable { + slot: EquipmentSlot::Shield, + }) + .with(DefenseBonus { defense: 3 }) + .marked::>() + .build(); +} \ No newline at end of file