Moved stun from AnimController to the character class, server notifies clients when the stun ends, husk infection included in character status messages
This commit is contained in:
@@ -13,26 +13,12 @@ namespace Barotrauma
|
||||
protected Character character;
|
||||
|
||||
protected float walkSpeed, swimSpeed;
|
||||
|
||||
protected float stunTimer;
|
||||
|
||||
|
||||
protected float walkPos;
|
||||
|
||||
protected readonly Vector2 stepSize;
|
||||
protected readonly float legTorque;
|
||||
|
||||
|
||||
|
||||
public float StunTimer
|
||||
{
|
||||
get { return stunTimer; }
|
||||
set
|
||||
{
|
||||
if (!MathUtils.IsValid(value)) return;
|
||||
stunTimer = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public AnimController(Character character, XElement element)
|
||||
: base(character, element)
|
||||
{
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (Frozen) return;
|
||||
|
||||
if (character.IsDead || character.IsUnconscious || stunTimer > 0.0f)
|
||||
if (character.IsDead || character.IsUnconscious || character.Stun > 0.0f)
|
||||
{
|
||||
Collider.FarseerBody.FixedRotation = false;
|
||||
|
||||
@@ -63,12 +63,7 @@ namespace Barotrauma
|
||||
Collider.LinearVelocity = (MainLimb.SimPosition - Collider.SimPosition) * 60.0f;
|
||||
Collider.SmoothRotate(MainLimb.Rotation);
|
||||
}
|
||||
|
||||
if (stunTimer > 0)
|
||||
{
|
||||
stunTimer -= deltaTime;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -89,7 +84,7 @@ namespace Barotrauma
|
||||
|
||||
if (strongestImpact > 0.0f)
|
||||
{
|
||||
stunTimer = MathHelper.Clamp(strongestImpact * 0.5f, stunTimer, 5.0f);
|
||||
character.Stun = MathHelper.Clamp(strongestImpact * 0.5f, character.Stun, 5.0f);
|
||||
strongestImpact = 0.0f;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,18 +67,13 @@ namespace Barotrauma
|
||||
Collider.LinearVelocity = (GetLimb(LimbType.Waist).SimPosition - Collider.SimPosition) * 20.0f;
|
||||
Collider.SmoothRotate(GetLimb(LimbType.Torso).Rotation);
|
||||
|
||||
if (stunTimer > 0)
|
||||
{
|
||||
stunTimer -= deltaTime;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//stun (= disable the animations) if the ragdoll receives a large enough impact
|
||||
if (strongestImpact > 0.0f)
|
||||
{
|
||||
character.StartStun(MathHelper.Min(strongestImpact * 0.5f, 5.0f));
|
||||
character.SetStun(MathHelper.Min(strongestImpact * 0.5f, 5.0f));
|
||||
strongestImpact = 0.0f;
|
||||
return;
|
||||
}
|
||||
@@ -979,7 +974,7 @@ namespace Barotrauma
|
||||
|
||||
|
||||
float itemAngle;
|
||||
if (Anim != Animation.Climbing && !usingController && stunTimer <= 0.0f && aim && itemPos != Vector2.Zero)
|
||||
if (Anim != Animation.Climbing && !usingController && character.Stun <= 0.0f && aim && itemPos != Vector2.Zero)
|
||||
{
|
||||
Vector2 mousePos = ConvertUnits.ToSimUnits(character.CursorPosition);
|
||||
|
||||
|
||||
@@ -276,14 +276,15 @@ namespace Barotrauma
|
||||
set { oxygenAvailable = MathHelper.Clamp(value, 0.0f, 100.0f); }
|
||||
}
|
||||
|
||||
private float stunTimer;
|
||||
public float Stun
|
||||
{
|
||||
get { return AnimController.StunTimer; }
|
||||
get { return stunTimer; }
|
||||
set
|
||||
{
|
||||
if (GameMain.Client != null) return;
|
||||
|
||||
StartStun(value);
|
||||
SetStun(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1397,6 +1398,16 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
if (Stun > 0.0f)
|
||||
{
|
||||
stunTimer -= deltaTime;
|
||||
if (stunTimer < 0.0f && GameMain.Server != null)
|
||||
{
|
||||
//stun ended -> notify clients
|
||||
GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.Status });
|
||||
}
|
||||
}
|
||||
|
||||
if (IsUnconscious)
|
||||
{
|
||||
UpdateUnconscious(deltaTime);
|
||||
@@ -1717,7 +1728,7 @@ namespace Barotrauma
|
||||
|
||||
public AttackResult AddDamage(Vector2 worldPosition, DamageType damageType, float amount, float bleedingAmount, float stun, bool playSound, float attackForce = 0.0f)
|
||||
{
|
||||
StartStun(stun);
|
||||
SetStun(stun);
|
||||
|
||||
Limb closestLimb = null;
|
||||
float closestDistance = 0.0f;
|
||||
@@ -1750,20 +1761,20 @@ namespace Barotrauma
|
||||
return attackResult;
|
||||
}
|
||||
|
||||
public void StartStun(float stunTimer, bool allowStunDecrease = false, bool isNetworkMessage = false)
|
||||
public void SetStun(float newStun, bool allowStunDecrease = false, bool isNetworkMessage = false)
|
||||
{
|
||||
if (GameMain.Client != null && !isNetworkMessage) return;
|
||||
|
||||
if ((stunTimer <= AnimController.StunTimer && !allowStunDecrease) || !MathUtils.IsValid(stunTimer)) return;
|
||||
if ((newStun <= stunTimer && !allowStunDecrease) || !MathUtils.IsValid(newStun)) return;
|
||||
|
||||
if (GameMain.Server != null &&
|
||||
(Math.Sign(stunTimer) != Math.Sign(AnimController.StunTimer) || Math.Abs(stunTimer - AnimController.StunTimer) > 0.1f))
|
||||
(Math.Sign(newStun) != Math.Sign(stunTimer) || Math.Abs(newStun - stunTimer) > 0.1f))
|
||||
{
|
||||
GameMain.Server.CreateEntityEvent(this, new object[] { NetEntityEvent.Type.Status });
|
||||
}
|
||||
|
||||
if (Math.Sign(stunTimer) != Math.Sign(AnimController.StunTimer)) AnimController.ResetPullJoints();
|
||||
AnimController.StunTimer = Math.Max(AnimController.StunTimer, stunTimer);
|
||||
if (Math.Sign(newStun) != Math.Sign(stunTimer)) AnimController.ResetPullJoints();
|
||||
stunTimer = newStun;
|
||||
|
||||
selectedConstruction = null;
|
||||
}
|
||||
|
||||
@@ -602,6 +602,8 @@ namespace Barotrauma
|
||||
Stun = MathHelper.Clamp(Stun, 0.0f, 60.0f);
|
||||
msg.WriteRangedSingle(Stun, 0.0f, 60.0f, 8);
|
||||
}
|
||||
|
||||
msg.Write(HuskInfectionState > 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -654,12 +656,23 @@ namespace Barotrauma
|
||||
if (stunned)
|
||||
{
|
||||
float newStunTimer = msg.ReadRangedSingle(0.0f, 60.0f, 8);
|
||||
StartStun(newStunTimer, true, true);
|
||||
SetStun(newStunTimer, true, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
StartStun(0.0f, true, true);
|
||||
SetStun(0.0f, true, true);
|
||||
}
|
||||
|
||||
bool huskInfected = msg.ReadBoolean();
|
||||
if (huskInfected)
|
||||
{
|
||||
HuskInfectionState = Math.Max(HuskInfectionState, 0.01f);
|
||||
}
|
||||
else
|
||||
{
|
||||
HuskInfectionState = 0.0f;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ namespace Barotrauma
|
||||
return;
|
||||
}
|
||||
|
||||
character.StartStun(0.5f);
|
||||
character.SetStun(0.5f);
|
||||
if (character.AnimController.Dir < 1.0f)
|
||||
{
|
||||
character.AnimController.Flip();
|
||||
|
||||
@@ -528,7 +528,7 @@ namespace Barotrauma
|
||||
Character.Controlled.AddDamage(CauseOfDeath.Damage, -Character.Controlled.MaxHealth, null);
|
||||
Character.Controlled.Oxygen = 100.0f;
|
||||
Character.Controlled.Bleeding = 0.0f;
|
||||
Character.Controlled.AnimController.StunTimer = 0.0f;
|
||||
Character.Controlled.SetStun(0.0f, true);
|
||||
}
|
||||
break;
|
||||
case "revive":
|
||||
|
||||
@@ -479,7 +479,7 @@ namespace Barotrauma.Items.Components
|
||||
body.ApplyLinearImpulse(new Vector2(dir * 0.5f, isOpen ? 0.0f : -1.0f));
|
||||
}
|
||||
|
||||
c.StartStun(0.2f);
|
||||
c.SetStun(0.2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace Barotrauma.Items.Components
|
||||
float degreeOfSuccess = DegreeOfSuccess(character);
|
||||
if (Rand.Range(0.0f, 50.0f) < degreeOfSuccess) return false;
|
||||
|
||||
character.StartStun(5.0f);
|
||||
character.SetStun(5.0f);
|
||||
|
||||
item.ApplyStatusEffects(ActionType.OnFailure, 1.0f, character);
|
||||
|
||||
|
||||
@@ -497,7 +497,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (c.Submarine != submarine) continue;
|
||||
|
||||
if (impact > 2.0f) c.StartStun((impact - 2.0f) * 0.1f);
|
||||
if (impact > 2.0f) c.SetStun((impact - 2.0f) * 0.1f);
|
||||
|
||||
foreach (Limb limb in c.AnimController.Limbs)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user