/// <summary> /// Load previous data async /// </summary> public void LoadPreviousTwSnapshot(string previousPath, WorldVillagesCollection villages, Dictionary <string, Player> players, Dictionary <string, Tribe> tribes) { bool load = true; if (previousPath != null) { string currentPath = PreviousWorldDataDateDirectory; _previousData = previousPath; if (currentPath == PreviousWorldDataDateDirectory) { load = false; } } if (load && PreviousWorldDataDateDirectory != null) { var wrapper = new DictionaryLoaderWrapper(); wrapper.Villages = villages; wrapper.Tribes = tribes; wrapper.Players = players; wrapper.Path = PreviousWorldDataDateDirectory; DictionaryLoader invoker = BeginDictionaryAsync; invoker.BeginInvoke(wrapper, EndDictionaryAsync, null); } }
private World() { Settings = new WorldSettings(); EventPublisher = new Publisher(); Map = Map.CreateMap(); _miniMap = Map.CreateMiniMap(Map); _players = new Dictionary<string, Player>(); _tribes = new Dictionary<string, Tribe>(); _villages = new WorldVillagesCollection(); Cache = new AutoCompleteCache(); Views = new ViewsCollection(); You = new Player(); }
private World() { Settings = new WorldSettings(); EventPublisher = new Publisher(); Map = Map.CreateMap(); _miniMap = Map.CreateMiniMap(Map); _players = new Dictionary <string, Player>(); _tribes = new Dictionary <string, Tribe>(); _villages = new WorldVillagesCollection(); Cache = new AutoCompleteCache(); Views = new ViewsCollection(); You = new Player(); }
private void LoadTwSnapshot(string dataPath, out WorldVillagesCollection villages, out Dictionary<string, Player> players, out Dictionary<string, Tribe> tribes) { if (IsValidDataPath(dataPath)) { // load map files string[] readVillages = File.ReadAllLines(dataPath + FileVillageString); string[] readPlayers = File.ReadAllLines(dataPath + FilePlayerString); string[] readTribes = File.ReadAllLines(dataPath + FileTribeString); // Temporary dictionaries for mapping var tempPlayers = new Dictionary<int, string>(WorldPlayerCount); var tempTribes = new Dictionary<int, string>(WorldTribeCount); // Load tribes tribes = new Dictionary<string, Tribe>(readTribes.Length + 1); foreach (string tribeString in readTribes) { var tribe = new Tribe(tribeString.Split(',')); tribes.Add(tribe.Tag.ToUpper(), tribe); tempTribes.Add(tribe.Id, tribe.Tag.ToUpper()); } // Load players players = new Dictionary<string, Player>(readPlayers.Length + 1); foreach (string playerString in readPlayers) { var player = new Player(playerString.Split(',')); // Find tribe if (player.TribeId != 0 && tempTribes.ContainsKey(player.TribeId)) { Tribe tribe = tribes[tempTribes[player.TribeId]]; player.Tribe = tribe; tribes[tribe.Tag.ToUpper()].AddPlayer(player); } players.Add(player.Name.ToUpper(), player); tempPlayers.Add(player.Id, player.Name.ToUpper()); } // Load villages villages = new WorldVillagesCollection(readVillages.Length + 1); foreach (string villageString in readVillages) { var village = new Village(villageString.Split(',')); // links to and from players if (village.PlayerId != 0 && tempPlayers.ContainsKey(village.PlayerId)) { Player player = players[tempPlayers[village.PlayerId]]; village.Player = player; players[player.Name.ToUpper()].AddVillage(village); } if (village.Location.IsValidGameCoordinate()) { villages.Add(new Point(village.X, village.Y), village); } } } else { tribes = new Dictionary<string, Tribe>(); players = new Dictionary<string, Player>(); villages = new WorldVillagesCollection(); } }
/// <summary> /// Load previous data async /// </summary> public void LoadPreviousTwSnapshot(string previousPath, WorldVillagesCollection villages, Dictionary<string, Player> players, Dictionary<string, Tribe> tribes) { bool load = true; if (previousPath != null) { string currentPath = PreviousWorldDataDateDirectory; _previousData = previousPath; if (currentPath == PreviousWorldDataDateDirectory) load = false; } if (load && PreviousWorldDataDateDirectory != null) { var wrapper = new DictionaryLoaderWrapper(); wrapper.Villages = villages; wrapper.Tribes = tribes; wrapper.Players = players; wrapper.Path = PreviousWorldDataDateDirectory; DictionaryLoader invoker = BeginDictionaryAsync; invoker.BeginInvoke(wrapper, EndDictionaryAsync, null); } }
/// <summary> /// Loads the village, player and tribe files into memory /// </summary> /// <param name="villages">Output villages dictionary</param> /// <param name="players">Output players dictionary</param> /// <param name="tribes">Output tribes dictionary</param> public void LoadCurrentAndPreviousTwSnapshot(out WorldVillagesCollection villages, out Dictionary<string, Player> players, out Dictionary<string, Tribe> tribes) { LoadTwSnapshot(CurrentWorldDataDateDirectory, out villages, out players, out tribes); LoadPreviousTwSnapshot(null, villages, players, tribes); }
private void LoadTwSnapshot(string dataPath, out WorldVillagesCollection villages, out Dictionary <string, Player> players, out Dictionary <string, Tribe> tribes) { if (IsValidDataPath(dataPath)) { // load map files string[] readVillages = File.ReadAllLines(dataPath + FileVillageString); string[] readPlayers = File.ReadAllLines(dataPath + FilePlayerString); string[] readTribes = File.ReadAllLines(dataPath + FileTribeString); // Temporary dictionaries for mapping var tempPlayers = new Dictionary <int, string>(WorldPlayerCount); var tempTribes = new Dictionary <int, string>(WorldTribeCount); // Load tribes tribes = new Dictionary <string, Tribe>(readTribes.Length + 1); foreach (string tribeString in readTribes) { var tribe = new Tribe(tribeString.Split(',')); tribes.Add(tribe.Tag.ToUpper(), tribe); tempTribes.Add(tribe.Id, tribe.Tag.ToUpper()); } // Load players players = new Dictionary <string, Player>(readPlayers.Length + 1); foreach (string playerString in readPlayers) { var player = new Player(playerString.Split(',')); // Find tribe if (player.TribeId != 0 && tempTribes.ContainsKey(player.TribeId)) { Tribe tribe = tribes[tempTribes[player.TribeId]]; player.Tribe = tribe; tribes[tribe.Tag.ToUpper()].AddPlayer(player); } players.Add(player.Name.ToUpper(), player); tempPlayers.Add(player.Id, player.Name.ToUpper()); } // Load villages villages = new WorldVillagesCollection(readVillages.Length + 1); foreach (string villageString in readVillages) { var village = new Village(villageString.Split(',')); // links to and from players if (village.PlayerId != 0 && tempPlayers.ContainsKey(village.PlayerId)) { Player player = players[tempPlayers[village.PlayerId]]; village.Player = player; players[player.Name.ToUpper()].AddVillage(village); } if (village.Location.IsValidGameCoordinate()) { villages.Add(new Point(village.X, village.Y), village); } } } else { tribes = new Dictionary <string, Tribe>(); players = new Dictionary <string, Player>(); villages = new WorldVillagesCollection(); } }
/// <summary> /// Loads the village, player and tribe files into memory /// </summary> /// <param name="villages">Output villages dictionary</param> /// <param name="players">Output players dictionary</param> /// <param name="tribes">Output tribes dictionary</param> public void LoadCurrentAndPreviousTwSnapshot(out WorldVillagesCollection villages, out Dictionary <string, Player> players, out Dictionary <string, Tribe> tribes) { LoadTwSnapshot(CurrentWorldDataDateDirectory, out villages, out players, out tribes); LoadPreviousTwSnapshot(null, villages, players, tribes); }