Preview improvements. StillBug
This commit is contained in:
1 parent
f927552adc
commit
3678d039e3
161 files changed
+34009
-61541
No files matched your search
@@ -0,0 +1,47 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Code.OfficeGame.BattleMode.Actions.AI
|
||||
{
|
||||
public interface IBattleAiResolver
|
||||
{
|
||||
bool TryResolveNextAction(
|
||||
EntityProperties entity,
|
||||
IReadOnlyDictionary<BattleActionType, BattleAction> battleActions,
|
||||
out BattleActionDecisionResult decisionResult,
|
||||
out BattleActionData actionData);
|
||||
}
|
||||
|
||||
public sealed class BattleAiResolver : IBattleAiResolver
|
||||
{
|
||||
private readonly Dictionary<EnemyDeciderTypes, EnemyDecider> _deciders;
|
||||
|
||||
public BattleAiResolver(IEnumerable<EnemyDecider> enemyDeciders)
|
||||
{
|
||||
_deciders = enemyDeciders.ToDictionary(x => x.EnemyDeciderType);
|
||||
}
|
||||
|
||||
public bool TryResolveNextAction(
|
||||
EntityProperties entity,
|
||||
IReadOnlyDictionary<BattleActionType, BattleAction> battleActions,
|
||||
out BattleActionDecisionResult decisionResult,
|
||||
out BattleActionData actionData)
|
||||
{
|
||||
if (_deciders.TryGetValue(entity.TeamData.DeciderType, out var decider))
|
||||
{
|
||||
(decisionResult, actionData) = decider.DecideEnemy(entity, battleActions);
|
||||
|
||||
if (decisionResult != null
|
||||
&& actionData != null
|
||||
&& decisionResult.ActionType != BattleActionType.None)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
decisionResult = null;
|
||||
actionData = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
File renamed without changes.
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Code.Game.Entities;
|
||||
using Code.Game.OfficeGame.Entities;
|
||||
using Code.OfficeGame.BattleMode.Actions;
|
||||
using Code.OfficeGame.BattleMode.Actions.AI;
|
||||
using Code.OfficeGame.BattleMode.Effects;
|
||||
using Code.OfficeGame.BattleMode.HitBoxes;
|
||||
using KinematicCharacterController;
|
||||
@@ -14,12 +16,14 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
float TickDelta { get; }
|
||||
int CurrentSimFrame { get; }
|
||||
int GetSlotIndex(EntityId entityId);
|
||||
|
||||
void SubmitAttack(
|
||||
EntityId attackerId,
|
||||
EntityId defenderId,
|
||||
HitBoxPartType hitPart,
|
||||
Vector3 hitWorldPosition,
|
||||
EntityAttackedData attackedData);
|
||||
|
||||
void RecordHitboxVisual(BoxCollider box, Color color);
|
||||
}
|
||||
|
||||
@@ -46,9 +50,14 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
private Dictionary<EntityId, int> _idToSlot;
|
||||
private EntityActionSlotSnapshot[] _workingSlots;
|
||||
|
||||
public BattleSimulator(Dictionary<BattleActionType, BattleAction> actions)
|
||||
private readonly IBattleAiResolver _aiResolver;
|
||||
|
||||
public BattleSimulator(
|
||||
Dictionary<BattleActionType, BattleAction> actions,
|
||||
IBattleAiResolver aiResolver)
|
||||
{
|
||||
_actions = actions;
|
||||
_aiResolver = aiResolver;
|
||||
}
|
||||
|
||||
public void BindEntities(EntityProperties[] entities)
|
||||
@@ -75,6 +84,7 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
{
|
||||
if (unique.Add(t)) list.Add(t);
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
@@ -162,6 +172,7 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
{
|
||||
EntitySnapshot.ApplyVisualOnly(_entities[i], _entityBones[i], snapshot.Entities[i].PhysicsAndVisuals);
|
||||
}
|
||||
|
||||
Physics.SyncTransforms();
|
||||
}
|
||||
|
||||
@@ -172,8 +183,10 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
{
|
||||
for (int i = 0; i < _entities.Length; i++)
|
||||
{
|
||||
EntitySnapshot.RestoreForSimulation(_entities[i], _entityBones[i], snapshot.Entities[i].PhysicsAndVisuals);
|
||||
EntitySnapshot.RestoreForSimulation(_entities[i], _entityBones[i],
|
||||
snapshot.Entities[i].PhysicsAndVisuals);
|
||||
}
|
||||
|
||||
Physics.SyncTransforms();
|
||||
}
|
||||
|
||||
@@ -240,6 +253,7 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
if (slot.ActionType != BattleActionType.None && slot.ActionData != null && !slot.ActionData.Finished)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -368,6 +382,50 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
}
|
||||
}
|
||||
|
||||
// Авто-цепочка ходов ИИ: если игрок НЕ освободился в этом кадре, но всё ещё занят действием,
|
||||
// освободившиеся враги сразу выбирают следующее действие прямо внутри запекания.
|
||||
if (_aiResolver != null && readyMask != 0UL)
|
||||
{
|
||||
bool anyPlayerReadyThisFrame = false;
|
||||
bool anyPlayerStillBusy = false;
|
||||
|
||||
for (int i = 0; i < _entities.Length; i++)
|
||||
{
|
||||
if (_entities[i].EntityHealth.IsDead) continue;
|
||||
if (_entities[i].TeamData.Team != EntityTeam.Good) continue;
|
||||
|
||||
if ((readyMask & (1UL << i)) != 0UL)
|
||||
anyPlayerReadyThisFrame = true;
|
||||
else if (_workingSlots[i].ActionType != BattleActionType.None &&
|
||||
!_workingSlots[i].ActionData.Finished)
|
||||
anyPlayerStillBusy = true;
|
||||
}
|
||||
|
||||
if (!anyPlayerReadyThisFrame && anyPlayerStillBusy)
|
||||
{
|
||||
for (int i = 0; i < _entities.Length; i++)
|
||||
{
|
||||
if ((readyMask & (1UL << i)) == 0UL) continue;
|
||||
|
||||
var entity = _entities[i];
|
||||
if (entity.TeamData.Team != EntityTeam.ChaoticEvil) continue;
|
||||
|
||||
if (_aiResolver.TryResolveNextAction(entity, _actions, out var nextDecision, out var nextData))
|
||||
{
|
||||
_workingSlots[i] = new EntityActionSlotSnapshot
|
||||
{
|
||||
ActionType = nextDecision.ActionType,
|
||||
DecisionResult = nextDecision,
|
||||
ActionData = nextData,
|
||||
LastCompletedActionType = _workingSlots[i].LastCompletedActionType,
|
||||
ActionStartFrame = frame,
|
||||
EstimatedEndFrame = frame + nextData.TotalFrames
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return CaptureCurrentFrame(
|
||||
frame,
|
||||
currentStage,
|
||||
@@ -404,10 +462,12 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
|
||||
int damage = request.Damage;
|
||||
foreach (var effect in attacker.Effects)
|
||||
if (effect is AttackEffect atk) atk.Apply(ref damage);
|
||||
if (effect is AttackEffect atk)
|
||||
atk.Apply(ref damage);
|
||||
|
||||
foreach (var effect in defender.Effects)
|
||||
if (effect is DefenseEffect def) def.Apply(ref damage);
|
||||
if (effect is DefenseEffect def)
|
||||
def.Apply(ref damage);
|
||||
|
||||
defender.EntityHealth.GetDamage(damage, request.HitBoxPartType);
|
||||
|
||||
@@ -429,7 +489,8 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
|
||||
if (defender.EntityHealth.IsDead)
|
||||
{
|
||||
_workingSlots[defenderSlot] = EntityActionSlotSnapshot.CreateNone(frame, oldSlot.LastCompletedActionType);
|
||||
_workingSlots[defenderSlot] =
|
||||
EntityActionSlotSnapshot.CreateNone(frame, oldSlot.LastCompletedActionType);
|
||||
|
||||
_frameEvents.Add(new TimelineEvent(
|
||||
frame,
|
||||
|
||||
@@ -67,8 +67,10 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
HealthPanelsHolder healthPanelsHolder,
|
||||
CameraStateMachine cameraStateMachine,
|
||||
IParticleService particleService,
|
||||
BattleModeCursorController cursorController)
|
||||
BattleModeCursorController cursorController,
|
||||
IBattleAiResolver aiResolver)
|
||||
{
|
||||
_aiResolver = aiResolver;
|
||||
_cursorController = cursorController;
|
||||
_timelinePanel = timelinePanel;
|
||||
_decisionPanel = battleActionDecisionPanel;
|
||||
@@ -80,7 +82,7 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
_battleActionDeciders = battleActionDeciders.ToDictionary(x => x.DeciderType);
|
||||
_enemyDeciders = enemyDeciders.ToDictionary(x => x.EnemyDeciderType);
|
||||
|
||||
_simulator = new BattleSimulator(_battleActions);
|
||||
_simulator = new BattleSimulator(_battleActions, aiResolver);
|
||||
foreach (var action in _battleActions.Values)
|
||||
action.SetSimulationContext(_simulator);
|
||||
}
|
||||
@@ -139,6 +141,7 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
|
||||
private CancellationToken _battleLoopCt;
|
||||
private BattleModeCursorController _cursorController;
|
||||
private IBattleAiResolver _aiResolver;
|
||||
|
||||
public async UniTask RunBattleLoopAsync(List<EntityProperties> entities, CancellationToken ctx)
|
||||
{
|
||||
@@ -182,7 +185,7 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
HideAllPreviewVisuals();
|
||||
RebakeFromCommitted(recordGhosts: false);
|
||||
|
||||
int nextPauseFrame = Track.FindNextPauseFrame(_committedFrame.Value);
|
||||
int nextPauseFrame = Track.FindNextPlayerPauseFrame(_committedFrame.Value, _entities);
|
||||
if (nextPauseFrame <= _committedFrame.Value)
|
||||
{
|
||||
await UniTask.Yield(PlayerLoopTiming.Update, ctx);
|
||||
@@ -259,18 +262,23 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
|
||||
if (entity.TeamData.Team == EntityTeam.ChaoticEvil)
|
||||
{
|
||||
var (enemyRes, enemyData) = _enemyDeciders[entity.TeamData.DeciderType]
|
||||
.DecideEnemy(entity, _battleActions);
|
||||
var lastCompleted = Track.GetFrame(_committedFrame.Value)
|
||||
.Entities[slotIndex].ActionSlot.LastCompletedActionType;
|
||||
|
||||
return new EntityActionSlotSnapshot
|
||||
if (_aiResolver.TryResolveNextAction(entity, _battleActions, out var enemyRes, out var enemyData))
|
||||
{
|
||||
ActionType = enemyRes.ActionType,
|
||||
DecisionResult = enemyRes,
|
||||
ActionData = enemyData,
|
||||
LastCompletedActionType = Track.GetFrame(_committedFrame.Value).Entities[slotIndex].ActionSlot.LastCompletedActionType,
|
||||
ActionStartFrame = _committedFrame.Value,
|
||||
EstimatedEndFrame = _committedFrame.Value + enemyData.TotalFrames
|
||||
};
|
||||
return new EntityActionSlotSnapshot
|
||||
{
|
||||
ActionType = enemyRes.ActionType,
|
||||
DecisionResult = enemyRes,
|
||||
ActionData = enemyData,
|
||||
LastCompletedActionType = lastCompleted,
|
||||
ActionStartFrame = _committedFrame.Value,
|
||||
EstimatedEndFrame = _committedFrame.Value + enemyData.TotalFrames
|
||||
};
|
||||
}
|
||||
|
||||
return EntityActionSlotSnapshot.CreateNone(_committedFrame.Value, lastCompleted);
|
||||
}
|
||||
|
||||
if (entity.TeamData.Team == EntityTeam.Good)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Code.Game.OfficeGame.Entities;
|
||||
using Code.OfficeGame.BattleMode.Actions;
|
||||
|
||||
namespace Code.OfficeGame.BattleMode.Timeline
|
||||
@@ -101,5 +102,27 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Первый кадр после fromFrame, на котором завершил действие хотя бы один игрок (EntityTeam.Good).
|
||||
/// Если игроков в маске нет (например, игрок мёртв), возвращает LastFrame.
|
||||
/// </summary>
|
||||
public int FindNextPlayerPauseFrame(int fromFrame, EntityProperties[] entities)
|
||||
{
|
||||
ulong playerMask = 0UL;
|
||||
for (int i = 0; i < entities.Length; i++)
|
||||
{
|
||||
if (entities[i].TeamData.Team == EntityTeam.Good)
|
||||
playerMask |= 1UL << i;
|
||||
}
|
||||
|
||||
for (int f = fromFrame + 1; f < _frames.Count; f++)
|
||||
{
|
||||
if ((_frames[f].ReadySlotsMask & playerMask) != 0UL)
|
||||
return f;
|
||||
}
|
||||
|
||||
return LastFrame;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Code.OfficeGame.BattleMode.Actions;
|
||||
|
||||
namespace Code.OfficeGame.BattleMode.Timeline
|
||||
{
|
||||
public interface IBattleAiResolver
|
||||
{
|
||||
bool TryResolveNextAction(
|
||||
EntityProperties entity,
|
||||
IReadOnlyDictionary<BattleActionType, BattleAction> actions,
|
||||
out BattleActionDecisionResult decision,
|
||||
out BattleActionData actionData);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user