package object import "strings" type EquipSlot string const ( SlotHead EquipSlot = "head" SlotNeck EquipSlot = "neck" SlotTorso EquipSlot = "torso" SlotLegs EquipSlot = "legs" SlotHands EquipSlot = "hands" SlotFeet EquipSlot = "feet" SlotBack EquipSlot = "back" SlotAmmo EquipSlot = "ammo" SlotMainHand EquipSlot = "main_hand" SlotOffHand EquipSlot = "off_hand" SlotRing EquipSlot = "ring" ) type WeaponType string const ( WeaponMelee WeaponType = "melee" WeaponRanged WeaponType = "ranged" WeaponTechnology WeaponType = "technology" ) type ItemDef struct { ID string `yaml:"id"` Name string `yaml:"name"` Aliases []string `yaml:"aliases"` Description string `yaml:"description"` Value int `yaml:"value"` Stackable bool `yaml:"stackable"` EquipSlot EquipSlot `yaml:"equip_slot"` WeaponType WeaponType `yaml:"weapon_type"` Stats ItemStats `yaml:"stats"` Speed int `yaml:"speed"` ToolType string `yaml:"tool_type"` ToolSpeed int `yaml:"tool_speed"` } type ItemStats struct { AttackBonus int `yaml:"attack_bonus"` StrengthBonus int `yaml:"strength_bonus"` DefenseBonus int `yaml:"defense_bonus"` ScienceBonus int `yaml:"science_bonus"` TechnologyBonus int `yaml:"technology_bonus"` } func (d *ItemDef) MatchesName(input string) bool { lower := strings.ToLower(strings.TrimSpace(input)) if lower == "" { return false } if strings.ToLower(d.Name) == lower { return true } for _, alias := range d.Aliases { if strings.ToLower(alias) == lower { return true } } if wordPrefixMatch(lower, d.Name) { return true } for _, alias := range d.Aliases { if wordPrefixMatch(lower, alias) { return true } } return false } func wordPrefixMatch(input, name string) bool { inputWords := strings.Fields(input) if len(inputWords) == 0 { return false } nameWords := strings.Fields(strings.ToLower(name)) for _, iw := range inputWords { found := false for _, nw := range nameWords { if strings.HasPrefix(nw, iw) || strings.HasPrefix(iw, nw) { found = true break } } if !found { return false } } return true }