From 8ce02c1f47b323ad098bd7e8b887cf054412265d Mon Sep 17 00:00:00 2001 From: DualFroz Date: Mon, 7 Sep 2026 19:31:30 +0200 Subject: [PATCH] feat: add loadHandsFromMenu and storeHandsIntoMenu to Equipment --- core/src/Equipment.cpp | 82 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/core/src/Equipment.cpp b/core/src/Equipment.cpp index a75a302..c19a665 100644 --- a/core/src/Equipment.cpp +++ b/core/src/Equipment.cpp @@ -310,3 +310,85 @@ EquipmentStats Equipment::stats() const { return stats; } +int Equipment::wearFromHit(float incomingDamage, uint32_t& rng) { + return wearArmor(worn, incomingDamage, rng); +} + +WearResult Equipment::useHeld(EquipSlot slot, int amount, uint32_t& rng) { + if (!isHandSlot(slot)) return WearResult::NotDamageable; + return damageStack(hands[static_cast(handIndex(slot))], amount, rng); +} + +int Equipment::absorbExperience(int experience) { + if (experience <= 0) return 0; + int budget = experience; + int repaired = 0; + + for (Armor& piece : worn.pieces) { + if (budget <= 0) break; + if (!piece.worn() || !piece.enchants.has(EnchantKind::Mending)) continue; + int missing = piece.maxDurability - piece.durability; + if (missing <= 0) continue; + int restore = std::min(budget * 2, missing); + piece.durability += restore; + repaired += restore; + budget -= (restore + 1) / 2; + } + + for (MetaStack& held : hands) { + if (budget <= 0) break; + int restore = mendingRepair(held, budget); + if (restore <= 0) continue; + repaired += restore; + budget -= (restore + 1) / 2; + } + + return repaired; +} + +int Equipment::wornPieces() const { + int count = 0; + for (const Armor& piece : worn.pieces) { + if (piece.worn()) ++count; + } + return count; +} + +bool Equipment::empty() const { + return wornPieces() == 0 && hands[0].empty() && hands[1].empty(); +} + +void loadHandsFromMenu(Equipment& gear, const ContainerMenu& menu, int selectedHotbarSlot) { + const MenuLayout& layout = menu.layout(); + if (layout.hotbarFirst >= 0 && selectedHotbarSlot >= 0 && + selectedHotbarSlot < layout.hotbarCount) { + gear.mainHandStack() = menu.stackAt(layout.hotbarFirst + selectedHotbarSlot); + } + if (layout.offHandSlot >= 0) { + gear.offHandStack() = menu.stackAt(layout.offHandSlot); + } +} + +void storeHandsIntoMenu(Equipment& gear, ContainerMenu& menu, int selectedHotbarSlot) { + const MenuLayout& layout = menu.layout(); + if (layout.hotbarFirst >= 0 && selectedHotbarSlot >= 0 && + selectedHotbarSlot < layout.hotbarCount) { + menu.stackAt(layout.hotbarFirst + selectedHotbarSlot) = gear.mainHand(); + } + if (layout.offHandSlot >= 0) { + menu.stackAt(layout.offHandSlot) = gear.offHand(); + } +} + +float equippedMeleeDamage(const Equipment& gear, const CombatStats& attacker, + const EffectSet& attackerEffects, bool undeadTarget, + bool arthropodTarget, bool critical) { + EquipmentStats stats = gear.stats(); + CombatStats armed = attacker; + armed.baseAttackDamage = stats.attackDamage; + armed.attackSpeed = stats.attackSpeed; + return meleeAttackDamage(armed, stats.weaponEnchants, attackerEffects, undeadTarget, + arthropodTarget, critical); +} + +} // namespace vf