Example #1
0
        /// <summary>
        /// Deserializes the specified reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            TimeSpan ts = TimeSpan.Zero;

            int version = reader.ReadInt();

            switch (version)
            {
            case 1:
            {
                m_Reset            = reader.ReadBool();
                ts                 = reader.ReadDeltaTime() - DateTime.Now;
                m_NextMaintTime    = DateTime.Now + ts;
                ts                 = reader.ReadDeltaTime() - DateTime.Now;
                m_NextSpawnTime    = DateTime.Now + ts;
                m_SpawnTimeMinutes = reader.ReadInt();
                m_GuardType        = (KinFactionGuardTypes)reader.ReadInt();
                goto case 0;
            }

            case 0:
            {
                m_City   = (KinFactionCities)reader.ReadInt();
                m_Owner  = (PlayerMobile)reader.ReadMobile();
                m_Silver = reader.ReadInt();
                break;
            }
            }
        }
Example #2
0
        /// <summary>
        /// Returns cost type of the guard using reflection, or defaults to Medium. This is the amount of slots required for the guard.
        /// </summary>
        /// <returns></returns>
        public static int GetGuardCostType(KinFactionGuardTypes guardType)
        {
            //Default to medium cost
            int  cost = (int)KinFactionGuardCostTypes.MediumCost;
            Type t    = SpawnerType.GetType(guardType.ToString());

            if (t == null)
            {
                return(cost);
            }
            //Although foreach is used here, there will only be one of these attributes.
            foreach (KinFactionGuardTypeAttribute att in t.GetCustomAttributes(typeof(KinFactionGuardTypeAttribute), true))
            {
                //Use the custom value if it was provided
                if (att.CustomSlotCost > 0)
                {
                    cost = att.CustomSlotCost;
                }
                else
                {
                    cost = (int)att.GuardCostType;
                }
            }
            return(cost);
        }
Example #3
0
        /// <summary>
        /// Returns silver guard hire cost based on guard type using reflection
        /// </summary>
        /// <returns></returns>
        public static int GetGuardHireCost(KinFactionGuardTypes guardType)
        {
            //Default to medium cost
            int  cost = KinSystemSettings.GuardTypeMediumSilverCost;
            Type t    = SpawnerType.GetType(guardType.ToString());

            if (t == null)
            {
                return(cost);
            }
            foreach (KinFactionGuardTypeAttribute att in t.GetCustomAttributes(typeof(KinFactionGuardTypeAttribute), true))
            {                    //Although foreach is used here, there will only be one of these attributes.
                //Use the custom value if it was provided
                if (att.CustomHireCost > 0)
                {
                    cost = att.CustomHireCost;
                }
                else
                {
                    switch (att.GuardCostType)
                    {
                    case KinFactionGuardCostTypes.LowCost: cost = KinSystemSettings.GuardTypeLowSilverCost; break;

                    case KinFactionGuardCostTypes.MediumCost: cost = KinSystemSettings.GuardTypeMediumSilverCost; break;

                    case KinFactionGuardCostTypes.HighCost: cost = KinSystemSettings.GuardTypeHighSilverCost; break;
                    }
                }
            }
            return(cost);
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="KinGuardPost"/> class.
        /// </summary>
        /// <param name="itemID">The item ID.</param>
        /// <param name="owner">The owner.</param>
        /// <param name="guardType">Type of the guard.</param>
        /// <param name="city">The city.</param>
        public KinGuardPost(int itemID, PlayerMobile owner, KinFactionGuardTypes guardType, KinFactionCities city)
        {
            this.ItemID = itemID;
            Movable     = false;
            Visible     = true;
            m_City      = city;
            m_Owner     = owner;
            m_GuardType = guardType;
            ArrayList creaturesName = new ArrayList();             //bah *! $ arraylists

            creaturesName.Add(guardType.ToString());

            InitSpawn(1, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1), 0, 4, creaturesName);
        }
