Esempio n. 1
0
        public IEnumerable <Act.Status> HitAndWait(bool loadBar, Func <float> maxProgress,
                                                   Func <float> progress, Action incrementProgress,
                                                   Func <Vector3> pos, string playSound = "", Func <bool> continueHitting = null, bool maintainPos = true)
        {
            Vector3 currentPos = Physics.LocalTransform.Translation;

            CurrentCharacterMode = Stats.CurrentClass.AttackMode;
            Sprite.ResetAnimations(CurrentCharacterMode);
            Sprite.PlayAnimations(CurrentCharacterMode);
            var   p_current      = pos();
            Timer incrementTimer = new Timer(1.0f, false);

            while (progress() < maxProgress())
            {
                if (continueHitting != null && !continueHitting())
                {
                    yield break;
                }

                if (loadBar)
                {
                    Drawer2D.DrawLoadBar(Manager.World.Renderer.Camera, AI.Position + Vector3.Up, Color.LightGreen, Color.Black, 64, 4,
                                         progress() / maxProgress());
                }
                Physics.Active = false;
                Physics.Face(p_current);
                if (Attacks[0].PerformNoDamage(this, DwarfTime.LastTime, p_current))
                {
                    p_current = pos();
                }
                Physics.Velocity = Vector3.Zero;

                if (!String.IsNullOrEmpty(playSound))
                {
                    NoiseMaker.MakeNoise(playSound, AI.Position, true);
                }

                incrementTimer.Update(DwarfTime.LastTime);
                if (incrementTimer.HasTriggered)
                {
                    Sprite.ReloopAnimations(Stats.CurrentClass.AttackMode);
                    incrementProgress();
                }

                if (maintainPos)
                {
                    var matrix = Physics.LocalTransform;
                    matrix.Translation     = currentPos;
                    Physics.LocalTransform = matrix;
                }

                yield return(Act.Status.Running);
            }
            Sprite.PauseAnimations(Stats.CurrentClass.AttackMode);
            CurrentCharacterMode = CharacterMode.Idle;
            Physics.Active       = true;
            yield return(Act.Status.Success);

            yield break;
        }