summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-04-12 23:10:10 +0200
committertroido <troido@protonmail.com>2020-04-12 23:10:10 +0200
commitcfd462a26b3ed4c5f23760a77ae87ce61dc9bbe2 (patch)
treec5118158196ec9924ba1123f6279cfe88dbca6e5
parent883e56e07a48dc0d4916614abc33e40dde1d1d66 (diff)
replaced Dead component with trigger messages
-rw-r--r--src/components/messages.rs19
-rw-r--r--src/components/mod.rs8
-rw-r--r--src/room.rs2
-rw-r--r--src/systems/attacking.rs9
-rw-r--r--src/systems/die.rs28
-rw-r--r--src/systems/droploot.rs24
-rw-r--r--src/systems/interact.rs9
7 files changed, 67 insertions, 32 deletions
diff --git a/src/components/messages.rs b/src/components/messages.rs
index 8fe38e3..fa4d747 100644
--- a/src/components/messages.rs
+++ b/src/components/messages.rs
@@ -65,3 +65,22 @@ pub struct AttackMessage {
impl Message for AttackMessage {}
pub type AttackInbox = Inbox<AttackMessage>;
+
+
+
+
+
+
+
+
+#[derive(Debug, Clone)]
+pub enum Trigger {
+ Loot,
+ Die,
+ Remove
+}
+impl Message for Trigger {}
+
+pub type TriggerBox = Inbox<Trigger>;
+
+
diff --git a/src/components/mod.rs b/src/components/mod.rs
index 412dc2e..530cda3 100644
--- a/src/components/mod.rs
+++ b/src/components/mod.rs
@@ -11,7 +11,9 @@ pub mod ear;
pub use messages::{
AttackMessage,
AttackInbox,
- AttackType
+ AttackType,
+ Trigger,
+ TriggerBox
};
pub use faction::Faction;
pub use interactable::Interactable;
@@ -125,10 +127,6 @@ pub struct RoomExit {
#[storage(NullStorage)]
pub struct Entered;
-#[derive(Default, Component, Debug, Clone)]
-#[storage(NullStorage)]
-pub struct Dead;
-
#[derive(Component, Debug, Clone)]
#[storage(HashMapStorage)]
pub struct Trap {
diff --git a/src/room.rs b/src/room.rs
index c8a0dac..c2edaf6 100644
--- a/src/room.rs
+++ b/src/room.rs
@@ -118,7 +118,7 @@ impl <'a, 'b>Room<'a, 'b> {
world.insert(NewEntities::new(encyclopedia));
register_insert!(
world,
- (Position, Visible, Controller, Movable, New, Removed, Moved, Player, Inventory, Health, Serialise, RoomExit, Entered, Dead, Trap, Fighter, Healing, Volatile, ControlCooldown, Autofight, MonsterAI, Home, AttackInbox, Item, Spawner, Clan, Faction, Interactable, Loot, Grow, Equipment, CreationTime, Flags, Ear),
+ (Position, Visible, Controller, Movable, New, Removed, Moved, Player, Inventory, Health, Serialise, RoomExit, Entered, TriggerBox, Trap, Fighter, Healing, Volatile, ControlCooldown, Autofight, MonsterAI, Home, AttackInbox, Item, Spawner, Clan, Faction, Interactable, Loot, Grow, Equipment, CreationTime, Flags, Ear),
(Ground, Input, Output, Size, Spawn, Players, Emigration, Time)
);
diff --git a/src/systems/attacking.rs b/src/systems/attacking.rs
index 804fac1..a202878 100644
--- a/src/systems/attacking.rs
+++ b/src/systems/attacking.rs
@@ -15,7 +15,8 @@ use crate::{
Health,
AttackInbox,
AttackType,
- Dead,
+ Trigger,
+ TriggerBox,
Position,
Autofight,
Ear,
@@ -34,14 +35,14 @@ impl <'a> System<'a> for Attacking {
Entities<'a>,
WriteStorage<'a, AttackInbox>,
WriteStorage<'a, Health>,
- WriteStorage<'a, Dead>,
+ WriteStorage<'a, TriggerBox>,
ReadStorage<'a, Position>,
Write<'a, NewEntities>,
WriteStorage<'a, Autofight>,
WriteStorage<'a, Ear>,
ReadStorage<'a, Visible>
);
- fn run(&mut self, (entities, mut attackeds, mut healths, mut deads, positions, mut new, mut autofighters, mut ears, visibles): Self::SystemData) {
+ fn run(&mut self, (entities, mut attackeds, mut healths, mut triggerboxes, positions, mut new, mut autofighters, mut ears, visibles): Self::SystemData) {
for (entity, attacked, autofighter) in (&entities, &attackeds, &mut autofighters).join() {
for attack in &attacked.messages {
@@ -83,7 +84,7 @@ impl <'a> System<'a> for Attacking {
}
health.health = util::clamp(health.health, 0, health.maxhealth);
if health.health == 0 {
- deads.insert(target, Dead).unwrap();
+ TriggerBox::add_message(&mut triggerboxes, target, Trigger::Die);
let killers = attacker_names.join(" and ");
say(&mut ears, target, Notification::Die{actor: killers.clone(), target: target_name.clone()});
for actor in attackers {
diff --git a/src/systems/die.rs b/src/systems/die.rs
index e9fb127..c6fd646 100644
--- a/src/systems/die.rs
+++ b/src/systems/die.rs
@@ -9,7 +9,7 @@ use specs::{
};
use crate::{
- components::{Dead, Removed, Player},
+ components::{Trigger, TriggerBox, Removed, Player},
resources::Emigration,
purgatory,
playerstate::RoomPos
@@ -20,19 +20,27 @@ pub struct Die;
impl <'a> System<'a> for Die {
type SystemData = (
Entities<'a>,
- ReadStorage<'a, Dead>,
+ ReadStorage<'a, TriggerBox>,
WriteStorage<'a, Removed>,
Write<'a, Emigration>,
ReadStorage<'a, Player>
);
- fn run(&mut self, (entities, deads, mut removeds, mut emigration, players): Self::SystemData) {
- // npcs etc get removed when dead
- for (entity, _, _) in (&entities, &deads, !&players).join() {
- removeds.insert(entity, Removed).unwrap();
- }
- // players move to purgatory when dead
- for (player, _) in (&players, &deads).join() {
- emigration.emigrants.push((player.id.clone(), purgatory::purgatory_id(), RoomPos::Unknown));
+ fn run(&mut self, (entities, triggerboxes, mut removeds, mut emigration, players): Self::SystemData) {
+ for (entity, triggerbox) in (&entities, &triggerboxes).join() {
+ for trigger in triggerbox.messages.iter() {
+ match trigger {
+ Trigger::Die | Trigger::Remove => {
+ if let Some(player) = players.get(entity) {
+ // players move to purgatory when dead
+ emigration.emigrants.push((player.id.clone(), purgatory::purgatory_id(), RoomPos::Unknown));
+ } else {
+ // npcs etc get removed when dead
+ removeds.insert(entity, Removed).unwrap();
+ }
+ }
+ _ => {}
+ }
+ }
}
}
}
diff --git a/src/systems/droploot.rs b/src/systems/droploot.rs
index 5eff7f7..33e71c0 100644
--- a/src/systems/droploot.rs
+++ b/src/systems/droploot.rs
@@ -12,7 +12,8 @@ use crate::{
components::{
Position,
Loot,
- Dead
+ Trigger,
+ TriggerBox
},
resources::{NewEntities}
};
@@ -23,16 +24,23 @@ impl <'a> System<'a> for DropLoot{
type SystemData = (
ReadStorage<'a, Position>,
Write<'a, NewEntities>,
- ReadStorage<'a, Dead>,
+ ReadStorage<'a, TriggerBox>,
ReadStorage<'a, Loot>
);
- fn run(&mut self, (positions, mut new, deads, loots): Self::SystemData) {
- for (position, _, loot) in (&positions, &deads, &loots).join(){
- for (template, chance) in &loot.loot {
- if *chance > rand::thread_rng().gen_range(0.0, 1.0) {
- // todo: better error handling
- new.create(position.pos, &template).unwrap();
+ fn run(&mut self, (positions, mut new, triggerboxes, loots): Self::SystemData) {
+ for (position, triggerbox, loot) in (&positions, &triggerboxes, &loots).join(){
+ for message in triggerbox.messages.iter() {
+ match message {
+ Trigger::Die | Trigger::Loot => {
+ for (template, chance) in &loot.loot {
+ if *chance > rand::thread_rng().gen_range(0.0, 1.0) {
+ // todo: better error handling
+ new.create(position.pos, &template).unwrap();
+ }
+ }
+ }
+ _ => {}
}
}
}
diff --git a/src/systems/interact.rs b/src/systems/interact.rs
index 73f9023..2c6ee91 100644
--- a/src/systems/interact.rs
+++ b/src/systems/interact.rs
@@ -16,7 +16,8 @@ use crate::{
Position,
ControlCooldown,
Interactable,
- Dead,
+ Trigger,
+ TriggerBox,
Notification,
Ear,
Inventory,
@@ -35,14 +36,14 @@ impl <'a> System<'a> for Interact {
Read<'a, Ground>,
WriteStorage<'a, ControlCooldown>,
ReadStorage<'a, Interactable>,
- WriteStorage<'a, Dead>,
+ WriteStorage<'a, TriggerBox>,
Write<'a, NewEntities>,
WriteStorage<'a, Ear>,
WriteStorage<'a, Inventory>,
ReadStorage<'a, Visible>
);
- fn run(&mut self, (entities, controllers, positions, ground, mut cooldowns, interactables, mut deads, new, mut ears, mut inventories, visibles): Self::SystemData) {
+ fn run(&mut self, (entities, controllers, positions, ground, mut cooldowns, interactables, mut triggerbox, new, mut ears, mut inventories, visibles): Self::SystemData) {
for (entity, controller, position) in (&entities, &controllers, &positions).join(){
let mut target = None;
let ear = ears.get_mut(entity);
@@ -66,7 +67,7 @@ impl <'a> System<'a> for Interact {
let name = visibles.get(ent).map(|v| v.name.as_str());
match interactable {
Interactable::Harvest => {
- deads.insert(ent, Dead).unwrap();
+ TriggerBox::add_message(&mut triggerbox, ent, Trigger::Die);
}
Interactable::Say(text) => {
say(ear, text.clone(), name);