-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlootBag.lua
89 lines (74 loc) · 1.92 KB
/
lootBag.lua
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
lootBag = {
server = {},
client = {}
}
local defaults = {server={}, client={}}
for _, sc in ipairs{'server', 'client'} do
for k, v in pairs{x=0, y=0, type='lootBag'} do
defaults[sc][k] = function() return v end
end
defaults[sc].id = function() return lume.uuid() end
defaults[sc].items = function() return {} end
end
defaults.server.realm = function() return serverRealm end
defaults.client.realm = function() return clientRealm end
lootBagSlots = {}
for j=1, 2 do
for i=1, 4 do
table.insert(lootBagSlots, {
x = 7 + (i-1)*18,
y = 22 + (j-1)*18,
w = 15,
h = 15
})
end
end
function lootBag.server:new(o)
o = o or {}
for k, v in pairs(defaults.server) do
if o[k] == nil then o[k] = v() end
end
setmetatable(o, self)
self.__index = self
return o
end
function lootBag.server:spawn()
self.spawnTime = gameTime
self.realm.lootBags[self.id] = self
server.added.lootBags[self.id] = self:serialize()
return self
end
function lootBag.server:serialize()
-- todo: realm id
return {
id = self.id,
x = self.x, y = self.y,
type = self.type,
items = self.items,
life = self.life,
spawnTime = self.spawnTime
}
end
function lootBag.server:destroy()
self.realm.lootBags[self.id] = nil
server.currentState.lootBags[self.id] = nil
server.removed.lootBags[self.id] = self.id
end
function lootBag.client:new(o)
o = o or {}
for k, v in pairs(defaults.client) do
if o[k] == nil then o[k] = v() end
end
setmetatable(o, self)
self.__index = self
return o
end
function lootBag.client:spawn()
self.realm.lootBags[self.id] = self
client.currentState.lootBags[self.id] = self
return self
end
function lootBag.client:destroy()
self.realm.lootBags[self.id] = nil
client.currentState.lootBags[self.id] = nil
end