summaryrefslogtreecommitdiff
path: root/src/systems
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-03-05 14:47:48 +0100
committertroido <troido@protonmail.com>2020-03-05 14:47:48 +0100
commita520382eb19e4234ed52fd1eb9fb965b5967d522 (patch)
tree5b4a8831cd544f57c6119eac5785973dc9e9bd50 /src/systems
parent7846b871f5c9d57a19dbf09b7acbf0d6b38a69ca (diff)
equipment is now a part of the inventory
Diffstat (limited to 'src/systems')
-rw-r--r--src/systems/attacking.rs7
-rw-r--r--src/systems/fight.rs11
-rw-r--r--src/systems/take.rs4
-rw-r--r--src/systems/useitem.rs21
-rw-r--r--src/systems/view.rs2
5 files changed, 19 insertions, 26 deletions
diff --git a/src/systems/attacking.rs b/src/systems/attacking.rs
index 597f781..4318695 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, Equipment, equipment::Stat},
+ components::{Health, AttackInbox, AttackType, Dead, Position, Autofight},
resources::NewEntities,
Template,
util
@@ -27,10 +27,9 @@ impl <'a> System<'a> for Attacking {
WriteStorage<'a, Dead>,
ReadStorage<'a, Position>,
Write<'a, NewEntities>,
- WriteStorage<'a, Autofight>,
- ReadStorage<'a, Equipment>
+ WriteStorage<'a, Autofight>
);
- fn run(&mut self, (entities, mut attackeds, mut healths, mut deads, positions, mut new, mut autofighters, equipments): Self::SystemData) {
+ fn run(&mut self, (entities, mut attackeds, mut healths, mut deads, positions, mut new, mut autofighters): 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 7a02ba0..3e1142b 100644
--- a/src/systems/fight.rs
+++ b/src/systems/fight.rs
@@ -19,8 +19,7 @@ use crate::components::{
ControlCooldown,
Autofight,
Faction,
- Equipment,
- equipment::Stat
+ Inventory
};
use crate::controls::{Control};
@@ -41,10 +40,10 @@ impl <'a> System<'a> for Fight {
WriteStorage<'a, ControlCooldown>,
WriteStorage<'a, Autofight>,
ReadStorage<'a, Faction>,
- ReadStorage<'a, Equipment>
+ ReadStorage<'a, Inventory>
);
- fn run(&mut self, (entities, controllers, positions, ground, mut attacked, fighters, healths, mut cooldowns, mut autofighters, factions, equipments): Self::SystemData) {
+ fn run(&mut self, (entities, controllers, positions, ground, mut attacked, fighters, healths, mut cooldowns, mut autofighters, factions, inventories): Self::SystemData) {
for (entity, controller, position, fighter) in (&entities, &controllers, &positions, &fighters).join(){
let mut target = None;
match &controller.control {
@@ -70,8 +69,8 @@ impl <'a> System<'a> for Fight {
}
if let Some(ent) = target {
let mut attack = fighter.attack.clone();
- if let Some(equipment) = equipments.get(entity) {
- attack = attack.apply_bonuses(&equipment.all_bonuses());
+ if let Some(inventory) = inventories.get(entity) {
+ attack = attack.apply_bonuses(&inventory.equipment_bonuses());
}
AttackInbox::add_message(&mut attacked, ent, AttackMessage{typ: attack, attacker: Some(entity)});
cooldowns.insert(entity, ControlCooldown{amount: fighter.cooldown}).unwrap();
diff --git a/src/systems/take.rs b/src/systems/take.rs
index 1d139d8..0652fdb 100644
--- a/src/systems/take.rs
+++ b/src/systems/take.rs
@@ -50,7 +50,7 @@ impl <'a> System<'a> for Take {
}
for ent in ents {
if let Some(item) = items.get(ent) {
- inventory.items.insert(0, item.clone());
+ inventory.items.insert(0, (item.clone(), false));
if let Err(msg) = removed.insert(ent, Removed) {
println!("{:?}", msg);
}
@@ -62,7 +62,7 @@ impl <'a> System<'a> for Take {
if *rank >= inventory.items.len() {
return
}
- let item = inventory.items.remove(*rank);
+ let (item, _is_equipped) = inventory.items.remove(*rank);
let _ = new.create(position.pos, item.ent);
}
_ => {}
diff --git a/src/systems/useitem.rs b/src/systems/useitem.rs
index 7d37322..bf2d138 100644
--- a/src/systems/useitem.rs
+++ b/src/systems/useitem.rs
@@ -16,8 +16,7 @@ use crate::{
Inventory,
AttackInbox,
AttackMessage,
- AttackType,
- Equipment
+ AttackType
},
resources::{NewEntities},
components::item::ItemAction::{None, Build, Eat, Equip},
@@ -33,16 +32,15 @@ impl <'a> System<'a> for Use {
ReadStorage<'a, Position>,
WriteStorage<'a, Inventory>,
Write<'a, NewEntities>,
- WriteStorage<'a, AttackInbox>,
- WriteStorage<'a, Equipment>
+ WriteStorage<'a, AttackInbox>
);
- fn run(&mut self, (entities, controllers, positions, mut inventories, mut new, mut attacked, mut equipments): Self::SystemData) {
+ fn run(&mut self, (entities, controllers, positions, mut inventories, mut new, mut attacked): Self::SystemData) {
for (ent, controller, position, inventory) in (&entities, &controllers, &positions, &mut inventories).join(){
match &controller.control {
Control::Use(rank) => {
- if let Some(item) = inventory.items.get(*rank) {
- match &item.action {
+ if let Some(slot) = inventory.items.get_mut(*rank) {
+ match &slot.0.action {
Build(template) => {
new.create(position.pos, template.clone()).unwrap();
inventory.items.remove(*rank);
@@ -51,12 +49,9 @@ 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()));
- }
- }
+ Equip(_equippable) => {
+ // todo: unequip previous
+ slot.1 = true;
}
None => {}
}
diff --git a/src/systems/view.rs b/src/systems/view.rs
index cff24fa..0ed1cf7 100644
--- a/src/systems/view.rs
+++ b/src/systems/view.rs
@@ -73,7 +73,7 @@ impl <'a> System<'a> for View {
updates.change = Some(changes.clone());
}
if let Some(inventory) = inventories.get(ent){
- updates.inventory = Some(inventory.items.iter().map(|item| item.name.clone()).collect());
+ updates.inventory = Some(inventory.items.iter().map(|(item, _equipped)| item.name.clone()).collect());
}
if let Some(health) = healths.get(ent){
updates.health = Some((health.health, health.maxhealth));