diff options
| author | historia <[not public]> | 2026-06-19 02:08:55 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-19 02:08:55 -0400 |
| commit | 458916fb78dcef3ff77cb29b7ba98d9f646819fc (patch) | |
| tree | 19cd8b8eef41a1aa00d155bf7953ad2770f91a4c /internal/game/cmd_mix.go | |
| parent | 97a1a908b9e6e6d3516628c139c9b64262b4fe08 (diff) | |
| download | thehouseoficarus-458916fb78dcef3ff77cb29b7ba98d9f646819fc.tar.gz | |
feat: rough pharmacy skill added
Diffstat (limited to 'internal/game/cmd_mix.go')
| -rw-r--r-- | internal/game/cmd_mix.go | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/internal/game/cmd_mix.go b/internal/game/cmd_mix.go new file mode 100644 index 0000000..3082870 --- /dev/null +++ b/internal/game/cmd_mix.go @@ -0,0 +1,113 @@ +package game + +import ( + "thehouseoficarus/internal/action" + "thehouseoficarus/internal/net" + "thehouseoficarus/internal/player" + "thehouseoficarus/internal/world" +) + +func (g *Game) doMix(sess *net.Session, input string) { + p := sess.Player.(*player.Player) + g.CancelAction(p) + + allRecipes, err := g.RecipeStore.LoadAll() + if err != nil { + sess.WriteLine("Error loading recipes.") + return + } + + if input == "" { + g.showMixMenu(sess, p, allRecipes) + return + } + + qty, itemName := parseQty(input) + _ = qty + + var matched []action.RecipeDef + for _, r := range allRecipes { + if r.Type != "pharmacy" { + continue + } + outDef, _ := g.ItemStore.Load(r.Output) + name := r.Output + if outDef != nil { + name = outDef.Name + } + if world.WordPrefixMatch(itemName, name) { + matched = append(matched, r) + } + } + + if len(matched) == 0 { + sess.WriteLine("You can't mix that.") + return + } + + var available []action.RecipeDef + for _, r := range matched { + if r.HasAllItems(p.HasItem) && p.Level(player.Pharmacy) >= r.Level { + available = append(available, r) + } + } + + if len(available) == 0 { + sess.WriteLine("You don't have the materials for that.") + return + } + + if len(available) == 1 { + g.promptHowMany(sess, available[0].ID) + return + } + + sess.State = net.StateRecipeChoice + var names []string + for _, r := range available { + names = append(names, g.recipeName(sess, &r)) + } + g.showMenuTable(sess, "What would you like to mix?", names) + sess.PendingMenu = recipeMenuData(available) +} + +func (g *Game) showMixMenu(sess *net.Session, p *player.Player, allRecipes []action.RecipeDef) { + seen := make(map[string]bool) + var entries []recipeEntry + + for _, r := range allRecipes { + if r.Type != "pharmacy" { + continue + } + if seen[r.ID] { + continue + } + if !r.HasAllItems(p.HasItem) { + continue + } + seen[r.ID] = true + entries = append(entries, recipeEntry{g.recipeName(sess, &r), r}) + } + + if len(entries) == 0 { + sess.WriteLine("You don't have anything you can mix.") + return + } + + if len(entries) == 1 { + if p.OptionBool("mix_all") { + g.startProductionFromRecipe(sess, p, &entries[0].Recipe, 0) + return + } + g.promptHowMany(sess, entries[0].Recipe.ID) + return + } + + sess.State = net.StateRecipeChoice + var names []string + for _, e := range entries { + names = append(names, e.ItemName) + } + g.showMenuTable(sess, "What would you like to mix?", names) + sess.PendingMenu = entryMenuData(entries) +} |
