Add a sword item, Weapon/Damage components

This commit is contained in:
Daniel Lynn 2021-07-11 11:23:46 -05:00
parent 734ac096c4
commit b6e044a8fe
4 changed files with 22 additions and 0 deletions

View File

@ -24,6 +24,14 @@ Templates(
provides: Some([ ("MagicMap", 0) ]),
frequency: 1,
),
Template(
entity_type: Item,
name: "Rusty Sword",
glyph: '/',
levels: [0, 1, 2],
frequency: 1,
base_damage: Some(1),
),
Template(
entity_type: Enemy,
name: "Goblin",

View File

@ -89,3 +89,9 @@ pub struct ActivateItem {
pub used_by: Entity,
pub item: Entity,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Damage(pub i32);
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Weapon;

View File

@ -17,6 +17,7 @@ pub fn spawn_player(ecs: &mut World, pos: Point) {
},
Name("Player 1".to_string()),
FieldOfView::new(8),
Damage(1),
));
}

View File

@ -96,5 +96,12 @@ impl Templates {
_ => println!("Warning: we don't know how to provide {}", provides),
});
}
if let Some(damage) = &template.base_damage {
commands.add_component(entity, Damage(*damage));
if template.entity_type == EntityType::Item {
commands.add_component(entity, Weapon);
}
}
}
}