public FactionState( GenericReader reader )
        {
            int version = reader.ReadEncodedInt();

            switch ( version )
            {
                case 4:
                {
                    int count = reader.ReadEncodedInt();

                    for ( int i = 0; i < count; ++i )
                    {
                        DateTime time = reader.ReadDateTime();

                        if ( i < m_LastBroadcasts.Length )
                            m_LastBroadcasts[i] = time;
                    }

                    goto case 3;
                }
                case 3:
                case 2:
                case 1:
                {
                    m_Election = new Election( reader );

                    goto case 0;
                }
                case 0:
                {
                    m_Faction = Faction.ReadReference( reader );

                    m_Commander = reader.ReadMobile();

                    if ( version < 4 )
                    {
                        DateTime time = reader.ReadDateTime();

                        if ( m_LastBroadcasts.Length > 0 )
                            m_LastBroadcasts[0] = time;
                    }

                    m_Tithe = reader.ReadEncodedInt();
                    m_Silver = reader.ReadEncodedInt();

                    int memberCount = reader.ReadEncodedInt();

                    m_Members = new PlayerStateCollection();

                    for ( int i = 0; i < memberCount; ++i )
                    {
                        PlayerState pl = new PlayerState( reader, m_Faction, m_Members );

                        if ( pl.Mobile != null )
                            m_Members.Add( pl );
                    }

                    m_Faction.State = this;
                    m_Faction.UpdateRanks();

                    m_FactionItems = new FactionItemCollection();

                    if ( version >= 2 )
                    {
                        int factionItemCount = reader.ReadEncodedInt();

                        for ( int i = 0; i < factionItemCount; ++i )
                        {
                            FactionItem factionItem = new FactionItem( reader, m_Faction );

                            if ( !factionItem.HasExpired )
                                factionItem.Attach();
                            else
                                Timer.DelayCall( TimeSpan.Zero, new TimerCallback( factionItem.Detach ) ); // sandbox detachment
                        }
                    }

                    m_FactionTraps = new FactionTrapCollection();

                    if ( version >= 3 )
                    {
                        int factionTrapCount = reader.ReadEncodedInt();

                        for ( int i = 0; i < factionTrapCount; ++i )
                        {
                            BaseFactionTrap trap = reader.ReadItem() as BaseFactionTrap;

                            if ( trap != null && !trap.CheckDecay() )
                                m_FactionTraps.Add( trap );
                        }
                    }

                    break;
                }
            }

            if ( version < 1 )
                m_Election = new Election( m_Faction );
        }
Example #2
0
        public void RemovePlayerState(PlayerState pl)
        {
            if (pl == null || !this.Members.Contains(pl))
                return;

            int killPoints = pl.KillPoints;

            if (pl.RankIndex != -1)
            {
                while ((pl.RankIndex + 1) < this.ZeroRankOffset)
                {
                    PlayerState pNext = this.Members[pl.RankIndex + 1] as PlayerState;
                    this.Members[pl.RankIndex + 1] = pl;
                    this.Members[pl.RankIndex] = pNext;
                    pl.RankIndex++;
                    pNext.RankIndex--;
                }

                this.ZeroRankOffset--;
            }

            this.Members.Remove(pl);

            PlayerMobile pm = (PlayerMobile)pl.Mobile;
            if (pm == null)
                return;

            Mobile mob = pl.Mobile;
            if (pm.FactionPlayerState == pl)
            {
                pm.FactionPlayerState = null;

                mob.InvalidateProperties();
                mob.Delta(MobileDelta.Noto);

                if (this.Election.IsCandidate(mob))
                    this.Election.RemoveCandidate(mob);

                if (pl.Finance != null)
                    pl.Finance.Finance = null;

                if (pl.Sheriff != null)
                    pl.Sheriff.Sheriff = null;

                this.Election.RemoveVoter(mob);

                if (this.Commander == mob)
                    this.Commander = null;

                pm.ValidateEquipment();
            }

            if (killPoints > 0)
                DistributePoints(killPoints);
        }
Example #3
0
		public void RemovePlayerState(PlayerState pl)
		{
			if (pl == null || !Members.Contains(pl))
			{
				return;
			}

			int killPoints = pl.KillPoints;

			if (pl.RankIndex != -1)
			{
				while ((pl.RankIndex + 1) < ZeroRankOffset)
				{
					PlayerState pNext = Members[pl.RankIndex + 1];
					Members[pl.RankIndex + 1] = pl;
					Members[pl.RankIndex] = pNext;
					pl.RankIndex++;
					pNext.RankIndex--;
				}

				ZeroRankOffset--;
			}

			Members.Remove(pl);

			var pm = (PlayerMobile)pl.Mobile;
			if (pm == null)
			{
				return;
			}

			Mobile mob = pl.Mobile;
			if (pm.FactionPlayerState == pl)
			{
				pm.FactionPlayerState = null;

				mob.InvalidateProperties();
				mob.Delta(MobileDelta.Noto);

				if (Election.IsCandidate(mob))
				{
					Election.RemoveCandidate(mob);
				}

				if (pl.Finance != null)
				{
					pl.Finance.Finance = null;
				}

				if (pl.Sheriff != null)
				{
					pl.Sheriff.Sheriff = null;
				}

				Election.RemoveVoter(mob);

				if (Commander == mob)
				{
					Commander = null;
				}

				pm.ValidateEquipment();
			}

			if (killPoints > 0)
			{
				LoggingCustom.Log(
					"LOG_FactionPoints.txt",
					DateTime.Now + "\t" + pm.Name + "\tFaction.RemovePlayerState: DistributePoints\t" + killPoints);
				DistributePoints(killPoints);
			}
		}
Example #4
0
		public FactionState( GenericReader reader )
		{
			int version = reader.ReadEncodedInt();

			switch ( version )
			{
                case 5:
                    {
                        m_LastAtrophy = reader.ReadDateTime();
                        goto case 4;
                    }
				case 4:
				{
					int count = reader.ReadEncodedInt();

					for ( int i = 0; i < count; ++i )
					{
						DateTime time = reader.ReadDateTime();

						if ( i < m_LastBroadcasts.Length )
							m_LastBroadcasts[i] = time;
					}

					goto case 3;
				}
				case 3:
				case 2:
				case 1:
				{
					m_Election = new Election( reader );

					goto case 0;
				}
				case 0:
				{
					m_Faction = Faction.ReadReference( reader );

					m_Commander = reader.ReadMobile();

                    if (version < 5)
                        m_LastAtrophy = DateTime.Now;

					if ( version < 4 )
					{
						DateTime time = reader.ReadDateTime();

						if ( m_LastBroadcasts.Length > 0 )
							m_LastBroadcasts[0] = time;
					}

					m_Tithe = reader.ReadEncodedInt();
					m_Silver = reader.ReadEncodedInt();

					int memberCount = reader.ReadEncodedInt();

					m_Members = new List<PlayerState>();

					for ( int i = 0; i < memberCount; ++i )
					{
						PlayerState pl = new PlayerState( reader, m_Faction, m_Members );

						if ( pl.Mobile != null )
							m_Members.Add( pl );
					}

					m_Faction.State = this;

                    m_Faction.ZeroRankOffset = m_Members.Count;
                    m_Members.Sort();

                    for (int i = m_Members.Count - 1; i >= 0; i--)
                    {
                        PlayerState player = m_Members[i];

                        if (player.KillPoints <= 0)
                            m_Faction.ZeroRankOffset = i;
                        else
                            player.RankIndex = i;
                    }


					m_FactionItems = new List<FactionItem>();

					if ( version >= 2 )
					{
						int factionItemCount = reader.ReadEncodedInt();

						for ( int i = 0; i < factionItemCount; ++i )
						{
							FactionItem factionItem = new FactionItem( reader, m_Faction );

                            Timer.DelayCall(TimeSpan.Zero, new TimerCallback(factionItem.CheckAttach)); // sandbox attachment
						}
					}

					m_FactionTraps = new List<BaseFactionTrap>();

					if ( version >= 3 )
					{
						int factionTrapCount = reader.ReadEncodedInt();

						for ( int i = 0; i < factionTrapCount; ++i )
						{
							BaseFactionTrap trap = reader.ReadItem() as BaseFactionTrap;

							if ( trap != null && !trap.CheckDecay() )
								m_FactionTraps.Add( trap );
						}
					}

					break;
				}
			}

			if ( version < 1 )
				m_Election = new Election( m_Faction );
		}
Example #5
0
        public override void OnResponse(NetState sender, RelayInfo info)
        {
            switch (info.ButtonID)
            {
            case 1:                     // continue
            {
                Guild guild = m_From.Guild as Guild;

                if (guild == null)
                {
                    PlayerState pl = PlayerState.Find(m_From);

                    if (pl != null)
                    {
                        pl.Leaving = DateTime.UtcNow;

                        if (Faction.LeavePeriod == TimeSpan.FromDays(3.0))
                        {
                            m_From.SendLocalizedMessage(1005065);                                             // You will be removed from the faction in 3 days
                        }
                        else
                        {
                            m_From.SendMessage("You will be removed from the faction in {0} days.", Faction.LeavePeriod.TotalDays);
                        }
                    }
                }
                else if (guild.Leader != m_From)
                {
                    m_From.SendLocalizedMessage(1005061);                                     // You cannot quit the faction because you are not the guild master
                }
                else
                {
                    m_From.SendLocalizedMessage(1042285);                                     // Your guild is now quitting the faction.

                    for (int i = 0; i < guild.Members.Count; ++i)
                    {
                        Mobile      mob = guild.Members[i];
                        PlayerState pl  = PlayerState.Find(mob);

                        if (pl != null)
                        {
                            pl.Leaving = DateTime.UtcNow;

                            if (Faction.LeavePeriod == TimeSpan.FromDays(3.0))
                            {
                                mob.SendLocalizedMessage(1005060);                                                 // Your guild will quit the faction in 3 days
                            }
                            else
                            {
                                mob.SendMessage("Your guild will quit the faction in {0} days.", Faction.LeavePeriod.TotalDays);
                            }
                        }
                    }
                }

                break;
            }

            case 2:                                  // cancel
            {
                m_From.SendLocalizedMessage(500737); // Canceled resignation.
                break;
            }
            }
        }
