feat: add slotOffset and handIndex
This commit is contained in:
1 parent
8884fe5a53
commit
f21ca33cdc
1 file changed
+153
@@ -0,0 +1,153 @@
|
||||
#include "vf/Equipment.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace vf {
|
||||
|
||||
namespace {
|
||||
|
||||
int slotOffset(EquipSlot slot) { return static_cast<int>(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<int>(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";
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user