private static void PostProcess(object obj) { if (obj is RecallRune) { RecallRune rune = (RecallRune)obj; if (Spells.SpellHelper.IsAnyT2A(rune.TargetMap, rune.Target)) { rune.Delete(); } else if (Spells.SpellHelper.IsFeluccaDungeon(rune.TargetMap, rune.Target)) { Regions.DungeonRegion reg = Region.Find(rune.Target, rune.TargetMap) as Regions.DungeonRegion; if (reg != null) { if (reg.Name == "Fire" || reg.Name == "Ice" || reg.Name == "Orc Cave" || reg.Name == "Terathan Keep") { rune.Delete(); } } } } }
public static void ImportWorld() { ArrayList retry = new ArrayList(), houses = new ArrayList(); int count = 0; foreach (Account a in Accounts.List.Values) { for (int i = 0; i < 6; i++) { if (a[i] != null) { a[i].Player = false; } a[i] = null; } } using (StreamReader r = new StreamReader("world.txt", System.Text.Encoding.ASCII)) { string line; IEntity curObj = null; Mobile prevMob = null; Type curType = null; while ((line = r.ReadLine()) != null) { if (string.IsNullOrEmpty(line)) { continue; } string[] parts = line.Split(new char[] { '=' }, 3, StringSplitOptions.None); if (parts.Length != 3) { Console.WriteLine("Warning! Wrong number of fields: {0} -- {1}", parts.Length, line); continue; } /*if (parts[0] == "Profile") * { * long prevPos = r.BaseStream.Position; * while ((line = r.ReadLine()) != null) * { * string[] split = line.Split(new char[] { '=' }, 3, StringSplitOptions.None); * * if (split.Length != 3) * { * parts[2] += "\n" + line; * prevPos = r.BaseStream.Position; * } * else * { * r.BaseStream.Seek(prevPos, SeekOrigin.Begin); * break; * } * } * }*/ try { if (parts[0] == "Object") { PostProcess(curObj); parts[1] = TranslateType(parts[1]); curObj = null; curType = ScriptCompiler.FindTypeByFullName(parts[1], true); if (curType == null) { InsertError("{0}: Type missing", parts[1]); continue; } Serial oldSer = Utility.ToInt32(parts[2]); /*if (IsType(curType, typeof(Item))) * Serial.NewItem = Utility.ToInt32(parts[2]) - 1; * else if (IsType(curType, typeof(Mobile) )) * Serial.NewMobile = Utility.ToInt32(parts[2]) - 1; */ try { curObj = Activator.CreateInstance(curType, new object[0]) as IEntity; } catch { } if (curObj == null) { try { if (curType == typeof(BankBox) && prevMob != null) { curObj = new BankBox(prevMob); } //curObj = Activator.CreateInstance( curType, new object[1]{prevMob} ) as IEntity; } catch { } if (curObj == null) { InsertError("{0}: Unable to construct", parts[1]); continue; } } if (curObj is Mobile) { _Mobiles[oldSer] = curObj; prevMob = (Mobile)curObj; } else if (curObj is Item) { _Items[oldSer] = curObj; } count++; if ((count % 10000) == 0) { Console.WriteLine("Completed {0} objects so far", count - 1); } } else if (parts[0] == "House") { string type, loc, map, owner; type = r.ReadLine(); loc = r.ReadLine(); map = r.ReadLine(); owner = r.ReadLine(); houses.Add(new string[] { type, loc, map, owner }); } else if (parts[0] == "Skills") { Mobile m = FindMobile(Utility.ToInt32(parts[2])); while ((line = r.ReadLine()) != null) { if (line == "EndSkills" || line == "") { break; } parts = line.Split(new char[] { '=' }, 3, StringSplitOptions.None); if (parts.Length != 3) { continue; } SkillName name = (SkillName)Enum.Parse(typeof(SkillName), parts[0]); m.Skills[name].BaseFixedPoint = Utility.ToInt32(parts[2]); } } else if (parts[0] == "RuneBookEntry") { if (curObj is Runebook) { Point3D pt = Point3D.Parse(parts[1]); bool okay = true; if (Spells.SpellHelper.IsAnyT2A(Map.Felucca, pt)) { okay = false; } else if (Spells.SpellHelper.IsFeluccaDungeon(Map.Felucca, pt)) { Regions.DungeonRegion reg = Region.Find(pt, Map.Felucca) as Regions.DungeonRegion; if (reg != null) { if (reg.Name == "Fire" || reg.Name == "Ice" || reg.Name == "Orc Cave" || reg.Name == "Terathan Keep") { okay = false; } } } if (okay) { ((Runebook)curObj).Entries.Add(new RunebookEntry(pt, Map.Felucca, parts[2], null)); } } } else if (curObj != null) { DoProperty(curObj, curType, parts, retry); } } catch (Exception e) { InsertError("Exception '{0}' for line '{1}'", e.Message, line); } } PostProcess(curObj); } foreach (object[] list in retry) { DoProperty(list[0], list[1] as Type, list[2] as string[], null); } foreach (string[] list in houses) { list[0] = TranslateType(list[0]); Type deedType = ScriptCompiler.FindTypeByFullName(list[0], true); Point3D loc = Point3D.Parse(list[1]); Map map = Map.Parse(list[2]); Mobile owner = FindMobile(Utility.ToInt32(list[3])); if (deedType == null || !deedType.IsSubclassOf(typeof(HouseDeed))) { InsertError("{0}: Type missing\n", list[0]); continue; } if (owner == null || map == null || map == Map.Internal || loc == Point3D.Zero) { InsertError("House properties messed up (owner probably missing)\n"); continue; } HouseDeed deed = null; try { deed = Activator.CreateInstance(deedType, new object[0]) as HouseDeed; } catch { } if (deed == null) { InsertError("Failed to create deed {0}\n", list[0]); continue; } BaseHouse house = deed.GetHouse(owner); house.MoveToWorld(loc, map); deed.Delete(); } Console.WriteLine("Import complete, imported {0} objects.", count); Console.WriteLine("\nErrors:"); foreach (string err in _Errors.Keys) { Console.WriteLine("{0} (Count={1})", err, _Errors[err]); } Console.WriteLine("Done. Saving..."); World.Save(); Console.WriteLine("Press enter to quit. REMOVE THIS SCRIPT BEFORE RUNNING THE SERVER AGAIN"); Console.ReadLine(); System.Diagnostics.Process.GetCurrentProcess().Kill(); }