Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Character flipping enhancements #14673

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,16 @@ public void ClientReadPosition(IReadMessage msg, float sendingTime)
keys[(int)InputType.Ragdoll].Held = ragdollInput;
keys[(int)InputType.Ragdoll].SetState(false, ragdollInput);

facingRight = msg.ReadBoolean();
}

facingRight = msg.ReadBoolean();

if (AnimController.IsFlipped == facingRight)
{
if((AnimController is HumanoidAnimController && !CanMove) || AnimController is FishAnimController)
{
TryFlipCharacter();
}
TheNinjaScout marked this conversation as resolved.
Show resolved Hide resolved
}

bool entitySelected = msg.ReadBoolean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,10 @@ public void ServerWritePosition(ReadWriteMessage tempBuffer, Client c)

tempBuffer.WriteBoolean(IsRagdolled || Stun > 0.0f || IsDead || IsIncapacitated);

tempBuffer.WriteBoolean(AnimController.Dir > 0.0f);
}

tempBuffer.WriteBoolean(AnimController.Dir > 0.0f);

if (SelectedCharacter != null || HasSelectedAnyItem)
{
tempBuffer.WriteBoolean(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ protected override void UpdateAnim(float deltaTime)
}
}

if (!IsStuck && CurrentFishAnimation.Flip && character.AIController is not { CanFlip: false })
if (!IsStuck && CurrentFishAnimation.Flip && character.AIController is not { CanFlip: false } && (GameMain.NetworkMember == null || !GameMain.NetworkMember.IsClient))
{
flipCooldown -= deltaTime;
if (TargetDir != Direction.None && TargetDir != dir)
Expand All @@ -296,14 +296,9 @@ protected override void UpdateAnim(float deltaTime)
}
bool isMovingFastEnough = Math.Abs(MainLimb.LinearVelocity.X) > requiredSpeed;
bool isTryingToMoveHorizontally = Math.Abs(TargetMovement.X) > Math.Abs(TargetMovement.Y);
if ((flipTimer > CurrentFishAnimation.FlipDelay && flipCooldown <= 0.0f && ((isMovingFastEnough && isTryingToMoveHorizontally) || IsMovingBackwards))
|| character.IsRemotePlayer)
if ((flipTimer > CurrentFishAnimation.FlipDelay && flipCooldown <= 0.0f) && ((isMovingFastEnough && isTryingToMoveHorizontally) || IsMovingBackwards))
{
Flip();
if (!inWater || (CurrentSwimParams != null && CurrentSwimParams.Mirror))
{
Mirror(CurrentSwimParams != null ? CurrentSwimParams.MirrorLerp : true);
}
flipTimer = 0.0f;
flipCooldown = CurrentFishAnimation.FlipCooldown;
}
Expand Down Expand Up @@ -1029,6 +1024,10 @@ public override void Flip()
//no need to do anything when flipping vertically oriented limbs
//the sprite gets flipped horizontally, which does the job
}
if (!inWater || (CurrentSwimParams != null && CurrentSwimParams.Mirror))
{
Mirror(CurrentSwimParams != null ? CurrentSwimParams.MirrorLerp : true);
}
}

public void Mirror(bool lerp = true)
Expand Down
29 changes: 24 additions & 5 deletions Barotrauma/BarotraumaShared/SharedSource/Characters/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2111,11 +2111,7 @@ public void Control(float deltaTime, Camera cam)
((!IsClimbing && AnimController.OnGround) || (IsClimbing && IsKeyDown(InputType.Aim))) &&
!AnimController.InWater)
{
if (dontFollowCursor)
{
AnimController.TargetDir = Direction.Right;
}
else
if (AnimController is not FishAnimController)
{
if (CursorPosition.X < AnimController.Collider.Position.X - cursorFollowMargin)
{
Expand All @@ -2126,6 +2122,10 @@ public void Control(float deltaTime, Camera cam)
AnimController.TargetDir = Direction.Right;
}
}
if (AnimController is HumanoidAnimController && dontFollowCursor) // For character editor
{
AnimController.TargetDir = Direction.Right;
}
}

if (GameMain.NetworkMember != null)
Expand Down Expand Up @@ -5808,6 +5808,25 @@ public void StopClimbing()
AnimController.StopClimbing();
ReleaseSecondaryItem();
}

public void TryFlipCharacter()
{
if (AnimController is FishAnimController fishAnimController)
{
if (fishAnimController.CurrentFishAnimation.Flip)
{
fishAnimController.Flip();
}
}
else
{
AnimController.TargetDir = (AnimController.TargetDir == Direction.Left) ? Direction.Right : Direction.Left;
if (!CanMove)
{
AnimController.Flip();
}
}
}
}

class ActiveTeamChange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ private IEnumerable<CoroutineStatus> CreateAIHusk()
}

husk.SetStun(5);
if (character.IsFlipped)
{
husk.TryFlipCharacter();
}
yield return new WaitForSeconds(5, false);
#if CLIENT
husk?.PlaySound(CharacterSound.SoundType.Idle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ public AITrigger(XElement element)

private readonly int useItemCount;

private readonly bool removeItem, dropContainedItems, dropItem, removeCharacter, breakLimb, hideLimb;
private readonly bool removeItem, dropContainedItems, dropItem, removeCharacter, breakLimb, hideLimb, flipCharacter;
private readonly float hideLimbTimer;

public readonly ActionType type = ActionType.OnActive;
Expand Down Expand Up @@ -968,6 +968,9 @@ protected StatusEffect(ContentXElement element, string parentDebugName)
case "removecharacter":
removeCharacter = true;
break;
case "flipcharacter":
flipCharacter = true;
break;
case "breaklimb":
breakLimb = true;
break;
Expand Down Expand Up @@ -1603,6 +1606,9 @@ protected void Apply(float deltaTime, Entity entity, IReadOnlyList<ISerializable
PhysicsBody parentItemBody = parentItem?.body;
Hull hull = GetHull(entity);
Vector2 position = GetPosition(entity, targets, worldPosition);

bool isNotClient = GameMain.NetworkMember == null || !GameMain.NetworkMember.IsClient;

if (useItemCount > 0)
{
Character useTargetCharacter = null;
Expand Down Expand Up @@ -1687,6 +1693,17 @@ protected void Apply(float deltaTime, Entity entity, IReadOnlyList<ISerializable
}
}
}
if (flipCharacter)
{
for (int i = 0; i < targets.Count; i++)
{
var target = CharacterFromTarget(targets[i]);
if (target != null && isNotClient)
{
target.TryFlipCharacter();
}
}
}
if (breakLimb || hideLimb)
{
for (int i = 0; i < targets.Count; i++)
Expand Down Expand Up @@ -1756,8 +1773,6 @@ protected void Apply(float deltaTime, Entity entity, IReadOnlyList<ISerializable
}
}

bool isNotClient = GameMain.NetworkMember == null || !GameMain.NetworkMember.IsClient;

for (int i = 0; i < targets.Count; i++)
{
var target = targets[i];
Expand Down Expand Up @@ -2051,6 +2066,10 @@ entity is Item item &&
foreach (var target in targets)
{
if (target is not Character character) { continue; }
if (character.IsFlipped)
{
newCharacter.TryFlipCharacter();
}
if (characterSpawnInfo.TransferInventory && character.Inventory != null && newCharacter.Inventory != null)
{
if (character.Inventory.Capacity != newCharacter.Inventory.Capacity) { return; }
Expand Down