From f21ca33cdccdca37e81c3c9ffd3bd9a47fea9d8d Mon Sep 17 00:00:00 2001 From: DualFroz Date: Mon, 7 Sep 2026 19:05:23 +0200 Subject: [PATCH] feat: add slotOffset and handIndex --- core/src/Equipment.cpp | 153 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 core/src/Equipment.cpp diff --git a/core/src/Equipment.cpp b/core/src/Equipment.cpp new file mode 100644 index 0000000..3dfe21b --- /dev/null +++ b/core/src/Equipment.cpp @@ -0,0 +1,153 @@ +#include "vf/Equipment.h" + +#include + +namespace vf { + +namespace { + +int slotOffset(EquipSlot slot) { return static_cast(slot); } + +int handIndex(EquipSlot slot) { return slot == EquipSlot::OffHand ? 1 : 0; } + +const MetaStack& noStack() { + static const MetaStack nothing; + return nothing; +} + +const Armor& noArmor() { + static const Armor nothing; + return nothing; +} + +float swordDamage(ToolTier tier) { + switch (tier) { + case ToolTier::Wood: return 4.0f; + case ToolTier::Stone: return 5.0f; + case ToolTier::Iron: return 6.0f; + case ToolTier::Gold: return 4.0f; + case ToolTier::Diamond: return 7.0f; + case ToolTier::None: break; + } + return unarmedAttackDamage; +} + +float axeDamage(ToolTier tier) { + switch (tier) { + case ToolTier::Wood: return 7.0f; + case ToolTier::Stone: return 9.0f; + case ToolTier::Iron: return 9.0f; + case ToolTier::Gold: return 7.0f; + case ToolTier::Diamond: return 9.0f; + case ToolTier::None: break; + } + return unarmedAttackDamage; +} + +float pickaxeDamage(ToolTier tier) { + switch (tier) { + case ToolTier::Wood: return 2.0f; + case ToolTier::Stone: return 3.0f; + case ToolTier::Iron: return 4.0f; + case ToolTier::Gold: return 2.0f; + case ToolTier::Diamond: return 5.0f; + case ToolTier::None: break; + } + return unarmedAttackDamage; +} + +float axeSpeed(ToolTier tier) { + switch (tier) { + case ToolTier::Wood: return 0.8f; + case ToolTier::Stone: return 0.8f; + case ToolTier::Iron: return 0.9f; + case ToolTier::Gold: return 1.0f; + case ToolTier::Diamond: return 1.0f; + case ToolTier::None: break; + } + return unarmedAttackSpeed; +} + +float hoeSpeed(ToolTier tier) { + switch (tier) { + case ToolTier::Wood: return 1.0f; + case ToolTier::Stone: return 2.0f; + case ToolTier::Iron: return 3.0f; + case ToolTier::Gold: return 1.0f; + case ToolTier::Diamond: return 4.0f; + case ToolTier::None: break; + } + return unarmedAttackSpeed; +} + +void addModifier(EquipmentStats& stats, AttributeModifier::Attribute attribute, + AttributeModifier::Operation operation, float amount, EquipSlot slot) { + if (amount == 0.0f) return; + AttributeModifier modifier; + modifier.attribute = attribute; + modifier.operation = operation; + modifier.amount = amount; + modifier.slot = slot; + stats.modifiers.push_back(modifier); +} + +} // namespace + +const char* equipSlotName(EquipSlot slot) { + switch (slot) { + case EquipSlot::Head: return "head"; + case EquipSlot::Chest: return "chest"; + case EquipSlot::Legs: return "legs"; + case EquipSlot::Feet: return "feet"; + case EquipSlot::MainHand: return "mainHand"; + case EquipSlot::OffHand: return "offHand"; + case EquipSlot::Count: break; + } + return "unknown"; +} + +bool isArmorSlot(EquipSlot slot) { return slotOffset(slot) < static_cast(EquipSlot::MainHand); } + +bool isHandSlot(EquipSlot slot) { + return slot == EquipSlot::MainHand || slot == EquipSlot::OffHand; +} + +Armor::Slot armorSlotFor(EquipSlot slot) { + switch (slot) { + case EquipSlot::Head: return Armor::Slot::Helmet; + case EquipSlot::Chest: return Armor::Slot::Chestplate; + case EquipSlot::Legs: return Armor::Slot::Leggings; + case EquipSlot::Feet: return Armor::Slot::Boots; + case EquipSlot::MainHand: + case EquipSlot::OffHand: + case EquipSlot::Count: + break; + } + return Armor::Slot::Count; +} + +EquipSlot equipSlotFor(Armor::Slot slot) { + switch (slot) { + case Armor::Slot::Helmet: return EquipSlot::Head; + case Armor::Slot::Chestplate: return EquipSlot::Chest; + case Armor::Slot::Leggings: return EquipSlot::Legs; + case Armor::Slot::Boots: return EquipSlot::Feet; + case Armor::Slot::Count: break; + } + return EquipSlot::Count; +} + +const char* attributeName(AttributeModifier::Attribute attribute) { + switch (attribute) { + case AttributeModifier::Attribute::AttackDamage: return "attackDamage"; + case AttributeModifier::Attribute::AttackSpeed: return "attackSpeed"; + case AttributeModifier::Attribute::AttackReach: return "attackReach"; + case AttributeModifier::Attribute::MiningSpeed: return "miningSpeed"; + case AttributeModifier::Attribute::MovementSpeed: return "movementSpeed"; + case AttributeModifier::Attribute::ArmorPoints: return "armorPoints"; + case AttributeModifier::Attribute::ArmorToughness: return "armorToughness"; + case AttributeModifier::Attribute::Count: break; + } + return "unknown"; +} +