Example #6
0
        private static void EventSink_Speech(SpeechEventArgs e)
        {
            var from     = e.Mobile;
            var keywords = e.Keywords;

            for (var i = 0; i < keywords.Length; ++i)
            {
                switch (keywords[i])
                {
                case 0x00E4:     // *i wish to access the city treasury*
                {
                    var town = Town.FromRegion(from.Region);

                    if (town?.IsFinance(from) != true || !from.Alive)
                    {
                        break;
                    }

                    if (FactionGump.Exists(from))
                    {
                        from.SendLocalizedMessage(1042160);         // You already have a faction menu open.
                    }
                    else if (town.Owner != null && from is PlayerMobile mobile)
                    {
                        mobile.SendGump(new FinanceGump(mobile, town.Owner, town));
                    }

                    break;
                }

                case 0x0ED:     // *i am sheriff*
                {
                    var town = Town.FromRegion(from.Region);

                    if (town?.IsSheriff(from) != true || !from.Alive)
                    {
                        break;
                    }

                    if (FactionGump.Exists(from))
                    {
                        from.SendLocalizedMessage(1042160);         // You already have a faction menu open.
                    }
                    else if (town.Owner != null)
                    {
                        from.SendGump(new SheriffGump((PlayerMobile)from, town.Owner, town));
                    }

                    break;
                }

                case 0x00EF:     // *you are fired*
                {
                    var town = Town.FromRegion(from.Region);

                    if (town == null)
                    {
                        break;
                    }

                    if (town.IsFinance(from) || town.IsSheriff(from))
                    {
                        town.BeginOrderFiring(from);
                    }

                    break;
                }

                case 0x00E5:     // *i wish to resign as finance minister*
                {
                    var pl = PlayerState.Find(from);

                    if (pl?.Finance != null)
                    {
                        pl.Finance.Finance = null;
                        from.SendLocalizedMessage(1005081);         // You have been fired as Finance Minister
                    }

                    break;
                }

                case 0x00EE:     // *i wish to resign as sheriff*
                {
                    var pl = PlayerState.Find(from);

                    if (pl?.Sheriff != null)
                    {
                        pl.Sheriff.Sheriff = null;
                        from.SendLocalizedMessage(1010270);         // You have been fired as Sheriff
                    }

                    break;
                }

                case 0x00E9:     // *what is my faction term status*
                {
                    var pl = PlayerState.Find(from);

                    if (pl?.IsLeaving == true)
                    {
                        if (Faction.CheckLeaveTimer(from))
                        {
                            break;
                        }

                        var remaining = pl.Leaving + Faction.LeavePeriod - Core.Now;

                        if (remaining.TotalDays >= 1)
                        {
                            from.SendLocalizedMessage(
                                1042743,
                                remaining.TotalDays
                                .ToString("N0")
                                );     // Your term of service will come to an end in ~1_DAYS~ days.
                        }
                        else if (remaining.TotalHours >= 1)
                        {
                            // Your term of service will come to an end in ~1_HOURS~ hours.
                            from.SendLocalizedMessage(1042741, remaining.TotalHours.ToString("N0"));
                        }
                        else
                        {
                            // Your term of service will come to an end in less than one hour.
                            from.SendLocalizedMessage(1042742);
                        }
                    }
                    else if (pl != null)
                    {
                        // You are not in the process of quitting the faction.
                        from.SendLocalizedMessage(1042233);
                    }

                    break;
                }

                case 0x00EA:     // *message faction*
                {
                    var faction = Faction.Find(from);

                    if (faction?.IsCommander(from) != true)
                    {
                        break;
                    }

                    if (from.AccessLevel == AccessLevel.Player && !faction.FactionMessageReady)
                    {
                        // The required time has not yet passed since the last message was sent
                        from.SendLocalizedMessage(1010264);
                    }
                    else
                    {
                        faction.BeginBroadcast(from);
                    }

                    break;
                }

                case 0x00EC:     // *showscore*
                {
                    var pl = PlayerState.Find(from);

                    if (pl != null)
                    {
                        Timer.DelayCall(ShowScore_Sandbox, pl);
                    }

                    break;
                }

                case 0x0178:     // i honor your leadership
                {
                    Faction.Find(from)?.BeginHonorLeadership(from);
                    break;
                }
                }
            }
        }
        public FactionStoneGump(PlayerMobile from, Faction faction) : base(20, 30)
        {
            m_From    = from;
            m_Faction = faction;

            AddPage(0);

            AddBackground(0, 0, 550, 440, 5054);
            AddBackground(10, 10, 530, 420, 3000);

            #region General
            AddPage(1);

            AddHtmlText(20, 30, 510, 20, faction.Definition.Header, false, false);

            AddHtmlLocalized(20, 60, 100, 20, 1011429, false, false);               // Led By :
            AddHtml(125, 60, 200, 20, faction.Commander != null ? faction.Commander.Name : "Nobody", false, false);

            AddHtmlLocalized(20, 80, 100, 20, 1011457, false, false);               // Tithe rate :
            if (faction.Tithe >= 0 && faction.Tithe <= 100 && (faction.Tithe % 10) == 0)
            {
                AddHtmlLocalized(125, 80, 350, 20, 1011480 + (faction.Tithe / 10), false, false);
            }
            else
            {
                AddHtml(125, 80, 350, 20, faction.Tithe + "%", false, false);
            }

            AddHtmlLocalized(20, 100, 100, 20, 1011458, false, false);               // Traps placed :
            AddHtml(125, 100, 50, 20, faction.Traps.Count.ToString(), false, false);

            AddHtmlLocalized(55, 225, 200, 20, 1011428, false, false);               // VOTE FOR LEADERSHIP
            AddButton(20, 225, 4005, 4007, ToButtonID(0, 0), GumpButtonType.Reply, 0);

            AddHtmlLocalized(55, 150, 100, 20, 1011430, false, false);               // CITY STATUS
            AddButton(20, 150, 4005, 4007, 0, GumpButtonType.Page, 2);

            AddHtmlLocalized(55, 175, 100, 20, 1011444, false, false);               // STATISTICS
            AddButton(20, 175, 4005, 4007, 0, GumpButtonType.Page, 4);

            bool isMerchantQualified = MerchantTitles.HasMerchantQualifications(from);

            PlayerState pl = PlayerState.Find(from);

            if (pl != null && pl.MerchantTitle != MerchantTitle.None)
            {
                AddHtmlLocalized(55, 200, 250, 20, 1011460, false, false);                   // UNDECLARE FACTION MERCHANT
                AddButton(20, 200, 4005, 4007, ToButtonID(1, 0), GumpButtonType.Reply, 0);
            }
            else if (isMerchantQualified)
            {
                AddHtmlLocalized(55, 200, 250, 20, 1011459, false, false);                   // DECLARE FACTION MERCHANT
                AddButton(20, 200, 4005, 4007, 0, GumpButtonType.Page, 5);
            }
            else
            {
                AddHtmlLocalized(55, 200, 250, 20, 1011467, false, false);                   // MERCHANT OPTIONS
                AddImage(20, 200, 4020);
            }

            AddHtmlLocalized(55, 250, 300, 20, 1011461, false, false);               // COMMANDER OPTIONS
            if (faction.IsCommander(from))
            {
                AddButton(20, 250, 4005, 4007, 0, GumpButtonType.Page, 6);
            }
            else
            {
                AddImage(20, 250, 4020);
            }

            AddHtmlLocalized(55, 275, 300, 20, 1011426, false, false);               // LEAVE THIS FACTION
            AddButton(20, 275, 4005, 4007, ToButtonID(0, 1), GumpButtonType.Reply, 0);

            AddHtmlLocalized(55, 300, 200, 20, 1011441, false, false);               // EXIT
            AddButton(20, 300, 4005, 4007, 0, GumpButtonType.Reply, 0);
            #endregion

            #region City Status
            AddPage(2);

            AddHtmlLocalized(20, 30, 250, 20, 1011430, false, false);               // CITY STATUS

            List <Town> towns = Town.Towns;

            for (int i = 0; i < towns.Count; ++i)
            {
                Town town = towns[i];

                AddHtmlText(40, 55 + (i * 30), 150, 20, town.Definition.TownName, false, false);

                if (town.Owner == null)
                {
                    AddHtmlLocalized(200, 55 + (i * 30), 150, 20, 1011462, false, false);                       // : Neutral
                }
                else
                {
                    AddHtmlLocalized(200, 55 + (i * 30), 150, 20, town.Owner.Definition.OwnerLabel, false, false);

                    BaseMonolith monolith = town.Monolith;

                    AddImage(20, 60 + (i * 30), (monolith != null && monolith.Sigil != null && monolith.Sigil.IsPurifying) ? 0x938 : 0x939);
                }
            }


            AddImage(20, 300, 2361);
            AddHtmlLocalized(45, 295, 300, 20, 1011491, false, false);               // sigil may be recaptured

            AddImage(20, 320, 2360);
            AddHtmlLocalized(45, 315, 300, 20, 1011492, false, false);               // sigil may not be recaptured

            AddHtmlLocalized(55, 350, 100, 20, 1011447, false, false);               // BACK
            AddButton(20, 350, 4005, 4007, 0, GumpButtonType.Page, 1);
            #endregion

            #region Statistics
            AddPage(4);

            AddHtmlLocalized(20, 30, 150, 20, 1011444, false, false);               // STATISTICS

            AddHtmlLocalized(20, 100, 100, 20, 1011445, false, false);              // Name :
            AddHtml(120, 100, 150, 20, from.Name, false, false);

            AddHtmlLocalized(20, 130, 100, 20, 1018064, false, false);               // score :
            AddHtml(120, 130, 100, 20, (pl != null ? pl.KillPoints : 0).ToString(), false, false);

            AddHtmlLocalized(20, 160, 100, 20, 1011446, false, false);               // Rank :
            AddHtml(120, 160, 100, 20, (pl != null ? pl.Rank.Rank : 0).ToString(), false, false);

            AddHtmlLocalized(55, 250, 100, 20, 1011447, false, false);               // BACK
            AddButton(20, 250, 4005, 4007, 0, GumpButtonType.Page, 1);
            #endregion

            #region Merchant Options
            if ((pl == null || pl.MerchantTitle == MerchantTitle.None) && isMerchantQualified)
            {
                AddPage(5);

                AddHtmlLocalized(20, 30, 250, 20, 1011467, false, false);                   // MERCHANT OPTIONS

                AddHtmlLocalized(20, 80, 300, 20, 1011473, false, false);                   // Select the title you wish to display

                MerchantTitleInfo[] infos = MerchantTitles.Info;

                for (int i = 0; i < infos.Length; ++i)
                {
                    MerchantTitleInfo info = infos[i];

                    if (MerchantTitles.IsQualified(from, info))
                    {
                        AddButton(20, 100 + (i * 30), 4005, 4007, ToButtonID(1, i + 1), GumpButtonType.Reply, 0);
                    }
                    else
                    {
                        AddImage(20, 100 + (i * 30), 4020);
                    }

                    AddHtmlText(55, 100 + (i * 30), 200, 20, info.Label, false, false);
                }

                AddHtmlLocalized(55, 340, 100, 20, 1011447, false, false);                   // BACK
                AddButton(20, 340, 4005, 4007, 0, GumpButtonType.Page, 1);
            }
            #endregion

            #region Commander Options
            if (faction.IsCommander(from))
            {
                #region General
                AddPage(6);

                AddHtmlLocalized(20, 30, 200, 20, 1011461, false, false);                   // COMMANDER OPTIONS

                AddHtmlLocalized(20, 70, 120, 20, 1011457, false, false);                   // Tithe rate :
                if (faction.Tithe >= 0 && faction.Tithe <= 100 && (faction.Tithe % 10) == 0)
                {
                    AddHtmlLocalized(140, 70, 250, 20, 1011480 + (faction.Tithe / 10), false, false);
                }
                else
                {
                    AddHtml(140, 70, 250, 20, faction.Tithe + "%", false, false);
                }

                AddHtmlLocalized(20, 100, 120, 20, 1011474, false, false);                   // Silver available :
                AddHtml(140, 100, 50, 20, faction.Silver.ToString("N0"), false, false);      // NOTE: Added 'N0' formatting

                AddHtmlLocalized(55, 130, 200, 20, 1011478, false, false);                   // CHANGE TITHE RATE
                AddButton(20, 130, 4005, 4007, 0, GumpButtonType.Page, 8);

                AddHtmlLocalized(55, 160, 200, 20, 1018301, false, false);                   // TRANSFER SILVER
                if (faction.Silver >= 10000)
                {
                    AddButton(20, 160, 4005, 4007, 0, GumpButtonType.Page, 7);
                }
                else
                {
                    AddImage(20, 160, 4020);
                }

                AddHtmlLocalized(55, 310, 100, 20, 1011447, false, false);                   // BACK
                AddButton(20, 310, 4005, 4007, 0, GumpButtonType.Page, 1);
                #endregion

                #region Town Finance
                if (faction.Silver >= 10000)
                {
                    AddPage(7);

                    AddHtmlLocalized(20, 30, 250, 20, 1011476, false, false);                       // TOWN FINANCE

                    AddHtmlLocalized(20, 50, 400, 20, 1011477, false, false);                       // Select a town to transfer 10000 silver to

                    for (int i = 0; i < towns.Count; ++i)
                    {
                        Town town = towns[i];

                        AddHtmlText(55, 75 + (i * 30), 200, 20, town.Definition.TownName, false, false);

                        if (town.Owner == faction)
                        {
                            AddButton(20, 75 + (i * 30), 4005, 4007, ToButtonID(2, i), GumpButtonType.Reply, 0);
                        }
                        else
                        {
                            AddImage(20, 75 + (i * 30), 4020);
                        }
                    }

                    AddHtmlLocalized(55, 310, 100, 20, 1011447, false, false);                       // BACK
                    AddButton(20, 310, 4005, 4007, 0, GumpButtonType.Page, 1);
                }
                #endregion

                #region Change Tithe Rate
                AddPage(8);

                AddHtmlLocalized(20, 30, 400, 20, 1011479, false, false);                   // Select the % for the new tithe rate

                int y = 55;

                for (int i = 0; i <= 10; ++i)
                {
                    if (i == 5)
                    {
                        y += 5;
                    }

                    AddHtmlLocalized(55, y, 300, 20, 1011480 + i, false, false);
                    AddButton(20, y, 4005, 4007, ToButtonID(3, i), GumpButtonType.Reply, 0);

                    y += 20;

                    if (i == 5)
                    {
                        y += 5;
                    }
                }

                AddHtmlLocalized(55, 310, 300, 20, 1011447, false, false);                   // BACK
                AddButton(20, 310, 4005, 4007, 0, GumpButtonType.Page, 1);
                #endregion
            }
            #endregion
        }
        public override void OnResponse(NetState sender, RelayInfo info)
        {
            int type, index;

            if (!FromButtonID(info.ButtonID, out type, out index))
            {
                return;
            }

            switch (type)
            {
            case 0:                     // general
            {
                switch (index)
                {
                case 0:                                 // vote
                {
                    m_From.SendGump(new ElectionGump(m_From, m_Faction.Election));
                    break;
                }

                case 1:                                 // leave
                {
                    m_From.SendGump(new LeaveFactionGump(m_From, m_Faction));
                    break;
                }
                }

                break;
            }

            case 1:                     // merchant title
            {
                if (index >= 0 && index <= MerchantTitles.Info.Length)
                {
                    PlayerState pl = PlayerState.Find(m_From);

                    MerchantTitle     newTitle = (MerchantTitle)index;
                    MerchantTitleInfo mti      = MerchantTitles.GetInfo(newTitle);

                    if (mti == null)
                    {
                        m_From.SendLocalizedMessage(1010120);                                   // Your merchant title has been removed

                        if (pl != null)
                        {
                            pl.MerchantTitle = newTitle;
                        }
                    }
                    else if (MerchantTitles.IsQualified(m_From, mti))
                    {
                        m_From.SendLocalizedMessage(mti.Assigned);

                        if (pl != null)
                        {
                            pl.MerchantTitle = newTitle;
                        }
                    }
                }

                break;
            }

            case 2:                     // transfer silver
            {
                if (!m_Faction.IsCommander(m_From))
                {
                    return;
                }

                List <Town> towns = Town.Towns;

                if (index >= 0 && index < towns.Count)
                {
                    Town town = towns[index];

                    if (town.Owner == m_Faction)
                    {
                        if (m_Faction.Silver >= 10000)
                        {
                            m_Faction.Silver -= 10000;
                            town.Silver      += 10000;

                            // 10k in silver has been received by:
                            m_From.SendLocalizedMessage(1042726, true, " " + town.Definition.FriendlyName);
                        }
                    }
                }

                break;
            }

            case 3:                     // change tithe
            {
                if (!m_Faction.IsCommander(m_From))
                {
                    return;
                }

                if (index >= 0 && index <= 10)
                {
                    m_Faction.Tithe = index * 10;
                }

                break;
            }
            }
        }
