1424 lines
65 KiB
C#
1424 lines
65 KiB
C#
using GamePath;
|
|
|
|
namespace Harmony.EntityMoveHelperPatches
|
|
{
|
|
|
|
[HarmonyPatch(typeof(EntityMoveHelper))]
|
|
[HarmonyPatch("StartJump")]
|
|
public class StartJumpPatch
|
|
{
|
|
public static bool Prefix(EntityMoveHelper __instance, bool calcYaw, float distance = 0.0f, float heightDiff = 0.0f)
|
|
{
|
|
//if (__instance.entity.Jumping || !__instance.entity.onGround && !__instance.entity.IsInElevator() || __instance.entity.Electrocuted)
|
|
if (__instance.entity.Jumping || __instance.entity.Climbing || __instance.entity.Electrocuted)
|
|
{
|
|
//Log.Out("EntityMoveHelperPatches-StartJump __instance.entity.Jumping: " + __instance.entity.Jumping);
|
|
//Log.Out("EntityMoveHelperPatches-StartJump __instance.entity.onGround: " + __instance.entity.onGround);
|
|
//Log.Out("EntityMoveHelperPatches-StartJump __instance.entity.fallDistance: " + __instance.entity.fallDistance);
|
|
//Log.Out("EntityMoveHelperPatches-StartJump __instance.entity.IsInElevator(): " + __instance.entity.IsInElevator());
|
|
//Log.Out("EntityMoveHelperPatches-StartJump __instance.entity.Climbing: " + __instance.entity.Climbing);
|
|
//Log.Out("EntityMoveHelperPatches-StartJump __instance.entity.Electrocuted: " + __instance.entity.Electrocuted);
|
|
return false;
|
|
}
|
|
//Log.Out("EntityMoveHelperPatches-StartJump __instance.entity.position: " + __instance.entity.position);
|
|
//Log.Out("EntityMoveHelperPatches-StartJump __instance.moveToPos: " + __instance.moveToPos);
|
|
__instance.JumpToPos = __instance.moveToPos;
|
|
if (__instance.entity.GetAttackTarget() != null && __instance.entity.CanSee(__instance.entity.GetAttackTarget()))
|
|
{
|
|
__instance.JumpToPos = __instance.entity.GetAttackTarget().position;
|
|
}
|
|
//Log.Out("EntityMoveHelperPatches-StartJump __instance.JumpToPos: " + __instance.JumpToPos);
|
|
__instance.jumpYaw = calcYaw ? Mathf.Atan2(__instance.JumpToPos.x - __instance.entity.position.x, __instance.JumpToPos.z - __instance.entity.position.z) * 57.29578f : __instance.entity.rotation.y;
|
|
//Log.Out("EntityMoveHelperPatches-StartJump __instance.jumpYaw: " + __instance.jumpYaw);
|
|
//Log.Out("EntityMoveHelperPatches-StartJump distance: " + distance);
|
|
//Log.Out("EntityMoveHelperPatches-StartJump heightDiff: " + heightDiff);
|
|
|
|
__instance.entity.Jumping = true;
|
|
__instance.entity.SetJumpDistance(distance, heightDiff);
|
|
//Log.Out("EntityMoveHelperPatches-StartJump CLEAR BLOCKED");
|
|
__instance.IsBlocked = false;
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/*[HarmonyPatch(typeof(EntityMoveHelper))]
|
|
[HarmonyPatch("CheckBlocked")]
|
|
public class CheckBlockedPatch
|
|
{
|
|
public static bool Prefix(EntityMoveHelper __instance, Vector3 pos, Vector3 endPos, int baseY)
|
|
{
|
|
Log.Out("EntityMoveHelperPatches-CheckBlocked START");
|
|
__instance.IsBlocked = false;
|
|
Vector3 vector3_1 = pos;
|
|
endPos.y -= 0.01f;
|
|
Vector3 vector3_2 = endPos - vector3_1;
|
|
float num1 = vector3_2.magnitude + 1f / 1000f;
|
|
Vector3 direction = vector3_2 * (1f / num1);
|
|
Ray ray = new Ray(vector3_1 - direction * 0.375f, direction);
|
|
if ((double)num1 > (double)__instance.ccRadius + 0.34999999403953552)
|
|
{
|
|
num1 = __instance.ccRadius + 0.35f;
|
|
if (__instance.isTempMove)
|
|
num1 += 0.4f;
|
|
}
|
|
if (baseY >= 2)
|
|
num1 += 0.21f;
|
|
if (!Voxel.Raycast(__instance.entity.world, ray, (float)((double)num1 - 0.125 + 0.375), 1082195968, 128, 0.125f))
|
|
{
|
|
Log.Out("EntityMoveHelperPatches-CheckBlocked 1");
|
|
return false;
|
|
}
|
|
if (baseY == 0 && (double)Voxel.phyxRaycastHit.normal.y > 0.64300000667572021)
|
|
{
|
|
Vector2 vector2_1;
|
|
vector2_1.x = Voxel.phyxRaycastHit.normal.x;
|
|
vector2_1.y = Voxel.phyxRaycastHit.normal.z;
|
|
vector2_1.Normalize();
|
|
Vector2 vector2_2;
|
|
vector2_2.x = direction.x;
|
|
vector2_2.y = direction.z;
|
|
vector2_2.Normalize();
|
|
if ((double)vector2_2.x * (double)vector2_1.x + (double)vector2_2.y * (double)vector2_1.y < -0.699999988079071)
|
|
{
|
|
Log.Out("EntityMoveHelperPatches-CheckBlocked 2");
|
|
return false;
|
|
}
|
|
}
|
|
if (Voxel.voxelRayHitInfo.hit.blockValue.Block is BlockDamage)
|
|
{
|
|
Log.Out("EntityMoveHelperPatches-CheckBlocked 3");
|
|
return false;
|
|
}
|
|
__instance.HitInfo = Voxel.voxelRayHitInfo.Clone();
|
|
Log.Out("EntityMoveHelperPatches-CheckBlocked SET BLOCKED");
|
|
__instance.IsBlocked = true;
|
|
__instance.blockedHeight = __instance.HitInfo.hit.pos.y - __instance.entity.position.y;
|
|
Vector3 vector3_3 = pos - __instance.HitInfo.hit.pos;
|
|
float sqrMagnitude = vector3_3.sqrMagnitude;
|
|
if ((double)sqrMagnitude >= (double)__instance.blockedDistSq)
|
|
{
|
|
return false;
|
|
}
|
|
__instance.blockedDistSq = sqrMagnitude;
|
|
float num2 = 1f / Mathf.Sqrt(sqrMagnitude);
|
|
float num3 = __instance.ccRadius + 0.4f;
|
|
__instance.tempMoveToPos = vector3_3 * (num2 * num3) + __instance.HitInfo.hit.pos;
|
|
__instance.tempMoveToPos.y = Mathf.MoveTowards(__instance.tempMoveToPos.y, __instance.moveToPos.y, 1f);
|
|
__instance.isTempMove = true;
|
|
__instance.obstacleCheckTickDelay = 12;
|
|
__instance.ResetStuckCheck();
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(EntityMoveHelper))]
|
|
[HarmonyPatch("CheckEntityBlocked")]
|
|
public class CheckEntityBlockedPatch
|
|
{
|
|
public static bool Prefix(EntityMoveHelper __instance, Vector3 pos, Vector3 endPos)
|
|
{
|
|
Log.Out("EntityMoveHelperPatches-CheckEntityBlocked START");
|
|
Vector3 direction = endPos - pos;
|
|
pos.y += 0.7f;
|
|
RaycastHit hitInfo;
|
|
if (!Physics.SphereCast(pos - Origin.position, 0.15f, direction, out hitInfo, 0.8f, 524288))
|
|
return false;
|
|
Transform transform1 = hitInfo.transform;
|
|
if (!(bool)(UnityEngine.Object)transform1)
|
|
return false;
|
|
Transform transform2 = transform1.parent.Find("GameObject");
|
|
if (!(bool)(UnityEngine.Object)transform2)
|
|
return false;
|
|
EntityAlive component = transform2.GetComponent<EntityAlive>();
|
|
if (!(bool)(UnityEngine.Object)component || !((UnityEngine.Object)component != (UnityEngine.Object)__instance.entity))
|
|
return false;
|
|
float sqrMagnitude = (__instance.entity.position - component.position).sqrMagnitude;
|
|
float num = (float)((double)__instance.ccRadius + (double)component.m_characterController.GetRadius() + 0.15999999642372131 + 0.25);
|
|
if ((double)sqrMagnitude >= (double)num * (double)num)
|
|
return false;
|
|
__instance.BlockedEntity = component;
|
|
__instance.blockedEntityDistSq = sqrMagnitude;
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(EntityMoveHelper))]
|
|
[HarmonyPatch("CheckAreaBlocked")]
|
|
public class CheckAreaBlockedPatch
|
|
{
|
|
public static bool Prefix(EntityMoveHelper __instance)
|
|
{
|
|
Log.Out("EntityMoveHelperPatches-CheckAreaBlocked START");
|
|
Vector3 headPosition = __instance.entity.getHeadPosition() with
|
|
{
|
|
y = __instance.entity.position.y
|
|
};
|
|
Vector3 vector3_1 = __instance.moveToPos - headPosition;
|
|
double f = (double)Mathf.Atan2(vector3_1.x, vector3_1.z);
|
|
float num1 = Mathf.Sin((float)f);
|
|
float num2 = Mathf.Cos((float)f);
|
|
vector3_1.Normalize();
|
|
Vector3 vector3_2 = headPosition + vector3_1 * 0.575f;
|
|
for (float num3 = __instance.ccHeight - 0.125f; (double)num3 > 0.22499999403953552; num3 -= 0.25f)
|
|
{
|
|
for (int index = 0; index < 3; ++index)
|
|
{
|
|
double checkEdgeX = (double)EntityMoveHelper.checkEdgeXs[index];
|
|
float num4 = (float)checkEdgeX * num2;
|
|
float num5 = (float)(checkEdgeX * -(double)num1);
|
|
Vector3 pos = headPosition;
|
|
pos.x += num4;
|
|
pos.y += num3;
|
|
pos.z += num5;
|
|
Vector3 endPos = vector3_2;
|
|
endPos.x += num4;
|
|
endPos.y += num3;
|
|
endPos.z += num5;
|
|
__instance.CheckBlocked(pos, endPos, 1);
|
|
if (__instance.IsBlocked)
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(EntityMoveHelper))]
|
|
[HarmonyPatch("CheckBlockedUp")]
|
|
public class CheckBlockedUpPatch
|
|
{
|
|
public static bool Prefix(EntityMoveHelper __instance, Vector3 pos)
|
|
{
|
|
Log.Out("EntityMoveHelperPatches-CheckBlockedUp START");
|
|
__instance.IsBlocked = false;
|
|
Vector3 headPosition = __instance.entity.getHeadPosition() with
|
|
{
|
|
x = pos.x,
|
|
z = pos.z
|
|
};
|
|
headPosition.y -= 0.625f;
|
|
if (!Voxel.Raycast(__instance.entity.world, new Ray(headPosition, Vector3.up), 1f, 1082195968, 128, 0.125f) || Voxel.voxelRayHitInfo.hit.blockValue.Block is BlockDamage)
|
|
{
|
|
return false;
|
|
}
|
|
__instance.HitInfo = Voxel.voxelRayHitInfo.Clone();
|
|
Log.Out("EntityMoveHelperPatches-CheckBlockedUp SET BLOCKED");
|
|
__instance.IsBlocked = true;
|
|
float sqrMagnitude = (pos - __instance.HitInfo.hit.pos).sqrMagnitude;
|
|
if ((double)sqrMagnitude >= (double)__instance.blockedDistSq)
|
|
{
|
|
return false;
|
|
}
|
|
__instance.blockedDistSq = sqrMagnitude;
|
|
__instance.obstacleCheckTickDelay = 12;
|
|
__instance.ResetStuckCheck();
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(EntityMoveHelper))]
|
|
[HarmonyPatch("StopMove")]
|
|
public class StopMovePatch
|
|
{
|
|
public static bool Prefix(EntityMoveHelper __instance)
|
|
{
|
|
__instance.IsActive = false;
|
|
if (!__instance.entity.Jumping || __instance.entity.isSwimming)
|
|
{
|
|
__instance.entity.SetMoveForward(0.0f);
|
|
__instance.entity.SetRotationAndStopTurning(__instance.entity.rotation);
|
|
}
|
|
__instance.expiryTicks = 0;
|
|
__instance.IsBlocked = false;
|
|
__instance.BlockedTime = 0.0f;
|
|
__instance.BlockedEntity = (EntityAlive)null;
|
|
|
|
Log.Out("EntityMoveHelperPatches-StopMove CLEAR BLOCKED");
|
|
Log.Out("StackTrace: '{0}'", Environment.StackTrace);
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(EntityMoveHelper))]
|
|
[HarmonyPatch("CheckWorldBlocked")]
|
|
public class CheckWorldBlockedPatch
|
|
{
|
|
public static bool Prefix(EntityMoveHelper __instance)
|
|
{
|
|
Log.Out("EntityMoveHelperPatches-CheckWorldBlocked START");
|
|
__instance.DamageScale = 1f;
|
|
Vector3 headPosition = __instance.entity.getHeadPosition();
|
|
headPosition.x = (float)((double)__instance.entity.position.x * 0.40000000596046448 + (double)headPosition.x * 0.60000002384185791);
|
|
headPosition.z = (float)((double)__instance.entity.position.z * 0.40000000596046448 + (double)headPosition.z * 0.60000002384185791);
|
|
headPosition.y = __instance.entity.position.y;
|
|
float num1 = Utils.FastClamp(__instance.ccHeight - 0.125f, 0.7f, 1.5f);
|
|
headPosition.y += num1;
|
|
Vector3 moveToPos = __instance.moveToPos with
|
|
{
|
|
y = headPosition.y
|
|
};
|
|
__instance.CheckBlocked(headPosition, moveToPos, (double)num1 >= 1.0 ? 1 : 0);
|
|
if ((double)num1 >= 1.0)
|
|
{
|
|
if (__instance.IsBlocked)
|
|
{
|
|
return false;
|
|
}
|
|
Vector3 pos = headPosition with
|
|
{
|
|
y = (float)((double)__instance.entity.position.y + (double)__instance.entity.stepHeight + 0.125)
|
|
};
|
|
moveToPos.y = pos.y;
|
|
__instance.CheckBlocked(pos, moveToPos, 0);
|
|
if (!__instance.IsBlocked)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
if (!__instance.IsBlocked)
|
|
{
|
|
return false;
|
|
}
|
|
WorldRayHitInfo hitInfo = __instance.HitInfo;
|
|
moveToPos.y = headPosition.y + 1f;
|
|
if ((double)num1 < 1.0)
|
|
headPosition.y += 0.3f;
|
|
__instance.CheckBlocked(headPosition, moveToPos, 2);
|
|
if (__instance.IsBlocked)
|
|
{
|
|
BlockValue blockValue1 = hitInfo.hit.blockValue;
|
|
float num2 = (float)(blockValue1.Block.MaxDamage - blockValue1.damage);
|
|
if (__instance.HitInfo.hit.blockPos.x != Utils.Fastfloor(__instance.moveToPos.x) || __instance.HitInfo.hit.blockPos.z != Utils.Fastfloor(__instance.moveToPos.z))
|
|
{
|
|
__instance.HitInfo = hitInfo;
|
|
}
|
|
else
|
|
{
|
|
BlockValue blockValue2 = __instance.HitInfo.hit.blockValue;
|
|
float num3 = (float)(blockValue2.Block.MaxDamage - blockValue2.damage);
|
|
if ((double)num2 * 0.699999988079071 < (double)num3)
|
|
__instance.HitInfo = hitInfo;
|
|
}
|
|
}
|
|
Log.Out("EntityMoveHelperPatches-CheckWorldBlocked SET BLOCKED");
|
|
__instance.IsBlocked = true;
|
|
|
|
return false;
|
|
}
|
|
}*/
|
|
|
|
[HarmonyPatch(typeof(EntityMoveHelper))]
|
|
[HarmonyPatch("UpdateMoveHelper")]
|
|
|
|
public class UpdateMoveHelperPatch
|
|
{
|
|
public static bool Prefix(EntityMoveHelper __instance)
|
|
{
|
|
if (!__instance.IsActive)
|
|
{
|
|
//if (__instance.entity is EntityNPCRebirth)
|
|
//Log.Out($"UpdateMoveHelper-Prefix this: {__instance.entity}, !__instance.IsActive return false, moveToPos: {__instance.moveToPos}");
|
|
return false;
|
|
}
|
|
if (--__instance.expiryTicks <= 0)
|
|
{
|
|
//if (__instance.entity is EntityNPCRebirth)
|
|
//Log.Out($"UpdateMoveHelper-Prefix this: {__instance.entity}, StopMove()");
|
|
__instance.StopMove();
|
|
}
|
|
else
|
|
{
|
|
__instance.ccHeight = __instance.entity.m_characterController.GetHeight();
|
|
__instance.ccRadius = __instance.entity.m_characterController.GetRadius();
|
|
Vector3 position = __instance.entity.position;
|
|
Vector3 vector3_1 = __instance.moveToPos;
|
|
|
|
//if (__instance.entity is EntityNPCRebirth)
|
|
//{
|
|
//Log.Out($"EntityMoveHelperPatches::Prefix entity: {__instance.entity}, position: {__instance.entity.position}, moveToPos: {__instance.moveToPos}, IsActive: {__instance.IsActive}");
|
|
//Log.Out($"Stacktrace: {System.Environment.StackTrace}");
|
|
//}
|
|
|
|
if (__instance.isTempMove)
|
|
{
|
|
if (!__instance.IsBlocked)
|
|
{
|
|
__instance.isTempMove = false;
|
|
__instance.ResetStuckCheck();
|
|
}
|
|
else
|
|
vector3_1 = __instance.tempMoveToPos;
|
|
}
|
|
bool jumping = __instance.entity.Jumping;
|
|
bool flag1 = jumping || __instance.entity.isSwimming;
|
|
bool flag2 = jumping && !__instance.entity.isSwimming;
|
|
float x1 = vector3_1.x - position.x;
|
|
float z1 = vector3_1.z - position.z;
|
|
float f1 = (float)((double)x1 * (double)x1 + (double)z1 * (double)z1);
|
|
float num1 = vector3_1.y - (position.y + 0.05f);
|
|
bool flag3 = __instance.entity.IsInElevator();
|
|
__instance.isClimb = false;
|
|
if (flag3 && __instance.entity.bCanClimbLadders && (double)f1 < 0.10890001058578491 && (double)num1 > 0.10000000149011612 && !jumping)
|
|
__instance.isClimb = true;
|
|
else if ((double)f1 <= 0.00039999998989515007 && (double)Utils.FastAbs(num1) < 0.25 && !__instance.isTempMove)
|
|
{
|
|
__instance.StopMove();
|
|
return false;
|
|
}
|
|
AvatarController avatarController = __instance.entity.emodel.avatarController;
|
|
if (avatarController.IsRootMotionForced())
|
|
{
|
|
__instance.entity.SetMoveForwardWithModifiers(__instance.moveSpeed, 1f, false);
|
|
__instance.ResetStuckCheck();
|
|
__instance.ClearTempMove();
|
|
__instance.ClearBlocked();
|
|
}
|
|
else if (!flag1 && !__instance.isDigging && !avatarController.IsAnimationWithMotionRunning() || __instance.entity.sleepingOrWakingUp || !__instance.entity.bodyDamage.HasLimbs || !__instance.entity.bodyDamage.CurrentStun.CanMove() || __instance.entity.emodel.IsRagdollActive || avatarController.IsLocomotionPreempted())
|
|
{
|
|
__instance.entity.SetMoveForward(0.0f);
|
|
__instance.ResetStuckCheck();
|
|
__instance.ClearBlocked();
|
|
}
|
|
else
|
|
{
|
|
float y1 = __instance.moveToPos.x - position.x;
|
|
float x2 = __instance.moveToPos.z - position.z;
|
|
float f2 = (float)((double)y1 * (double)y1 + (double)x2 * (double)x2);
|
|
float num2 = __instance.moveToPos.y - (position.y + 0.05f);
|
|
if ((double)num2 < -1.1000000238418579 && (double)f2 <= 0.010000000707805157 && !flag2 && __instance.entity.onGround)
|
|
__instance.DigStart(20);
|
|
if (__instance.isDigging)
|
|
{
|
|
__instance.DigUpdate();
|
|
}
|
|
else
|
|
{
|
|
float num3 = Mathf.Atan2(y1, x2) * 57.29578f;
|
|
__instance.moveToDir = !flag2 ? Mathf.MoveTowardsAngle(__instance.moveToDir, num3, 13f) : num3;
|
|
__instance.entity.emodel.ClearLookAt();
|
|
if (__instance.hasNextPos || (double)f2 >= 0.022500000894069672)
|
|
{
|
|
float yaw = 9999f;
|
|
if (flag2)
|
|
{
|
|
yaw = __instance.jumpYaw;
|
|
}
|
|
else
|
|
{
|
|
float y2 = y1;
|
|
float x3 = x2;
|
|
if (__instance.hasNextPos && (double)f2 <= 2.25)
|
|
{
|
|
float t = Mathf.Sqrt(f2) / 1.5f;
|
|
y2 = Mathf.Lerp(__instance.nextMoveToPos.x, __instance.moveToPos.x, t) - position.x;
|
|
x3 = Mathf.Lerp(__instance.nextMoveToPos.z, __instance.moveToPos.z, t) - position.z;
|
|
}
|
|
if (__instance.focusTicks > 0)
|
|
{
|
|
--__instance.focusTicks;
|
|
y2 = __instance.focusPos.x - position.x;
|
|
x3 = __instance.focusPos.z - position.z;
|
|
}
|
|
if ((double)y2 * (double)y2 + (double)x3 * (double)x3 > 9.9999997473787516E-05)
|
|
yaw = Mathf.Atan2(y2, x3) * 57.29578f;
|
|
}
|
|
if ((double)yaw < 9000.0)
|
|
{
|
|
double num4 = (double)__instance.entity.SeekYaw(yaw, 0.0f, 30f);
|
|
}
|
|
}
|
|
float num5 = Mathf.Abs(Mathf.DeltaAngle(num3, __instance.moveToDir));
|
|
float _speedScale = 1f;
|
|
if (__instance.IsUnreachableAbove && !__instance.entity.IsRunning)
|
|
_speedScale = 1.3f;
|
|
float num6 = num5 - 15f;
|
|
if ((double)num6 > 0.0)
|
|
_speedScale *= 1f - Utils.FastMin(num6 / 30f, 0.8f);
|
|
if ((double)_speedScale > 0.5)
|
|
{
|
|
if ((double)__instance.BlockedTime > 0.10000000149011612)
|
|
_speedScale = 0.5f;
|
|
if (__instance.focusTicks > 0)
|
|
_speedScale = 0.45f;
|
|
}
|
|
if (flag3 && !__instance.entity.onGround)
|
|
_speedScale = 0.5f;
|
|
if (__instance.entity.hasBeenAttackedTime > 0 && (double)__instance.entity.painResistPercent < 1.0)
|
|
_speedScale = 0.1f;
|
|
if (!__instance.hasNextPos && !__instance.isTempMove && !jumping && (double)f1 < 0.36000001430511475 && (double)_speedScale > 0.10000000149011612)
|
|
{
|
|
float num7 = (float)((double)_speedScale * (double)Mathf.Sqrt(f1) / 0.60000002384185791);
|
|
if ((double)num7 < 0.10000000149011612)
|
|
num7 = 0.1f;
|
|
_speedScale = num7;
|
|
}
|
|
bool isBreakingBlocks = __instance.entity.IsBreakingBlocks;
|
|
if (isBreakingBlocks)
|
|
_speedScale = 0.03f;
|
|
|
|
//if (__instance.entity is EntityNPCRebirth)
|
|
//Log.Out($"EntityMoveHelper::UpdateMoveHelper - this: {__instance.entity}, SetMoveForwardWithModifiers moveSpeed: {__instance.moveSpeed}");
|
|
|
|
__instance.entity.SetMoveForwardWithModifiers(__instance.moveSpeed, _speedScale, __instance.isClimb);
|
|
if ((double)_speedScale > 0.0)
|
|
{
|
|
float x4 = x1;
|
|
float z2 = z1;
|
|
float minMotion = 0.02f * _speedScale;
|
|
float maxMotion = 1f;
|
|
if (!__instance.isTempMove)
|
|
{
|
|
if (__instance.entity.entityType == EntityType.Bandit)
|
|
__instance.entity.AddMotion(__instance.moveToDir, (float)((double)__instance.entity.speedForward * (double)_speedScale * 40.0 * 0.019999999552965164));
|
|
if ((double)__instance.SideStepAngle != 0.0)
|
|
{
|
|
double f3 = ((double)__instance.moveToDir + (double)__instance.SideStepAngle) * (Math.PI / 180.0);
|
|
x4 = Mathf.Sin((float)f3);
|
|
z2 = Mathf.Cos((float)f3);
|
|
minMotion = 0.025f;
|
|
maxMotion = 0.06f;
|
|
__instance.moveToPos = Vector3.MoveTowards(__instance.moveToPos, position, 0.0100000007f);
|
|
}
|
|
else if ((double)f1 > 0.42249995470046997)
|
|
{
|
|
double f4 = (double)__instance.moveToDir * (Math.PI / 180.0);
|
|
x4 = Mathf.Sin((float)f4);
|
|
z2 = Mathf.Cos((float)f4);
|
|
}
|
|
}
|
|
__instance.entity.MakeMotionMoveToward(x4, z2, minMotion, maxMotion);
|
|
if (flag3)
|
|
{
|
|
Vector3 normalized = new Vector3(x1, num1, z1).normalized;
|
|
float num8 = Mathf.Pow(__instance.moveSpeed, 0.4f);
|
|
if ((double)num1 > 0.10000000149011612)
|
|
num8 *= 0.7f;
|
|
else if ((double)num1 < -0.10000000149011612)
|
|
num8 *= 1.4f;
|
|
__instance.entity.motion = normalized * (num8 * 0.1f);
|
|
}
|
|
}
|
|
if (flag2)
|
|
return false;
|
|
if (__instance.entity.isSwimming && (double)__instance.entity.swimStrokeRate.x > 0.0)
|
|
{
|
|
--__instance.swimStrokeDelayTicks;
|
|
if (__instance.swimStrokeDelayTicks <= 0)
|
|
{
|
|
__instance.swimStrokeDelayTicks = (int)(20.0 / (double)__instance.random.RandomRange(__instance.entity.swimStrokeRate.x, __instance.entity.swimStrokeRate.y));
|
|
__instance.StartSwimStroke();
|
|
__instance.swimStrokeDelayTicks += 3;
|
|
}
|
|
}
|
|
if (isBreakingBlocks || (double)num5 > 60.0 || (double)_speedScale == 0.0)
|
|
__instance.moveToTicks = 0;
|
|
else if (++__instance.moveToTicks > 6)
|
|
{
|
|
__instance.moveToTicks = 0;
|
|
float num9 = Mathf.Sqrt((float)((double)x1 * (double)x1 + (double)num1 * (double)num1 + (double)z1 * (double)z1));
|
|
float num10 = __instance.moveToDistance - num9;
|
|
if ((double)num10 < 0.020999999716877937)
|
|
{
|
|
if ((double)num10 < -0.0099999997764825821)
|
|
__instance.moveToDistance = num9;
|
|
if (++__instance.moveToFailCnt >= 3)
|
|
{
|
|
bool flag4 = (double)num2 < -1.1000000238418579 && (double)f2 <= 0.64000004529953;
|
|
if (flag4 && __instance.entity.onGround && (double)__instance.random.RandomFloat < 0.60000002384185791)
|
|
{
|
|
__instance.DigStart(80);
|
|
return false;
|
|
}
|
|
__instance.CheckAreaBlocked();
|
|
if (__instance.IsBlocked)
|
|
{
|
|
if ((double)__instance.random.RandomFloat < 0.699999988079071)
|
|
{
|
|
__instance.DamageScale = 6f;
|
|
__instance.obstacleCheckTickDelay = 40;
|
|
return false;
|
|
}
|
|
__instance.StartJump(false, (float)(0.5 + (double)__instance.random.RandomFloat * 0.40000000596046448), 1.3f);
|
|
return false;
|
|
}
|
|
if (flag4)
|
|
return false;
|
|
if ((double)__instance.random.RandomFloat > 0.5)
|
|
{
|
|
if (!__instance.entity.Attack(false))
|
|
return false;
|
|
__instance.entity.Attack(true);
|
|
return false;
|
|
}
|
|
__instance.StartJump(false, (float)(0.699999988079071 + (double)__instance.random.RandomFloat * 0.800000011920929), 1.4f);
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
__instance.moveToDistance = num9;
|
|
if ((double)num10 >= 0.070000000298023224)
|
|
__instance.moveToFailCnt = 0;
|
|
}
|
|
}
|
|
if (!__instance.entity.onGround && !__instance.entity.isSwimming && !flag3 && !__instance.isClimb && ((double)num2 < -0.5 || (double)num2 > 0.5))
|
|
{
|
|
__instance.BlockedTime = 0.0f;
|
|
__instance.BlockedEntity = (EntityAlive)null;
|
|
}
|
|
else if (--__instance.obstacleCheckTickDelay <= 0)
|
|
{
|
|
__instance.obstacleCheckTickDelay = 4;
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper CLEAR BLOCKED A");
|
|
__instance.IsBlocked = false;
|
|
__instance.BlockedEntity = (EntityAlive)null;
|
|
__instance.blockedDistSq = float.MaxValue;
|
|
if (__instance.isClimb)
|
|
__instance.CheckBlockedUp(position);
|
|
else if ((double)num5 < 10.0)
|
|
{
|
|
__instance.CheckEntityBlocked(position, __instance.moveToPos);
|
|
__instance.CheckWorldBlocked();
|
|
__instance.SideStepAngle = 0.0f;
|
|
if (!__instance.IsUnreachableAbove && __instance.hasNextPos && (__instance.IsBlocked || (bool)(UnityEngine.Object)__instance.BlockedEntity))
|
|
{
|
|
__instance.SideStepAngle = __instance.CalcObstacleSideStep();
|
|
if ((double)__instance.SideStepAngle != 0.0)
|
|
{
|
|
__instance.isTempMove = false;
|
|
__instance.BlockedEntity = (EntityAlive)null;
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper CLEAR BLOCKED B");
|
|
__instance.IsBlocked = false;
|
|
}
|
|
}
|
|
if ((bool)(UnityEngine.Object)__instance.BlockedEntity)
|
|
{
|
|
if (!__instance.IsBlocked || (double)__instance.blockedEntityDistSq < (double)__instance.blockedDistSq)
|
|
{
|
|
__instance.moveToTicks = 0;
|
|
if ((double)__instance.random.RandomFloat < 0.10000000149011612)
|
|
{
|
|
if (__instance.BlockedEntity.moveHelper != null && __instance.BlockedEntity.moveHelper.IsBlocked)
|
|
__instance.StartJump(false, 0.7f, __instance.BlockedEntity.height * 0.8f);
|
|
}
|
|
else
|
|
__instance.Push(__instance.BlockedEntity);
|
|
}
|
|
}
|
|
else if ((__instance.IsBlocked || !__instance.hasNextPos) && (double)num2 < -1.5 && (double)f2 >= 2.25 && __instance.entity.onGround)
|
|
{
|
|
float num11 = Mathf.Sqrt(f2 + num2 * num2) + 1f / 1000f;
|
|
if ((double)num2 / (double)num11 < -0.86000001430511475)
|
|
__instance.DigStart(160);
|
|
}
|
|
}
|
|
}
|
|
if (__instance.IsBlocked)
|
|
{
|
|
__instance.BlockedTime += 0.05f;
|
|
}
|
|
else
|
|
{
|
|
__instance.BlockedTime = 0.0f;
|
|
}
|
|
if (!__instance.entity.CanEntityJump() || __instance.isClimb || flag1)
|
|
return false;
|
|
|
|
float distance = 0.0f;
|
|
float heightDiff = 0.9f;
|
|
|
|
// NEW CODE _START
|
|
float numHeight = 0f;
|
|
|
|
if (__instance.entity is EntityZombieSDX)
|
|
{
|
|
EntityZombieSDX myEntity = (EntityZombieSDX)__instance.entity;
|
|
|
|
if (myEntity.flMaxJumpHeight > 1)
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper __instance.BlockedTime: " + __instance.BlockedTime);
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper ___blockedHeight: " + ___blockedHeight);
|
|
|
|
bool bIsAir = false;
|
|
|
|
if (__instance.HitInfo != null)
|
|
{
|
|
int numAir = 0;
|
|
for (int i = 0; i < (int)myEntity.flMaxJumpHeight + (int)myEntity.flMaxJumpSize; i++)
|
|
{
|
|
Vector3i blockPos = __instance.HitInfo.hit.blockPos;
|
|
Vector3i EntityPos = Vector3i.zero;
|
|
|
|
EntityPos.x = (int)myEntity.position.x;
|
|
EntityPos.z = (int)myEntity.position.z;
|
|
EntityPos.y = (int)myEntity.position.y + i;
|
|
|
|
blockPos.y = (int)myEntity.position.y + i;
|
|
|
|
BlockValue block1 = __instance.entity.world.GetBlock(blockPos);
|
|
BlockValue block2 = __instance.entity.world.GetBlock(EntityPos);
|
|
|
|
if (!block2.isair)
|
|
{
|
|
break;
|
|
}
|
|
|
|
if (block1.isair)
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper IS AIR");
|
|
numAir++;
|
|
if (numAir == (int)myEntity.flMaxJumpSize)
|
|
{
|
|
numHeight = i;
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper GetBlockName: " + block.Block.GetBlockName());
|
|
numAir = 0;
|
|
}
|
|
}
|
|
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper numAir: " + numAir);
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper myEntity.flMaxJumpSize: " + myEntity.flMaxJumpSize);
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper myEntity.flMaxJumpHeight: " + myEntity.flMaxJumpHeight);
|
|
|
|
if (numAir >= (int)myEntity.flMaxJumpSize)
|
|
{
|
|
bIsAir = true;
|
|
}
|
|
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper ENTITY, X: " + myEntity.position.x);
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper ENTITY, Y: " + myEntity.position.y);
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper ENTITY, Z: " + myEntity.position.z);
|
|
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper BLOCK , X: " + blockPos.x);
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper BLOCK , Y: " + blockPos.y);
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper BLOCK , Z: " + blockPos.z);
|
|
|
|
if (!bIsAir)
|
|
{
|
|
distance = 0;
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper IS AIR");
|
|
if (__instance.BlockedTime > 0.15f)
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper Jump 2a");
|
|
distance = 0.55f + __instance.random.RandomFloat * 0.3f;
|
|
}
|
|
else if (num2 > 1.5f && f2 <= 0.040000003f && __instance.random.RandomFloat < 0.1f)
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper Jump 3a");
|
|
distance = 0.02f;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
distance = 0;
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (__instance.BlockedTime > 0.15f && __instance.blockedHeight < myEntity.flMaxJumpHeight)
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper Jump 2b");
|
|
distance = 0.55f + __instance.random.RandomFloat * 0.3f;
|
|
}
|
|
else if (num2 > 1.5f && f2 <= 0.040000003f && __instance.random.RandomFloat < 0.1f)
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper Jump 3b");
|
|
distance = 0.02f;
|
|
}
|
|
}
|
|
}
|
|
// NEW CODE - END
|
|
else if ((double)__instance.BlockedTime > 0.15000000596046448 && (double)__instance.blockedHeight < 1.0)
|
|
distance = (float)(0.550000011920929 + (double)__instance.random.RandomFloat * 0.30000001192092896);
|
|
else if ((double)num2 > 1.5 && (double)f2 <= 0.040000002831220627 && (double)__instance.random.RandomFloat < 0.10000000149011612)
|
|
distance = 0.02f;
|
|
|
|
if (__instance.IsUnreachableSideJump && (double)num5 < 25.0)
|
|
{
|
|
PathEntity path = __instance.entity.navigator.getPath();
|
|
if (path == null || path.NodeCountRemaining() <= 1)
|
|
{
|
|
Vector3 vector3_2 = __instance.entity.position + __instance.entity.GetForwardVector() * 0.2f;
|
|
vector3_2.y += 0.4f;
|
|
RaycastHit hitInfo;
|
|
if (!Physics.Raycast(vector3_2 - Origin.position, Vector3.down, out hitInfo, 3.4f, 1082195968) || (double)hitInfo.distance > 2.2000000476837158)
|
|
{
|
|
distance = __instance.entity.jumpMaxDistance;
|
|
heightDiff = __instance.UnreachablePos.y - __instance.entity.position.y;
|
|
}
|
|
}
|
|
}
|
|
if ((double)distance <= 0.0)
|
|
return false;
|
|
Vector3i vector3i = new Vector3i(Utils.Fastfloor(position.x), Utils.Fastfloor(position.y + 2.35f), Utils.Fastfloor(position.z));
|
|
BlockValue block = __instance.entity.world.GetBlock(vector3i);
|
|
if (!block.Block.IsMovementBlocked((IBlockAccess)__instance.entity.world, vector3i, block, BlockFace.None))
|
|
{
|
|
//NEW CODE - START
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper IS BLOCKED block: " + block.Block.GetBlockName());
|
|
if (__instance.entity is EntityNPCRebirth && block.Block.GetBlockName() == "air" && !__instance.IsBlocked)
|
|
{
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper IS BLOCKED block: " + block.Block.GetBlockName());
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper IS BLOCKED num22: " + num22);
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper IS BLOCKED heightDiff: " + heightDiff);
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper IS BLOCKED ___blockedHeight: " + ___blockedHeight);
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper IS BLOCKED numHeight: " + numHeight);
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper IS BLOCKED ___jumpYaw: " + ___jumpYaw);
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper IS BLOCKED __instance.IsBlocked: " + __instance.IsBlocked);
|
|
__instance.IsUnreachableSideJump = false;
|
|
return false;
|
|
}
|
|
//NEW CODE - END
|
|
__instance.StartJump(true, distance, heightDiff);
|
|
if (__instance.IsUnreachableSideJump)
|
|
{
|
|
__instance.UnreachablePercent += 0.1f;
|
|
__instance.IsDestroyAreaTryUnreachable = true;
|
|
}
|
|
}
|
|
__instance.IsUnreachableSideJump = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/*public static MethodInfo ResetStuckCheck = AccessTools.Method(typeof(global::EntityMoveHelper), "ResetStuckCheck", new Type[] { });
|
|
public static MethodInfo DigStart = AccessTools.Method(typeof(global::EntityMoveHelper), "DigStart", new Type[] { typeof(int) });
|
|
public static MethodInfo DigUpdate = AccessTools.Method(typeof(global::EntityMoveHelper), "DigUpdate", new Type[] { });
|
|
public static MethodInfo StartSwimStroke = AccessTools.Method(typeof(global::EntityMoveHelper), "StartSwimStroke", new Type[] { });
|
|
public static MethodInfo CheckAreaBlocked = AccessTools.Method(typeof(global::EntityMoveHelper), "CheckAreaBlocked", new Type[] { });
|
|
public static MethodInfo Push = AccessTools.Method(typeof(global::EntityMoveHelper), "Push", new Type[] { typeof(global::EntityAlive) });
|
|
public static MethodInfo CheckBlockedUp = AccessTools.Method(typeof(global::EntityMoveHelper), "CheckBlockedUp", new Type[] { typeof(Vector3) });
|
|
public static MethodInfo CheckEntityBlocked = AccessTools.Method(typeof(global::EntityMoveHelper), "CheckEntityBlocked", new Type[] { typeof(Vector3), typeof(Vector3) });
|
|
public static MethodInfo CheckWorldBlocked = AccessTools.Method(typeof(global::EntityMoveHelper), "CheckWorldBlocked", new Type[] { });
|
|
public static MethodInfo CalcObstacleSideStep = AccessTools.Method(typeof(global::EntityMoveHelper), "CalcObstacleSideStep", new Type[] { });
|
|
public static MethodInfo StartJump = AccessTools.Method(typeof(global::EntityMoveHelper), "StartJump", new Type[] { typeof(bool), typeof(float), typeof(float) });
|
|
|
|
public static bool Prefix(ref global::EntityMoveHelper __instance,
|
|
ref global::EntityAlive __instance.entity,
|
|
ref int ___moveToFailCnt,
|
|
ref int ___moveToTicks,
|
|
ref int ___expiryTicks,
|
|
ref float ___ccHeight,
|
|
ref float ___ccRadius,
|
|
ref bool ___isTempMove,
|
|
ref Vector3 ___moveToPos,
|
|
ref Vector3 ___tempMoveToPos,
|
|
ref bool ___isClimb,
|
|
float ___moveSpeed,
|
|
bool ___hasNextPos,
|
|
ref bool ___isDigging,
|
|
ref float ___moveToDir,
|
|
ref float ___jumpYaw,
|
|
Vector3 ___nextMoveToPos,
|
|
ref int ___focusTicks,
|
|
Vector3 ___focusPos,
|
|
ref int ___swimStrokeDelayTicks,
|
|
ref float ___moveToDistance,
|
|
ref int ___obstacleCheckTickDelay,
|
|
ref float ___blockedDistSq,
|
|
ref float ___blockedEntityDistSq,
|
|
ref float ___blockedHeight,
|
|
GameRandom ___random,
|
|
ref float ___SideStepAngle,
|
|
ref Vector3 ___digStartPos,
|
|
ref float ___digForTicks,
|
|
bool ___CanBreakBlocks,
|
|
ref float ___digTicks,
|
|
ref float ___digActionTicks,
|
|
ref bool ___digAttacked,
|
|
ref float ___digForwardCount,
|
|
ref Vector3 ___JumpToPos,
|
|
ref WorldRayHitInfo ___HitInfo,
|
|
ref DamageResponse ___damageResponse
|
|
)
|
|
{
|
|
if (!__instance.IsActive)
|
|
{
|
|
return false;
|
|
}
|
|
int num = ___expiryTicks - 1;
|
|
___expiryTicks = num;
|
|
if (num <= 0)
|
|
{
|
|
__instance.Stop();
|
|
return false;
|
|
}
|
|
___ccHeight = __instance.entity.m_characterController.GetHeight();
|
|
___ccRadius = __instance.entity.m_characterController.GetRadius();
|
|
Vector3 position = __instance.entity.position;
|
|
Vector3 vector = ___moveToPos;
|
|
if (___isTempMove)
|
|
{
|
|
if (!__instance.IsBlocked)
|
|
{
|
|
___isTempMove = false;
|
|
ResetStuckCheck.Invoke(__instance, new object[] { });
|
|
}
|
|
else
|
|
{
|
|
vector = ___tempMoveToPos;
|
|
}
|
|
}
|
|
bool jumping = __instance.entity.Jumping;
|
|
bool flag = jumping || __instance.entity.isSwimming;
|
|
bool flag2 = jumping && !__instance.entity.isSwimming;
|
|
float num2 = vector.x - position.x;
|
|
float num3 = vector.z - position.z;
|
|
float num4 = num2 * num2 + num3 * num3;
|
|
float num5 = vector.y - (position.y + 0.05f);
|
|
bool flag3 = __instance.entity.IsInElevator();
|
|
|
|
___isClimb = false;
|
|
if (flag3 && __instance.entity.bCanClimbLadders && num4 < 0.10890001f && num5 > 0.1f && !jumping)
|
|
{
|
|
___isClimb = true;
|
|
}
|
|
else if (num4 <= 0.0004f && Utils.FastAbs(num5) < 0.25f && !___isTempMove)
|
|
{
|
|
__instance.Stop();
|
|
return false;
|
|
}
|
|
AvatarController avatarController = __instance.entity.emodel.avatarController;
|
|
if (avatarController.IsRootMotionForced())
|
|
{
|
|
__instance.entity.SetMoveForwardWithModifiers(___moveSpeed, 1f, false);
|
|
ResetStuckCheck.Invoke(__instance, new object[] { });
|
|
__instance.ClearTempMove();
|
|
__instance.ClearBlocked();
|
|
return false;
|
|
}
|
|
if ((!flag && !___isDigging && !avatarController.IsAnimationWithMotionRunning()) || __instance.entity.sleepingOrWakingUp || !__instance.entity.bodyDamage.HasLimbs || !__instance.entity.bodyDamage.CurrentStun.CanMove() || __instance.entity.emodel.IsRagdollActive || avatarController.IsLocomotionPreempted())
|
|
{
|
|
__instance.entity.SetMoveForward(0f);
|
|
ResetStuckCheck.Invoke(__instance, new object[] { });
|
|
__instance.ClearBlocked();
|
|
return false;
|
|
}
|
|
float num6 = ___moveToPos.x - position.x;
|
|
float num7 = ___moveToPos.z - position.z;
|
|
float num8 = num6 * num6 + num7 * num7;
|
|
float num9 = ___moveToPos.y - (position.y + 0.05f);
|
|
if (num9 < -1.1f && num8 <= 0.010000001f && !flag2 && __instance.entity.onGround)
|
|
{
|
|
DigStart.Invoke(__instance, new object[] { 20 });
|
|
}
|
|
if (___isDigging)
|
|
{
|
|
DigUpdate.Invoke(__instance, new object[] { });
|
|
return false;
|
|
}
|
|
float num10 = Mathf.Atan2(num6, num7) * 57.29578f;
|
|
if (flag2)
|
|
{
|
|
___moveToDir = num10;
|
|
}
|
|
else
|
|
{
|
|
___moveToDir = Mathf.MoveTowardsAngle(___moveToDir, num10, 13f);
|
|
}
|
|
__instance.entity.emodel.ClearLookAt();
|
|
if (___hasNextPos || num8 >= 0.0225f)
|
|
{
|
|
float num11 = 9999f;
|
|
if (flag2)
|
|
{
|
|
num11 = ___jumpYaw;
|
|
}
|
|
else
|
|
{
|
|
float num12 = num6;
|
|
float num13 = num7;
|
|
if (___hasNextPos && num8 <= 2.25f)
|
|
{
|
|
float t = Mathf.Sqrt(num8) / 1.5f;
|
|
num12 = Mathf.Lerp(___nextMoveToPos.x, ___moveToPos.x, t) - position.x;
|
|
num13 = Mathf.Lerp(___nextMoveToPos.z, ___moveToPos.z, t) - position.z;
|
|
}
|
|
if (___focusTicks > 0)
|
|
{
|
|
___focusTicks--;
|
|
num12 = ___focusPos.x - position.x;
|
|
num13 = ___focusPos.z - position.z;
|
|
}
|
|
if (num12 * num12 + num13 * num13 > 0.0001f)
|
|
{
|
|
num11 = Mathf.Atan2(num12, num13) * 57.29578f;
|
|
}
|
|
}
|
|
if (num11 < 9000f)
|
|
{
|
|
__instance.entity.SeekYaw(num11, 0f, 30f);
|
|
}
|
|
}
|
|
float num14 = Mathf.Abs(Mathf.DeltaAngle(num10, ___moveToDir));
|
|
float num15 = 1f;
|
|
if (__instance.IsUnreachableAbove && !__instance.entity.IsRunning)
|
|
{
|
|
num15 = 1.3f;
|
|
}
|
|
float num16 = num14 - 15f;
|
|
if (num16 > 0f)
|
|
{
|
|
num15 *= 1f - Utils.FastMin(num16 / 30f, 0.8f);
|
|
}
|
|
if (num15 > 0.5f)
|
|
{
|
|
if (__instance.BlockedTime > 0.1f)
|
|
{
|
|
num15 = 0.5f;
|
|
}
|
|
if (___focusTicks > 0)
|
|
{
|
|
num15 = 0.45f;
|
|
}
|
|
}
|
|
if (flag3 && !__instance.entity.onGround)
|
|
{
|
|
num15 = 0.5f;
|
|
}
|
|
if (__instance.entity.hasBeenAttackedTime > 0 && __instance.entity.painResistPercent < 1f)
|
|
{
|
|
num15 = 0.1f;
|
|
}
|
|
if (!___hasNextPos && !___isTempMove && !jumping && num4 < 0.36f && num15 > 0.1f)
|
|
{
|
|
float num17 = num15 * Mathf.Sqrt(num4) / 0.6f;
|
|
if (num17 < 0.1f)
|
|
{
|
|
num17 = 0.1f;
|
|
}
|
|
num15 = num17;
|
|
}
|
|
bool isBreakingBlocks = __instance.entity.IsBreakingBlocks;
|
|
if (isBreakingBlocks)
|
|
{
|
|
num15 = 0.03f;
|
|
}
|
|
__instance.entity.SetMoveForwardWithModifiers(___moveSpeed, num15, ___isClimb);
|
|
if (num15 > 0f)
|
|
{
|
|
float x = num2;
|
|
float z = num3;
|
|
float minMotion = 0.02f * num15;
|
|
float maxMotion = 1f;
|
|
if (!___isTempMove)
|
|
{
|
|
if (__instance.entity.entityType == EntityType.Bandit)
|
|
{
|
|
__instance.entity.AddMotion(___moveToDir, __instance.entity.speedForward * num15 * 40f * 0.02f);
|
|
}
|
|
if (__instance.SideStepAngle != 0f)
|
|
{
|
|
float f = (___moveToDir + __instance.SideStepAngle) * 0.017453292f;
|
|
x = Mathf.Sin(f);
|
|
z = Mathf.Cos(f);
|
|
minMotion = 0.025f;
|
|
maxMotion = 0.06f;
|
|
___moveToPos = Vector3.MoveTowards(___moveToPos, position, 0.010000001f);
|
|
}
|
|
else if (num4 > 0.42249995f)
|
|
{
|
|
float f2 = ___moveToDir * 0.017453292f;
|
|
x = Mathf.Sin(f2);
|
|
z = Mathf.Cos(f2);
|
|
}
|
|
}
|
|
__instance.entity.MakeMotionMoveToward(x, z, minMotion, maxMotion);
|
|
if (flag3)
|
|
{
|
|
Vector3 vector2 = new Vector3(num2, num5, num3).normalized;
|
|
float num18 = Mathf.Pow(___moveSpeed, 0.4f);
|
|
if (num5 > 0.1f)
|
|
{
|
|
num18 *= 0.7f;
|
|
}
|
|
else if (num5 < -0.1f)
|
|
{
|
|
num18 *= 1.4f;
|
|
}
|
|
vector2 *= num18 * 0.1f;
|
|
__instance.entity.motion = vector2;
|
|
}
|
|
}
|
|
if (flag2)
|
|
{
|
|
return false;
|
|
}
|
|
if (__instance.entity.isSwimming && __instance.entity.swimStrokeRate.x > 0f)
|
|
{
|
|
___swimStrokeDelayTicks--;
|
|
if (___swimStrokeDelayTicks <= 0)
|
|
{
|
|
___swimStrokeDelayTicks = (int)(20f / ___random.RandomRange(__instance.entity.swimStrokeRate.x, __instance.entity.swimStrokeRate.y));
|
|
StartSwimStroke.Invoke(__instance, new object[] { });
|
|
|
|
___swimStrokeDelayTicks += 3;
|
|
}
|
|
}
|
|
if (isBreakingBlocks || num14 > 60f || num15 == 0f)
|
|
{
|
|
___moveToTicks = 0;
|
|
}
|
|
else
|
|
{
|
|
num = ___moveToTicks + 1;
|
|
___moveToTicks = num;
|
|
if (num > 6)
|
|
{
|
|
___moveToTicks = 0;
|
|
float num19 = Mathf.Sqrt(num2 * num2 + num5 * num5 + num3 * num3);
|
|
float num20 = ___moveToDistance - num19;
|
|
if (num20 < 0.021f)
|
|
{
|
|
if (num20 < -0.01f)
|
|
{
|
|
___moveToDistance = num19;
|
|
}
|
|
num = ___moveToFailCnt + 1;
|
|
___moveToFailCnt = num;
|
|
if (num >= 3)
|
|
{
|
|
bool flag4 = num9 < -1.1f && num8 <= 0.64000005f;
|
|
if (flag4 && __instance.entity.onGround && ___random.RandomFloat < 0.6f)
|
|
{
|
|
DigStart.Invoke(__instance, new object[] { 80 });
|
|
return false;
|
|
}
|
|
CheckAreaBlocked.Invoke(__instance, new object[] { });
|
|
|
|
if (__instance.IsBlocked)
|
|
{
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper IS BLOCKED A");
|
|
if (___random.RandomFloat < 0.7f)
|
|
{
|
|
__instance.DamageScale = 6f;
|
|
___obstacleCheckTickDelay = 40;
|
|
return false;
|
|
}
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper StartJump A");
|
|
StartJump.Invoke(__instance, new object[] { false, 0.5f + ___random.RandomFloat * 0.4f, 1.3f });
|
|
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
if (flag4)
|
|
{
|
|
return false;
|
|
}
|
|
if (___random.RandomFloat > 0.5f)
|
|
{
|
|
if (__instance.entity.Attack(false))
|
|
{
|
|
__instance.entity.Attack(true);
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper IS BLOCKED B");
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper StartJump B");
|
|
StartJump.Invoke(__instance, new object[] { false, 0.7f + ___random.RandomFloat * 0.8f, 1.4f });
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
___moveToDistance = num19;
|
|
if (num20 >= 0.07f)
|
|
{
|
|
___moveToFailCnt = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!__instance.entity.onGround && !__instance.entity.isSwimming && !flag3 && !___isClimb && (num9 < -0.5f || num9 > 0.5f))
|
|
{
|
|
__instance.BlockedTime = 0f;
|
|
__instance.BlockedEntity = null;
|
|
}
|
|
else
|
|
{
|
|
num = ___obstacleCheckTickDelay - 1;
|
|
___obstacleCheckTickDelay = num;
|
|
if (num <= 0)
|
|
{
|
|
___obstacleCheckTickDelay = 4;
|
|
__instance.IsBlocked = false;
|
|
__instance.BlockedEntity = null;
|
|
___blockedDistSq = float.MaxValue;
|
|
if (___isClimb)
|
|
{
|
|
CheckBlockedUp.Invoke(__instance, new object[] { position });
|
|
|
|
}
|
|
else if (num14 < 10f)
|
|
{
|
|
CheckEntityBlocked.Invoke(__instance, new object[] { position, ___moveToPos });
|
|
CheckWorldBlocked.Invoke(__instance, new object[] { });
|
|
|
|
__instance.SideStepAngle = 0f;
|
|
if (!__instance.IsUnreachableAbove && ___hasNextPos && (__instance.IsBlocked || __instance.BlockedEntity))
|
|
{
|
|
CalcObstacleSideStep.Invoke(__instance, new object[] { });
|
|
|
|
if (__instance.SideStepAngle != 0f)
|
|
{
|
|
___isTempMove = false;
|
|
__instance.BlockedEntity = null;
|
|
__instance.IsBlocked = false;
|
|
}
|
|
}
|
|
if (__instance.BlockedEntity)
|
|
{
|
|
if (!__instance.IsBlocked || ___blockedEntityDistSq < ___blockedDistSq)
|
|
{
|
|
___moveToTicks = 0;
|
|
if (___random.RandomFloat < 0.1f)
|
|
{
|
|
if (__instance.BlockedEntity.moveHelper != null && __instance.BlockedEntity.moveHelper.IsBlocked)
|
|
{
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper IS BLOCKED C");
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper StartJump C");
|
|
StartJump.Invoke(__instance, new object[] { false, 0.7f, __instance.BlockedEntity.height * 0.8f });
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Push.Invoke(__instance, new object[] { __instance.BlockedEntity });
|
|
|
|
}
|
|
}
|
|
}
|
|
else if ((__instance.IsBlocked || !___hasNextPos) && num9 < -1.5f && num8 >= 2.25f && __instance.entity.onGround)
|
|
{
|
|
float num21 = Mathf.Sqrt(num8 + num9 * num9) + 0.001f;
|
|
if (num9 / num21 < -0.86f)
|
|
{
|
|
DigStart.Invoke(__instance, new object[] { 160 });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (__instance.IsBlocked)
|
|
{
|
|
__instance.BlockedTime += 0.05f;
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper 4");
|
|
__instance.BlockedTime = 0f;
|
|
}
|
|
if (__instance.entity.CanEntityJump() && !___isClimb && !flag)
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper Jump 1");
|
|
|
|
float num22 = 0f;
|
|
float heightDiff = 0.9f;
|
|
int numHeight = 0;
|
|
|
|
if (__instance.entity is EntityZombieSDX)
|
|
{
|
|
EntityZombieSDX myEntity = (EntityZombieSDX)__instance.entity;
|
|
|
|
if (myEntity.flMaxJumpHeight > 1)
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper __instance.BlockedTime: " + __instance.BlockedTime);
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper ___blockedHeight: " + ___blockedHeight);
|
|
|
|
bool bIsAir = false;
|
|
|
|
if (__instance.HitInfo != null)
|
|
{
|
|
int numAir = 0;
|
|
for (int i = 0; i < (int)myEntity.flMaxJumpHeight + (int)myEntity.flMaxJumpSize; i++)
|
|
{
|
|
Vector3i blockPos = __instance.HitInfo.hit.blockPos;
|
|
Vector3i EntityPos = Vector3i.zero;
|
|
|
|
EntityPos.x = (int)myEntity.position.x;
|
|
EntityPos.z = (int)myEntity.position.z;
|
|
EntityPos.y = (int)myEntity.position.y + i;
|
|
|
|
blockPos.y = (int)myEntity.position.y + i;
|
|
|
|
BlockValue block = __instance.entity.world.GetBlock(blockPos);
|
|
BlockValue block2 = __instance.entity.world.GetBlock(EntityPos);
|
|
|
|
if (!block2.isair)
|
|
{
|
|
break;
|
|
}
|
|
|
|
if (block.isair)
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper IS AIR");
|
|
numAir++;
|
|
if (numAir == (int)myEntity.flMaxJumpSize)
|
|
{
|
|
numHeight = i;
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper GetBlockName: " + block.Block.GetBlockName());
|
|
numAir = 0;
|
|
}
|
|
}
|
|
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper numAir: " + numAir);
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper myEntity.flMaxJumpSize: " + myEntity.flMaxJumpSize);
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper myEntity.flMaxJumpHeight: " + myEntity.flMaxJumpHeight);
|
|
|
|
if (numAir >= (int)myEntity.flMaxJumpSize)
|
|
{
|
|
bIsAir = true;
|
|
}
|
|
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper ENTITY, X: " + myEntity.position.x);
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper ENTITY, Y: " + myEntity.position.y);
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper ENTITY, Z: " + myEntity.position.z);
|
|
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper BLOCK , X: " + blockPos.x);
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper BLOCK , Y: " + blockPos.y);
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper BLOCK , Z: " + blockPos.z);
|
|
|
|
if (!bIsAir)
|
|
{
|
|
num22 = 0;
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper IS AIR");
|
|
if (__instance.BlockedTime > 0.15f)
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper Jump 2a");
|
|
num22 = 0.55f + ___random.RandomFloat * 0.3f;
|
|
}
|
|
else if (num9 > 1.5f && num8 <= 0.040000003f && ___random.RandomFloat < 0.1f)
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper Jump 3a");
|
|
num22 = 0.02f;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
num22 = 0;
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (__instance.BlockedTime > 0.15f && ___blockedHeight < myEntity.flMaxJumpHeight)
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper Jump 2b");
|
|
num22 = 0.55f + ___random.RandomFloat * 0.3f;
|
|
}
|
|
else if (num9 > 1.5f && num8 <= 0.040000003f && ___random.RandomFloat < 0.1f)
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper Jump 3b");
|
|
num22 = 0.02f;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (__instance.BlockedTime > 0.15f && ___blockedHeight < 1f)
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper Jump 2c");
|
|
num22 = 0.55f + ___random.RandomFloat * 0.3f;
|
|
}
|
|
else if (num9 > 1.5f && num8 <= 0.040000003f && ___random.RandomFloat < 0.1f)
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper Jump 3c");
|
|
num22 = 0.02f;
|
|
}
|
|
}
|
|
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper __instance.IsUnreachableSideJump: " + __instance.IsUnreachableSideJump);
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper num14: " + num14);
|
|
if (__instance.IsUnreachableSideJump && num14 < 25f)
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper Jump 4");
|
|
PathEntity path = __instance.entity.navigator.getPath();
|
|
if (path == null || path.NodeCountRemaining() <= 1)
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper Jump 5");
|
|
Vector3 a = __instance.entity.position + __instance.entity.GetForwardVector() * 0.2f;
|
|
a.y += 0.4f;
|
|
RaycastHit raycastHit;
|
|
if (!Physics.Raycast(a - Origin.position, Vector3.down, out raycastHit, 3.4f, 1082195968) || raycastHit.distance > 2.2f)
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper Jump 6");
|
|
num22 = __instance.entity.jumpMaxDistance;
|
|
heightDiff = __instance.UnreachablePos.y - __instance.entity.position.y;
|
|
}
|
|
}
|
|
}
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper num22: " + num22);
|
|
|
|
if (num22 > 0f)
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper Jump 7");
|
|
Vector3i vector3i = new Vector3i(Utils.Fastfloor(position.x), Utils.Fastfloor(position.y + 2.35f), Utils.Fastfloor(position.z));
|
|
BlockValue block = __instance.entity.world.GetBlock(vector3i);
|
|
if (!block.Block.IsMovementBlocked(__instance.entity.world, vector3i, block, BlockFace.None))
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper Jump 8");
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper IS BLOCKED block: " + block.Block.GetBlockName());
|
|
|
|
if (__instance.entity is EntityNPCRebirth && block.Block.GetBlockName() == "air" && !__instance.IsBlocked)
|
|
{
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper IS BLOCKED block: " + block.Block.GetBlockName());
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper IS BLOCKED num22: " + num22);
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper IS BLOCKED heightDiff: " + heightDiff);
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper IS BLOCKED ___blockedHeight: " + ___blockedHeight);
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper IS BLOCKED numHeight: " + numHeight);
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper IS BLOCKED ___jumpYaw: " + ___jumpYaw);
|
|
//Log.Out("EntityMoveHelperPatches-UpdateMoveHelper IS BLOCKED __instance.IsBlocked: " + __instance.IsBlocked);
|
|
__instance.IsUnreachableSideJump = false;
|
|
return false;
|
|
}
|
|
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper StartJump D");
|
|
StartJump.Invoke(__instance, new object[] { true, num22, heightDiff });
|
|
|
|
if (__instance.IsUnreachableSideJump)
|
|
{
|
|
//Log.Out("EntityMoveHelperRebirth-UpdateMoveHelper Jump 9");
|
|
__instance.UnreachablePercent += 0.1f;
|
|
__instance.IsDestroyAreaTryUnreachable = true;
|
|
}
|
|
}
|
|
__instance.IsUnreachableSideJump = false;
|
|
}
|
|
}
|
|
return false;
|
|
}*/
|
|
}
|
|
} |