destructible items

This commit is contained in:
Llywelwyn 2023-07-09 09:23:52 +01:00
parent 06c3d40c65
commit d4d25955cc
4 changed files with 32 additions and 11 deletions

View file

@ -114,6 +114,9 @@ pub struct WantsToUseItem {
#[derive(Component, Debug)]
pub struct Consumable {}
#[derive(Component, Debug)]
pub struct Destructible {}
#[derive(Component, Clone)]
pub struct ParticleLifetime {
pub lifetime_ms: f32,

View file

@ -1,6 +1,7 @@
use super::{
gamelog::GameLog, CombatStats, Consumable, InBackpack, InflictsDamage, Map, Name, ParticleBuilder, Position,
ProvidesHealing, SufferDamage, WantsToDropItem, WantsToPickupItem, WantsToUseItem, AOE, DEFAULT_PARTICLE_LIFETIME,
gamelog::GameLog, CombatStats, Consumable, Destructible, InBackpack, InflictsDamage, Map, Name, ParticleBuilder,
Position, ProvidesHealing, SufferDamage, WantsToDropItem, WantsToPickupItem, WantsToUseItem, AOE,
DEFAULT_PARTICLE_LIFETIME,
};
use specs::prelude::*;
@ -44,6 +45,7 @@ impl<'a> System<'a> for ItemUseSystem {
WriteStorage<'a, WantsToUseItem>,
ReadStorage<'a, Name>,
ReadStorage<'a, Consumable>,
ReadStorage<'a, Destructible>,
ReadStorage<'a, ProvidesHealing>,
WriteStorage<'a, CombatStats>,
WriteStorage<'a, SufferDamage>,
@ -62,6 +64,7 @@ impl<'a> System<'a> for ItemUseSystem {
mut wants_to_use,
names,
consumables,
destructibles,
provides_healing,
mut combat_stats,
mut suffer_damage,
@ -165,14 +168,23 @@ impl<'a> System<'a> for ItemUseSystem {
);
}
for mob in targets.iter() {
let destructible = destructibles.get(*mob);
let entity_name = names.get(*mob).unwrap();
match destructible {
None => {
SufferDamage::new_damage(&mut suffer_damage, *mob, damage.amount);
if entity == *player_entity {
let mob_name = names.get(*mob).unwrap();
gamelog.entries.push(format!(
"{} takes {} damage from the {}!",
mob_name.name, damage.amount, item_being_used.name
entity_name.name, damage.amount, item_being_used.name
));
}
}
Some(_destructible) => {
gamelog.entries.push(format!("{} is destroyed!", entity_name.name));
entities.delete(*mob).expect("Delete failed");
}
}
used_item = true;
}

View file

@ -265,6 +265,7 @@ fn main() -> rltk::BError {
gs.ecs.register::<WantsToDropItem>();
gs.ecs.register::<WantsToUseItem>();
gs.ecs.register::<Consumable>();
gs.ecs.register::<Destructible>();
gs.ecs.register::<ParticleLifetime>();
let map = Map::new_map_rooms_and_corridors();

View file

@ -1,6 +1,6 @@
use super::{
BlocksTile, CombatStats, Consumable, InflictsDamage, Item, Monster, Name, Player, Position, ProvidesHealing,
Ranged, Rect, Renderable, Viewshed, AOE, MAPWIDTH,
BlocksTile, CombatStats, Consumable, Destructible, InflictsDamage, Item, Monster, Name, Player, Position,
ProvidesHealing, Ranged, Rect, Renderable, Viewshed, AOE, MAPWIDTH,
};
use rltk::{RandomNumberGenerator, RGB};
use specs::prelude::*;
@ -140,6 +140,7 @@ fn health_potion(ecs: &mut World, x: i32, y: i32) {
.with(Name { name: "potion of health".to_string() })
.with(Item {})
.with(Consumable {})
.with(Destructible {})
.with(ProvidesHealing { amount: 12 })
.build();
}
@ -156,6 +157,7 @@ fn weak_health_potion(ecs: &mut World, x: i32, y: i32) {
.with(Name { name: "potion of lesser health".to_string() })
.with(Item {})
.with(Consumable {})
.with(Destructible {})
.with(ProvidesHealing { amount: 6 })
.build();
}
@ -172,6 +174,7 @@ fn poison_potion(ecs: &mut World, x: i32, y: i32) {
.with(Name { name: "potion of ... health?".to_string() })
.with(Item {})
.with(Consumable {})
.with(Destructible {})
.with(ProvidesHealing { amount: -12 })
.build();
}
@ -188,6 +191,7 @@ fn magic_missile_scroll(ecs: &mut World, x: i32, y: i32) {
.with(Name { name: "scroll of magic missile".to_string() })
.with(Item {})
.with(Consumable {})
.with(Destructible {})
.with(Ranged { range: 12 })
.with(InflictsDamage { amount: 10 })
.build();
@ -205,6 +209,7 @@ fn fireball_scroll(ecs: &mut World, x: i32, y: i32) {
.with(Name { name: "scroll of fireball".to_string() })
.with(Item {})
.with(Consumable {})
.with(Destructible {})
.with(Ranged { range: 10 })
.with(InflictsDamage { amount: 20 })
.with(AOE { radius: 3 })