aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_smelt.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-17 21:13:07 -0400
committerhistoria <[not public]>2026-06-17 21:13:07 -0400
commitec2e94e3463654a6288464a4c070b48ef9bf7368 (patch)
tree3c5df0f9a6a5968fa4c725a7d331825883ae798c /internal/game/cmd_smelt.go
parenteef5ddaa94f8cff6010d092c30fed53d2be01524 (diff)
downloadthehouseoficarus-ec2e94e3463654a6288464a4c070b48ef9bf7368.tar.gz
feat: smithing added, item/object interaction reworked. recipes and menus refactored.
Diffstat (limited to 'internal/game/cmd_smelt.go')
-rw-r--r--internal/game/cmd_smelt.go163
1 files changed, 22 insertions, 141 deletions
diff --git a/internal/game/cmd_smelt.go b/internal/game/cmd_smelt.go
index a308352..e0889f6 100644
--- a/internal/game/cmd_smelt.go
+++ b/internal/game/cmd_smelt.go
@@ -2,25 +2,18 @@ package game
import (
"fmt"
- "strconv"
- "strings"
"thehouseoficarus/internal/action"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/player"
)
-type smeltableEntry struct {
- ItemName string
- Recipe action.RecipeDef
-}
-
func (g *Game) doSmelt(sess *net.Session, input string) {
p := sess.Player.(*player.Player)
g.CancelAction(p)
- stationName := g.findFurnace(p.RoomID)
- if stationName == "" {
+ stationDefID, stationName := g.findStation(p.RoomID, []string{"furnace"})
+ if stationDefID == "" {
sess.WriteLine("You need a furnace to smelt.")
return
}
@@ -32,7 +25,7 @@ func (g *Game) doSmelt(sess *net.Session, input string) {
}
if input == "" {
- g.showSmeltMenu(sess, p, allRecipes, stationName)
+ g.showSmeltMenu(sess, p, allRecipes, stationDefID, stationName)
return
}
@@ -55,38 +48,27 @@ func (g *Game) doSmelt(sess *net.Session, input string) {
var recipes []action.RecipeDef
for _, r := range allRecipes {
- if r.Type != "smelting" {
- continue
- }
- if !smeltStationOK(stationName, r.Station) {
+ if r.Type != "smelting" || !stationMatch(stationDefID, r.Station) || !r.MatchesEntry(itemID) {
continue
}
- if !r.MatchesEntry(itemID) {
- continue
- }
- if !r.HasAllItemsQty(p.CountItem) {
- continue
- }
- skillLevel := p.Level(player.SkillName(r.Skill))
- if skillLevel < r.Level {
+ if !r.HasAllItemsQty(p.CountItem) || p.Level(player.SkillName(r.Skill)) < r.Level {
continue
}
recipes = append(recipes, r)
}
if len(recipes) == 0 {
- sess.WriteLine("You can't smelt that here.")
+ sess.WriteLine("You can't smelt that.")
return
}
if len(recipes) == 1 {
- g.startSmelt(sess, p, &recipes[0], stationName)
+ g.promptHowMany(sess, recipes[0].ID)
return
}
- sess.PendingRecipeItem = itemID
- sess.PendingCookMenu = smeltRecipesToMenuData(recipes)
- sess.State = net.StateSmeltRecipe
+ sess.PendingMenu = recipeMenuData(recipes)
+ sess.State = net.StateRecipeChoice
sess.WriteLine("\nWhat would you like to smelt?")
for i, r := range recipes {
sess.WriteLine(fmt.Sprintf(" %d) %s", i+1, g.recipeName(sess, &r)))
@@ -94,137 +76,36 @@ func (g *Game) doSmelt(sess *net.Session, input string) {
sess.WriteLine(fmt.Sprintf(" %d) Nothing", len(recipes)+1))
}
-func (g *Game) showSmeltMenu(sess *net.Session, p *player.Player, allRecipes []action.RecipeDef, stationName string) {
+func (g *Game) showSmeltMenu(sess *net.Session, p *player.Player, allRecipes []action.RecipeDef, stationDefID, stationName string) {
seen := make(map[string]bool)
- var smeltables []smeltableEntry
+ var entries []recipeEntry
for _, r := range allRecipes {
- if r.Type != "smelting" {
- continue
- }
- if !smeltStationOK(stationName, r.Station) {
- continue
- }
- if seen[r.ID] {
- continue
- }
- if !r.HasAllItemsQty(p.CountItem) {
+ if r.Type != "smelting" || !stationMatch(stationDefID, r.Station) {
continue
}
- skillLevel := p.Level(player.SkillName(r.Skill))
- if skillLevel < r.Level {
+ if seen[r.ID] || !r.HasAllItemsQty(p.CountItem) || p.Level(player.SkillName(r.Skill)) < r.Level {
continue
}
seen[r.ID] = true
- smeltables = append(smeltables, smeltableEntry{g.recipeName(sess, &r), r})
+ entries = append(entries, recipeEntry{g.recipeName(sess, &r), r})
}
- if len(smeltables) == 0 {
+ if len(entries) == 0 {
sess.WriteLine("You don't have anything you can smelt.")
return
}
- if len(smeltables) == 1 {
- g.startSmelt(sess, p, &smeltables[0].Recipe, stationName)
+ if len(entries) == 1 {
+ g.promptHowMany(sess, entries[0].Recipe.ID)
return
}
- sess.PendingRecipeItem = ""
- sess.State = net.StateSmeltRecipe
+ sess.State = net.StateRecipeChoice
sess.WriteLine("\nWhat would you like to smelt?")
- for i, s := range smeltables {
- sess.WriteLine(fmt.Sprintf(" %d) %s", i+1, s.ItemName))
- }
- sess.WriteLine(fmt.Sprintf(" %d) Nothing", len(smeltables)+1))
-
- sess.PendingCookMenu = makeSmeltMenuData(smeltables)
-}
-
-func (g *Game) handleSmeltRecipe(sess *net.Session, input string) {
- p := sess.Player.(*player.Player)
- input = strings.TrimSpace(input)
- if input == "" {
- return
- }
-
- choice, err := strconv.Atoi(input)
- if err != nil {
- sess.State = net.StateGame
- sess.PendingRecipeItem = ""
- sess.PendingCookMenu = nil
- sess.WriteLine("You decide not to smelt anything.")
- g.reprompt(sess)
- return
- }
-
- if len(sess.PendingCookMenu) > 0 {
- menuData := sess.PendingCookMenu
- sess.PendingCookMenu = nil
- if choice <= 0 || choice > len(menuData)+1 {
- sess.WriteLine("Invalid choice.")
- return
- }
- sess.State = net.StateGame
- if choice == len(menuData)+1 {
- sess.WriteLine("You decide not to smelt anything.")
- g.reprompt(sess)
- return
- }
- entry := menuData[choice-1]
-
- all, loadErr := g.RecipeStore.LoadAll()
- if loadErr != nil {
- g.reprompt(sess)
- return
- }
- for _, r := range all {
- if r.ID == entry["recipe_id"] {
- stationName := g.findFurnace(p.RoomID)
- g.startSmelt(sess, p, &r, stationName)
- return
- }
- }
- g.reprompt(sess)
- return
- }
-
- sess.State = net.StateGame
- g.reprompt(sess)
-}
-
-func smeltStationOK(stationName string, recipeStations []string) bool {
- for _, rs := range recipeStations {
- if rs == "furnace" && stationName == "furnace" {
- return true
- }
- }
- return false
-}
-
-func (g *Game) findFurnace(roomID int) string {
- for _, obj := range g.World.AllObjInstances(roomID) {
- if obj.Depleted {
- continue
- }
- if obj.DefID == "furnace" {
- return "furnace"
- }
- }
- return ""
-}
-
-func makeSmeltMenuData(smeltables []smeltableEntry) []map[string]string {
- out := make([]map[string]string, len(smeltables))
- for i, s := range smeltables {
- out[i] = map[string]string{"recipe_id": s.Recipe.ID}
- }
- return out
-}
-
-func smeltRecipesToMenuData(recipes []action.RecipeDef) []map[string]string {
- out := make([]map[string]string, len(recipes))
- for i, r := range recipes {
- out[i] = map[string]string{"recipe_id": r.ID}
+ for i, e := range entries {
+ sess.WriteLine(fmt.Sprintf(" %d) %s", i+1, e.ItemName))
}
- return out
+ sess.WriteLine(fmt.Sprintf(" %d) Nothing", len(entries)+1))
+ sess.PendingMenu = entryMenuData(entries)
}