Example #9
0
 protected virtual void OnRankUpdate(PlayerState pl)
 {
 }
Example #10
0
        public void Slice()
        {
            if (m_Faction.Election != this)
            {
                if (m_Timer != null)
                {
                    m_Timer.Stop();
                }

                m_Timer = null;

                return;
            }

            switch (m_State)
            {
            case ElectionState.Pending:
            {
                if ((m_LastStateTime + PendingPeriod) > DateTime.UtcNow)
                {
                    break;
                }

                m_Faction.Broadcast(1038023);         // Campaigning for the Faction Commander election has begun.

                m_Candidates.Clear();
                State = ElectionState.Campaign;

                break;
            }

            case ElectionState.Campaign:
            {
                if ((m_LastStateTime + CampaignPeriod) > DateTime.UtcNow)
                {
                    break;
                }

                if (m_Candidates.Count == 0)
                {
                    m_Faction.Broadcast(1038025);         // Nobody ran for office.
                    State = ElectionState.Pending;
                }
                else if (m_Candidates.Count == 1)
                {
                    m_Faction.Broadcast(1038029);         // Only one member ran for office.

                    Candidate winner = m_Candidates[0];

                    Mobile      mob = winner.Mobile;
                    PlayerState pl  = PlayerState.Find(mob);

                    if (pl == null || pl.Faction != m_Faction || mob == m_Faction.Commander)
                    {
                        m_Faction.Broadcast(1038026);         // Faction leadership has not changed.
                    }
                    else
                    {
                        m_Faction.Broadcast(1038028);         // The faction has a new commander.
                        m_Faction.Commander = mob;
                    }

                    m_Candidates.Clear();
                    State = ElectionState.Pending;
                }
                else
                {
                    m_Faction.Broadcast(1038030);
                    State = ElectionState.Election;
                }

                break;
            }

            case ElectionState.Election:
            {
                if ((m_LastStateTime + VotingPeriod) > DateTime.UtcNow)
                {
                    break;
                }

                m_Faction.Broadcast(1038024);         // The results for the Faction Commander election are in

                Candidate winner = null;

                for (int i = 0; i < m_Candidates.Count; ++i)
                {
                    Candidate cd = m_Candidates[i];

                    PlayerState pl = PlayerState.Find(cd.Mobile);

                    if (pl == null || pl.Faction != m_Faction)
                    {
                        continue;
                    }

                    //cd.CleanMuleVotes();

                    if (winner == null || cd.Votes > winner.Votes)
                    {
                        winner = cd;
                    }
                }

                if (winner == null)
                {
                    m_Faction.Broadcast(1038026);         // Faction leadership has not changed.
                }
                else if (winner.Mobile == m_Faction.Commander)
                {
                    m_Faction.Broadcast(1038027);         // The incumbent won the election.
                }
                else
                {
                    m_Faction.Broadcast(1038028);         // The faction has a new commander.
                    m_Faction.Commander = winner.Mobile;
                }

                m_Candidates.Clear();
                State = ElectionState.Pending;

                break;
            }
            }
        }
Example #11
0
        public void OnJoinAccepted(Mobile mob)
        {
            PlayerMobile pm = mob as PlayerMobile;

            if (pm == null)
            {
                return;                 // sanity
            }
            PlayerState pl = PlayerState.Find(pm);

            if (pm.Young)
            {
                pm.SendLocalizedMessage(1010104);                   // You cannot join a faction as a young player
            }
            else if (pl != null && pl.IsLeaving)
            {
                pm.SendLocalizedMessage(1005051);                   // You cannot use the faction stone until you have finished quitting your current faction
            }
            else if (AlreadyHasCharInFaction(pm))
            {
                pm.SendLocalizedMessage(1005059);                   // You cannot join a faction because you already declared your allegiance with another character
            }
            else if (IsFactionBanned(mob))
            {
                pm.SendLocalizedMessage(1005052);                   // You are currently banned from the faction system
            }
            else if (pm.Guild != null)
            {
                Guild guild = pm.Guild as Guild;

                if (guild.Leader != pm)
                {
                    pm.SendLocalizedMessage(1005057);                       // You cannot join a faction because you are in a guild and not the guildmaster
                }
                //else if ( !Guild.NewGuildSystem && guild.Type != GuildType.Regular )
                //pm.SendLocalizedMessage( 1042161 ); // You cannot join a faction because your guild is an Order or Chaos type.
                else if (!Guild.NewGuildSystem && guild.Enemies != null && guild.Enemies.Count > 0) //CAN join w/wars in new system
                {
                    pm.SendLocalizedMessage(1005056);                                               // You cannot join a faction with active Wars
                }
                else if (!CanHandleInflux(guild.Members.Count))
                {
                    pm.SendLocalizedMessage(1018031);                       // In the interest of faction stability, this faction declines to accept new members for now.
                }
                else
                {
                    ArrayList members = new ArrayList(guild.Members);

                    for (int i = 0; i < members.Count; ++i)
                    {
                        PlayerMobile member = members[i] as PlayerMobile;

                        if (member == null)
                        {
                            continue;
                        }

                        JoinGuilded(member, guild);
                    }
                }
            }
            else if (!CanHandleInflux(1))
            {
                pm.SendLocalizedMessage(1018031);                   // In the interest of faction stability, this faction declines to accept new members for now.
            }
            else
            {
                JoinAlone(mob);
            }
        }
Example #12
0
        public override void Execute(CommandEventArgs e, object obj)
        {
            Mobile mob = (Mobile)obj;

            switch (m_KickType)
            {
            case FactionKickType.Kick:
            {
                PlayerState pl = PlayerState.Find(mob);

                if (pl != null)
                {
                    pl.Faction.RemoveMember(mob);
                    mob.SendMessage("You have been kicked from your faction.");
                    AddResponse("They have been kicked from their faction.");
                }
                else
                {
                    LogFailure("They are not in a faction.");
                }

                break;
            }

            case FactionKickType.Ban:
            {
                Account acct = mob.Account as Account;

                if (acct != null)
                {
                    if (acct.GetTag("FactionBanned") == null)
                    {
                        acct.SetTag("FactionBanned", "true");
                        AddResponse("The account has been banned from joining factions.");
                    }
                    else
                    {
                        AddResponse("The account is already banned from joining factions.");
                    }

                    for (int i = 0; i < acct.Length; ++i)
                    {
                        mob = acct[i];

                        if (mob != null)
                        {
                            PlayerState pl = PlayerState.Find(mob);

                            if (pl != null)
                            {
                                pl.Faction.RemoveMember(mob);
                                mob.SendMessage("You have been kicked from your faction.");
                                AddResponse("They have been kicked from their faction.");
                            }
                        }
                    }
                }
                else
                {
                    LogFailure("They have no assigned account.");
                }

                break;
            }

            case FactionKickType.Unban:
            {
                Account acct = mob.Account as Account;

                if (acct != null)
                {
                    if (acct.GetTag("FactionBanned") == null)
                    {
                        AddResponse("The account is not already banned from joining factions.");
                    }
                    else
                    {
                        acct.RemoveTag("FactionBanned");
                        AddResponse("The account may now freely join factions.");
                    }
                }
                else
                {
                    LogFailure("They have no assigned account.");
                }

                break;
            }
            }
        }
Example #13
0
        public static void HandleDeath(Mobile victim, Mobile killer)
        {
            if (killer == null)
            {
                killer = victim.FindMostRecentDamager(true);
            }

            PlayerState killerState = PlayerState.Find(killer);

            Container pack = victim.Backpack;

            if (pack != null)
            {
                Container killerPack = (killer == null ? null : killer.Backpack);
                Item[]    sigils     = pack.FindItemsByType(typeof(Sigil));

                for (int i = 0; i < sigils.Length; ++i)
                {
                    Sigil sigil = (Sigil)sigils[i];

                    if (killerState != null && killerPack != null)
                    {
                        if (Sigil.ExistsOn(killer))
                        {
                            sigil.ReturnHome();
                            killer.SendLocalizedMessage(1010258);                               // The sigil has gone back to its home location because you already have a sigil.
                        }
                        else if (!killerPack.TryDropItem(killer, sigil, false))
                        {
                            sigil.ReturnHome();
                            killer.SendLocalizedMessage(1010259);                               // The sigil has gone home because your backpack is full.
                        }
                    }
                    else
                    {
                        sigil.ReturnHome();
                    }
                }
            }

            if (killerState == null)
            {
                return;
            }

            if (victim is BaseCreature)
            {
                BaseCreature bc            = (BaseCreature)victim;
                Faction      victimFaction = bc.FactionAllegiance;

                if (bc.Map == Faction.Facet && victimFaction != null && killerState.Faction != victimFaction)
                {
                    int silver = killerState.Faction.AwardSilver(killer, bc.FactionSilverWorth);

                    if (silver > 0)
                    {
                        killer.SendLocalizedMessage(1042748, silver.ToString("N0"));                             // Thou hast earned ~1_AMOUNT~ silver for vanquishing the vile creature.
                    }
                }

                #region Ethics
                if (bc.Map == Faction.Facet && bc.GetEthicAllegiance(killer) == BaseCreature.Allegiance.Enemy)
                {
                    Ethics.Player killerEPL = Ethics.Player.Find(killer);

                    if (killerEPL != null && (100 - killerEPL.Power) > Utility.Random(100))
                    {
                        ++killerEPL.Power;
                        ++killerEPL.History;
                    }
                }
                #endregion

                return;
            }

            PlayerState victimState = PlayerState.Find(victim);

            if (victimState == null)
            {
                return;
            }

            if (killer == victim || killerState.Faction != victimState.Faction)
            {
                ApplySkillLoss(victim);
            }

            if (killerState.Faction != victimState.Faction)
            {
                if (victimState.KillPoints <= -6)
                {
                    killer.SendLocalizedMessage(501693);                       // This victim is not worth enough to get kill points from.

                    #region Ethics
                    Ethics.Player killerEPL = Ethics.Player.Find(killer);
                    Ethics.Player victimEPL = Ethics.Player.Find(victim);

                    if (killerEPL != null && victimEPL != null && victimEPL.Power > 0 && victimState.CanGiveSilverTo(killer))
                    {
                        int powerTransfer = Math.Max(1, victimEPL.Power / 5);

                        if (powerTransfer > (100 - killerEPL.Power))
                        {
                            powerTransfer = 100 - killerEPL.Power;
                        }

                        if (powerTransfer > 0)
                        {
                            victimEPL.Power -= (powerTransfer + 1) / 2;
                            killerEPL.Power += powerTransfer;

                            killerEPL.History += powerTransfer;

                            victimState.OnGivenSilverTo(killer);
                        }
                    }
                    #endregion
                }
                else
                {
                    int award = Math.Max(victimState.KillPoints / 10, 1);

                    if (award > 40)
                    {
                        award = 40;
                    }

                    if (victimState.CanGiveSilverTo(killer))
                    {
                        if (victimState.KillPoints > 0)
                        {
                            int silver = 0;

                            silver = killerState.Faction.AwardSilver(killer, award * 40);

                            if (silver > 0)
                            {
                                killer.SendLocalizedMessage(1042736, String.Format("{0:N0} silver\t{1}", silver, victim.Name));                                     // You have earned ~1_SILVER_AMOUNT~ pieces for vanquishing ~2_PLAYER_NAME~!
                            }
                        }

                        victimState.KillPoints -= award;
                        killerState.KillPoints += award;

                        int offset = (award != 1 ? 0 : 2);                           // for pluralization

                        string args = String.Format("{0}\t{1}\t{2}", award, victim.Name, killer.Name);

                        killer.SendLocalizedMessage(1042737 + offset, args);                           // Thou hast been honored with ~1_KILL_POINTS~ kill point(s) for vanquishing ~2_DEAD_PLAYER~!
                        victim.SendLocalizedMessage(1042738 + offset, args);                           // Thou has lost ~1_KILL_POINTS~ kill point(s) to ~3_ATTACKER_NAME~ for being vanquished!

                        #region Ethics
                        Ethics.Player killerEPL = Ethics.Player.Find(killer);
                        Ethics.Player victimEPL = Ethics.Player.Find(victim);

                        if (killerEPL != null && victimEPL != null && victimEPL.Power > 0)
                        {
                            int powerTransfer = Math.Max(1, victimEPL.Power / 5);

                            if (powerTransfer > (100 - killerEPL.Power))
                            {
                                powerTransfer = 100 - killerEPL.Power;
                            }

                            if (powerTransfer > 0)
                            {
                                victimEPL.Power -= (powerTransfer + 1) / 2;
                                killerEPL.Power += powerTransfer;

                                killerEPL.History += powerTransfer;
                            }
                        }
                        #endregion

                        victimState.OnGivenSilverTo(killer);
                    }
                    else
                    {
                        killer.SendLocalizedMessage(1042231);                           // You have recently defeated this enemy and thus their death brings you no honor.
                    }
                }
            }
        }
Example #14
0
        public FactionState(IGenericReader reader)
        {
            var version = reader.ReadEncodedInt();

            switch (version)
            {
                case 5:
                    {
                        LastAtrophy = reader.ReadDateTime();
                        goto case 4;
                    }
                case 4:
                    {
                        var count = reader.ReadEncodedInt();

                        for (var i = 0; i < count; ++i)
                        {
                            var time = reader.ReadDateTime();

                            if (i < m_LastBroadcasts.Length)
                                m_LastBroadcasts[i] = time;
                        }

                        goto case 3;
                    }
                case 3:
                case 2:
                case 1:
                    {
                        Election = new Election(reader);

                        goto case 0;
                    }
                case 0:
                    {
                        m_Faction = Faction.ReadReference(reader);

                        m_Commander = reader.ReadMobile();

                        if (version < 5)
                            LastAtrophy = DateTime.UtcNow;

                        if (version < 4)
                        {
                            var time = reader.ReadDateTime();

                            if (m_LastBroadcasts.Length > 0)
                                m_LastBroadcasts[0] = time;
                        }

                        Tithe = reader.ReadEncodedInt();
                        Silver = reader.ReadEncodedInt();

                        var memberCount = reader.ReadEncodedInt();

                        Members = new List<PlayerState>();

                        for (var i = 0; i < memberCount; ++i)
                        {
                            var pl = new PlayerState(reader, m_Faction, Members);

                            if (pl.Mobile != null)
                                Members.Add(pl);
                        }

                        m_Faction.State = this;

                        m_Faction.ZeroRankOffset = Members.Count;
                        Members.Sort();

                        for (var i = Members.Count - 1; i >= 0; i--)
                        {
                            var player = Members[i];

                            if (player.KillPoints <= 0)
                                m_Faction.ZeroRankOffset = i;
                            else
                                player.RankIndex = i;
                        }

                        FactionItems = new List<FactionItem>();

                        if (version >= 2)
                        {
                            var factionItemCount = reader.ReadEncodedInt();

                            for (var i = 0; i < factionItemCount; ++i)
                            {
                                var factionItem = new FactionItem(reader, m_Faction);

                                Timer.DelayCall(factionItem.CheckAttach); // sandbox attachment
                            }
                        }

                        Traps = new List<BaseFactionTrap>();

                        if (version >= 3)
                        {
                            var factionTrapCount = reader.ReadEncodedInt();

                            for (var i = 0; i < factionTrapCount; ++i)
                                if (reader.ReadItem() is BaseFactionTrap trap && !trap.CheckDecay())
                                    Traps.Add(trap);
                        }

                        break;
                    }
            }

            if (version < 1)
                Election = new Election(m_Faction);
        }
