Add some better equipment

This commit is contained in:
Timothy Warren 2021-11-15 11:48:01 -05:00
parent a2ef1810d9
commit 43e9ebd52b
2 changed files with 46 additions and 2 deletions

View File

@ -29,8 +29,10 @@ impl RandomTable {
} }
pub fn add<S: ToString>(mut self, name: S, weight: i32) -> Self { pub fn add<S: ToString>(mut self, name: S, weight: i32) -> Self {
if weight > 0 {
self.total_weight += weight; self.total_weight += weight;
self.entries.push(RandomEntry::new(name, weight)); self.entries.push(RandomEntry::new(name, weight));
}
self self
} }

View File

@ -47,6 +47,8 @@ fn room_table(map_depth: i32) -> RandomTable {
.add("Magic Missile Scroll", 4) .add("Magic Missile Scroll", 4)
.add("Dagger", 3) .add("Dagger", 3)
.add("Shield", 3) .add("Shield", 3)
.add("Longsword", map_depth - 1)
.add("Tower Shield", map_depth - 1)
} }
/// fills a room with stuff! /// 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), "Magic Missile Scroll" => magic_missile_scroll(ecs, x, y),
"Dagger" => dagger(ecs, x, y), "Dagger" => dagger(ecs, x, y),
"Shield" => shield(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::<SimpleMarker<SerializeMe>>() .marked::<SimpleMarker<SerializeMe>>()
.build(); .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::<SimpleMarker<SerializeMe>>()
.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::<SimpleMarker<SerializeMe>>()
.build();
}