Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Checks if an entity can attack another.
- *
- * @param source
- * The source entity.
- * @param victim
- * The target entity.
- * @return <code>true</code> if so, <code>false</code> if not.
- */
- public static boolean canAttack(Entity source, Entity victim) {
- /*
- * Check for the state of life of both entities.
- */
- if (victim.isDead() || source.isDead())
- return false;
- /*
- * Check if the victim is already in combat and if the current zone of
- * both entities allows multicombat.
- */
- if (victim.isInCombat()
- && (victim.getZone().getType() == ZoneType.COMBAT_SINGLE || source
- .getZone().getType() == ZoneType.COMBAT_SINGLE)) {
- if (source instanceof Player) {
- Player p = (Player) source;
- p.getActionSender().sendMessage(
- "That opponent is already under attack!");
- }
- return false;
- }
- if ((source instanceof Player) && (victim instanceof Player)) {
- // Player VS Player
- } else if ((source instanceof Player) && (victim instanceof NPC)) {
- // Player VS NPC
- } else if ((source instanceof NPC) && victim instanceof Player) {
- // NPC VS Player
- } else if ((source instanceof NPC && victim instanceof NPC)) {
- // NPC VS NPC
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement