Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.68 KB | None | 0 0
  1. package org.prophanis.game.node.entity.joint.old_combat.battle.impl;
  2.  
  3. import org.prophanis.game.node.entity.Entity;
  4. import org.prophanis.game.node.entity.joint.Animator.Priority;
  5. import org.prophanis.game.node.entity.joint.old_combat.CombatResource;
  6. import org.prophanis.game.node.entity.joint.old_combat.battle.BattleStyle;
  7. import org.prophanis.game.node.entity.joint.old_combat.hit.Hit;
  8. import org.prophanis.game.node.entity.npc.NPC;
  9. import org.prophanis.game.node.entity.player.Player;
  10. import org.prophanis.game.node.entity.player.joint.Equipment;
  11. import org.prophanis.game.node.entity.pulse.PulseEvent;
  12. import org.prophanis.game.node.entity.update.context.Animation;
  13. import org.prophanis.game.node.item.Item;
  14.  
  15. /**
  16.  * A class containing a melee attack singleton.
  17.  * @author Displee
  18.  */
  19. public class MeleeBattle extends BattleStyle {
  20.  
  21.     @Override
  22.     public boolean canSwing(Entity entity, Entity victim) {
  23.         final boolean inRange = entity.getCenterLocation().withinDistance(victim.getCenterLocation(), distance(entity, victim) + (entity.getSize() >> 1) + (victim.getSize() >> 1));
  24.         return inRange;
  25.     }
  26.  
  27.     @Override
  28.     public int swing(Entity entity, Entity victim) {
  29.         boolean face = true;
  30.         if (victim.getAttributes().get("last_face_entity", -1) == entity.getClientIndex()) {
  31.             face = false;
  32.         }
  33.         if (face) {
  34.             victim.face(entity);
  35.         }
  36.         return 1;
  37.     }
  38.  
  39.     @Override
  40.     public void impact(Entity entity, Entity victim) {
  41.         Hit[] hits = new Hit[1];
  42.         final boolean special = entity instanceof Player && ((Player) entity).getVarpManager().get(301) == 1;
  43.         if (super.handleSpecial(entity)) {
  44.             if (entity instanceof Player) {
  45.                 hits = CombatResource.calculateSpecialHits(entity);
  46.             } else {
  47.                 //NPC Specials?
  48.             }
  49.             entity.getAttributes().set("special_request", false);
  50.         } else {
  51.             if (special) {
  52.                 return;
  53.             }
  54.             entity.getAnimator().animate(new Animation(CombatResource.getAttackAnimation(entity), Priority.HIGH));
  55.             hits[0] = CombatResource.calculateNormalHit(entity);
  56.         }
  57.         for (Hit hit : hits) {
  58.             if (hit != null) {
  59.                 victim.getCombatManager().getHits().add(hit);
  60.             }
  61.         }
  62.     }
  63.  
  64.     @Override
  65.     public void visualizeImpact(Entity entity, Entity victim) {
  66.         if (!victim.getCombatManager().getHits().isEmpty()) {
  67.             for (int i = 0; i < 2; i++) {
  68.                 final Hit hit = victim.getCombatManager().getHits().poll();
  69.                 if (hit != null) {
  70.                     victim.impact(entity, hit);
  71.                     victim.onImpact(entity);
  72.                 }
  73.             }
  74.             if (!victim.getCombatManager().getHits().isEmpty()) {
  75.                 victim.getPulseManager().register(new PulseEvent<Entity>(2) {
  76.  
  77.                     @Override
  78.                     public boolean handle(Entity node) {
  79.                         for (int i = 0; i < 2; i++) {
  80.                             final Hit hit = victim.getCombatManager().getHits().poll();
  81.                             if (hit != null) {
  82.                                 victim.impact(entity, hit);
  83.                             }
  84.                         }
  85.                         return true;
  86.                     }
  87.                 });
  88.             }
  89.             victim.getAnimator().animate(new Animation(CombatResource.getDefenceAnimation(victim)));
  90.         }
  91.     }
  92.  
  93.     @Override
  94.     public int interval(Entity entity, Entity victim) {
  95.         if (entity instanceof Player) {
  96.             final Player player = (Player) entity;
  97.             final Item item = player.getEquipment().get(Equipment.SLOT_WEAPON);
  98.             if (item != null) {
  99.                 return item.getDefinition().getAttackInterval();
  100.             }
  101.             return 3;
  102.         } else {
  103.             return ((NPC) entity).getDefinition().getAttackDelay();
  104.         }
  105.     }
  106.  
  107.     @Override
  108.     public int distance(Entity entity, Entity victim) {
  109.         if (entity instanceof Player) {
  110.             final Item weapon = ((Player) entity).getEquipment().get(Equipment.SLOT_WEAPON);
  111.             if (weapon != null && ((weapon.getId() >= 3190 && weapon.getId() <= 3204) || weapon.getId() == 6599)) {
  112.                 return 2;//Halberds
  113.             }
  114.         }
  115.         return victim.getSize();
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement