-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemy.java
More file actions
366 lines (322 loc) · 8.98 KB
/
Enemy.java
File metadata and controls
366 lines (322 loc) · 8.98 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
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
import java.util.ArrayList;
/**
* The parent class for the creatures that appear
*
* @author James Lu
* @version 0.02
*/
public abstract class Enemy extends Actor
{
protected Map world;
protected GreenfootImage bg;
protected HealthBar hpBar;
//movemnet variables
private int x, y;
private float realX, realY;
private float accX, accY;
private int stage;
//stats
protected String name;
protected String stringType;
protected int type;
protected int maxHp;
protected int currentHp;
protected int targetHp;
protected int armor;
protected float speed;
protected boolean flying;
protected boolean isBoss;
//debuffs
protected float slowX, slowY;
protected float armorRedu;
protected float dot;
protected ArrayList<Debuff> debuff;
protected DebuffVisu dv;
protected Enemy(int hp, int armor, float speed, boolean isBoss, boolean isFlying){
this();
this.maxHp = hp;
this.currentHp = maxHp;
this.targetHp = maxHp + maxHp/20;
this.armor = armor;
this.speed = speed;
this.isBoss = isBoss;
this.flying = isFlying;
hpBar = new HealthBar (maxHp, currentHp);
}
public Enemy(){
debuff = new ArrayList<Debuff>();
dv = new DebuffVisu(this);
}
protected void addedToWorld(World world){
this.world = (Map)world;
x = 0;
y = 0;
stage = 0;
realX = getX();
realY = getY();
accX = 0;
accY = 0;
world.addObject (hpBar, Math.round (realX), Math.round (realY));
world.addObject (dv, Math.round (realX), Math.round (realY));
}
public void act(){
chooseMovement();
debuffs();
}
/**
* Damages the mob <br>
* The first int is the damage, the second is the damage type <br>
* Returns the amount of damage after armor reduction
*/
public int damageCalc(int d, int dmgType){
float dmg;
if (dmgType == -1){
return d;
}else{
dmg = d * Data.elementDamage[type-1][dmgType-1];
}
float dmgRdu; //dmg reduction
float tempArmor = armor - armorRedu;
if (tempArmor >= 0){
//dmgRdu = ( (0.06f * armor) / (1 + 0.06f * armor)) * 100f; //dota armor values
dmgRdu = dmg / ((100f + tempArmor) / 100f);
if (dmgRdu > 1){
return Math.round (dmgRdu);
}
else{
return 1;
}
} else{
dmgRdu = (float) (1.0d - Math.pow (0.94d, -tempArmor)) * 100;
return Math.round (dmgRdu);
}
}
/**
* Damages the enemy <br>
* First int is the damage, second int is the damage type
*/
public void damage (int dmg, int dmgType){
int realDmg = damageCalc (dmg, dmgType);
currentHp -= realDmg;
hpBar.changeHp (currentHp);
if (currentHp <=0){
world.removeObject (hpBar);
world.removeObject (dv);
world.mobDie (this, false);
}
}
/**
* changes the targetting hp, NOT the actual hp <br>
* call after shooting a projectile at the enemy
*/
public void targetDmg (int dmg, int dmgType){
int realDmg = damageCalc (dmg, dmgType);
targetHp -= realDmg;
}
/**
* called when the weapon with a debuff hits the enemy
*/
public void addDebuff (int id, int debuffLv, int element, int orgDmg){
for (Debuff d : debuff){
if (d.getId() == id){
//increase duration
d.increasseDuration();
return;
}
}
debuff.add (new Debuff (id, debuffLv, this));
dv.setDebuff (id);
}
private void debuffs(){
slowX = 0;
slowY = 0;
dot = 0;
for (int i = 0; i < debuff.size(); i++){
Debuff d = debuff.get (i);
d.run();
//movement speed
slowX = accX * d.getSlow();
slowY = accY * d.getSlow();
//armor redu
armorRedu = d.getRedu();
//damage
damage (d.getDmg(), -1);
dot += d.getDOT();
}
}
/**
* called by the debuff class to remove itself once its run out
*/
public void removeDebuff(Debuff d){
debuff.remove (d);
dv.show (false);
}
private void chooseMovement(){
if (x == 49 && y == 25){
world.removeObject (hpBar);
world.removeObject (dv);
currentHp = 0;
world.mobDie (this, true);
}
else{
if (x == 10 && y == 12 && stage == 0){
stage = 1;
}
else if (x == 39 && y == 12 && stage == 1){
stage = 2;
}
movement();
}
}
/**
* the method for the movement of the mob
*/
private void movement(){
Tile tempTile = world.getTile (x, y);
int smoothMoveX, smoothMoveY;
int intX, intY;
if (realX-getX() > 1.5){
realX = getX();
}
if (realY-getY() > 1.5){
realY = getY();
}
accX = (tempTile.getMovementX(stage) * speed);
accY = (tempTile.getMovementY(stage) * speed);
//adds the acceleration to the real x and y
realX += (accX - slowX);
realY += (accY - slowY);
//smooth movment variables, for making it stay in the grid
smoothMoveX = Math.round((realX-12) % 20) - 10;
smoothMoveY = Math.round((realY-15) % 20) - 10;
//change the scale x and y values
if (speed > 3){
x = Math.round(((realX)-22) /20.0f);
y = Math.round(((realY)-25) /20.0f);
}
else{
if (accX > 0){
x = Math.round( ((realX)-32) /20.0f);
}
else if (accX < 0){
if ((realX-22) % 20 >= 10){
x = Math.round ( ((realX)-22) /20.0f);
}
else if ( (realX-22) % 20 < 10){
x = (int)( ((realX)-3) /20.0f);
}
}
if (accY > 0){
y = Math.round( ((realY)-35) /20.0f);
}
else if (accY < 0){
if ((realY-25) % 20 >= 10){
y = Math.round ( ((realY)-25) /20.0f);
}
else if ( (realY-25) % 20 < 10){
y = (int)( ((realY)-6) /20.0f);
}
}
}
//if x is not moving, change x to fit in the grid, same for y
if (accX == 0){
realX -= smoothMoveX;
}
else if (accY == 0){
realY -= smoothMoveY;
}
intX = Math.round (realX);
intY = Math.round (realY);
hpBar.changeLocation (intX, intY);
dv .changeLocation (intX, intY);
setLocation (intX, intY);
}
/**
* Returns the max hp of the enemy
*/
public int getMaxHp(){
return maxHp;
}
/**
* Returns the current hp of the enemy
*/
public int getHp(){
return currentHp;
}
/**
* call to check the targetting hp, to see if the enemy would of died already
*/
public int getTargetHp(){
return targetHp;
}
/**
* Returns the amount of armor the enemy has
*/
public int getArmor(){
return armor;
}
/**
* Returns the enemy's speed
*/
public float getSpeed(){
return speed;
}
/**
* Returns the type of the enemy
*/
public int getType(){
return type;
}
/**
* Returns the type of the enemy, in string
*/
public String getStringType(){
return stringType;
}
/**
* Returns the name of the enemy
*/
public String getName(){
return name;
}
/**
* Returns an arraylist of debuffs that the enemy currently has
*/
public ArrayList<Debuff> getDebuffs(){
return debuff;
}
/**
* Returns an arraylist of int ids of debuffs the enemy currently has
*/
public ArrayList<Integer> getIntDebuffs(){
ArrayList<Integer> al = new ArrayList<Integer> (debuff.size());
for (int i = 0; i < debuff.size(); i++){
al.add (debuff.get(i).getId());
}
return al;
}
/**
* Returns the amount of slow this enemy has
*/
public float getSlow(){
if (accX != 0){
return slowX;
}else{
return slowY;
}
}
/**
* Returns the armor reduction of the enmemy
*/
public float getRedu(){
return armorRedu;
}
/**
* Returns the DOT (Damage Over Time) of the enemy
*/
public float getDOT(){
return dot;
}
}