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; }); }
public Timer(string n, int t, Action onF) { this.name = n; this.finalTick = t; this.onFinish += onF; TimersContainer.Add(this); }
private static void OnRootConsoleUpdate(object sender, UpdateEventArgs e) { TimersContainer.Logic(); if (currentState != null) { currentState.Logic(); } }
public void Logic() { this.ticks++; if (this.ticks >= finalTick) { if (onFinish != null) { onFinish(); onFinish = null; } TimersContainer.Remove(this); } }