- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitems.lua
More file actions
Latest commit
431 lines (413 loc) · 18 KB
/
Copy pathitems.lua
File metadata and controls
431 lines (413 loc) · 18 KB
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
items= {
server= {
container= {}
},
client= {
container= {},
requested= {}
}
}
localimageId2Type= {
armor0Helmet='helmet', armor1Helmet='helmet',
armor0Chest='chest', armor1Chest='chest',
armor0Pants='pants', armor1Pants='pants'
}
for_, vinipairs{'sword0', 'sword1', 'sword2', 'sword3', 'sword4'} do
imageId2Type[v] ='sword'
end
functionitems.server.newItem(data)
ifnotdata.idthen
data.id=lume.uuid()
end
ifnotdata.imageIdthen
data.imageId='apple'
end
ifnotdata.typethen
data.type=imageId2Type[data.imageId]
data.type=data.typeordata.imageId
end
items.server.container[data.id] =data
returndata.id
end
functionitems.server.reset()
items.server.container= {}
end
functionitems.server.getItem(id)
ifid==nilthenreturnnilend
returnitems.server.container[id]
end
functionitems.client.reset()
items.client.container= {}
items.client.requested= {}
end
functionitems.client.getItem(id)
ifid==nilthenreturnnilend
localitem=items.client.container[id]
ifitemthen
returnitem
else
ifnotitems.client.requested[id] then
client.nutClient:sendRPC('getItem', bitser.dumps{id=id})
items.client.requested[id] =true
end
returnnil
end
end
-- todo: refactor
functionitems.client.mousepressed(x, y, btn, isTouch, presses)
localmx, my=window2game(x, y)
mx, my=lume.round(mx), lume.round(my)
localwmx, wmy=camera:screen2world(mx, my)
-- hud
localbag=playerController.player.inventory
localpanel=hud.inventoryPanel
localpmx=mx-lume.round(panel.x)
localpmy=my-lume.round(panel.y)
forslotId, slotinipairs(hud.inventorySlots) do
ifpmx>=slot.xandpmx<=slot.x+slot.w
andpmy>=slot.yandpmy<=slot.y+slot.handpanel.openthen
uiMouseDown=true
ifbag.items[slotId] then
-- use item
ifbtn==1and (love.keyboard.isScancodeDown('lshift') orpresses>1) then
client.useItem{
bagId=bag.id,
slotId=slotId
}
end
-- move items
ifbtn==1then
localheldItem=playerController.heldItem
heldItem.itemId=bag.items[slotId]
heldItem.bagId=bag.id
heldItem.slotId=slotId
heldItem.offset.x=slot.x-pmx
heldItem.offset.y=slot.y-pmy
elseifbtn==2then
localclosestBag=playerController.closestBag
localcqb=playerController.closestQuestBlock
ifclosestBag.idandclosestBag.openthen
localbagTo=client.currentState.lootBags[closestBag.id]
forbagSlotId, _inipairs(lootBagSlots) do
ifbagTo.items[bagSlotId] ==nilthen
client.moveItem{
from= {
bagId=bag.id,
slotId=slotId
},
to= {
bagId=bagTo.id,
slotId=bagSlotId
}
}
break
end
end
elseifcqb.idandcqb.openthen
localqb=client.currentState.entities[cqb.id]
ifqbthen
localitem=items.client.getItem(bag.items[slotId])
ifnotitemthenbreakend
forquestSlotId, questItemIdinpairs(quests.current.cost) do
localquestItem=items.client.getItem(questItemId)
ifnotquestItemthenbreakend
ifquests.current.heldItems[questSlotId] ==nil
anditem.imageId==questItem.imageIdthen
quests.current.heldItems[questSlotId] =bag.items[slotId]
client.setInventorySlot{
slotId=slotId,
itemId=nil
}
break
end
end
end
end
end
end
end
end
-- lootBags
localclosestBag=playerController.closestBag
ifclosestBag.idandclosestBag.openthen
localbag=client.currentState.lootBags[closestBag.id]
localimg=gfx.ui.bag
localbmx=wmx- (lume.round(bag.x) -lume.round(img:getWidth()/2))
localbmy=wmy- (lume.round(bag.y) -img:getHeight() -20)
forslotId, slotinipairs(lootBagSlots) do
ifbmx>=slot.xandbmx<=slot.x+slot.w
andbmy>=slot.yandbmy<=slot.y+slot.hthen
uiMouseDown=true
ifbag.items[slotId] then
ifbtn==1then
localheldItem=playerController.heldItem
heldItem.itemId=bag.items[slotId]
heldItem.bagId=bag.id
heldItem.slotId=slotId
heldItem.offset.x=slot.x-bmx
heldItem.offset.y=slot.y-bmy
elseifbtn==2then
localp=playerController.player
localitem=items.client.getItem(bag.items[slotId])
ifnotitemthenbreakend
forinvSlotId, _inipairs(hud.inventorySlots) do
localslotType=slot2type[invSlotId]
ifp.inventory.items[invSlotId] ==nil
and (slotType==nilorslotType==item.type) then
client.moveItem{
from= {
bagId=bag.id,
slotId=slotId
},
to= {
bagId=p.inventory.id,
slotId=invSlotId
}
}
break
end
end
end
end
break
end
end
end
-- quest
localcqb=playerController.closestQuestBlock
ifcqb.idandcqb.openthen
localqb=client.currentState.entities[cqb.id]
ifqbthen
localimg=gfx.ui.quest
localbmx=wmx- (lume.round(qb.x+8) -lume.round(img:getWidth()/2))
localbmy=wmy- (lume.round(qb.y+8) -img:getHeight() -20)
forslotId, slotinipairs(questBlockSlots) do
localexists=true
localitem=items.client.getItem(quests.current.heldItems[slotId])
ifnotitemthen
exists=false
ifslotId<=4then
item=items.client.getItem(quests.current.cost[slotId])
else
item=items.client.getItem(quests.current.reward[slotId-4])
end
end
ifslotId>=5then
localallExist=true
fori, iteminipairs(quests.current.cost) do
ifnotquests.current.heldItems[i] then
allExist=false
break
end
end
exists=allExist
end
ifbmx>=slot.xandbmx<=slot.x+slot.w
andbmy>=slot.yandbmy<=slot.y+slot.hthen
uiMouseDown=true
ifitemandexiststhen
ifbtn==1then
localheldItem=playerController.heldItem
heldItem.itemId=item.id
heldItem.bagId='quest'
heldItem.slotId=slotId
heldItem.offset.x=slot.x-bmx
heldItem.offset.y=slot.y-bmy
elseifbtn==2then
localbag=playerController.player.inventory
forinvSlotId, _inipairs(hud.inventorySlots) do
localslotType=slot2type[invSlotId]
ifbag.items[invSlotId] ==nil
and (slotType==nilorslotType==item.type) then
client.setInventorySlot{
slotId=invSlotId,
itemId=item.id
}
ifslot.type=='cost' then
quests.current.heldItems[slotId] =nil
elseifslot.type=='reward' then
quests.refresh()
end
break
end
end
end
end
end
end
end
end
end
functionitems.client.mousereleased(x, y, btn, isTouch, presses)
localmx, my=window2game(x, y)
mx, my=lume.round(mx), lume.round(my)
localwmx, wmy=camera:screen2world(mx, my)
ifbtn==1then
-- hud
localheldItem=playerController.heldItem
localitemIsHeld=true
ifheldItem.bagIdthen
localbagFrom=client.currentState.lootBags[heldItem.bagId]
ifheldItem.bagId=='inventory' then
bagFrom=playerController.player.inventory
end
localbagTo=playerController.player.inventory
localpanel=hud.inventoryPanel
localpmx=mx-lume.round(panel.x)
localpmy=my-lume.round(panel.y)
ifpmx>0andpmx<panel.img:getWidth()
andpmy>0andpmy<panel.img:getHeight() then
forslotId, slotinipairs(hud.inventorySlots) do
ifpmx>=slot.xandpmx<=slot.x+slot.w
andpmy>=slot.yandpmy<=slot.y+slot.hthen
localitem=items.client.getItem(heldItem.itemId)
ifnotitemthenbreakend
localslotType=slot2type[slotId]
if (slotType==nilorslotType==item.type) then
ifheldItem.bagId=='quest' then
client.setInventorySlot{
slotId=slotId,
itemId=heldItem.itemId
}
ifheldItem.slotId<=4then
quests.current.heldItems[heldItem.slotId] =nil
elseifheldItem.slotId==5then
quests.refresh()
end
itemIsHeld=false
break
end
client.moveItem{
from= {
bagId=bagFrom.id,
slotId=heldItem.slotId
},
to= {
bagId=bagTo.id,
slotId=slotId
}
}
itemIsHeld=false
-- move clientside before response (will be corrected/affirmed)
localtemp=bagTo.items[slotId]
bagTo.items[slotId] =bagFrom.items[heldItem.slotId]
bagFrom.items[heldItem.slotId] =temp
break
end
end
end
-- move to open slot if dropped in inventory panel
ifitemIsHeldthen
forinvSlotId, _inipairs(hud.inventorySlots) do
localitem=items.client.getItem(heldItem.itemId)
ifnotitemthenbreakend
localslotType=slot2type[invSlotId]
ifbagTo.items[invSlotId] ==nil
and (slotType==nilorslotType==item.type) then
ifheldItem.bagId=='quest' then
client.setInventorySlot{
slotId=invSlotId,
itemId=heldItem.itemId
}
ifheldItem.slotId<=4then
quests.current.heldItems[heldItem.slotId] =nil
elseifheldItem.slotId==5then
quests.refresh()
end
itemIsHeld=false
break
end
client.moveItem{
from= {
bagId=bagFrom.id,
slotId=heldItem.slotId
},
to= {
bagId=bagTo.id,
slotId=invSlotId
}
}
itemIsHeld=false
break
end
end
end
end
end
-- lootBags
localclosestBag=playerController.closestBag
localheldItem=playerController.heldItem
ifclosestBag.idandclosestBag.openandheldItem.bagIdthen
localbagFrom=client.currentState.lootBags[heldItem.bagId]
ifheldItem.bagId=='inventory' then
bagFrom=playerController.player.inventory
end
localbagTo=client.currentState.lootBags[closestBag.id]
localimg=gfx.ui.bag
localbmx=wmx- (lume.round(bagTo.x) -lume.round(img:getWidth()/2))
localbmy=wmy- (lume.round(bagTo.y) -img:getHeight() -20)
forslotId, slotinipairs(lootBagSlots) do
ifbmx>=slot.xandbmx<=slot.x+slot.w
andbmy>=slot.yandbmy<=slot.y+slot.hthen
ifheldItem.bagId=='quest' then
break
end
client.moveItem{
from= {
bagId=bagFrom.id,
slotId=heldItem.slotId
},
to= {
bagId=bagTo.id,
slotId=slotId
}
}
itemIsHeld=false
-- move clientside before response (will be corrected/affirmed)
localtemp=bagTo.items[slotId]
bagTo.items[slotId] =bagFrom.items[heldItem.slotId]
bagFrom.items[heldItem.slotId] =temp
break
end
end
end
-- quest
localcqb=playerController.closestQuestBlock
ifcqb.idandcqb.openandheldItem.bagId=='inventory' then
localqb=client.currentState.entities[cqb.id]
ifqbthen
localp=playerController.player
localimg=gfx.ui.quest
localbmx=wmx- (lume.round(qb.x+8) -lume.round(img:getWidth()/2))
localbmy=wmy- (lume.round(qb.y+8) -img:getHeight() -20)
forslotId=1, 4do
localslot=questBlockSlots[slotId]
ifbmx>=slot.xandbmx<=slot.x+slot.w
andbmy>=slot.yandbmy<=slot.y+slot.hthen
localitem=items.client.getItem(heldItem.itemId)
ifnotitemthenbreakend
localquestItemId=quests.current.cost[slotId]
localquestItem=items.client.getItem(questItemId)
ifnotquestItemthenbreakend
ifquests.current.heldItems[slotId] ==nil
anditem.imageId==questItem.imageIdthen
quests.current.heldItems[slotId] =p.inventory.items[heldItem.slotId]
itemIsHeld=false
client.setInventorySlot{
slotId=heldItem.slotId,
itemId=nil
}
break
end
end
end
end
end
ifheldItem.bagId=='inventory' anditemIsHeldthen
client.dropItem{
slotId=heldItem.slotId
}
itemIsHeld=false
end
end
end