예제 #1
0
 /// <summary>
 /// Finds a connected players index based on their player id
 /// </summary>
 /// <param name="playerID">The id of the player to find</param>
 /// <returns>The players index if found; otherwise, returns -1</returns>
 public static TcpClientIdentifier FindTcpID(string playerID)
 {
     rwLock.EnterReadLock();
     try
     {
         int index = playerIDToTcpIDList.IndexOfKey(playerID);
         if (index > -1)
         {
             return(playerIDToTcpIDList.ValueByIndex(index));
         }
         else
         {
             return(null);
         }
     }
     finally
     {
         rwLock.ExitReadLock();
     }
 }
예제 #2
0
        public static void GuildStepDown(Client client)
        {
            if (string.IsNullOrEmpty(client.Player.GuildName))
            {
                Messenger.PlayerMsg(client, "You are not in a guild.", Text.BrightRed);
                return;
            }
            bool stepDown = false;

            if (client.Player.GuildAccess > Enums.GuildRank.Member)
            {
                stepDown = true;
            }

            int index = -1;

            using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Players))
            {
                ListPair <string, int> members = DataManager.Players.PlayerDataManager.LoadGuild(dbConnection.Database, client.Player.GuildName);

                index = members.IndexOfKey(client.Player.CharID);

                if (stepDown)
                {
                    DataManager.Players.PlayerDataManager.SetGuildAccess(dbConnection.Database, members.KeyByIndex(index), (int)client.Player.GuildAccess - 1);
                    Messenger.PlayerMsg(client, "You have stepped down from your position in the guild.", Text.Blue);
                }
                else
                {
                    DataManager.Players.PlayerDataManager.RemoveGuildMember(dbConnection.Database, client.Player.CharID);
                    Messenger.PlayerMsg(client, "You have left your guild.", Text.Blue);
                }
            }

            if (stepDown)
            {
                client.Player.GuildAccess = (Enums.GuildRank)((int)client.Player.GuildAccess - 1);
            }
            else
            {
                client.Player.GuildName   = "";
                client.Player.GuildAccess = Enums.GuildRank.None;
            }
            //send the guild access data to all
            Messenger.SendPlayerGuild(client);

            //send the update to all possible guild members
            if (index > -1)
            {
                Messenger.SendFullGuildUpdate(client.Player.GuildName);
            }
        }
예제 #3
0
        public static Party FindParty(string partyID)
        {
            Party party = null;

            rwLock.EnterReadLock();
            try {
                int partyIndex = parties.IndexOfKey(partyID);
                if (partyIndex > -1)
                {
                    party = parties.ValueByIndex(partyIndex);
                }
            } finally {
                rwLock.ExitReadLock();
            }
            return(party);
        }
예제 #4
0
        private IEnumerable <Client> GetMapClients(ListPair <IMap, List <Client> > clientCollection, IMap map)
        {
            int mapIndex = clientCollection.IndexOfKey(map);

            if (mapIndex > -1)
            {
                List <Client> clients = clientCollection.ValueByIndex(mapIndex);
                foreach (Client client in clients)
                {
                    yield return(client);
                }
            }
            else
            {
                List <Client> clients = new List <Client>();
                foreach (Client client in map.GetClients())
                {
                    clients.Add(client);
                    yield return(client);
                }
                clientCollection.Add(map, clients);
            }
        }
예제 #5
0
 private IEnumerable<Client> GetMapClients(ListPair<IMap, List<Client>> clientCollection, IMap map)
 {
     int mapIndex = clientCollection.IndexOfKey(map);
     if (mapIndex > -1) {
         List<Client> clients = clientCollection.ValueByIndex(mapIndex);
         foreach (Client client in clients) {
             yield return client;
         }
     } else {
         List<Client> clients = new List<Client>();
         foreach (Client client in map.GetClients()) {
             clients.Add(client);
             yield return client;
         }
         clientCollection.Add(map, clients);
     }
 }
예제 #6
0
 private IEnumerable<IMap> GetBorderingMaps(ListPair<IMap, Object[]> borderingMapCollection, IMap centralMap)
 {
     int mapIndex = borderingMapCollection.IndexOfKey(centralMap);
     if (mapIndex > -1) {
         Object[] maps = borderingMapCollection.ValueByIndex(mapIndex);
         foreach (IMap map in maps) {
             if (map != null) {
                 yield return map;
             }
         }
     } else {
         Object[] maps = new object[9];
         for (int borderingMapID = 0; borderingMapID < 9; borderingMapID++) {
             if (MapManager.IsBorderingMapLoaded(centralMap, (Enums.MapID)borderingMapID)) {
                 IMap borderingMap = MapManager.RetrieveBorderingMap(centralMap, (Enums.MapID)borderingMapID, true);
                 if (borderingMap != null) {
                     maps[borderingMapID] = borderingMap;
                     yield return borderingMap;
                 }
             }
         }
         borderingMapCollection.Add(centralMap, maps);
     }
 }