-
Notifications
You must be signed in to change notification settings - Fork 0
/
double-click.go
293 lines (278 loc) · 6.94 KB
/
double-click.go
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
package events
// Common DoubleClick events
import (
"strconv"
"strings"
"github.com/qbradq/sharduo/internal/game"
"github.com/qbradq/sharduo/internal/gumps"
"github.com/qbradq/sharduo/lib/clientpacket"
"github.com/qbradq/sharduo/lib/template"
"github.com/qbradq/sharduo/lib/uo"
)
func init() {
reg("CashCheck", CashCheck)
reg("Edit", Edit)
reg("HarvestCrop", HarvestCrop)
reg("Mount", Mount)
reg("OpenBackpack", OpenBackpack)
reg("OpenBankBox", OpenBankBox)
reg("OpenContainer", OpenContainer)
reg("OpenPaperDoll", OpenPaperDoll)
reg("OpenTeleportGUMP", OpenTeleportGUMP)
reg("PlayerDoubleClick", PlayerDoubleClick)
reg("TransferHue", TransferHue)
}
// PlayerDoubleClick selects between the open paper doll and dismount actions
// based on the identity of the source.
func PlayerDoubleClick(receiver, source game.Object, v any) bool {
rm, ok := receiver.(game.Mobile)
if !ok {
return false
}
sm, ok := source.(game.Mobile)
if !ok {
return false
}
if receiver.Serial() != source.Serial() {
// Someone is trying to open our paper doll, just send it
if sm.NetState() != nil {
sm.NetState().OpenPaperDoll(rm)
}
return true
}
if rm.IsMounted() {
rm.Dismount()
} else {
sm.NetState().OpenPaperDoll(rm)
}
return true
}
// OpenPaperDoll opens the paper doll of the receiver mobile to the source.
func OpenPaperDoll(receiver, source game.Object, v any) bool {
rm, ok := receiver.(game.Mobile)
if !ok {
return false
}
sm, ok := source.(game.Mobile)
if !ok {
return false
}
if sm.NetState() != nil {
sm.NetState().OpenPaperDoll(rm)
}
return true
}
// OpenContainer opens this container for the mobile. As an additional
// restriction it checks the Z distance against the uo.ContainerOpen* limits.
func OpenContainer(receiver, source game.Object, v any) bool {
rc, ok := receiver.(game.Container)
if !ok {
return false
}
sm, ok := source.(game.Mobile)
if !ok || sm.NetState() == nil {
return false
}
rl := game.RootParent(receiver).Location()
sl := game.RootParent(source).Location()
dz := rl.Z - sl.Z
if game.RootParent(rc).Location().XYDistance(sm.Location()) > uo.MaxUseRange {
sm.NetState().Cliloc(nil, 500312) // You cannot reach that.
return false
}
if dz < uo.ContainerOpenLowerLimit || dz > uo.ContainerOpenUpperLimit {
sm.NetState().Cliloc(nil, 500312) // You cannot reach that.
return false
}
// Line of sight check
if !sm.HasLineOfSight(rc) {
sm.NetState().Cliloc(nil, 500950) // You cannot see that.
return false
}
rc.Open(sm)
return true
}
// Mount attempts to mount the source mobile onto the receiver.
func Mount(receiver, source game.Object, v any) bool {
rm, ok := receiver.(game.Mobile)
if !ok {
return false
}
sm, ok := source.(game.Mobile)
if !ok {
return false
}
if rm.ControlMaster() == nil || rm.ControlMaster().Serial() != sm.Serial() {
return false
}
// Range check
if game.RootParent(sm).Location().XYDistance(rm.Location()) > uo.MaxUseRange {
sm.NetState().Cliloc(nil, 502803) // It's too far away.
return false
}
// Line of sight check
if !sm.HasLineOfSight(rm) {
sm.NetState().Cliloc(nil, 500950) // You cannot see that.
return false
}
sm.Mount(rm)
return true
}
// OpenBackpack attempts to open the backpack of the receiver as in snooping or
// pack animals.
func OpenBackpack(receiver, source game.Object, v any) bool {
sm, ok := source.(game.Mobile)
if !ok {
return false
}
if sm.NetState() == nil {
return false
}
rm, ok := receiver.(game.Mobile)
if !ok {
return false
}
// Control check
if rm.ControlMaster() != nil && rm.ControlMaster().Serial() != sm.Serial() {
// TODO Snooping?
return false
}
// Range check
if game.RootParent(sm).Location().XYDistance(rm.Location()) > uo.MaxUseRange {
sm.NetState().Cliloc(nil, 502803) // It's too far away.
return false
}
// Line of sight check
if !sm.HasLineOfSight(rm) {
sm.NetState().Cliloc(nil, 500950) // You cannot see that.
return false
}
bpo := rm.EquipmentInSlot(uo.LayerBackpack)
if bpo == nil {
// Something very wrong
return false
}
bp, ok := bpo.(game.Container)
if !ok {
// Something very wrong
return false
}
bp.Open(sm)
return true
}
// OpenBankBox attempts to open the bank box of the source.
func OpenBankBox(receiver, source game.Object, v any) bool {
m, ok := source.(game.Mobile)
if !ok {
return false
}
if m.NetState() == nil {
return false
}
bbo := m.EquipmentInSlot(uo.LayerBankBox)
if bbo == nil {
return false
}
bb, ok := bbo.(game.Container)
if !ok {
return false
}
bb.Open(m)
game.GetWorld().Map().SendCliloc(receiver, uo.SpeechNormalRange, 1080021,
strconv.Itoa(bb.ItemCount()), strconv.Itoa(int(bb.Weight()))) // Bank container has ~1_VAL~ items, ~2_VAL~ stones
return true
}
func TransferHue(receiver, source game.Object, v any) bool {
if receiver == nil || source == nil {
return false
}
sm, ok := source.(game.Mobile)
if !ok || sm.NetState() == nil {
return false
}
sm.NetState().Speech(source, "Target object to set hue %d", receiver.Hue())
sm.NetState().TargetSendCursor(uo.TargetTypeObject, func(tr *clientpacket.TargetResponse) {
o := game.GetWorld().Find(tr.TargetObject)
if o == nil {
return
}
o.SetHue(receiver.Hue())
game.GetWorld().Update(o)
})
return true
}
func Edit(receiver, source game.Object, v any) bool {
sm, ok := source.(game.Mobile)
if !ok || sm.NetState() == nil || !sm.NetState().Account().HasRole(game.RoleGameMaster) {
return false
}
gumps.Edit(sm, receiver)
return true
}
func OpenTeleportGUMP(receiver, source game.Object, v any) bool {
if source == nil {
return false
}
sm, ok := source.(game.Mobile)
if !ok {
return false
}
if sm.NetState() == nil {
return false
}
sm.NetState().GUMP(gumps.New("teleport"), source, nil)
return true
}
func HarvestCrop(receiver, source game.Object, v any) bool {
sm, ok := source.(game.Mobile)
if !ok || sm.NetState() == nil {
return false
}
// Range check
if game.RootParent(sm).Location().XYDistance(receiver.Location()) > uo.MaxUseRange {
sm.NetState().Cliloc(nil, 502803) // It's too far away.
return false
}
// Line of sight check
if !sm.HasLineOfSight(receiver) {
sm.NetState().Cliloc(nil, 500950) // You cannot see that.
return false
}
tn := strings.TrimSuffix(receiver.TemplateName(), "Crop")
i := template.Create[game.Item](tn)
if i == nil {
return false
}
if !sm.DropToBackpack(i, false) {
sm.DropToFeet(i)
}
game.Remove(receiver)
return true
}
func CashCheck(receiver, source game.Object, v any) bool {
check := receiver.(*game.Check)
sm, ok := source.(game.Mobile)
if !ok || sm.NetState() == nil {
return false
}
if !sm.InBank(check) {
sm.NetState().Speech(sm, "That must be in your bank box to use.")
return false
}
game.Remove(check)
for {
n := check.CheckAmount()
if n < 1 {
break
}
if n > uo.MaxStackAmount {
n = uo.MaxStackAmount
} else {
check.SetCheckAmount(check.CheckAmount() - n)
}
gc := template.Create[game.Item]("GoldCoin")
gc.SetAmount(n)
sm.DropToBankBox(gc, true)
}
return true
}