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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
package game
import (
"fmt"
"strings"
"thehouseoficarus/internal/engine"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/player"
)
func (g *Game) advanceClean(sess *net.Session, p *player.Player) {
phase, _ := p.BackgroundAction.Data["phase"].(int)
filter, _ := p.BackgroundAction.Data["filter"].(string)
if phase == 0 {
p.BackgroundAction.Data["phase"] = 1
p.BackgroundAction.WaitLeft = engine.ToTicks(2)
return
}
allRecipes, err := g.RecipeStore.LoadAll()
if err != nil {
g.CancelBackgroundAction(p)
return
}
var recipe *cleanMatch
for _, r := range allRecipes {
if r.Type != "clean" {
continue
}
if filter != "" {
if len(r.Consume) == 0 || len(r.Consume[0].Items) == 0 {
continue
}
if !strings.Contains(r.Consume[0].Items[0], filter) &&
!strings.Contains(r.Output, filter) {
continue
}
}
if p.Level(player.Pharmacy) < r.Level {
continue
}
if !r.HasAllItems(p.HasItem) {
continue
}
recipe = &cleanMatch{r.Consume[0].Items[0], r.Output, r.XP, r.Message}
break
}
if recipe == nil {
sess.WriteLine("\nYou've finished cleaning herbs.")
g.CancelBackgroundAction(p)
return
}
for i := 0; i < 28; i++ {
slot := p.InvSlot(i)
if slot != nil && slot.ItemID == recipe.consumeID {
slot.ItemID = recipe.outputID
break
}
}
if recipe.xp > 0 {
if newLevel := p.AddSkillXP(player.Pharmacy, recipe.xp); newLevel > 0 {
sess.WriteLine(g.colorize(sess, "level_up",
fmt.Sprintf("*** You are now level %d pharmacy! ***", newLevel)))
}
}
g.AccountStore.SaveCharacter(p)
msg := recipe.message
if msg == "" {
outDef, _ := g.ItemStore.Load(recipe.outputID)
outputName := recipe.outputID
if outDef != nil {
outputName = outDef.Name
}
msg = fmt.Sprintf("You clean a %s.", outputName)
}
if p.OptionBool("xp_drops") && recipe.xp > 0 {
abbr := player.SkillAbbr[player.Pharmacy]
msg += g.colorize(sess, "xp", fmt.Sprintf(" (+%dxp %s)", recipe.xp, abbr))
}
sess.WriteLine(msg)
hasMore := false
for _, r := range allRecipes {
if r.Type != "clean" {
continue
}
if filter != "" {
if len(r.Consume) == 0 || len(r.Consume[0].Items) == 0 {
continue
}
if !strings.Contains(r.Consume[0].Items[0], filter) &&
!strings.Contains(r.Output, filter) {
continue
}
}
if p.Level(player.Pharmacy) >= r.Level && r.HasAllItems(p.HasItem) {
hasMore = true
break
}
}
if !hasMore {
sess.WriteLine("\nYou've finished cleaning herbs.")
g.CancelBackgroundAction(p)
return
}
p.BackgroundAction.WaitLeft = engine.ToTicks(2)
}
type cleanMatch struct {
consumeID string
outputID string
xp int
message string
}
|