1
This commit is contained in:
@@ -2,6 +2,8 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITFALL.Items.Melee;
|
||||
using BITFALL.Combat;
|
||||
using BITFALL.Player.Movement;
|
||||
using BITKit;
|
||||
using BITKit.Core.Entites;
|
||||
using BITKit.Entities;
|
||||
@@ -24,7 +26,7 @@ namespace BITFALL.Entities.Equipment.Melee
|
||||
public virtual bool Enabled { get; set; }
|
||||
public virtual void Initialize()
|
||||
{
|
||||
|
||||
meleeController.Entity.Inject(this);
|
||||
}
|
||||
|
||||
public virtual void OnStateEntry(IState old)
|
||||
@@ -43,6 +45,7 @@ namespace BITFALL.Entities.Equipment.Melee
|
||||
{
|
||||
[Header(Constant.Header.Input)]
|
||||
[SerializeField] private InputActionReference attackAction;
|
||||
[SerializeField] private InputActionReference blockAction;
|
||||
|
||||
[Header(Constant.Header.Gameobjects)]
|
||||
[SerializeField] private Transform velocityReference;
|
||||
@@ -55,15 +58,68 @@ namespace BITFALL.Entities.Equipment.Melee
|
||||
|
||||
[Inject]
|
||||
private IEntityMovement _movement;
|
||||
[Inject]
|
||||
private IPlayerMovement _playerMovement;
|
||||
[Inject] private IHealth _health;
|
||||
public override void OnAwake()
|
||||
{
|
||||
base.OnAwake();
|
||||
inputActionGroup.RegisterCallback(attackAction, OnAttack);
|
||||
inputActionGroup.RegisterCallback(blockAction, OnBlock);
|
||||
_health.OnDamageFactory += OnDamageFactory;
|
||||
|
||||
_movement.OnStateChanged += OnMovementStateChanged;
|
||||
}
|
||||
|
||||
private void OnMovementStateChanged(IEntityMovementState arg1, IEntityMovementState arg2)
|
||||
{
|
||||
switch (arg2)
|
||||
{
|
||||
case IPlayerDodgeState:
|
||||
TransitionState<Idle>();
|
||||
animator.Play(BITConstant.Player.Dodge);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private int OnDamageFactory(DamageMessage arg1, int arg2)
|
||||
{
|
||||
if (Enabled is false || arg1.Initiator is null) return arg2;
|
||||
if (CurrentState is not Blocking blocking) return arg2;
|
||||
var combat = arg1.Initiator.Get<IMeleeCombat>();
|
||||
if (combat is null) return arg2;
|
||||
|
||||
if (blocking.AllowBlockStun && _playerMovement.Stamina >= melee.BlockStaminaCost)
|
||||
{
|
||||
arg2 =0;
|
||||
combat.HitStun();
|
||||
|
||||
animator.Play(BITConstant.Player.BlockStun);
|
||||
|
||||
_playerMovement.Stamina -= melee.BlockStaminaCost*0.5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_playerMovement.Stamina > melee.BlockStaminaCost)
|
||||
{
|
||||
animator.Play(BITConstant.Player.BlockStun);
|
||||
arg2 /= 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
animator.Play(BITConstant.Player.BlockBreak);
|
||||
arg2 /= 2;
|
||||
}
|
||||
_playerMovement.Stamina -= melee.BlockStaminaCost;
|
||||
}
|
||||
|
||||
|
||||
return arg2;
|
||||
}
|
||||
public override void Entry()
|
||||
{
|
||||
base.Entry();
|
||||
|
||||
TransitionState<Draw>();
|
||||
}
|
||||
|
||||
@@ -79,7 +135,19 @@ namespace BITFALL.Entities.Equipment.Melee
|
||||
|
||||
animator.animator.SetFloat(BITConstant.Player.SqrMagnitude,sqr);
|
||||
}
|
||||
|
||||
private void OnBlock(InputAction.CallbackContext obj)
|
||||
{
|
||||
switch (obj)
|
||||
{
|
||||
case {interaction:TapInteraction,started:true} when CurrentState is Idle:
|
||||
TransitionState<Blocking>();
|
||||
break;
|
||||
case {interaction:TapInteraction,performed:true} when CurrentState is Blocking:
|
||||
case {interaction:HoldInteraction,canceled:true} when CurrentState is Blocking:
|
||||
TransitionState<Idle>();
|
||||
break;
|
||||
}
|
||||
}
|
||||
private void OnAttack(InputAction.CallbackContext context)
|
||||
{
|
||||
//如果启用了指针则不开火
|
||||
@@ -89,13 +157,13 @@ namespace BITFALL.Entities.Equipment.Melee
|
||||
}
|
||||
switch (context)
|
||||
{
|
||||
case {interaction: TapInteraction,performed:true} when CurrentState is not (Attack or HeavyAttack or Draw):
|
||||
case {interaction: TapInteraction,performed:true} when CurrentState is not (Attack or HeavyAttack or Draw or Blocking):
|
||||
TransitionState<Attack>();
|
||||
break;
|
||||
case {interaction: HoldInteraction,started:true} when CurrentState is not (Charging or Attack or HeavyAttack or Draw):
|
||||
case {interaction: HoldInteraction,started:true} when CurrentState is not (Charging or Attack or HeavyAttack or Draw or Blocking):
|
||||
TransitionState<Charging>();
|
||||
break;
|
||||
case {interaction: HoldInteraction,canceled:true} when CurrentState is not (Attack or Idle or Draw):
|
||||
case {interaction: HoldInteraction,canceled:true} when CurrentState is not (Attack or Idle or Draw or Blocking):
|
||||
TransitionState<HeavyAttack>();
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user