Ejemplo n.º 1
0
        private void ComputeCommander(int race)
        {
            var candidates = application.DB.CommanderCandidates.Find(Query <CommanderCandidate> .EQ(c => c.race, race)).ToArray();
            int maxVoices  = -1;
            CommanderCandidate maxVoicesCandidate = null;

            for (int i = 0; i < candidates.Length; i++)
            {
                if (candidates[i].voices > maxVoices)
                {
                    maxVoices          = candidates[i].voices;
                    maxVoicesCandidate = candidates[i];
                }
            }

            if (maxVoicesCandidate != null)
            {
                log.InfoFormat("set commander from voting results = {0}", maxVoicesCandidate.characterID);
                //change race status in race commands service
                application.RaceCommands.SetRaceStatus(race, RaceStatus.Commander, maxVoicesCandidate.login, maxVoicesCandidate.gameRefID, maxVoicesCandidate.characterID);

                //change race status at player character
                application.Players.SetRaceStatus(maxVoicesCandidate.gameRefID, maxVoicesCandidate.characterID, (int)RaceStatus.Commander);
                log.InfoFormat("set race = {0} commander: {1} [green]", (Race)(byte)race, maxVoicesCandidate.login);

                //change event to clients about new commander
                application.Clients.SendNewCommanderElected(race, maxVoicesCandidate.login);

                //send notification to commander with greatings

                Hashtable notificationData = new Hashtable {
                    { (int)SPC.Race, race }
                };
                var notification = application.Notifications.Create(Guid.NewGuid().ToString(),
                                                                    "s_note_new_commander",
                                                                    notificationData, ServerClientCommon.NotficationRespondAction.Delete, ServerClientCommon.NotificationSourceServiceType.Election,
                                                                    ServerClientCommon.NotificationSubType.Unknown);
                application.Notifications.SetNotificationToCharacter(maxVoicesCandidate.characterID, notification);
            }
        }
Ejemplo n.º 2
0
 public bool TryGetCandidate(string characterID, out CommanderCandidate candidate)
 {
     return(mCandidates.TryGetValue(characterID, out candidate));
 }
Ejemplo n.º 3
0
 public bool TryAddCandidate(CommanderCandidate candidate)
 {
     return(mCandidates.TryAdd(candidate.characterID, candidate));
 }
Ejemplo n.º 4
0
 private void AddCandidate(CommanderCandidate candidate)
 {
     application.DB.CommanderCandidates.Save(candidate);
     mCache.TryAddCandidate(candidate);
 }
Ejemplo n.º 5
0
        public bool AddCandidate(string login, string gameRefID, string characterID)
        {
            if (!electionInfo.registrationStarted)
            {
                log.Info("error registration not allowed");
                return(false);
            }
            if (ExistCandidate(characterID))
            {
                log.Info("error candidate already exists");
                return(false);
            }

            var player = application.Players.GetExistingPlayer(gameRefID);

            if (player == null || player.Data == null)
            {
                log.Info("AddCandidate error: player not found");
                return(false);
            }

            var character = player.Data.GetCharacter(characterID);

            if (character == null)
            {
                log.Info("AddCandidate error: character not found");
                return(false);
            }

            int level = application.leveling.LevelForExp(character.Exp);

            if (level < LEVEL_FOR_CANDIDATE)
            {
                log.InfoFormat("AddCandidate error - level is low = {0}", level);
                return(false);
            }

            var guild = application.Guilds.GetGuild(characterID);

            if (guild == null)
            {
                log.InfoFormat("AddCandidate error - guild for candidate not founded");
                return(false);
            }

            var store = application.Stores.GetOrCreatePlayerStore(login, gameRefID, characterID);

            if (store == null)
            {
                log.InfoFormat("AddCandidate error - store for candidate not founded");
                return(false);
            }

            if (store.credits < CREDITS_FOR_CANDIDATE)
            {
                log.InfoFormat("AddCandidate error - credits not enough");
                return(false);
            }

            //remove 500 gold
            store.RemoveCredits(CREDITS_FOR_CANDIDATE);

            CommanderCandidate newCandidate = new CommanderCandidate {
                characterID = characterID, gameRefID = gameRefID, login = login, race = character.Race, voices = 0, guildName = guild.name
            };

            //application.DB.CommanderCandidates.Save(newCandidate);
            AddCandidate(newCandidate);

            log.InfoFormat("candidate registration successfull");
            return(true);
        }