-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCard.lua
329 lines (298 loc) · 12.6 KB
/
Card.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
Card = Class{__includes = BaseState}
function Card:init(card,team,number,column,graphics,imagesInfo,imagesIndexes,evolutionSpriteBatch,evolutionMaxSpriteBatch)
self.team = team
self.number = number
self.stats = Characters[card[1]]
self.level = card[2] or 1
self.evolution = card[3] or 0
if self.evolution == 4 then
self.evolutionMaxSprite = evolutionMaxSpriteBatch:add(0,0,0,0,0)
elseif self.evolution > 0 then
self.evolution1Sprite = evolutionSpriteBatch:add(0,0,0,0,0)
if self.evolution > 1 then
self.evolution2Sprite = evolutionSpriteBatch:add(0,0,0,0,0)
if self.evolution > 2 then
self.evolution3Sprite = evolutionSpriteBatch:add(0,0,0,0,0)
end
end
end
if self.stats['filename'] then
self.imagePath = 'Characters/' .. self.stats['filename'] .. '/' .. self.stats['filename']
else
self.imagePath = 'Characters/' .. card[1] .. '/' .. card[1]
end
if imagesIndexes[self.imagePath] then
self.image = true
else
if imagesInfo[self.imagePath] then
table.insert(imagesInfo[self.imagePath][1],self)
else
imagesInfo[self.imagePath] = {{self}, false}
end
self.image = false
end
self.width,self.height = 115,173
self.health = 1000
self.modifier = ((self.level + (60 - self.level) / 1.7) / 60) * (1 - ((4 - self.evolution) * 0.1))
self.meleeOffense = self.stats['meleeOffense'] * (self.modifier)
if self.stats['rangedOffense'] then
self.rangedOffense = self.stats['rangedOffense'] * (self.modifier)
else
self.rangedOffense = self.meleeOffense
end
self.defense = self.stats['defense'] * (self.modifier)
self.evade = self.stats['evade']
self.range = self.stats['range']
self.meleeOffenseStat = (self.meleeOffense/800)^4/2
self.rangedOffenseStat = (self.rangedOffense/800)^4
if self.stats['projectile1'] then
self.projectileManager = ProjectileManager(self.stats, self.team, self.width, self.height, graphics, imagesInfo)
if self.projectileManager.projectileCount > 1 then
self.rangedOffense = self.rangedOffense / (self.projectileManager.projectileCount^0.2)
end
end
if self.stats['weapon1'] then
self.weaponManager = WeaponManager(self.stats, self.team, self.width, self.height, self, graphics, imagesInfo)
end
self.meleeProjectile = self.weaponManager == nil and (self.stats['projectile1'] == 'Lightning' or self.stats['projectile1'] == 'Force Blast' or self.stats['projectile1'] == 'Force Drain')
self.possibleTargets = {}
self.targets = {}
if self.team == 1 then
self.enemyDeck = P2deck
else
self.enemyDeck = P1deck
end
self.column = column
self.row = self.number % 6
if self.team == 1 then
self.targetX = ((VIRTUALWIDTH / 12) * self.column) + 22 - 20
else
self.targetX = ((VIRTUALWIDTH / 12) * self.column) + 22 + 20
end
self.x = self.targetX
self.targetY = ((VIRTUALHEIGHT / 6) * self.row + (self.height / 48))
self.y = self.targetY
self.dodge = 0
end
function Card:deleteEvolutionSprites(evolutionSpriteBatch,evolutionMaxSpriteBatch)
if self.evolutionMaxSprite then
evolutionMaxSpriteBatch:set(self.evolutionMaxSprite,0,0,0,0,0) --Unfortunately closest thing to deleting Sprites there is
elseif self.evolution > 0 and evolutionImage then
evolutionSpriteBatch:set(self.evolution1Sprite,0,0,0,0,0)
if self.evolution > 1 then
evolutionSpriteBatch:set(self.evolution2Sprite,0,0,0,0,0)
if self.evolution > 2 then
evolutionSpriteBatch:set(self.evolution3Sprite,0,0,0,0,0)
end
end
end
end
function Card:deleteGraphics(graphics)
if self.weaponManager then
self.weaponManager:hideWeapons(graphics)
end
if self.projectileManager then
self.projectileManager:hideProjectiles(graphics)
end
end
function Card:distance(target)
return math.abs(self.column - target.column) + math.abs(self.row - target.row)
end
function Card:move()
if self.team == 1 then
self.targetX = self.targetX + 160
self.column = self.column + 1
else
self.targetX = self.targetX - 160
self.column = self.column - 1
end
end
function Card:move2()
if self.team == 1 then
if P1deck[self.number-6] == nil and self.number - 6 >= 0 then
P1deck[self.number-6] = P1deck[self.number]
P1deck[self.number] = nil
self.number = self.number - 6
self.targetX = self.targetX + 160
self.column = self.column + 1
end
elseif P2deck[self.number-6] == nil and self.number - 6 >= 0 then
P2deck[self.number-6] = P2deck[self.number]
P2deck[self.number] = nil
self.number = self.number - 6
self.targetX = self.targetX - 160
self.column = self.column - 1
end
end
function Card:aim()
self.meleeAttack = false
if (self.column == 5 or self.column == 6) and self.enemyDeck[self.number] ~= nil and (self.enemyDeck[self.number].column == 6 or self.enemyDeck[self.number].column == 5) then
self.targets[1] = self.number
if self.meleeProjectile then
self.projectileManager:fireall(self,self.enemyDeck[self.targets[1]])
end
self.meleeAttack = true
elseif (self.column == 5 or self.column == 6) and (self.range == 1 or self.meleeOffenseStat > self.rangedOffenseStat) and (self.enemyDeck[self.number-1] ~= nil and (self.enemyDeck[self.number-1].column == 6 or self.enemyDeck[self.number-1].column == 5) or (self.enemyDeck[self.number+1] ~= nil and (self.enemyDeck[self.number+1].column == 6 or self.enemyDeck[self.number+1].column == 6))) then
if self.enemyDeck[self.number-1] ~= nil then
self.targets[1] = self.number-1
elseif self.enemyDeck[self.number+1] ~= nil then
self.targets[1] = self.number+1
end
if self.meleeProjectile then
self.projectileManager:fireall(self,self.enemyDeck[self.targets[1]])
end
self.meleeAttack = true
elseif self.range > 1 then
self.targets[1] = self:target(self.range)
if self.projectileManager then
if self.targets[1] then
self.projectileManager.projectiles[1]:fire(self,self.enemyDeck[self.targets[1]])
end
for k, pair in pairs(self.projectileManager.projectiles) do
if k > 1 then
self.targets[k] = self:target(pair.range)
if self.targets[k] then
pair:fire(self,self.enemyDeck[self.targets[k]])
end
end
end
end
end
if self.weaponManager then
self.weaponManager:visibility(self.meleeAttack)
end
end
function Card:target(range)
for k, pair in pairs(self.possibleTargets) do
self.possibleTargets[k] = nil
end
self.totalProbability = 0
for k, pair in pairs(self.enemyDeck) do
distance = self:distance(pair)
if distance <= range then
self.possibleTargets[k] = self.totalProbability + range/distance
self.totalProbability = self.totalProbability + range/distance
end
end
if self.totalProbability > 0 then
self.rangedAttackRoll = love.math.random() * self.totalProbability
for k, pair in pairs(self.possibleTargets) do
if self.rangedAttackRoll < self.possibleTargets[k] then
return k
end
end
end
end
function Card:attack(graphics)
for k, pair in pairs(self.targets) do
self:attack2(pair)
self.targets[k] = nil
end
if self.projectileManager then self.projectileManager:hideProjectiles(graphics) end
end
function Card:attack2(target)
self.attackRoll = love.math.random(100) / 100
self.enemyDeck[target].attacksTaken = self.enemyDeck[target].attacksTaken + 1
if self.attackRoll > self.enemyDeck[target].evade then
if self.meleeAttack then self.offense = self.meleeOffense else self.offense = self.rangedOffense end
if self.offense < self.enemyDeck[target].defense then
self.damage = 0
else
self.damage = ((self.offense - self.enemyDeck[target].defense) / 800) ^ 3
end
self.defenceDown = (self.offense / 100) * (self.offense / self.enemyDeck[target].defense) ^ 3
if self.projectileManager and self.projectileManager.projectileCount > 1 then
self.defenceDown = self.defenceDown / (self.projectileManager.projectileCount^0.2)
end
if target ~= self.number and self.range == 1 then
self.damage = self.damage / 2
self.defenceDown = self.defenceDown / 2
end
self.enemyDeck[target].health = self.enemyDeck[target].health - (self.damage + 1)
if self.enemyDeck[target].defense > 0 then
self.enemyDeck[target].defense = self.enemyDeck[target].defense - self.defenceDown
if self.enemyDeck[target].defense < 0 then self.enemyDeck[target].defense = 0 end
else
self.enemyDeck[target].defense = 0
end
else
self.enemyDeck[target].dodge = self.enemyDeck[target].dodge + 1
end
end
function Card:update(dt)
if self.projectileManager then
self.projectileManager:update(dt)
end
if self.targetX > self.x then
self.x = self.x + dt * 500
if self.x > self.targetX then self.x = self.targetX end
elseif self.targetX < self.x then
self.x = self.x - dt * 500
if self.x < self.targetX then self.x = self.targetX end
end
if self.targetY > self.y then
self.y = self.y + dt * 500
if self.y > self.targetY then self.y = self.targetY end
elseif self.targetY < self.y then
self.y = self.y - dt * 500
if self.y < self.targetY then self.y = self.targetY end
end
end
function Card:renderHealthBar1()
if self.health < 1000 then
love.graphics.rectangle('fill',self.x-2,self.y-4,self.width+4,10,5,5)
end
end
function Card:renderHealthBar2()
if self.health < 1000 then
if self.dodge == 0 then
love.graphics.setColor(1,0.82,0)
else
self.colour = self.dodge / self.attacksTaken
self.colour = self.colour + (1-self.colour) / 2 --Proportionally increases brightness of self.colour so it's between 0.5 and 1 rather than 0 and 1
love.graphics.setColor(self.colour,self.colour,self.colour)
end
love.graphics.rectangle('fill',self.x-2,self.y-4,(self.width+4)/(1000/self.health),10,5,5)
end
end
function Card:render(evolutionSpriteBatch,evolutionMaxSpriteBatch,imagesIndexes,imagesArrayLayer)
if self.image then --In theory this could cause cards not to render but it'd have to be on a very very slow system for this to happen
love.graphics.drawLayer(imagesArrayLayer,imagesIndexes[self.imagePath],self.x,self.y,0,1)
if self.evolution == 4 then
evolutionMaxSpriteBatch:set(self.evolutionMaxSprite,self.x+self.width-evolutionMaxImage:getWidth()-4,self.y+4)
elseif self.evolution > 0 then
evolutionSpriteBatch:set(self.evolution1Sprite,self.x+115-5,self.y+3,math.rad(90))
if self.evolution > 1 then
evolutionSpriteBatch:set(self.evolution2Sprite,self.x+115-6-evolutionImage:getHeight(),self.y+3,math.rad(90))
if self.evolution > 2 then
evolutionSpriteBatch:set(self.evolution3Sprite,self.x+115-7-evolutionImage:getHeight()*2,self.y+3,math.rad(90))
end
end
end
end
-- if self.number == 15 and self.team == 2 then
-- if self.possibleTargets ~= nil then
-- y = 100
-- for k, pair in pairs(self.possibleTargets) do
-- y = y + 100
-- love.graphics.print(tostring(k) .. ' ' .. tostring(pair),0,y)
-- love.graphics.print(self.rangedAttackRoll,800,100)
-- love.graphics.print(self.totalProbability,0,100)
-- end
-- end
-- love.graphics.print(self.stats,0,0)
-- end
-- if self.number == 2 and if self.team == 2 then
-- love.graphics.print(self.attacksTaken)
-- love.graphics.print(self.defense,0,100)
-- end
-- love.graphics.print(self.damage)
-- love.graphics.print(self.defenceDown,0,100)
-- love.graphics.print(self.defense,0,200)
-- elseif self.team == 2 then
-- love.graphics.print(self.damage,1600)
-- love.graphics.print(self.defenceDown,1600,100)
-- love.graphics.print(self.defense,1600,200)
-- end
-- end
end