示例#1
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);
        }
示例#2
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));
        }
示例#3
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);
        }
示例#4
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);
                    }
                });
            }
        }
示例#5
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);
        }
示例#6
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.
            }
        }
        public Group_ElectionViewModel(Election election, Guid?userId)
        {
            if (election != null)
            {
                Id               = election.Id;
                Title            = election.Title;
                Stage            = (ElectionStage)election.Stage;
                Quorum           = election.Quorum;
                Turnout          = election.Turnout;
                GroupModersCount = election.Group.ModeratorsCount;
                About            = new Group_Election_AboutViewModel(election);

                GroupMember gm = null;
                if (userId.HasValue && election.GroupId.HasValue)
                {
                    gm = GroupService.UserInGroup(userId.Value, election.GroupId.Value);
                }

                IEnumerable <Candidate> candidates = election.Candidates.Where(x => x.Petition != null).OrderByDescending(x => x.Petition.Signers.Count);
                candidates = candidates.Union(election.Candidates.Where(x => x.Petition == null));
                if (election.Stage != (byte)ElectionStage.Agitation)
                {
                    candidates = candidates.Where(x => x.Status == (byte)CandidateStatus.Confirmed);
                }
                Candidates = candidates.Select(x => new Group_Election_CandidateViewModel(x, gm)).ToList();
                Winners    = election.Candidates
                             .Where(x => x.Status == (byte)CandidateStatus.Winner)
                             .OrderByDescending(x => x.Electorate.Count)
                             .Select(x => new Group_Election_CandidateViewModel(x, gm))
                             .ToList();

                switch (Stage)
                {
                case ElectionStage.Agitation: ElectionCandidates = new Group_ElectionCandidatesViewModel(election, userId); break;

                case ElectionStage.Voting: ElectionVoting = new Group_ElectionVotingViewModel(election, userId); break;
                }
            }
            else
            {
                Candidates         = new List <Group_Election_CandidateViewModel>();
                Winners            = new List <Group_Election_CandidateViewModel>();
                About              = new Group_Election_AboutViewModel();
                ElectionCandidates = new Group_ElectionCandidatesViewModel();
                ElectionVoting     = new Group_ElectionVotingViewModel();
            }

            if (UserContext.Current != null)
            {
                var candidate = Candidates.FirstOrDefault(x => x.UserId == UserContext.Current.Id);
                if (candidate != null)
                {
                    IsCandidate = true;
                    CandidateId = candidate.Id;
                }
                else
                {
                    CandidateId = null;
                }
            }
        }