Files

139 lines
4.8 KiB
C#
Raw Permalink Normal View History

2022-12-27 13:12:53 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2022-12-29 19:32:58 +02:00
public class HurtAirState : HurtParentState
2022-12-27 13:12:53 +02:00
{
2022-12-27 20:19:09 +02:00
public override void UpdateLogic(PlayerNetwork player)
2022-12-27 13:12:53 +02:00
{
if (!player.enter)
{
OnEnter(player);
return;
}
if (player.enter)
if (player.animationFrames < 4)
{
player.animationFrames++;
}
2023-01-07 23:17:55 +02:00
base.UpdateLogic(player);
2022-12-27 20:19:09 +02:00
player.animation = "HurtAir";
2023-01-04 17:56:46 +02:00
ToHurtState(player);
2022-12-29 14:40:06 +02:00
ToFallState(player);
2023-01-17 04:12:57 +02:00
ToShadowbreakState(player);
2022-12-27 13:12:53 +02:00
}
2023-01-07 23:17:55 +02:00
protected override void AfterHitstop(PlayerNetwork player)
2022-12-27 13:12:53 +02:00
{
2023-02-14 14:31:19 +02:00
if (player.stunFrames == player.attackHurtNetwork.hitStun && player.attackHurtNetwork.knockbackArc == 0)
2023-01-28 17:42:01 +02:00
{
2023-07-02 23:17:37 +03:00
player.velocity = new DemonVector2((DemonFloat)0, (DemonFloat)1.1);
2023-01-28 17:42:01 +02:00
}
2023-01-07 23:17:55 +02:00
base.AfterHitstop(player);
ToIdleState(player);
}
private void ToIdleState(PlayerNetwork player)
{
2023-01-19 02:51:24 +02:00
if (player.attackHurtNetwork.knockbackArc > 0 && player.knockback <= 1)
{
return;
}
2023-07-02 23:17:37 +03:00
if ((DemonFloat)player.position.y <= DemonicsPhysics.GROUND_POINT)
2022-12-27 20:19:09 +02:00
{
2023-01-07 23:17:55 +02:00
player.player.StopShakeCoroutine();
if (player.health <= 0)
{
EnterState(player, "Death");
return;
}
2023-01-07 23:17:55 +02:00
if (player.stunFrames <= 0 || player.comboTimer <= 0)
2022-12-28 14:10:45 +02:00
{
if (SceneSettings.IsTrainingMode && player.isAi)
TrainingSettings.BlockCountCurrent = TrainingSettings.BlockCount;
2023-01-19 19:06:45 +02:00
ResetCombo(player);
2023-01-10 18:39:07 +02:00
player.player.PlayerUI.UpdateHealthDamaged(player.healthRecoverable);
2023-01-23 18:31:58 +02:00
EnterState(player, "Idle");
2023-01-07 23:17:55 +02:00
}
else
{
player.stunFrames = player.attackHurtNetwork.hitStun;
2023-07-02 23:17:37 +03:00
player.velocity = DemonVector2.Zero;
2023-01-07 23:17:55 +02:00
player.animationFrames = 0;
2023-01-23 18:31:58 +02:00
EnterState(player, "Hurt", true);
2022-12-28 14:10:45 +02:00
}
}
}
2023-01-07 23:17:55 +02:00
private void ToFallState(PlayerNetwork player)
2022-12-29 19:32:58 +02:00
{
2023-02-22 14:57:43 +02:00
if (player.health <= 0)
{
return;
}
2023-01-07 23:17:55 +02:00
if (player.stunFrames <= 0 || player.comboTimer <= 0)
2022-12-29 19:32:58 +02:00
{
if (SceneSettings.IsTrainingMode && player.isAi)
TrainingSettings.BlockCountCurrent = TrainingSettings.BlockCount;
2023-01-19 19:06:45 +02:00
ResetCombo(player);
2023-01-10 18:39:07 +02:00
player.player.PlayerUI.UpdateHealthDamaged(player.healthRecoverable);
2023-03-06 13:56:15 +02:00
if (AIHurt(player))
return;
2023-01-23 18:31:58 +02:00
EnterState(player, "Fall");
2022-12-29 19:32:58 +02:00
}
}
2022-12-28 14:10:45 +02:00
private void ToHurtState(PlayerNetwork player)
{
2023-01-15 13:05:14 +02:00
if (IsColliding(player))
2022-12-28 14:10:45 +02:00
{
2023-01-07 23:17:55 +02:00
player.player.StopShakeCoroutine();
2023-01-10 18:39:07 +02:00
player.player.PlayerUI.UpdateHealthDamaged(player.healthRecoverable);
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");
2023-01-13 15:28:18 +02:00
return;
}
2023-01-07 23:17:55 +02:00
if (player.attackHurtNetwork.hardKnockdown || player.attackHurtNetwork.softKnockdown)
2022-12-28 14:10:45 +02:00
{
2023-01-23 18:31:58 +02:00
EnterState(player, "Airborne");
2023-01-04 17:56:46 +02:00
}
else
{
2023-01-23 18:31:58 +02:00
EnterState(player, "HurtAir");
2022-12-28 14:10:45 +02:00
}
2022-12-27 20:19:09 +02:00
}
2022-12-27 13:12:53 +02:00
}
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);
2023-01-07 23:17:55 +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++;
2023-01-07 23:17:55 +02:00
}
2022-12-27 13:12:53 +02:00
}
2022-12-27 20:19:09 +02:00