feat: add loadHandsFromMenu and storeHandsIntoMenu to Equipment
This commit is contained in:
1 parent
c38bf7b07a
commit
8ce02c1f47
1 file changed
+82
@@ -310,3 +310,85 @@ EquipmentStats Equipment::stats() const {
|
|||||||
return stats;
|
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<std::size_t>(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
|
||||||
Reference in new issue
Block a user