1 | package main;
|
---|
2 |
|
---|
3 | import java.awt.*;
|
---|
4 | import java.awt.image.BufferedImage;
|
---|
5 | import java.io.*;
|
---|
6 | import java.util.*;
|
---|
7 | import javax.imageio.ImageIO;
|
---|
8 |
|
---|
9 | import gamegui.Animation;
|
---|
10 |
|
---|
11 | public class Creature implements Comparable<Creature> {
|
---|
12 |
|
---|
13 | public int passive;
|
---|
14 | public int thorns;
|
---|
15 | public int confused;
|
---|
16 | public int sand;
|
---|
17 |
|
---|
18 | protected String name;
|
---|
19 | protected CreatureType type;
|
---|
20 | protected Model model;
|
---|
21 | protected int level;
|
---|
22 | protected Point loc;
|
---|
23 | protected int[] attributes;
|
---|
24 | protected int hitpoints;
|
---|
25 | protected int manapoints;
|
---|
26 | protected int maxHitpoints;
|
---|
27 | protected int maxManapoints;
|
---|
28 | protected int experience;
|
---|
29 | protected EquippedWeapon weapon;
|
---|
30 | protected EquippedWeapon spell;
|
---|
31 |
|
---|
32 | private Point target;
|
---|
33 | private Creature enemyTarget;
|
---|
34 | private int speed;
|
---|
35 | private long lastMoved;
|
---|
36 | private long lastAttacked;
|
---|
37 | private LinkedList<ItemDrop> drops;
|
---|
38 | private LinkedList<EffectTimer> effectTimers;
|
---|
39 | private boolean disabled;
|
---|
40 | private SpawnPoint spawnPoint;
|
---|
41 | private boolean dying;
|
---|
42 |
|
---|
43 | public Creature() {
|
---|
44 | this.name = "";
|
---|
45 | this.loc = new Point(0, 0);
|
---|
46 | this.target = this.loc;
|
---|
47 | this.attributes = new int[4];
|
---|
48 | this.experience = 0;
|
---|
49 | this.weapon = null;
|
---|
50 | this.spell = null;
|
---|
51 | this.drops = new LinkedList<ItemDrop>();
|
---|
52 | this.effectTimers = new LinkedList<EffectTimer>();
|
---|
53 | this.disabled = false;
|
---|
54 | this.spawnPoint = null;
|
---|
55 | this.passive = 0;
|
---|
56 | this.thorns = 0;
|
---|
57 | this.confused = 0;
|
---|
58 | this.sand = 0;
|
---|
59 | this.dying = false;
|
---|
60 | }
|
---|
61 |
|
---|
62 | public Creature(String name, CreatureType type) {
|
---|
63 | this.name = name;
|
---|
64 | this.type = type;
|
---|
65 | this.loc = new Point(0, 0);
|
---|
66 | this.target = this.loc;
|
---|
67 | this.attributes = new int[4];
|
---|
68 | this.experience = 0;
|
---|
69 | this.weapon = null;
|
---|
70 | this.spell = null;
|
---|
71 | this.drops = new LinkedList<ItemDrop>();
|
---|
72 | this.effectTimers = new LinkedList<EffectTimer>();
|
---|
73 | this.disabled = false;
|
---|
74 | this.spawnPoint = null;
|
---|
75 | this.passive = 0;
|
---|
76 | this.thorns = 0;
|
---|
77 | this.confused = 0;
|
---|
78 | this.sand = 0;
|
---|
79 | this.dying = false;
|
---|
80 | }
|
---|
81 |
|
---|
82 | public Creature(Creature cr) {
|
---|
83 | this.name = cr.name;
|
---|
84 | this.type = cr.type;
|
---|
85 | this.model = new Model(cr.model);
|
---|
86 | this.level = cr.level;
|
---|
87 | this.loc = new Point(cr.loc);
|
---|
88 | this.target = cr.target;
|
---|
89 | this.speed = cr.speed;
|
---|
90 | this.lastMoved = cr.lastMoved;
|
---|
91 | this.lastAttacked = cr.lastAttacked;
|
---|
92 | this.attributes = (int[])cr.attributes.clone();
|
---|
93 | this.hitpoints = cr.hitpoints;
|
---|
94 | this.manapoints = cr.manapoints;
|
---|
95 | this.maxHitpoints = cr.maxHitpoints;
|
---|
96 | this.maxManapoints = cr.maxManapoints;
|
---|
97 | this.experience = cr.experience;
|
---|
98 | this.weapon = cr.weapon.copy((Point)null);
|
---|
99 | if (cr.spell != null)
|
---|
100 | this.spell = cr.spell.copy((Point)null);
|
---|
101 | this.drops = cr.drops;
|
---|
102 | this.effectTimers = new LinkedList<EffectTimer>(cr.effectTimers);
|
---|
103 | this.disabled = cr.disabled;
|
---|
104 | this.spawnPoint = null;
|
---|
105 | this.passive = cr.passive;
|
---|
106 | this.thorns = cr.thorns;
|
---|
107 | this.confused = cr.confused;
|
---|
108 | this.sand = cr.sand;
|
---|
109 | this.dying = cr.dying;
|
---|
110 | }
|
---|
111 |
|
---|
112 | public Creature copy() {
|
---|
113 | return new Creature(this);
|
---|
114 | }
|
---|
115 |
|
---|
116 | public void setDying(boolean dying) {
|
---|
117 | if (!this.model.hasDeath())
|
---|
118 | return;
|
---|
119 | if (dying) {
|
---|
120 | this.model.setAction(Action.Dying);
|
---|
121 | } else {
|
---|
122 | this.model.getAnimation(Direction.West, Action.Dying).reset();
|
---|
123 | }
|
---|
124 | this.dying = dying;
|
---|
125 | }
|
---|
126 |
|
---|
127 | public boolean isDying() {
|
---|
128 | return this.dying;
|
---|
129 | }
|
---|
130 |
|
---|
131 | public void checkTimedEffects() {
|
---|
132 | Iterator<EffectTimer> iter = this.effectTimers.iterator();
|
---|
133 | while (iter.hasNext()) {
|
---|
134 | EffectTimer cur = iter.next();
|
---|
135 | if (cur.expired()) {
|
---|
136 | cur.getEffect().cancelEffect(this);
|
---|
137 | iter.remove();
|
---|
138 | }
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 | public void addEffect(TimedEffect e) {
|
---|
143 | this.effectTimers.add(new EffectTimer(e, e.getDuration()));
|
---|
144 | }
|
---|
145 |
|
---|
146 | public Point move() {
|
---|
147 | Point newLoc;
|
---|
148 | double dist = (this.speed * (System.currentTimeMillis() - this.lastMoved) / 1000L);
|
---|
149 | if (this.lastMoved == 0L) {
|
---|
150 | dist = 0.0D;
|
---|
151 | }
|
---|
152 | if (this.enemyTarget != null) {
|
---|
153 | this.target = this.enemyTarget.loc;
|
---|
154 | }
|
---|
155 | this.lastMoved = System.currentTimeMillis();
|
---|
156 | if (Point.dist(this.loc, this.target) <= dist) {
|
---|
157 | newLoc = this.target;
|
---|
158 | if (this.model.getAction() != Action.Attacking) {
|
---|
159 | this.model.setAction(Action.Standing);
|
---|
160 | }
|
---|
161 | } else {
|
---|
162 | if (this.model.getAction() != Action.Attacking) {
|
---|
163 | this.model.setAction(Action.Walking);
|
---|
164 | }
|
---|
165 | int xDif = (int)(Point.xDif(this.loc, this.target) * dist / Point.dist(this.loc, this.target));
|
---|
166 | int yDif = (int)(Point.yDif(this.loc, this.target) * dist / Point.dist(this.loc, this.target));
|
---|
167 | newLoc = new Point(this.loc.getX(), this.loc.getXMin() + xDif, this.loc.getY(), this.loc.getYMin() + yDif);
|
---|
168 | newLoc.setX(newLoc.getX() + newLoc.getXMin() / 100);
|
---|
169 | newLoc.setXMin(newLoc.getXMin() % 100);
|
---|
170 | newLoc.setY(newLoc.getY() + newLoc.getYMin() / 100);
|
---|
171 | newLoc.setYMin(newLoc.getYMin() % 100);
|
---|
172 | if (newLoc.getXMin() < 0) {
|
---|
173 | newLoc.setX(newLoc.getX() - 1);
|
---|
174 | newLoc.setXMin(newLoc.getXMin() + 100);
|
---|
175 | } else if (newLoc.getYMin() < 0) {
|
---|
176 | newLoc.setY(newLoc.getY() - 1);
|
---|
177 | newLoc.setYMin(newLoc.getYMin() + 100);
|
---|
178 | }
|
---|
179 | this.model.setDirection(calcDirection());
|
---|
180 | }
|
---|
181 | return newLoc;
|
---|
182 | }
|
---|
183 |
|
---|
184 | private Direction calcDirection() {
|
---|
185 | Direction dir;
|
---|
186 | int xDif2 = Point.xDif(this.loc, this.target);
|
---|
187 | int yDif2 = Point.yDif(this.target, this.loc);
|
---|
188 | double angle = 1.5707963267948966D;
|
---|
189 | if (xDif2 == 0) {
|
---|
190 | if (yDif2 != 0) {
|
---|
191 | angle *= Math.abs(yDif2 / yDif2);
|
---|
192 | }
|
---|
193 | } else {
|
---|
194 | angle = Math.atan(yDif2 / xDif2);
|
---|
195 | }
|
---|
196 | if (angle >= 0.7853981633974483D) {
|
---|
197 | dir = Direction.North;
|
---|
198 | } else if (-0.7853981633974483D <= angle && angle <= 0.7853981633974483D) {
|
---|
199 | dir = Direction.East;
|
---|
200 | } else {
|
---|
201 | dir = Direction.South;
|
---|
202 | }
|
---|
203 | if (xDif2 < 0)
|
---|
204 | switch (dir) {
|
---|
205 | case North:
|
---|
206 | dir = Direction.South;
|
---|
207 | break;
|
---|
208 | case South:
|
---|
209 | dir = Direction.North;
|
---|
210 | break;
|
---|
211 | case East:
|
---|
212 | dir = Direction.West;
|
---|
213 | break;
|
---|
214 | }
|
---|
215 | return dir;
|
---|
216 | }
|
---|
217 |
|
---|
218 | public Projectile attack(Creature enemy, AttackType attType) {
|
---|
219 | Weapon weap = selectWeapon(attType);
|
---|
220 | if (System.currentTimeMillis() - this.lastAttacked >= (weap.getAttackSpeed() * 100) && !this.disabled) {
|
---|
221 | this.lastAttacked = System.currentTimeMillis();
|
---|
222 | Point oldTarget = this.target;
|
---|
223 | this.target = enemy.getLoc();
|
---|
224 | this.model.setDirection(calcDirection());
|
---|
225 | this.target = oldTarget;
|
---|
226 | if (attType != AttackType.Spell) {
|
---|
227 | this.model.setAction(Action.Attacking);
|
---|
228 | this.model.getAnimation(this.model.getDirection(), this.model.getAction()).reset();
|
---|
229 | }
|
---|
230 | if (weap.getType() == ItemType.RangedWeapon || weap.getType() == ItemType.Spell) {
|
---|
231 | Point loc = new Point(this.loc);
|
---|
232 | loc.setY(loc.getY() - 55);
|
---|
233 | return weap.spawnProjectile(loc, enemy.getLoc());
|
---|
234 | }
|
---|
235 | weap.applyContactEffects(enemy);
|
---|
236 | }
|
---|
237 | return null;
|
---|
238 | }
|
---|
239 |
|
---|
240 | public Projectile attack(Point targ, AttackType attType) {
|
---|
241 | Weapon weap = selectWeapon(attType);
|
---|
242 | if ((System.currentTimeMillis() - this.lastAttacked) / 100L >= weap.getAttackSpeed() && !this.disabled) {
|
---|
243 | this.lastAttacked = System.currentTimeMillis();
|
---|
244 | Point oldTarget = this.target;
|
---|
245 | this.target = targ;
|
---|
246 | this.model.setDirection(calcDirection());
|
---|
247 | this.target = oldTarget;
|
---|
248 | if (attType != AttackType.Spell) {
|
---|
249 | this.model.setAction(Action.Attacking);
|
---|
250 | this.model.getAnimation(this.model.getDirection(), this.model.getAction()).reset();
|
---|
251 | }
|
---|
252 | if (weap.getType() == ItemType.RangedWeapon || weap.getType() == ItemType.Spell) {
|
---|
253 | Point loc = new Point(this.loc);
|
---|
254 | loc.setY(loc.getY() - 30);
|
---|
255 | return weap.spawnProjectile(loc, targ);
|
---|
256 | }
|
---|
257 | }
|
---|
258 | return null;
|
---|
259 | }
|
---|
260 |
|
---|
261 | private Weapon selectWeapon(AttackType attType) {
|
---|
262 | switch (attType) {
|
---|
263 | case Weapon:
|
---|
264 | return this.weapon;
|
---|
265 | case Spell:
|
---|
266 | return this.spell;
|
---|
267 | }
|
---|
268 | return this.weapon;
|
---|
269 | }
|
---|
270 |
|
---|
271 | public void addDrop(ItemDrop item) {
|
---|
272 | this.drops.add(item);
|
---|
273 | }
|
---|
274 |
|
---|
275 | public LinkedList<ItemDrop> getDrops() {
|
---|
276 | return this.drops;
|
---|
277 | }
|
---|
278 |
|
---|
279 | public LinkedList<Item> spawnDrops() {
|
---|
280 | LinkedList<Item> newDrops = new LinkedList<Item>();
|
---|
281 | Iterator<ItemDrop> iter = this.drops.iterator();
|
---|
282 | Random gen = new Random();
|
---|
283 | while (iter.hasNext()) {
|
---|
284 | ItemDrop cur = iter.next();
|
---|
285 | if (gen.nextDouble() <= cur.getDropChance()) {
|
---|
286 | newDrops.add(cur.getItem());
|
---|
287 | }
|
---|
288 | }
|
---|
289 | return newDrops;
|
---|
290 | }
|
---|
291 |
|
---|
292 | public void draw(Graphics g, int playerX, int playerY) {
|
---|
293 | if (this.passive > 0) {
|
---|
294 | g.drawImage(LostHavenRPG.passiveAura, 375 + this.loc.getX() - playerX, 300 - this.model.getHeight() + this.loc.getY() - playerY, null);
|
---|
295 | }
|
---|
296 | if (this.thorns > 0) {
|
---|
297 | g.drawImage(LostHavenRPG.thornsAura, 375 + this.loc.getX() - playerX, 300 - this.model.getHeight() + this.loc.getY() - playerY, null);
|
---|
298 | }
|
---|
299 | this.model.draw(g, 400 + this.loc.getX() - playerX, 300 + this.loc.getY() - playerY);
|
---|
300 | if (this.confused > 0) {
|
---|
301 | g.drawImage(LostHavenRPG.confuseAura, 375 + this.loc.getX() - playerX, 300 - this.model.getHeight() + this.loc.getY() - playerY, null);
|
---|
302 | }
|
---|
303 | if (this.sand > 0) {
|
---|
304 | g.drawImage(LostHavenRPG.sandAura, 375 + this.loc.getX() - playerX, 300 - this.model.getHeight() + this.loc.getY() - playerY, null);
|
---|
305 | }
|
---|
306 | g.setColor(Color.red);
|
---|
307 | g.fillRect(360 + this.loc.getX() - playerX, 290 - this.model.getHeight() + this.loc.getY() - playerY, 80 * this.hitpoints / this.maxHitpoints, 10);
|
---|
308 | g.setColor(Color.black);
|
---|
309 | Font font12 = new Font("Arial", 0, 12);
|
---|
310 | FontMetrics metrics = g.getFontMetrics(font12);
|
---|
311 | g.setFont(font12);
|
---|
312 | g.drawString(this.name, 400 + this.loc.getX() - playerX - metrics.stringWidth(this.name) / 2, 300 - this.model.getHeight() + this.loc.getY() - playerY);
|
---|
313 | }
|
---|
314 |
|
---|
315 | public void save(PrintWriter out) {
|
---|
316 | out.println(this.type);
|
---|
317 | if (this.spawnPoint == null) {
|
---|
318 | out.println(-1);
|
---|
319 | } else {
|
---|
320 | out.println(this.spawnPoint.idNum);
|
---|
321 | }
|
---|
322 | out.println(String.valueOf(this.loc.getX()) + "," + this.loc.getY());
|
---|
323 | out.println(this.model.getDirection());
|
---|
324 | out.println(this.model.getAction());
|
---|
325 | out.println(this.hitpoints);
|
---|
326 | out.println(this.manapoints);
|
---|
327 | out.println(this.passive);
|
---|
328 | out.println(this.thorns);
|
---|
329 | out.println(this.confused);
|
---|
330 | out.println(this.sand);
|
---|
331 | if (this.weapon == null) {
|
---|
332 | out.println("None");
|
---|
333 | } else {
|
---|
334 | out.println(this.weapon.getName());
|
---|
335 | }
|
---|
336 | }
|
---|
337 |
|
---|
338 | public static Creature loadTemplate(BufferedReader in) {
|
---|
339 | Creature cr = new Creature();
|
---|
340 | BufferedImage[] imgProj = new BufferedImage[8];
|
---|
341 | try {
|
---|
342 | cr.name = in.readLine();
|
---|
343 | cr.type = CreatureType.valueOf(cr.name);
|
---|
344 | if (cr.type == CreatureType.Player) {
|
---|
345 | cr = Player.loadTemplate(in);
|
---|
346 | }
|
---|
347 | cr.setSpeed(Integer.parseInt(in.readLine()));
|
---|
348 | cr.setAttribute(Attribute.Strength, Integer.parseInt(in.readLine()));
|
---|
349 | cr.setAttribute(Attribute.Dexterity, Integer.parseInt(in.readLine()));
|
---|
350 | cr.setAttribute(Attribute.Constitution, Integer.parseInt(in.readLine()));
|
---|
351 | cr.setAttribute(Attribute.Wisdom, Integer.parseInt(in.readLine()));
|
---|
352 | ItemType wType = ItemType.valueOf(in.readLine());
|
---|
353 | if (wType == ItemType.RangedWeapon) {
|
---|
354 | imgProj = LostHavenRPG.imgBow;
|
---|
355 | } else if (wType == ItemType.Spell) {
|
---|
356 | imgProj[0] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png"));
|
---|
357 | imgProj[1] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png"));
|
---|
358 | imgProj[2] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png"));
|
---|
359 | imgProj[3] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png"));
|
---|
360 | imgProj[4] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png"));
|
---|
361 | imgProj[5] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png"));
|
---|
362 | imgProj[6] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png"));
|
---|
363 | imgProj[7] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png"));
|
---|
364 | }
|
---|
365 | cr.model = cr.loadModel(cr.type.toString());
|
---|
366 | cr.setWeapon(new Weapon("None", wType, "Dagger.png", imgProj, 10, Integer.parseInt(in.readLine()), Integer.parseInt(in.readLine())));
|
---|
367 | cr.setExperience(Integer.parseInt(in.readLine()));
|
---|
368 | } catch (IOException ioe) {
|
---|
369 | ioe.printStackTrace();
|
---|
370 | }
|
---|
371 | return cr;
|
---|
372 | }
|
---|
373 |
|
---|
374 | public Model loadModel(String folder) {
|
---|
375 | boolean noAnims = false;
|
---|
376 | Animation anmStandN = new Animation("north", 0, 0, 40, 60, 300, true);
|
---|
377 | Animation anmStandS = new Animation("south", 0, 0, 40, 60, 300, true);
|
---|
378 | Animation anmStandE = new Animation("east", 0, 0, 40, 60, 300, true);
|
---|
379 | Animation anmStandW = new Animation("west", 0, 0, 40, 60, 300, true);
|
---|
380 | Animation anmWalkN = new Animation("north", 0, 0, 40, 60, 300, true);
|
---|
381 | Animation anmWalkS = new Animation("south", 0, 0, 40, 60, 300, true);
|
---|
382 | Animation anmWalkE = new Animation("east", 0, 0, 40, 60, 300, true);
|
---|
383 | Animation anmWalkW = new Animation("west", 0, 0, 40, 60, 300, true);
|
---|
384 | Animation anmAttackN = new Animation("north", 0, 0, 40, 60, 500, false);
|
---|
385 | Animation anmAttackS = new Animation("south", 0, 0, 40, 60, 500, false);
|
---|
386 | Animation anmAttackE = new Animation("east", 0, 0, 40, 60, 500, false);
|
---|
387 | Animation anmAttackW = new Animation("west", 0, 0, 40, 60, 500, false);
|
---|
388 | Animation anmDeath = new Animation("west", 0, 0, 40, 60, 1000, false);
|
---|
389 | BufferedImage walkN = null;
|
---|
390 | BufferedImage walkS = null;
|
---|
391 | BufferedImage walkE = null;
|
---|
392 | BufferedImage walkW = null;
|
---|
393 | boolean hasDeathAnim = (getClass().getResource("../images/" + folder + "/Death1.png") != null);
|
---|
394 | try {
|
---|
395 | if (getClass().getResource("../images/" + folder + "/WalkN.png") != null) {
|
---|
396 | walkN = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkN.png"));
|
---|
397 | anmWalkN.addFrame(walkN);
|
---|
398 | walkS = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkS.png"));
|
---|
399 | anmWalkS.addFrame(walkS);
|
---|
400 | walkE = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkE.png"));
|
---|
401 | anmWalkE.addFrame(walkE);
|
---|
402 | walkW = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkW.png"));
|
---|
403 | anmWalkW.addFrame(walkW);
|
---|
404 | } else if (getClass().getResource("../images/" + folder + "/WalkN1.png") != null) {
|
---|
405 | walkN = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkN1.png"));
|
---|
406 | anmWalkN.addFrame(walkN);
|
---|
407 | anmWalkN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkN2.png")));
|
---|
408 | walkS = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkS1.png"));
|
---|
409 | anmWalkS.addFrame(walkS);
|
---|
410 | anmWalkS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkS2.png")));
|
---|
411 | walkE = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkE1.png"));
|
---|
412 | anmWalkE.addFrame(walkE);
|
---|
413 | anmWalkE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkE2.png")));
|
---|
414 | walkW = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkW1.png"));
|
---|
415 | anmWalkW.addFrame(walkW);
|
---|
416 | anmWalkW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkW2.png")));
|
---|
417 | } else {
|
---|
418 | noAnims = true;
|
---|
419 | anmStandN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
|
---|
420 | anmStandS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
|
---|
421 | anmStandE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
|
---|
422 | anmStandW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
|
---|
423 | anmWalkN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
|
---|
424 | anmWalkN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
|
---|
425 | anmWalkS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
|
---|
426 | anmWalkS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
|
---|
427 | anmWalkE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
|
---|
428 | anmWalkE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
|
---|
429 | anmWalkW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
|
---|
430 | anmWalkW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
|
---|
431 | anmAttackN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
|
---|
432 | anmAttackS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
|
---|
433 | anmAttackE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
|
---|
434 | anmAttackW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png")));
|
---|
435 | }
|
---|
436 | if (!noAnims) {
|
---|
437 | BufferedImage standN, standS, standE, standW;
|
---|
438 | if (getClass().getResource("../images/" + folder + "/StandN.png") == null) {
|
---|
439 | standN = walkN;
|
---|
440 | standS = walkS;
|
---|
441 | standE = walkE;
|
---|
442 | standW = walkW;
|
---|
443 | } else {
|
---|
444 | standN = ImageIO.read(getClass().getResource("../images/" + folder + "/StandN.png"));
|
---|
445 | standS = ImageIO.read(getClass().getResource("../images/" + folder + "/StandS.png"));
|
---|
446 | standE = ImageIO.read(getClass().getResource("../images/" + folder + "/StandE.png"));
|
---|
447 | standW = ImageIO.read(getClass().getResource("../images/" + folder + "/StandW.png"));
|
---|
448 | anmWalkN = new Animation("north", 0, 0, 40, 60, 150, true);
|
---|
449 | anmWalkS = new Animation("south", 0, 0, 40, 60, 150, true);
|
---|
450 | anmWalkE = new Animation("east", 0, 0, 40, 60, 150, true);
|
---|
451 | anmWalkW = new Animation("west", 0, 0, 40, 60, 150, true);
|
---|
452 | anmWalkN.addFrame(walkN);
|
---|
453 | anmWalkN.addFrame(standN);
|
---|
454 | anmWalkN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkN2.png")));
|
---|
455 | anmWalkN.addFrame(standN);
|
---|
456 | anmWalkS.addFrame(walkS);
|
---|
457 | anmWalkS.addFrame(standS);
|
---|
458 | anmWalkS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkS2.png")));
|
---|
459 | anmWalkS.addFrame(standS);
|
---|
460 | anmWalkE.addFrame(walkE);
|
---|
461 | anmWalkE.addFrame(standE);
|
---|
462 | anmWalkE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkE2.png")));
|
---|
463 | anmWalkE.addFrame(standE);
|
---|
464 | anmWalkW.addFrame(walkW);
|
---|
465 | anmWalkW.addFrame(standW);
|
---|
466 | anmWalkW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkW2.png")));
|
---|
467 | anmWalkW.addFrame(standW);
|
---|
468 | }
|
---|
469 | anmStandN.addFrame(standN);
|
---|
470 | anmStandS.addFrame(standS);
|
---|
471 | anmStandE.addFrame(standE);
|
---|
472 | anmStandW.addFrame(standW);
|
---|
473 | if (getClass().getResource("../images/" + folder + "/AttackN.png") != null) {
|
---|
474 | anmAttackN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackN.png")));
|
---|
475 | anmAttackN.addFrame(standN);
|
---|
476 | anmAttackS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackS.png")));
|
---|
477 | anmAttackS.addFrame(standS);
|
---|
478 | anmAttackE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackE.png")));
|
---|
479 | anmAttackE.addFrame(standE);
|
---|
480 | anmAttackW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackW.png")));
|
---|
481 | anmAttackW.addFrame(standW);
|
---|
482 | } else if (getClass().getResource("../images/" + folder + "/AttackN1.png") != null) {
|
---|
483 | anmAttackN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackN1.png")));
|
---|
484 | anmAttackN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackN2.png")));
|
---|
485 | anmAttackS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackS1.png")));
|
---|
486 | anmAttackS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackS2.png")));
|
---|
487 | anmAttackE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackE1.png")));
|
---|
488 | anmAttackE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackE2.png")));
|
---|
489 | anmAttackW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackW1.png")));
|
---|
490 | anmAttackW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackW2.png")));
|
---|
491 | } else {
|
---|
492 | anmAttackN.addFrame(standN);
|
---|
493 | anmAttackS.addFrame(standS);
|
---|
494 | anmAttackE.addFrame(standE);
|
---|
495 | anmAttackW.addFrame(standW);
|
---|
496 | }
|
---|
497 | if (hasDeathAnim) {
|
---|
498 | anmDeath.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/Death1.png")));
|
---|
499 | anmDeath.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/Death2.png")));
|
---|
500 | }
|
---|
501 | }
|
---|
502 | } catch (IOException ioe) {
|
---|
503 | ioe.printStackTrace();
|
---|
504 | }
|
---|
505 | Model model = new Model(hasDeathAnim);
|
---|
506 | model.addAnimation(Direction.North, Action.Standing, anmStandN);
|
---|
507 | model.addAnimation(Direction.South, Action.Standing, anmStandS);
|
---|
508 | model.addAnimation(Direction.East, Action.Standing, anmStandE);
|
---|
509 | model.addAnimation(Direction.West, Action.Standing, anmStandW);
|
---|
510 | model.addAnimation(Direction.North, Action.Walking, anmWalkN);
|
---|
511 | model.addAnimation(Direction.South, Action.Walking, anmWalkS);
|
---|
512 | model.addAnimation(Direction.East, Action.Walking, anmWalkE);
|
---|
513 | model.addAnimation(Direction.West, Action.Walking, anmWalkW);
|
---|
514 | model.addAnimation(Direction.North, Action.Attacking, anmAttackN);
|
---|
515 | model.addAnimation(Direction.South, Action.Attacking, anmAttackS);
|
---|
516 | model.addAnimation(Direction.East, Action.Attacking, anmAttackE);
|
---|
517 | model.addAnimation(Direction.West, Action.Attacking, anmAttackW);
|
---|
518 | if (hasDeathAnim) {
|
---|
519 | model.addAnimation(Direction.West, Action.Dying, anmDeath);
|
---|
520 | }
|
---|
521 | return model;
|
---|
522 | }
|
---|
523 |
|
---|
524 | public void load(BufferedReader in) {
|
---|
525 | try {
|
---|
526 | this.spawnPoint = LostHavenRPG.getSpawnPoint(Integer.parseInt(in.readLine()));
|
---|
527 | if (this.spawnPoint != null) {
|
---|
528 | this.spawnPoint.numSpawns++;
|
---|
529 | }
|
---|
530 | String strLoc = in.readLine();
|
---|
531 | getLoc().setX(Integer.valueOf(strLoc.substring(0, strLoc.indexOf(","))).intValue());
|
---|
532 | getLoc().setY(Integer.valueOf(strLoc.substring(strLoc.indexOf(",") + 1)).intValue());
|
---|
533 | getModel().setDirection(Direction.valueOf(in.readLine()));
|
---|
534 | getModel().setAction(Action.valueOf(in.readLine()));
|
---|
535 | setHitpoints(Integer.valueOf(in.readLine()).intValue());
|
---|
536 | setManapoints(Integer.valueOf(in.readLine()).intValue());
|
---|
537 | this.passive = Integer.valueOf(in.readLine()).intValue();
|
---|
538 | this.thorns = Integer.valueOf(in.readLine()).intValue();
|
---|
539 | this.confused = Integer.valueOf(in.readLine()).intValue();
|
---|
540 | this.sand = Integer.valueOf(in.readLine()).intValue();
|
---|
541 | String strWeapon = in.readLine();
|
---|
542 | if (!strWeapon.equals("None")) {
|
---|
543 | setWeapon((Weapon)LostHavenRPG.items.get(strWeapon));
|
---|
544 | }
|
---|
545 | } catch (IOException ioe) {
|
---|
546 | ioe.printStackTrace();
|
---|
547 | }
|
---|
548 | }
|
---|
549 |
|
---|
550 | protected int attributeIndex(Attribute attribute) {
|
---|
551 | switch (attribute) {
|
---|
552 | case Strength:
|
---|
553 | return 0;
|
---|
554 | case Dexterity:
|
---|
555 | return 1;
|
---|
556 | case Constitution:
|
---|
557 | return 2;
|
---|
558 | case Wisdom:
|
---|
559 | return 3;
|
---|
560 | }
|
---|
561 | return -1;
|
---|
562 | }
|
---|
563 |
|
---|
564 | public int getAttribute(Attribute attribute) {
|
---|
565 | return this.attributes[attributeIndex(attribute)];
|
---|
566 | }
|
---|
567 |
|
---|
568 | public void setAttribute(Attribute attribute, int num) {
|
---|
569 | this.attributes[attributeIndex(attribute)] = num;
|
---|
570 | updateStats();
|
---|
571 | }
|
---|
572 |
|
---|
573 | private void updateStats() {
|
---|
574 | this.hitpoints = 2 * this.attributes[2];
|
---|
575 | this.maxHitpoints = 2 * this.attributes[2];
|
---|
576 | this.manapoints = 2 * this.attributes[3];
|
---|
577 | this.maxManapoints = 2 * this.attributes[3];
|
---|
578 | }
|
---|
579 |
|
---|
580 | public Creature getEnemyTarget() {
|
---|
581 | return this.enemyTarget;
|
---|
582 | }
|
---|
583 |
|
---|
584 | public int getExperience() {
|
---|
585 | return this.experience;
|
---|
586 | }
|
---|
587 |
|
---|
588 | public int getHitpoints() {
|
---|
589 | return this.hitpoints;
|
---|
590 | }
|
---|
591 |
|
---|
592 | public Model getModel() {
|
---|
593 | return this.model;
|
---|
594 | }
|
---|
595 |
|
---|
596 | public long getLastAttacked() {
|
---|
597 | return this.lastAttacked;
|
---|
598 | }
|
---|
599 |
|
---|
600 | public long getLastMoved() {
|
---|
601 | return this.lastMoved;
|
---|
602 | }
|
---|
603 |
|
---|
604 | public int getLevel() {
|
---|
605 | return this.level;
|
---|
606 | }
|
---|
607 |
|
---|
608 | public Point getLoc() {
|
---|
609 | return this.loc;
|
---|
610 | }
|
---|
611 |
|
---|
612 | public int getManapoints() {
|
---|
613 | return this.manapoints;
|
---|
614 | }
|
---|
615 |
|
---|
616 | public int getMaxHitpoints() {
|
---|
617 | return this.maxHitpoints;
|
---|
618 | }
|
---|
619 |
|
---|
620 | public int getMaxManapoints() {
|
---|
621 | return this.maxManapoints;
|
---|
622 | }
|
---|
623 |
|
---|
624 | public String getName() {
|
---|
625 | return this.name;
|
---|
626 | }
|
---|
627 |
|
---|
628 | public int getSpeed() {
|
---|
629 | return this.speed;
|
---|
630 | }
|
---|
631 |
|
---|
632 | public Point getTarget() {
|
---|
633 | return this.target;
|
---|
634 | }
|
---|
635 |
|
---|
636 | public CreatureType getType() {
|
---|
637 | return this.type;
|
---|
638 | }
|
---|
639 |
|
---|
640 | public EquippedWeapon getWeapon() {
|
---|
641 | return this.weapon;
|
---|
642 | }
|
---|
643 |
|
---|
644 | public EquippedWeapon getSpell() {
|
---|
645 | return this.spell;
|
---|
646 | }
|
---|
647 |
|
---|
648 | public void setEnemyTarget(Creature enemyTarget) {
|
---|
649 | this.enemyTarget = enemyTarget;
|
---|
650 | }
|
---|
651 |
|
---|
652 | public void setExperience(int experience) {
|
---|
653 | this.experience = experience;
|
---|
654 | }
|
---|
655 |
|
---|
656 | public void setHitpoints(int hitpoints) {
|
---|
657 | if (hitpoints > 0) {
|
---|
658 | this.hitpoints = hitpoints;
|
---|
659 | } else {
|
---|
660 | this.hitpoints = 0;
|
---|
661 | }
|
---|
662 | }
|
---|
663 |
|
---|
664 | public void setModel(Model model) {
|
---|
665 | this.model = model;
|
---|
666 | }
|
---|
667 |
|
---|
668 | public void setLastAttacked(long lastAttacked) {
|
---|
669 | this.lastAttacked = lastAttacked;
|
---|
670 | }
|
---|
671 |
|
---|
672 | public void setLastMoved(long lastMoved) {
|
---|
673 | this.lastMoved = lastMoved;
|
---|
674 | }
|
---|
675 |
|
---|
676 | public void setLevel(int level) {
|
---|
677 | this.level = level;
|
---|
678 | }
|
---|
679 |
|
---|
680 | public void setLoc(Point loc) {
|
---|
681 | this.loc = loc;
|
---|
682 | }
|
---|
683 |
|
---|
684 | public void setManapoints(int manapoints) {
|
---|
685 | if (manapoints > 0) {
|
---|
686 | this.manapoints = manapoints;
|
---|
687 | } else {
|
---|
688 | this.manapoints = 0;
|
---|
689 | }
|
---|
690 | }
|
---|
691 |
|
---|
692 | public void setMaxHitpoints(int maxHitpoints) {
|
---|
693 | this.maxHitpoints = maxHitpoints;
|
---|
694 | }
|
---|
695 |
|
---|
696 | public void setMaxManapoints(int maxManapoints) {
|
---|
697 | this.maxManapoints = maxManapoints;
|
---|
698 | }
|
---|
699 |
|
---|
700 | public void setName(String name) {
|
---|
701 | this.name = name;
|
---|
702 | }
|
---|
703 |
|
---|
704 | public void setSpeed(int speed) {
|
---|
705 | this.speed = speed;
|
---|
706 | }
|
---|
707 |
|
---|
708 | public void setTarget(Point target) {
|
---|
709 | this.target = target;
|
---|
710 | }
|
---|
711 |
|
---|
712 | public void setType(CreatureType type) {
|
---|
713 | this.type = type;
|
---|
714 | }
|
---|
715 |
|
---|
716 | public void setWeapon(Weapon weapon) {
|
---|
717 | this.weapon = new EquippedWeapon(this, weapon);
|
---|
718 | this.weapon.update();
|
---|
719 | (this.model.getAnimation(Direction.North, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.North, Action.Attacking)).frames.size());
|
---|
720 | (this.model.getAnimation(Direction.South, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.South, Action.Attacking)).frames.size());
|
---|
721 | (this.model.getAnimation(Direction.East, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.East, Action.Attacking)).frames.size());
|
---|
722 | (this.model.getAnimation(Direction.West, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.West, Action.Attacking)).frames.size());
|
---|
723 | }
|
---|
724 |
|
---|
725 | public void setSpell(Weapon spell) {
|
---|
726 | this.spell = new EquippedWeapon(this, spell);
|
---|
727 | this.spell.update();
|
---|
728 | }
|
---|
729 |
|
---|
730 | public SpawnPoint getSpawnPoint() {
|
---|
731 | return this.spawnPoint;
|
---|
732 | }
|
---|
733 |
|
---|
734 | public void setSpawnPoint(SpawnPoint sp) {
|
---|
735 | this.spawnPoint = sp;
|
---|
736 | }
|
---|
737 |
|
---|
738 | public boolean farFromSpawnPoint() {
|
---|
739 | if (this.spawnPoint == null)
|
---|
740 | return false;
|
---|
741 | return (Point.dist(this.spawnPoint.getLoc(), this.loc) > 800.0D);
|
---|
742 | }
|
---|
743 |
|
---|
744 | public boolean closerToSpawnPoint(Point newLoc) {
|
---|
745 | if (this.spawnPoint == null)
|
---|
746 | return false;
|
---|
747 | return (Point.dist(this.spawnPoint.getLoc(), this.loc) >= Point.dist(this.spawnPoint.getLoc(), newLoc));
|
---|
748 | }
|
---|
749 |
|
---|
750 | public void disable() {
|
---|
751 | this.disabled = true;
|
---|
752 | }
|
---|
753 |
|
---|
754 | public void enable() {
|
---|
755 | this.disabled = false;
|
---|
756 | }
|
---|
757 |
|
---|
758 | public String toString() {
|
---|
759 | return this.name;
|
---|
760 | }
|
---|
761 |
|
---|
762 | public int compareTo(Creature c) {
|
---|
763 | return 0;
|
---|
764 | }
|
---|
765 | }
|
---|