tidy up PhysicsComponent

This commit is contained in:
UnknownShadow200 2017-04-09 21:56:43 +10:00
parent eaab271d08
commit c0e90d2a57
2 changed files with 26 additions and 31 deletions

View File

@ -71,6 +71,7 @@ namespace ClassicalSharp.Entities {
public bool HalfSpeeding; public bool HalfSpeeding;
public bool CanJumpHigher { get { return Enabled && CanAnyHacks && CanSpeed; } } public bool CanJumpHigher { get { return Enabled && CanAnyHacks && CanSpeed; } }
public bool Floating { get { return Noclip || Flying; } }
/// <summary> Parses hack flags specified in the motd and/or name of the server. </summary> /// <summary> Parses hack flags specified in the motd and/or name of the server. </summary>
/// <remarks> Recognises +/-hax, +/-fly, +/-noclip, +/-speed, +/-respawn, +/-ophax, and horspeed=xyz </remarks> /// <remarks> Recognises +/-hax, +/-fly, +/-noclip, +/-speed, +/-respawn, +/-ophax, and horspeed=xyz </remarks>

View File

@ -33,7 +33,7 @@ namespace ClassicalSharp.Entities {
} }
public void UpdateVelocityState() { public void UpdateVelocityState() {
if (hacks.Flying || hacks.Noclip) { if (hacks.Floating) {
entity.Velocity.Y = 0; // eliminate the effect of gravity entity.Velocity.Y = 0; // eliminate the effect of gravity
int dir = (hacks.FlyingUp || jumping) ? 1 : (hacks.FlyingDown ? -1 : 0); int dir = (hacks.FlyingUp || jumping) ? 1 : (hacks.FlyingDown ? -1 : 0);
@ -109,34 +109,32 @@ namespace ClassicalSharp.Entities {
public void PhysicsTick(Vector3 vel) { public void PhysicsTick(Vector3 vel) {
if (hacks.Noclip) entity.onGround = false; if (hacks.Noclip) entity.onGround = false;
float multiply = GetBaseMultiply(true); float baseSpeed = GetBaseSpeed();
float yMultiply = GetBaseMultiply(hacks.CanSpeed); float horSpeed = baseSpeed * GetSpeed(true);
float modifier = LowestSpeedModifier(); float verSpeed = baseSpeed * Math.Max(1, GetSpeed(hacks.CanSpeed) / 5);
float yMul = Math.Max(1f, yMultiply / 5) * modifier; if (!hacks.Floating) {
float horMul = multiply * modifier; if (secondJump) { horSpeed *= 93f; verSpeed *= 10f; }
if (!(hacks.Flying || hacks.Noclip)) { else if (firstJump) { horSpeed *= 46.5f; verSpeed *= 7.5f; }
if (secondJump) { horMul *= 93f; yMul *= 10f; }
else if (firstJump) { horMul *= 46.5f; yMul *= 7.5f; }
} }
if (entity.TouchesAnyWater() && !hacks.Flying && !hacks.Noclip) { if (entity.TouchesAnyWater() && !hacks.Floating) {
MoveNormal(vel, 0.02f * horMul, waterDrag, liquidGrav, yMul); MoveNormal(vel, 0.02f * horSpeed, waterDrag, liquidGrav, verSpeed);
} else if (entity.TouchesAnyLava() && !hacks.Flying && !hacks.Noclip) { } else if (entity.TouchesAnyLava() && !hacks.Floating) {
MoveNormal(vel, 0.02f * horMul, lavaDrag, liquidGrav, yMul); MoveNormal(vel, 0.02f * horSpeed, lavaDrag, liquidGrav, verSpeed);
} else if (entity.TouchesAnyRope() && !hacks.Flying && !hacks.Noclip) { } else if (entity.TouchesAnyRope() && !hacks.Floating) {
MoveNormal(vel, 0.02f * 1.7f, ropeDrag, ropeGrav, yMul); MoveNormal(vel, 0.02f * 1.7f, ropeDrag, ropeGrav, verSpeed);
} else { } else {
float factor = !(hacks.Flying || hacks.Noclip) && entity.onGround ? 0.1f : 0.02f; float factor = !hacks.Floating && entity.onGround ? 0.1f : 0.02f;
float gravity = useLiquidGravity ? liquidGrav : entity.Model.Gravity; float gravity = useLiquidGravity ? liquidGrav : entity.Model.Gravity;
if (hacks.Flying || hacks.Noclip) { if (hacks.Floating) {
MoveFlying(vel, factor * horMul, entity.Model.Drag, gravity, yMul); MoveFlying(vel, factor * horSpeed, entity.Model.Drag, gravity, verSpeed);
} else { } else {
MoveNormal(vel, factor * horMul, entity.Model.Drag, gravity, yMul); MoveNormal(vel, factor * horSpeed, entity.Model.Drag, gravity, verSpeed);
} }
if (entity.BlockUnderFeet == Block.Ice && !(hacks.Flying || hacks.Noclip)) { if (entity.BlockUnderFeet == Block.Ice && !hacks.Floating) {
// limit components to +-0.25f by rescaling vector to [-0.25, 0.25] // limit components to +-0.25f by rescaling vector to [-0.25, 0.25]
if (Math.Abs(entity.Velocity.X) > 0.25f || Math.Abs(entity.Velocity.Z) > 0.25f) { if (Math.Abs(entity.Velocity.X) > 0.25f || Math.Abs(entity.Velocity.Z) > 0.25f) {
float scale = Math.Min( float scale = Math.Min(
@ -189,19 +187,15 @@ namespace ClassicalSharp.Entities {
entity.Velocity.Y -= gravity; entity.Velocity.Y -= gravity;
} }
float GetBaseMultiply(bool canSpeed) { float GetSpeed(bool canSpeed) {
float multiply = 0; float factor = hacks.Floating ? 8 : 1, speed = factor;
float speed = (hacks.Flying || hacks.Noclip) ? 8 : 1; if (hacks.Speeding && canSpeed) speed += factor * hacks.SpeedMultiplier;
if (hacks.HalfSpeeding && canSpeed) speed += factor * hacks.SpeedMultiplier / 2;
return hacks.CanSpeed ? speed : Math.Min(speed, hacks.MaxSpeedMultiplier);
if (hacks.Speeding && canSpeed) multiply += speed * hacks.SpeedMultiplier;
if (hacks.HalfSpeeding && canSpeed) multiply += speed * hacks.SpeedMultiplier / 2;
if (multiply == 0) multiply = speed;
return hacks.CanSpeed ? multiply : Math.Min(multiply, hacks.MaxSpeedMultiplier);
} }
const float inf = float.PositiveInfinity; const float inf = float.PositiveInfinity;
float LowestSpeedModifier() { float GetBaseSpeed() {
AABB bounds = entity.Bounds; AABB bounds = entity.Bounds;
useLiquidGravity = false; useLiquidGravity = false;
float baseModifier = LowestModifier(bounds, false); float baseModifier = LowestModifier(bounds, false);