diff --git a/Mods/0-SCore/Harmony/EAI/EAITarget.cs b/Mods/0-SCore/Harmony/EAI/EAITarget.cs index 9eb9aef7..0ed4d5ea 100644 --- a/Mods/0-SCore/Harmony/EAI/EAITarget.cs +++ b/Mods/0-SCore/Harmony/EAI/EAITarget.cs @@ -48,21 +48,9 @@ public static void Postfix(ref bool __result, EAITarget __instance, global::Enti return; } - // allow an override for the action stuff. If its set here, then use faction targeting. - if (!EntityUtilities.CheckProperty(__instance.theEntity.entityId, "AllEntitiesUseFactionTargeting")) - { - // This patches the check for all entities, so if we're not supposed to use faction - // targeting for everything, stop now. Otherwise, do the faction check. - if (!Configuration.CheckFeatureStatus("AdvancedNPCFeatures", "AllEntitiesUseFactionTargeting")) - { - // Even if *all* entities don't use faction targeting, this entity still should - // if it has one of the UseFactions tags. Only stop now if it doesn't. - if (!EntityUtilities.UseFactions(__instance.theEntity)) - { - return; - } - } - } + if (!EntityUtilities.UseFactionTargeting(__instance.theEntity)) + return; + var myRelationship = FactionManager.Instance.GetRelationshipTier(__instance.theEntity, _e); switch (myRelationship) { diff --git a/Mods/0-SCore/Harmony/NPCFeatures/EntityAlivePatcher.cs b/Mods/0-SCore/Harmony/NPCFeatures/EntityAlivePatcher.cs index d3d87f67..d1c6496b 100644 --- a/Mods/0-SCore/Harmony/NPCFeatures/EntityAlivePatcher.cs +++ b/Mods/0-SCore/Harmony/NPCFeatures/EntityAlivePatcher.cs @@ -50,21 +50,9 @@ public class EntityAliveDamageEntity { private static bool Prefix(global::EntityAlive __instance, ref int __result, DamageSource _damageSource) { + if (!EntityUtilities.UseFactionTargeting(__instance)) + return true; - // allow an override for the action stuff. If its set here, then use faction targeting. - if (!EntityUtilities.CheckProperty(__instance.entityId, "AllEntitiesUseFactionTargeting")) - { - // New feature flag, specific to this feature. - if (!Configuration.CheckFeatureStatus(AdvFeatureClass, "AllEntitiesUseFactionTargeting")) - { - // Even if *all* entities don't use faction damage rules, this entity should - // if it has one of the UseFactions tags. Only stop now if it doesn't. - if (!EntityUtilities.UseFactions(__instance)) - { - return true; - } - } - } if (_damageSource.damageType == EnumDamageTypes.Suicide) return true; @@ -132,6 +120,28 @@ private static bool Prefix( } } + /// + /// Harmony patch to disable the firing of "onSelf[Primary/Secondary]Action[Ray/Graze]Hit" + /// events if the holding entity can't damage the target entity. + /// + [HarmonyPatch(typeof(ItemActionDynamic))] + [HarmonyPatch(nameof(ItemActionDynamic.hitTarget))] + public class ItemActionDynamicHitTarget + { + private static bool Prefix( + ItemActionDynamic __instance, + ItemActionData _actionData, + WorldRayHitInfo hitInfo) + { + if (!EntityUtilities.UseFactionTargeting(_actionData.invData.holdingEntity)) + return true; + + return EntityTargetingUtilities.CanDamage( + _actionData.invData.holdingEntity, + ItemActionAttack.GetEntityFromHit(hitInfo)); + } + } + [HarmonyPatch(typeof(global::EntityAlive))] [HarmonyPatch("SetAttackTarget")] public class EntityAliveSetAttackTarget diff --git a/Mods/0-SCore/Scripts/Entities/EntityUtilities.cs b/Mods/0-SCore/Scripts/Entities/EntityUtilities.cs index 026e075f..2da8fc09 100644 --- a/Mods/0-SCore/Scripts/Entities/EntityUtilities.cs +++ b/Mods/0-SCore/Scripts/Entities/EntityUtilities.cs @@ -123,6 +123,26 @@ public static bool UseFactions(EntityAlive entity) return false; } + /// + /// Returns true if this entity should use faction targeting, according to feature settings, + /// entity properties, or entity tags. + /// + /// + /// + public static bool UseFactionTargeting(EntityAlive entity) + { + return + // allow an override for the action stuff. If its set here, then use faction targeting. + CheckProperty(entity.entityId, "AllEntitiesUseFactionTargeting") || + + // New feature flag, specific to this feature. + Configuration.CheckFeatureStatus(AdvFeatureClass, "AllEntitiesUseFactionTargeting") || + + // Even if *all* entities don't use faction targeting rules, this entity should if it has + // one of the UseFactions tags. + UseFactions(entity); + } + public static void AddBuffToRadius(string strBuff, Vector3 position, int Radius) { // If there's no radius, pick 30 blocks.