Silly enemy, attack bug fix
This commit is contained in:
1 parent
b02e201cd0
commit
1d107924bf
567 files changed
+197825
-635242
No files matched your search
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
|
||||
@@ -6,6 +7,8 @@ namespace Code.OfficeGame.BattleMode.Actions.AI
|
||||
public abstract class EnemyDecider
|
||||
{
|
||||
public abstract UniTask<(BattleActionDecisionResult decisionResult, BattleActionData actionData)>
|
||||
DecideEnemy(CancellationToken ctx, EntityProperties entity);
|
||||
DecideEnemy(CancellationToken ctx, EntityProperties entity, Dictionary<BattleActionType, BattleAction> battleActions);
|
||||
|
||||
public abstract EnemyDeciderTypes EnemyDeciderType { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1bba480028a459a960d731f9ae971d5
|
||||
timeCreated: 1794940179
|
||||
guid: bbfe8fd114bf4814b5efecee9b2bf086
|
||||
timeCreated: 1794949033
|
||||
@@ -0,0 +1,66 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2dfe2052460497c938ce9fdcc3826c1
|
||||
timeCreated: 1794949053
|
||||
@@ -1,7 +1,6 @@
|
||||
using Code.Game.Gameplay.Player;
|
||||
using Code.OfficeGame.BattleMode.Actions.Deciders;
|
||||
using Code.OfficeGame.BattleMode.Timeline;
|
||||
using KinematicCharacterController;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
public override void Tick(float tickDelta, EntityProperties entity, BattleActionDecisionResult battleActionDecisionResult,
|
||||
BattleActionData battleActionData)
|
||||
{
|
||||
battleActionData.Finished = true;
|
||||
// battleActionData.Finished = true;
|
||||
}
|
||||
|
||||
|
||||
public override BattleActionType ActionType => BattleActionType.None;
|
||||
public override DeciderType DeciderType => DeciderType.AsIs;
|
||||
public override BattleActionData MountAndGetFrames(EntityProperties entity, BattleActionDecisionResult result)
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Code.OfficeGame.BattleMode.Actions.Deciders
|
||||
private CameraStateMachine _cameraStateMachine;
|
||||
private IInputService _inputService;
|
||||
|
||||
private Quaternion _targetRotation;
|
||||
private Quaternion _targetRotation, _chosenRotation;
|
||||
|
||||
private LayerMask _navMeshMask;
|
||||
|
||||
@@ -46,11 +46,13 @@ namespace Code.OfficeGame.BattleMode.Actions.Deciders
|
||||
|
||||
_waitForEnterTokenSource.Dispose();
|
||||
_waitForEnterTokenSource = null;
|
||||
|
||||
if (_chosenRotation == default) _chosenRotation = _targetRotation;
|
||||
|
||||
return new RotationBattleActionDeciderResult()
|
||||
{
|
||||
ResultCode = _decisionResultCode,
|
||||
Rotation = _targetRotation
|
||||
Rotation = _chosenRotation
|
||||
};
|
||||
}
|
||||
|
||||
@@ -153,6 +155,8 @@ namespace Code.OfficeGame.BattleMode.Actions.Deciders
|
||||
_playerLockedDecisionMarker.transform.rotation = _targetRotation;
|
||||
_playerLockedDecisionMarker.Toggle(true);
|
||||
|
||||
_chosenRotation = _targetRotation;
|
||||
|
||||
_waitForEnterTokenSource?.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
|
||||
public EntityHealth EntityHealth;
|
||||
|
||||
public EntityTeam Team;
|
||||
public EntityTeamData TeamData;
|
||||
|
||||
[DoNotSerialize]
|
||||
public List<Effect> Effects = new();
|
||||
|
||||
@@ -12,6 +12,8 @@ using Code.Infrastructure.SceneLoader;
|
||||
using Code.Infrastructure.UI;
|
||||
using Code.Infrastructure.Utils;
|
||||
using Code.OfficeGame.BattleMode.Actions;
|
||||
using Code.OfficeGame.BattleMode.Actions.AI;
|
||||
using Code.OfficeGame.BattleMode.Actions.AI.EnemyDeciders;
|
||||
using Code.OfficeGame.BattleMode.Actions.Attacks;
|
||||
using Code.OfficeGame.BattleMode.Actions.Deciders;
|
||||
using Code.OfficeGame.BattleMode.Actions.Player;
|
||||
@@ -121,6 +123,8 @@ namespace Code.Game.OfficeGame.GameStates
|
||||
builder.RegisterType(typeof(RotationBattleActionDecider), new[]{ typeof(BattleActionDecider) } , Lifetime.Singleton, Resolution.Eager);
|
||||
builder.RegisterType(typeof(AsIsBattleActionDecider), new[]{ typeof(BattleActionDecider) } , Lifetime.Singleton, Resolution.Eager);
|
||||
|
||||
builder.RegisterType(typeof(FrankAttackDecider), new[]{ typeof(EnemyDecider) } , Lifetime.Singleton, Resolution.Eager);
|
||||
|
||||
builder.RegisterType(typeof(BattleTimeline), Lifetime.Singleton, Resolution.Eager);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Code.Infrastructure.Camera;
|
||||
using Code.Infrastructure.UI;
|
||||
@@ -41,8 +40,6 @@ namespace Code.OfficeGame.BattleMode.Health.UI
|
||||
Vector3 screenPos = _camera.WorldToScreenPoint(_target.position);
|
||||
|
||||
bool isVisible = screenPos.z > 0;
|
||||
if (gameObject.activeSelf != isVisible)
|
||||
gameObject.SetActive(isVisible);
|
||||
|
||||
if (isVisible)
|
||||
transform.position = screenPos;
|
||||
|
||||
@@ -7,6 +7,7 @@ using Code.Game.OfficeGame.BattleMode;
|
||||
using Code.Game.OfficeGame.Entities;
|
||||
using Code.Infrastructure.Camera;
|
||||
using Code.OfficeGame.BattleMode.Actions;
|
||||
using Code.OfficeGame.BattleMode.Actions.AI;
|
||||
using Code.OfficeGame.BattleMode.Actions.Deciders;
|
||||
using Code.OfficeGame.BattleMode.Effects;
|
||||
using Code.OfficeGame.BattleMode.Snapshots;
|
||||
@@ -30,6 +31,7 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
|
||||
private Dictionary<BattleActionType, BattleAction> _battleActions;
|
||||
private Dictionary<DeciderType, BattleActionDecider> _battleActionDeciders;
|
||||
private Dictionary<EnemyDeciderTypes, EnemyDecider> _enemyDeciders;
|
||||
|
||||
private Dictionary<EntityId, EntityProperties> _entities;
|
||||
private Dictionary<EntityId, BattleActionData> _battleActionDatas = new();
|
||||
@@ -49,6 +51,7 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
BattleTimelinePanel timelinePanel,
|
||||
IEnumerable<BattleAction> battleActions,
|
||||
IEnumerable<BattleActionDecider> battleActionDeciders,
|
||||
IEnumerable<EnemyDecider> enemyDeciders,
|
||||
BattleActionDecisionPanel battleActionDecisionPanel,
|
||||
CameraStateMachine cameraStateMachine)
|
||||
{
|
||||
@@ -64,6 +67,7 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
}
|
||||
|
||||
_battleActionDeciders = battleActionDeciders.ToDictionary(x => x.DeciderType);
|
||||
_enemyDeciders = enemyDeciders.ToDictionary(x=>x.EnemyDeciderType);
|
||||
}
|
||||
|
||||
public async UniTask RunBattleLoopAsync(List<EntityProperties> entities, CancellationToken ctx)
|
||||
@@ -347,9 +351,8 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
|
||||
private async UniTask<(BattleActionDecisionResult, BattleActionData)> DecideAction(CancellationToken ctx,
|
||||
EntityProperties entity)
|
||||
|
||||
{
|
||||
if(entity.Team == EntityTeam.Good)
|
||||
if(entity.TeamData.Team == EntityTeam.Good)
|
||||
{
|
||||
var (decisionResult, actionData) = await DecideForPlayer(ctx, entity);
|
||||
|
||||
@@ -358,10 +361,19 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
|
||||
return (decisionResult, actionData);
|
||||
}
|
||||
|
||||
if (entity.TeamData.Team == EntityTeam.ChaoticEvil)
|
||||
{
|
||||
var (enemyDecisionResult, enemyActionData) =
|
||||
await _enemyDeciders[entity.TeamData.DeciderType].DecideEnemy(ctx, entity, _battleActions);
|
||||
|
||||
|
||||
|
||||
return (null,null);
|
||||
if (enemyDecisionResult == null || enemyActionData == null)
|
||||
throw new ArgumentNullException(nameof(enemyDecisionResult));
|
||||
|
||||
return (enemyDecisionResult, enemyActionData);
|
||||
}
|
||||
|
||||
return (new AsIsBattleActionDeciderResult(), new NoneBattleActionData());
|
||||
}
|
||||
|
||||
private async UniTask<(BattleActionDecisionResult decisionResult, BattleActionData actionData)> DecideForPlayer(CancellationToken ctx, EntityProperties entity)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using Alchemy.Inspector;
|
||||
using Code.OfficeGame.BattleMode.Actions.AI;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Code.Game.OfficeGame.Entities
|
||||
{
|
||||
// Совершенству нет предела, пора перестать делать
|
||||
[Serializable]
|
||||
public struct EntityTeamData
|
||||
{
|
||||
public EntityTeam Team;
|
||||
|
||||
[HelpBox("Choose automated", HelpBoxMessageType.Warning)]
|
||||
public EnemyDeciderTypes DeciderType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c8ada8c19fd4447977632955cbbab13
|
||||
timeCreated: 1794947114
|
||||
@@ -649,6 +649,9 @@ MonoBehaviour:
|
||||
EntityHitBoxes: {fileID: 763278329666219388}
|
||||
EntityPreviewVisuals: {fileID: 1229843420206488908}
|
||||
EntityHealth: {fileID: 1670091874095856659}
|
||||
TeamData:
|
||||
Team: 1
|
||||
DeciderType: 0
|
||||
--- !u!114 &1229843420206488908
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
Reference in new issue
Block a user