public final L2Object[] getTargetList(L2Character activeChar) { List targetList = new FastList(); // Get the target type of the skill // (ex : ONE, SELF, HOLY, PET, AURA, AURA_CLOSE, AREA, MULTIFACE, PARTY, CLAN, CORPSE_PLAYER, CORPSE_MOB, CORPSE_CLAN, UNLOCKABLE, ITEM, UNDEAD) SkillTargetType targetType = getTargetType(); // Init to null the target of the skill L2Character target = null; // Get the L2Objcet targeted by the user of the skill at this moment L2Object objTarget = activeChar.getTarget(); // Get the type of the skill // (ex : PDAM, MDAM, DOT, BLEED, POISON, HEAL, HOT, MANAHEAL, MANARECHARGE, AGGDAMAGE, BUFF, DEBUFF, STUN, ROOT, RESURRECT, PASSIVE...) SkillType skillType = getSkillType(); // If the L2Object targeted is a L2Character, it becomes the L2Character target if(objTarget instanceof L2Character) { target = (L2Character) objTarget; } switch(targetType) { // The skill can only be used on the L2Character targeted, or on the caster itself case TARGET_ONE: { /** * Commented out by [NeXuS], since you CAN heal/buff/etc a NPC instance. * But if you do so, you should just flag, like doing it on a flagged player or a player with karma. */ /* Skills BUFF, HEAL, MANAHEAL, HOT, REFLECT, NEGATE if(skillType == SkillType.BUFF || skillType == SkillType.HEAL || skillType == SkillType.MANAHEAL || skillType == SkillType.HOT || skillType == SkillType.REFLECT || skillType == SkillType.NEGATE) { // If target is npc or null then just focus on self for heal and buff type skills L2PcInstance tgt = null; // If the target is a L2PcInstance, it becomes the target of the skill // else if the activechar is a L2PcInstance, it becomes the target of the skill if(target instanceof L2PcInstance) tgt = (L2PcInstance)target; else if (activeChar instanceof L2PcInstance) tgt = (L2PcInstance)activeChar; // If a target is found, return it in a table else send a system message TARGET_IS_INCORRECT if (tgt != null && !tgt.isAlikeDead()) return new L2Character[]{tgt}; activeChar.sendPacket(new SystemMessage(SystemMessage.TARGET_IS_INCORRECT)); return null; } else {*/ // Check for null target or any other invalid target if(target == null || target.isDead() || (target == activeChar && !( skillType == SkillType.BUFF || skillType == SkillType.HEAL || skillType == SkillType.HEAL_PERCENT || skillType == SkillType.HOT || skillType == SkillType.MANAHEAL || skillType == SkillType.MANARECHARGE || skillType == SkillType.NEGATE || skillType == SkillType.CANCEL || skillType == SkillType.REFLECT || skillType == SkillType.UNBLEED || skillType == SkillType.UNPOISON || skillType == SkillType.SEED ))) { activeChar.sendPacket(new SystemMessage(SystemMessage.TARGET_IS_INCORRECT)); return null; } // If a target is found, return it in a table else send a system message TARGET_IS_INCORRECT return new L2Character[]{target}; //} } case TARGET_SELF: { return new L2Character[]{activeChar}; } case TARGET_HOLY: { if (activeChar instanceof L2PcInstance) { if (activeChar.getTarget() instanceof L2ArtefactInstance) return new L2Character[]{(L2ArtefactInstance)activeChar.getTarget()}; } return null; } case TARGET_PET: { target = activeChar.getPet(); if (target != null && !target.isDead()) return new L2Character[]{target}; return null; } case TARGET_AURA: { int radius = getSkillRadius(); for (L2Object obj : activeChar.getKnownList().getKnownObjects()) { if (obj instanceof L2Attackable || obj instanceof L2PcInstance) { // Don't add this target if this is a Pc->Pc pvp casting and pvp condition not met if (activeChar instanceof L2PcInstance && !((L2PcInstance)activeChar).checkPvpSkill(obj, this)) continue; // check if both attacker and target are L2PcInstances and if they are in same party or clan if ( (activeChar instanceof L2PcInstance && obj instanceof L2PcInstance) && ( ((L2PcInstance)activeChar).getClanId() == ((L2PcInstance)obj).getClanId() || ( (((L2PcInstance)activeChar).getParty() != null && ((L2PcInstance)obj).getParty() != null) && ((L2PcInstance)activeChar).getParty().getPartyLeaderOID() == ((L2PcInstance)obj).getParty().getPartyLeaderOID() ))) continue; if (!Util.checkIfInRange(radius, activeChar, obj, true)) continue; targetList.add((L2Character)obj); } } return targetList.toArray(new L2Character[targetList.size()]); } case TARGET_AREA: { if ( ( // ) !(target instanceof L2Attackable) && // Target is not L2Attackable and !(target instanceof L2PcInstance) // Target is not L2PcInstance ) || // ) or ( // ( this.getCastRange() >= 0 && // Range skill and ( // ( target == null || // No target or target == activeChar || // Target is self or target.isAlikeDead() // Target is dead/fake death ) // ) ) // ) ) { activeChar.sendPacket(new SystemMessage(SystemMessage.TARGET_IS_INCORRECT)); return null; } L2Character cha; if (this.getCastRange() >= 0) { cha = target; targetList.add((L2Character)cha); // Add target to target list } else cha = activeChar; boolean skillUserIsL2PcInstance = (activeChar instanceof L2PcInstance); boolean effectOriginIsL2PcInstance = (cha instanceof L2PcInstance); boolean objIsL2PcInstance; int radius = getSkillRadius(); for (L2Object obj : cha.getKnownList().getKnownObjects()) { if (!(obj instanceof L2Character)) continue; target = (L2Character) obj; if(!target.isAlikeDead() && target != activeChar) // If target is not dead/fake death and not self { if (!Util.checkIfInRange(radius, cha, obj, true)) // Go to next obj if obj isn't in range continue; objIsL2PcInstance = (obj instanceof L2PcInstance); if (skillUserIsL2PcInstance) // Skill attacker is L2PcInstance, hit everything except { if ( ( // ( objIsL2PcInstance && // obj is L2PcInstance and ( // ( ( // In same clan (((L2PcInstance)activeChar).getClan() != null && ((L2PcInstance)obj).getClan() != null) && ((L2PcInstance)activeChar).getClan().getClanId() == ((L2PcInstance)obj).getClan().getClanId() ) || // or in same party ( (((L2PcInstance)activeChar).getParty() != null && ((L2PcInstance)obj).getParty() != null) && ((L2PcInstance)activeChar).getParty().getPartyLeaderOID() == ((L2PcInstance)obj).getParty().getPartyLeaderOID() ) || // or not pvp with !((L2PcInstance)activeChar).checkPvpSkill(obj, this) ) // ) ) ) continue; } else // Skill user is not L2PcInstance { if (effectOriginIsL2PcInstance && // If effect starts at L2PcInstance and !objIsL2PcInstance) // Object is not L2PcInstance continue; } targetList.add((L2Character)obj); // Add obj to target lists } } if (targetList.size() == 0) return null; return targetList.toArray(new L2Character[targetList.size()]); } case TARGET_MULTIFACE: { if((!(target instanceof L2Attackable) && !(target instanceof L2PcInstance))) { activeChar.sendPacket(new SystemMessage(SystemMessage.TARGET_IS_INCORRECT)); return null; } targetList.add(target); int radius = getSkillRadius(); for (L2Object obj : activeChar.getKnownList().getKnownObjects()) { if (!Util.checkIfInRange(radius, activeChar, obj, true)) continue; if(obj instanceof L2Attackable && obj != target) targetList.add((L2Character)obj); if(targetList.size() == 0) { activeChar.sendPacket(new SystemMessage(SystemMessage.TARGET_CANT_FOUND)); return null; } } return targetList.toArray(new L2Character[targetList.size()]); //TODO multiface targets all around right now. need it to just get targets //the character is facing. } case TARGET_PARTY: { if(activeChar instanceof L2PcInstance) { L2PcInstance player = (L2PcInstance) activeChar; L2Party party = player.getParty(); targetList.add(player); if(party != null) { // Get all visible objects in a spheric area near the L2Character // Get a list of Party Members List partyList = party.getPartyMembers(); int radius = getSkillRadius(); for(L2PcInstance partyMember : partyList) { if (partyMember == null) continue; if(!partyMember.isDead()) { if (!Util.checkIfInRange(radius, activeChar, partyMember, true)) continue; targetList.add(partyMember); break; } } } } return targetList.toArray(new L2Character[targetList.size()]); } case TARGET_CORPSE_ALLY: case TARGET_ALLY: { if(activeChar instanceof L2PcInstance) { int radius = getSkillRadius(); L2PcInstance player = (L2PcInstance) activeChar; L2Clan clan = player.getClan(); if (targetType != SkillTargetType.TARGET_CORPSE_ALLY) targetList.add(player); if(clan != null) { // Get all visible objects in a spheric area near the L2Character // Get Clan Members for ( L2Object newTarget : activeChar.getKnownList().getKnownObjects()) { if (newTarget == null || !(newTarget instanceof L2PcInstance)) continue; if ((((L2PcInstance)newTarget).getAllyId() == 0 || ((L2PcInstance)newTarget).getAllyId() != player.getAllyId()) && (((L2PcInstance)newTarget).getClan() == null || ((L2PcInstance)newTarget).getClanId() != player.getClanId())) continue; if (targetType == SkillTargetType.TARGET_CORPSE_ALLY && !((L2PcInstance)newTarget).isDead()) continue; if (!Util.checkIfInRange(radius, activeChar, newTarget, true)) continue; // Don't add this target if this is a Pc->Pc pvp casting and pvp condition not met if (!player.checkPvpSkill(newTarget, this)) continue; targetList.add((L2Character)newTarget); } } } return targetList.toArray(new L2Character[targetList.size()]); } case TARGET_CORPSE_CLAN: case TARGET_CLAN: { if(activeChar instanceof L2PcInstance) { int radius = getSkillRadius(); L2PcInstance player = (L2PcInstance) activeChar; L2Clan clan = player.getClan(); if (targetType != SkillTargetType.TARGET_CORPSE_CLAN) targetList.add(player); if(clan != null) { // Get all visible objects in a spheric area near the L2Character // Get Clan Members for (L2ClanMember member : clan.getMembers()) { L2PcInstance newTarget = member.getPlayerInstance(); if (newTarget == null) continue; if (targetType == SkillTargetType.TARGET_CORPSE_CLAN && !((L2PcInstance)newTarget).isDead()) continue; if (!Util.checkIfInRange(radius, activeChar, newTarget, true)) continue; // Don't add this target if this is a Pc->Pc pvp casting and pvp condition not met if (!player.checkPvpSkill(newTarget, this)) continue; targetList.add((L2Character)newTarget); } } } return targetList.toArray(new L2Character[targetList.size()]); } case TARGET_CORPSE_PLAYER: { if(target != null && target.isDead()) { L2PcInstance player = null; if (activeChar instanceof L2PcInstance) player = (L2PcInstance)activeChar; L2PcInstance targetPlayer = null; if (target instanceof L2PcInstance) targetPlayer = (L2PcInstance)target; L2PetInstance targetPet = null; if (target instanceof L2PetInstance) targetPet = (L2PetInstance)target; if(player != null && (targetPlayer != null || targetPet != null)) { boolean condGood = true; if ( getId() == 1016 // Greater Resurrection ) { // Can only res party memeber or own pet if (targetPet != null) { if (targetPet.getOwner() != player) { condGood = false; player.sendMessage("You are not the owner of this pet"); } } else { if (player.getParty() == null || targetPlayer.getParty() == null || player.getParty().getPartyLeaderOID() != targetPlayer.getParty().getPartyLeaderOID()) condGood = false; } } if (condGood) { targetList.add(target); return targetList.toArray(new L2Object[targetList.size()]); } } } activeChar.sendPacket(new SystemMessage(SystemMessage.TARGET_IS_INCORRECT)); return null; } case TARGET_CORPSE_MOB: { if(!(target instanceof L2Attackable) || !target.isDead()) { activeChar.sendPacket(new SystemMessage(SystemMessage.TARGET_IS_INCORRECT)); return null; } targetList.add(target); return targetList.toArray(new L2Object[targetList.size()]); } case TARGET_UNLOCKABLE: { if(!(target instanceof L2DoorInstance)) { activeChar.sendPacket(new SystemMessage(SystemMessage.TARGET_IS_INCORRECT)); return null; } targetList.add(target); return targetList.toArray(new L2Object[targetList.size()]); } case TARGET_ITEM: { SystemMessage sm = new SystemMessage(SystemMessage.S1_S2); sm.addString("Target type of skill is not currently handled"); activeChar.sendPacket(sm); return null; } case TARGET_UNDEAD: { if (target instanceof L2NpcInstance) { if(!((L2NpcInstance)target).isUndead()) { activeChar.sendPacket(new SystemMessage(SystemMessage.TARGET_IS_INCORRECT)); return null; } targetList.add(target); return targetList.toArray(new L2Object[targetList.size()]); } } default: { SystemMessage sm = new SystemMessage(614); sm.addString("Target type of skill is not currently handled"); activeChar.sendPacket(sm); return null; } }//end switch }