diff options
| author | troido <troido@protonmail.com> | 2020-03-05 12:50:25 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-03-05 12:50:25 +0100 |
| commit | 170741fe959d30ee43ce689fd5fbae725cc1dae4 (patch) | |
| tree | de337876fb9afc3ca20e5a99ef61689813f51ebe /src/systems | |
| parent | ea99b86b89659624133a63f03600f0b57592a5f4 (diff) | |
equipent now kinda works
Diffstat (limited to 'src/systems')
| -rw-r--r-- | src/systems/attacking.rs | 7 | ||||
| -rw-r--r-- | src/systems/fight.rs | 15 | ||||
| -rw-r--r-- | src/systems/useitem.rs | 17 |
3 files changed, 28 insertions, 11 deletions
diff --git a/src/systems/attacking.rs b/src/systems/attacking.rs index 4318695..597f781 100644 --- a/src/systems/attacking.rs +++ b/src/systems/attacking.rs @@ -11,7 +11,7 @@ use specs::{ }; use crate::{ - components::{Health, AttackInbox, AttackType, Dead, Position, Autofight}, + components::{Health, AttackInbox, AttackType, Dead, Position, Autofight, Equipment, equipment::Stat}, resources::NewEntities, Template, util @@ -27,9 +27,10 @@ impl <'a> System<'a> for Attacking { WriteStorage<'a, Dead>, ReadStorage<'a, Position>, Write<'a, NewEntities>, - WriteStorage<'a, Autofight> + WriteStorage<'a, Autofight>, + ReadStorage<'a, Equipment> ); - fn run(&mut self, (entities, mut attackeds, mut healths, mut deads, positions, mut new, mut autofighters): Self::SystemData) { + fn run(&mut self, (entities, mut attackeds, mut healths, mut deads, positions, mut new, mut autofighters, equipments): Self::SystemData) { for (entity, attacked, autofighter) in (&entities, &attackeds, &mut autofighters).join() { for attack in &attacked.messages { diff --git a/src/systems/fight.rs b/src/systems/fight.rs index cd6399f..7a02ba0 100644 --- a/src/systems/fight.rs +++ b/src/systems/fight.rs @@ -18,7 +18,9 @@ use crate::components::{ Health, ControlCooldown, Autofight, - Faction + Faction, + Equipment, + equipment::Stat }; use crate::controls::{Control}; @@ -38,10 +40,11 @@ impl <'a> System<'a> for Fight { ReadStorage<'a, Health>, WriteStorage<'a, ControlCooldown>, WriteStorage<'a, Autofight>, - ReadStorage<'a, Faction> + ReadStorage<'a, Faction>, + ReadStorage<'a, Equipment> ); - fn run(&mut self, (entities, controllers, positions, ground, mut attacked, fighters, healths, mut cooldowns, mut autofighters, factions): Self::SystemData) { + fn run(&mut self, (entities, controllers, positions, ground, mut attacked, fighters, healths, mut cooldowns, mut autofighters, factions, equipments): Self::SystemData) { for (entity, controller, position, fighter) in (&entities, &controllers, &positions, &fighters).join(){ let mut target = None; match &controller.control { @@ -66,7 +69,11 @@ impl <'a> System<'a> for Fight { _ => {} } if let Some(ent) = target { - AttackInbox::add_message(&mut attacked, ent, AttackMessage{typ: fighter.attack.clone(), attacker: Some(entity)}); + let mut attack = fighter.attack.clone(); + if let Some(equipment) = equipments.get(entity) { + attack = attack.apply_bonuses(&equipment.all_bonuses()); + } + AttackInbox::add_message(&mut attacked, ent, AttackMessage{typ: attack, attacker: Some(entity)}); cooldowns.insert(entity, ControlCooldown{amount: fighter.cooldown}).unwrap(); if let Some(autofighter) = autofighters.get_mut(entity){ autofighter.target = Some(ent); diff --git a/src/systems/useitem.rs b/src/systems/useitem.rs index 89a301c..7d37322 100644 --- a/src/systems/useitem.rs +++ b/src/systems/useitem.rs @@ -16,10 +16,11 @@ use crate::{ Inventory, AttackInbox, AttackMessage, - AttackType + AttackType, + Equipment }, resources::{NewEntities}, - components::item::ItemAction::{None, Build, Eat}, + components::item::ItemAction::{None, Build, Eat, Equip}, controls::Control, }; @@ -32,10 +33,11 @@ impl <'a> System<'a> for Use { ReadStorage<'a, Position>, WriteStorage<'a, Inventory>, Write<'a, NewEntities>, - WriteStorage<'a, AttackInbox> + WriteStorage<'a, AttackInbox>, + WriteStorage<'a, Equipment> ); - fn run(&mut self, (entities, controllers, positions, mut inventories, mut new, mut attacked): Self::SystemData) { + fn run(&mut self, (entities, controllers, positions, mut inventories, mut new, mut attacked, mut equipments): Self::SystemData) { for (ent, controller, position, inventory) in (&entities, &controllers, &positions, &mut inventories).join(){ match &controller.control { Control::Use(rank) => { @@ -49,6 +51,13 @@ impl <'a> System<'a> for Use { AttackInbox::add_message(&mut attacked, ent, AttackMessage{typ: AttackType::Heal(*health_diff), attacker: Option::None}); inventory.items.remove(*rank); } + Equip(equippable) => { + if let Some(equipment) = equipments.get_mut(ent) { + if equipment.equipment.contains_key(&equippable.slot) { + equipment.equipment.insert(equippable.slot, Some(equippable.clone())); + } + } + } None => {} } } |
