-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainer.lua
More file actions
120 lines (96 loc) · 3.15 KB
/
container.lua
File metadata and controls
120 lines (96 loc) · 3.15 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
----------------------------
----- Container class
----------------------------
require('scripts/globals/interaction/actions/event')
require('scripts/globals/interaction/actions/message')
require('scripts/globals/interaction/actions/sequence')
require('scripts/globals/interaction/actions/keyitem')
Container = {}
Container.__index = Container
Container.__eq = function(c1, c2)
return c1.id == c2.id
end
function Container:new(varPrefix)
if varPrefix == nil or string.len(varPrefix) < 5 then
printf("Invalid container with prefix: %s", varPrefix)
end
local obj = {}
setmetatable(obj, self)
obj.varPrefix = varPrefix
obj.id = varPrefix
return obj
end
function Container:cleanup(player)
player:clearVarsWithPrefix(self.varPrefix)
end
-----------------------------
-- Action helper functions
function Container:event(eventid, ...)
return Event:new(eventid, ...)
end
function Container:cutscene(eventid, ...)
return Event:new(eventid, ...):cutscene()
end
function Container:progressEvent(eventid, ...)
return Event:new(eventid, ...):progress()
end
function Container:priorityEvent(eventid, ...)
return Event:new(eventid, ...):progress()
end
function Container:progressCutscene(eventid, ...)
return Event:new(eventid, ...):cutscene():progress()
end
function Container:replaceEvent(eventid, ...)
return Event:new(eventid, ...):replaceDefault()
end
function Container:keyItem(keyItemId)
return KeyItemAction:new(keyItemId)
end
function Container:message(messageId, messageType, ...)
return Message:new(messageId, messageType, ...)
end
function Container:messageText(messageId, ...)
return Message:new(messageId, Message.Type.Text, ...)
end
function Container:messageSpecial(messageId, ...)
return Message:new(messageId, Message.Type.Special, ...)
end
function Container:replaceMessage(messageId, messageType, ...)
return Message:new(messageId, messageType, ...):replaceDefault()
end
function Container:sequence(...)
if type(...) == 'number' then
return Message:new(...)
else
return Sequence:new({...})
end
end
-----------------------------
-- Variable helper functions
function Container:getVar(player, name)
return player:getVar(self.varPrefix .. name)
end
function Container:setVar(player, name, value)
return player:setVar(self.varPrefix .. name, value)
end
function Container:isVarBitsSet(player, name, ...)
local sum = 0
for _, bitNum in ipairs({...}) do
sum = sum + bit.lshift(1, bitNum)
end
return bit.band(player:getVar(self.varPrefix .. name), sum) ~= 0
end
function Container:setVarBit(player, name, bitNum)
local currentValue = player:getVar(self.varPrefix .. name)
local bitValue = bit.lshift(1, bitNum)
if bit.band(currentValue, bitValue) == 0 then
return player:setVar(self.varPrefix .. name, currentValue + bitValue)
end
end
function Container:unsetVarBit(player, name, bitNum)
local currentValue = player:getVar(self.varPrefix .. name)
local bitValue = bit.lshift(1, bitNum)
if bit.band(currentValue, bitValue) ~= 0 then
return player:setVar(self.varPrefix .. name, currentValue - bitValue)
end
end