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); } }
public Inventory(ListPair<int, DataManager.Characters.InventoryItem> loadedInventory) { items = new ListPair<int, InventoryItem>(); for (int i = 0; i < loadedInventory.Count; i++) { items.Add(loadedInventory.KeyByIndex(i), new InventoryItem(loadedInventory.ValueByIndex(i))); } }
public void LoadShop(string[] parse) { pnlShopList.Visible = false; pnlShopEditor.Visible = true; this.Size = new System.Drawing.Size(pnlShopEditor.Width, pnlShopEditor.Height); txtName.Text = parse[2]; txtJoinSay.Text = parse[3]; txtLeaveSay.Text = parse[4]; shopItemList = new ListPair <int, Client.Logic.Shops.ShopItem>(); for (int i = 0; i < MaxInfo.MAX_TRADES; i++) { Shops.ShopItem shopItem = new Shops.ShopItem(); shopItem.GiveItem = parse[5 + i * 3].ToInt(); shopItem.GiveValue = parse[6 + i * 3].ToInt(); shopItem.GetItem = parse[7 + i * 3].ToInt(); shopItemList.Add(i, shopItem); } //if (lbxShopItems.SelectedItems.Count > 0) { //lbxShopItems.SelectItem(lbxShopItems.SelectedItems[0].TextIdentifier); //} RefreshShopItemList(); lbxShopItems.SelectItem(0); btnEdit.Text = "Edit"; }
public void AddTournament(Tournament tournament) { if (tournaments.Keys.Contains(tournament.ID) == false) { tournaments.Add(tournament.ID, tournament); } }
public ThreadedTimer CreateTimer(string timerID, string methodName, int interval, bool autoStart, bool autoStop, params object[] param) { ThreadedTimer timer = new ThreadedTimer(methodName, interval, autoStart, autoStop, param); timers.Add(timerID, timer); return(timer); }
public void AddGnpClient(TClientID clientID, GnpClient gnpClient) { if (clients.ContainsKey(clientID) == false) { // If the collection does not contain a client with the same ID, add it clients.Add(clientID, gnpClient); } }
public Inventory(ListPair <int, DataManager.Characters.InventoryItem> loadedInventory) { items = new ListPair <int, InventoryItem>(); for (int i = 0; i < loadedInventory.Count; i++) { items.Add(loadedInventory.KeyByIndex(i), new InventoryItem(loadedInventory.ValueByIndex(i))); } }
public static void CreateNewParty(Client leader) { PacketHitList hitlist = null; PacketHitList.MethodStart(ref hitlist); List <string> partyIDs = new List <string>(); using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Players)) { partyIDs = LoadPartyIDList(dbConnection.Database); } if (leader.Player.PartyID == null) { string partyID = null; rwLock.EnterWriteLock(); try { while (true) { string tempID = Security.PasswordGen.Generate(10, 15); if (partyIDs.Contains(tempID) == false) { partyID = tempID; break; } } Party party = new Party(partyID, leader); leader.Player.PartyID = partyID; parties.Add(partyID, party); } finally { rwLock.ExitWriteLock(); } leader.Player.AddExpKitModule(new AvailableExpKitModule(Enums.ExpKitModules.Party, true)); PacketBuilder.AppendPartyMemberDataFor(leader, hitlist, 0); hitlist.AddPacket(leader, PacketBuilder.CreateChatMsg("You have created a new party!", Text.BrightGreen)); } else { hitlist.AddPacket(leader, PacketBuilder.CreateChatMsg("You are already in a party!", Text.BrightRed)); } PacketHitList.MethodEnded(ref hitlist); }
public IntPtr LoadAudioStreamFromUrl(string url, string cacheDirectory) { lock (audioUrlStreamLoaderLockObject) { lock (audioDataCache) { if (audioDataCache.ContainsKey(url)) { return(audioDataCache[url].AudioStreamPointer); } } AudioDataCache dataCache = new AudioDataCache(); dataCache.CachePath = cacheDirectory + Path.GetFileName(url); dataCache.CacheStream = new FileStream(dataCache.CachePath + ".tmp", FileMode.Create, FileAccess.Write); dataCache.CallbackDelegate = new DownloadCallbackDelegate(AudioDownloadCallback); IntPtr urlPtr = Marshal.StringToHGlobalUni(url); lock (audioDataCache) { if (audioDataCache.ContainsKey(url) == false) { audioDataCache.Add(url, dataCache); } else { dataCache.CallbackDelegate = null; if (urlPtr != IntPtr.Zero) { Marshal.FreeHGlobal(urlPtr); urlPtr = IntPtr.Zero; } } } dataCache.AudioStreamPointer = Bass.BASS_StreamCreateURL(url, 0, 0, dataCache.CallbackDelegate, urlPtr); if (dataCache.AudioStreamPointer == IntPtr.Zero) { // Uh oh! We couldn't play the sfx stream! lock (audioDataCache) { if (audioDataCache.ContainsKey(url)) { audioDataCache.RemoveAtKey(url); } if (urlPtr != IntPtr.Zero) { Marshal.FreeHGlobal(urlPtr); urlPtr = IntPtr.Zero; } } dataCache.CacheStream.Close(); File.Delete(dataCache.CachePath + ".tmp"); dataCache.CachePath = null; } return(dataCache.AudioStreamPointer); } }
public void Add(string connectionID, IPlayer player) { lock (lockObject) { if (!players.ContainsKey(connectionID)) { players.Add(connectionID, player); } else { players[connectionID] = player; } } }
public static void CreateAIInstance(string className, string aiType) { if (script != null) { if (NPCAIType.ContainsKey(aiType) == false) { Type type = script.GetType(className); IAICore instance = (IAICore)script.CreateInstance(className); AITypes.Add(className, type); AIInstances.Add(className, instance); NPCAIType.Add(aiType, className); //InvokeSub(className, "Init", Globals.mNetScript, Globals.mObjFactory, Globals.mIOTools, Globals.mDebug); } } }
/// <summary> /// Adds a player to the index list /// </summary> /// <param name="playerID">The id of the player to add</param> /// <param name="tcpID">The id of the tcp client to add</param> public static void AddPlayerToIndexList(string playerID, TcpClientIdentifier tcpID) { rwLock.EnterUpgradeableReadLock(); try { int index = playerIDToTcpIDList.IndexOfKey(playerID); if (index == -1) { rwLock.EnterWriteLock(); try { playerIDToTcpIDList.Add(playerID, tcpID); } finally { rwLock.ExitWriteLock(); } } } finally { rwLock.ExitUpgradeableReadLock(); } }
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); } }
public static ListPair<string, int> LoadGuild(MySql database, string guildName) { string query = "SELECT guild.CharID, guild.GuildAccess " + "FROM guild " + "WHERE guild.GuildName = \'" + guildName + "\';"; ListPair<string, int> guildMembers = new ListPair<string, int>(); List<DataColumnCollection> rows = database.RetrieveRows(query); if (rows != null) { for (int i = 0; i < rows.Count; i++) { guildMembers.Add(rows[i]["CharID"].ValueString, rows[i]["GuildAccess"].ValueString.ToInt()); } } return guildMembers; }
public void SaveCharacterData(DatabaseConnection dbConnection) { if (loaded && !SavingLocked) { dataLock.EnterWriteLock(); try { if (playerData.AvailableModules == null) { playerData.AvailableModules = ""; } PlayerDataManager.SavePlayerAvailableExpKitModules(dbConnection.Database, playerData); PlayerDataManager.SavePlayerCharacteristics(dbConnection.Database, playerData); PlayerDataManager.SavePlayerGuild(dbConnection.Database, playerData); PlayerDataManager.SavePlayerItemGenerals(dbConnection.Database, playerData); JobList.SaveJobList(dbConnection); //PlayerDataManager.SavePlayerJobList(dbConnection.Database, playerData); PlayerDataManager.SavePlayerLocation(dbConnection.Database, playerData); //PlayerDataManager.SavePlayerMissionBoardGenerals(dbConnection.Database, playerData); missionBoard.SaveMissionBoardData(); PlayerDataManager.SavePlayerMissionBoardMissions(dbConnection.Database, playerData); PlayerDataManager.SavePlayerMissionGenerals(dbConnection.Database, playerData); PlayerDataManager.SavePlayerStoryGenerals(dbConnection.Database, playerData); PlayerDataManager.SavePlayerStoryHelperStateSettings(dbConnection.Database, playerData); PlayerDataManager.SavePlayerStatistics(dbConnection.Database, playerData); // Save inventory ListPair <int, Characters.InventoryItem> updatedInventory = new ListPair <int, Characters.InventoryItem>(); for (int i = 1; i <= Inventory.Count; i++) { if (Inventory[i].Updated) { updatedInventory.Add(i, Inventory[i].BaseInventoryItem); Inventory[i].Updated = false; } } PlayerDataManager.SavePlayerInventoryUpdates(dbConnection.Database, CharID, updatedInventory); // Save bank ListPair <int, Characters.InventoryItem> updatedBank = new ListPair <int, Characters.InventoryItem>(); for (int i = 1; i <= Bank.Count; i++) { if (Bank[i].Updated) { updatedBank.Add(i, Bank[i].BaseInventoryItem); Bank[i].Updated = false; } } PlayerDataManager.SavePlayerBankUpdates(dbConnection.Database, CharID, updatedBank); // Save trigger events playerData.TriggerEvents.Clear(); for (int i = 0; i < triggerEvents.Count; i++) { PlayerDataTriggerEvent triggerEvent = new PlayerDataTriggerEvent(); triggerEvents[i].Save(triggerEvent); playerData.TriggerEvents.Add(triggerEvent); } PlayerDataManager.SavePlayerTriggerEvents(dbConnection.Database, playerData); // Save team for (int i = 0; i < team.Length; i++) { playerData.TeamMembers[i].RecruitIndex = team[i].RecruitIndex; playerData.TeamMembers[i].UsingTempStats = team[i].InTempMode; if (team[i].Loaded) { team[i].Save(dbConnection); } } PlayerDataManager.SavePlayerTeam(dbConnection.Database, playerData); IMap map = GetCurrentMap(); if (map != null && (map.MapType == Enums.MapType.Instanced || map.MapType == Enums.MapType.RDungeonMap || map.MapType == Enums.MapType.House)) { map.Save(); //mInstancedMapManager.SaveActiveMap(); } lock (mapsToDelete) { AI.AIProcessor.mapGC.AddMaps(mapsToDelete); mapsToDelete.Clear(); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Map: " + MapID + System.Environment.NewLine + ex.ToString()); } finally { dataLock.ExitWriteLock(); } } }
public void AddParameter(string paramID, string value) { parameters.Add(paramID, value); }
public void LoadShop(string[] parse) { pnlShopList.Visible = false; pnlShopEditor.Visible = true; this.Size = new System.Drawing.Size(pnlShopEditor.Width, pnlShopEditor.Height); txtName.Text = parse[2]; txtJoinSay.Text = parse[3]; txtLeaveSay.Text = parse[4]; shopItemList = new ListPair<int, Client.Logic.Shops.ShopItem>(); for (int i = 0; i < MaxInfo.MAX_TRADES; i++) { Shops.ShopItem shopItem = new Shops.ShopItem(); shopItem.GiveItem = parse[5 + i * 3].ToInt(); shopItem.GiveValue = parse[6 + i * 3].ToInt(); shopItem.GetItem = parse[7 + i * 3].ToInt(); shopItemList.Add(i, shopItem); } //if (lbxShopItems.SelectedItems.Count > 0) { //lbxShopItems.SelectItem(lbxShopItems.SelectedItems[0].TextIdentifier); //} RefreshShopItemList(); lbxShopItems.SelectItem(0); btnEdit.Text = "Edit"; }
public void SaveCharacterData(DatabaseConnection dbConnection) { if (loaded && !SavingLocked) { dataLock.EnterWriteLock(); try { if (playerData.AvailableModules == null) { playerData.AvailableModules = ""; } PlayerDataManager.SavePlayerAvailableExpKitModules(dbConnection.Database, playerData); PlayerDataManager.SavePlayerCharacteristics(dbConnection.Database, playerData); PlayerDataManager.SavePlayerGuild(dbConnection.Database, playerData); PlayerDataManager.SavePlayerItemGenerals(dbConnection.Database, playerData); JobList.SaveJobList(dbConnection); //PlayerDataManager.SavePlayerJobList(dbConnection.Database, playerData); PlayerDataManager.SavePlayerLocation(dbConnection.Database, playerData); //PlayerDataManager.SavePlayerMissionBoardGenerals(dbConnection.Database, playerData); missionBoard.SaveMissionBoardData(); PlayerDataManager.SavePlayerMissionBoardMissions(dbConnection.Database, playerData); PlayerDataManager.SavePlayerMissionGenerals(dbConnection.Database, playerData); PlayerDataManager.SavePlayerStoryGenerals(dbConnection.Database, playerData); PlayerDataManager.SavePlayerStoryHelperStateSettings(dbConnection.Database, playerData); PlayerDataManager.SavePlayerStatistics(dbConnection.Database, playerData); // Save inventory ListPair<int, Characters.InventoryItem> updatedInventory = new ListPair<int, Characters.InventoryItem>(); for (int i = 1; i <= Inventory.Count; i++) { if (Inventory[i].Updated) { updatedInventory.Add(i, Inventory[i].BaseInventoryItem); Inventory[i].Updated = false; } } PlayerDataManager.SavePlayerInventoryUpdates(dbConnection.Database, CharID, updatedInventory); // Save bank ListPair<int, Characters.InventoryItem> updatedBank = new ListPair<int, Characters.InventoryItem>(); for (int i = 1; i <= Bank.Count; i++) { if (Bank[i].Updated) { updatedBank.Add(i, Bank[i].BaseInventoryItem); Bank[i].Updated = false; } } PlayerDataManager.SavePlayerBankUpdates(dbConnection.Database, CharID, updatedBank); // Save trigger events playerData.TriggerEvents.Clear(); for (int i = 0; i < triggerEvents.Count; i++) { PlayerDataTriggerEvent triggerEvent = new PlayerDataTriggerEvent(); triggerEvents[i].Save(triggerEvent); playerData.TriggerEvents.Add(triggerEvent); } PlayerDataManager.SavePlayerTriggerEvents(dbConnection.Database, playerData); // Save team for (int i = 0; i < team.Length; i++) { playerData.TeamMembers[i].RecruitIndex = team[i].RecruitIndex; playerData.TeamMembers[i].UsingTempStats = team[i].InTempMode; if (team[i].Loaded) { team[i].Save(dbConnection); } } PlayerDataManager.SavePlayerTeam(dbConnection.Database, playerData); IMap map = GetCurrentMap(); if (map != null && (map.MapType == Enums.MapType.Instanced || map.MapType == Enums.MapType.RDungeonMap || map.MapType == Enums.MapType.House)) { map.Save(); //mInstancedMapManager.SaveActiveMap(); } lock (mapsToDelete) { AI.AIProcessor.mapGC.AddMaps(mapsToDelete); mapsToDelete.Clear(); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Map: " + MapID + System.Environment.NewLine + ex.ToString()); } finally { dataLock.ExitWriteLock(); } } }
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); } }
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); } }
public void Add(int slot, InventoryItem item) { items.Add(slot, item); }