Example #1
0
 public void Close()
 {
     log("", "Close");
     try {
         m_Fleet.remove(m_Class, m_Enforcer);
         StateTracker.getInstance().removeFleetIfEmpty(m_FleetID, m_OwnerType);
     } catch (NullReferenceException e) {
         log("Error: " + e, "Close", Logger.severity.ERROR);
     }
     m_Fleet    = null;
     m_Enforcer = null;
     m_Logger   = null;
 }
        private void timerExpired()
        {
            if (m_Timer == null)
            {
                return;
            }

            log("Dereliction timer has expired", "timerExpired");

            StateTracker.getInstance().removeDerelictTimer(m_TimerInfo.GridID);

            m_Timer.Dispose();
            m_Timer = null;

            CompletedPhase = m_TimerInfo.Phase;
            m_TimerInfo    = null;

            TimerExpired = true;
        }
        /// <summary>
        /// Cancels the dereliction timer
        /// </summary>
        /// <returns>False if there was no timer to cancel</returns>
        public bool cancel()
        {
            if (m_Timer == null)
            {
                return(false);
            }

            StateTracker.getInstance().removeDerelictTimer(m_TimerInfo.GridID);

            m_Timer.Dispose();
            m_Timer = null;

            m_TimerInfo = null;

            TimerExpired = false;

            log("Timer cancelled", "cancel");

            return(true);
        }
        /// <summary>
        /// Starts or resumes the derelict timer
        /// </summary>
        /// <returns>Returns false if dereliction is disabled</returns>
        public bool start()
        {
            int seconds             = ConquestSettings.getInstance().CleanupPeriod;
            int settingsTimerLength = seconds * 1000;

            log("Starting timer with settings start value of " + seconds + " seconds.",
                "start", Logger.severity.TRACE);
            if (seconds < 0)
            {
                log("Dereliction timers disabled.  No timer started.", "start");
                return(false);
            }

            // Check if there is a timer to resume for this entity
            DT_INFO existing = StateTracker.getInstance().findActiveDerelictTimer(m_Grid.EntityId);

            if (existing != null)
            {
                // Resuming an existing timer
                log("Resuming existing timer", "start");

                m_TimerInfo = existing;

                // If the settings Timer Length has changed, update this timer accordingly
                if (m_TimerInfo.TimerLength != settingsTimerLength)
                {
                    log("Timer length has changed from " + m_TimerInfo.TimerLength +
                        "ms to " + settingsTimerLength + "ms", "start");

                    int     savedMillis     = m_TimerInfo.MillisRemaining;
                    decimal lengthRatio     = (decimal)settingsTimerLength / (decimal)m_TimerInfo.TimerLength;
                    int     correctedMillis = (int)(savedMillis * lengthRatio);

                    log("Changing this timer from " + savedMillis + "ms to " + correctedMillis +
                        "ms using ratio " + lengthRatio, "start");

                    m_TimerInfo.MillisRemaining = correctedMillis;
                    m_TimerInfo.TimerLength     = settingsTimerLength;
                }

                m_Timer = new MyTimer(m_TimerInfo.MillisRemaining, timerExpired);
                m_Timer.Start();
                log("Timer resumed with " + m_TimerInfo.MillisRemaining + "ms", "start");
            }
            else
            {
                // Starting a new timer
                log("Starting new timer", "start");

                m_TimerInfo                 = new DT_INFO();
                m_TimerInfo.GridID          = m_Grid.EntityId;
                m_TimerInfo.Phase           = DT_INFO.PHASE.INITIAL;
                m_TimerInfo.TimerLength     = seconds * 1000;
                m_TimerInfo.MillisRemaining = m_TimerInfo.TimerLength;
                m_TimerInfo.LastUpdated     = DateTime.UtcNow;

                m_Timer = new MyTimer(m_TimerInfo.MillisRemaining, timerExpired);
                m_Timer.Start();
                log("Timer started with " + m_TimerInfo.MillisRemaining + "ms", "start");

                StateTracker.getInstance().addNewDerelictTimer(m_TimerInfo);
            }

            return(true);
        }