Пример #1
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);
                }
            }
        }
Пример #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);
				}
			}
		}