Great timeline system (Age of AI WON)
This commit is contained in:
1 parent
2ce0391c16
commit
e312131725
182 files changed
+380070
-470221
No files matched your search
@@ -1,6 +1,5 @@
|
||||
using System.Linq;
|
||||
using Code.Game.Entities;
|
||||
using Code.Infrastructure.Particles;
|
||||
using Code.Infrastructure.Utils;
|
||||
using Code.OfficeGame.BattleMode.Actions.Deciders;
|
||||
using Code.OfficeGame.BattleMode.HitBoxes;
|
||||
@@ -11,21 +10,29 @@ namespace Code.OfficeGame.BattleMode.Actions.Attacks
|
||||
{
|
||||
public class BattleActionPlayerAttackMMA : BattleAction
|
||||
{
|
||||
private AttackActionConfig _attackData;
|
||||
private IParticleService _particleService;
|
||||
public int EntryStateHash => Animator.StringToHash("WalkBlend");
|
||||
private readonly AttackActionConfig _attackData;
|
||||
private static readonly int EntryStateHash = Animator.StringToHash("WalkBlend");
|
||||
|
||||
public BattleActionPlayerAttackMMA(MultipleConfig<BattleActionParameters> attackData,
|
||||
IParticleService particleService)
|
||||
public BattleActionPlayerAttackMMA(MultipleConfig<BattleActionParameters> attackData)
|
||||
{
|
||||
_particleService = particleService;
|
||||
_attackData = (AttackActionConfig)
|
||||
attackData.Configs.SingleOrDefault(x => x.ActionType == ActionType);
|
||||
_attackData = (AttackActionConfig)attackData.Configs.SingleOrDefault(x => x.ActionType == ActionType);
|
||||
}
|
||||
|
||||
public override BattleActionType ActionType => BattleActionType.PlayerAttackMMA;
|
||||
public override DeciderType DeciderType => DeciderType.Rotation;
|
||||
|
||||
public override void Tick(float tickDelta,
|
||||
public override BattleActionData MountAndGetFrames(EntityProperties entity, BattleActionDecisionResult result)
|
||||
{
|
||||
return new AttackBattleActionData
|
||||
{
|
||||
TotalFrames = _attackData.TotalFrames,
|
||||
TransitionFrames = _attackData.TransitionFrames,
|
||||
StartRotation = entity.KinematicCharacterMotor.TransientRotation
|
||||
};
|
||||
}
|
||||
|
||||
public override void Tick(
|
||||
float tickDelta,
|
||||
EntityProperties entity,
|
||||
BattleActionDecisionResult battleActionDecisionResult,
|
||||
BattleActionData battleActionData)
|
||||
@@ -41,42 +48,50 @@ namespace Code.OfficeGame.BattleMode.Actions.Attacks
|
||||
{
|
||||
actionData.TransitionFrames = _attackData.TransitionFrames;
|
||||
actionData.TotalFrames = _attackData.TotalFrames;
|
||||
|
||||
actionData.StartRotation = entity.KinematicCharacterMotor.TransientRotation;
|
||||
actionData.HitEntities.Clear();
|
||||
|
||||
entity.SyncRootMotionToMotor();
|
||||
|
||||
var entityAnimator = entity.animator;
|
||||
entityAnimator.applyRootMotion = true;
|
||||
|
||||
var transitionTime = actionData.TransitionFrames * BattleTimeline.TickDelta;
|
||||
entityAnimator.CrossFadeInFixedTime(_attackData.StateHash, transitionTime);
|
||||
entityAnimator.CrossFadeInFixedTime(_attackData.StateHash, actionData.TransitionFrames * BattleTimeline.TickDelta);
|
||||
}
|
||||
else if (actionData.CurrentFrame <= actionData.TransitionFrames
|
||||
&& actionData.TransitionFrames > 0)
|
||||
else if (actionData.CurrentFrame <= actionData.TransitionFrames && actionData.TransitionFrames > 0)
|
||||
{
|
||||
float t = (float)actionData.CurrentFrame / actionData.TransitionFrames;
|
||||
Quaternion transientRotation = Quaternion.Lerp(
|
||||
entity.KinematicCharacterMotor.TransientRotation,
|
||||
deciderResult.Rotation,
|
||||
t);
|
||||
|
||||
entity.KinematicCharacterMotor.SetRotation(transientRotation);
|
||||
Quaternion rot = Quaternion.Slerp(actionData.StartRotation, deciderResult.Rotation, t);
|
||||
entity.KinematicCharacterMotor.SetRotation(rot);
|
||||
}
|
||||
|
||||
actionData.CurrentFrame++;
|
||||
}
|
||||
|
||||
public override void PostPhysicsTick(
|
||||
EntityProperties entity,
|
||||
BattleActionDecisionResult battleActionDecisionResult,
|
||||
BattleActionData battleActionData)
|
||||
{
|
||||
if (battleActionData is not AttackBattleActionData actionData) return;
|
||||
|
||||
if (actionData.CurrentFrame >= _attackData.HitboxStartFrame
|
||||
&& actionData.CurrentFrame <= _attackData.HitboxEndFrame)
|
||||
{
|
||||
entity.EntityHitBoxes.CheckHitsForCurrentFrame(OnEnemyHit, _attackData.AttackingBodyPart);
|
||||
entity.EntityHitBoxes.CheckHitsForCurrentFrame(OnEnemyHit, HitBoxPartType.RAnkle);
|
||||
entity.EntityHitBoxes.CheckHitsForCurrentFrame(
|
||||
SimContext,
|
||||
(attackerCol, enemyCol, hitPart) => OnEnemyHit(actionData, attackerCol, enemyCol, hitPart),
|
||||
_attackData.AttackingBodyPart);
|
||||
|
||||
entity.EntityHitBoxes.CheckHitsForCurrentFrame(
|
||||
SimContext,
|
||||
(attackerCol, enemyCol, hitPart) => OnEnemyHit(actionData, attackerCol, enemyCol, hitPart),
|
||||
HitBoxPartType.RAnkle);
|
||||
}
|
||||
|
||||
if (actionData.CurrentFrame >= actionData.TotalFrames)
|
||||
{
|
||||
var entityAnimator = entity.animator;
|
||||
|
||||
entity.SyncRootMotionToMotor();
|
||||
|
||||
entityAnimator.applyRootMotion = false;
|
||||
entityAnimator.Play(EntryStateHash, 0, 0f);
|
||||
entityAnimator.Update(0f);
|
||||
|
||||
@@ -84,59 +99,55 @@ namespace Code.OfficeGame.BattleMode.Actions.Attacks
|
||||
}
|
||||
}
|
||||
|
||||
public override DeciderType DeciderType => DeciderType.Rotation;
|
||||
|
||||
public override BattleActionData MountAndGetFrames(EntityProperties entity, BattleActionDecisionResult result)
|
||||
{
|
||||
return new AttackBattleActionData() { TotalFrames = _attackData.TotalFrames };
|
||||
}
|
||||
|
||||
public override void Finish(EntityProperties entity, BattleActionData actionData, BattleActionDecisionResult result)
|
||||
{
|
||||
// var entityAnimator = entity.animator;
|
||||
//
|
||||
// entity.SyncRootMotionToMotor();
|
||||
//
|
||||
// entityAnimator.Play(EntryStateHash, 0, 0f);
|
||||
// entityAnimator.Update(0f);
|
||||
entity.animator.applyRootMotion = false;
|
||||
}
|
||||
|
||||
private void OnEnemyHit(Collider attacker, Collider enemyCollider)
|
||||
{
|
||||
var defenderId = enemyCollider.GetComponentInParent<EntityProperties>().GetEntityId();
|
||||
var attackerId = attacker.GetComponentInParent<EntityProperties>().GetEntityId();
|
||||
|
||||
Vector3 attackerDirection = attacker.transform.TransformDirection(_attackData.LocalKnockbackDirection);
|
||||
attackerDirection.y = 0f;
|
||||
attackerDirection.Normalize();
|
||||
|
||||
var actionData = new StuggerActionData
|
||||
private void OnEnemyHit(
|
||||
AttackBattleActionData attackData,
|
||||
Collider attacker,
|
||||
Collider enemyCollider,
|
||||
HitBoxPartType hitPart)
|
||||
{
|
||||
var defenderProps = enemyCollider.GetComponentInParent<EntityProperties>();
|
||||
var attackerProps = attacker.GetComponentInParent<EntityProperties>();
|
||||
if (defenderProps == null || attackerProps == null) return;
|
||||
|
||||
var defenderId = defenderProps.GetEntityId();
|
||||
var attackerId = attackerProps.GetEntityId();
|
||||
|
||||
// Защита от многокадрового урона по одной цели за один удар
|
||||
if (!attackData.HitEntities.Add(defenderId)) return;
|
||||
|
||||
Vector3 knockbackDir = attackerProps.KinematicCharacterMotor.Transform
|
||||
.TransformDirection(_attackData.LocalKnockbackDirection);
|
||||
knockbackDir.y = 0f;
|
||||
if (knockbackDir.sqrMagnitude > 0.0001f) knockbackDir.Normalize();
|
||||
|
||||
var forcedActionData = new StuggerActionData
|
||||
{
|
||||
TotalFrames = _attackData.StuggerFrames,
|
||||
CurrentFrame = 0,
|
||||
KnockbackDirection = attackerDirection,
|
||||
KnockbackDirection = knockbackDir,
|
||||
KnockbackSpeed = _attackData.KnockbackSpeed,
|
||||
KnockbackDistance = _attackData.KnockbackDistance
|
||||
};
|
||||
var decisionResult = new AsIsBattleActionDeciderResult { ActionType = BattleActionType.Stugger };
|
||||
|
||||
EntityAttackedData attackedData = new()
|
||||
var forcedDecision = new AsIsBattleActionDeciderResult
|
||||
{
|
||||
ForcedActionData = actionData,
|
||||
ForcedDecisionResult = decisionResult,
|
||||
ActionType = BattleActionType.Stugger,
|
||||
ResultCode = BattleActionDecisionResultCode.Decided
|
||||
};
|
||||
|
||||
var attackedData = new EntityAttackedData
|
||||
{
|
||||
ForcedActionData = forcedActionData,
|
||||
ForcedDecisionResult = forcedDecision,
|
||||
Damage = _attackData.Damage
|
||||
};
|
||||
|
||||
battleTimeline.AttackRequest(attackerId, defenderId, attackedData);
|
||||
|
||||
//battleTimeline.ForceDecideAction(originEntityId, actionData, decisionResult);
|
||||
|
||||
if(!BattleTimeline.IsSilentSimulation)
|
||||
_particleService.EmitOneShot(
|
||||
new ParticlePartitionIDPair(ParticlePartition.HitParticles, 0),
|
||||
15,
|
||||
enemyCollider.transform.position,
|
||||
Quaternion.identity);
|
||||
SimContext.SubmitAttack(attackerId, defenderId, hitPart, enemyCollider.transform.position, attackedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user