66 lines
2.4 KiB
C#
66 lines
2.4 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using Cysharp.Threading.Tasks;
|
|
using UnityEngine;
|
|
|
|
namespace Code.OfficeGame.BattleMode.Actions.AI.EnemyDeciders
|
|
{
|
|
public class FrankAttackDecider : EnemyDecider
|
|
{
|
|
private EntityProperties _player;
|
|
|
|
public FrankAttackDecider(EntityProperties player)
|
|
{
|
|
_player = player;
|
|
}
|
|
|
|
public override async UniTask<(BattleActionDecisionResult decisionResult, BattleActionData actionData)> DecideEnemy(
|
|
CancellationToken ctx,
|
|
EntityProperties entity,
|
|
Dictionary<BattleActionType,BattleAction> battleActions)
|
|
{
|
|
await UniTask.Yield();
|
|
|
|
var entityPosition = entity.transform.position;
|
|
var playerPosition = _player.transform.position;
|
|
|
|
var enemyToPlayer = playerPosition - entityPosition;
|
|
var rotateToPlayer = Quaternion.LookRotation(
|
|
playerPosition - entityPosition,
|
|
Vector3.up);
|
|
|
|
BattleActionDecisionResult decisionResult = null;
|
|
BattleActionData actionData = null;
|
|
|
|
if (enemyToPlayer.magnitude > 1f)
|
|
{
|
|
var positionToPlayer = entityPosition + enemyToPlayer.normalized * (enemyToPlayer.magnitude - 0.5f);
|
|
|
|
decisionResult = new PositionBattleActionDeciderResult()
|
|
{
|
|
ActionType = BattleActionType.Move,
|
|
Position = positionToPlayer,
|
|
Rotation = rotateToPlayer,
|
|
ResultCode = BattleActionDecisionResultCode.Decided
|
|
};
|
|
|
|
actionData = battleActions[BattleActionType.Move].MountAndGetFrames(entity, decisionResult);
|
|
}
|
|
else
|
|
{
|
|
decisionResult = new RotationBattleActionDeciderResult()
|
|
{
|
|
ActionType = BattleActionType.PlayerAttackMMA,
|
|
Rotation = rotateToPlayer,
|
|
ResultCode = BattleActionDecisionResultCode.Decided
|
|
};
|
|
|
|
actionData = battleActions[BattleActionType.PlayerAttackMMA].MountAndGetFrames(entity, decisionResult);
|
|
}
|
|
|
|
return (decisionResult, actionData);
|
|
}
|
|
|
|
public override EnemyDeciderTypes EnemyDeciderType => EnemyDeciderTypes.FrankAttack;
|
|
}
|
|
} |