public static string GetGoalName(WonderMail wonderMail) { //if (wonderMail.MissionType == Enums.MissionType.CompleteDungeon) { // return Dungeons.DungeonManager.Dungeons[wonderMail.DungeonIndex].Name; //} if (wonderMail.RDungeonFloor == -1) { string mapName = null; using (Database.DatabaseConnection dbConnection = new Database.DatabaseConnection(Database.DatabaseID.Data)) { mapName = DataManager.Maps.MapDataManager.GetMapName(dbConnection.Database, MapManager.GenerateMapID(wonderMail.DungeonMapNum)); } if (!string.IsNullOrEmpty(mapName)) { return(mapName); } else { return("???"); } } else { return(RDungeons.RDungeonFloorGen.GenerateName(wonderMail.DungeonMapNum, wonderMail.RDungeonFloor)); } }
public void Save() { lock (lockObject) { using (Database.DatabaseConnection dbConnection = new Database.DatabaseConnection(Database.DatabaseID.Data)) { MapManager.SaveInstancedMap(dbConnection, MapID, this); } } }
/// <summary> /// /// </summary> public static void ClearDataBase() { DialogResult result = MessageBox.Show("Are you sure you want to delete the contents of the database?", "Are you sure...", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { try { LoadFromDatabaseForm databaseForm = new LoadFromDatabaseForm(); Database.DatabaseConnection conn = new Database.DatabaseConnection(databaseForm.ServerNameBox.Text, Convert.ToUInt32(databaseForm.PortBox.Text), databaseForm.DatabaseNameBox.Text, databaseForm.UserNameBox.Text, databaseForm.PasswordBox.Text); conn.openConnection(); Database.DatabaseOperations.ClearDatabase(conn); } catch (Exception ex) { LogManager.Logger.Log(ex); } } }
public void Save() { lock (lockObject) { using (Database.DatabaseConnection dbConnection = new Database.DatabaseConnection(Database.DatabaseID.Data)) { MapManager.SaveHouseMap(dbConnection, MapID, this); } } }
public void ProcessAI() { try { TickCount tickCount = Core.GetTickCount(); PacketHitList packetList = null; PacketHitList.MethodStart(ref packetList); if (map.IsSaving == false) { // Keys/Other timed tile stuff for (int x = 0; x <= map.MaxX; x++) { for (int y = 0; y <= map.MaxY; y++) { if (map.Tile[x, y] != null) { if (tickCount.Elapsed(map.Tile[x, y].DoorTimer, 5000)) { if ((map.Tile[x, y].Type == Enums.TileType.Key || map.Tile[x, y].Type == Enums.TileType.Door) && map.Tile[x, y].DoorOpen == true) { map.Tile[x, y].DoorOpen = false; packetList.AddPacketToMap(map, TcpPacket.CreatePacket("mapkey", x.ToString(), y.ToString(), "0")); } } } } } Scripting.ScriptManager.InvokeSub("OnMapTick", map); if (map.ProcessingPaused == false) { int livingNpcs = 0; for (int mapNpcSlot = 0; mapNpcSlot < Constants.MAX_MAP_NPCS; mapNpcSlot++) { int npcNum = map.ActiveNpc[mapNpcSlot].Num; MapNpc mapNpc = map.ActiveNpc[mapNpcSlot]; if (npcNum > 0) { livingNpcs++; Npc npc = NpcManager.Npcs[npcNum]; if (npc.Behavior != Enums.NpcBehavior.FullyScriptedAI || npc.AIScript == "" || npc.AIScript.ToLower() == "none") { #region Used for attacking on sight if (npc.Behavior == Enums.NpcBehavior.AttackOnSight || npc.Behavior == Enums.NpcBehavior.Guard) { foreach (Client i in map.GetClients()) { if (i.Player.MapID == map.MapID && map.ActiveNpc[mapNpcSlot].Target == null && !i.Player.Dead && i.Player.Hunted && map.Tile[i.Player.X, i.Player.Y].Type != Enums.TileType.NPCAvoid && i.Player.Hunted) { if (MovementProcessor.CanCharacterSeeCharacter(map, map.ActiveNpc[mapNpcSlot], i.Player.GetActiveRecruit())) { if (npc.Behavior == Enums.NpcBehavior.AttackOnSight/* || i.Player.PK == true*/) { //if (!string.IsNullOrEmpty(npc.AttackSay)) { // packetList.AddPacket(i, PacketBuilder.CreateChatMsg("A " + npc.Name + " : " + npc.AttackSay, Text.Grey)); //} map.ActiveNpc[mapNpcSlot].Target = i; } } } } } #endregion #region Used for walking/targetting/picking up items if (npcNum > 0) { bool hasNpcWalked; if (map.ActiveNpc[mapNpcSlot].Target != null && map.ActiveNpc[mapNpcSlot].Target.IsPlaying() && map.ActiveNpc[mapNpcSlot].Target.Player.MapID == map.MapID && (map.Tile[map.ActiveNpc[mapNpcSlot].Target.Player.X, map.ActiveNpc[mapNpcSlot].Target.Player.Y].Type == Enums.TileType.NPCAvoid || !map.ActiveNpc[mapNpcSlot].Target.Player.Hunted || map.ActiveNpc[mapNpcSlot].Target.Player.Dead || !MovementProcessor.CanCharacterSeeCharacter(map, map.ActiveNpc[mapNpcSlot], map.ActiveNpc[mapNpcSlot].Target.Player.GetActiveRecruit()))) { map.ActiveNpc[mapNpcSlot].Target = null; } Client target = map.ActiveNpc[mapNpcSlot].Target; if (npc.Behavior != Enums.NpcBehavior.Shopkeeper) { if (target != null) { if (target.IsPlaying() && target.Player.MapID == map.MapID) { hasNpcWalked = false; int dir = Math.Rand(0, 5); hasNpcWalked = AIProcessor.MoveNpcInDirection((Enums.Direction)dir, map, target, packetList, mapNpcSlot); if (!hasNpcWalked) { foreach (Enums.Direction direction in Enum.GetValues(typeof(Enums.Direction))) { if (direction != (Enums.Direction)dir) { if (AIProcessor.MoveNpcInDirection(direction, map, target, packetList, mapNpcSlot)) { break; } } } } if (hasNpcWalked == false) { if (map.ActiveNpc[mapNpcSlot].X - 1 == target.Player.X && map.ActiveNpc[mapNpcSlot].Y == target.Player.Y) { if (map.ActiveNpc[mapNpcSlot].Direction != Enums.Direction.Left) { MovementProcessor.ChangeNpcDir(packetList, map, mapNpcSlot, Enums.Direction.Left); } hasNpcWalked = true; } if (map.ActiveNpc[mapNpcSlot].X + 1 == target.Player.X && map.ActiveNpc[mapNpcSlot].Y == target.Player.Y) { if (map.ActiveNpc[mapNpcSlot].Direction != Enums.Direction.Right) { MovementProcessor.ChangeNpcDir(packetList, map, mapNpcSlot, Enums.Direction.Right); } hasNpcWalked = true; } if (map.ActiveNpc[mapNpcSlot].X == target.Player.X && map.ActiveNpc[mapNpcSlot].Y - 1 == target.Player.Y) { if (map.ActiveNpc[mapNpcSlot].Direction != Enums.Direction.Up) { MovementProcessor.ChangeNpcDir(packetList, map, mapNpcSlot, Enums.Direction.Up); } hasNpcWalked = true; } if (map.ActiveNpc[mapNpcSlot].X == target.Player.X && map.ActiveNpc[mapNpcSlot].Y + 1 == target.Player.Y) { if (map.ActiveNpc[mapNpcSlot].Direction != Enums.Direction.Down) { MovementProcessor.ChangeNpcDir(packetList, map, mapNpcSlot, Enums.Direction.Down); } hasNpcWalked = true; } } if (hasNpcWalked == false) { int val = Math.Rand(0, 2); if (val == 1) { val = Math.Rand(0, 4); if (MovementProcessor.CanNpcMove(map, mapNpcSlot, (Enums.Direction)val)) { MovementProcessor.NpcMove(packetList, map, mapNpcSlot, map.ActiveNpc[mapNpcSlot].Direction, Enums.Speed.Walking); } } } } else { map.ActiveNpc[mapNpcSlot].Target = null; } } else { int shouldWalk = Math.Rand(0, 2); if (npc.Behavior != Enums.NpcBehavior.Friendly) { for (int i = 0; i < Constants.MAX_MAP_ITEMS; i++) { if (map.ActiveItem[i].X == map.ActiveNpc[mapNpcSlot].X && map.ActiveItem[i].Y == map.ActiveNpc[mapNpcSlot].Y && map.ActiveItem[i].Num > -1 && map.ActiveNpc[mapNpcSlot].HeldItem == null) { map.ActiveNpc[mapNpcSlot].MapGetItem(); shouldWalk = 1; } } } else if (npc.Behavior == Enums.NpcBehavior.Friendly) { foreach (Client i in map.GetClients()) { if (i.Player.X >= map.ActiveNpc[mapNpcSlot].X - 1 && i.Player.X <= map.ActiveNpc[mapNpcSlot].X + 1 && i.Player.Y >= map.ActiveNpc[mapNpcSlot].Y - 1 && i.Player.Y <= map.ActiveNpc[mapNpcSlot].Y + 1) { shouldWalk = Math.Rand(0, 10); break; } } } if (shouldWalk == 0) { shouldWalk = Math.Rand(0, 5); if (MovementProcessor.CanNpcMove(map, mapNpcSlot, (Enums.Direction)shouldWalk)) { MovementProcessor.NpcMove(packetList, map, mapNpcSlot, map.ActiveNpc[mapNpcSlot].Direction, Enums.Speed.Walking); } } } } } #endregion #region Used for attacking players if (npcNum > 0) { Client target = map.ActiveNpc[mapNpcSlot].Target; if (target != null) { if (target.IsPlaying() && target.Player.MapID == map.MapID) { // Make sure npcs dont attack more then once a second if (Core.GetTickCount().Elapsed(map.ActiveNpc[mapNpcSlot].AttackTimer, 1000)) { int usableMoveCount = 0; for (int i = 0; i < mapNpc.Moves.Length; i++) { if (mapNpc.Moves[i].MoveNum > -1 && mapNpc.Moves[i].CurrentPP > 0) { usableMoveCount++; } } if (usableMoveCount == 0) { if (BattleProcessor.ShouldUseMove(map, mapNpc, -1)) { mapNpc.UseMove(-1); } } else { // Try to use a move, up to 50 times for (int i = 0; i < 50; i++) { int moveSlotToUse = Server.Math.Rand(0, 5) - 1; if (moveSlotToUse == -1) { // A standard attack if (BattleProcessor.ShouldUseMove(map, mapNpc, moveSlotToUse)) { mapNpc.UseMove(moveSlotToUse); break; } } else { if (mapNpc.Moves[moveSlotToUse].MoveNum > -1 && mapNpc.Moves[moveSlotToUse].CurrentPP > 0) { // Use a move if (BattleProcessor.ShouldUseMove(map, mapNpc, moveSlotToUse)) { mapNpc.UseMove(moveSlotToUse); break; } } } } } } } else { map.ActiveNpc[mapNpcSlot].Target = null; } } } #endregion if (npcNum > 0 && map.ActiveNpc[mapNpcSlot].HPChanged) { map.ActiveNpc[mapNpcSlot].SendHPToMap(packetList, map, mapNpcSlot); } } else { // Scripted AI: Reimplement? //Globals.AIScriptManager.CallAIProcessSub(NpcManager.Npcs[map.Npc[x].NpcNum].AIScript, tickCount, map.MapNum, x); } } } //try and spawn something if (map.NpcSpawnWait == null) { map.NpcSpawnWait = Core.GetTickCount(); } if (Core.GetTickCount().Tick > map.NpcSpawnWait.Tick) { if (livingNpcs < map.MaxNpcs) { map.SpawnNpc(true); } map.NpcSpawnWait = new TickCount(map.NpcSpawnWait.Tick + map.NpcSpawnTime * 1000); } } } //lock (MapManager.ActiveMapLockObject) { bool shouldRemove = false; if (map.PlayersOnMap.Count == 0 && tickCount.Elapsed(map.ActivationTime, AIProcessor.MapTTL)) { if (map.IsProcessingComplete()) { shouldRemove = true; for (int i = 1; i < 9; i++) { IMap borderingMap = MapManager.RetrieveActiveBorderingMap(map, (Enums.MapID)i); if (borderingMap != null) { if (borderingMap.PlayersOnMap.Count > 0) { shouldRemove = false; } } } if (shouldRemove) { MapManager.rwLock.EnterWriteLock(); try { if (map.MapType == Enums.MapType.House) { // Only save the map here when logging out - otherwise, the map is saved when the player is saved map.Save(); } if ((map.MapType == Enums.MapType.RDungeonMap || map.MapType == Enums.MapType.Instanced)) { using (Database.DatabaseConnection dbConnection = new Database.DatabaseConnection(Database.DatabaseID.Data)) { if (MapManager.GetTotalPlayersOnMap(dbConnection, map.MapID) == 0) { DataManager.Maps.MapDataManager.DeleteMap(dbConnection.Database, map.MapID); } else { map.Save(); } } } MapManager.UnsafeRemoveActiveMap(map.MapID); } finally { MapManager.rwLock.ExitWriteLock(); } } } } //} PacketHitList.MethodEnded(ref packetList); } catch (Exception ex) { Server.Exceptions.ErrorLogger.WriteToErrorLog(ex, "MapAIProcessor"); } }
public void ProcessAI() { try { TickCount tickCount = Core.GetTickCount(); PacketHitList packetList = null; PacketHitList.MethodStart(ref packetList); if (map.IsSaving == false) { // Keys/Other timed tile stuff for (int x = 0; x <= map.MaxX; x++) { for (int y = 0; y <= map.MaxY; y++) { if (map.Tile[x, y] != null) { if (tickCount.Elapsed(map.Tile[x, y].DoorTimer, 5000)) { if ((map.Tile[x, y].Type == Enums.TileType.Key || map.Tile[x, y].Type == Enums.TileType.Door) && map.Tile[x, y].DoorOpen == true) { map.Tile[x, y].DoorOpen = false; packetList.AddPacketToMap(map, TcpPacket.CreatePacket("mapkey", x.ToString(), y.ToString(), "0")); } } } } } Scripting.ScriptManager.InvokeSub("OnMapTick", map); if (map.ProcessingPaused == false) { int livingNpcs = 0; for (int mapNpcSlot = 0; mapNpcSlot < Constants.MAX_MAP_NPCS; mapNpcSlot++) { int npcNum = map.ActiveNpc[mapNpcSlot].Num; MapNpc mapNpc = map.ActiveNpc[mapNpcSlot]; if (npcNum > 0) { livingNpcs++; Npc npc = NpcManager.Npcs[npcNum]; if (npc.Behavior != Enums.NpcBehavior.FullyScriptedAI || npc.AIScript == "" || npc.AIScript.ToLower() == "none") { #region Used for attacking on sight if (npc.Behavior == Enums.NpcBehavior.AttackOnSight || npc.Behavior == Enums.NpcBehavior.Guard) { foreach (Client i in map.GetClients()) { if (i.Player.MapID == map.MapID && map.ActiveNpc[mapNpcSlot].Target == null && !i.Player.Dead && i.Player.Hunted && map.Tile[i.Player.X, i.Player.Y].Type != Enums.TileType.NPCAvoid && i.Player.Hunted) { if (MovementProcessor.CanCharacterSeeCharacter(map, map.ActiveNpc[mapNpcSlot], i.Player.GetActiveRecruit())) { if (npc.Behavior == Enums.NpcBehavior.AttackOnSight /* || i.Player.PK == true*/) { //if (!string.IsNullOrEmpty(npc.AttackSay)) { // packetList.AddPacket(i, PacketBuilder.CreateChatMsg("A " + npc.Name + " : " + npc.AttackSay, Text.Grey)); //} map.ActiveNpc[mapNpcSlot].Target = i; } } } } } #endregion #region Used for walking/targetting/picking up items if (npcNum > 0) { bool hasNpcWalked; if (map.ActiveNpc[mapNpcSlot].Target != null && map.ActiveNpc[mapNpcSlot].Target.IsPlaying() && map.ActiveNpc[mapNpcSlot].Target.Player.MapID == map.MapID && (map.Tile[map.ActiveNpc[mapNpcSlot].Target.Player.X, map.ActiveNpc[mapNpcSlot].Target.Player.Y].Type == Enums.TileType.NPCAvoid || !map.ActiveNpc[mapNpcSlot].Target.Player.Hunted || map.ActiveNpc[mapNpcSlot].Target.Player.Dead || !MovementProcessor.CanCharacterSeeCharacter(map, map.ActiveNpc[mapNpcSlot], map.ActiveNpc[mapNpcSlot].Target.Player.GetActiveRecruit()))) { map.ActiveNpc[mapNpcSlot].Target = null; } Client target = map.ActiveNpc[mapNpcSlot].Target; if (npc.Behavior != Enums.NpcBehavior.Shopkeeper) { if (target != null) { if (target.IsPlaying() && target.Player.MapID == map.MapID) { hasNpcWalked = false; int dir = Math.Rand(0, 5); hasNpcWalked = AIProcessor.MoveNpcInDirection((Enums.Direction)dir, map, target, packetList, mapNpcSlot); if (!hasNpcWalked) { foreach (Enums.Direction direction in Enum.GetValues(typeof(Enums.Direction))) { if (direction != (Enums.Direction)dir) { if (AIProcessor.MoveNpcInDirection(direction, map, target, packetList, mapNpcSlot)) { break; } } } } if (hasNpcWalked == false) { if (map.ActiveNpc[mapNpcSlot].X - 1 == target.Player.X && map.ActiveNpc[mapNpcSlot].Y == target.Player.Y) { if (map.ActiveNpc[mapNpcSlot].Direction != Enums.Direction.Left) { MovementProcessor.ChangeNpcDir(packetList, map, mapNpcSlot, Enums.Direction.Left); } hasNpcWalked = true; } if (map.ActiveNpc[mapNpcSlot].X + 1 == target.Player.X && map.ActiveNpc[mapNpcSlot].Y == target.Player.Y) { if (map.ActiveNpc[mapNpcSlot].Direction != Enums.Direction.Right) { MovementProcessor.ChangeNpcDir(packetList, map, mapNpcSlot, Enums.Direction.Right); } hasNpcWalked = true; } if (map.ActiveNpc[mapNpcSlot].X == target.Player.X && map.ActiveNpc[mapNpcSlot].Y - 1 == target.Player.Y) { if (map.ActiveNpc[mapNpcSlot].Direction != Enums.Direction.Up) { MovementProcessor.ChangeNpcDir(packetList, map, mapNpcSlot, Enums.Direction.Up); } hasNpcWalked = true; } if (map.ActiveNpc[mapNpcSlot].X == target.Player.X && map.ActiveNpc[mapNpcSlot].Y + 1 == target.Player.Y) { if (map.ActiveNpc[mapNpcSlot].Direction != Enums.Direction.Down) { MovementProcessor.ChangeNpcDir(packetList, map, mapNpcSlot, Enums.Direction.Down); } hasNpcWalked = true; } } if (hasNpcWalked == false) { int val = Math.Rand(0, 2); if (val == 1) { val = Math.Rand(0, 4); if (MovementProcessor.CanNpcMove(map, mapNpcSlot, (Enums.Direction)val)) { MovementProcessor.NpcMove(packetList, map, mapNpcSlot, map.ActiveNpc[mapNpcSlot].Direction, Enums.Speed.Walking); } } } } else { map.ActiveNpc[mapNpcSlot].Target = null; } } else { int shouldWalk = Math.Rand(0, 2); if (npc.Behavior != Enums.NpcBehavior.Friendly) { for (int i = 0; i < Constants.MAX_MAP_ITEMS; i++) { if (map.ActiveItem[i].X == map.ActiveNpc[mapNpcSlot].X && map.ActiveItem[i].Y == map.ActiveNpc[mapNpcSlot].Y && map.ActiveItem[i].Num > -1 && map.ActiveNpc[mapNpcSlot].HeldItem == null) { map.ActiveNpc[mapNpcSlot].MapGetItem(); shouldWalk = 1; } } } else if (npc.Behavior == Enums.NpcBehavior.Friendly) { foreach (Client i in map.GetClients()) { if (i.Player.X >= map.ActiveNpc[mapNpcSlot].X - 1 && i.Player.X <= map.ActiveNpc[mapNpcSlot].X + 1 && i.Player.Y >= map.ActiveNpc[mapNpcSlot].Y - 1 && i.Player.Y <= map.ActiveNpc[mapNpcSlot].Y + 1) { shouldWalk = Math.Rand(0, 10); break; } } } if (shouldWalk == 0) { shouldWalk = Math.Rand(0, 5); if (MovementProcessor.CanNpcMove(map, mapNpcSlot, (Enums.Direction)shouldWalk)) { MovementProcessor.NpcMove(packetList, map, mapNpcSlot, map.ActiveNpc[mapNpcSlot].Direction, Enums.Speed.Walking); } } } } } #endregion #region Used for attacking players if (npcNum > 0) { Client target = map.ActiveNpc[mapNpcSlot].Target; if (target != null) { if (target.IsPlaying() && target.Player.MapID == map.MapID) { // Make sure npcs dont attack more then once a second if (Core.GetTickCount().Elapsed(map.ActiveNpc[mapNpcSlot].AttackTimer, 1000)) { int usableMoveCount = 0; for (int i = 0; i < mapNpc.Moves.Length; i++) { if (mapNpc.Moves[i].MoveNum > -1 && mapNpc.Moves[i].CurrentPP > 0) { usableMoveCount++; } } if (usableMoveCount == 0) { if (BattleProcessor.ShouldUseMove(map, mapNpc, -1)) { mapNpc.UseMove(-1); } } else { // Try to use a move, up to 50 times for (int i = 0; i < 50; i++) { int moveSlotToUse = Server.Math.Rand(0, 5) - 1; if (moveSlotToUse == -1) { // A standard attack if (BattleProcessor.ShouldUseMove(map, mapNpc, moveSlotToUse)) { mapNpc.UseMove(moveSlotToUse); break; } } else { if (mapNpc.Moves[moveSlotToUse].MoveNum > -1 && mapNpc.Moves[moveSlotToUse].CurrentPP > 0) { // Use a move if (BattleProcessor.ShouldUseMove(map, mapNpc, moveSlotToUse)) { mapNpc.UseMove(moveSlotToUse); break; } } } } } } } else { map.ActiveNpc[mapNpcSlot].Target = null; } } } #endregion if (npcNum > 0 && map.ActiveNpc[mapNpcSlot].HPChanged) { map.ActiveNpc[mapNpcSlot].SendHPToMap(packetList, map, mapNpcSlot); } } else { // Scripted AI: Reimplement? //Globals.AIScriptManager.CallAIProcessSub(NpcManager.Npcs[map.Npc[x].NpcNum].AIScript, tickCount, map.MapNum, x); } } } //try and spawn something if (map.NpcSpawnWait == null) { map.NpcSpawnWait = Core.GetTickCount(); } if (Core.GetTickCount().Tick > map.NpcSpawnWait.Tick) { if (livingNpcs < map.MaxNpcs) { map.SpawnNpc(true); } map.NpcSpawnWait = new TickCount(map.NpcSpawnWait.Tick + map.NpcSpawnTime * 1000); } } } //lock (MapManager.ActiveMapLockObject) { bool shouldRemove = false; if (map.PlayersOnMap.Count == 0 && tickCount.Elapsed(map.ActivationTime, AIProcessor.MapTTL)) { if (map.IsProcessingComplete()) { shouldRemove = true; for (int i = 1; i < 9; i++) { IMap borderingMap = MapManager.RetrieveActiveBorderingMap(map, (Enums.MapID)i); if (borderingMap != null) { if (borderingMap.PlayersOnMap.Count > 0) { shouldRemove = false; } } } if (shouldRemove) { MapManager.rwLock.EnterWriteLock(); try { if (map.MapType == Enums.MapType.House) { // Only save the map here when logging out - otherwise, the map is saved when the player is saved map.Save(); } if ((map.MapType == Enums.MapType.RDungeonMap || map.MapType == Enums.MapType.Instanced)) { using (Database.DatabaseConnection dbConnection = new Database.DatabaseConnection(Database.DatabaseID.Data)) { if (MapManager.GetTotalPlayersOnMap(dbConnection, map.MapID) == 0) { DataManager.Maps.MapDataManager.DeleteMap(dbConnection.Database, map.MapID); } else { map.Save(); } } } MapManager.UnsafeRemoveActiveMap(map.MapID); } finally { MapManager.rwLock.ExitWriteLock(); } } } } //} PacketHitList.MethodEnded(ref packetList); } catch (Exception ex) { Server.Exceptions.ErrorLogger.WriteToErrorLog(ex, "MapAIProcessor"); } }
public void Cleanup() { while (true) { // Keep this thread alive! resetEvent.WaitOne(); // Wait until we should do another GC resetEvent.Reset(); // Go through all queued items while (true) { string mapID = null; bool hasItem = cleanupQueue.TryDequeue(out mapID); if (!hasItem) { break; // Break out of the loop } using (Database.DatabaseConnection dbConnection = new Database.DatabaseConnection(Database.DatabaseID.Data)) { if (MapManager.GetTotalPlayersOnMap(dbConnection, mapID) == 0) { DataManager.Maps.MapDataManager.DeleteMap(dbConnection.Database, mapID); } } } } /* * old code for reference: * //lock (MapManager.ActiveMapLockObject) { bool shouldRemove = false; if (map.PlayersOnMap.Count == 0 && tickCount.Elapsed(map.ActivationTime, AIProcessor.MapTTL)) { if (map.IsProcessingComplete()) { shouldRemove = true; for (int i = 1; i < 9; i++) { IMap borderingMap = MapManager.RetrieveActiveBorderingMap(map, (Enums.MapID)i); if (borderingMap != null) { if (borderingMap.PlayersOnMap.Count > 0) { shouldRemove = false; } } } if (shouldRemove) { MapManager.rwLock.EnterWriteLock(); try { if (map.MapType == Enums.MapType.House) { // Only save the map here when logging out - otherwise, the map is saved when the player is saved map.Save(); } if ((map.MapType == Enums.MapType.RDungeonMap || map.MapType == Enums.MapType.Instanced)) { using (Database.DatabaseConnection dbConnection = new Database.DatabaseConnection(Database.DatabaseID.Data)) { if (MapManager.GetTotalPlayersOnMap(dbConnection, map.MapID) == 0) { DataManager.Maps.MapDataManager.DeleteMap(dbConnection.Database, map.MapID); } } } MapManager.UnsafeRemoveActiveMap(map.MapID); } finally { MapManager.rwLock.ExitWriteLock(); } } } } //} */ }
public static string GetGoalName(WonderMail wonderMail) { //if (wonderMail.MissionType == Enums.MissionType.CompleteDungeon) { // return Dungeons.DungeonManager.Dungeons[wonderMail.DungeonIndex].Name; //} if (wonderMail.RDungeonFloor == -1) { string mapName = null; using (Database.DatabaseConnection dbConnection = new Database.DatabaseConnection(Database.DatabaseID.Data)) { mapName = DataManager.Maps.MapDataManager.GetMapName(dbConnection.Database, MapManager.GenerateMapID(wonderMail.DungeonMapNum)); } if (!string.IsNullOrEmpty(mapName)) { return mapName; } else { return "???"; } } else { return RDungeons.RDungeonFloorGen.GenerateName(wonderMail.DungeonMapNum, wonderMail.RDungeonFloor); } }
/// <summary> /// /// </summary> public static void LoadFromDatabase() { TrackLayout.Track.Clear(); LoadFromDatabaseForm databaseForm = new LoadFromDatabaseForm(); if (databaseForm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { // TODO: Set up the database Database.DatabaseConnection conn = new Database.DatabaseConnection(databaseForm.ServerNameBox.Text, Convert.ToUInt32(databaseForm.PortBox.Text), databaseForm.DatabaseNameBox.Text, databaseForm.UserNameBox.Text, databaseForm.PasswordBox.Text); Query q = new Query(); List<string> list; String p = Prompt.ShowDialog("Enter A Track Circuit\n\n Type 'ALL' to Display Every Track Circuit", "Track Information Needed!"); if (p.Trim().ToUpper() == "ALL") { list = q.runQuery(conn, "SELECT * FROM track_segments"); } else { list = q.runQuery(conn, "SELECT * FROM track_segments where trackCircuit = '" + p.Trim() + "'"); } int numRows = list.Count / 15; TrackSegment ts; for (int i = 0; i < numRows; i++) { var offset = 15*i; bool exists = false; ts = new TrackSegment(list[offset + 0].ToString(), list[offset + 1].ToString(), list[offset + 2].ToString(), Convert.ToInt32(list[offset + 3].ToString()), Convert.ToInt32(list[offset + 4].ToString()), Convert.ToDouble(list[offset + 5].ToString()), Convert.ToDouble(list[offset + 6].ToString()), Convert.ToDouble(list[offset + 7].ToString()), Convert.ToDouble(list[offset + 8].ToString()), Convert.ToDouble(list[offset + 9].ToString()), Convert.ToDouble(list[offset + 10].ToString()), Convert.ToDouble(list[offset + 11].ToString()), Convert.ToDouble(list[offset + 12].ToString()), Convert.ToInt32(list[offset + 13].ToString()), Convert.ToInt32(list[offset + 14].ToString())); foreach(TrackSegment segment in TrackLayout.Track) { if (ts.IsSame(segment)) { exists = true; } } if(!exists) { TrackLayout.Track.Add(ts); } } } catch (Exception ex) { LogManager.Logger.Log(ex); } } }
public void Cleanup() { while (true) // Keep this thread alive! { resetEvent.WaitOne(); // Wait until we should do another GC resetEvent.Reset(); // Go through all queued items while (true) { string mapID = null; bool hasItem = cleanupQueue.TryDequeue(out mapID); if (!hasItem) { break; // Break out of the loop } using (Database.DatabaseConnection dbConnection = new Database.DatabaseConnection(Database.DatabaseID.Data)) { if (MapManager.GetTotalPlayersOnMap(dbConnection, mapID) == 0) { DataManager.Maps.MapDataManager.DeleteMap(dbConnection.Database, mapID); } } } } /* * old code for reference: * //lock (MapManager.ActiveMapLockObject) { * bool shouldRemove = false; * if (map.PlayersOnMap.Count == 0 && tickCount.Elapsed(map.ActivationTime, AIProcessor.MapTTL)) { * if (map.IsProcessingComplete()) { * shouldRemove = true; * * for (int i = 1; i < 9; i++) { * * IMap borderingMap = MapManager.RetrieveActiveBorderingMap(map, (Enums.MapID)i); * if (borderingMap != null) { * if (borderingMap.PlayersOnMap.Count > 0) { * shouldRemove = false; * } * } * } * * if (shouldRemove) { * MapManager.rwLock.EnterWriteLock(); * try { * if (map.MapType == Enums.MapType.House) { * // Only save the map here when logging out - otherwise, the map is saved when the player is saved * map.Save(); * } * if ((map.MapType == Enums.MapType.RDungeonMap || map.MapType == Enums.MapType.Instanced)) { * using (Database.DatabaseConnection dbConnection = new Database.DatabaseConnection(Database.DatabaseID.Data)) { * if (MapManager.GetTotalPlayersOnMap(dbConnection, map.MapID) == 0) { * DataManager.Maps.MapDataManager.DeleteMap(dbConnection.Database, map.MapID); * } * } * } * * MapManager.UnsafeRemoveActiveMap(map.MapID); * } finally { * MapManager.rwLock.ExitWriteLock(); * } * } * } * } * //} */ }
public async Task SyncPokedex(int startingDexNum, int endingDexNum) { using (var dbConnection = new Database.DatabaseConnection(Database.DatabaseID.Data)) { var client = new PokeClient(); for (var i = startingDexNum; i <= endingDexNum; i++) { var pokemon = await client.Get <Jirapi.Resources.Pokemon>(i); var species = await client.Get <Jirapi.Resources.PokemonSpecies>(i); var pokedexEntry = Pokedex.GetPokemon(i); pokedexEntry.Name = species.Names.Where(x => x.Language.Name == "en").First().Name1; pokedexEntry.SpeciesName = species.Genera.Where(x => x.Language.Name == "en").First().Genus1; var growthGroup = species.GrowthRate.Name; switch (growthGroup.ToLower()) { case "slow": pokedexEntry.GrowthGroup = Enums.GrowthGroup.Slow; break; case "medium": pokedexEntry.GrowthGroup = Enums.GrowthGroup.Fluctuating; break; case "medium-slow": pokedexEntry.GrowthGroup = Enums.GrowthGroup.MediumSlow; break; case "medium-fast": pokedexEntry.GrowthGroup = Enums.GrowthGroup.MediumFast; break; case "fast": pokedexEntry.GrowthGroup = Enums.GrowthGroup.Fast; break; case "erratic": pokedexEntry.GrowthGroup = Enums.GrowthGroup.Erratic; break; default: throw new NotImplementedException(); } foreach (var eggGroup in species.EggGroups) { await eggGroup.FillResource(); } if (species.EggGroups.Count > 0) { pokedexEntry.EggGroup1 = species.EggGroups[0].Resource.Names.Where(x => x.Language.Name == "en").First().Name1; } if (species.EggGroups.Count > 1) { pokedexEntry.EggGroup2 = species.EggGroups[1].Resource.Names.Where(x => x.Language.Name == "en").First().Name1; } // Load abilities foreach (var ability in pokemon.Abilities) { await ability.Ability.FillResource(); } for (var n = 0; n < pokemon.Forms.Count; n++) { var form = pokemon.Forms[n]; await form.FillResource(); PokemonForm pokedexForm; if (pokedexEntry.Forms.Count > n) { pokedexForm = pokedexEntry.Forms[n]; } else { pokedexForm = new PokemonForm(); pokedexEntry.Forms.Add(pokedexForm); } if (string.IsNullOrEmpty(form.Resource.FormName)) { pokedexForm.FormName = "Normal"; } else { pokedexForm.FormName = form.Resource.FormName; } pokedexForm.Weight = pokemon.Weight; pokedexForm.Height = pokemon.Height; pokedexForm.BaseRewardExp = pokemon.BaseExperience; pokedexForm.BaseHP = pokemon.Stats.Where(x => x.Stat.Name == "hp").First().BaseStat; pokedexForm.BaseAtt = pokemon.Stats.Where(x => x.Stat.Name == "attack").First().BaseStat; pokedexForm.BaseDef = pokemon.Stats.Where(x => x.Stat.Name == "defense").First().BaseStat; pokedexForm.BaseSpAtt = pokemon.Stats.Where(x => x.Stat.Name == "special-attack").First().BaseStat; pokedexForm.BaseSpDef = pokemon.Stats.Where(x => x.Stat.Name == "special-defense").First().BaseStat; pokedexForm.BaseSpd = pokemon.Stats.Where(x => x.Stat.Name == "speed").First().BaseStat; if (pokemon.Types.Count > 0) { pokedexForm.Type1 = MapTypeNameToType(pokemon.Types[0].Type.Name); } if (pokemon.Types.Count > 1) { pokedexForm.Type2 = MapTypeNameToType(pokemon.Types[1].Type.Name); } pokedexForm.Ability1 = "None"; pokedexForm.Ability2 = "None"; pokedexForm.Ability3 = "None"; if (pokemon.Abilities.Count > 0) { pokedexForm.Ability1 = pokemon.Abilities[0].Ability.Resource.Names.Where(x => x.Language.Name == "en").First().Name1; } if (pokemon.Abilities.Count > 1) { pokedexForm.Ability2 = pokemon.Abilities[1].Ability.Resource.Names.Where(x => x.Language.Name == "en").First().Name1; } if (pokemon.Abilities.Count > 2) { pokedexForm.Ability3 = pokemon.Abilities[2].Ability.Resource.Names.Where(x => x.Language.Name == "en").First().Name1; } pokedexForm.LevelUpMoves.Clear(); pokedexForm.TMMoves.Clear(); pokedexForm.TutorMoves.Clear(); pokedexForm.EggMoves.Clear(); foreach (var move in pokemon.Moves) { var versionGroupDetails = move.VersionGroupDetails.First(); switch (versionGroupDetails.MoveLearnMethod.Name.ToLower()) { case "level-up": { var moveId = FindMoveByName(move.Move.Name); if (moveId > -1) { pokedexForm.LevelUpMoves.Add(new LevelUpMove(moveId, versionGroupDetails.LevelLearnedAt)); } } break; case "machine": { var moveId = FindMoveByName(move.Move.Name); if (moveId > -1) { pokedexForm.TMMoves.Add(moveId); } } break; case "tutor": { var moveId = FindMoveByName(move.Move.Name); if (moveId > -1) { pokedexForm.TutorMoves.Add(moveId); } } break; case "egg": { var moveId = FindMoveByName(move.Move.Name); if (moveId > -1) { pokedexForm.EggMoves.Add(moveId); } } break; default: throw new NotImplementedException(); } } } Pokedex.SavePokemon(dbConnection, i); } } }