Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. /**
  2. * Checks if an entity can attack another.
  3. *
  4. * @param source
  5. * The source entity.
  6. * @param victim
  7. * The target entity.
  8. * @return <code>true</code> if so, <code>false</code> if not.
  9. */
  10. public static boolean canAttack(Entity source, Entity victim) {
  11. /*
  12. * Check for the state of life of both entities.
  13. */
  14. if (victim.isDead() || source.isDead())
  15. return false;
  16. /*
  17. * Check if the victim is already in combat and if the current zone of
  18. * both entities allows multicombat.
  19. */
  20. if (victim.isInCombat()
  21. && (victim.getZone().getType() == ZoneType.COMBAT_SINGLE || source
  22. .getZone().getType() == ZoneType.COMBAT_SINGLE)) {
  23. if (source instanceof Player) {
  24. Player p = (Player) source;
  25. p.getActionSender().sendMessage(
  26. "That opponent is already under attack!");
  27. }
  28. return false;
  29. }
  30. if ((source instanceof Player) && (victim instanceof Player)) {
  31. // Player VS Player
  32. } else if ((source instanceof Player) && (victim instanceof NPC)) {
  33. // Player VS NPC
  34. } else if ((source instanceof NPC) && victim instanceof Player) {
  35. // NPC VS Player
  36. } else if ((source instanceof NPC && victim instanceof NPC)) {
  37. // NPC VS NPC
  38. }
  39. return true;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement