Files
zzz_REBIRTH__Utils/Harmony/Harmony_EAISetNearestCorpseAsTarget.cs
2025-06-04 16:44:53 +09:30

104 lines
4.7 KiB
C#

using System.Collections.Generic;
namespace Harmony.EAISetNearestCorpseAsTargetPatches
{
[HarmonyPatch(typeof(EAISetNearestCorpseAsTarget))]
[HarmonyPatch("Continue")]
public class ContinuePatch
{
public static bool Prefix(Block __instance, ref bool __result,
global::EntityAlive ___targetEntity,
global::EntityAlive ___theEntity
)
{
//Log.Out("EAISetNearestCorpseAsTargetPatches-Continue ___targetEntity != null: " + (___targetEntity != null));
if (___targetEntity != null)
{
//Log.Out("EAISetNearestCorpseAsTargetPatches-Continue ___targetEntity.IsDead(): " + (___targetEntity.IsDead()));
//Log.Out("EAISetNearestCorpseAsTargetPatches-Continue !(___targetEntity is EntityZombie): " + (!(___targetEntity is EntityZombie)));
//Log.Out("EAISetNearestCorpseAsTargetPatches-Continue !(___targetEntity != ___theEntity.GetAttackTarget()): " + (!(___targetEntity != ___theEntity.GetAttackTarget())));
}
__result = ___targetEntity && ___targetEntity.IsDead() && !(___targetEntity is EntityZombie) && !(___targetEntity != ___theEntity.GetAttackTarget());
return false;
}
}
[HarmonyPatch(typeof(EAISetNearestCorpseAsTarget))]
[HarmonyPatch("CanExecute")]
public class CanExecutePatch
{
public static bool Prefix(Block __instance, ref bool __result,
ref global::EntityAlive ___targetEntity,
global::EntityAlive ___theEntity,
ref int ___rndTimeout,
float ___maxXZDistance,
EntityFlags ___targetFlags,
ref List<Entity> ___entityList,
EAISetNearestEntityAsTargetSorter ___sorter,
EAIManager ___manager
)
{
//Log.Out("EAISetNearestCorpseAsTargetPatches-CanExecute START");
if (___theEntity.HasInvestigatePosition)
{
//Log.Out("EAISetNearestCorpseAsTargetPatches-CanExecute 1");
__result = false;
return false;
}
if (___theEntity.IsSleeping)
{
//Log.Out("EAISetNearestCorpseAsTargetPatches-CanExecute 2");
__result = false;
return false;
}
if (___rndTimeout > 0 && ___manager.random.RandomRange(___rndTimeout) != 0)
{
//Log.Out("EAISetNearestCorpseAsTargetPatches-CanExecute 3");
__result = false;
return false;
}
global::EntityAlive attackTarget = ___theEntity.GetAttackTarget();
if (attackTarget is EntityPlayer && attackTarget.IsAlive() && ___manager.random.RandomFloat < 0.95f)
{
//Log.Out("EAISetNearestCorpseAsTargetPatches-CanExecute 4");
__result = false;
return false;
}
float radius = ___theEntity.IsSleeper ? 7f : ___maxXZDistance;
___theEntity.world.GetEntitiesAround(___targetFlags, ___targetFlags, ___theEntity.position, radius, ___entityList);
___entityList.Sort(___sorter);
global::EntityAlive entityAlive = null;
for (int i = 0; i < ___entityList.Count; i++)
{
//Log.Out("EAISetNearestCorpseAsTargetPatches-CanExecute i: " + i);
global::EntityAlive entityAlive2 = ___entityList[i] as global::EntityAlive;
if (entityAlive2)
{
//Log.Out("EAISetNearestCorpseAsTargetPatches-CanExecute 5");
if (entityAlive2.IsDead())
{
//Log.Out("EAISetNearestCorpseAsTargetPatches-CanExecute 6");
if (!(___targetEntity is EntityZombie))
{
//Log.Out("EAISetNearestCorpseAsTargetPatches-CanExecute entityAlive: " + entityAlive2.EntityClass.entityClassName);
entityAlive = entityAlive2;
break;
}
}
}
}
___entityList.Clear();
___targetEntity = entityAlive;
__result = ___targetEntity != null;
//Log.Out("EAISetNearestCorpseAsTargetPatches-CanExecute __result: " + __result);
return false;
}
}
}