aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_craft.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-19 18:20:26 -0400
committerhistoria <[not public]>2026-06-19 18:20:26 -0400
commit0ea4eec5dd2122c6704216971eb1249276297867 (patch)
tree430fbbef04e837820f1d031c190f52ecd6112e25 /internal/game/cmd_craft.go
parent3a58125d14bb307f861b38c6c5b0a63babde7e08 (diff)
downloadthehouseoficarus-0ea4eec5dd2122c6704216971eb1249276297867.tar.gz
shop fixes, 'toggle' completely removed, movement speed increased
Diffstat (limited to 'internal/game/cmd_craft.go')
-rw-r--r--internal/game/cmd_craft.go78
1 files changed, 42 insertions, 36 deletions
diff --git a/internal/game/cmd_craft.go b/internal/game/cmd_craft.go
index 50a99e0..7f8808b 100644
--- a/internal/game/cmd_craft.go
+++ b/internal/game/cmd_craft.go
@@ -6,12 +6,19 @@ import (
"thehouseoficarus/internal/action"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/player"
- "thehouseoficarus/internal/world"
)
func (g *Game) doCraft(sess *net.Session, input string) {
- p := sess.Player.(*player.Player)
- g.CancelAction(p)
+ g.doGenericStationSkill(sess, input, "crafting", player.Crafting, "last_craft", "Crafting", "craft", "Craft")
+}
+
+func (g *Game) doConstruct(sess *net.Session, input string) {
+ g.doGenericStationSkill(sess, input, "construction", player.Construction, "last_construct", "Construction", "construct", "Construct")
+}
+
+func (g *Game) doGenericStationSkill(sess *net.Session, input string, recipeType string, skill player.SkillName, flagKey, label, verbPast, verbCap string) {
+ p := sess.Player
+ g.cancelAction(p)
allRecipes, err := g.RecipeStore.LoadAll()
if err != nil {
@@ -19,29 +26,29 @@ func (g *Game) doCraft(sess *net.Session, input string) {
return
}
- var craftRecipes []action.RecipeDef
+ var recipes []action.RecipeDef
for _, r := range allRecipes {
- if r.Type != "crafting" {
+ if r.Type != recipeType {
continue
}
- if !g.craftRecipeVisible(p, &r) {
+ if !g.genericRecipeVisible(p, &r) {
continue
}
- craftRecipes = append(craftRecipes, r)
+ recipes = append(recipes, r)
}
if input != "" {
- g.doCraftWithInput(sess, p, craftRecipes, input)
+ g.doGenericWithInput(sess, p, recipes, input, skill, flagKey, label, verbCap)
return
}
- lastRecipeID, _ := p.Flags["last_craft"].(string)
+ lastRecipeID, _ := p.Flags[flagKey].(string)
if lastRecipeID != "" {
- for i := range craftRecipes {
- if craftRecipes[i].ID == lastRecipeID {
- r := &craftRecipes[i]
- if g.canDoCraftRecipe(p, r) {
- g.startCraftRecipe(sess, p, r, 0)
+ for i := range recipes {
+ if recipes[i].ID == lastRecipeID {
+ r := &recipes[i]
+ if g.canDoGenericRecipe(p, r, skill) {
+ g.startGenericRecipe(sess, p, r, 0, flagKey)
return
}
break
@@ -49,44 +56,45 @@ func (g *Game) doCraft(sess *net.Session, input string) {
}
}
- available := g.availableCraftRecipes(p, craftRecipes)
+ available := g.availableGenericRecipes(p, recipes)
if len(available) == 0 {
- sess.WriteLine("You don't have any materials to craft.")
+ sess.WriteLine("You don't have any materials to " + verbPast + ".")
return
}
- if p.OptionBool("craft_all") && len(available) == 1 {
- g.startCraftRecipe(sess, p, &available[0], 0)
+ optionKey := verbPast + "_all"
+ if p.OptionBool(optionKey) && len(available) == 1 {
+ g.startGenericRecipe(sess, p, &available[0], 0, flagKey)
return
}
- g.showProductionTable(sess, p, available, "Crafting", "crafting", "last_craft", "Craft", false)
+ g.showProductionTable(sess, p, available, label, recipeType, flagKey, verbCap, false)
}
-func (g *Game) doCraftWithInput(sess *net.Session, p *player.Player, craftRecipes []action.RecipeDef, input string) {
+func (g *Game) doGenericWithInput(sess *net.Session, p *player.Player, recipes []action.RecipeDef, input string, skill player.SkillName, flagKey, label, verbCap string) {
qty, productName := parseQty(input)
productName = strings.TrimSpace(productName)
var matched []action.RecipeDef
- for _, r := range craftRecipes {
+ for _, r := range recipes {
outDef, _ := g.ItemStore.Load(r.Output)
name := r.Output
if outDef != nil {
name = outDef.Name
}
- if world.WordPrefixMatch(productName, name) {
+ if action.WordPrefixMatch(productName, name) {
matched = append(matched, r)
}
}
if len(matched) == 0 {
- sess.WriteLine("You can't craft that.")
+ sess.WriteLine("You can't " + strings.ToLower(verbCap) + " that.")
return
}
var available []action.RecipeDef
for _, r := range matched {
- if g.canDoCraftRecipe(p, &r) {
+ if g.canDoGenericRecipe(p, &r, skill) {
available = append(available, r)
}
}
@@ -97,14 +105,14 @@ func (g *Game) doCraftWithInput(sess *net.Session, p *player.Player, craftRecipe
}
if len(available) == 1 {
- g.startCraftRecipe(sess, p, &available[0], qty)
+ g.startGenericRecipe(sess, p, &available[0], qty, flagKey)
return
}
- g.showProductionTable(sess, p, available, "Crafting", "crafting", "last_craft", "Craft", false)
+ g.showProductionTable(sess, p, available, label, label, flagKey, verbCap, false)
}
-func (g *Game) craftRecipeVisible(p *player.Player, r *action.RecipeDef) bool {
+func (g *Game) genericRecipeVisible(p *player.Player, r *action.RecipeDef) bool {
if len(r.Station) > 0 {
stID, _ := g.findStation(p.RoomID, r.Station)
if stID == "" {
@@ -117,8 +125,8 @@ func (g *Game) craftRecipeVisible(p *player.Player, r *action.RecipeDef) bool {
return true
}
-func (g *Game) canDoCraftRecipe(p *player.Player, r *action.RecipeDef) bool {
- if p.Level(player.Crafting) < r.Level {
+func (g *Game) canDoGenericRecipe(p *player.Player, r *action.RecipeDef, skill player.SkillName) bool {
+ if p.Level(skill) < r.Level {
return false
}
if !r.HasAllItemsQty(p.CountItem) {
@@ -136,9 +144,9 @@ func (g *Game) canDoCraftRecipe(p *player.Player, r *action.RecipeDef) bool {
return true
}
-func (g *Game) availableCraftRecipes(p *player.Player, allCraft []action.RecipeDef) []action.RecipeDef {
+func (g *Game) availableGenericRecipes(p *player.Player, allRecipes []action.RecipeDef) []action.RecipeDef {
var result []action.RecipeDef
- for _, r := range allCraft {
+ for _, r := range allRecipes {
if r.HasAllItemsQty(p.CountItem) {
result = append(result, r)
}
@@ -146,11 +154,9 @@ func (g *Game) availableCraftRecipes(p *player.Player, allCraft []action.RecipeD
return result
}
-func (g *Game) startCraftRecipe(sess *net.Session, p *player.Player, recipe *action.RecipeDef, count int) {
- if p.Flags == nil {
- p.Flags = make(map[string]any)
- }
- p.Flags["last_craft"] = recipe.ID
+func (g *Game) startGenericRecipe(sess *net.Session, p *player.Player, recipe *action.RecipeDef, count int, flagKey string) {
+ p.EnsureFlags()
+ p.Flags[flagKey] = recipe.ID
g.AccountStore.SaveCharacter(p)
g.startProductionFromRecipe(sess, p, recipe, count)