1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
package game
import (
"fmt"
"strings"
"thehouseoficarus/internal/action"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/player"
)
func (g *Game) executeSmelt(sess *net.Session, args []string, rawInput string) {
g.doSmelt(sess, strings.Join(args, " "))
}
func (g *Game) doSmelt(sess *net.Session, input string) {
p := sess.Player
g.cancelAction(p)
stationDefID, stationName := g.findStation(p.RoomID, []string{"furnace"})
if stationDefID == "" {
sess.WriteLine("You need a furnace to smelt.")
return
}
allRecipes, err := g.RecipeStore.LoadAll()
if err != nil {
sess.WriteLine("Error loading recipes.")
return
}
if input == "" {
g.showSmeltMenu(sess, p, allRecipes, stationDefID, stationName)
return
}
matches := g.findInventoryMatches(input, p)
if len(matches) == 0 {
sess.WriteLine(fmt.Sprintf("You don't have any '%s'.", input))
return
}
unique := uniqueItemNames(matches)
if len(unique) > 1 {
g.showWhichOne(sess, matches)
return
}
itemID := matches[0].ID
var recipes []action.RecipeDef
for _, r := range allRecipes {
if r.Type != "smelting" || !stationMatch(stationDefID, r.Station) || !r.MatchesEntry(itemID) {
continue
}
if !r.HasAllItemsQty(p.CountItem) || p.Level(player.SkillName(r.EffectiveSkill())) < r.Level {
continue
}
recipes = append(recipes, r)
}
g.showRecipeChoice(sess, p, recipes, "You can't smelt that.", "What would you like to smelt?", "")
}
func (g *Game) showSmeltMenu(sess *net.Session, p *player.Player, allRecipes []action.RecipeDef, stationDefID, stationName string) {
seen := make(map[string]bool)
var recipes []action.RecipeDef
for _, r := range allRecipes {
if r.Type != "smelting" || !stationMatch(stationDefID, r.Station) {
continue
}
if seen[r.ID] || !r.HasAllItemsQty(p.CountItem) || p.Level(player.SkillName(r.EffectiveSkill())) < r.Level {
continue
}
seen[r.ID] = true
recipes = append(recipes, r)
}
g.showRecipeChoice(sess, p, recipes, "You don't have anything you can smelt.", "What would you like to smelt?", "smelt_all")
}
|