2022-12-26 03:47:56 +02:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
2022-12-29 19:32:58 +02:00
|
|
|
public class HurtState : HurtParentState
|
2022-12-26 03:47:56 +02:00
|
|
|
{
|
|
|
|
|
public override void UpdateLogic(PlayerNetwork player)
|
|
|
|
|
{
|
2023-01-06 23:10:53 +02:00
|
|
|
base.UpdateLogic(player);
|
2022-12-26 03:47:56 +02:00
|
|
|
player.animation = "Hurt";
|
2023-01-03 22:34:07 +02:00
|
|
|
if (player.animationFrames < 4)
|
|
|
|
|
{
|
|
|
|
|
player.animationFrames++;
|
|
|
|
|
}
|
|
|
|
|
ToHurtState(player);
|
2022-12-26 03:47:56 +02:00
|
|
|
ToIdleState(player);
|
|
|
|
|
}
|
|
|
|
|
private void ToIdleState(PlayerNetwork player)
|
|
|
|
|
{
|
2023-01-06 05:24:44 +02:00
|
|
|
if (player.stunFrames <= 0 || player.comboTimer <= 0)
|
2022-12-26 03:47:56 +02:00
|
|
|
{
|
2023-01-06 04:04:42 +02:00
|
|
|
player.combo = 0;
|
|
|
|
|
player.player.OtherPlayerUI.ResetCombo();
|
2023-01-06 03:10:59 +02:00
|
|
|
player.player.StopShakeCoroutine();
|
2023-01-06 05:24:44 +02:00
|
|
|
player.player.PlayerUI.SetComboTimerActive(false);
|
2023-01-10 18:39:07 +02:00
|
|
|
player.player.PlayerUI.UpdateHealthDamaged(player.healthRecoverable);
|
2023-01-05 16:37:41 +02:00
|
|
|
player.velocity = DemonicsVector2.Zero;
|
2022-12-26 03:47:56 +02:00
|
|
|
player.enter = false;
|
|
|
|
|
player.state = "Idle";
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-03 22:34:07 +02:00
|
|
|
private void ToHurtState(PlayerNetwork player)
|
|
|
|
|
{
|
2023-01-04 17:56:46 +02:00
|
|
|
if (!player.otherPlayer.canChainAttack && DemonicsCollider.Colliding(player.otherPlayer.hitbox, player.hurtbox))
|
2023-01-03 22:34:07 +02:00
|
|
|
{
|
2023-01-08 18:48:39 +02:00
|
|
|
player.enter = false;
|
|
|
|
|
player.attackHurtNetwork = player.otherPlayer.attackNetwork;
|
|
|
|
|
if (DemonicsPhysics.IsInCorner(player))
|
|
|
|
|
{
|
|
|
|
|
player.otherPlayer.knockback = 0;
|
|
|
|
|
player.otherPlayer.pushbackStart = player.otherPlayer.position;
|
|
|
|
|
player.otherPlayer.pushbackEnd = new DemonicsVector2(player.otherPlayer.position.x + (player.attackHurtNetwork.knockbackForce * -player.otherPlayer.flip), DemonicsPhysics.GROUND_POINT);
|
|
|
|
|
player.otherPlayer.pushbackDuration = player.attackHurtNetwork.knockbackDuration;
|
|
|
|
|
}
|
2023-01-06 03:10:59 +02:00
|
|
|
player.player.StopShakeCoroutine();
|
2023-01-10 18:39:07 +02:00
|
|
|
player.player.PlayerUI.UpdateHealthDamaged(player.healthRecoverable);
|
2023-01-07 23:17:55 +02:00
|
|
|
if (player.attackHurtNetwork.hardKnockdown)
|
|
|
|
|
{
|
|
|
|
|
player.state = "Airborne";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (player.attackHurtNetwork.knockbackArc == 0 || player.attackHurtNetwork.softKnockdown)
|
|
|
|
|
{
|
|
|
|
|
player.state = "Hurt";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
player.state = "HurtAir";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
protected override void OnEnter(PlayerNetwork player)
|
|
|
|
|
{
|
|
|
|
|
CheckFlip(player);
|
2023-01-08 05:07:16 +02:00
|
|
|
base.OnEnter(player);
|
2023-01-07 23:17:55 +02:00
|
|
|
}
|
|
|
|
|
protected override void Knockback(PlayerNetwork player)
|
|
|
|
|
{
|
2023-01-08 05:07:16 +02:00
|
|
|
DemonicsFloat ratio = (DemonicsFloat)player.knockback / (DemonicsFloat)player.attackHurtNetwork.knockbackDuration;
|
|
|
|
|
DemonicsFloat distance = player.pushbackEnd.x - player.pushbackStart.x;
|
|
|
|
|
DemonicsFloat nextX = DemonicsFloat.Lerp(player.pushbackStart.x, player.pushbackEnd.x, ratio);
|
|
|
|
|
DemonicsFloat baseY = DemonicsFloat.Lerp(player.pushbackStart.y, player.pushbackEnd.y, (nextX - player.pushbackStart.x) / distance);
|
|
|
|
|
DemonicsFloat arc = player.attackHurtNetwork.knockbackArc * (nextX - player.pushbackStart.x) * (nextX - player.pushbackEnd.x) / ((-0.25f) * distance * distance);
|
|
|
|
|
DemonicsVector2 nextPosition = DemonicsVector2.Zero;
|
|
|
|
|
if (player.attackHurtNetwork.knockbackArc == 0 || player.attackHurtNetwork.softKnockdown)
|
2023-01-07 23:17:55 +02:00
|
|
|
{
|
2023-01-08 05:07:16 +02:00
|
|
|
nextPosition = new DemonicsVector2(nextX, player.position.y);
|
2022-12-29 19:32:58 +02:00
|
|
|
}
|
2023-01-08 05:07:16 +02:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
nextPosition = new DemonicsVector2(nextX, baseY + arc);
|
|
|
|
|
}
|
|
|
|
|
player.position = nextPosition;
|
|
|
|
|
player.position = nextPosition;
|
|
|
|
|
if (player.position.x >= DemonicsPhysics.WALL_RIGHT_POINT)
|
|
|
|
|
{
|
|
|
|
|
player.position = new DemonicsVector2(DemonicsPhysics.WALL_RIGHT_POINT, player.position.y);
|
|
|
|
|
}
|
|
|
|
|
else if (player.position.x <= DemonicsPhysics.WALL_LEFT_POINT)
|
|
|
|
|
{
|
|
|
|
|
player.position = new DemonicsVector2(DemonicsPhysics.WALL_LEFT_POINT, player.position.y);
|
|
|
|
|
}
|
|
|
|
|
player.knockback++;
|
2022-12-29 19:32:58 +02:00
|
|
|
}
|
2022-12-26 03:47:56 +02:00
|
|
|
}
|