Example #5
0
            /// <summary>
            /// Sets the type of the guard.
            /// </summary>
            /// <param name="type">The type.</param>
            private void SetGuardType(KinFactionGuardTypes type)
            {
                //Check if the new type is the same cost as the old type
                KinFactionGuardTypes currentType = (KinFactionGuardTypes)m_State.GetValue <KinFactionGuardTypes>("Type");
                int cost        = KinSystem.GetGuardCostType(type);
                int currentCost = KinSystem.GetGuardCostType(currentType);

                if (!cost.Equals(currentCost))
                {
                    //Modify the slots accordingly
                    int slots = (int)m_State.GetValue <int>("Slots");
                    slots += (currentCost - cost);
                    if (slots < 0)
                    {
                        return;
                    }
                    m_State.SetValue("Slots", slots);
                }
                m_State.SetValue("Type", type);
            }
Example #6
0
            /// <summary>
            /// Gets the guard text colour.
            /// </summary>
            /// <param name="guardType">Type of the guard.</param>
            /// <returns></returns>
            private int GetGuardTextColour(KinFactionGuardTypes guardType)
            {
                //less than five maint costs is low health
                int cost = KinSystem.GetGuardCostType(guardType);

                if (cost == (int)KinFactionGuardCostTypes.HighCost)
                {
                    return(136);                     //red
                }
                //less than 10 maint costs is medium health
                if (cost == (int)KinFactionGuardCostTypes.MediumCost)
                {
                    return(1359);                     //orange
                }
                if (cost == (int)KinFactionGuardCostTypes.LowCost)
                {
                    return(271);            //green!
                }
                return(130);                //red TODO: Special colour here.
            }
Example #7
0
			/// <summary>
			/// Sets the type of the guard.
			/// </summary>
			/// <param name="type">The type.</param>
			private void SetGuardType(KinFactionGuardTypes type)
			{
				//Check if the new type is the same cost as the old type
				KinFactionGuardTypes currentType = (KinFactionGuardTypes)m_State.GetValue<KinFactionGuardTypes>("Type");
				int cost = KinSystem.GetGuardCostType(type);
				int currentCost = KinSystem.GetGuardCostType(currentType);
				if( !cost.Equals(currentCost))
				{
					//Modify the slots accordingly
					int slots = (int)m_State.GetValue<int>("Slots");
					slots += (currentCost - cost);
					if (slots < 0) return;
					m_State.SetValue("Slots", slots);
				}
				m_State.SetValue("Type", type);
			}
Example #8
0
			/// <summary>
			/// Gets the guard text colour.
			/// </summary>
			/// <param name="guardType">Type of the guard.</param>
			/// <returns></returns>
			private int GetGuardTextColour(KinFactionGuardTypes guardType)
			{
				//less than five maint costs is low health
				int cost = KinSystem.GetGuardCostType(guardType);				

				if( cost == (int)KinFactionGuardCostTypes.HighCost )
					return 136;  //red
			
				//less than 10 maint costs is medium health
				if (cost == (int)KinFactionGuardCostTypes.MediumCost )
					return 1359;  //orange

				if (cost == (int)KinFactionGuardCostTypes.LowCost)
					return 271; //green!

				return 130; //red TODO: Special colour here.
			}
