diff options
| author | troido <troido@protonmail.com> | 2020-03-05 15:08:54 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-03-05 15:08:54 +0100 |
| commit | 6e4b88fc62e5e2cf008cadd42c65d51cb3dbbf0e (patch) | |
| tree | 52d779068861c25c44d6b4731532d7a66a38672a /src/systems | |
| parent | a520382eb19e4234ed52fd1eb9fb965b5967d522 (diff) | |
don't equip 2 objects in the same slot
Diffstat (limited to 'src/systems')
| -rw-r--r-- | src/systems/useitem.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/systems/useitem.rs b/src/systems/useitem.rs index bf2d138..de9ed29 100644 --- a/src/systems/useitem.rs +++ b/src/systems/useitem.rs @@ -39,8 +39,8 @@ impl <'a> System<'a> for Use { for (ent, controller, position, inventory) in (&entities, &controllers, &positions, &mut inventories).join(){ match &controller.control { Control::Use(rank) => { - if let Some(slot) = inventory.items.get_mut(*rank) { - match &slot.0.action { + if let Some(entry) = inventory.items.get_mut(*rank) { + match &entry.0.action { Build(template) => { new.create(position.pos, template.clone()).unwrap(); inventory.items.remove(*rank); @@ -49,9 +49,16 @@ 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) => { - // todo: unequip previous - slot.1 = true; + Equip(equippable) => { + let slot = equippable.slot; + for otherentry in inventory.items.iter_mut() { + if let Equip(other) = &otherentry.0.action { + if other.slot == slot { + otherentry.1 = false; + } + } + } + inventory.items[*rank].1 = true; } None => {} } |
