81 lines
3.3 KiB
C#
81 lines
3.3 KiB
C#
using System.Linq;
|
|
using Code.Infrastructure.Utils;
|
|
using Code.OfficeGame.BattleMode.Actions.Deciders;
|
|
using Code.OfficeGame.BattleMode.HitBoxes;
|
|
using UnityEngine;
|
|
|
|
namespace Code.OfficeGame.BattleMode.Actions.Attacks
|
|
{
|
|
public class BattleActionPlayerAttackMMA : BattleAction
|
|
{
|
|
private AttackActionConfig _attackData;
|
|
public int EntryStateHash => Animator.StringToHash("WalkBlend");
|
|
|
|
public BattleActionPlayerAttackMMA(MultipleConfig<BattleActionParameters> attackData)
|
|
{
|
|
_attackData = (AttackActionConfig)
|
|
attackData.Configs.SingleOrDefault(x=>x.ActionType == ActionType);
|
|
}
|
|
public override BattleActionType ActionType => BattleActionType.PlayerAttackMMA;
|
|
|
|
public override bool Tick(float tickDelta,
|
|
EntityProperties entity,
|
|
BattleActionDecisionResult battleActionDecisionResult,
|
|
BattleActionData battleActionData)
|
|
{
|
|
if (battleActionData is not AttackBattleActionData actionData) return true;
|
|
|
|
if (actionData.CurrentFrame == 0)
|
|
{
|
|
var entityAnimator = entity.animator;
|
|
|
|
// TODO Root Motion не должен быть использован в нормальных анимациях
|
|
entityAnimator.Play(EntryStateHash, 0, 0f); // Создать None State и кинуть эту штуку туда
|
|
entityAnimator.Update(0f);
|
|
|
|
entityAnimator.applyRootMotion = false;
|
|
entityAnimator.transform.localPosition = Vector3.zero;
|
|
entityAnimator.transform.localRotation = Quaternion.identity;
|
|
|
|
entityAnimator.applyRootMotion = true;
|
|
entityAnimator.Play(_attackData.StateHash, 0, 0f);
|
|
}
|
|
|
|
actionData.CurrentFrame++;
|
|
|
|
if (actionData.CurrentFrame >= _attackData.HitboxStartFrame
|
|
&& actionData.CurrentFrame <= _attackData.HitboxEndFrame)
|
|
{
|
|
entity.EntityHitBoxes.CheckHitsForCurrentFrame(OnEnemyHit, HitBoxPartType.LArm);
|
|
}
|
|
|
|
if (actionData.CurrentFrame >= _attackData.TotalFrames)
|
|
{
|
|
var entityAnimator = entity.animator;
|
|
|
|
entityAnimator.Play(EntryStateHash, 0, 0f); // Создать None State и кинуть эту штуку туда
|
|
entityAnimator.Update(0f);
|
|
|
|
// TODO С нормальными анимациями не нужен будет рут моушен√
|
|
entityAnimator.applyRootMotion = false;
|
|
entityAnimator.transform.localPosition = Vector3.zero;
|
|
entityAnimator.transform.localRotation = Quaternion.identity;
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public override DeciderType DeciderType => DeciderType.Position;
|
|
public override BattleActionData MountAndGetFrames(EntityProperties entity, BattleActionDecisionResult result)
|
|
{
|
|
return new AttackBattleActionData() { TotalFrames = _attackData.TotalFrames };
|
|
}
|
|
|
|
private void OnEnemyHit(Collider enemyCollider)
|
|
{
|
|
Debug.Log($"Попадание в {enemyCollider.name}! Урон: {_attackData.Damage}");
|
|
}
|
|
}
|
|
} |