1 import java.awt.*;
2 import javax.swing.*;
3 import java.applet.*;
4 import java.awt.image.*;
5 import java.awt.geom.*;
6 import java.net.*;
7 import java.util.*;
8
17 public abstract class Monster extends MapObject
18 {
19
23 public static final int ELECTRIC = 0;
24
27 public static final int EARTH = 1;
28
31 public static final int FIRE = 2;
32
35 public static final int WATER = 3;
36
39 public static final int GAS = 4;
40
41
44 public static final int MAXLEVEL = 100;
45
48 public static final int MAXATTACKS = 4;
49
50
53 protected int hp;
57 protected int defp;
61 protected int attp;
65 protected int exp;
69 protected int maxHP;
73 protected int maxDef;
77 protected int maxAtt;
81 protected int maxExp;
85 protected int level;
89 protected int maxLevel;
93 protected int kind;
97 protected Vector attacks;
101 protected String name;
102
105 protected boolean battle;
106
109 static MapObject mp;
110
111
116 public abstract void addAttack(String attack);
117
122 public abstract String getA1();
123
128 public abstract String getA2();
129
134 public abstract String getA3();
135
140 public abstract String getA4();
141
146 public abstract String getA5();
147
152 public abstract String getA6();
153
159 public abstract boolean substituteAttack(Attack removed, Attack added);
160
165 public void setHP(int nhp)
166 {
167 if(nhp < 0)
168 hp = 0;
169 else if(nhp <= maxHP)
170 hp = nhp;
171 else
172 hp = maxHP;
173 }
174
179 public int getHP() { return hp; }
180
185 protected void setMaxHP(int nmhp)
186 {
187 if(nmhp > maxHP && level <= MAXLEVEL)
188 maxHP = nmhp;
189 }
190
195 public int getMaxHP() { return maxHP; }
196
201 public void setDefense(int ndp)
202 {
203 if(ndp <= 0)
204 return;
205 if(ndp <= maxDef)
206 defp = ndp;
207 else
208 defp = maxDef;
209 }
210
215 public int getDefense() { return defp; }
216
221 protected void setMaxDefense(int nmdp)
222 {
223 if(nmdp > maxDef && level <= MAXLEVEL)
224 maxDef = nmdp;
225 }
226
231 public int getMaxDefense() { return maxDef; }
232
237 public void setAttack(int nap)
238 {
239 if(nap <= 0)
240 return;
241 if(nap <= maxAtt)
242 attp = nap;
243 else
244 attp = maxAtt;
245 }
246
251 public int getAttack() { return attp; }
252
257 protected void setMaxAttack(int nmap)
258 {
259 if(nmap > maxAtt && level <= MAXLEVEL)
260 maxAtt = nmap;
261 }
262
267 public int getMaxAttack() { return maxAtt; }
268
274 protected boolean setExperience(int nep) throws AttacksFullException
275 {
276 if(nep > exp && nep <= maxExp)
277 {
278 exp = nep;
279 return false;
280 }
281 else if(nep > maxExp && level <= MAXLEVEL)
282 {
283 levelUp();
284 return true;
285 }
286 return false;
287 }
288
293 public int getExperience() { return exp; }
294
295
300 protected void setMaxExperience(int nmep)
301 {
302 if(nmep > maxExp && level <= MAXLEVEL)
303 maxExp = nmep;
304 }
305
310 public int getMaxExperience() { return maxExp; }
311
316 public int getLevel() { return level; }
317
322 public int getKind() { return kind; }
323
328 public void setLevel(int level) {
330 if(level <= MAXLEVEL)
331 this.level = level;
332 }
333
338 public int getMaxLevel() { return maxLevel; }
339
342 public int getNumberOfAttacks() { return attacks.size(); }
343
348 protected void levelUp() throws AttacksFullException
349 {
350 if((level == MAXLEVEL))
351 return;
352 level++;
353
354 int maxh = 0, maxa = 0, maxd = 0;
355
356 setMaxExperience(10*level);
357
358 switch(getKind())
359 {
360 case ELECTRIC:
361 {
362 maxa = maxAtt + 10;
363 maxd = maxDef + 7;
364 maxh = maxHP + 6;
365 break;
366 }
367 case EARTH:
368 {
369 maxa = maxAtt + 7;
370 maxd = maxDef + 6;
371 maxh = maxHP + 10;
372 break;
373 }
374 case FIRE:
375 {
376 maxa = maxAtt + 6;
377 maxd = maxDef + 7;
378 maxh = maxHP + 10;
379 break;
380 }
381 case WATER:
382 {
383 maxa = maxAtt + 7;
384 maxd = maxDef + 10;
385 maxh = maxHP + 6;
386 break;
387 }
388 case GAS:
389 {
390 maxa = maxAtt + 6;
391 maxd = maxDef + 10;
392 maxh = maxHP + 7;
393 break;
394 }
395 }
396 setMaxAttack(maxa);
397 setMaxDefense(maxd);
398 setMaxHP(maxh);
399 setMaxExperience(maxExp+10);
400
401 setAttack((attp - maxAtt) + maxa);
403 setDefense((defp - maxDef) + maxd);
404 setHP((hp - maxHP) + maxh);
405 }
406
407
413 public boolean finishFight(Monster m) throws AttacksFullException
414 {
415 int nmep = (2 * m.getLevel()) - this.level;
416 boolean b = false;
417 if(level < 10)
418 {
419 if(nmep > 0)
420 {
421 if(setExperience(exp+nmep))
422 b = true;
423 }
424 else
425 {
426 if(setExperience(exp + 2))
427 b = true;
428 }
429 }
430 else if(level < 50)
431 {
432 if(nmep > 15)
433 {
434 if(setExperience(exp+nmep))
435 b = true;
436 }
437 else
438 {
439 if(setExperience(exp + 15))
440 b = true;
441 }
442 }
443 else
444 {
445 if(nmep > 40)
446 {
447 if(setExperience(exp+nmep))
448 b = true;
449 }
450 else
451 {
452 if(setExperience(exp + 40))
453 b = true;
454 }
455 }
456 return b;
457 }
458
463 public void setName(String name)
464 {
465 if(name != null)
466 this.name = name;
467 }
468
473 public String getName() { return name; }
474
479 public String[] getAttacks()
480 {
481 String[] s = new String[MAXATTACKS];
482 for(int i = 0; i < attacks.size(); i++)
483 {
484 s[i] = ((Attack)attacks.get(i)).getName();
485 }
486 return s;
487 }
488
494 public Attack getAttack(int pos)
495 {
496 if(pos >= 0 && pos < attacks.size())
497 {
498 return (Attack)attacks.get(pos);
499 }
500 return null;
501 }
502
508 public boolean equals(Object o)
509 {
510 if(o instanceof Monster)
511 return equals((Monster)o);
512 return false;
513 }
514
520 public boolean equals(Monster m)
521 {
522 if(m.getName().equals(name) && m.getHP() == hp && m.getDefense() == defp && m.getAttack() == attp && m.getExperience() == exp && m.getLevel() == level
523 && m.getKind() == kind && m.getMaxHP() == maxHP && m.getMaxDefense() == maxDef && m.getMaxAttack() == maxAtt && m.getMaxExperience() == maxExp
524 && m.getMaxLevel() == maxLevel)
525 return true;
526 return false;
527 }
528
533 public boolean isBattling() { return battle; }
534
537 public void startBattle() { battle = true; }
538
541 public void stopBattle() { battle = false; }
542
547 public void setBehind(MapObject m)
548 {
549 if(m == null)
550 return;
551 else if(m.canBeEntered())
552 this.mp = m;
553 }
554
559 public void paint(Graphics g)
560 {
561 if(mp != null)
562 mp.paint(g);
563 }
564 }