public static bool HostileEvenIfConfused(GameObject target, GameObject caster) { var targetFaction = target?.GetComponent <Faction>(); var casterFaction = caster?.GetComponent <Faction>(); var targetAiController = GameUtilities.FindActiveAIController(target); if (targetFaction?.IsHostile(caster) == true || casterFaction?.IsHostile(target) == true) { //they're actually hostile return(true); } if (targetAiController == null) { //not AI controller. Can never be confused. return(false); } if (!IEModOptions.TargetTurnedEnemies) { //no more checks if the option is disabled. return(false); } var targetOriginal = targetAiController.GetOriginalTeam()?.GetRelationship(casterFaction?.CurrentTeam) == Faction.Relationship.Hostile; return(targetOriginal); }
public static bool FriendlyRightNowAndAlsoWhenConfused(GameObject target, GameObject caster) { var targetFaction = target?.GetComponent <Faction>(); var casterFaction = caster?.GetComponent <Faction>(); var targetAiController = GameUtilities.FindActiveAIController(target); if (IEModOptions.TargetTurnedEnemies && targetAiController != null && casterFaction != null) { var targetOriginallyFriendly = targetAiController.GetOriginalTeam()?.GetRelationship(casterFaction.CurrentTeam) == Faction.Relationship.Friendly; if (!targetOriginallyFriendly) { return(false); } } return(targetFaction?.IsFriendly(caster) == true || casterFaction?.IsFriendly(target) == true); }
public bool IsValidTargetNew(GameObject target, GameObject caster, TargetType validType) { var confusedArentFriends = IEModOptions.TargetTurnedEnemies; //(original decompiled code:) if (IgnoreValidTargetCheck()) { return(true); } if (target == null) { return(false); } if (caster == null) { caster = Owner; } var component1 = target.GetComponent <Health>(); if (component1 == null || !component1.CanBeTargeted || !target.activeInHierarchy) { return(false); } var activeAiController = GameUtilities.FindActiveAIController(target); if (activeAiController != null && activeAiController.IsBusy) { return(false); } var component2 = target.GetComponent <CharacterStats>(); if (ApplyOnceOnly && m_ability != null && (component2 != null && component2.CountStatusEffects(m_ability) > 0)) { return(false); } var component3 = caster.GetComponent <Faction>(); var targetFaction = target.GetComponent <Faction>(); switch (validType) { case TargetType.All: if (!component1.Unconscious && !component1.Dead) { return(true); } break; case TargetType.Hostile: //(this part is modified) if (component1.Unconscious || component1.Dead) { break; } if ((component3 != null && component3.IsHostile(target)) || (targetFaction != null && targetFaction.IsHostile(caster))) { return(true); } if (confusedArentFriends && activeAiController != null && component3 != null && activeAiController.GetOriginalTeam().GetRelationship(component3.CurrentTeam) == Faction.Relationship.Hostile) { return(true); } break; case TargetType.Friendly: if (component1.Unconscious || component1.Dead) { break; } if (component3 != null && !component3.IsHostile(target) && (targetFaction == null || !targetFaction.IsHostile(caster))) { if (!confusedArentFriends || activeAiController == null || activeAiController.GetOriginalTeam().GetRelationship(component3.CurrentTeam) != Faction.Relationship.Hostile) { return(true); } } break; case TargetType.FriendlyUnconscious: if (component3 != null && component1.Unconscious && !component3.IsHostile(target) && (targetFaction == null || !targetFaction.IsHostile(caster))) { return(true); } break; case TargetType.AllDeadOrUnconscious: if (component1.Unconscious || component1.Dead) { return(true); } break; case TargetType.HostileWithGrimoire: if (component3 != null && component3.IsHostile(target) || targetFaction != null && targetFaction.IsHostile(caster)) { var component5 = target.GetComponent <Equipment>(); if (component5 != null && component5.CurrentItems != null && component5.CurrentItems.Grimoire != null) { return(true); } } break; case TargetType.HostileVessel: if ((component3 != null && component3.IsHostile(target) || targetFaction != null && targetFaction.IsHostile(caster)) && (component2 != null && component2.CharacterRace == CharacterStats.Race.Vessel)) { return(true); } break; case TargetType.HostileBeast: if ((component3 != null && component3.IsHostile(target) || targetFaction != null && targetFaction.IsHostile(caster)) && (component2 != null && component2.CharacterRace == CharacterStats.Race.Beast)) { return(true); } break; case TargetType.Dead: if (component1.Dead) { return(true); } break; case TargetType.Ally: var component6 = caster.GetComponent <PartyMemberAI>(); var component7 = target.GetComponent <PartyMemberAI>(); if (component6 != null && component6.gameObject.activeInHierarchy) { if (component7 != null && component7.gameObject.activeInHierarchy) { return(true); } break; } if (component7 == null || !component7.gameObject.activeInHierarchy) { return(true); } break; case TargetType.AllyNotSelf: if (target != caster && IsValidTarget(target, caster, TargetType.Ally)) { return(true); } break; case TargetType.AllyNotSelfOrHostile: if (IsValidTarget(target, caster, TargetType.Hostile) || IsValidTarget(target, caster, TargetType.AllyNotSelf)) { return(true); } break; case TargetType.NotSelf: if (target != caster && !component1.Unconscious && !component1.Dead) { return(true); } break; case TargetType.DragonOrDrake: if (component2 != null && (component2.CharacterClass == CharacterStats.Class.Drake || component2.CharacterClass == CharacterStats.Class.AdraDragon || component2.CharacterClass == CharacterStats.Class.SkyDragon)) { return(true); } break; case TargetType.FriendlyIncludingCharmed: if (!component1.Unconscious && !component1.Dead) { if (component3 != null && !component3.IsHostile(target)) { return(true); } if (caster != null) { var component5 = caster.GetComponent <Faction>(); if (component5 != null && activeAiController != null) { var originalTeam = activeAiController.GetOriginalTeam(); if (originalTeam != null && originalTeam.GetRelationship(component5.CurrentTeam) != Faction.Relationship.Hostile) { return(true); } } } } break; case TargetType.Self: if (target == caster && !component1.Unconscious && !component1.Dead) { return(true); } break; } return(false); }
public bool mod_IsValidTarget(GameObject target, GameObject caster, TargetType validType) { //+ UNTOUCHED ORIGINAL CODE if (IgnoreValidTargetCheck()) { return(true); } if (target == null) { return(false); } if (caster == null) { caster = Owner; } Health component = target.GetComponent <Health>(); if (component == null || !component.CanBeTargeted || !target.activeInHierarchy) { return(false); } if (component.Dead) { if (!TargetTypeUtils.ValidTargetDead(validType)) { return(false); } } else if (component.Unconscious && !TargetTypeUtils.ValidTargetUnconscious(validType)) { return(false); } AIController aIController = GameUtilities.FindActiveAIController(target); if (aIController != null && aIController.IsBusy) { return(false); } CharacterStats characterStat = target.GetComponent <CharacterStats>(); if (ApplyOnceOnly && m_ability != null && characterStat != null && characterStat.CountStatusEffects(m_ability) > 0) { return(false); } Faction casterFaction = caster.GetComponent <Faction>(); Faction targetFaction = target.GetComponent <Faction>(); //+ END ORIGINAL CODE //!+ MODIFICATIONS //Replaced all appearances of 'faction.IsHostile(target) || component1 != null && component1.IsHostile(caster)' with 'HostileEvenIfConfused(target,caster)' switch (validType) { case TargetType.All: { return(true); } case TargetType.Hostile: { if (HostileEvenIfConfused(target, caster)) { return(true); } break; } case TargetType.Friendly: { if (FriendlyRightNowAndAlsoWhenConfused(target, caster)) { return(true); } break; } case TargetType.FriendlyUnconscious: { if (casterFaction != null && component.Unconscious && !component.Dead && !casterFaction.IsHostile(target) && (targetFaction == null || !targetFaction.IsHostile(caster))) { return(true); } break; } case TargetType.AllDeadOrUnconscious: { if (component.Unconscious || component.Dead) { return(true); } break; } case TargetType.HostileWithGrimoire: { if (HostileEvenIfConfused(target, caster)) { Equipment equipment = target.GetComponent <Equipment>(); if (equipment != null && equipment.CurrentItems != null && equipment.CurrentItems.Grimoire != null) { return(true); } } break; } case TargetType.HostileVessel: { if (HostileEvenIfConfused(target, caster) && characterStat != null && characterStat.CharacterRace == CharacterStats.Race.Vessel) { return(true); } break; } case TargetType.HostileBeast: { if (HostileEvenIfConfused(target, caster) && characterStat != null && characterStat.CharacterRace == CharacterStats.Race.Beast) { return(true); } break; } case TargetType.Dead: { if (component.Dead) { return(true); } break; } case TargetType.Ally: { PartyMemberAI partyMemberAI = caster.GetComponent <PartyMemberAI>(); PartyMemberAI partyMemberAI1 = target.GetComponent <PartyMemberAI>(); if (partyMemberAI != null && partyMemberAI.gameObject.activeInHierarchy) { if (partyMemberAI1 != null && partyMemberAI1.gameObject.activeInHierarchy) { return(true); } } else if (partyMemberAI1 == null || !partyMemberAI1.gameObject.activeInHierarchy) { return(true); } break; } case TargetType.AllyNotSelf: { if (target != caster && IsValidTarget(target, caster, TargetType.Ally)) { return(true); } break; } case TargetType.AllyNotSelfOrHostile: { if (IsValidTarget(target, caster, TargetType.Hostile) || IsValidTarget(target, caster, TargetType.AllyNotSelf)) { return(true); } break; } case TargetType.NotSelf: { if (target != caster) { return(true); } break; } case TargetType.DragonOrDrake: { if (characterStat != null && (characterStat.CharacterClass == CharacterStats.Class.Drake || characterStat.CharacterClass == CharacterStats.Class.AdraDragon || characterStat.CharacterClass == CharacterStats.Class.SkyDragon)) { return(true); } break; } case TargetType.FriendlyIncludingCharmed: { if (!HostileEvenIfConfused(target, caster)) { return(true); } if (caster != null) { if (casterFaction != null && aIController != null) { Team originalTeam = aIController.GetOriginalTeam(); if (originalTeam != null && originalTeam.GetRelationship(casterFaction.CurrentTeam) != Faction.Relationship.Hostile) { return(true); } } } break; } case TargetType.Self: { if (target == caster) { return(true); } break; } case TargetType.FriendlyNotVessel: { if (characterStat != null && characterStat.CharacterRace != CharacterStats.Race.Vessel && !HostileEvenIfConfused(target, caster)) { return(true); } break; } case AttackBase.TargetType.SpiritOrSummonedCreature: { if (characterStat && characterStat.CharacterRace == CharacterStats.Race.Spirit || aIController && aIController.SummonType == AIController.AISummonType.Summoned) { return(true); } break; } case AttackBase.TargetType.OwnAnimalCompanion: { if (aIController.SummonType == AIController.AISummonType.AnimalCompanion && aIController.Summoner == caster) { return(true); } break; } case AttackBase.TargetType.HostileWithNpcAppearance: { NPCAppearance nPCAppearance = target.GetComponent <NPCAppearance>(); if (nPCAppearance && nPCAppearance.isActiveAndEnabled && this.IsValidTarget(target, caster, AttackBase.TargetType.Hostile)) { return(true); } break; } case AttackBase.TargetType.OwnerOfPairedAbility: { PairedAbility pairedAbility = base.GetComponent <PairedAbility>(); if (!pairedAbility) { UIDebug.Instance.LogOnScreenWarning(string.Concat("Ability '", base.name, "' must have a PairedAbility component to use OwnerOfPairedAbility target type."), UIDebug.Department.Design, 10f); return(false); } return(!pairedAbility.OtherAbility ? false : target == pairedAbility.OtherAbility.Owner); } case AttackBase.TargetType.AnyWithResonance: { return(characterStat.CountStatusEffects("resonance", caster) > 0); } } //!+END MODIFICATIONS return(false); }
public virtual List <GameObject> FindAoeTargetsNew(GameObject caster, Vector3 parentForward, Vector3 hitPosition) { bool disableFriendlyFire = PlayerPrefs.GetInt("DisableFriendlyFire", 0) == 1; bool confusedArentFriends = PlayerPrefs.GetInt("TargetTurnedEnemies", 0) == 1; List <GameObject> list = new List <GameObject>(); float num = this.AdjustedBlastRadius; float num2 = num; if (this.ValidTargets == AttackBase.TargetType.All && this.BlastRadius < this.AdjustedBlastRadius) { num = this.BlastRadius; } foreach (Faction current in Faction.ActiveFactionComponents) { if (!(current == null)) { if (!(current.gameObject == base.Owner) || this.DamageAngleDegrees <= 0f || this.DamageAngleDegrees >= 360f) { Vector3 vector = current.transform.position - hitPosition; float sqrMagnitude = vector.sqrMagnitude; if (!this.ExcludeTarget || sqrMagnitude > 1.401298E-45f) { float cachedRadius = current.CachedRadius; float num3 = (num + cachedRadius) * (num + cachedRadius); float num4 = (num2 + cachedRadius) * (num2 + cachedRadius); Vector3 vector2 = vector.normalized; if (this.TargetAngle > 0f) { vector2 = Quaternion.Euler(0f, this.TargetAngle, 0f) * vector2; } float num5 = Vector3.Angle(parentForward, vector2); bool flag = num5 <= this.DamageAngleDegrees * 0.5f; bool flag2 = sqrMagnitude < 1.401298E-45f || (flag && sqrMagnitude <= num4); bool flag3 = sqrMagnitude < 1.401298E-45f || (flag && sqrMagnitude <= num3); if (flag2 && GameUtilities.LineofSight(hitPosition, current.gameObject.transform.position, 1f, false, true)) { if ((this.ValidTargets == TargetType.Friendly || this.ValidTargets == TargetType.FriendlyIncludingCharmed) && !base.IsValidTarget(current.gameObject, caster, AttackBase.TargetType.Hostile) && base.IsValidTarget(current.gameObject, caster)) { if (confusedArentFriends) { Faction casterFaction = caster.GetComponent <Faction>(); var aiController = GameUtilities.FindActiveAIController(current.gameObject); if (aiController == null || aiController.GetOriginalTeam().GetRelationship(casterFaction.CurrentTeam) != Faction.Relationship.Hostile) { list.Add(current.gameObject); } } else { list.Add(current.gameObject); } } else if ( (this.ValidTargets == AttackBase.TargetType.Hostile && !base.IsValidTarget(current.gameObject, caster)) || (!flag3 && this.ValidTargets == TargetType.All && !base.IsValidTarget(current.gameObject, caster, TargetType.Hostile))) { if (IsValidTarget(current.gameObject, caster, TargetType.All) && confusedArentFriends) { Faction casterFaction = caster.GetComponent <Faction>(); var aiController = GameUtilities.FindActiveAIController(current.gameObject); if (aiController != null && aiController.GetOriginalTeam().GetRelationship(casterFaction.CurrentTeam) == Faction.Relationship.Hostile) { list.Add(current.gameObject); } } } else if (this.ValidTargets == AttackBase.TargetType.All && base.IsValidTarget(current.gameObject, caster, AttackBase.TargetType.Hostile)) { Faction casterFaction = caster.GetComponent <Faction>(); if (disableFriendlyFire) { if (!(current.isPartyMember || casterFaction.IsFriendly(current))) { list.Add(current.gameObject); } } else { list.Add(current.gameObject); } } else if (flag3 && base.IsValidTarget(current.gameObject, caster)) { if (disableFriendlyFire) { if (this.ValidTargets == TargetType.All) { Faction casterFaction = caster.GetComponent <Faction>(); if (!(current.isPartyMember || casterFaction.IsFriendly(current))) { list.Add(current.gameObject); } } else { list.Add(current.gameObject); } } else { list.Add(current.gameObject); } } } } } } } int num6 = list.IndexOf(base.Owner); if (num6 > 0) { list[num6] = list[0]; list[0] = base.Owner; } return(list); }
public virtual List <GameObject> FindAoeTargetsNew(GameObject caster, Vector3 parentForward, Vector3 hitPosition) { /* * The purpose of this method is to return a collection of the targets of a given area attack, according to the rules of the game. */ bool disableFriendlyFire = IEModOptions.DisableFriendlyFire; ; bool confusedArentFriends = IEModOptions.TargetTurnedEnemies; var list = new List <GameObject>(); float blastRadius = AdjustedBlastRadius; //note that ajdBlastRadius is the wider blast radius. float adjBlastRadius = blastRadius; if (ValidTargets == TargetType.All && BlastRadius < AdjustedBlastRadius) { blastRadius = BlastRadius; } foreach (Faction current in Faction.ActiveFactionComponents) { if (current == null) { continue; } if (current.gameObject == Owner && !(DamageAngleDegrees <= 0f) && !(DamageAngleDegrees >= 360f)) { continue; } Vector3 vector = current.transform.position - hitPosition; float sqrMagnitude = vector.sqrMagnitude; if (ExcludeTarget && !(sqrMagnitude > float.Epsilon)) { continue; } float cachedRadius = current.CachedRadius; float sqrBlastRadiusPlus = (blastRadius + cachedRadius) * (blastRadius + cachedRadius); float sqrAdjBlastRadiusPlus = (adjBlastRadius + cachedRadius) * (adjBlastRadius + cachedRadius); Vector3 vector2 = vector.normalized; if (TargetAngle > 0f) { vector2 = Quaternion.Euler(0f, TargetAngle, 0f) * vector2; } bool isWithinAngle = Vector3.Angle(parentForward, vector2) <= DamageAngleDegrees * 0.5f; bool isWithinAdjRadius = sqrMagnitude < float.Epsilon || (isWithinAngle && sqrMagnitude <= sqrAdjBlastRadiusPlus); bool isWithinPureRadius = sqrMagnitude < float.Epsilon || (isWithinAngle && sqrMagnitude <= sqrBlastRadiusPlus); if (!isWithinAdjRadius || !GameUtilities.LineofSight(hitPosition, current.gameObject.transform.position, 1f, false, true)) { //if the target isn't even within the adj (wider) radius OR isn't within line of sight (there is cover) //it's not in the target list. continue; } Faction casterFaction = caster.GetComponent <Faction>(); //if isValidForHostile, that means that the target is valid when it is hostile. This means that the AOE is a negative effect var isValidForHostile = IsValidTarget(current.gameObject, caster, TargetType.Hostile); var isValidTarget = IsValidTarget(current.gameObject, caster); var isCurrentFriendly = (current.isPartyMember || casterFaction.IsFriendly(current)); //I tried organizing the code by setting the whole FindActiveAIController thing into a variable, but in some situations it throws NullReferenceExceptions. //these situations seem to be avoided by doing it like this. if ((ValidTargets == TargetType.Friendly || ValidTargets == TargetType.FriendlyIncludingCharmed) && !isValidForHostile && isValidTarget) { if (!confusedArentFriends || (GameUtilities.FindActiveAIController(current.gameObject) ? GameUtilities.FindActiveAIController(current.gameObject).GetOriginalTeam()?.GetRelationship(casterFaction.CurrentTeam) : null) != Faction.Relationship.Hostile) { list.Add(current.gameObject); } } else if ( (ValidTargets == TargetType.Hostile && !isValidTarget) || (!isWithinPureRadius && ValidTargets == TargetType.All && !isValidForHostile)) { if (IsValidTarget(current.gameObject, caster, TargetType.All) && confusedArentFriends && (GameUtilities.FindActiveAIController(current.gameObject) ? GameUtilities.FindActiveAIController(current.gameObject).GetOriginalTeam()?.GetRelationship(casterFaction.CurrentTeam) : null) == Faction.Relationship.Hostile) { list.Add(current.gameObject); } } else if (ValidTargets == TargetType.All && isValidForHostile) { if (!disableFriendlyFire || !isCurrentFriendly) { list.Add(current.gameObject); } } else if (isWithinPureRadius && isValidTarget) { //in this case, if (!disableFriendlyFire || ValidTargets != TargetType.All || !isCurrentFriendly) { list.Add(current.gameObject); } } } int num6 = list.IndexOf(Owner); if (num6 > 0) { list[num6] = list[0]; list[0] = Owner; } return(list); }