Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.00 KB | None | 0 0
  1. package com.runelive.world.content.combat.strategy.impl;
  2.  
  3. import com.runelive.engine.task.Task;
  4. import com.runelive.engine.task.TaskManager;
  5. import com.runelive.model.*;
  6. import com.runelive.util.Misc;
  7. import com.runelive.world.World;
  8. import com.runelive.world.content.combat.CombatContainer;
  9. import com.runelive.world.content.combat.CombatType;
  10. import com.runelive.world.content.combat.HitQueue;
  11. import com.runelive.world.content.combat.strategy.CombatStrategy;
  12. import com.runelive.world.entity.impl.Character;
  13. import com.runelive.world.entity.impl.npc.NPC;
  14. import com.runelive.world.entity.impl.player.Player;
  15.  
  16. import java.util.ArrayList;
  17. import java.util.List;
  18.  
  19. public class Phoenix implements CombatStrategy {
  20.  
  21. public static NPC PHOENIX;
  22.  
  23. public static ArrayList<NPC> MINION = new ArrayList<NPC>();
  24.  
  25. public static void spawn(int id, Position pos) {
  26. PHOENIX = new NPC(id, pos);
  27. World.register(PHOENIX);
  28. PHOENIX.forceChat(RESPAWN_MESSAGES[(int) (Math.random() * RESPAWN_MESSAGES.length)]);
  29. }
  30.  
  31. public static final String[] RESPAWN_MESSAGES = {
  32. "I am near immortal !",
  33. "Time to die",
  34. "Mwuahahaha!!!",
  35. "I was resurrected",
  36. "I'm baaaaaaaaaaaaaack"
  37. };
  38.  
  39. public static void resetOrIncrement() {
  40. if (World.PHOENIX_RESPAWN >= 5) {
  41. World.PHOENIX_RESPAWN = 0;
  42. } else {
  43. World.PHOENIX_RESPAWN++;
  44. }
  45. }
  46.  
  47. public boolean summonMinions(Player p) {
  48. p.getPacketSender().sendMessage("The phoenix has summoned it's minions on you!");
  49. // System.out.println("Summoning... || size: " + MINION.size());
  50. MINION.add(new NPC(6216, p.getPosition()));
  51. MINION.get(MINION.size()-1).getCombatBuilder().attack(p.getCharacter());
  52. World.register(MINION.get(MINION.size()-1));
  53. MINION.get(MINION.size()-1).forceChat("I will die for my master!");
  54. // System.out.println("Spawned minion["+i+"] || size: " + MINION.size());
  55. /*boolean doubleSpawn = Misc.random(10) == 1;
  56. if (doubleSpawn) {
  57. // System.out.println("Double Spawning minion");
  58. p.setRegionInstance(new RegionInstance(p, RegionInstance.RegionInstanceType.PHOENIX));
  59. NPC npc_ = new NPC(6216, p.getPosition());
  60. npc_.getCombatBuilder().setAttackTimer(3);
  61. npc_.getCombatBuilder().attack(p.getCharacter());
  62. World.register(npc_);
  63. p.getRegionInstance().getNpcsList().add(npc_);
  64. }*/
  65. // System.out.println("Spawning minion");
  66. return false;
  67. }
  68.  
  69. /**
  70. *
  71. * @param n checks the minion NPC array
  72. */
  73. public static void despawnMinions(ArrayList<NPC> n) {
  74. for (int i = 0; i < MINION.size(); i++) {
  75. MINION.remove(n);
  76. World.deregister(MINION.get(i));
  77. }
  78. MINION.clear();
  79. }
  80.  
  81. /**
  82. * Checks for any minions
  83. * @return true if there are any spawn minions
  84. */
  85. public static boolean anyMinionAlive() {
  86. boolean sizeIsZero = MINION.size() == 0 ? true : false;
  87. return sizeIsZero;
  88. }
  89.  
  90. public static void death(final int id, final Position pos) {
  91. TaskManager.submit(new Task(40, World.PHOENIX_RESPAWN < 5 ? true : false) {
  92. @Override
  93. protected void execute() {
  94. despawnMinions(MINION);
  95. resetOrIncrement();
  96. spawn(id, pos);
  97. stop();
  98. }
  99. });
  100. }
  101.  
  102. @Override
  103. public boolean canAttack(Character entity, Character victim) {
  104. return true;
  105. }
  106.  
  107. @Override
  108. public CombatContainer attack(Character entity, Character victim) {
  109. return null;
  110. }
  111.  
  112. @Override
  113. public boolean customContainerAttack(Character entity, Character victim) {
  114. NPC phoenix = (NPC) entity;
  115. if (victim.getConstitution() <= 0) {
  116. return true;
  117. }
  118. if (phoenix.isChargingAttack()) {
  119. return true;
  120. }
  121.  
  122. final CombatType style = Misc.getRandom(3) == 0 ? CombatType.MAGIC : CombatType.RANGED;
  123. boolean spawnMinions = Misc.getRandom(50) == 2 ? true : false;
  124. phoenix.performAnimation(new Animation(phoenix.getDefinition().getAttackAnimation()));
  125. phoenix.setChargingAttack(true);
  126. Player target = (Player) victim;
  127. final List<Player> list = Misc.getCombinedPlayerList(target);
  128. TaskManager.submit(new Task(1, phoenix, false) {
  129. int tick = 0;
  130.  
  131. @Override
  132. public void execute() {
  133. if (style == CombatType.MAGIC) {
  134. if (tick == 1) {
  135. for (Player near : list) {
  136. if (near == null)
  137. continue;
  138. new Projectile(phoenix, near, 393, 44, 3, 43, 43, 0)
  139. .sendProjectile();
  140. near.performGraphic(new Graphic(129));
  141. if (spawnMinions) {
  142. summonMinions(near);
  143. }
  144. }
  145. } else if (tick == 2) {
  146. for (Player near : list) {
  147. if (near == null)
  148. continue;
  149. //System.out.println("Near player: " + near.getUsername());
  150. phoenix.getCombatBuilder().setVictim(near);
  151. new HitQueue.CombatHit(phoenix.getCombatBuilder(), new CombatContainer(phoenix, near, 1, CombatType.MAGIC, true))
  152. .handleAttack();
  153. }
  154. phoenix.setChargingAttack(false);
  155. stop();
  156. }
  157. } else if (style == CombatType.RANGED) {
  158. if (tick == 1) {
  159. new Projectile(phoenix, victim, 1099, 44, 5, 33, 33, 0).sendProjectile();
  160. if (spawnMinions) {
  161. summonMinions((Player) victim);
  162. }
  163. } else if (tick == 2) {
  164. new HitQueue.CombatHit(phoenix.getCombatBuilder(),
  165. new CombatContainer(phoenix, victim, 1, style, true)).handleAttack();
  166. phoenix.setChargingAttack(false);
  167. stop();
  168. }
  169. }
  170. tick++;
  171. }
  172. });
  173. return true;
  174. }
  175.  
  176. @Override
  177. public int attackDelay(Character entity) {
  178. return entity.getAttackSpeed();
  179. }
  180.  
  181. @Override
  182. public int attackDistance(Character entity) {
  183. return 4;
  184. }
  185.  
  186. @Override
  187. public CombatType getCombatType() {
  188. return CombatType.MAGIC;
  189. }
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement