import java.util.*; /** * @author Nicklas Hjalmarsson * @version 1.0 * * Datatype for a dragon */ public class Dragon{ static int DRAGPICS = 5; String name; short Strength; short Health; short Speed; short Perception; short Wisdom; short Age; short Owner; short Stealth; //0 Snabbast möjligt 100 ligger under en buske och gömmer sig short Courage; //100 slåss till döden 0 bättre fly short Weariness; //Vid 0 helt pigg vid 100 dödstrött String Mission = ""; String MissionGoal = ""; boolean fake = false ; //true if the dragon cannot rise its stat may happen if it is a skeletdragon an Illusion or something like that short X_position; short Y_position; short X_destination; short Y_destination; byte[] Looks = {1,2,3,4}; // [0] = image range 0-4 // [1] = Spell effects 1 Gaias private static String[] dragonNames = {"Smaug","Appetizer", "Sunblock", "Arrow", "Bandit", "Meemer", "Ori", "Razz", "Kari", "Eurak","Moonbeam","Star","Loner", "Pally", "Geezer","Tiamat","Glaurung","Ebenezer", "Tekla","Avram","Tarnak","Obelia","Korbik","Cutter","Skywise","Redlance","Goldskin", "Ringun","Orvar","Krii","Belly","Gorbag","Blauman","Kruul","Eagleye","Hawk","Owl"}; private static int dragonNameCtr = -1; /** * Default constructor */ public Dragon(){ this.name = getNewName(); Strength = 20; Health = 100; Speed = 25; Perception = 20; Wisdom = 20; Age = 0; Stealth = 0; Weariness = 0; Courage = 50; Looks[0] = (byte)Dice.rand(DRAGPICS-1); Owner = -1; } /** * This is the constructor you should use */ Dragon(String name,Area a){ this(); this.name = name; dragonNameCtr--; X_position = a.x; Y_position = a.y; a.addDragon(name); } /** * This is another constructor you should use */ Dragon(Area a){ this(); X_position = a.x; Y_position = a.y; //så att de stannar kvar :) X_destination = a.x; Y_destination = a.y; a.addDragon(name); } /** * Constructor to make a dragon from a form * do not use for creating new dragons */ public Dragon(String str){ StringTokenizer tok = new StringTokenizer(str,"|"); // System.out.println("Tokenize to "+tok.countTokens()); name = tok.nextToken(); Strength = (short)Integer.parseInt(tok.nextToken()); Health = (short)Integer.parseInt(tok.nextToken()); Speed = (short)Integer.parseInt(tok.nextToken()); Perception = (short)Integer.parseInt(tok.nextToken()); Wisdom = (short)Integer.parseInt(tok.nextToken()); Age = (short)Integer.parseInt(tok.nextToken()); Owner = (short)Integer.parseInt(tok.nextToken()); Stealth = (short)Integer.parseInt(tok.nextToken()); Courage = (short)Integer.parseInt(tok.nextToken()); Weariness = (short)Integer.parseInt(tok.nextToken()); Mission = tok.nextToken(); MissionGoal = tok.nextToken(); fake = Boolean.getBoolean(tok.nextToken()); X_position = (short)Integer.parseInt(tok.nextToken()); Y_position = (short)Integer.parseInt(tok.nextToken()); X_destination = (short)Integer.parseInt(tok.nextToken()); Y_destination = (short)Integer.parseInt(tok.nextToken()); int i = 0; while(tok.hasMoreTokens()){ Looks[i] = (byte)Integer.parseInt(tok.nextToken()); i++; } if (Mission.equals("null")) Mission = ""; if (MissionGoal.equals("null")) MissionGoal = ""; } public Area getArea(Area[][] Map){ return Map[X_position][Y_position]; } public Area getDestination(Area[][] Map){ return Map[X_destination][Y_destination]; } public int movement(){ return (int)((Speed/7)*(1-(float)Stealth/100)*(1-(float)Weariness/100)); } public int attack(){ return (int)(2*Strength+Courage*(1-(float)Weariness/100)); } public int defence(){ return (int)(Speed+((100-Courage)/2)*(1-(float)Weariness/100)); } /** * @returns true if the Dragon does not dare to stay and fight */ public boolean flee(Dragon d){ // System.out.println(name+" farlig:"+(d.Strength - Strength +50)+ // " Modig:"+(int)(Courage*(0.7 + (float)Health/150))); return (d.Strength - Strength +50) > (int)(Courage*(0.7 + (float)Health/150)); } /** * @returns true if the Dragon does not dare to stay and fight against the city */ public boolean flee(City c){ return (c.attack()/2 - Strength +50) > (int)(Courage*(0.7 + (float)Health/150)); } /** * Use when a Dragon flees fom a battle to set his new Mission and destination */ public void flee(Fod game){ City c = (City)game.cities.get(game.players[Owner].homeCity); if(c != null){ Area a = (c.getArea(game.Map)); Mission = "GOTO"; MissionGoal = c.Name; setDestination(a); }else{ Area a = game.Map[Dice.rand(game.world.X_SIZE-1)][Dice.rand(game.world.Y_SIZE-1)]; Mission = "GOTO"; MissionGoal = a.getTerrain(); setDestination(a); } } public void setDestination(Area a){ X_destination = a.x; Y_destination = a.y; } /** * use to correct eventual malformed values */ public void incStr(int x){ Strength += (short)x; if(Strength < 0) Strength = 0; if(Strength > 100) Strength = 100; } public void incSpd(int x){ Speed += (short)x; if(Speed < 0) Speed = 0; if(Speed > 100) Speed = 100; } public void incWis(int x){ Wisdom += x; if(Wisdom < 0) Wisdom = 0; if(Wisdom > 100) Wisdom = 100; } public void incPcp(int x){ Perception += (short)x; if(Perception < 0) Perception = 0; if(Perception > 100) Perception = 100; } public void incWea(int x){ if(!fake){ Weariness += (short)x; if(Weariness < 0) Weariness = 0; if(Weariness > 100) Weariness = 100; } } public void tuneValues(){ if(Health < 0) Health = 0; if(Health > 100) Health = 100; if(Weariness < 0) Weariness = 0; if(Weariness > 100) Weariness = 100; if(Stealth < 0) Stealth = 0; if(Stealth > 100) Stealth = 100; if(Courage < 0) Courage = 0; if(Courage > 100) Courage = 100; } /** * Use to get a form to pass through sockets from a dragon */ public String Toform(){ String looks= ""; for(int i =0;i