Files

247 lines
9.2 KiB
C#
Raw Normal View History

2022-12-26 03:47:56 +02:00
using UnityEngine;
public class AttackState : State
{
public override void UpdateLogic(PlayerNetwork player)
{
2023-01-01 02:09:37 +02:00
player.dashDirection = 0;
2023-04-01 22:50:26 +03:00
if (player.enter)
if (!player.hitstop)
{
2023-04-02 19:53:57 +03:00
player.animationFrames++;
player.attackFrames--;
2023-04-01 22:50:26 +03:00
}
2022-12-26 03:47:56 +02:00
if (!player.enter)
{
2023-01-29 15:10:49 +02:00
if (player.juggleBounce & player.isAir)
{
player.position = new DemonicsVector2((DemonicsFloat)player.position.x, (DemonicsFloat)player.position.y + 7);
player.juggleBounce = false;
}
2023-01-23 18:31:58 +02:00
player.inputBuffer.inputItems[player.inputBuffer.index].frame = 0;
2023-01-01 02:09:37 +02:00
player.animationFrames = 0;
2022-12-26 03:47:56 +02:00
SetTopPriority(player);
2023-01-04 17:56:46 +02:00
player.canChainAttack = false;
2022-12-26 03:47:56 +02:00
player.enter = true;
2023-01-14 19:39:35 +02:00
player.hitbox.enter = false;
2023-01-05 16:37:41 +02:00
player.sound = player.attackNetwork.attackSound;
player.animation = player.attackNetwork.name;
player.attackFrames = DemonicsAnimator.GetMaxAnimationFrames(player.playerStats._animation, player.animation);
2022-12-26 03:47:56 +02:00
}
2023-04-02 19:53:57 +03:00
if (!player.hitstop)
{
AttackCancel(player);
}
2022-12-26 03:47:56 +02:00
if (!player.isAir)
{
2023-01-16 13:26:54 +02:00
player.velocity = new DemonicsVector2(player.attackNetwork.travelDistance.x * (DemonicsFloat)player.flip, (DemonicsFloat)player.attackNetwork.travelDistance.y);
2022-12-26 03:47:56 +02:00
}
else
{
2023-01-05 16:37:41 +02:00
player.velocity = new DemonicsVector2(player.velocity.x, player.velocity.y - (float)DemonicsPhysics.GRAVITY);
2022-12-26 03:47:56 +02:00
}
2023-04-01 22:50:26 +03:00
2023-01-08 18:48:39 +02:00
if (!player.isAir)
{
if (player.pushbackDuration > 0 && player.knockback <= player.pushbackDuration)
{
2023-01-09 18:16:00 +02:00
DemonicsFloat ratio = (DemonicsFloat)player.knockback / (DemonicsFloat)player.pushbackDuration;
2023-01-08 18:48:39 +02:00
DemonicsFloat nextX = DemonicsFloat.Lerp(player.pushbackStart.x, player.pushbackEnd.x, ratio);
DemonicsVector2 nextPosition = new DemonicsVector2(nextX, player.position.y);
player.position = nextPosition;
player.knockback++;
2023-01-11 00:22:37 +02:00
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);
}
2023-01-08 18:48:39 +02:00
}
}
UpdateFramedata(player);
2023-01-07 23:17:55 +02:00
ToJumpState(player);
ToJumpForwardState(player);
2022-12-26 03:47:56 +02:00
ToIdleState(player);
2023-01-06 23:10:53 +02:00
ToIdleFallState(player);
2023-01-09 00:34:18 +02:00
ToHurtState(player);
2023-01-14 19:39:35 +02:00
Shadow(player);
2022-12-26 03:47:56 +02:00
}
2023-01-14 19:39:35 +02:00
2023-01-23 18:31:58 +02:00
private void AttackCancel(PlayerNetwork player)
{
2023-04-02 19:53:57 +03:00
2023-01-23 18:31:58 +02:00
if (player.canChainAttack)
{
if (player.inputBuffer.CurrentInput().frame != 0)
{
if ((DemonicsFloat)player.position.y > DemonicsPhysics.GROUND_POINT)
{
player.isAir = true;
}
if (player.inputBuffer.CurrentInput().inputEnum == InputEnum.Special)
{
Arcana(player, player.isAir);
}
else
{
if (!(player.attackInput == InputEnum.Medium && player.isCrouch))
{
if (player.inputBuffer.CurrentInput().inputEnum != InputEnum.Throw)
{
if (!(player.attackInput == InputEnum.Heavy && !player.isCrouch && player.inputBuffer.CurrentInput().inputEnum == InputEnum.Heavy && player.direction.y >= 0))
{
Attack(player, player.isAir);
}
}
}
}
}
}
}
2022-12-27 13:12:53 +02:00
private void ToJumpState(PlayerNetwork player)
{
2023-01-14 19:39:35 +02:00
if (player.attackNetwork.jumpCancelable && player.canChainAttack || player.isAir && player.canDoubleJump && player.canChainAttack)
2022-12-27 13:12:53 +02:00
{
if (player.direction.y > 0)
{
2023-01-28 17:42:01 +02:00
if (player.isAir)
{
player.canDoubleJump = false;
}
2023-01-29 15:10:49 +02:00
player.juggleBounce = true;
2022-12-27 13:12:53 +02:00
player.isCrouch = false;
player.isAir = false;
GameSimulation.Hitstop = 0;
2023-01-23 18:31:58 +02:00
EnterState(player, "Jump");
2022-12-27 13:12:53 +02:00
}
}
}
private void ToJumpForwardState(PlayerNetwork player)
{
2023-01-14 19:39:35 +02:00
if (player.attackNetwork.jumpCancelable && player.canChainAttack || player.isAir && player.canDoubleJump && player.canChainAttack)
2022-12-27 13:12:53 +02:00
{
if (player.direction.y > 0 && player.direction.x != 0)
{
2023-01-28 17:42:01 +02:00
if (player.isAir)
{
player.canDoubleJump = false;
}
2022-12-31 20:46:52 +02:00
player.jumpDirection = (int)player.direction.x;
2023-01-29 15:10:49 +02:00
player.juggleBounce = true;
2022-12-27 13:12:53 +02:00
player.isCrouch = false;
player.isAir = false;
GameSimulation.Hitstop = 0;
2023-01-23 18:31:58 +02:00
EnterState(player, "JumpForward");
2022-12-27 13:12:53 +02:00
}
}
}
2022-12-26 03:47:56 +02:00
private void ToIdleFallState(PlayerNetwork player)
{
if (player.isAir && (DemonicsFloat)player.position.y <= DemonicsPhysics.GROUND_POINT && (DemonicsFloat)player.velocity.y <= (DemonicsFloat)0)
{
2023-01-23 18:31:58 +02:00
player.sound = "Landed";
2023-01-07 23:17:55 +02:00
player.inPushback = false;
2022-12-26 03:47:56 +02:00
player.isCrouch = false;
player.isAir = false;
2023-01-23 18:31:58 +02:00
EnterState(player, "Idle");
2022-12-26 03:47:56 +02:00
}
}
private void ToIdleState(PlayerNetwork player)
{
if (player.attackFrames <= 0)
{
2023-01-16 13:26:54 +02:00
if (player.isAir || (DemonicsFloat)player.position.y > DemonicsPhysics.GROUND_POINT)
2023-01-06 23:10:53 +02:00
{
player.isCrouch = false;
player.isAir = false;
2023-01-23 18:31:58 +02:00
EnterState(player, "Fall");
2023-01-06 23:10:53 +02:00
}
else
{
if (player.direction.y < 0)
{
player.isCrouch = false;
player.isAir = false;
2023-01-23 18:31:58 +02:00
EnterState(player, "Crouch");
2023-01-06 23:10:53 +02:00
}
else
{
player.isCrouch = false;
player.isAir = false;
2023-01-23 18:31:58 +02:00
EnterState(player, "Idle");
2023-01-06 23:10:53 +02:00
}
}
2022-12-26 03:47:56 +02:00
}
}
2023-01-09 18:16:00 +02:00
2023-01-09 00:34:18 +02:00
private void ToHurtState(PlayerNetwork player)
{
2023-01-20 17:59:16 +02:00
if (IsColliding(player))
2023-01-09 00:34:18 +02:00
{
2023-01-17 23:48:42 +02:00
if (player.attackHurtNetwork.attackType == AttackTypeEnum.Throw)
{
2023-01-23 18:31:58 +02:00
EnterState(player, "Grabbed");
2023-01-17 23:48:42 +02:00
return;
}
2023-01-17 00:02:29 +02:00
if (player.attackHurtNetwork.moveName == "Shadowbreak")
{
2023-01-23 18:31:58 +02:00
EnterState(player, "Knockback");
2023-01-17 00:02:29 +02:00
return;
}
2023-01-09 18:16:00 +02:00
if (player.attackNetwork.superArmor && !player.player.PlayerAnimator.InRecovery(player.animation, player.animationFrames))
{
2023-01-10 18:39:07 +02:00
player.sound = player.attackHurtNetwork.impactSound;
2023-01-09 18:16:00 +02:00
if (player.attackHurtNetwork.cameraShakerNetwork.timer > 0)
{
CameraShake.Instance.Shake(player.attackHurtNetwork.cameraShakerNetwork);
}
2023-01-17 00:02:29 +02:00
player.health -= CalculateDamage(player, player.attackHurtNetwork.damage, player.playerStats.Defense);
player.healthRecoverable -= CalculateRecoverableDamage(player, player.attackHurtNetwork.damage, player.playerStats.Defense);
2023-01-19 04:00:28 +02:00
player.canChainAttack = false;
if (GameSimulation.Hitstop <= 0)
{
GameSimulation.Hitstop = player.attackHurtNetwork.hitstop;
}
2023-01-09 18:16:00 +02:00
player.player.PlayerAnimator.SpriteSuperArmorEffect();
player.player.PlayerUI.Damaged();
2023-01-10 18:39:07 +02:00
player.player.PlayerUI.UpdateHealthDamaged(player.healthRecoverable);
2023-01-09 18:16:00 +02:00
return;
}
2023-01-09 00:34:18 +02:00
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-14 19:39:35 +02:00
2023-01-17 00:02:29 +02:00
2023-01-20 17:59:16 +02:00
if (player.attackHurtNetwork.hardKnockdown)
2023-01-09 00:34:18 +02:00
{
2023-01-23 18:31:58 +02:00
EnterState(player, "Airborne");
2023-01-09 00:34:18 +02:00
}
else
{
2023-01-20 17:59:16 +02:00
if ((DemonicsFloat)player.position.y <= DemonicsPhysics.GROUND_POINT)
2023-01-09 00:34:18 +02:00
{
if (player.attackHurtNetwork.knockbackArc == 0 || player.attackHurtNetwork.softKnockdown)
{
2023-01-23 18:31:58 +02:00
EnterState(player, "Hurt");
2023-01-09 00:34:18 +02:00
}
else
{
2023-01-23 18:31:58 +02:00
EnterState(player, "HurtAir");
2023-01-09 00:34:18 +02:00
}
}
2023-01-20 17:59:16 +02:00
else
{
2023-01-23 18:31:58 +02:00
EnterState(player, "HurtAir");
2023-01-20 17:59:16 +02:00
}
2023-01-09 00:34:18 +02:00
}
}
}
2022-12-26 03:47:56 +02:00
}