forked from Farbod678/kdm-tts
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Armor.ttslua
66 lines (52 loc) · 1.98 KB
/
Armor.ttslua
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
local Check = require("Kdm/Util/Check")
local Expansion = require("Kdm/Expansion")
---------------------------------------------------------------------------------------------------
local Armor = {}
Armor.__index = Armor
---------------------------------------------------------------------------------------------------
function Armor.Init(saveState)
Armor.armor = {}
for _, expansion in ipairs(Expansion.All()) do
for name, stats in pairs(expansion.armorStats or {}) do
if Armor.armor[name] then
assert(false, string.format("Armor %s was already registered by expansion %s", name, Armor.armor[name].expansion))
end
Armor.armor[name] = Armor.Create(name, expansion.name, stats)
end
end
end
---------------------------------------------------------------------------------------------------
function Armor.Get(armor)
return Armor.armor[armor]
end
---------------------------------------------------------------------------------------------------
function Armor.Create(name, expansion, stats)
assert(Check.Str(name))
assert(Check.Str(expansion))
assert(Check.Num(stats.head))
assert(Check.Num(stats.arms))
assert(Check.Num(stats.body))
assert(Check.Num(stats.waist))
assert(Check.Num(stats.legs))
local armor = {
name = name,
expansion = expansion,
head = stats.head,
arms = stats.arms,
body = stats.body,
waist = stats.waist,
legs = stats.legs,
modifier = stats.modifier,
}
setmetatable(armor, Armor)
return armor
end
---------------------------------------------------------------------------------------------------
function Armor:__tostring()
return string.format("%s (%d/%d/%d/%d/%d)", self.name, self.head, self.arms, self.body, self.waist, self.legs)
end
---------------------------------------------------------------------------------------------------
return {
Init = Armor.Init,
Get = Armor.Get,
}