aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_fletch.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_fletch.go
parent17e7725f252c7f5d3be2e9c37d62751c631f196f (diff)
downloadthehouseoficarus-97a1a908b9e6e6d3516628c139c9b64262b4fe08.tar.gz
feat: crafting roughly implemented (leather, gems, gold, clay, spinning).
Diffstat (limited to 'internal/game/cmd_fletch.go')
-rw-r--r--internal/game/cmd_fletch.go175
1 files changed, 22 insertions, 153 deletions
diff --git a/internal/game/cmd_fletch.go b/internal/game/cmd_fletch.go
index fe8c0b3..60acb92 100644
--- a/internal/game/cmd_fletch.go
+++ b/internal/game/cmd_fletch.go
@@ -1,12 +1,9 @@
package game
import (
- "fmt"
- "sort"
"strings"
"thehouseoficarus/internal/action"
- "thehouseoficarus/internal/color"
"thehouseoficarus/internal/combat"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/player"
@@ -24,6 +21,9 @@ var fletchGemItems = map[string]bool{
}
func fletchNeedsKnife(r *action.RecipeDef) bool {
+ if r.Tool == "knife" {
+ return true
+ }
for _, e := range r.Consume {
for _, id := range e.Items {
if fletchLogItems[id] {
@@ -37,6 +37,9 @@ func fletchNeedsKnife(r *action.RecipeDef) bool {
}
func fletchNeedsChisel(r *action.RecipeDef) bool {
+ if r.Tool == "chisel" {
+ return true
+ }
for _, e := range r.Consume {
for _, id := range e.Items {
if fletchGemItems[id] {
@@ -104,7 +107,7 @@ func (g *Game) doFletch(sess *net.Session, input string) {
return
}
- g.showFletchTable(sess, p, available)
+ g.showProductionTable(sess, p, available, "Fletching", "fletching", "last_fletch", "Fletch", true)
}
func (g *Game) doFletchWithInput(sess *net.Session, p *player.Player, fletchRecipes []action.RecipeDef, input string) {
@@ -146,10 +149,13 @@ func (g *Game) doFletchWithInput(sess *net.Session, p *player.Player, fletchReci
return
}
- g.showFletchTable(sess, p, available)
+ g.showProductionTable(sess, p, available, "Fletching", "fletching", "last_fletch", "Fletch", true)
}
func (g *Game) hasFletchTools(p *player.Player, r *action.RecipeDef) bool {
+ if r.Tool != "" {
+ return g.hasToolType(p, r.Tool)
+ }
if fletchNeedsKnife(r) && !g.hasToolType(p, "knife") {
return false
}
@@ -175,154 +181,6 @@ func (g *Game) availableFletchRecipes(p *player.Player, allFletch []action.Recip
return result
}
-func (g *Game) showFletchTable(sess *net.Session, p *player.Player, available []action.RecipeDef) {
- sort.Slice(available, func(i, j int) bool {
- return available[i].Level < available[j].Level
- })
-
- mode := g.colorMode(sess)
- skillLevel := p.Level(player.Fletching)
- dimSpec := color.Parse("240")
-
- tbl := &Table{
- Title: "Fletching Actions",
- Columns: []string{"#", "Product", "Materials", "Level"},
- }
-
- for i, r := range available {
- 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)
- }
-
- var matParts []string
- for _, e := range r.Consume {
- itemName := e.Items[0]
- if def, err := g.ItemStore.Load(e.Items[0]); err == nil {
- itemName = def.Name
- }
- if e.Qty > 1 {
- matParts = append(matParts, fmt.Sprintf("%s x%d", itemName, e.Qty))
- } else {
- matParts = append(matParts, itemName)
- }
- }
- matStr := strings.Join(matParts, ", ")
- levelStr := fmt.Sprint(r.Level)
- numStr := fmt.Sprintf("%d", i+1)
-
- canMake := skillLevel >= r.Level
- if canMake {
- productName = g.itemColorize(sess, outDef, productName)
- } else {
- productName = color.Render(mode, dimSpec, productName)
- matStr = color.Render(mode, dimSpec, matStr)
- levelStr = color.Render(mode, dimSpec, levelStr)
- numStr = color.Render(mode, dimSpec, numStr)
- }
-
- tbl.Rows = append(tbl.Rows, []string{numStr, productName, matStr, levelStr})
- }
-
- unicode := p.OptionBool("unicode")
- sess.WriteLine("")
- for _, line := range tbl.Render(unicode) {
- sess.WriteLine(line)
- }
-
- lastRecipeID, _ := p.Flags["last_fletch"].(string)
- hint := ""
- if lastRecipeID != "" {
- for _, r := range available {
- if r.ID == lastRecipeID {
- if outDef, err := g.ItemStore.Load(r.Output); err == nil {
- hint = outDef.Name
- }
- break
- }
- }
- }
-
- if hint != "" {
- sess.Write(fmt.Sprintf("Fletch what (enter for all %s): ", hint))
- } else {
- sess.Write("Fletch what: ")
- }
-
- sess.PendingMenu = recipeMenuData(available)
- sess.State = net.StateFletchProduct
-}
-
-func (g *Game) handleFletchProduct(sess *net.Session, input string) {
- p := sess.Player.(*player.Player)
- menuData := sess.PendingMenu
- sess.PendingMenu = nil
- 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 _, entry := range menuData {
- rid := entry["recipe_id"]
- for _, r := range allRecipes {
- if r.ID == rid {
- recipes = append(recipes, r)
- break
- }
- }
- }
-
- if len(recipes) == 0 {
- g.reprompt(sess)
- return
- }
-
- sort.Slice(recipes, func(i, j int) bool {
- return recipes[i].Level < recipes[j].Level
- })
-
- lastRecipeID, _ := p.Flags["last_fletch"].(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
- }
-
- if !g.canDoFletchRecipe(p, sel.Recipe) {
- if p.Level(player.Fletching) < sel.Recipe.Level {
- sess.WriteLine(fmt.Sprintf("You need level %d fletching to make that.", sel.Recipe.Level))
- } else {
- sess.WriteLine("You don't have the materials for that.")
- }
- g.reprompt(sess)
- return
- }
-
- g.startFletchAction(sess, p, sel.Recipe, sel.Count)
-}
-
func (g *Game) findFletchRecipesForItems(p *player.Player, itemAID, itemBID string) []action.RecipeDef {
allRecipes, err := g.RecipeStore.LoadAll()
if err != nil {
@@ -346,6 +204,17 @@ func (g *Game) findFletchRecipesForItems(p *player.Player, itemAID, itemBID stri
continue
}
+ if r.Tool != "" {
+ if r.Tool == toolTypeA && r.MatchesEntry(itemBID) {
+ matched = append(matched, r)
+ continue
+ }
+ if r.Tool == toolTypeB && r.MatchesEntry(itemAID) {
+ matched = append(matched, r)
+ continue
+ }
+ }
+
aMatch := false
bMatch := false
for _, e := range r.Consume {