v0.19.0.0 (unstable)

This commit is contained in:
Regalis11
2022-07-20 18:47:07 +03:00
parent 2e2663a175
commit 6b55adcdd9
170 changed files with 2769 additions and 1634 deletions
@@ -101,7 +101,7 @@ namespace Barotrauma
{
if (InWater || !CanWalk)
{
return TargetMovement.LengthSquared() > MathUtils.Pow2(SwimSlowParams.MovementSpeed);
return TargetMovement.LengthSquared() > MathUtils.Pow2(SwimSlowParams.MovementSpeed + 0.0001f);
}
else
{
@@ -134,9 +134,12 @@ namespace Barotrauma
}
}
public enum Animation { None, Climbing, UsingConstruction, Struggle, CPR };
public enum Animation { None, Climbing, UsingItem, Struggle, CPR, UsingItemWhileClimbing };
public Animation Anim;
public bool IsUsingItem => Anim == Animation.UsingItem || Anim == Animation.UsingItemWhileClimbing;
public bool IsClimbing => Anim == Animation.Climbing || Anim == Animation.UsingItemWhileClimbing;
public Vector2 AimSourceWorldPos
{
get
@@ -280,7 +283,7 @@ namespace Barotrauma
public void UpdateUseItem(bool allowMovement, Vector2 handWorldPos)
{
useItemTimer = 0.5f;
Anim = Animation.UsingConstruction;
StartUsingItem();
if (!allowMovement)
{
@@ -359,8 +362,13 @@ namespace Barotrauma
Vector2 itemPos = aim ? aimPos : holdPos;
var controller = character.SelectedConstruction?.GetComponent<Controller>();
var controller = character.SelectedItem?.GetComponent<Controller>();
bool usingController = controller != null && !controller.AllowAiming;
if (!usingController)
{
controller = character.SelectedSecondaryItem?.GetComponent<Controller>();
usingController = controller != null && !controller.AllowAiming;
}
bool isClimbing = character.IsClimbing && Math.Abs(character.AnimController.TargetMovement.Y) > 0.01f;
float itemAngle;
Holdable holdable = item.GetComponent<Holdable>();
@@ -722,5 +730,45 @@ namespace Barotrauma
CalculateArmLengths();
}
}
private void StartAnimation(Animation animation)
{
if (animation == Animation.UsingItem)
{
Anim = IsClimbing ? Animation.UsingItemWhileClimbing : Animation.UsingItem;
}
else if (animation == Animation.Climbing)
{
Anim = IsUsingItem ? Animation.UsingItemWhileClimbing : Animation.Climbing;
}
else
{
Anim = animation;
}
}
private void StopAnimation(Animation animation)
{
if (animation == Animation.UsingItem)
{
Anim = IsClimbing ? Animation.Climbing : Animation.None;
}
else if (animation == Animation.Climbing)
{
Anim = IsUsingItem ? Animation.UsingItem : Animation.None;
}
else
{
Anim = Animation.None;
}
}
public void StartUsingItem() => StartAnimation(Animation.UsingItem);
public void StartClimbing() => StartAnimation(Animation.Climbing);
public void StopUsingItem() => StopAnimation(Animation.UsingItem);
public void StopClimbing() => StopAnimation(Animation.Climbing);
}
}
@@ -237,13 +237,14 @@ namespace Barotrauma
public override void UpdateAnim(float deltaTime)
{
if (Frozen) return;
if (Frozen) { return; }
if (MainLimb == null) { return; }
levitatingCollider = !IsHanging;
ColliderIndex = Crouching && !swimming ? 1 : 0;
if (character.SelectedConstruction?.GetComponent<Controller>()?.ControlCharacterPose ?? false ||
character.SelectedConstruction?.GetComponent<Ladder>() != null ||
if ((character.SelectedItem?.GetComponent<Controller>()?.ControlCharacterPose ?? false) ||
(character.SelectedSecondaryItem?.GetComponent<Controller>()?.ControlCharacterPose ?? false) ||
character.SelectedSecondaryItem?.GetComponent<Ladder>() != null ||
(ForceSelectAnimationType != AnimationType.Crouch && ForceSelectAnimationType != AnimationType.NotDefined))
{
Crouching = false;
@@ -354,12 +355,16 @@ namespace Barotrauma
{
ApplyTestPose();
}
else
else if (Anim != Animation.UsingItem)
{
if (Anim != Animation.UsingConstruction)
if (Anim != Animation.UsingItemWhileClimbing)
{
ResetPullJoints();
}
else
{
ResetPullJoints(l => l.IsLowerBody);
}
}
if (SimplePhysicsEnabled)
@@ -377,49 +382,53 @@ namespace Barotrauma
switch (Anim)
{
case Animation.Climbing:
case Animation.UsingItemWhileClimbing:
levitatingCollider = false;
UpdateClimbing();
UpdateUseItemTimer();
break;
case Animation.CPR:
UpdateCPR(deltaTime);
break;
case Animation.UsingConstruction:
case Animation.UsingItem:
default:
if (Anim == Animation.UsingConstruction)
{
useItemTimer -= deltaTime;
if (useItemTimer <= 0.0f) Anim = Animation.None;
}
UpdateUseItemTimer();
swimmingStateLockTimer -= deltaTime;
if (forceStanding || character.AnimController.AnimationTestPose)
{
swimming = false;
}
else
else if (swimming != inWater && swimmingStateLockTimer <= 0.0f)
{
//0.5 second delay for switching between swimming and walking
//prevents rapid switches between swimming/walking if the water level is fluctuating around the minimum swimming depth
if (swimming != inWater && swimmingStateLockTimer <= 0.0f)
{
swimming = inWater;
swimmingStateLockTimer = 0.5f;
}
swimming = inWater;
swimmingStateLockTimer = 0.5f;
}
if (swimming)
{
UpdateSwimming();
}
else
else if (character.SelectedItem == null || !(character.SelectedSecondaryItem?.GetComponent<Controller>() is { } controller) ||
!controller.ControlCharacterPose || !controller.UserInCorrectPosition)
{
UpdateStanding();
}
break;
}
void UpdateUseItemTimer()
{
if (IsUsingItem)
{
useItemTimer -= deltaTime;
if (useItemTimer <= 0.0f)
{
StopUsingItem();
}
}
}
if (Timing.TotalTime > LockFlippingUntil && TargetDir != dir && !IsStuck)
{
Flip();
@@ -841,7 +850,9 @@ namespace Barotrauma
float targetSpeed = TargetMovement.Length();
if (targetSpeed > 0.1f && !character.IsRemotelyControlled && !Aiming)
{
if (Anim != Animation.UsingConstruction && !(character.SelectedConstruction?.GetComponent<Controller>()?.ControlCharacterPose ?? false))
if (!IsUsingItem &&
!(character.SelectedItem?.GetComponent<Controller>()?.ControlCharacterPose ?? false) &&
!(character.SelectedSecondaryItem?.GetComponent<Controller>()?.ControlCharacterPose ?? false))
{
if (rotation > 20 && rotation < 170)
{
@@ -1041,12 +1052,17 @@ namespace Barotrauma
void UpdateClimbing()
{
var ladder = character.SelectedConstruction?.GetComponent<Ladder>();
if (ladder == null || character.IsIncapacitated)
var ladder = character.SelectedSecondaryItem?.GetComponent<Ladder>();
if (character.IsIncapacitated)
{
Anim = Animation.None;
return;
}
else if (ladder == null)
{
StopClimbing();
return;
}
onGround = false;
IgnorePlatforms = true;
@@ -1209,15 +1225,21 @@ namespace Barotrauma
{
RotateHead(head);
}
else if (Anim == Animation.UsingItemWhileClimbing && character.SelectedItem is { } selectedItem)
{
Vector2 diff = (selectedItem.WorldPosition - head.WorldPosition) * Dir;
float targetRotation = MathHelper.WrapAngle(MathUtils.VectorToAngle(diff) - MathHelper.PiOver4 * Dir);
head.body.SmoothRotate(targetRotation, force: WalkParams.HeadTorque);
}
else
{
float movementMultiplier = targetMovement.Y < 0 ? 0 : 1;
head.body.SmoothRotate(MathHelper.PiOver4 * movementMultiplier * Dir, WalkParams.HeadTorque);
head.body.SmoothRotate(MathHelper.PiOver4 * movementMultiplier * Dir, force: WalkParams.HeadTorque);
}
if (!ladder.Item.Prefab.Triggers.Any())
if (ladder.Item.Prefab.Triggers.None())
{
character.SelectedConstruction = null;
character.SelectedSecondaryItem = null;
return;
}
@@ -1247,8 +1269,7 @@ namespace Barotrauma
if (!isClimbing)
{
Anim = Animation.None;
character.SelectedConstruction = null;
character.StopClimbing();
IgnorePlatforms = false;
}
@@ -1487,7 +1508,7 @@ namespace Barotrauma
target.AnimController.ResetPullJoints();
}
if (Anim == Animation.Climbing)
if (IsClimbing)
{
//cannot drag up ladders if the character is conscious
if (target.AllowInput && (GameMain.NetworkMember == null || !GameMain.NetworkMember.IsClient))
@@ -922,12 +922,13 @@ namespace Barotrauma
{
limb.MoveToPos(pos, amount, pullFromCenter);
}
public void ResetPullJoints()
public void ResetPullJoints(Func<Limb, bool> condition = null)
{
for (int i = 0; i < Limbs.Length; i++)
{
if (Limbs[i] == null) { continue; }
if (condition != null && !condition(Limbs[i])) { continue; }
Limbs[i].PullJointEnabled = false;
}
}