Example #9
0
            /// <summary>
            /// Commit any outstanding changes
            /// </summary>
            /// <param name="sender"></param>
            void ICommitGumpEntity.CommitChanges()
            {
                if (!((ICommitGumpEntity)this).Validate())
                {
                    m_Gump.From.SendMessage("The guard post has been changed since you were modifying it. Please make the changes again.");
                    return;
                }
                if (m_State.IsValueDirty <KinFactionGuardTypes>("Type"))
                {
                    //set guard type

                    //TODO: - check some delay?
                    GuardPost.GuardType = (KinFactionGuardTypes)m_State.GetValue <KinFactionGuardTypes>("Type");
                    m_Gump.From.SendMessage("Guard type changed to {0}.", KinSystem.GetEnumTypeDescription <KinFactionGuardTypes>((KinFactionGuardTypes)m_State.GetValue <KinFactionGuardTypes>("Type")));
                }
                if (m_State.IsValueDirty <KinGuardPost.HireSpeeds>("Speed"))
                {
                    GuardPost.HireSpeed = (KinGuardPost.HireSpeeds)m_State.GetValue <KinGuardPost.HireSpeeds>("Speed");
                    m_Gump.From.SendMessage("Hire rate successfully changed to {0}", KinSystem.GetEnumTypeDescription <KinGuardPost.HireSpeeds>((KinGuardPost.HireSpeeds)m_State.GetValue <KinGuardPost.HireSpeeds>("Speed")));
                    GuardPost.RefreshNextSpawnTime();
                }
                if (m_State.IsValueDirty <int>("Slots"))
                {
                    KinFactionGuardTypes currentType = (KinFactionGuardTypes)m_State.GetOriginalValue <KinFactionGuardTypes>("Type");
                    KinFactionGuardTypes type        = (KinFactionGuardTypes)m_State.GetValue <KinFactionGuardTypes>("Type");
                    int cost        = KinSystem.GetGuardCostType(type);
                    int currentCost = KinSystem.GetGuardCostType(currentType);
                    int slots       = 0;
                    slots += (currentCost - cost);
                    KinCityData data = KinCityManager.GetCityData(GuardPost.City);
                    if (data == null)
                    {
                        return;
                    }
                    KinCityData.BeneficiaryData bd = data.GetBeneficiary(GuardPost.Owner);
                    if (bd == null)
                    {
                        return;
                    }
                    bd.ModifyGuardSlots(slots);
                    m_Gump.From.SendMessage("Unassigned guard slots modified by {0}.", slots);
                }

                /*
                 * if (m_State.StyleChanged)
                 * {
                 *      //Assign new style
                 *      GuardPost.FightStyle = m_State.Style;
                 * }
                 */
                if (m_State.IsValueDirty <FightMode>("Target"))
                {
                    //Dont overwrite this one
                    // 0 the strongest, weakest, closest
                    //NAND out the options so these bits are all 0
                    GuardPost.FightMode &= ~FightMode.Strongest;
                    GuardPost.FightMode &= ~FightMode.Weakest;
                    GuardPost.FightMode &= ~FightMode.Closest;
                    //write new version
                    GuardPost.FightMode |= (FightMode)m_State.GetValue <FightMode>("Target");
                    m_Gump.From.SendMessage("Guard target priority successfully changed.");
                    GuardPost.UpdateExisitngGuards();
                }
            }
Example #10
0
		/// <summary>
		/// Deserializes the specified reader.
		/// </summary>
		/// <param name="reader">The reader.</param>
		public override void Deserialize(GenericReader reader)
		{			
			base.Deserialize(reader);

			TimeSpan ts = TimeSpan.Zero;

			int version = reader.ReadInt();
			switch (version)
			{
				case 1:
					{
						m_Reset = reader.ReadBool();
						ts = reader.ReadDeltaTime() - DateTime.Now;
						m_NextMaintTime = DateTime.Now + ts;						
						ts = reader.ReadDeltaTime() - DateTime.Now;
						m_NextSpawnTime = DateTime.Now + ts;
						m_SpawnTimeMinutes = reader.ReadInt();
						m_GuardType = (KinFactionGuardTypes)reader.ReadInt();
						goto case 0;
					}
				case 0:
					{
						m_City = (KinFactionCities)reader.ReadInt();
						m_Owner = (PlayerMobile)reader.ReadMobile();
						m_Silver = reader.ReadInt();
						break;
					}
			}
		}
Example #11
0
		/// <summary>
		/// Initializes a new instance of the <see cref="KinGuardPost"/> class.
		/// </summary>
		/// <param name="itemID">The item ID.</param>
		/// <param name="owner">The owner.</param>
		/// <param name="guardType">Type of the guard.</param>
		/// <param name="city">The city.</param>
		public KinGuardPost(int itemID, PlayerMobile owner, KinFactionGuardTypes guardType, KinFactionCities city)			
		{
			this.ItemID = itemID;
			Movable = false;
			Visible = true;
			m_City = city;
			m_Owner = owner;
			m_GuardType = guardType; 
			ArrayList creaturesName = new ArrayList(); //bah *! $ arraylists			
			creaturesName.Add(guardType.ToString()); 

			InitSpawn(1, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1), 0, 4, creaturesName);
		}