112 lines
4.3 KiB
C#
112 lines
4.3 KiB
C#
|
|
namespace Harmony.EAITargetPatches
|
|
{
|
|
[HarmonyPatch(typeof(EAITarget))]
|
|
[HarmonyPatch("check")]
|
|
public class EAITarget_checkPatch
|
|
{
|
|
public static bool Prefix(EAITarget __instance, ref bool __result, EntityAlive _e, bool ___bNeedToSee)
|
|
{
|
|
//Log.Out($"EAITargetPatches-check START");
|
|
|
|
if (_e == null || _e == __instance.theEntity)
|
|
{
|
|
|
|
/*//Log.Out($"EAITargetPatches-check _e == null: " + (_e == null));
|
|
//Log.Out($"EAITargetPatches-check _e == __instance.theEntity: " + (_e == __instance.theEntity));*/
|
|
__result = false;
|
|
return false;
|
|
}
|
|
|
|
//Log.Out($"EAITargetPatches-check _e: " + _e.EntityClass.entityClassName);
|
|
//Log.Out($"EAITargetPatches-check __instance.theEntity: " + __instance.theEntity.EntityClass.entityClassName);
|
|
//Log.Out($"EAITargetPatches-check !_e.IsAlive(): " + (!_e.IsAlive()));
|
|
//Log.Out($"EAITargetPatches-check _e.IsIgnoredByAI(): " + (_e.IsIgnoredByAI()));
|
|
|
|
if (!_e.IsAlive() || _e.IsIgnoredByAI())
|
|
{
|
|
//Log.Out($"EAITargetPatches-check 1");
|
|
__result = false;
|
|
return false;
|
|
}
|
|
|
|
if (_e is EntitySupplyCrate)
|
|
{
|
|
//Log.Out($"EAITargetPatches-check 2a");
|
|
if (!__instance.theEntity.Buffs.HasBuff("buffSupplyCrateSpawn"))
|
|
{
|
|
//Log.Out($"EAITargetPatches-check 2b");
|
|
__result = false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
Vector3i blockPos = World.worldToBlockPos(_e.position);
|
|
|
|
if (RebirthVariables.noHit)
|
|
{
|
|
//Log.Out($"EAITargetPatches-check NO HIT source: {__instance.theEntity.EntityName} target: {_e.EntityName}");
|
|
//Log.Out($"EAITargetPatches-check NO HIT CanSee: {__instance.theEntity.CanSee(_e)}");
|
|
}
|
|
|
|
if (!__instance.theEntity.isWithinHomeDistance(blockPos.x, blockPos.y, blockPos.z) || __instance.bNeedToSee && !__instance.theEntity.CanSee(_e))
|
|
{
|
|
//Log.Out($"EAITargetPatches-check 3");
|
|
__result = false;
|
|
return false;
|
|
}
|
|
|
|
EntityPlayer _other = _e as EntityPlayer;
|
|
|
|
if (_other != null && RebirthVariables.noHit)
|
|
{
|
|
//Log.Out($"EAITargetPatches-check NO HIT CanSeeStealth: {__instance.theEntity.CanSeeStealth(__instance.theEntity.GetDistance((Entity)_other), _other.Stealth.lightLevel)}");
|
|
}
|
|
|
|
__result = !(_other != null) || __instance.theEntity.CanSeeStealth(__instance.theEntity.GetDistance((Entity)_other), _other.Stealth.lightLevel);
|
|
|
|
if (RebirthUtilities.IsCurrentRevengeTarget(__instance.theEntity, _e))
|
|
{
|
|
//Log.Out($"EAITargetPatches-check 4");
|
|
__result = true;
|
|
return false;
|
|
}
|
|
|
|
if (__result)
|
|
{
|
|
//Log.Out($"EAITargetPatches-check 5");
|
|
bool shouldAttack = RebirthUtilities.VerifyFactionStanding(__instance.theEntity, _e);
|
|
|
|
//Log.Out($"EAITargetPatches-check 6, shouldAttack: " + shouldAttack);
|
|
|
|
if (!shouldAttack) RebirthUtilities.TeLog($"EAITarget::check - this: {__instance.theEntity}, shouldAttack {shouldAttack}");
|
|
|
|
if (RebirthVariables.noHit)
|
|
{
|
|
//Log.Out($"EAITargetPatches-check NO HIT shouldAttack: {shouldAttack}");
|
|
}
|
|
|
|
__result = shouldAttack;
|
|
}
|
|
|
|
/*if (__result == false)
|
|
{
|
|
bool canSeeStealth = true;
|
|
|
|
if (_other != null)
|
|
{
|
|
canSeeStealth = __instance.theEntity.CanSeeStealth(__instance.theEntity.GetDistance((Entity)_other), _other.Stealth.lightLevel);
|
|
}
|
|
|
|
// player is stealthy so the entity cannot see them at this time
|
|
//RebirthUtilities.TeLog($"EAITarget::check - this: {__instance.theEntity}, entityPlayer: {_other}, canSeeStealth: {canSeeStealth}, player's stealth light level: {_other.Stealth.lightLevel}");
|
|
}*/
|
|
|
|
//Log.Out($"EAITargetPatches-check 7, __result: " + __result);
|
|
|
|
return false;
|
|
|
|
}
|
|
}
|
|
}
|