Health System
This commit is contained in:
1 parent
329cc98ade
commit
cb05da5e89
87 files changed
+568550
-155362
No files matched your search
@@ -7,6 +7,7 @@ using Code.Game.OfficeGame.BattleMode;
|
||||
using Code.Infrastructure.Camera;
|
||||
using Code.OfficeGame.BattleMode.Actions;
|
||||
using Code.OfficeGame.BattleMode.Actions.Deciders;
|
||||
using Code.OfficeGame.BattleMode.Effects;
|
||||
using Code.OfficeGame.BattleMode.Snapshots;
|
||||
using Code.OfficeGame.BattleMode.UI;
|
||||
using Cysharp.Threading.Tasks;
|
||||
@@ -40,6 +41,9 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
|
||||
private SemaphoreSlim _preview = new(1,1);
|
||||
|
||||
// Entity, damage
|
||||
private List<EntityAttackedData> _attackRequests = new();
|
||||
|
||||
public BattleTimeline(
|
||||
BattleTimelinePanel timelinePanel,
|
||||
IEnumerable<BattleAction> battleActions,
|
||||
@@ -318,8 +322,11 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
Physics.Simulate(TickDelta);
|
||||
Physics.SyncTransforms();
|
||||
|
||||
ProcessAttackRequests();
|
||||
|
||||
var readyEntities = _battleActionDatas
|
||||
.Where(x => x.Value.Finished)
|
||||
.Where(x=> !inEntities[x.Key].EntityHealth.IsDead)
|
||||
.Select(x => x.Key)
|
||||
.ToArray();
|
||||
|
||||
@@ -433,23 +440,98 @@ namespace Code.OfficeGame.BattleMode.Timeline
|
||||
return (decisionResult, actionData);
|
||||
}
|
||||
|
||||
public void ForceDecideAction(
|
||||
EntityId entityId,
|
||||
BattleActionData forcedBattleActionData,
|
||||
BattleActionDecisionResult forcedBattleActionDataResult)
|
||||
{
|
||||
if(_battleActionDatas.TryGetValue(entityId, out var battleActionData)
|
||||
&& _actionDecisionResults.TryGetValue(entityId, out var actionDecisionResult))
|
||||
_battleActions[_actionDecisionResults[entityId].ActionType]
|
||||
.Finish(
|
||||
_entities[entityId],
|
||||
battleActionData,
|
||||
actionDecisionResult);
|
||||
|
||||
_battleActionDatas[entityId] = forcedBattleActionData;
|
||||
_actionDecisionResults[entityId] = forcedBattleActionDataResult;
|
||||
// public void ForceDecideAction(
|
||||
// EntityId entityId,
|
||||
// BattleActionData forcedBattleActionData,
|
||||
// BattleActionDecisionResult forcedBattleActionDataResult)
|
||||
// {
|
||||
// if(_battleActionDatas.TryGetValue(entityId, out var battleActionData)
|
||||
// && _actionDecisionResults.TryGetValue(entityId, out var actionDecisionResult))
|
||||
// _battleActions[_actionDecisionResults[entityId].ActionType]
|
||||
// .Finish(
|
||||
// _entities[entityId],
|
||||
// battleActionData,
|
||||
// actionDecisionResult);
|
||||
//
|
||||
// _battleActionDatas[entityId] = forcedBattleActionData;
|
||||
// _actionDecisionResults[entityId] = forcedBattleActionDataResult;
|
||||
//
|
||||
// Debug.Log($"Задано действие {forcedBattleActionDataResult.ActionType} для {entityId} with {forcedBattleActionData.GetType()}");
|
||||
// }
|
||||
|
||||
Debug.Log($"Задано действие {forcedBattleActionDataResult.ActionType} для {entityId} with {forcedBattleActionData.GetType()}");
|
||||
private void ProcessAttackRequests()
|
||||
{
|
||||
foreach (var request in _attackRequests)
|
||||
{
|
||||
var attacker = request.Attacker;
|
||||
var defender = request.Defender;
|
||||
|
||||
var attackEffects = attacker.Effects.Where(x => x.Type == EffectType.Attack)
|
||||
.Select(x => (AttackEffect)x);
|
||||
|
||||
var damage = request.Damage;
|
||||
|
||||
foreach (var effect in attackEffects)
|
||||
{
|
||||
effect.Apply(damage);
|
||||
}
|
||||
|
||||
var defendEffects = defender.Effects.Where(x => x.Type == EffectType.Defense)
|
||||
.Select(x => (DefenseEffect)x);
|
||||
|
||||
foreach (var effect in defendEffects)
|
||||
{
|
||||
effect.Apply(damage);
|
||||
}
|
||||
|
||||
defender.EntityHealth.GetDamage(damage, request.HitBoxPartType);
|
||||
|
||||
var defenderId = request.DefenderId;
|
||||
|
||||
if (_battleActionDatas.TryGetValue(defenderId, out var battleActionData)
|
||||
&& _actionDecisionResults.TryGetValue(defenderId, out var actionDecisionResult))
|
||||
_battleActions[_actionDecisionResults[defenderId].ActionType]
|
||||
.Finish(
|
||||
_entities[defenderId],
|
||||
battleActionData,
|
||||
actionDecisionResult);
|
||||
|
||||
Debug.Log($"{defender} got {damage} and {defender.EntityHealth.IsDead}");
|
||||
|
||||
if (defender.EntityHealth.IsDead)
|
||||
{
|
||||
var forcedDeathData = new NoneBattleActionData();
|
||||
var forcedDeathDecision = new AsIsBattleActionDeciderResult();
|
||||
|
||||
_battleActionDatas[defenderId] = forcedDeathData;
|
||||
_actionDecisionResults[defenderId] = forcedDeathDecision;
|
||||
}
|
||||
else
|
||||
{
|
||||
_battleActionDatas[defenderId] = request.ForcedActionData;
|
||||
_actionDecisionResults[defenderId] = request.ForcedDecisionResult;
|
||||
}
|
||||
}
|
||||
|
||||
_attackRequests.Clear();
|
||||
}
|
||||
|
||||
public void AttackRequest(EntityId attacker, EntityId defender, EntityAttackedData attackedData)
|
||||
{
|
||||
if (_attackRequests.Contains(attackedData)) return;
|
||||
|
||||
attackedData.AttackerId = attacker;
|
||||
attackedData.DefenderId = defender;
|
||||
|
||||
attackedData.Attacker = _entities[attacker];
|
||||
attackedData.Defender = _entities[defender];
|
||||
|
||||
_attackRequests.Add(attackedData);
|
||||
}
|
||||
|
||||
public void KillEntity(EntityId entityId)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user