1package model 2 3type Slot string 4 5const ( 6 SlotWeapon Slot = "weapon" 7 SlotArmor Slot = "armor" 8 SlotHelm Slot = "helm" 9 SlotTrinket Slot = "trinket" 10) 11 12type Item struct { 13 ID string `json:"id"` 14 Name string `json:"name"` 15 Slot Slot `json:"slot"` 16 Rarity string `json:"rarity"` 17 Bonus Stats `json:"bonus"` 18 Abilities []string `json:"abilities,omitempty"` 19 Key bool `json:"key,omitempty"` 20 Trait string `json:"trait,omitempty"` 21 Value int `json:"value"` 22} 23 24var rarityWorth = map[string]int{"common": 4, "uncommon": 6, "rare": 9, "epic": 13, "legendary": 18} 25 26func Price(it Item) int { 27 b := it.Bonus 28 worth := b.MaxHP/3 + b.Attack + b.Defense + b.Magic + (b.Speed+b.Crit)/2 29 if it.Trait != "" { 30 worth += 4 31 } 32 return max(1, worth*rarityWorth[it.Rarity]) 33} 34 35type Gear map[Slot]*Item