Files

113 lines
4.1 KiB
C#
Raw Permalink Normal View History

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)
{
if (!player.enter)
{
OnEnter(player);
return;
}
if (player.enter)
if (player.animationFrames < 4)
{
player.animationFrames++;
}
2023-01-06 23:10:53 +02:00
base.UpdateLogic(player);
2022-12-26 03:47:56 +02:00
player.animation = "Hurt";
2023-07-02 23:17:37 +03:00
player.velocity = DemonVector2.Zero;
2022-12-26 03:47:56 +02:00
ToIdleState(player);
2023-01-29 15:10:49 +02:00
ToHurtState(player);
2023-01-17 04:12:57 +02:00
ToShadowbreakState(player);
2022-12-26 03:47:56 +02:00
}
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
{
if (SceneSettings.IsTrainingMode && player.isAi)
TrainingSettings.BlockCountCurrent = TrainingSettings.BlockCount;
2023-01-19 17:07:46 +02:00
ResetCombo(player);
2023-01-10 18:39:07 +02:00
player.player.PlayerUI.UpdateHealthDamaged(player.healthRecoverable);
2023-07-02 23:17:37 +03:00
player.velocity = DemonVector2.Zero;
if (player.health <= 0)
{
EnterState(player, "Death");
return;
}
2023-03-06 13:56:15 +02:00
if (AIHurt(player))
return;
2023-01-23 18:31:58 +02:00
EnterState(player, "Idle");
2022-12-26 03:47:56 +02:00
}
}
2023-01-23 18:31:58 +02:00
private void ToHurtState(PlayerNetwork player)
2023-01-03 22:34:07 +02:00
{
2023-01-14 19:39:35 +02:00
if (IsColliding(player))
2023-01-03 22:34:07 +02:00
{
2023-01-13 15:28:18 +02:00
if (player.attackHurtNetwork.attackType == AttackTypeEnum.Throw)
{
2023-01-23 18:31:58 +02:00
EnterState(player, "Grabbed");
return;
2023-01-13 15:28:18 +02:00
}
2023-01-08 18:48:39 +02:00
if (DemonicsPhysics.IsInCorner(player))
{
player.otherPlayer.knockback = 0;
player.otherPlayer.pushbackStart = player.otherPlayer.position;
2023-07-02 23:17:37 +03:00
player.otherPlayer.pushbackEnd = new DemonVector2(player.otherPlayer.position.x + (player.attackHurtNetwork.knockbackForce * -player.otherPlayer.flip), DemonicsPhysics.GROUND_POINT);
2023-01-08 18:48:39 +02:00
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)
{
2023-01-23 18:31:58 +02:00
EnterState(player, "Airborne");
2023-01-07 23:17:55 +02:00
}
else
{
if (player.attackHurtNetwork.knockbackArc == 0 || player.attackHurtNetwork.softKnockdown)
{
2023-01-23 18:31:58 +02:00
EnterState(player, "Hurt");
2023-01-07 23:17:55 +02:00
}
else
{
2023-01-23 18:31:58 +02:00
EnterState(player, "HurtAir");
2023-01-07 23:17:55 +02:00
}
}
}
}
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-07-02 23:17:37 +03:00
DemonFloat ratio = (DemonFloat)player.knockback / (DemonFloat)player.attackHurtNetwork.knockbackDuration;
DemonFloat distance = player.pushbackEnd.x - player.pushbackStart.x;
DemonFloat nextX = DemonFloat.Lerp(player.pushbackStart.x, player.pushbackEnd.x, ratio);
DemonFloat baseY = DemonFloat.Lerp(player.pushbackStart.y, player.pushbackEnd.y, (nextX - player.pushbackStart.x) / distance);
DemonFloat arc = player.attackHurtNetwork.knockbackArc * (nextX - player.pushbackStart.x) * (nextX - player.pushbackEnd.x) / ((-0.25f) * distance * distance);
DemonVector2 nextPosition = DemonVector2.Zero;
2023-01-08 05:07:16 +02:00
if (player.attackHurtNetwork.knockbackArc == 0 || player.attackHurtNetwork.softKnockdown)
2023-01-07 23:17:55 +02:00
{
2023-07-02 23:17:37 +03:00
nextPosition = new DemonVector2(nextX, player.position.y);
2022-12-29 19:32:58 +02:00
}
2023-01-08 05:07:16 +02:00
else
{
2023-07-02 23:17:37 +03:00
nextPosition = new DemonVector2(nextX, baseY + arc);
2023-01-08 05:07:16 +02:00
}
player.position = nextPosition;
if (player.position.x >= DemonicsPhysics.WALL_RIGHT_POINT)
{
2023-07-02 23:17:37 +03:00
player.position = new DemonVector2(DemonicsPhysics.WALL_RIGHT_POINT, player.position.y);
2023-01-08 05:07:16 +02:00
}
else if (player.position.x <= DemonicsPhysics.WALL_LEFT_POINT)
{
2023-07-02 23:17:37 +03:00
player.position = new DemonVector2(DemonicsPhysics.WALL_LEFT_POINT, player.position.y);
2023-01-08 05:07:16 +02:00
}
player.knockback++;
2022-12-29 19:32:58 +02:00
}
2022-12-26 03:47:56 +02:00
}