diff options
| author | historia <[not public]> | 2026-06-25 15:40:48 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-25 15:40:48 -0400 |
| commit | abd612c15799f604e671e83dc7c410ed2b44185f (patch) | |
| tree | 0597ca92350de73aac2a7cf26b2f2d6595dac0cc /internal/game/cmd_craft.go | |
| parent | 2725e2927a1595c7b100d942d1f14146252adeb7 (diff) | |
| download | thehouseoficarus-abd612c15799f604e671e83dc7c410ed2b44185f.tar.gz | |
slop refactor
Diffstat (limited to 'internal/game/cmd_craft.go')
| -rw-r--r-- | internal/game/cmd_craft.go | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/internal/game/cmd_craft.go b/internal/game/cmd_craft.go index 3290daa..254b938 100644 --- a/internal/game/cmd_craft.go +++ b/internal/game/cmd_craft.go @@ -3,8 +3,9 @@ package game import ( "strings" + "thehouseoficarus/internal/behavior" + "thehouseoficarus/internal/item" "thehouseoficarus/internal/net" - "thehouseoficarus/internal/object" "thehouseoficarus/internal/player" ) @@ -30,7 +31,7 @@ func (g *Game) doStationSkill(sess *net.Session, input string, recipeType string items := g.CraftIndex.ByType(recipeType) - var filtered []*object.ItemDef + var filtered []*item.ItemDef for _, item := range items { if !g.itemVisible(p, item) { continue @@ -75,13 +76,13 @@ func (g *Game) doStationSkill(sess *net.Session, input string, recipeType string g.showProductionTable(sess, p, available, label, recipeType, flagKey, verbCap, false) } -func (g *Game) doWithInput(sess *net.Session, p *player.Player, items []*object.ItemDef, input string, skill player.SkillName, flagKey, label, verbCap string) { +func (g *Game) doWithInput(sess *net.Session, p *player.Player, items []*item.ItemDef, input string, skill player.SkillName, flagKey, label, verbCap string) { qty, productName := parseQty(input) productName = strings.TrimSpace(productName) - var matched []*object.ItemDef + var matched []*item.ItemDef for _, item := range items { - if object.WordPrefixMatch(productName, item.Name) { + if behavior.WordPrefixMatch(productName, item.Name) { matched = append(matched, item) } } @@ -91,7 +92,7 @@ func (g *Game) doWithInput(sess *net.Session, p *player.Player, items []*object. return } - var available []*object.ItemDef + var available []*item.ItemDef for _, item := range matched { if g.canDoItem(p, item, skill) { available = append(available, item) @@ -111,8 +112,8 @@ func (g *Game) doWithInput(sess *net.Session, p *player.Player, items []*object. g.showProductionTable(sess, p, available, label, label, flagKey, verbCap, false) } -func (g *Game) itemVisible(p *player.Player, item *object.ItemDef) bool { - return item.FindCraft(func(c object.CraftDef) bool { +func (g *Game) itemVisible(p *player.Player, def *item.ItemDef) bool { + return def.FindCraft(func(c item.CraftDef) bool { if len(c.Station) > 0 { stID, _ := g.findStation(p.RoomID, c.Station) if stID == "" { @@ -126,8 +127,8 @@ func (g *Game) itemVisible(p *player.Player, item *object.ItemDef) bool { }) != nil } -func (g *Game) canDoItem(p *player.Player, item *object.ItemDef, skill player.SkillName) bool { - m := item.FindCraft(func(c object.CraftDef) bool { +func (g *Game) canDoItem(p *player.Player, def *item.ItemDef, skill player.SkillName) bool { + m := def.FindCraft(func(c item.CraftDef) bool { if p.Level(skill) < c.Level { return false } @@ -148,31 +149,31 @@ func (g *Game) canDoItem(p *player.Player, item *object.ItemDef, skill player.Sk return m != nil } -func (g *Game) availableItems(p *player.Player, allItems []*object.ItemDef) []*object.ItemDef { - var result []*object.ItemDef - for _, item := range allItems { - m := item.FindCraft(func(c object.CraftDef) bool { +func (g *Game) availableItems(p *player.Player, allItems []*item.ItemDef) []*item.ItemDef { + var result []*item.ItemDef + for _, def := range allItems { + m := def.FindCraft(func(c item.CraftDef) bool { return craftHasAllItemsQty(&c, p.CountItem) }) if m != nil { - result = append(result, item) + result = append(result, def) } } return result } -func (g *Game) startItem(sess *net.Session, p *player.Player, item *object.ItemDef, count int, flagKey string) { +func (g *Game) startItem(sess *net.Session, p *player.Player, def *item.ItemDef, count int, flagKey string) { p.EnsureFlags() - p.Flags[flagKey] = item.ID + p.Flags[flagKey] = def.ID g.AccountStore.SaveCharacter(p) - g.startProductionFromItem(sess, p, item, count) + g.startProductionFromItem(sess, p, def, count) } func (g *Game) hasGrimyHerbs(p *player.Player) bool { items := g.CraftIndex.ByType("clean") - for _, item := range items { - if item.FindCraft(func(c object.CraftDef) bool { + for _, def := range items { + if def.FindCraft(func(c item.CraftDef) bool { return craftHasAllItems(&c, p.HasItem) }) != nil { return true @@ -181,7 +182,7 @@ func (g *Game) hasGrimyHerbs(p *player.Player) bool { return false } -func (g *Game) findCraftItems(p *player.Player, itemAID, itemBID string) []*object.ItemDef { +func (g *Game) findCraftItems(p *player.Player, itemAID, itemBID string) []*item.ItemDef { items := g.CraftIndex.ByType("crafting") toolTypeA := "" @@ -193,9 +194,9 @@ func (g *Game) findCraftItems(p *player.Player, itemAID, itemBID string) []*obje toolTypeB = defB.ToolType } - var matched []*object.ItemDef - for _, item := range items { - match := item.FindCraft(func(c object.CraftDef) bool { + var matched []*item.ItemDef + for _, def := range items { + match := def.FindCraft(func(c item.CraftDef) bool { if c.Tool == "" { return false } @@ -208,7 +209,7 @@ func (g *Game) findCraftItems(p *player.Player, itemAID, itemBID string) []*obje return false }) if match != nil { - matched = append(matched, item) + matched = append(matched, def) } } return matched |
