Example #1
0
        public virtual void TryToAttack(Vector dir)
        {
            this.facing = dir;

            if (!this.canAttack || this.Stamina.GetCurrent() < 30)
            {
                return;
            }

            this.canAttack          = false;
            this.isRestoringStamina = false;

            this.currentAnimation = new Animation(new List <char>()
            {
                '!'
            }, 10, this, () =>
            {
                var attack    = new Attack(AttackType.Melee, this.position, this.facing, 25, this, Attack.LW_ATTACK);
                this.Stamina -= 30;
                if (this.staminaTimer != null)
                {
                    TimersContainer.Remove(this.staminaTimer);
                    this.staminaTimer = null;
                }
                this.staminaTimer = new Timer("restStam", attack.ticks + 15,
                                              () => { this.isRestoringStamina = true; });
                new Timer("restCanAttack", attack.ticks - 3,
                          () => { this.canAttack = true; });
                this.currentAnimation = null;
            });
        }
Example #2
0
        public Timer(string n, int t, Action onF)
        {
            this.name      = n;
            this.finalTick = t;
            this.onFinish += onF;

            TimersContainer.Add(this);
        }
Example #3
0
        private static void OnRootConsoleUpdate(object sender, UpdateEventArgs e)
        {
            TimersContainer.Logic();

            if (currentState != null)
            {
                currentState.Logic();
            }
        }
Example #4
0
 public void Logic()
 {
     this.ticks++;
     if (this.ticks >= finalTick)
     {
         if (onFinish != null)
         {
             onFinish();
             onFinish = null;
         }
         TimersContainer.Remove(this);
     }
 }