include library.ai_lib; include library.buff; include library.pet_lib; include library.target_dummy; include library.utils; //----------------------------------------------------------------------- void clearTargetList() { const obj_id self = getSelf(); utils.removeScriptVarTree(self, "ai.combat.targetSocialGroup.verified"); } //----------------------------------------------------------------------- boolean isValidTarget(obj_id target) { if(!isIdValid(target)) { return false; } boolean result = true; const obj_id self = getSelf(); deltadictionary dict = self.getScriptVars(); const String targetSocialGroupVerified = "ai.combat.targetSocialGroup.verified." + target; if (!pvpCanAttack(self, target)) { // Can't attack this target LOGC(aiLoggingEnabled(self), "debug_ai", "ai_combat_target::isValidTarget() self(" + self + ":" + getName(self) + ") target(" + target + ":" + getName(target) + ") CAN'T ATTACK THIS TARGET"); result = false; } else if ( isGameObjectTypeOf(getTopMostContainer(target), GOT_building_player) && !target_dummy.isTargetDummy(target) ) { // AI not allowed in this structure LOGC(aiLoggingEnabled(self), "debug_ai", "ai_combat_target::isValidTarget() self(" + self + ":" + getName(self) + ") target(" + target + ":" + getName(target) + ") NOT ALLOWED IN STRUCTURE"); result = false; } else if (dict.getBoolean(targetSocialGroupVerified) == false) { const String selfSocialGroup = ai_lib.getSocialGroup(self); if (selfSocialGroup != null && ai_lib.isMob(target)) { if (!isIdValid(getMaster(self)) && !isIdValid(getMaster(target)) && selfSocialGroup.equals(ai_lib.getSocialGroup(target))) { // They are in the same social group LOGC(aiLoggingEnabled(self), "debug_ai", "ai_combat_target::isValidTarget() self(" + self + ":" + getName(self) + ") target(" + target + ":" + getName(target) + ") SAME SOCIAL GROUP"); result = false; } else { // They are not in the same social group dict.put(targetSocialGroupVerified, true); } } } string evasionObjVarName = "me_evasion." + target; if(utils.hasScriptVar(self, evasionObjVarName) && buff.hasBuff(target, "me_evasion_1")) { obj_id[] thoseWhoHateMe = getHateList(self); // Nobody else on my hate list but you, buddy. if(thoseWhoHateMe.length < 2) { // debugSpeakMsg(self, "Valid Target: " + target + " is in evasion mode."); return true; } // debugSpeakMsg(self, "Invalid Target: " + target + " is in evasion mode."); return false; } if(hasObjVar(target, "ai.combat.limitAttackers") && !isPlayer(target) && !pet_lib.hasMaster(target)) { int attackers = getIntObjVar(target, "ai.combat.limitAttackers"); obj_id[] haters = getHateList(target); if(haters.length >= attackers) { int npcCount = 0; for(int i = 0, j = haters.length; i < j; i++) { // Count how many NPC's are in combat with this target. if(isIdValid(haters[i]) && !isPlayer(haters[i]) && !pet_lib.hasMaster(haters[i])) { npcCount++; } // If there are more NPC attackers than the limit, this is a bad target. if(npcCount > attackers) { stopCombat(self); clearHateList(self); return false; } // If the target has me already in its list before the limit is reached, this is a valid target. if(isIdValid(haters[i]) && haters[i] == self) { return true; } } } } return result; }