/// <summary> /// Spawns a new power vortex at the _vortexSpawnLocation /// Starts the vortex expire timer. /// </summary> public void SpawnVortex() { //switch off scheduled mode.. m_ScheduledMode = false; //clear points from last time just in case m_DefensePoints.Clear(); m_Vortex = new PowerVortex(this); m_Vortex.MoveToWorld(m_VortexSpawnLocation, this.Map); //Start vortex expire timer m_Timer = new VortexExpireTimer(TimeSpan.FromMinutes(KinSystemSettings.VortexExpireMinutes), this); m_Timer.Start(); //Set the time variable to the end time so we can preserve on server restart m_Time = DateTime.Now + TimeSpan.FromMinutes(KinSystemSettings.VortexExpireMinutes); //Announce! KinSystem.SendKinMessage(string.Format("A power vortex targeting the City of {0} has appeared!", m_City.ToString())); }
/// <summary> /// Deserializes the specified reader. /// </summary> /// <param name="reader">The reader.</param> public override void Deserialize(GenericReader reader) { TimeSpan ts = TimeSpan.Zero; bool timerActive = false; base.Deserialize(reader); int version = reader.ReadInt(); switch (version) { case 1: { m_ScheduledMode = reader.ReadBool(); goto case 0; } case 0: { m_City = (KinFactionCities)reader.ReadInt(); m_Vortex = (PowerVortex)reader.ReadMobile(); ts = reader.ReadDeltaTime() - DateTime.Now; m_VortexSpawnLocation = reader.ReadPoint3D(); m_Active = reader.ReadBool(); timerActive = reader.ReadBool(); break; } } if (timerActive) { //Sort out the timer state: //Whilst in capture phase, _time will represent the expire time of the current vortex, so start timer with new delay if (InCapturePhase()) { if (ts == TimeSpan.Zero) { //something weird happened, start expire timer afresh from kinsettings m_Time = DateTime.Now + TimeSpan.FromHours(KinSystemSettings.VortexExpireMinutes); } else { m_Time = DateTime.Now + ts; } if (m_Time < DateTime.Now) { //Vortex should have expired already, set it for 1 minute ts = TimeSpan.FromMinutes(1); } m_Timer = new VortexExpireTimer(ts, this); } else //if there's no vortex then the time represents the next spawn time { //Apply the delta and create a timer m_Time = DateTime.Now + ts; m_Timer = new VortexSpawnTimer(this); } //Only start the timer if Active if (m_Active) { m_Timer.Start(); } } else { m_Time = DateTime.Now + ts; } }