-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabilities.lua
236 lines (210 loc) · 7.73 KB
/
abilities.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
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
local field = require "field"
local rules = require "rules"
local football = require "football"
local movement = require "movement"
local nui = require "nui"
local preview = require "preview"
local abilities = {}
abilities.load = function()
end
abilities.update_item = function(knight, dt)
if movement.update_object(knight.item, dt) then
if not knight.item.active then
knight.item.visible = false
end
knight.item.flourish = false
end
end
abilities.draw_item = function(knight)
if knight.item.visible and abilities.adjacent(knight.tile_x, knight.tile_y, knight.item.tile_x, knight.item.tile_y) then
local quad = art.direction(knight.tile_x, knight.tile_y, knight.item.tile_x, knight.item.tile_y)
art.draw_quad(knight.item.type, art.quad.item[quad], knight.item.x, knight.item.y)
art.draw_quad(knight.item.type.."_overlay", art.quad.item[quad], knight.item.x, knight.item.y, 1, 1, 1, "color", palette[rules.get_color(knight.team)])
end
end
abilities.update_hud = function(knight_id, knight, action, dt)
if action == "position" then
nui.edit.element("", "move", "content", {img = art.img.ability_icons, quad = art.quad.ability_icon[5]})
else
nui.edit.element("", "move", "content", {img = art.img.ability_icons, quad = art.quad.ability_icon[1]})
end
if knight.carrier then
nui.edit.element("", "ability", "content", {img = art.img.ability_icons, quad = art.quad.ability_icon[6]})
elseif abilities.type(knight_id, knight) == "throw" then
nui.edit.element("", "ability", "content", {img = art.img.ability_icons, quad = art.quad.ability_icon[4]})
elseif knight.team == rules.get_offense() then
nui.edit.element("", "ability", "content", {img = art.img.ability_icons, quad = art.quad.ability_icon[2]})
else
nui.edit.element("", "ability", "content", {img = art.img.ability_icons, quad = art.quad.ability_icon[3]})
end
local ball = football.get_ball()
if action == "position" or knight_id == ball.carrier then
nui.edit.element("", "move", "type", 1)
nui.edit.element("", "ability", "type", 2)
elseif action == "ability" then
nui.edit.element("", "ability", "type", 1)
else
nui.edit.element("", "move", "type", 1)
end
end
abilities.use = function(knight_id, knight, x, y)
if abilities.valid(knight.tile_x, knight.tile_y, x, y) then
local type = abilities.type(knight_id, knight)
if type then -- ball carrier cannot use an ability
return abilities.start[type](knight, x, y)
else
return false
end
else
abilities.cancel(knight_id, knight)
return false
end
end
abilities.cancel = function(knight_id, knight)
local type = abilities.type(knight_id, knight)
if type then
abilities.reset[type](knight, 0)
end
end
abilities.type = function(knight_id, knight)
local qb = rules.get_qb()
local offense = rules.get_offense()
if qb == knight_id and not football.thrown() then
return "throw"
elseif not knight.carrier then
return "item"
end
end
abilities.start = {}
abilities.start.throw = function(knight, x, y)
if not football.thrown() then
football.throw(knight.x, knight.y, x, y)
return true
end
return false
end
abilities.preview_throw = function(knight, x, y)
if abilities.valid(knight.tile_x, knight.tile_y, x, y) then
local path = movement.get_path(knight.tile_x, knight.tile_y, x, y)
preview.add_path("preview", path, knight.tile_x, knight.tile_y, "green")
preview.add_icon("preview", 6, path[#path].x, path[#path].y, "green")
else
preview.add_icon("preview", 6, x, y, "red")
end
end
abilities.preview_item = function(knight_id, knight, knights, x, y)
local icon = 4
if knight.team == rules.get_offense() then
icon = 5
end
if abilities.valid(knight.tile_x, knight.tile_y, x, y) and abilities.adjacent(knight.tile_x, knight.tile_y, x, y) and not abilities.overlap(knight_id, knight, knights, x, y) then
preview.add_icon("preview", icon, x, y, "green")
else
preview.add_icon("preview", icon, x, y, "red")
preview.set_border(knight.tile_x, knight.tile_y, 1.5, abilities.adjacent)
end
end
abilities.overlap = function(knight_id, knight, knights, x, y)
if abilities.type(knight_id, knight) == "item" then
for i, v in ipairs(knights) do -- make sure teammate hasn't put an item in the tile
if v.item.active and v.team == knight.team then
if v.item.tile_x == x and v.item.tile_y == y then
return false
end
end
end
end
end
abilities.start.item = function(knight, x, y)
if abilities.adjacent(knight.tile_x, knight.tile_y, x, y) then
knight.item.new_x = x
knight.item.new_y = y
knight.item.active = true
if knight.team == rules.get_offense() then
knight.item.type = "shield"
else
knight.item.type = "sword"
end
return true
else
return false
end
end
abilities.set_preview = function(knight_id, knight, team, resolve)
if knight.item.active and team == knight.team and not resolve then
preview.remove_path("preview") -- remove precedence
preview.remove_path(knight_id)
if knight.team == rules.get_offense() then
preview.add_icon(knight_id, 5, knight.item.new_x, knight.item.new_y)
else
preview.add_icon(knight_id, 4, knight.item.new_x, knight.item.new_y)
end
end
end
abilities.set = function(knight, step_time)
if knight.item.active then
knight.item.visible = true
knight.item.tile_x = knight.item.new_x
knight.item.tile_y = knight.item.new_y
knight.item.x = knight.tile_x
knight.item.y = knight.tile_y
movement.lerp(knight.item, knight.tile_x, knight.tile_y, knight.item.tile_x, knight.item.tile_y, step_time/2)
end
end
abilities.reset = {}
abilities.reset.throw = function()
football.reset()
end
abilities.reset.item = function(knight, step_time)
knight.item.active = false
if knight.item.visible then
if knight.item.flourish then
abilities.sheath(knight)
else
movement.lerp(knight.item, knight.item.tile_x, knight.item.tile_y, knight.tile_x, knight.tile_y, step_time/2)
end
end
end
abilities.valid = function(x1, y1, x2, y2)
return field.in_bounds(x2, y2) and not (x1 == x2 and y1 == y2)
end
abilities.adjacent = function(x1, y1, x2, y2)
local x_dif = x2-x1
local y_dif = y2-y1
return (x_dif >= -1 and x_dif <= 1 and y_dif >= -1 and y_dif <= 1 and not (x1 == x2 and y1 == y2))
end
abilities.collide = function(i, v, knights, step_time)
if v.team == rules.get_offense() and v.item.active then
for j, w in ipairs(knights) do
if w.item.active and v.team ~= w.team then -- items can collide
if v.item.new_x == w.item.new_x and v.item.new_y == w.item.new_y then -- items occupy same tile, cancel out
abilities.reset.item(v, step_time)
abilities.reset.item(w, step_time)
movement.bounce(v.item, v.tile_x, v.tile_y, v.item.new_x, v.item.new_y, step_time, .75)
movement.bounce(w.item, w.tile_x, w.tile_y, w.item.new_x, w.item.new_y, step_time, .75)
return true
end
end
end
end
return false
end
abilities.stab = function(knight, tackler, tile_x, tile_y, step_time)
abilities.start.item(tackler, tile_x, tile_y)
abilities.set(tackler, step_time)
movement.bounce(tackler.item, tackler.tile_x, tackler.tile_y, tackler.item.tile_x, tackler.item.tile_y, step_time, .75)
end
abilities.flourish = function(knight, step_time, sheath)
local x_dif = knight.item.tile_x - knight.tile_x
local y_dif = knight.item.tile_y - knight.tile_y
movement.bounce(knight.item, knight.item.tile_x, knight.item.tile_y, knight.item.tile_x+x_dif, knight.item.tile_y+y_dif, step_time/2, .25)
knight.item.flourish = true
if sheath then
abilities.sheath(knight)
end
end
abilities.sheath = function(knight)
knight.item.goal_x = knight.tile_x
knight.item.goal_y = knight.tile_y
end
return abilities