Ejemplo n.º 1
0
 public void ContinueTimer(TimerBase timer)
 {
     if (!this.IsTimerRunning(timer))
     {
         this.RunningTimers.Add(timer);
     }
 }
Ejemplo n.º 2
0
        public void HandleGameUpdate()
        {
            if (this.frameCounter >= TimerManager.FrameUpdateFreq)
            {
                this.frameCounter = 0;

                for (int i = 0; i < this.RunningTimers.Count; i++)
                {
                    TimerBase abstractTimer = this.RunningTimers[i];
                    abstractTimer.Update(TimerManager.FrameUpdateFreq);

                    if (abstractTimer.IsExpired())
                    {
                        if (this.InvokeTimerCallback(abstractTimer))
                        {
                            abstractTimer.Reset();
                        }
                        else
                        {
                            this.RunningTimers.RemoveAt(i--);
                        }
                    }
                }
            }

            this.frameCounter++;
        }
Ejemplo n.º 3
0
 public void StartTimer(TimerBase timer)
 {
     if (!this.IsTimerRunning(timer))
     {
         this.RunningTimers.Add(timer);
         timer.Reset();
     }
 }
Ejemplo n.º 4
0
 private bool InvokeTimerCallback(TimerBase timer)
 {
     try {
         return(timer.Callback(timer));
     } catch (Exception ex) {
         this.PluginTrace.WriteLineError("A Timer's callback has thrown an exception. Excpetion details: " + ex);
         return(false);
     }
 }
Ejemplo n.º 5
0
        private void AddTimer(TimerBase timer)
        {
            lock (this.alterTimersLock) {
                List <TimerBase> newTimers = new List <TimerBase>(this.runningTimers.Count);
                newTimers.AddRange(this.runningTimers);

                newTimers.Add(timer);
                Interlocked.Exchange(ref this.runningTimers, newTimers);
            }
        }
Ejemplo n.º 6
0
 public void RemoveTimer(TimerBase timer, bool andInvokeCallback = false)
 {
     try {
         if (andInvokeCallback)
         {
             this.InvokeTimerCallback(timer);
         }
     } finally {
         this.RunningTimers.Remove(timer);
     }
 }
Ejemplo n.º 7
0
 public void StartOrResetTimer(TimerBase timer)
 {
     if (this.IsTimerRunning(timer))
     {
         timer.Reset();
     }
     else
     {
         this.AddTimer(timer);
     }
 }
Ejemplo n.º 8
0
        public void RemoveTimer(TimerBase timer, bool andInvokeCallback = false)
        {
            lock (this.alterTimersLock) {
                List <TimerBase> newTimers = new List <TimerBase>(this.runningTimers.Count);
                newTimers.AddRange(this.runningTimers);

                newTimers.Remove(timer);
                Interlocked.Exchange(ref this.runningTimers, newTimers);
            }

            if (andInvokeCallback)
            {
                this.InvokeTimerCallback(timer);
            }
        }
Ejemplo n.º 9
0
        private bool RefillChestTimer_Callback(TimerBase timer)
        {
            RefillChestMetadata refillChest = (RefillChestMetadata)timer.Data;
              lock (this.WorldMetadata.Protections) {
            ProtectionEntry protection = this.WorldMetadata.Protections.Values.SingleOrDefault(p => p.RefillChestData == refillChest);
            if (protection == null)
              return false;

            DPoint chestLocation = protection.TileLocation;
            this.TryRefillChest(chestLocation, refillChest);

            // Returning true would mean the Timer would repeat.
            return false;
              }
        }
Ejemplo n.º 10
0
 public bool IsTimerRunning(TimerBase timer)
 {
     return(this.RunningTimers.Contains(timer));
 }
Ejemplo n.º 11
0
        private bool RefillChestTimer_Callback(TimerBase timer)
        {
            RefillChestMetadata refillChest = (RefillChestMetadata)timer.Data;
              lock (this.WorldMetadata.Protections) {
            ProtectionEntry protection = this.WorldMetadata.Protections.Values.SingleOrDefault(p => p.RefillChestData == refillChest);
            if (protection == null)
              return false;

            DPoint chestLocation = protection.TileLocation;
            try {
              this.TryRefillChest(chestLocation, refillChest);
            } catch (InvalidOperationException) {
              this.PluginTrace.WriteLineWarning($"Chest at position {chestLocation} doesn't seem to exist anymore. Can't refill it.");
              return false;
            }

            // Returning true would mean the Timer would repeat.
            return false;
              }
        }