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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
package game
import (
"fmt"
"math/rand"
"thehouseoficarus/internal/action"
"thehouseoficarus/internal/engine"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/player"
)
func (g *Game) startSmelt(sess *net.Session, p *player.Player, recipe *action.RecipeDef, stationName string) {
g.CancelAction(p)
if recipe.Skill != "" {
skillLevel := p.Level(player.SkillName(recipe.Skill))
if skillLevel < recipe.Level {
sess.WriteLine(fmt.Sprintf("You need level %d %s to smelt that.", recipe.Level, recipe.Skill))
return
}
}
if !recipe.HasAllItemsQty(p.CountItem) {
sess.WriteLine("You don't have the required ores.")
return
}
if p.FirstFreeSlot() == -1 {
sess.WriteLine("Your inventory is too full!")
return
}
wait := recipe.Wait
if wait <= 0 {
wait = 4
}
outputName := recipe.Output
if def, err := g.ItemStore.Load(recipe.Output); err == nil {
outputName = def.Name
}
p.Action = &action.Action{
Type: "smelt",
TargetID: recipe.ID,
TargetName: recipe.DisplayName(),
Data: map[string]any{
"recipe_id": recipe.ID,
"station_name": stationName,
"phase": 0,
"wait": wait,
},
WaitLeft: engine.ToTicks(1),
}
p.ActionState = &ActionState{Type: ActionSmelting, TargetName: outputName}
}
func (g *Game) advanceSmelt(sess *net.Session, p *player.Player) bool {
recipeID := p.Action.Data["recipe_id"].(string)
phase := p.Action.Data["phase"].(int)
wait := p.Action.Data["wait"].(float64)
all, err := g.RecipeStore.LoadAll()
if err != nil {
g.CancelAction(p)
return false
}
var recipe *action.RecipeDef
for _, r := range all {
if r.ID == recipeID {
recipe = &r
break
}
}
if recipe == nil {
g.CancelAction(p)
return false
}
if phase == 0 {
firstItem := recipe.FirstItemName(func(id string) (string, bool) {
def, err := g.ItemStore.Load(id)
if err != nil {
return id, false
}
return def.Name, true
})
sess.WriteLine(fmt.Sprintf("\nYou begin to process %s in the furnace.", firstItem))
p.Action.Data["phase"] = 1
p.Action.WaitLeft = engine.ToTicks(wait)
return true
}
skillLevel := p.Level(player.SkillName(recipe.Skill))
chance := 1.0
if recipe.Success != nil {
chance = action.SuccessChance(*recipe.Success, skillLevel, recipe.Level)
}
if rand.Float64() < chance {
freeSlot := p.FirstFreeSlot()
if freeSlot == -1 {
sess.WriteLine("Your inventory is too full!")
g.CancelAction(p)
return false
}
recipe.ConsumeAll(p.HasItem, p.RemoveItem)
p.SetInvSlot(freeSlot, &player.InventorySlot{ItemID: recipe.Output, Quantity: 1})
if recipe.XP > 0 {
if newLevel := p.AddSkillXP(player.SkillName(recipe.Skill), recipe.XP); newLevel > 0 {
sess.WriteLine(g.colorize(sess, "level_up", fmt.Sprintf("*** You are now level %d %s! ***", newLevel, recipe.Skill)))
}
}
g.AccountStore.SaveCharacter(p)
msg := recipe.Message
if msg == "" {
outputName := recipe.Output
if def, loadErr := g.ItemStore.Load(recipe.Output); loadErr == nil {
outputName = def.Name
}
msg = fmt.Sprintf("You remove a white hot %s!", outputName)
}
if p.OptionBool("xp_drops") && recipe.XP > 0 {
abbr := player.SkillAbbr[player.SkillName(recipe.Skill)]
msg += g.colorize(sess, "xp", fmt.Sprintf(" (+%dxp %s)", recipe.XP, abbr))
}
sess.WriteLine(msg)
} else {
recipe.ConsumeAll(p.HasItem, p.RemoveItem)
g.AccountStore.SaveCharacter(p)
msg := recipe.FailMessage
if msg == "" {
msg = "You fail to smelt a usable bar."
}
sess.WriteLine(g.colorize(sess, "damage", msg))
}
if recipe.HasAllItemsQty(p.CountItem) && p.FirstFreeSlot() >= 0 {
p.Action.Data["phase"] = 0
p.Action.WaitLeft = engine.ToTicks(wait)
return true
}
sess.WriteLine("\nYou've processed all the ore in your inventory.")
g.CancelAction(p)
return false
}
|