예제 #1
0
        private void ProcessLocomotionStack <T>(Stack <LocomotionManager <T> > locomotions) where T : PawnModelComponent
        {
            if (_soloAnimations.Any())
            {
                var animation = _soloAnimations.Peek();
                animation.UpdateAnimation();
                if (!animation.WeAreDuringAnimation())
                {
                    _soloAnimations.Pop();
                    if (_soloAnimations.Any())
                    {
                        _soloAnimations.Peek().StartAnimation();
                    }
                }
                return;
            }

            if (_magicUsage != null)
            {
                if (_magicUsage.MagicUsageEnded)
                {
                    _magicUsage = null;
                }
                else
                {
                    _magicUsage.Update();
                    return;
                }
            }
            ;

            if (locomotions.Any())
            {
                var currentLocomotion = locomotions.Peek();
                if (currentLocomotion.LocomotionFinished)
                {
                    locomotions.Pop();
                }
                else
                {
                    if (currentLocomotion.DuringAnimation)
                    {
                        currentLocomotion.UpdateAnimation();
                        return;
                    }
                    else
                    {
                        var steps            = currentLocomotion.AdvanceJourney(_courseModel);
                        var previousStep     = steps.PreviousStep;
                        var locomotionTarget = currentLocomotion.LocomotionTarget;
                        if (previousStep != null)
                        {
                            if (previousStep.ShouldRemoveUnitAfterStep(_courseModel))
                            {
                                locomotionTarget.PawnModel.SetUnitKilled();
                                locomotions.Pop();
                                return;
                            }
                        }

                        if (steps.NextStep != null)
                        {
                            var battleResults = steps.NextStep.ApplyStepToModel(_courseModel, locomotionTarget);
                            _unitLocomotions = new Stack <LocomotionManager <UnitModelComponent> >(_unitLocomotions
                                                                                                   .Where(c => !battleResults.UnitWasStruck(c.LocomotionTarget.Model)).Reverse());

                            foreach (var engagement in battleResults.Engagements)
                            {
                                var engagementResult = engagement.EngagementResult;

                                var innerAnimations = engagement.EngagementElements.Select(element =>
                                {
                                    var active  = GetPawnModelComponent(element.ActivePawn);
                                    var passive = GetPawnModelComponent(element.PassivePawn);
                                    return(element.EngagementVisibleConsequence.EngagementAnimation(_courseModel, MasterSound, active, passive));
                                }).ToList();
                                innerAnimations.AddRange(engagementResult.StruckUnits.Select(c => new UnitStruckAnimation(_unitModelToGameObjectMap[c])));

                                var anim = new CompositeAnimation(innerAnimations);

                                _soloAnimations.Push(anim);
                                if (_soloAnimations.Count >= 1)
                                {
                                    _soloAnimations.Peek().StartAnimation();
                                }


                                engagementResult.StruckUnits.ForEach(c =>
                                {
                                    _unitLocomotions.Push(LocomotionUtils.CreateDeathJourney(_unitModelToGameObjectMap[c]));
                                });

                                engagementResult.Displacements.ForEach(c =>
                                {
                                    _unitLocomotions.Push(LocomotionUtils.CreatePushJourney(_courseModel, _unitModelToGameObjectMap[c.Unit], c.DisplacementEnd));
                                });

                                engagementResult.Projectiles.ForEach(c =>
                                {
                                    var projectile = AddProjectile(c);
                                    _projectileLocomotions.Push(LocomotionUtils.CreateProjectileJourney(projectile, c.EndPosition, c.Type));
                                });
                            }
                        }
                    }
                }
            }
        }