Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.33 KB | None | 0 0
  1. package com.ruseps.world.content.combat.strategy.impl;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import com.ruseps.engine.task.Task;
  7. import com.ruseps.engine.task.TaskManager;
  8. import com.ruseps.model.Animation;
  9. import com.ruseps.model.Graphic;
  10. import com.ruseps.model.GraphicHeight;
  11. import com.ruseps.model.Locations;
  12. import com.ruseps.model.Position;
  13. import com.ruseps.model.Projectile;
  14. import com.ruseps.model.Skill;
  15. import com.ruseps.util.Misc;
  16. import com.ruseps.world.World;
  17. import com.ruseps.world.content.combat.CombatContainer;
  18. import com.ruseps.world.content.combat.CombatFactory;
  19. import com.ruseps.world.content.combat.CombatHitTask;
  20. import com.ruseps.world.content.combat.CombatType;
  21. import com.ruseps.world.content.combat.effect.CombatPoisonEffect.PoisonType;
  22. import com.ruseps.world.content.combat.strategy.CombatStrategy;
  23. import com.ruseps.world.entity.impl.npc.NPC;
  24. import com.ruseps.world.entity.impl.npc.NPCMovementCoordinator.Coordinator;
  25. import com.ruseps.world.entity.impl.player.Player;
  26. import com.ruseps.world.entity.impl.Character;
  27.  
  28. public class PyramidHead implements CombatStrategy {
  29.  
  30. public static NPC entity;
  31.  
  32. public static void spawn(int id, Position pos) {
  33. entity = new NPC(id, pos);
  34. entity.getMovementCoordinator().setCoordinator(new Coordinator(true, 3));
  35. World.register(entity);
  36. }
  37.  
  38. public static void death(final int id, final Position pos) {
  39. TaskManager.submit(new Task(id == 1160 ? 40 : 2) {
  40. @Override
  41. protected void execute() {
  42. stop();
  43. }
  44. });
  45. }
  46.  
  47. @Override
  48. public boolean canAttack(Character entity, Character victim) {
  49. return true;
  50. }
  51.  
  52. @Override
  53. public CombatContainer attack(Character entity, Character victim) {
  54. return null;
  55. }
  56.  
  57. public int attackCounter;
  58. public CombatType attackType = CombatType.MELEE;//starts with melee combat style
  59. public int lastVengeance;
  60. public int lastSpawn;
  61. public int lastPrayerSwitch;
  62.  
  63. protected static final int RANGE_ANIM = 1979;
  64. protected static final int RANGE_PROJECTILE = 278;
  65. protected static final int MAGIC_PROJECTILE = 279;
  66.  
  67. long specialAbilityCounter = Long.MAX_VALUE;
  68.  
  69. public boolean abilityActive() { //this returns true for 20k miliseconds after ability is activated
  70. return specialAbilityCounter + 20_000 > System.currentTimeMillis();
  71. }
  72.  
  73. ArrayList<PyramidSpawn> spawns = new ArrayList<PyramidSpawn>();
  74.  
  75. enum Spell {
  76. DEFAULT, SMOKE_BARRAGE, ICE_BARRAGE, BLOOD_BARRAGE, SHADOW_BARRAGE;
  77. }
  78.  
  79. @Override
  80. public boolean customContainerAttack(Character entity, Character victim) {//eh idk yea we can look more into it tomorrow :p
  81.  
  82. if (entity == null || victim == null)
  83. return true;
  84. if (victim.getConstitution() <= 0 )
  85. if (entity.getConstitution() <= 0)
  86. if (entity.getAsNpc().isChargingAttack())
  87. return true;
  88. if (attackType == null)
  89. attackType = CombatType.MELEE;
  90. attackCounter++;
  91. if (entity.getConstitution() < entity.getAsNpc().getDefaultConstitution()/3 && attackType.equals(CombatType.RANGED)) {
  92. attackType = CombatType.MAGIC;
  93. lastSpawn = attackCounter;
  94. spawns.add(new PyramidSpawn().spawn(this, 507, new Position(victim.getPosition().getX()- 3 + Misc.random(3), victim.getPosition().getY()- 3 + Misc.random(3))));
  95. spawns.add(new PyramidSpawn().spawn(this, 507, new Position(victim.getPosition().getX()- 3 + Misc.random(3), victim.getPosition().getY()- 3 + Misc.random(3))));
  96. spawns.add(new PyramidSpawn().spawn(this, 507, new Position(victim.getPosition().getX()- 3 + Misc.random(3), victim.getPosition().getY()- 3 + Misc.random(3))));
  97. spawns.add(new PyramidSpawn().spawn(this, 507, new Position(victim.getPosition().getX()- 3 + Misc.random(3), victim.getPosition().getY()- 3 + Misc.random(3))));
  98. } else if (entity.getConstitution() < entity.getAsNpc().getDefaultConstitution()*2/3 && attackType.equals(CombatType.MELEE)) {
  99. attackType = CombatType.RANGED;
  100. specialAbilityCounter = System.currentTimeMillis();
  101. } else if ((attackType.equals(CombatType.MAGIC) || attackType.equals(CombatType.RANGED)) && entity.getConstitution() > entity.getAsNpc().getDefaultConstitution() * 2 / 3)
  102. attackType = CombatType.MELEE;
  103.  
  104. if (abilityActive()) {
  105. entity.performGraphic(new Graphic(2320));
  106. }
  107. if (attackType.equals(CombatType.MAGIC)) {
  108. if (Misc.random(9) == 0 && lastVengeance + 5 <= attackCounter) { //vengeance fully set up and working
  109. lastVengeance = attackCounter;
  110. entity.setHasVengeance(true);
  111. entity.performAnimation(new Animation(1979));
  112. entity.performGraphic(new Graphic(726, GraphicHeight.HIGH));
  113. return true;
  114. }
  115. }
  116.  
  117. victim.setPoisonDamage(12);
  118.  
  119. if (victim.isPlayer()) {
  120. Player p = (Player) victim;
  121. final List<Player> list = Misc.getCombinedPlayerList(p);
  122.  
  123. if (attackType.equals(CombatType.MELEE)) {
  124. entity.performAnimation(new Animation(451));
  125. entity.getCombatBuilder()
  126. .setContainer(new CombatContainer(entity, victim, 1, 1, CombatType.MELEE, true));
  127. if (Misc.random(9) == 1) {//10% chance to stun player in melee form
  128. p.performGraphic(new Graphic(2391));
  129. p.getMovementQueue().freeze(10);
  130. }
  131. } else {
  132. entity.getAsNpc().setChargingAttack(true);
  133. TaskManager.submit(new Task(1, entity, false) {
  134. int tick = 0;
  135. Spell spell = Misc.random(3) == 0 ? Spell.BLOOD_BARRAGE : Misc.random(2) == 0 ? Spell.SHADOW_BARRAGE : Misc.random(6) == 0 ? Spell.ICE_BARRAGE : Spell.SMOKE_BARRAGE;
  136. @Override
  137. protected void execute() {
  138. tick++;
  139. if (tick == 1) {
  140. for (Player toAttack : list) {
  141. if (toAttack != null
  142. && Locations.goodDistance(entity.getPosition(), toAttack.getPosition(), 7)
  143. && toAttack.getConstitution() > 0) {
  144. new Projectile(entity, toAttack, attackType.equals(CombatType.MAGIC) ? MAGIC_PROJECTILE : RANGE_PROJECTILE, 44, 3, 43, 43, 0)
  145. .sendProjectile();
  146. entity.performAnimation(new Animation(attackType.equals(CombatType.MAGIC) ? 1979 : RANGE_ANIM));
  147. }
  148. if (attackType.equals(CombatType.MAGIC))
  149. switch(spell) {
  150. case SMOKE_BARRAGE:
  151. CombatFactory.poisonEntity(toAttack, PoisonType.SUPER);
  152. break;
  153. case ICE_BARRAGE:
  154. toAttack.getMovementQueue().freeze(10);
  155. break;
  156. case SHADOW_BARRAGE:
  157. int decrease = (int) (0.15 * (toAttack.getSkillManager().getCurrentLevel(Skill.ATTACK)));
  158. toAttack.getSkillManager().setCurrentLevel(Skill.ATTACK, toAttack.getSkillManager().getCurrentLevel(Skill.ATTACK) - decrease);
  159. toAttack.getSkillManager().updateSkill(Skill.ATTACK);
  160. break;
  161. default:
  162. break;
  163. }
  164. }
  165. } else if (tick == 3) {
  166. for (Player toAttack : list) {
  167. if (toAttack != null
  168. && Locations.goodDistance(entity.getPosition(), toAttack.getPosition(), 7)
  169. && toAttack.getConstitution() > 0) {
  170. toAttack.performGraphic(new Graphic(attackType.equals(CombatType.MAGIC) ? spell.equals(Spell.BLOOD_BARRAGE) ? 377 : spell.equals(Spell.SHADOW_BARRAGE) ? 383 : spell.equals(Spell.SMOKE_BARRAGE) ? 391 : spell.equals(Spell.ICE_BARRAGE) ? 369 : 391 : 278));
  171. }
  172. }
  173. } else if (tick == 5) {
  174. if (attackType.equals(CombatType.RANGED)) {
  175. for (Player toAttack : list) {
  176. if (toAttack != null
  177. && Locations.goodDistance(entity.getPosition(), toAttack.getPosition(), 7)
  178. && toAttack.getConstitution() > 0) {
  179. entity.setEntityInteraction(toAttack);
  180. entity.getCombatBuilder().setVictim(toAttack);
  181. int damage = new CombatHitTask(entity.getCombatBuilder(),
  182. new CombatContainer(entity, toAttack, 1, attackType, true))
  183. .handleAttack();
  184.  
  185. if (damage > toAttack.getSkillManager().getCurrentLevel(Skill.PRAYER))
  186. damage = toAttack.getSkillManager().getCurrentLevel(Skill.PRAYER);
  187. toAttack.getSkillManager().setCurrentLevel(Skill.PRAYER, toAttack.getSkillManager().getCurrentLevel(Skill.PRAYER) - damage);
  188. }
  189. }
  190. } else if (attackType.equals(CombatType.MAGIC)) {
  191. for (Player toAttack : list) {
  192. if (toAttack != null
  193. && Locations.goodDistance(entity.getPosition(), toAttack.getPosition(), 7)
  194. && toAttack.getConstitution() > 0) {
  195. entity.setEntityInteraction(toAttack);
  196. entity.getCombatBuilder().setVictim(toAttack);
  197. int damage = new CombatHitTask(entity.getCombatBuilder(), new CombatContainer(entity, toAttack, 1, attackType, true)).handleAttack();
  198. if (attackType.equals(CombatType.MAGIC) && spell.equals(Spell.BLOOD_BARRAGE))
  199. entity.setConstitution(entity.getConstitution() + damage/3);
  200. }
  201. }
  202. }
  203. stop();
  204. }
  205. }
  206.  
  207. @Override
  208. public void stop() {
  209. setEventRunning(false);
  210. entity.getAsNpc().setChargingAttack(false);
  211. }
  212. });
  213. }
  214. } else if (victim.isNpc()) {
  215.  
  216. }
  217. return true;
  218. }
  219.  
  220. @Override
  221. public int attackDelay(Character entity) {
  222. return entity.getAttackSpeed();
  223. }
  224.  
  225. @Override
  226. public int attackDistance(Character entity) {
  227. return 10;
  228. }
  229.  
  230. @Override
  231. public CombatType getCombatType() {
  232. return CombatType.MIXED;
  233. }
  234.  
  235. public void heal(int amount) {
  236. if (entity != null)
  237. entity.setConstitution(entity.getConstitution() + amount);
  238. }
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement