public PackDialogViewModel(ZoneSpawns zonespawns) { if (zonespawns == null) { throw new NullReferenceException(); } PackCommand = new DelegateCommand(x => { zonespawns.PackTable(_start, _end); System.Windows.MessageBox.Show("Pack complete", "Completed"); }, y => { return _start < _end && _end - _start >= zonespawns.Spawns.Count; }); }
public void OpenXML(string file,string zone,int version) { XmlSerializer serializer = new XmlSerializer(typeof(List<ZoneEntryStruct>)); Zone = zone; ZoneVersion = version; List<ZoneEntryStruct> spawns; try { using (var fs = new System.IO.FileStream(file, FileMode.Open)) { var obj = serializer.Deserialize(fs); spawns = obj as List<ZoneEntryStruct>; } } catch (Exception) { throw; } if (spawns == null) throw new FileFormatException(); _npcs.ClearCache(); _spawngroups.ClearCache(); if (LoadSpawnEntries) { if (_connection != null && _connection.State == System.Data.ConnectionState.Open) { var zps = new ZoneSpawnsDatabase(_connection, _config); _spawns = zps; zps.Lookup(Zone, ZoneVersion); } else { _spawns = new ZoneSpawnsLocal(_config); _spawns.Zone = Zone; _spawns.Version = ZoneVersion; } } var zoneNpcs = spawns.Where(x => x.IsNPC > 0 && x.PetOwnerID == 0 && x.IsMercenary == 0 ); int id = _npcs.GetNextIdForZone(Zone); if (id == -1) id = 0; foreach (var sp in zoneNpcs) { if ( _npcs.NPCs.Count(x => x.Level == sp.Level && x.Name == sp.SpawnName) == 0) { var npc = _npcs.CreateNPC(); Npc.SetNPCProperties(ref npc, sp); npc.Version = ZoneVersion; npc.Id = id; _npcs.AddNPC(npc); id += 1; } } Dictionary<string, SpawnGroup> spawngroupMap = new Dictionary<string, SpawnGroup>(); if (LoadSpawnGroups) { //all added spawngroups need to be flagged for insertion _spawngroups.Created(); foreach (var npc in _npcs.NPCs.GroupBy(x => x.Name)) { var sg = _spawngroups.CreateSpawnGroup(); foreach (var name in npc) { sg.AddEntry(name); } sg.Created(); _spawngroups.AddSpawnGroup(sg); sg.BalanceChance(); sg.Name = String.Format("{0}_{1}_v{2}", Zone, npc.ElementAt(0).Name, ZoneVersion); spawngroupMap[npc.ElementAt(0).Name] = sg; } } if (LoadSpawnEntries) { foreach (var npc in zoneNpcs) { Spawn2 spawn = _spawns.GetNewSpawn(); spawn.Created(); if (LoadSpawnGroups) { if (spawngroupMap.ContainsKey(npc.SpawnName)) { spawn.SpawnGroupRef = spawngroupMap[npc.SpawnName]; } } spawn.X = npc.XPos; spawn.Y = npc.YPos; spawn.Z = npc.ZPos; spawn.Heading = npc.Heading; _spawns.AddSpawn(spawn); } var serv = _service as SpawnsPlugin.SpawnDataService; if (serv != null) { serv.ZoneSpawns = _spawns; } } OnFileLoaded(FileSelected, FileLoadingEventArgs.LoadingState.Loaded); }