aboutsummaryrefslogtreecommitdiff
path: root/internal/item
diff options
context:
space:
mode:
Diffstat (limited to 'internal/item')
-rw-r--r--internal/item/item.go255
1 files changed, 187 insertions, 68 deletions
diff --git a/internal/item/item.go b/internal/item/item.go
index 890fa8d..0e63156 100644
--- a/internal/item/item.go
+++ b/internal/item/item.go
@@ -24,54 +24,195 @@ const (
SlotRing EquipSlot = "ring"
)
-type WeaponType string
+type EquipmentType string
const (
- WeaponMelee WeaponType = "melee"
- WeaponRanged WeaponType = "ranged"
- WeaponScience WeaponType = "science"
+ EquipMeleeWeapon EquipmentType = "melee_weapon"
+ EquipRangedWeapon EquipmentType = "ranged_weapon"
+ EquipScienceWeapon EquipmentType = "tech_weapon"
+ EquipArmor EquipmentType = "armor"
+ EquipTool EquipmentType = "tool"
+ EquipAmmo EquipmentType = "ammo"
)
+func (et EquipmentType) IsWeapon() bool {
+ return et == EquipMeleeWeapon || et == EquipRangedWeapon || et == EquipScienceWeapon
+}
+
+type AttackBonuses struct {
+ Stab int `yaml:"stab,omitempty"`
+ Slash int `yaml:"slash,omitempty"`
+ Crush int `yaml:"crush,omitempty"`
+ Ranged int `yaml:"ranged,omitempty"`
+ Science int `yaml:"science,omitempty"`
+}
+
+type DefenseBonuses struct {
+ Stab int `yaml:"stab,omitempty"`
+ Slash int `yaml:"slash,omitempty"`
+ Crush int `yaml:"crush,omitempty"`
+ Ranged int `yaml:"ranged,omitempty"`
+ Science int `yaml:"science,omitempty"`
+}
+
+type OtherBonuses struct {
+ Strength int `yaml:"strength,omitempty"`
+ Ranged int `yaml:"ranged,omitempty"`
+ Science int `yaml:"science,omitempty"`
+ Technology int `yaml:"technology,omitempty"`
+}
+
+type EquipmentDef struct {
+ Type EquipmentType `yaml:"type"`
+ Slot EquipSlot `yaml:"slot,omitempty"`
+ AttackType string `yaml:"attack_type,omitempty"`
+ Speed float64 `yaml:"speed,omitempty"`
+ Junk string `yaml:"junk,omitempty"`
+ Attack *AttackBonuses `yaml:"attack,omitempty"`
+ Defense *DefenseBonuses `yaml:"defense,omitempty"`
+ Other *OtherBonuses `yaml:"other,omitempty"`
+}
+
+type ToolDef struct {
+ Type string `yaml:"type"`
+ Speed float64 `yaml:"speed,omitempty"`
+}
+
type ItemDef struct {
- ID string `yaml:"id"`
- Name string `yaml:"name"`
- Color string `yaml:"color"`
- Description string `yaml:"description"`
- Value int `yaml:"value"`
- Stackable bool `yaml:"stackable"`
- EquipSlot EquipSlot `yaml:"equip_slot"`
- WeaponType WeaponType `yaml:"weapon_type"`
- AttackType string `yaml:"attack_type"`
- Stats ItemStats `yaml:"stats"`
- Speed float64 `yaml:"speed"`
- Requirements map[string]int `yaml:"requirements,omitempty"`
- ToolType string `yaml:"tool_type"`
- ToolSpeed float64 `yaml:"tool_speed"`
- BurnTicks float64 `yaml:"burn_ticks"`
- FireLevel int `yaml:"fire_level"`
- FireXP int `yaml:"fire_xp"`
- Quality int `yaml:"quality"`
- MaxQuality int `yaml:"max_quality"`
- SearchTable string `yaml:"search_table"`
- SearchMiscTable string `yaml:"search_misc_table"`
- SearchTicks float64 `yaml:"search_ticks"`
- SearchMessage string `yaml:"search_message"`
- HealValue int `yaml:"heal_value"`
- EatMessage string `yaml:"eat_message"`
- Craft CraftList `yaml:"craft,omitempty"`
- ProvidesJunk string `yaml:"provides_junk,omitempty"`
- FarmPatchType string `yaml:"farm_patch_type"`
- FarmLevel int `yaml:"farm_level"`
- FarmPlantXP int `yaml:"farm_plant_xp"`
- FarmHarvestXP int `yaml:"farm_harvest_xp"`
- FarmStages int `yaml:"farm_stages"`
- FarmProduct string `yaml:"farm_product"`
- FarmMinYield int `yaml:"farm_min_yield"`
- FarmMaxYield int `yaml:"farm_max_yield"`
- PotionEffect string `yaml:"potion_effect"`
- PotionBonus int `yaml:"potion_bonus"`
- PotionDuration float64 `yaml:"potion_duration"`
- Recoverable bool `yaml:"recoverable"`
+ ID string `yaml:"id"`
+ Name string `yaml:"name"`
+ Color string `yaml:"color"`
+ Description string `yaml:"description"`
+ Value int `yaml:"value"`
+ Stackable bool `yaml:"stackable"`
+ Recoverable bool `yaml:"recoverable"`
+
+ Equipment *EquipmentDef `yaml:"equipment,omitempty"`
+ Tool *ToolDef `yaml:"tool,omitempty"`
+ Requirements map[string]int `yaml:"requirements,omitempty"`
+
+ Quality int `yaml:"quality"`
+ MaxQuality int `yaml:"max_quality"`
+ Craft CraftList `yaml:"craft,omitempty"`
+
+ SearchTable string `yaml:"search_table"`
+ SearchTicks float64 `yaml:"search_ticks"`
+ SearchMessage string `yaml:"search_message"`
+
+ HealValue int `yaml:"heal_value"`
+ EatMessage string `yaml:"eat_message"`
+
+ FarmPatchType string `yaml:"farm_patch_type"`
+ FarmLevel int `yaml:"farm_level"`
+ FarmPlantXP int `yaml:"farm_plant_xp"`
+ FarmHarvestXP int `yaml:"farm_harvest_xp"`
+ FarmStages int `yaml:"farm_stages"`
+ FarmProduct string `yaml:"farm_product"`
+ FarmMinYield int `yaml:"farm_min_yield"`
+ FarmMaxYield int `yaml:"farm_max_yield"`
+
+ PotionEffect string `yaml:"potion_effect"`
+ PotionBonus int `yaml:"potion_bonus"`
+ PotionDuration float64 `yaml:"potion_duration"`
+
+ BurnTicks float64 `yaml:"burn_ticks"`
+ FireLevel int `yaml:"fire_level"`
+ FireXP int `yaml:"fire_xp"`
+}
+
+func (d *ItemDef) EquipmentType() EquipmentType {
+ if d.Equipment != nil {
+ return d.Equipment.Type
+ }
+ return ""
+}
+
+func (d *ItemDef) EquipSlot() EquipSlot {
+ if d.Equipment != nil {
+ return d.Equipment.Slot
+ }
+ return ""
+}
+
+func (d *ItemDef) Speed() float64 {
+ if d.Equipment != nil {
+ return d.Equipment.Speed
+ }
+ return 0
+}
+
+func (d *ItemDef) AttackType() string {
+ if d.Equipment != nil {
+ return d.Equipment.AttackType
+ }
+ return ""
+}
+
+func (d *ItemDef) ToolType() string {
+ if d.Tool != nil {
+ return d.Tool.Type
+ }
+ return ""
+}
+
+func (d *ItemDef) ToolSpeed() float64 {
+ if d.Tool != nil {
+ return d.Tool.Speed
+ }
+ return 0
+}
+
+func (d *ItemDef) ProvidesJunk() string {
+ if d.Equipment != nil {
+ return d.Equipment.Junk
+ }
+ return ""
+}
+
+type ItemStats struct {
+ StabAttack int
+ SlashAttack int
+ CrushAttack int
+ ScienceAttack int
+ RangedAttack int
+
+ StabDefense int
+ SlashDefense int
+ CrushDefense int
+ ScienceDefense int
+ RangedDefense int
+
+ StrengthBonus int
+ RangedStrength int
+ ScienceDamage int
+ TechnologyBonus int
+}
+
+func (d *ItemDef) Stats() ItemStats {
+ var s ItemStats
+ if d.Equipment != nil {
+ if d.Equipment.Attack != nil {
+ s.StabAttack = d.Equipment.Attack.Stab
+ s.SlashAttack = d.Equipment.Attack.Slash
+ s.CrushAttack = d.Equipment.Attack.Crush
+ s.RangedAttack = d.Equipment.Attack.Ranged
+ s.ScienceAttack = d.Equipment.Attack.Science
+ }
+ if d.Equipment.Defense != nil {
+ s.StabDefense = d.Equipment.Defense.Stab
+ s.SlashDefense = d.Equipment.Defense.Slash
+ s.CrushDefense = d.Equipment.Defense.Crush
+ s.RangedDefense = d.Equipment.Defense.Ranged
+ s.ScienceDefense = d.Equipment.Defense.Science
+ }
+ if d.Equipment.Other != nil {
+ s.StrengthBonus = d.Equipment.Other.Strength
+ s.RangedStrength = d.Equipment.Other.Ranged
+ s.ScienceDamage = d.Equipment.Other.Science
+ s.TechnologyBonus = d.Equipment.Other.Technology
+ }
+ }
+ return s
}
type CraftList []CraftDef
@@ -117,7 +258,7 @@ func (d *ItemDef) MatchingCrafts(fn func(CraftDef) bool) []*CraftDef {
return result
}
-type ConsumeEntry struct {
+type IngredientEntry struct {
Items []string `yaml:"items"`
Quantity int `yaml:"quantity"`
Byproducts []string `yaml:"byproducts"`
@@ -136,13 +277,13 @@ type SuccessFormula struct {
type CraftDef struct {
Type string `yaml:"type"`
- Skill string `yaml:"skill"`
+ Subtype string `yaml:"subtype,omitempty"`
Level int `yaml:"level"`
XP int `yaml:"xp"`
Wait float64 `yaml:"wait"`
Station []string `yaml:"station"`
Tool string `yaml:"tool"`
- Consume []ConsumeEntry `yaml:"consume"`
+ Ingredients []IngredientEntry `yaml:"ingredients"`
OutputQty int `yaml:"output_qty"`
Fail string `yaml:"fail"`
Message string `yaml:"message"`
@@ -154,31 +295,9 @@ type CraftDef struct {
}
func (c *CraftDef) EffectiveSkill() string {
- if c.Skill != "" {
- return c.Skill
- }
return c.Type
}
-type ItemStats struct {
- StabAttack int `yaml:"stab_attack"`
- SlashAttack int `yaml:"slash_attack"`
- CrushAttack int `yaml:"crush_attack"`
- ScienceAttack int `yaml:"science_attack"`
- RangedAttack int `yaml:"ranged_attack"`
-
- StabDefense int `yaml:"stab_defense"`
- SlashDefense int `yaml:"slash_defense"`
- CrushDefense int `yaml:"crush_defense"`
- ScienceDefense int `yaml:"science_defense"`
- RangedDefense int `yaml:"ranged_defense"`
-
- StrengthBonus int `yaml:"strength_bonus"`
- RangedStrength int `yaml:"ranged_strength"`
- ScienceDamage int `yaml:"science_damage"`
- TechnologyBonus int `yaml:"technology_bonus"`
-}
-
func (d *ItemDef) MatchesName(input string) bool {
lower := strings.ToLower(strings.TrimSpace(input))
if lower == "" {