destructible items
This commit is contained in:
parent
06c3d40c65
commit
d4d25955cc
4 changed files with 32 additions and 11 deletions
|
|
@ -114,6 +114,9 @@ pub struct WantsToUseItem {
|
||||||
#[derive(Component, Debug)]
|
#[derive(Component, Debug)]
|
||||||
pub struct Consumable {}
|
pub struct Consumable {}
|
||||||
|
|
||||||
|
#[derive(Component, Debug)]
|
||||||
|
pub struct Destructible {}
|
||||||
|
|
||||||
#[derive(Component, Clone)]
|
#[derive(Component, Clone)]
|
||||||
pub struct ParticleLifetime {
|
pub struct ParticleLifetime {
|
||||||
pub lifetime_ms: f32,
|
pub lifetime_ms: f32,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use super::{
|
use super::{
|
||||||
gamelog::GameLog, CombatStats, Consumable, InBackpack, InflictsDamage, Map, Name, ParticleBuilder, Position,
|
gamelog::GameLog, CombatStats, Consumable, Destructible, InBackpack, InflictsDamage, Map, Name, ParticleBuilder,
|
||||||
ProvidesHealing, SufferDamage, WantsToDropItem, WantsToPickupItem, WantsToUseItem, AOE, DEFAULT_PARTICLE_LIFETIME,
|
Position, ProvidesHealing, SufferDamage, WantsToDropItem, WantsToPickupItem, WantsToUseItem, AOE,
|
||||||
|
DEFAULT_PARTICLE_LIFETIME,
|
||||||
};
|
};
|
||||||
use specs::prelude::*;
|
use specs::prelude::*;
|
||||||
|
|
||||||
|
|
@ -44,6 +45,7 @@ impl<'a> System<'a> for ItemUseSystem {
|
||||||
WriteStorage<'a, WantsToUseItem>,
|
WriteStorage<'a, WantsToUseItem>,
|
||||||
ReadStorage<'a, Name>,
|
ReadStorage<'a, Name>,
|
||||||
ReadStorage<'a, Consumable>,
|
ReadStorage<'a, Consumable>,
|
||||||
|
ReadStorage<'a, Destructible>,
|
||||||
ReadStorage<'a, ProvidesHealing>,
|
ReadStorage<'a, ProvidesHealing>,
|
||||||
WriteStorage<'a, CombatStats>,
|
WriteStorage<'a, CombatStats>,
|
||||||
WriteStorage<'a, SufferDamage>,
|
WriteStorage<'a, SufferDamage>,
|
||||||
|
|
@ -62,6 +64,7 @@ impl<'a> System<'a> for ItemUseSystem {
|
||||||
mut wants_to_use,
|
mut wants_to_use,
|
||||||
names,
|
names,
|
||||||
consumables,
|
consumables,
|
||||||
|
destructibles,
|
||||||
provides_healing,
|
provides_healing,
|
||||||
mut combat_stats,
|
mut combat_stats,
|
||||||
mut suffer_damage,
|
mut suffer_damage,
|
||||||
|
|
@ -165,14 +168,23 @@ impl<'a> System<'a> for ItemUseSystem {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for mob in targets.iter() {
|
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);
|
SufferDamage::new_damage(&mut suffer_damage, *mob, damage.amount);
|
||||||
if entity == *player_entity {
|
if entity == *player_entity {
|
||||||
let mob_name = names.get(*mob).unwrap();
|
|
||||||
gamelog.entries.push(format!(
|
gamelog.entries.push(format!(
|
||||||
"{} takes {} damage from the {}!",
|
"{} 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;
|
used_item = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -265,6 +265,7 @@ fn main() -> rltk::BError {
|
||||||
gs.ecs.register::<WantsToDropItem>();
|
gs.ecs.register::<WantsToDropItem>();
|
||||||
gs.ecs.register::<WantsToUseItem>();
|
gs.ecs.register::<WantsToUseItem>();
|
||||||
gs.ecs.register::<Consumable>();
|
gs.ecs.register::<Consumable>();
|
||||||
|
gs.ecs.register::<Destructible>();
|
||||||
gs.ecs.register::<ParticleLifetime>();
|
gs.ecs.register::<ParticleLifetime>();
|
||||||
|
|
||||||
let map = Map::new_map_rooms_and_corridors();
|
let map = Map::new_map_rooms_and_corridors();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use super::{
|
use super::{
|
||||||
BlocksTile, CombatStats, Consumable, InflictsDamage, Item, Monster, Name, Player, Position, ProvidesHealing,
|
BlocksTile, CombatStats, Consumable, Destructible, InflictsDamage, Item, Monster, Name, Player, Position,
|
||||||
Ranged, Rect, Renderable, Viewshed, AOE, MAPWIDTH,
|
ProvidesHealing, Ranged, Rect, Renderable, Viewshed, AOE, MAPWIDTH,
|
||||||
};
|
};
|
||||||
use rltk::{RandomNumberGenerator, RGB};
|
use rltk::{RandomNumberGenerator, RGB};
|
||||||
use specs::prelude::*;
|
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(Name { name: "potion of health".to_string() })
|
||||||
.with(Item {})
|
.with(Item {})
|
||||||
.with(Consumable {})
|
.with(Consumable {})
|
||||||
|
.with(Destructible {})
|
||||||
.with(ProvidesHealing { amount: 12 })
|
.with(ProvidesHealing { amount: 12 })
|
||||||
.build();
|
.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(Name { name: "potion of lesser health".to_string() })
|
||||||
.with(Item {})
|
.with(Item {})
|
||||||
.with(Consumable {})
|
.with(Consumable {})
|
||||||
|
.with(Destructible {})
|
||||||
.with(ProvidesHealing { amount: 6 })
|
.with(ProvidesHealing { amount: 6 })
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
@ -172,6 +174,7 @@ fn poison_potion(ecs: &mut World, x: i32, y: i32) {
|
||||||
.with(Name { name: "potion of ... health?".to_string() })
|
.with(Name { name: "potion of ... health?".to_string() })
|
||||||
.with(Item {})
|
.with(Item {})
|
||||||
.with(Consumable {})
|
.with(Consumable {})
|
||||||
|
.with(Destructible {})
|
||||||
.with(ProvidesHealing { amount: -12 })
|
.with(ProvidesHealing { amount: -12 })
|
||||||
.build();
|
.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(Name { name: "scroll of magic missile".to_string() })
|
||||||
.with(Item {})
|
.with(Item {})
|
||||||
.with(Consumable {})
|
.with(Consumable {})
|
||||||
|
.with(Destructible {})
|
||||||
.with(Ranged { range: 12 })
|
.with(Ranged { range: 12 })
|
||||||
.with(InflictsDamage { amount: 10 })
|
.with(InflictsDamage { amount: 10 })
|
||||||
.build();
|
.build();
|
||||||
|
|
@ -205,6 +209,7 @@ fn fireball_scroll(ecs: &mut World, x: i32, y: i32) {
|
||||||
.with(Name { name: "scroll of fireball".to_string() })
|
.with(Name { name: "scroll of fireball".to_string() })
|
||||||
.with(Item {})
|
.with(Item {})
|
||||||
.with(Consumable {})
|
.with(Consumable {})
|
||||||
|
.with(Destructible {})
|
||||||
.with(Ranged { range: 10 })
|
.with(Ranged { range: 10 })
|
||||||
.with(InflictsDamage { amount: 20 })
|
.with(InflictsDamage { amount: 20 })
|
||||||
.with(AOE { radius: 3 })
|
.with(AOE { radius: 3 })
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue