Exemple #1
0
        public CityElection(CityLoyaltySystem city, GenericReader reader)
        {
            City       = city;
            Candidates = new List <BallotEntry>();

            int version = reader.ReadInt();

            ElectionEnded    = reader.ReadBool();
            AutoPickGovernor = reader.ReadDateTime();

            int c = reader.ReadInt();

            StartTimes = new DateTime[c];
            for (int i = 0; i < c; i++)
            {
                DateTime time = reader.ReadDateTime();

                if (time < DateTime.Now && ElectionEnded)
                {
                    time = new DateTime(time.Year + 1, time.Month, time.Day);
                }

                StartTimes[i] = time;
            }

            c = reader.ReadInt();
            for (int i = 0; i < c; i++)
            {
                BallotEntry entry = new BallotEntry(reader);
                if (entry.Player != null)
                {
                    Candidates.Add(entry);
                }
            }
        }
Exemple #2
0
        public override void OnResponse(RelayInfo info)
        {
            if (info.ButtonID == 1)
            {
                BaseGump.SendGump(new CityStoneGump(User, City));
            }
            else if (info.ButtonID == 2)
            {
                City.Election.TryWithdraw(User);
            }
            else if (info.ButtonID >= 100)
            {
                int id = info.ButtonID - 100;

                if (id >= 0 && id < Candidates.Count)
                {
                    BallotEntry entry = Candidates[id];

                    if (entry.Player != null)
                    {
                        City.Election.TryVote(User, entry.Player);
                    }
                }
            }
        }
Exemple #3
0
        public bool TryEndorse(PlayerMobile pm, PlayerMobile nominee)
        {
            if (pm.Young)
            {
                pm.SendMessage("Young players cannot endorose an nominee!");
            }
            else if (!City.IsCitizen(pm))
            {
                pm.SendLocalizedMessage(1153893); // You must be a citizen of this City to endorse a nominee for the ballot!
            }
            else
            {
                Account a = pm.Account as Account;

                for (int i = 0; i < a.Length; i++)
                {
                    Mobile m = a[i];

                    if (!(m is PlayerMobile))
                    {
                        continue;
                    }

                    BallotEntry ballot = Candidates.FirstOrDefault(entry => entry.Endorsements.Contains(m as PlayerMobile));

                    if (m is PlayerMobile && ballot != null)
                    {
                        pm.SendLocalizedMessage(1153892); // A character from this account has already endorsed a nominee!
                        return(false);
                    }

                    BallotEntry ballot2 = Candidates.FirstOrDefault(entry => entry.Player == m);

                    if (m is PlayerMobile && ballot2 != null)
                    {
                        pm.SendLocalizedMessage(1153912); // A character from this account is currently nominated for candidacy and cannot offer an endorsement.
                        return(false);
                    }
                }

                BallotEntry pentry = Candidates.FirstOrDefault(e => e.Player == nominee);

                if (pentry != null)
                {
                    //<CENTER>Are you sure you wish to endorse this nominee? All endorsements are final and cannot be changed!</CENTER>
                    pm.SendGump(new ConfirmCallbackGump(pm, null, 1154091, pentry, null, (m, o) =>
                    {
                        BallotEntry e = o as BallotEntry;
                        e.Endorsements.Add(m as PlayerMobile);
                        m.PrivateOverheadMessage(Network.MessageType.Regular, 0x3B2, 1153913, m.NetState); // *You etch your endorsement for the nominee into the stone*
                    }));

                    return(true);
                }
            }

            return(false);
        }
Exemple #4
0
        public override void AddGumpLayout()
        {
            AddBackground(0, 0, 600, 400, 5054);
            AddHtmlLocalized(10, 12, 200, 20, 1153914, 0xFFFF, false, false); // Candidate List

            int page = 0;

            AddPage(page);

            AddHtmlLocalized(10, 40, 120, 20, 1153915, 0xFFFF, false, false);  // Cast Vote
            AddHtmlLocalized(130, 40, 170, 20, 1153908, 0xFFFF, false, false); // Name
            AddHtmlLocalized(300, 40, 170, 20, 1153909, 0xFFFF, false, false); // Guild
            AddHtmlLocalized(470, 40, 80, 20, 1153916, 0xFFFF, false, false);  // Standing

            AddButton(10, 368, 4014, 4016, 1, GumpButtonType.Reply, 0);
            AddHtmlLocalized(45, 368, 150, 16, 1149777, 0xFFFF, false, false); // MAIN MENU

            AddButton(540, 368, 4017, 4019, 2, GumpButtonType.Reply, 0);
            AddHtmlLocalized(485, 368, 150, 16, 1153910, 0xFFFF, false, false); // Withdraw

            page++;
            AddPage(page);
            int pageIndex = 0;

            Candidates = new List <BallotEntry>(City.Election.Candidates.Where(e => e.Endorsements.Count > 0));

            for (int i = 0; i < Candidates.Count; i++)
            {
                BallotEntry entry = Candidates[i];

                Guild g = entry.Player == null ? null : entry.Player.Guild as Guild;

                AddButton(10, 70 + (pageIndex * 25), 4002, 4004, i + 100, GumpButtonType.Reply, 0);
                AddHtml(130, 70 + (pageIndex * 25), 200, 20, String.Format("<basefont color=#EEE8AA>{0}", entry.Player == null ? "Unknown" : entry.Player.Name), false, false);
                AddHtml(300, 70 + (pageIndex * 25), 200, 20, String.Format("<basefont color=#EEE8AA>{0}", g != null ? g.Name : ""), false, false);
                AddHtml(470, 70 + (pageIndex * 25), 200, 20, String.Format("<basefont color=#EEE8AA>{0}%", City.Election.GetStanding(entry).ToString("F1", System.Globalization.CultureInfo.InvariantCulture)), false, false);

                pageIndex++;

                if (pageIndex >= 10 && i < Candidates.Count - 1)
                {
                    pageIndex = 0;
                    page++;

                    AddHtml(535, 346, 100, 16, "<basefont color=#FFFFFF>NEXT", false, false);
                    AddButton(574, 348, 5601, 5605, 0, GumpButtonType.Page, page);

                    AddPage(page);
                }

                if (i > 10)
                {
                    AddHtml(32, 346, 100, 16, "<basefont color=#FFFFFF>BACK", false, false);
                    AddButton(10, 348, 5603, 5607, 0, GumpButtonType.Page, page - 1);
                }
            }
        }
Exemple #5
0
        public void OnRejectOffice(PlayerMobile pm)
        {
            BallotEntry entry = Candidates.FirstOrDefault(c => c.Player == pm);

            if (entry != null)
            {
                Candidates.Remove(entry);
            }

            AutoPickGovernor = DateTime.UtcNow + TimeSpan.FromDays(Utility.RandomMinMax(2, 4));
        }
Exemple #6
0
        public bool TryNominate(PlayerMobile pm)
        {
            CityLoyaltyEntry pentry = City.GetPlayerEntry <CityLoyaltyEntry>(pm);

            if (pm.Young)
            {
                pm.SendMessage("Young players cannot be nominated for the ballot!");
            }
            else if (!City.IsCitizen(pm) || pentry == null)
            {
                pm.SendLocalizedMessage(1153890); // You must be a citizen of this City to nominate yourself for the ballot!
            }
            else if (City.GetLoyaltyRating(pm) < LoyaltyRating.Adored)
            {
                pm.SendLocalizedMessage(1153891); // You must at least be adored within the City to nominate yourself for the ballot.
            }
            else
            {
                Account a = pm.Account as Account;
                for (int i = 0; i < a.Length; i++)
                {
                    Mobile m = a[i];

                    if (!(m is PlayerMobile))
                    {
                        continue;
                    }

                    BallotEntry ballot = Candidates.FirstOrDefault(entry => entry.Player == m);

                    if (ballot != null && m is PlayerMobile)
                    {
                        pm.SendLocalizedMessage(ballot.Endorsements.Count > 0 ? 1153917 : 1153889);  // A character from this account is currently endorsed for Candidacy and cannot be nominated.                                                                      // A character from this account has already been nominated to run for office.
                        return(false);                                                               // A character from this account has already been nominated to run for office.
                    }

                    ballot = Candidates.FirstOrDefault(entry => entry.Endorsements.Contains(m));

                    if (ballot != null && m is PlayerMobile)
                    {
                        pm.SendLocalizedMessage(1153892); // A character from this account has already endorsed a nominee!
                        return(false);
                    }
                }

                Candidates.Add(new BallotEntry(pm, pentry.Love, pentry.Hate));
                pm.PrivateOverheadMessage(Network.MessageType.Regular, 0x3B2, 1153905, pm.NetState); // *You etch your name into the stone*
                pm.SendLocalizedMessage(1154087);                                                    // You have 24 hours to get your nomination endorsed. If you do not get an endorsement within that period you will need to re-nominate yourself.

                return(true);
            }

            return(false);
        }
Exemple #7
0
        public override void AddGumpLayout()
        {
            AddBackground(0, 0, 600, 400, 5054);
            AddHtmlLocalized(10, 12, 200, 20, 1153906, 0xFFFF, false, false); // Current Nominees

            int page = 0;

            AddPage(page);

            AddHtmlLocalized(10, 40, 120, 20, 1153907, 0xFFFF, false, false);  // Endorse
            AddHtmlLocalized(130, 40, 170, 20, 1153908, 0xFFFF, false, false); // Name
            AddHtmlLocalized(300, 40, 170, 20, 1153909, 0xFFFF, false, false); // Guild

            AddButton(10, 368, 4014, 4016, 1, GumpButtonType.Reply, 0);
            AddHtmlLocalized(45, 368, 150, 16, 1149777, 0xFFFF, false, false); // MAIN MENU

            AddButton(540, 368, 4017, 4019, 2, GumpButtonType.Reply, 0);
            AddHtmlLocalized(485, 368, 150, 16, 1153910, 0xFFFF, false, false); // Withdraw

            page++;
            AddPage(page);
            int pageIndex = 0;

            for (int i = 0; i < City.Election.Candidates.Count; i++)
            {
                BallotEntry entry = City.Election.Candidates[i];

                Guild g = entry.Player == null ? null : entry.Player.Guild as Guild;

                AddButton(10, 70 + (pageIndex * 25), 4002, 4004, i + 100, GumpButtonType.Reply, 0);
                AddHtml(130, 70 + (pageIndex * 25), 200, 20, String.Format("<basefont color=#EEE8AA>{0}", entry.Player == null ? "Unknown" : entry.Player.Name), false, false);
                AddHtml(300, 70 + (pageIndex * 25), 200, 20, String.Format("<basefont color=#EEE8AA>{0}", g != null ? g.Name : ""), false, false);
                pageIndex++;

                if (pageIndex >= 10 && i < City.Election.Candidates.Count - 1)
                {
                    pageIndex = 0;
                    page++;

                    AddHtml(535, 346, 100, 16, "<basefont color=#FFFFFF>NEXT", false, false);
                    AddButton(574, 348, 5601, 5605, 0, GumpButtonType.Page, page);

                    AddPage(page);
                }

                if (i > 10)
                {
                    AddHtml(32, 346, 100, 16, "<basefont color=#FFFFFF>BACK", false, false);
                    AddButton(10, 348, 5603, 5607, 0, GumpButtonType.Page, page - 1);
                }
            }
        }
Exemple #8
0
        public void OnTick()
        {
            foreach (DateTime dt in StartTimes)
            {
                if (dt.Year == DateTime.Now.Year && DateTime.Now.Month == dt.Month && DateTime.Now.Day > 14 && !ElectionEnded)
                {
                    EndElection();
                }
                else if (dt.Year == DateTime.Now.Year && DateTime.Now.Month == dt.Month && DateTime.Now.Day == dt.Day && ElectionEnded)
                {
                    StartNewElection();
                }
            }

            if (City.Governor == null && AutoPickGovernor != DateTime.MinValue && DateTime.UtcNow > AutoPickGovernor)
            {
                if (City.GovernorElect != null)
                {
                    if (Candidates.Count > 0)
                    {
                        BallotEntry entry = Candidates.FirstOrDefault(c => c.Player == City.GovernorElect);

                        if (entry != null)
                        {
                            Candidates.Remove(entry);
                        }
                    }

                    City.GovernorElect = null;
                }

                if (Candidates.Count > 0)
                {
                    Candidates.Sort();
                    City.GovernorElect = Candidates[0].Player;
                }

                AutoPickGovernor = DateTime.MinValue;
            }

            if (CanNominate())
            {
                Candidates.ForEach(entry =>
                {
                    if (entry.TimeOfNomination + TimeSpan.FromHours(NominationDeadline) < DateTime.UtcNow && entry.Endorsements.Count == 0)
                    {
                        Candidates.Remove(entry);
                    }
                });
            }
        }
Exemple #9
0
        public double GetStanding(BallotEntry entry)
        {
            if (Candidates.Contains(entry))
            {
                if (entry.Votes.Count <= 0)
                {
                    return(0.0);
                }

                return((entry.Votes.Count / GetTotalVotes()) * 100);
            }

            return(0.0);
        }
Exemple #10
0
        public bool TryVote(PlayerMobile voter, PlayerMobile candidate)
        {
            if (!CanVote())
            {
                voter.SendLocalizedMessage(1153919); // The stone is not currently accepting votes.
            }
            else if (voter.Young)
            {
                voter.SendMessage("Young players cannot vote in a city election!");
            }
            else if (!City.IsCitizen(voter))
            {
                voter.SendLocalizedMessage(1153894); // You must be a citizen of this City to vote!
            }
            else if (City.GetLoyaltyRating(voter) < LoyaltyRating.Respected)
            {
                voter.SendLocalizedMessage(1154579); // You must be at least respected within the city to vote.
            }
            else
            {
                Account a = voter.Account as Account;

                for (int i = 0; i < a.Length; i++)
                {
                    Mobile m = a[i];

                    if (m is PlayerMobile && Candidates.FirstOrDefault(e => e.Votes.Contains(m)) != null)
                    {
                        voter.SendLocalizedMessage(1153922); // This account has already cast a vote in this election. You may only vote once.
                        return(false);
                    }
                }

                BallotEntry pentry = Candidates.FirstOrDefault(e => e.Player == candidate);

                if (pentry != null)
                {
                    //<CENTER>Are you sure you wish to cast your vote for this candidate? All votes are final and cannot be changed!</CENTER>
                    voter.SendGump(new ConfirmCallbackGump(voter, null, 1153921, pentry, null, (m, o) =>
                    {
                        BallotEntry e = o as BallotEntry;
                        e.Votes.Add(voter);
                        m.PrivateOverheadMessage(Network.MessageType.Regular, 0x3B2, 1153923, voter.NetState); // *You etch your vote into the stone*
                    }));
                }
            }

            return(false);
        }
Exemple #11
0
        public void TryWithdraw(PlayerMobile pm)
        {
            BallotEntry entry = Candidates.FirstOrDefault(e => e.Player == pm);

            if (entry != null)
            {
                //Are you sure you wish to withdrawal?
                pm.SendGump(new ConfirmCallbackGump(pm, null, 1153918, entry, null, (m, o) =>
                {
                    BallotEntry e = (BallotEntry)o;

                    if (Candidates.Contains(e))
                    {
                        Candidates.Remove(e);
                        m.PrivateOverheadMessage(Network.MessageType.Regular, 0x3B2, 1153911, m.NetState); // *You smudge your name off the stone*
                    }
                }));
            }
            else
            {
                pm.SendLocalizedMessage(1153924); // You are not currently on any ballot to withdraw from.
            }
        }