aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_smith.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-18 20:26:03 -0400
committerhistoria <[not public]>2026-06-18 20:26:03 -0400
commit97a1a908b9e6e6d3516628c139c9b64262b4fe08 (patch)
treed82953974edbfb4051dff1a48f1b264b9c264d28 /internal/game/cmd_smith.go
parent17e7725f252c7f5d3be2e9c37d62751c631f196f (diff)
downloadthehouseoficarus-97a1a908b9e6e6d3516628c139c9b64262b4fe08.tar.gz
feat: crafting roughly implemented (leather, gems, gold, clay, spinning).
Diffstat (limited to 'internal/game/cmd_smith.go')
-rw-r--r--internal/game/cmd_smith.go173
1 files changed, 1 insertions, 172 deletions
diff --git a/internal/game/cmd_smith.go b/internal/game/cmd_smith.go
index f2787a5..b539640 100644
--- a/internal/game/cmd_smith.go
+++ b/internal/game/cmd_smith.go
@@ -6,9 +6,7 @@ import (
"strings"
"thehouseoficarus/internal/action"
- "thehouseoficarus/internal/color"
"thehouseoficarus/internal/net"
- "thehouseoficarus/internal/object"
"thehouseoficarus/internal/player"
)
@@ -103,162 +101,8 @@ func (g *Game) showSmithTable(sess *net.Session, p *player.Player, barID string,
return
}
- sort.Slice(recipes, func(i, j int) bool {
- return recipes[i].Level < recipes[j].Level
- })
-
- mode := g.colorMode(sess)
- skillLevel := p.Level(player.Smithing)
- barCount := p.CountItem(barID)
- dimSpec := color.Parse("240")
-
- tbl := &Table{
- Title: titleCase(barName) + " Smithing",
- Columns: []string{"#", "Product", "Inputs", "Level Req."},
- }
-
- for i, r := range recipes {
- outDef, _ := g.ItemStore.Load(r.Output)
- productName := r.Output
- if outDef != nil {
- productName = outDef.Name
- }
-
- outputQty := r.OutputQty
- if outputQty <= 0 {
- outputQty = 1
- }
- if outDef != nil && outDef.Stackable && outputQty > 1 {
- productName = fmt.Sprintf("%s x%d", productName, outputQty)
- }
-
- bars := barsRequired(r, barID)
- inputStr := "1 bar"
- if bars > 1 {
- inputStr = fmt.Sprintf("%d bars", bars)
- }
- levelStr := fmt.Sprint(r.Level)
- numStr := fmt.Sprintf("%d", i+1)
-
- canMake := barCount >= bars && skillLevel >= r.Level
- if canMake {
- productName = g.itemColorize(sess, outDef, productName)
- } else {
- productName = color.Render(mode, dimSpec, productName)
- inputStr = color.Render(mode, dimSpec, inputStr)
- levelStr = color.Render(mode, dimSpec, levelStr)
- numStr = color.Render(mode, dimSpec, numStr)
- }
-
- tbl.Rows = append(tbl.Rows, []string{numStr, productName, inputStr, levelStr})
- }
-
- unicode := p.OptionBool("unicode")
- sess.WriteLine("")
- for _, line := range tbl.Render(unicode) {
- sess.WriteLine(line)
- }
-
lastFlag := fmt.Sprintf("last_smith_%s", barID)
- lastRecipeID, _ := p.Flags[lastFlag].(string)
- hint := ""
- if lastRecipeID != "" {
- for _, r := range recipes {
- if r.ID == lastRecipeID {
- if outDef, err := g.ItemStore.Load(r.Output); err == nil {
- hint = outDef.Name
- }
- break
- }
- }
- }
-
- if hint != "" {
- sess.Write(fmt.Sprintf("Produce what (enter for all %s): ", hint))
- } else {
- sess.Write("Produce what: ")
- }
-
- sess.PendingRecipeID = barID
- sess.State = net.StateSmithProduct
-}
-
-func (g *Game) handleSmithProduct(sess *net.Session, input string) {
- p := sess.Player.(*player.Player)
- barID := sess.PendingRecipeID
- sess.PendingRecipeID = ""
- sess.State = net.StateGame
-
- input = strings.TrimSpace(input)
-
- allRecipes, err := g.RecipeStore.LoadAll()
- if err != nil {
- g.reprompt(sess)
- return
- }
- var recipes []action.RecipeDef
- for _, r := range allRecipes {
- if r.Type == "smithing" && r.MatchesEntry(barID) {
- recipes = append(recipes, r)
- }
- }
-
- sort.Slice(recipes, func(i, j int) bool {
- return recipes[i].Level < recipes[j].Level
- })
-
- lastFlag := fmt.Sprintf("last_smith_%s", barID)
- lastRecipeID, _ := p.Flags[lastFlag].(string)
-
- sel, errMsg := g.resolveRecipeByInput(input, recipes, lastRecipeID)
- switch errMsg {
- case "ambiguous":
- sess.WriteLine("That's ambiguous.")
- g.reprompt(sess)
- return
- case "never_mind":
- sess.WriteLine("Never mind.")
- g.reprompt(sess)
- return
- }
-
- skillLevel := p.Level(player.Smithing)
- if skillLevel < sel.Recipe.Level {
- sess.WriteLine(fmt.Sprintf("You need level %d smithing to make that.", sel.Recipe.Level))
- g.reprompt(sess)
- return
- }
- if !sel.Recipe.HasAllItemsQty(p.CountItem) {
- sess.WriteLine("You don't have enough bars.")
- g.reprompt(sess)
- return
- }
-
- if p.Flags == nil {
- p.Flags = make(map[string]any)
- }
- p.Flags[lastFlag] = sel.Recipe.ID
- g.AccountStore.SaveCharacter(p)
-
- g.startProductionFromRecipe(sess, p, sel.Recipe, sel.Count)
-}
-
-func (g *Game) hasToolType(p *player.Player, toolType string) bool {
- if itemID, ok := p.Equipment[object.SlotMainHand]; ok {
- if def, err := g.ItemStore.Load(itemID); err == nil && def.ToolType == toolType {
- return true
- }
- }
- for i := 0; i < 28; i++ {
- slot := p.InvSlot(i)
- if slot == nil {
- continue
- }
- if def, err := g.ItemStore.Load(slot.ItemID); err == nil && def.ToolType == toolType {
- return true
- }
- }
- return false
+ g.showProductionTable(sess, p, recipes, titleCase(barName)+" Smithing", "smithing", lastFlag, "Produce", false)
}
func hasSmithingRecipes(allRecipes []action.RecipeDef, barID string) bool {
@@ -292,21 +136,6 @@ func findSmithableBars(allRecipes []action.RecipeDef, p *player.Player) []string
return bars
}
-func barsRequired(r action.RecipeDef, barID string) int {
- for _, e := range r.Consume {
- for _, id := range e.Items {
- if id == barID {
- qty := e.Qty
- if qty <= 0 {
- qty = 1
- }
- return qty
- }
- }
- }
- return 1
-}
-
func barMenuData(barIDs []string) []map[string]string {
out := make([]map[string]string, len(barIDs))
for i, id := range barIDs {