Example #15
0
        private static void EventSink_Speech(SpeechEventArgs e)
        {
            Mobile from = e.Mobile;

            // jakob, added 2 new commands
            if (e.Speech.ToLower().IndexOf("i wish to appoint a deputy commander") > -1)
            {
                Faction faction = Faction.Find(from);
                if (faction != null && faction.IsCommander(from) && !faction.IsDeputyCommander(from))
                {
                    faction.BeginAppointDeputyCommander(from);
                }
            }
            else if (e.Speech.ToLower().IndexOf("i wish to demote the deputy commander") > -1)
            {
                Faction faction = Faction.Find(from);
                if (faction != null && faction.IsCommander(from) && !faction.IsDeputyCommander(from) && faction.DeputyCommander != null)
                {
                    faction.DeputyCommander = null;
                    from.SendMessage("You have fired the deputy commander.");
                }
            }
            // Kamron, added this
            else if (e.Speech.ToLower().IndexOf("i wish to renew my spirit") > -1)
            {
                PlayerState ps = PlayerState.Find(from);
                if (ps != null && from is PlayerMobile)
                {
                    PlayerMobile pm = (PlayerMobile)from;

                    if (ps.KillPoints <= 1)
                    {
                        from.SendMessage("Your spirit cannot be cleansed.");
                    }
                    else if (Faction.InSkillLoss(pm))
                    {
                        ps.KillPoints--;
                        Faction.ClearSkillLoss(pm);
                        from.SendMessage("You cleanse your spirit and remove your sins.");
                    }
                    else
                    {
                        from.SendMessage("Your spirit does not need cleansing.");
                    }
                }
            }
            // end


            int[] keywords = e.Keywords;

            for (int i = 0; i < keywords.Length; ++i)
            {
                switch (keywords[i])
                {
                case 0x00E4:                         // *i wish to access the city treasury*
                {
                    Town town = Town.FromRegion(from.Region);

                    if (town == null || !town.IsFinance(from) || !from.Alive)
                    {
                        break;
                    }

                    if (FactionGump.Exists(from))
                    {
                        from.SendLocalizedMessage(1042160);                                   // You already have a faction menu open.
                    }
                    else if (town.Owner != null && from is PlayerMobile)
                    {
                        from.SendGump(new FinanceGump((PlayerMobile)from, town.Owner, town));
                    }

                    break;
                }

                case 0x0ED:                         // *i am sheriff*
                {
                    Town town = Town.FromRegion(from.Region);

                    if (town == null || !town.IsSheriff(from) || !from.Alive)
                    {
                        break;
                    }

                    if (FactionGump.Exists(from))
                    {
                        from.SendLocalizedMessage(1042160);                                   // You already have a faction menu open.
                    }
                    else if (town.Owner != null)
                    {
                        from.SendGump(new SheriffGump((PlayerMobile)from, town.Owner, town));
                    }

                    break;
                }

                case 0x00EF:                         // *you are fired*
                {
                    Town town = Town.FromRegion(from.Region);

                    if (town == null)
                    {
                        break;
                    }

                    if (town.IsFinance(from) || town.IsSheriff(from))
                    {
                        town.BeginOrderFiring(from);
                    }

                    break;
                }

                case 0x00E5:                         // *i wish to resign as finance minister*
                {
                    PlayerState pl = PlayerState.Find(from);

                    if (pl != null && pl.Finance != null)
                    {
                        pl.Finance.Finance = null;
                        from.SendLocalizedMessage(1005081);                                   // You have been fired as Finance Minister
                    }

                    break;
                }

                case 0x00EE:                         // *i wish to resign as sheriff*
                {
                    PlayerState pl = PlayerState.Find(from);

                    if (pl != null && pl.Sheriff != null)
                    {
                        pl.Sheriff.Sheriff = null;
                        from.SendLocalizedMessage(1010270);                                   // You have been fired as Sheriff
                    }

                    break;
                }

                case 0x00E9:                         // *what is my faction term status*
                {
                    PlayerState pl = PlayerState.Find(from);

                    if (pl != null && pl.IsLeaving)
                    {
                        if (Faction.CheckLeaveTimer(from))
                        {
                            break;
                        }

                        TimeSpan remaining = (pl.Leaving + Faction.LeavePeriod) - DateTime.Now;

                        if (remaining.TotalDays >= 1)
                        {
                            from.SendLocalizedMessage(1042743, remaining.TotalDays.ToString("N0"));                                         // Your term of service will come to an end in ~1_DAYS~ days.
                        }
                        else if (remaining.TotalHours >= 1)
                        {
                            from.SendLocalizedMessage(1042741, remaining.TotalHours.ToString("N0"));                                         // Your term of service will come to an end in ~1_HOURS~ hours.
                        }
                        else
                        {
                            from.SendLocalizedMessage(1042742);                                       // Your term of service will come to an end in less than one hour.
                        }
                    }
                    else if (pl != null)
                    {
                        from.SendLocalizedMessage(1042233);                                   // You are not in the process of quitting the faction.
                    }

                    break;
                }

                case 0x00EA:                         // *message faction*
                {
                    Faction faction = Faction.Find(from);

                    if (faction == null || !faction.IsCommander(from))
                    {
                        break;
                    }

                    if (from.AccessLevel == AccessLevel.Player && !faction.FactionMessageReady)
                    {
                        from.SendLocalizedMessage(1010264);                                   // The required time has not yet passed since the last message was sent
                    }
                    else
                    {
                        faction.BeginBroadcast(from);
                    }

                    break;
                }

                case 0x00EC:                         // *showscore*
                {
                    PlayerState pl = PlayerState.Find(from);

                    if (pl != null)
                    {
                        Timer.DelayCall(TimeSpan.Zero, new TimerStateCallback(ShowScore_Sandbox), pl);
                    }

                    break;
                }                         /*
                                           * case 0x0178: // i honor your leadership
                                           * {
                                           *    Faction faction = Faction.Find( from );
                                           *
                                           *    if ( faction != null )
                                           *            faction.BeginHonorLeadership( from );
                                           *
                                           *    break;
                                           * } */
                }
            }
        }