(6eeea9b7c) v0.9.10.0.0
This commit is contained in:
@@ -19,8 +19,8 @@ namespace Barotrauma
|
||||
None, LeftHand, RightHand, LeftArm, RightArm, LeftForearm, RightForearm,
|
||||
LeftLeg, RightLeg, LeftFoot, RightFoot, Head, Torso, Tail, Legs, RightThigh, LeftThigh, Waist, Jaw
|
||||
};
|
||||
|
||||
partial class LimbJoint : RevoluteJoint
|
||||
|
||||
partial class LimbJoint
|
||||
{
|
||||
public bool IsSevered;
|
||||
public bool CanBeSevered => Params.CanBeSevered;
|
||||
@@ -30,27 +30,135 @@ namespace Barotrauma
|
||||
|
||||
public float Scale => Params.Scale * ragdoll.RagdollParams.JointScale;
|
||||
|
||||
public LimbJoint(Limb limbA, Limb limbB, JointParams jointParams, Ragdoll ragdoll) : this(limbA, limbB, Vector2.One, Vector2.One)
|
||||
public readonly RevoluteJoint revoluteJoint;
|
||||
public readonly WeldJoint weldJoint;
|
||||
public Joint Joint => revoluteJoint ?? weldJoint as Joint;
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get => Joint.Enabled;
|
||||
set => Joint.Enabled = value;
|
||||
}
|
||||
|
||||
public Body BodyA => Joint.BodyA;
|
||||
|
||||
public Body BodyB => Joint.BodyB;
|
||||
|
||||
public Vector2 WorldAnchorA
|
||||
{
|
||||
get => Joint.WorldAnchorA;
|
||||
set => Joint.WorldAnchorA = value;
|
||||
}
|
||||
|
||||
public Vector2 WorldAnchorB
|
||||
{
|
||||
get => Joint.WorldAnchorB;
|
||||
set => Joint.WorldAnchorB = value;
|
||||
}
|
||||
|
||||
public Vector2 LocalAnchorA
|
||||
{
|
||||
get => revoluteJoint != null ? revoluteJoint.LocalAnchorA : weldJoint.LocalAnchorA;
|
||||
set
|
||||
{
|
||||
if (weldJoint != null)
|
||||
{
|
||||
weldJoint.LocalAnchorA = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
revoluteJoint.LocalAnchorA = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 LocalAnchorB
|
||||
{
|
||||
get => revoluteJoint != null ? revoluteJoint.LocalAnchorB : weldJoint.LocalAnchorB;
|
||||
set
|
||||
{
|
||||
if (weldJoint != null)
|
||||
{
|
||||
weldJoint.LocalAnchorB = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
revoluteJoint.LocalAnchorB = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool LimitEnabled
|
||||
{
|
||||
get => revoluteJoint != null ? revoluteJoint.LimitEnabled : false;
|
||||
set
|
||||
{
|
||||
if (revoluteJoint != null)
|
||||
{
|
||||
revoluteJoint.LimitEnabled = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float LowerLimit
|
||||
{
|
||||
get => revoluteJoint != null ? revoluteJoint.LowerLimit : 0;
|
||||
set
|
||||
{
|
||||
if (revoluteJoint != null)
|
||||
{
|
||||
revoluteJoint.LowerLimit = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float UpperLimit
|
||||
{
|
||||
get => revoluteJoint != null ? revoluteJoint.UpperLimit : 0;
|
||||
set
|
||||
{
|
||||
if (revoluteJoint != null)
|
||||
{
|
||||
revoluteJoint.UpperLimit = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float JointAngle => revoluteJoint != null ? revoluteJoint.JointAngle : weldJoint.ReferenceAngle;
|
||||
|
||||
public LimbJoint(Limb limbA, Limb limbB, JointParams jointParams, Ragdoll ragdoll) : this(limbA, limbB, Vector2.One, Vector2.One, jointParams.WeldJoint)
|
||||
{
|
||||
Params = jointParams;
|
||||
this.ragdoll = ragdoll;
|
||||
LoadParams();
|
||||
}
|
||||
|
||||
public LimbJoint(Limb limbA, Limb limbB, Vector2 anchor1, Vector2 anchor2)
|
||||
: base(limbA.body.FarseerBody, limbB.body.FarseerBody, anchor1, anchor2)
|
||||
public LimbJoint(Limb limbA, Limb limbB, Vector2 anchor1, Vector2 anchor2, bool weld = false)
|
||||
{
|
||||
CollideConnected = false;
|
||||
MotorEnabled = true;
|
||||
MaxMotorTorque = 0.25f;
|
||||
if (weld)
|
||||
{
|
||||
weldJoint = new WeldJoint(limbA.body.FarseerBody, limbB.body.FarseerBody, anchor1, anchor2);
|
||||
}
|
||||
else
|
||||
{
|
||||
revoluteJoint = new RevoluteJoint(limbA.body.FarseerBody, limbB.body.FarseerBody, anchor1, anchor2)
|
||||
{
|
||||
MotorEnabled = true,
|
||||
MaxMotorTorque = 0.25f
|
||||
};
|
||||
}
|
||||
Joint.CollideConnected = false;
|
||||
LimbA = limbA;
|
||||
LimbB = limbB;
|
||||
}
|
||||
|
||||
public void LoadParams()
|
||||
{
|
||||
MaxMotorTorque = Params.Stiffness;
|
||||
LimitEnabled = Params.LimitEnabled;
|
||||
if (revoluteJoint != null)
|
||||
{
|
||||
revoluteJoint.MaxMotorTorque = Params.Stiffness;
|
||||
revoluteJoint.LimitEnabled = Params.LimitEnabled;
|
||||
}
|
||||
if (float.IsNaN(Params.LowerLimit))
|
||||
{
|
||||
Params.LowerLimit = 0;
|
||||
@@ -61,17 +169,33 @@ namespace Barotrauma
|
||||
}
|
||||
if (ragdoll.IsFlipped)
|
||||
{
|
||||
LocalAnchorA = ConvertUnits.ToSimUnits(new Vector2(-Params.Limb1Anchor.X, Params.Limb1Anchor.Y) * Scale);
|
||||
LocalAnchorB = ConvertUnits.ToSimUnits(new Vector2(-Params.Limb2Anchor.X, Params.Limb2Anchor.Y) * Scale);
|
||||
UpperLimit = MathHelper.ToRadians(-Params.LowerLimit);
|
||||
LowerLimit = MathHelper.ToRadians(-Params.UpperLimit);
|
||||
if (weldJoint != null)
|
||||
{
|
||||
weldJoint.LocalAnchorA = ConvertUnits.ToSimUnits(new Vector2(-Params.Limb1Anchor.X, Params.Limb1Anchor.Y) * Scale);
|
||||
weldJoint.LocalAnchorB = ConvertUnits.ToSimUnits(new Vector2(-Params.Limb2Anchor.X, Params.Limb2Anchor.Y) * Scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
revoluteJoint.LocalAnchorA = ConvertUnits.ToSimUnits(new Vector2(-Params.Limb1Anchor.X, Params.Limb1Anchor.Y) * Scale);
|
||||
revoluteJoint.LocalAnchorB = ConvertUnits.ToSimUnits(new Vector2(-Params.Limb2Anchor.X, Params.Limb2Anchor.Y) * Scale);
|
||||
revoluteJoint.UpperLimit = MathHelper.ToRadians(-Params.LowerLimit);
|
||||
revoluteJoint.LowerLimit = MathHelper.ToRadians(-Params.UpperLimit);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LocalAnchorA = ConvertUnits.ToSimUnits(Params.Limb1Anchor * Scale);
|
||||
LocalAnchorB = ConvertUnits.ToSimUnits(Params.Limb2Anchor * Scale);
|
||||
UpperLimit = MathHelper.ToRadians(Params.UpperLimit);
|
||||
LowerLimit = MathHelper.ToRadians(Params.LowerLimit);
|
||||
if (weldJoint != null)
|
||||
{
|
||||
weldJoint.LocalAnchorA = ConvertUnits.ToSimUnits(Params.Limb1Anchor * Scale);
|
||||
weldJoint.LocalAnchorB = ConvertUnits.ToSimUnits(Params.Limb2Anchor * Scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
revoluteJoint.LocalAnchorA = ConvertUnits.ToSimUnits(Params.Limb1Anchor * Scale);
|
||||
revoluteJoint.LocalAnchorB = ConvertUnits.ToSimUnits(Params.Limb2Anchor * Scale);
|
||||
revoluteJoint.UpperLimit = MathHelper.ToRadians(Params.UpperLimit);
|
||||
revoluteJoint.LowerLimit = MathHelper.ToRadians(Params.LowerLimit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -166,10 +290,20 @@ namespace Barotrauma
|
||||
if (isSevered)
|
||||
{
|
||||
ragdoll.SubtractMass(this);
|
||||
if (type == LimbType.Head)
|
||||
{
|
||||
character.Kill(CauseOfDeathType.Unknown, null);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
severedFadeOutTimer = 0.0f;
|
||||
}
|
||||
if (!isSevered) severedFadeOutTimer = 0.0f;
|
||||
#if CLIENT
|
||||
if (isSevered) damageOverlayStrength = 100.0f;
|
||||
if (isSevered)
|
||||
{
|
||||
damageOverlayStrength = 100.0f;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -366,14 +500,42 @@ namespace Barotrauma
|
||||
|
||||
public string Name => Params.Name;
|
||||
|
||||
// Exposed for status effects
|
||||
public bool IsDead => character.IsDead;
|
||||
|
||||
public bool CanBeSeveredAlive
|
||||
{
|
||||
get
|
||||
{
|
||||
if (character.IsHumanoid) { return false; }
|
||||
if (this == character.AnimController.MainLimb) { return false; }
|
||||
if (character.AnimController.CanWalk)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case LimbType.LeftFoot:
|
||||
case LimbType.RightFoot:
|
||||
case LimbType.LeftLeg:
|
||||
case LimbType.RightLeg:
|
||||
case LimbType.LeftThigh:
|
||||
case LimbType.RightThigh:
|
||||
case LimbType.Legs:
|
||||
case LimbType.Waist:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, SerializableProperty> SerializableProperties
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
private readonly List<StatusEffect> statusEffects = new List<StatusEffect>();
|
||||
|
||||
public Limb(Ragdoll ragdoll, Character character, LimbParams limbParams)
|
||||
{
|
||||
this.ragdoll = ragdoll;
|
||||
@@ -436,6 +598,9 @@ namespace Barotrauma
|
||||
case "damagemodifier":
|
||||
DamageModifiers.Add(new DamageModifier(subElement, character.Name));
|
||||
break;
|
||||
case "statuseffect":
|
||||
statusEffects.Add(StatusEffect.Load(subElement, Name));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -521,11 +686,12 @@ namespace Barotrauma
|
||||
afflictionsCopy.Add(newAffliction);
|
||||
}
|
||||
}
|
||||
AddDamageProjSpecific(afflictionsCopy, playSound, appliedDamageModifiers);
|
||||
return new AttackResult(afflictionsCopy, this, appliedDamageModifiers);
|
||||
var result = new AttackResult(afflictionsCopy, this, appliedDamageModifiers);
|
||||
AddDamageProjSpecific(playSound, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
partial void AddDamageProjSpecific(IEnumerable<Affliction> afflictions, bool playSound, IEnumerable<DamageModifier> appliedDamageModifiers);
|
||||
partial void AddDamageProjSpecific(bool playSound, AttackResult result);
|
||||
|
||||
public bool SectorHit(Vector2 armorSector, Vector2 simPosition)
|
||||
{
|
||||
@@ -582,7 +748,8 @@ namespace Barotrauma
|
||||
public bool UpdateAttack(float deltaTime, Vector2 attackSimPos, IDamageable damageTarget, out AttackResult attackResult, float distance = -1, Limb targetLimb = null)
|
||||
{
|
||||
attackResult = default(AttackResult);
|
||||
float dist = distance > -1 ? distance : ConvertUnits.ToDisplayUnits(Vector2.Distance(SimPosition, attackSimPos));
|
||||
Vector2 simPos = ragdoll.SimplePhysicsEnabled ? character.SimPosition : SimPosition;
|
||||
float dist = distance > -1 ? distance : ConvertUnits.ToDisplayUnits(Vector2.Distance(simPos, attackSimPos));
|
||||
bool wasRunning = attack.IsRunning;
|
||||
attack.UpdateAttackTimer(deltaTime);
|
||||
|
||||
@@ -595,7 +762,7 @@ namespace Barotrauma
|
||||
case HitDetection.Distance:
|
||||
if (dist < attack.DamageRange)
|
||||
{
|
||||
structureBody = Submarine.PickBody(SimPosition, attackSimPos, collisionCategory: Physics.CollisionWall | Physics.CollisionLevel, allowInsideFixture: true);
|
||||
structureBody = Submarine.PickBody(simPos, attackSimPos, collisionCategory: Physics.CollisionWall | Physics.CollisionLevel, allowInsideFixture: true);
|
||||
if (damageTarget is Item i && i.GetComponent<Items.Components.Door>() != null)
|
||||
{
|
||||
// If the attack is aimed to an item and hits an item, it's successful.
|
||||
@@ -689,6 +856,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (limbIndex < 0 || limbIndex >= character.AnimController.Limbs.Length) { continue; }
|
||||
Limb limb = character.AnimController.Limbs[limbIndex];
|
||||
if (limb.IsSevered) { continue; }
|
||||
diff = attackSimPos - limb.SimPosition;
|
||||
if (diff == Vector2.Zero) { continue; }
|
||||
limb.body.ApplyTorque(limb.Mass * character.AnimController.Dir * attack.Torque * limb.Params.AttackForceMultiplier);
|
||||
@@ -811,6 +979,30 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
private readonly List<ISerializableEntity> targets = new List<ISerializableEntity>();
|
||||
public void ApplyStatusEffects(ActionType actionType, float deltaTime)
|
||||
{
|
||||
foreach (StatusEffect statusEffect in statusEffects)
|
||||
{
|
||||
if (statusEffect.type != actionType) { continue; }
|
||||
if (statusEffect.HasTargetType(StatusEffect.TargetType.NearbyItems) ||
|
||||
statusEffect.HasTargetType(StatusEffect.TargetType.NearbyCharacters))
|
||||
{
|
||||
targets.Clear();
|
||||
statusEffect.GetNearbyTargets(WorldPosition, targets);
|
||||
statusEffect.Apply(ActionType.OnActive, deltaTime, character, targets);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (statusEffect.HasTargetType(StatusEffect.TargetType.Character))
|
||||
{
|
||||
statusEffect.Apply(actionType, deltaTime, character, character, WorldPosition);
|
||||
}
|
||||
statusEffect.Apply(actionType, deltaTime, character, this, WorldPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
body?.Remove();
|
||||
|
||||
Reference in New Issue
Block a user