Coverage Summary for Class: Pirate (com.mygdx.game.Components)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| Pirate | 100% (1/1) | 90.3% (28/31) | 61.3% (65/106) |
1 package com.mygdx.game.Components; 2 3 import com.badlogic.gdx.math.Vector2; 4 import com.badlogic.gdx.utils.JsonValue; 5 import com.mygdx.game.Entitys.Ship; 6 import com.mygdx.game.Faction; 7 import com.mygdx.game.Managers.DifficultyManager; 8 import com.mygdx.game.Managers.GameManager; 9 import com.mygdx.utils.QueueFIFO; 10 11 /** 12 * Gives the concepts of health plunder, etc. Allows for firing of cannonballs, factions, death, targets 13 */ 14 public class Pirate extends Component { 15 private int factionId; 16 public static int plunder; 17 protected boolean isAlive; 18 public int health; 19 20 public int points; 21 public static int ammo; 22 private final int attackDmg; 23 public boolean isImmortality; 24 public boolean isUnlimitedAmmo; 25 public boolean isShootEightDirections; 26 public boolean isBiggerDamage; 27 28 /** 29 * The enemy that is being targeted by the AI. 30 */ 31 private final QueueFIFO<Ship> targets; 32 33 public Pirate() { 34 super(); 35 targets = new QueueFIFO<>(); 36 type = ComponentType.Pirate; 37 plunder = GameManager.getSettings().get("starting").getInt("plunder"); 38 factionId = 1; 39 isAlive = true; 40 JsonValue starting = GameManager.getSettings().get("starting"); 41 health = starting.getInt("health"); 42 attackDmg = starting.getInt("damage"); 43 ammo = starting.getInt("ammo"); 44 health = starting.getInt("health"); 45 isUnlimitedAmmo = false; 46 isImmortality = false; 47 isShootEightDirections = false; 48 isBiggerDamage = false; 49 points =0; 50 } 51 52 public void addTarget(Ship target) { 53 targets.add(target); 54 } 55 56 public int getPlunder() { 57 return plunder; 58 } 59 60 public void addPlunder(int money) { 61 plunder += money; 62 } 63 64 public Faction getFaction() { 65 return GameManager.getFaction(factionId); 66 } 67 68 public void setFactionId(int factionId) { 69 this.factionId = factionId; 70 } 71 72 //NEW FUNCTIONS 73 public void setImmortality(boolean state){ 74 isImmortality = state; 75 } 76 77 public boolean getImmortality() { return isImmortality; }; 78 79 public void setUnlimitedAmmo(boolean state){ 80 isUnlimitedAmmo = state; 81 } 82 83 public boolean getUnlimitedAmmo() { return isUnlimitedAmmo; }; 84 85 public void setShootEightDirections(boolean state){ 86 isShootEightDirections = state; 87 } 88 89 public boolean getShootEightDirections() { return isShootEightDirections; }; 90 91 public void setBiggerDamage(boolean state){ 92 isBiggerDamage = state; 93 } 94 95 public boolean getBiggerDamage() { return isBiggerDamage; }; 96 //END 97 public void takeDamage(float dmg) { 98 if (isImmortality) 99 dmg = 0; 100 101 health -= dmg; 102 if (health <= 0) { 103 health = 0; 104 isAlive = false; 105 } 106 } 107 108 /** 109 * Will shoot a cannonball assigning this.parent as the cannonball's parent (must be Ship atm) 110 * 111 * @param dir the direction to shoot in 112 */ 113 public void shoot(Vector2 dir) { 114 if (ammo == 0) { 115 return; 116 } 117 if(!isUnlimitedAmmo) 118 ammo--; 119 if(!isShootEightDirections) 120 GameManager.shoot((Ship) parent, dir); 121 else{ 122 GameManager.shoot((Ship) parent, new Vector2(0, 1)); 123 GameManager.shoot((Ship) parent, new Vector2(0, -1)); 124 GameManager.shoot((Ship) parent, new Vector2(1, 0)); 125 GameManager.shoot((Ship) parent, new Vector2(-1, 0)); 126 GameManager.shoot((Ship) parent, new Vector2(1, 1)); 127 GameManager.shoot((Ship) parent, new Vector2(-1, 1)); 128 GameManager.shoot((Ship) parent, new Vector2(1, -1)); 129 GameManager.shoot((Ship) parent, new Vector2(-1, -1)); 130 } 131 } 132 133 /** 134 * Adds ammo 135 * 136 * @param newAmmo amount to add 137 */ 138 public static void addAmmo(int newAmmo) { 139 ammo += newAmmo; 140 } 141 142 public int getHealth() { 143 return health; 144 } 145 146 public void setHealth(int overrideHealth) { 147 health = overrideHealth; 148 } 149 150 /** 151 * if dst to target is less than attack range 152 * target will be null if not in agro range 153 */ 154 public boolean canAttack() { 155 if (targets.peek() != null) { 156 final Ship p = (Ship) parent; 157 final Vector2 pos = p.getPosition(); 158 final float dst = pos.dst(targets.peek().getPosition()); 159 // withing attack range 160 return dst < Ship.getAttackRange(); 161 } 162 return false; 163 } 164 165 /** 166 * if dst to target is >= attack range 167 * target will be null if not in agro range 168 */ 169 public boolean isAgro() { 170 if (targets.peek() != null) { 171 final Ship p = (Ship) parent; 172 final Vector2 pos = p.getPosition(); 173 final float dst = pos.dst(targets.peek().getPosition()); 174 // out of attack range but in agro range 175 return dst >= Ship.getAttackRange(); 176 } 177 return false; 178 } 179 180 public Ship getTarget() { 181 return targets.peek(); 182 } 183 184 public void removeTarget() { 185 targets.pop(); 186 } 187 188 public boolean isAlive() { 189 return isAlive; 190 } 191 192 /** 193 * Kill its self 194 */ 195 public void kill() { 196 health = 0; 197 isAlive = false; 198 } 199 200 public void setAmmo(int ammo) { 201 this.ammo = ammo; 202 } 203 204 public int getAmmo() { 205 return ammo; 206 } 207 208 public int targetCount() { 209 return targets.size(); 210 } 211 212 public QueueFIFO<Ship> getTargets() { 213 return targets; 214 } 215 216 public int getPoints(){return points;} 217 218 public void addPoints(int value){points += value;} 219 }