aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_smith.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/cmd_smith.go')
-rw-r--r--internal/game/cmd_smith.go59
1 files changed, 27 insertions, 32 deletions
diff --git a/internal/game/cmd_smith.go b/internal/game/cmd_smith.go
index c7a32cd..712c03c 100644
--- a/internal/game/cmd_smith.go
+++ b/internal/game/cmd_smith.go
@@ -5,8 +5,8 @@ import (
"sort"
"strings"
- "thehouseoficarus/internal/action"
"thehouseoficarus/internal/net"
+ "thehouseoficarus/internal/object"
"thehouseoficarus/internal/player"
)
@@ -29,11 +29,7 @@ func (g *Game) doSmith(sess *net.Session, input string) {
return
}
- allRecipes, err := g.RecipeStore.LoadAll()
- if err != nil {
- sess.WriteLine("Error loading recipes.")
- return
- }
+ items := g.CraftIndex.ByType("smithing")
if input != "" {
matches := g.findInventoryMatches(input, p)
@@ -47,15 +43,15 @@ func (g *Game) doSmith(sess *net.Session, input string) {
return
}
barID := matches[0].ID
- if !hasSmithingRecipes(allRecipes, barID) {
+ if !hasSmithingItems(items, barID) {
sess.WriteLine("You can't smith that.")
return
}
- g.showSmithTable(sess, p, barID, allRecipes)
+ g.showSmithTable(sess, p, barID)
return
}
- barTypes := findSmithableBars(allRecipes, p)
+ barTypes := findSmithableBars(items, p)
if len(barTypes) == 0 {
sess.WriteLine("You don't have any bars to smith.")
return
@@ -63,12 +59,12 @@ func (g *Game) doSmith(sess *net.Session, input string) {
if len(barTypes) == 1 {
if p.OptionBool("smith_all") {
- if recipe := g.findSmithRecipe(p, barTypes[0], allRecipes); recipe != nil {
- g.startProductionFromRecipe(sess, p, recipe, 0)
+ if item := g.findSmithItem(p, barTypes[0], items); item != nil {
+ g.startProductionFromItem(sess, p, item, 0)
return
}
}
- g.showSmithTable(sess, p, barTypes[0], allRecipes)
+ g.showSmithTable(sess, p, barTypes[0])
return
}
@@ -86,17 +82,18 @@ func (g *Game) doSmith(sess *net.Session, input string) {
g.showMenuTable(sess, "Which bars would you like to smith?", names)
}
-func (g *Game) showSmithTable(sess *net.Session, p *player.Player, barID string, allRecipes []action.RecipeDef) {
+func (g *Game) showSmithTable(sess *net.Session, p *player.Player, barID string) {
barDef, _ := g.ItemStore.Load(barID)
barName := barID
if barDef != nil {
barName = barDef.Name
}
- var recipes []action.RecipeDef
- for _, r := range allRecipes {
- if r.Type == "smithing" && r.MatchesEntry(barID) {
- recipes = append(recipes, r)
+ allItems := g.CraftIndex.ByType("smithing")
+ var recipes []*object.ItemDef
+ for _, item := range allItems {
+ if craftMatchesEntry(item.FirstCraft(), barID) {
+ recipes = append(recipes, item)
}
}
@@ -109,22 +106,19 @@ func (g *Game) showSmithTable(sess *net.Session, p *player.Player, barID string,
g.showProductionTable(sess, p, recipes, titleCase(barName)+" Smithing", "smithing", lastFlag, "Produce", false)
}
-func hasSmithingRecipes(allRecipes []action.RecipeDef, barID string) bool {
- for _, r := range allRecipes {
- if r.Type == "smithing" && r.MatchesEntry(barID) {
+func hasSmithingItems(items []*object.ItemDef, barID string) bool {
+ for _, item := range items {
+ if craftMatchesEntry(item.FirstCraft(), barID) {
return true
}
}
return false
}
-func findSmithableBars(allRecipes []action.RecipeDef, p *player.Player) []string {
+func findSmithableBars(items []*object.ItemDef, p *player.Player) []string {
barSet := make(map[string]bool)
- for _, r := range allRecipes {
- if r.Type != "smithing" {
- continue
- }
- for _, e := range r.Consume {
+ for _, item := range items {
+ for _, e := range item.FirstCraft().Consume {
for _, id := range e.Items {
if p.HasItem(id) {
barSet[id] = true
@@ -148,15 +142,16 @@ func barMenuData(barIDs []string) []map[string]string {
return out
}
-func (g *Game) findSmithRecipe(p *player.Player, barID string, allRecipes []action.RecipeDef) *action.RecipeDef {
- var makeable []*action.RecipeDef
+func (g *Game) findSmithItem(p *player.Player, barID string, items []*object.ItemDef) *object.ItemDef {
+ var makeable []*object.ItemDef
skillLevel := p.Level(player.Smithing)
- for i, r := range allRecipes {
- if r.Type != "smithing" || !r.MatchesEntry(barID) {
+ for _, item := range items {
+ c := item.FirstCraft()
+ if !craftMatchesEntry(c, barID) {
continue
}
- if skillLevel >= r.Level && r.HasAllItemsQty(p.CountItem) {
- makeable = append(makeable, &allRecipes[i])
+ if skillLevel >= c.Level && craftHasAllItemsQty(c, p.CountItem) {
+ makeable = append(makeable, item)
}
}
if len(makeable) == 1 {