示例#1
0
 protected override void OnTick()
 {
     if (m_Cycle != 5)
     {
         //Display warning message
         if (KinCityManager.OnLBChangeWarning != null)
         {
             KinCityManager.OnLBChangeWarning(m_City);
             ++m_Cycle;
             Start();
         }
     }
     else
     {
         //Switch on LB guards
         KinCityData cityData = KinCityManager.GetCityData(m_City);
         if (cityData != null)
         {
             //Don't change the guards if it's somehow now owned by the GCs
             if (cityData.ControlingKin == IOBAlignment.None)
             {
                 return;
             }
             cityData.GuardOption = KinCityData.GuardOptions.LordBritish;
             cityData.ClearAllGuardPosts();
             //Switch on patrol npc guard type
             cityData.SetNPCFlag(KinCityData.NPCFlags.Patrol, true);
             //Raise event for the regions to sort themselves out with the new changes
             if (KinCityManager.OnChangeGuards != null)
             {
                 KinCityManager.OnChangeGuards(m_City, KinCityData.GuardOptions.LordBritish);
             }
         }
     }
 }
示例#2
0
        /// <summary>
        /// Changes the guards.
        /// </summary>
        /// <param name="city">The city.</param>
        /// <param name="guardOption">The guard option.</param>
        public static void ChangeGuards(KinFactionCities city, KinCityData.GuardOptions guardOption, bool overrideTimeout)
        {
            KinCityData cityData = GetCityData(city);

            if (cityData == null)
            {
                return;
            }
            if (cityData.GuardOption == guardOption)
            {
                return;
            }

            if (!overrideTimeout)
            {
                if (DateTime.Now <= cityData.LastGuardChangeTime + TimeSpan.FromHours(KinSystemSettings.GuardChangeTimeHours))
                {
                    return;
                }
            }
            cityData.LastGuardChangeTime = DateTime.Now;

            if (guardOption == KinCityData.GuardOptions.LordBritish)
            {
                LBGuardTimer timer = new LBGuardTimer(city);
                timer.Start();
            }
            else
            {
                cityData.GuardOption = guardOption;
                //Switch off patrol npc guard type
                cityData.SetNPCFlag(KinCityData.NPCFlags.Patrol, false);
                if (guardOption == KinCityData.GuardOptions.None)
                {
                    cityData.ClearAllGuardPosts();
                }

                //Update existing guards with the new rules
                foreach (KinCityData.BeneficiaryData bd in cityData.BeneficiaryDataList)
                {
                    foreach (KinGuardPost kgp in bd.GuardPosts)
                    {
                        if (kgp != null && !kgp.Deleted)
                        {
                            kgp.UpdateExisitngGuards();
                        }
                    }
                }

                //Raise event for the regions to sort themselves out with the new changes
                if (KinCityManager.OnChangeGuards != null)
                {
                    KinCityManager.OnChangeGuards(city, guardOption);
                }
            }
        }