-
Notifications
You must be signed in to change notification settings - Fork 0
/
pawn.lua
95 lines (83 loc) · 1.64 KB
/
pawn.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
90
91
92
93
94
95
local pawn = { last_id = 0 }
pawn.__index = pawn
function pawn:new(o)
o = o or {}
setmetatable(o, self)
return o
end
function pawn:move(x, y, walk)
--- if walk then XXX cause stuff like OAs
if map:in_bounds(x, y) and (not map[x][y].pawn) then
if map:in_bounds(self.x, self.y) then
map[self.x][self.y].pawn = nil
end
self.x = x
self.y = y
map[x][y].pawn = self.id
self.on_map = true
redraw = true
end
end
function pawn:remove_from_map()
if map:in_bounds(self.x, self.y) then
map[self.x][self.y].pawn = nil
end
self.x = nil
self.y = nil
self.on_map = false
redraw = true
end
function pawn:rotate(df)
self.facing = self.facing + df
if self.facing > 6 then
self.facing = ((self.facing - 1) % 6) + 1 -- ugggh why lua why
end
redraw = true
end
function pawn:get_sprite()
if self.hidden then
return nil
else
if self.facing <= 3 then
f = self.facing
sx = 1
else
f = 7 - self.facing
sx = -1
end
if map.waterline - map:elev(self.x, self.y) >= 2 then
return {self.sprite .. "_swim", sx}
else
return {self.sprite .. "_" .. f, sx}
end
end
end
function pawn:apply_status(s, dur)
self.status[s] = dur + cturn
end
local status_complete_effect =
{
}
function pawn:end_status(s, cancelled) -- if cancelled == true, skip the end effect
if not cancelled then
if status_complete_effect[s] then
status_complete_effect[s](self)
end
end
self.status[s] = nil
end
function pawn:check_status(s)
for i,v in pairs(self.status) do
if i == s then
if v < cturn then
-- duration ran out
self:end_status(s, false)
return false
else
return true
end
end
end
return false
end
return pawn