155 lines
4.0 KiB
C#
155 lines
4.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITFALL.Player.Movement;
|
|
using BITKit;
|
|
using BITKit.Entities;
|
|
using BITKit.StateMachine;
|
|
using UnityEngine;
|
|
|
|
namespace BITFALL.Entities.Equipment.Melee
|
|
{
|
|
[Serializable]
|
|
public sealed class Draw:PlayerMeleeControllerState
|
|
{
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
meleeController.animator[0].onStateExit += (state) =>
|
|
{
|
|
if(Enabled && state is BITConstant.Player.Draw)
|
|
meleeController.TransitionState<Idle>();
|
|
};
|
|
}
|
|
|
|
public override void OnStateEntry(IState old)
|
|
{
|
|
base.OnStateEntry(old);
|
|
meleeController.animator.Play(BITConstant.Player.Draw);
|
|
}
|
|
}
|
|
[Serializable]
|
|
public sealed class Idle:PlayerMeleeControllerState
|
|
{
|
|
[Inject]
|
|
private IEntityMovement _movement;
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
_movement.OnStateChanged += OnMovementStateChanged;
|
|
}
|
|
|
|
public override void OnStateEntry(IState old)
|
|
{
|
|
base.OnStateEntry(old);
|
|
meleeController.animator.CrossFade(BITConstant.Player.Idle,1f);
|
|
}
|
|
|
|
public override void OnStateUpdate(float deltaTime)
|
|
{
|
|
base.OnStateUpdate(deltaTime);
|
|
meleeController.animator.animator.SetBool(BITConstant.Player.IsRunning,_movement.CurrentState is IPlayerRunState or IPlayerSprintState);
|
|
meleeController.animator.animator.SetBool(BITConstant.Player.IsGrounded,_movement.IsGrounded);
|
|
meleeController.animator.animator.SetBool(BITConstant.Player.IsCrouched,_movement.CurrentState is IPlayerCrouchState);
|
|
}
|
|
|
|
private void OnMovementStateChanged(IEntityMovementState arg1, IEntityMovementState arg2)
|
|
{
|
|
switch (arg2)
|
|
{
|
|
case IPlayerClimbState:
|
|
case IPlayerLinkState:
|
|
meleeController.animator.Play(BITConstant.Player.Climb);
|
|
break;
|
|
}
|
|
|
|
if (Enabled is false) return;
|
|
}
|
|
}
|
|
[Serializable]
|
|
public sealed class Attack:PlayerMeleeControllerState
|
|
{
|
|
[Inject]
|
|
private IEntityMovement _movement;
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
meleeController.animator[0].onStateExit += (state) =>
|
|
{
|
|
if(Enabled && state is BITConstant.Player.Attack)
|
|
meleeController.TransitionState<Idle>();
|
|
};
|
|
}
|
|
public override void OnStateEntry(IState old)
|
|
{
|
|
base.OnStateEntry(old);
|
|
meleeController.animator.Play(BITConstant.Player.Attack);
|
|
}
|
|
public override void OnStateUpdate(float deltaTime)
|
|
{
|
|
base.OnStateUpdate(deltaTime);
|
|
_movement.ExecuteCommand<PlayerCancelRunCommand>();
|
|
}
|
|
}
|
|
[Serializable]
|
|
public sealed class Charging:PlayerMeleeControllerState
|
|
{
|
|
[Inject]
|
|
private IEntityMovement _movement;
|
|
|
|
public override void OnStateEntry(IState old)
|
|
{
|
|
base.OnStateEntry(old);
|
|
meleeController.animator.Play(BITConstant.Player.Charging);
|
|
|
|
}
|
|
public override void OnStateUpdate(float deltaTime)
|
|
{
|
|
base.OnStateUpdate(deltaTime);
|
|
_movement.ExecuteCommand<PlayerCancelRunCommand>();
|
|
}
|
|
}
|
|
[Serializable]
|
|
public sealed class HeavyAttack:PlayerMeleeControllerState
|
|
{
|
|
[Inject]
|
|
private IPlayerMovement _playerMovement;
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
meleeController.animator[0].onStateExit += (state) =>
|
|
{
|
|
if(Enabled && state is BITConstant.Player.HeavyAttack)
|
|
meleeController.TransitionState<Idle>();
|
|
};
|
|
|
|
}
|
|
public override void OnStateEntry(IState old)
|
|
{
|
|
base.OnStateEntry(old);
|
|
meleeController.animator.Play(BITConstant.Player.HeavyAttack);
|
|
_playerMovement.Stamina -= meleeController.melee.HeavyAttackStaminaCost;
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public sealed class Blocking : PlayerMeleeControllerState
|
|
{
|
|
public bool AllowBlockStun => _interval.AllowUpdateWithoutReset is false;
|
|
private readonly IntervalUpdate _interval = new(0.32f);
|
|
[Inject]
|
|
private IEntityMovement _movement;
|
|
public override void OnStateEntry(IState old)
|
|
{
|
|
base.OnStateEntry(old);
|
|
_interval.Reset();
|
|
meleeController.animator.Play(BITConstant.Player.Blocking);
|
|
}
|
|
public override void OnStateUpdate(float deltaTime)
|
|
{
|
|
base.OnStateUpdate(deltaTime);
|
|
_movement.ExecuteCommand<PlayerCancelRunCommand>();
|
|
}
|
|
}
|
|
}
|