public static SmallBulkEntry[] LoadEntries(string path) { path = Path.Combine(Core.BaseDirectory, path); var list = new List <SmallBulkEntry>(); if (File.Exists(path)) { using var ip = new StreamReader(path); string line; while ((line = ip.ReadLine()) != null) { if (line.Length == 0 || line.StartsWith("#")) { continue; } try { var split = line.Split('\t'); if (split.Length >= 2) { var type = AssemblyHandler.FindFirstTypeForName(split[0]); var graphic = Utility.ToInt32(split[^ 1]);
public static void SaveQuest_OnCommand(CommandEventArgs e) { Mobile m = e.Mobile; if (e.Length == 0 || e.Length > 2) { m.SendMessage("Syntax: SaveQuest <id> [saveEnabled=true]"); return; } Type index = AssemblyHandler.FindFirstTypeForName(e.GetString(0)); if (index == null || !Quests.TryGetValue(index, out MLQuest quest)) { m.SendMessage("Invalid quest type name."); return; } bool enable = e.Length == 2 ? e.GetBoolean(1) : true; quest.SaveEnabled = enable; m.SendMessage("Serialization for quest {0} is now {1}.", quest.GetType().Name, enable ? "enabled" : "disabled"); if (AutoGenerateNew && !enable) { m.SendMessage( "Please note that automatic generation of new quests is ON. This quest will be regenerated on the next server start."); } }
public static Spell NewSpell(string name, Mobile caster, Item scroll) { name = name.Replace(" ", ""); for (var i = 0; i < m_CircleNames.Length; ++i) { var t = AssemblyHandler.FindFirstTypeForName($"Server.Spells.{m_CircleNames[i]}.{name}", true) ?? AssemblyHandler.FindFirstTypeForName($"Server.Spells.{m_CircleNames[i]}.{name}Spell", true); if (t?.IsSubclassOf(typeof(SpecialMove)) == false) { m_Params[0] = caster; m_Params[1] = scroll; try { return(t.CreateInstance <Spell>(m_Params)); } catch { // ignored } } } return(null); }
public CategoryEntry(CategoryEntry parent, CategoryLine[] lines, ref int index) { Parent = parent; string text = lines[index].Text; int start = text.IndexOf('('); if (start < 0) { throw new FormatException($"Input string not correctly formatted ('{text}')"); } Title = text.Substring(0, start).Trim(); int end = text.IndexOf(')', ++start); if (end < start) { throw new FormatException($"Input string not correctly formatted ('{text}')"); } text = text.Substring(start, end - start); string[] split = text.Split(';'); List <Type> list = new List <Type>(); for (int i = 0; i < split.Length; ++i) { Type type = AssemblyHandler.FindFirstTypeForName(split[i].Trim()); if (type == null) { Console.WriteLine("Match type not found ('{0}')", split[i].Trim()); } else { list.Add(type); } } Matches = list.ToArray(); list.Clear(); int ourIndentation = lines[index].Indentation; ++index; List <CategoryEntry> entryList = new List <CategoryEntry>(); while (index < lines.Length && lines[index].Indentation > ourIndentation) { entryList.Add(new CategoryEntry(this, lines, ref index)); } SubCategories = entryList.ToArray(); entryList.Clear(); Matched = new List <CategoryTypeEntry>(); }
public override bool ValidateArgs(BaseCommandImplementor impl, CommandEventArgs e) { if (e.Length >= 1) { Type t = AssemblyHandler.FindFirstTypeForName(e.GetString(0)); if (t == null) { e.Mobile.SendMessage("No type with that name was found."); string match = e.GetString(0).Trim(); if (match.Length < 3) { e.Mobile.SendMessage("Invalid search string."); e.Mobile.SendGump(new AddGump(e.Mobile, match, 0, Type.EmptyTypes, false)); } else { e.Mobile.SendGump(new AddGump(e.Mobile, match, 0, AddGump.Match(match).ToArray(), true)); } } else { return(true); } } else { e.Mobile.SendGump(new CategorizedAddGump(e.Mobile)); } return(false); }
public BOBSmallEntry(IGenericReader reader) { var version = reader.ReadEncodedInt(); switch (version) { case 0: { var type = reader.ReadString(); if (type != null) { ItemType = AssemblyHandler.FindFirstTypeForName(type); } RequireExceptional = reader.ReadBool(); DeedType = (BODType)reader.ReadEncodedInt(); Material = (BulkMaterialType)reader.ReadEncodedInt(); AmountCur = reader.ReadEncodedInt(); AmountMax = reader.ReadEncodedInt(); Number = reader.ReadEncodedInt(); Graphic = reader.ReadEncodedInt(); Price = reader.ReadEncodedInt(); break; } } }
public override Type Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { if (reader.TokenType != JsonTokenType.String) { throw new JsonException("The JSON value could not be converted to System.Type"); } return(AssemblyHandler.FindFirstTypeForName(reader.GetString())); }
public static object ParseValue(Type type, string value) { try { if (IsEnum(type)) { return(Enum.Parse(type, value, true)); } if (IsType(type)) { return(AssemblyHandler.FindFirstTypeForName(value)); } if (IsParsable(type)) { return(ParseParsable(type, value)); } object obj = value; if (value?.StartsWith("0x", StringComparison.Ordinal) == true) { if (IsSignedNumeric(type)) { obj = Convert.ToInt64(value.Substring(2), 16); } else if (IsUnsignedNumeric(type)) { obj = Convert.ToUInt64(value.Substring(2), 16); } else { obj = Convert.ToInt32(value.Substring(2), 16); } } if (obj == null && !type.IsValueType) { return(null); } return(Convert.ChangeType(obj, type)); } catch { return(null); } }
public static MLQuest ReadQuestRef(IGenericReader reader) { string typeName = reader.ReadString(); if (typeName == null) { return(null); // not serialized } Type questType = AssemblyHandler.FindFirstTypeForName(typeName); if (questType == null) { return(null); // no longer a type } return(FindQuest(questType)); }
public LargeBulkEntry(LargeBOD owner, IGenericReader reader) { Owner = owner; m_Amount = reader.ReadInt(); Type realType = null; var type = reader.ReadString(); if (type != null) { realType = AssemblyHandler.FindFirstTypeForName(type); } Details = new SmallBulkEntry(realType, reader.ReadInt(), reader.ReadInt()); }
public CAGObject(CAGCategory parent, XmlTextReader xml) { Parent = parent; if (xml.MoveToAttribute("type")) { Type = AssemblyHandler.FindFirstTypeForName(xml.Value, false); } if (xml.MoveToAttribute("gfx")) { ItemID = XmlConvert.ToInt32(xml.Value); } if (xml.MoveToAttribute("hue")) { Hue = XmlConvert.ToInt32(xml.Value); } }
public TalismanAttribute(IGenericReader reader) { int version = reader.ReadInt(); SaveFlag flags = (SaveFlag)reader.ReadEncodedInt(); if (GetSaveFlag(flags, SaveFlag.Type)) { Type = AssemblyHandler.FindFirstTypeForName(reader.ReadString(), false); } if (GetSaveFlag(flags, SaveFlag.Name)) { Name = TextDefinition.Deserialize(reader); } if (GetSaveFlag(flags, SaveFlag.Amount)) { Amount = reader.ReadEncodedInt(); } }
public static void MLQuestsInfo_OnCommand(CommandEventArgs e) { Mobile m = e.Mobile; if (e.Length == 0) { m.SendMessage("Quest table length: {0}", Quests.Count); return; } Type index = AssemblyHandler.FindFirstTypeForName(e.GetString(0)); if (index == null || !Quests.TryGetValue(index, out MLQuest quest)) { m.SendMessage("Invalid quest type name."); return; } m.SendMessage("Activated: {0}", quest.Activated); m.SendMessage("Number of objectives: {0}", quest.Objectives.Count); m.SendMessage("Objective type: {0}", quest.ObjectiveType); m.SendMessage("Number of active instances: {0}", quest.Instances.Count); }
public BOBLargeSubEntry(IGenericReader reader) { int version = reader.ReadEncodedInt(); switch (version) { case 0: { string type = reader.ReadString(); if (type != null) { ItemType = AssemblyHandler.FindFirstTypeForName(type); } AmountCur = reader.ReadEncodedInt(); Number = reader.ReadEncodedInt(); Graphic = reader.ReadEncodedInt(); break; } } }
public static Type ReadType(Type[] referenceTable, IGenericReader reader) { var encoding = reader.ReadEncodedInt(); switch (encoding) { default: { return(null); } case 0x01: // indexed { var index = reader.ReadEncodedInt(); if (index >= 0 && index < referenceTable.Length) { return(referenceTable[index]); } return(null); } case 0x02: // by name { var fullName = reader.ReadString(); if (fullName == null) { return(null); } return(AssemblyHandler.FindFirstTypeForName(fullName)); } } }
public static Spell NewSpell(string name, Mobile caster, Item scroll) { for (int i = 0; i < m_CircleNames.Length; ++i) { Type t = AssemblyHandler.FindFirstTypeForName($"Server.Spells.{m_CircleNames[i]}.{name}"); if (t?.IsSubclassOf(typeof(SpecialMove)) == false) { m_Params[0] = caster; m_Params[1] = scroll; try { return((Spell)ActivatorUtil.CreateInstance(t, m_Params)); } catch { // ignored } } } return(null); }
public static string ConstructFromString(Type type, object obj, string value, ref object constructed) { object toSet; bool isSerial = IsSerial(type); if (isSerial) // mutate into int32 { type = m_NumericTypes[4]; } if (value == "(-null-)" && !type.IsValueType) { value = null; } if (IsEnum(type)) { try { toSet = Enum.Parse(type, value ?? "", true); } catch { return("That is not a valid enumeration member."); } } else if (IsType(type)) { try { toSet = AssemblyHandler.FindFirstTypeForName(value); if (toSet == null) { return("No type with that name was found."); } } catch { return("No type with that name was found."); } } else if (IsParsable(type)) { try { toSet = Parse(obj, type, value); } catch { return("That is not properly formatted."); } } else if (value == null) { toSet = null; } else if (value.StartsWith("0x") && IsNumeric(type)) { try { toSet = Convert.ChangeType(Convert.ToUInt64(value.Substring(2), 16), type); } catch { return("That is not properly formatted."); } } else { try { toSet = Convert.ChangeType(value, type); } catch { return("That is not properly formatted."); } } if (isSerial) // mutate back { toSet = (Serial)(toSet ?? Serial.MinusOne); } constructed = toSet; return(null); }
public static ObjectConditional ParseDirect(Mobile from, string[] args, int offset, int size) { if (args == null || size == 0) { return(Empty); } int index = 0; Type objectType = AssemblyHandler.FindFirstTypeForName(args[offset + index], true); if (objectType == null) { throw new Exception($"No type with that name ({args[offset + index]}) was found."); } ++index; List <ICondition[]> conditions = new List <ICondition[]>(); List <ICondition> current = new List <ICondition>(); current.Add(TypeCondition.Default); while (index < size) { string cur = args[offset + index]; bool inverse = false; if (InsensitiveStringHelpers.Equals(cur, "not") || cur == "!") { inverse = true; ++index; if (index >= size) { throw new Exception("Improperly formatted object conditional."); } } else if (InsensitiveStringHelpers.Equals(cur, "or") || cur == "||") { if (current.Count > 1) { conditions.Add(current.ToArray()); current.Clear(); current.Add(TypeCondition.Default); } ++index; continue; } string binding = args[offset + index]; index++; if (index >= size) { throw new Exception("Improperly formatted object conditional."); } string oper = args[offset + index]; index++; if (index >= size) { throw new Exception("Improperly formatted object conditional."); } string val = args[offset + index]; index++; Property prop = new Property(binding); prop.BindTo(objectType, PropertyAccess.Read); prop.CheckAccess(from); var condition = oper switch { "=" => (ICondition) new ComparisonCondition(prop, inverse, ComparisonOperator.Equal, val), "==" => new ComparisonCondition(prop, inverse, ComparisonOperator.Equal, val), "is" => new ComparisonCondition(prop, inverse, ComparisonOperator.Equal, val), "!=" => new ComparisonCondition(prop, inverse, ComparisonOperator.NotEqual, val), ">" => new ComparisonCondition(prop, inverse, ComparisonOperator.Greater, val), "<" => new ComparisonCondition(prop, inverse, ComparisonOperator.Lesser, val), ">=" => new ComparisonCondition(prop, inverse, ComparisonOperator.GreaterEqual, val), "<=" => new ComparisonCondition(prop, inverse, ComparisonOperator.LesserEqual, val), "==~" => new StringCondition(prop, inverse, StringOperator.Equal, val, true), "~==" => new StringCondition(prop, inverse, StringOperator.Equal, val, true), "=~" => new StringCondition(prop, inverse, StringOperator.Equal, val, true), "~=" => new StringCondition(prop, inverse, StringOperator.Equal, val, true), "is~" => new StringCondition(prop, inverse, StringOperator.Equal, val, true), "~is" => new StringCondition(prop, inverse, StringOperator.Equal, val, true), "!=~" => new StringCondition(prop, inverse, StringOperator.NotEqual, val, true), "~!=" => new StringCondition(prop, inverse, StringOperator.NotEqual, val, true), "starts" => new StringCondition(prop, inverse, StringOperator.StartsWith, val, false), "starts~" => new StringCondition(prop, inverse, StringOperator.StartsWith, val, true), "~starts" => new StringCondition(prop, inverse, StringOperator.StartsWith, val, true), "ends" => new StringCondition(prop, inverse, StringOperator.EndsWith, val, false), "ends~" => new StringCondition(prop, inverse, StringOperator.EndsWith, val, true), "~ends" => new StringCondition(prop, inverse, StringOperator.EndsWith, val, true), "contains" => new StringCondition(prop, inverse, StringOperator.Contains, val, false), "contains~" => new StringCondition(prop, inverse, StringOperator.Contains, val, true), "~contains" => new StringCondition(prop, inverse, StringOperator.Contains, val, true), _ => null }; if (condition == null) { throw new InvalidOperationException($"Unrecognized operator (\"{oper}\")."); } current.Add(condition); } conditions.Add(current.ToArray()); return(new ObjectConditional(objectType, conditions.ToArray())); } }
public static Type GetType(string name) => AssemblyHandler.FindFirstTypeForName(name);
private static void ParseSpawnerList(Mobile from, List <DynamicJson> spawners, JsonSerializerOptions options) { Stopwatch watch = Stopwatch.StartNew(); List <string> failures = new List <string>(); int count = 0; for (var i = 0; i < spawners.Count; i++) { var json = spawners[i]; Type type = AssemblyHandler.FindFirstTypeForName(json.Type); if (type == null || !typeof(BaseSpawner).IsAssignableFrom(type)) { string failure = $"GenerateSpawners: Invalid spawner type {json.Type ?? "(-null-)"} ({i})"; if (!failures.Contains(failure)) { failures.Add(failure); from.SendMessage(failure); } continue; } json.GetProperty("location", options, out Point3D location); json.GetProperty("map", options, out Map map); var eable = map.GetItemsInRange <BaseSpawner>(location, 0); if (eable.Any(sp => sp.GetType() == type)) { eable.Free(); continue; } eable.Free(); try { var spawner = ActivatorUtil.CreateInstance(type, json, options) as ISpawner; spawner !.MoveToWorld(location, map); spawner !.Respawn(); } catch (Exception) { string failure = $"GenerateSpawners: Spawner {type} failed to construct"; if (!failures.Contains(failure)) { failures.Add(failure); from.SendMessage(failure); } continue; } count++; } watch.Stop(); from.SendMessage("GenerateSpawners: Generated {0} spawners ({1:F2} seconds, {2} failures)", count, watch.Elapsed.TotalSeconds, failures.Count); }
public static DecorationListMag Read(StreamReader ip) { string line; while ((line = ip.ReadLine()) != null) { line = line.Trim(); if (line.Length > 0 && !line.StartsWith("#")) { break; } } if (string.IsNullOrEmpty(line)) { return(null); } var list = new DecorationListMag(); var indexOf = line.IndexOf(' '); list.m_Type = AssemblyHandler.FindFirstTypeForName(line.Substring(0, indexOf++), true); if (list.m_Type == null) { throw new ArgumentException($"Type not found for header: '{line}'"); } line = line.Substring(indexOf); indexOf = line.IndexOf('('); if (indexOf >= 0) { list.m_ItemID = Utility.ToInt32(line.Substring(0, indexOf - 1)); var parms = line.Substring(++indexOf); if (line.EndsWith(")")) { parms = parms.Substring(0, parms.Length - 1); } list.m_Params = parms.Split(';'); for (var i = 0; i < list.m_Params.Length; ++i) { list.m_Params[i] = list.m_Params[i].Trim(); } } else { list.m_ItemID = Utility.ToInt32(line); list.m_Params = m_EmptyParams; } list.m_Entries = new List <DecorationEntryMag>(); while ((line = ip.ReadLine()) != null) { line = line.Trim(); if (line.Length == 0) { break; } if (line.StartsWith("#")) { continue; } list.m_Entries.Add(new DecorationEntryMag(line)); } return(list); }
public void CreateArray(RelayInfo info, Mobile from, BaseSpawner spawner) { var ocount = spawner.Entries.Count; var rementries = new List <SpawnerEntry>(); for (var i = 0; i < 13; i++) { var index = i * 5; var entryindex = m_Page * 13 + i; var cte = info.GetTextEntry(index); var mte = info.GetTextEntry(index + 1); var poste = info.GetTextEntry(index + 2); var parmte = info.GetTextEntry(index + 3); var propte = info.GetTextEntry(index + 4); if (cte == null) { continue; } var str = cte.Text.Trim().ToLower(); if (str.Length > 0) { var type = AssemblyHandler.FindFirstTypeForName(str); if (type == null) { from.SendMessage("{0} is not a valid type name for entry #{1}.", str, i); return; } SpawnerEntry entry; if (entryindex < ocount) { entry = spawner.Entries[entryindex]; entry.SpawnedName = str; if (mte != null) { entry.SpawnedMaxCount = Utility.ToInt32(mte.Text.Trim()); } if (poste != null) { entry.SpawnedProbability = Utility.ToInt32(poste.Text.Trim()); } } else { var maxcount = 1; var probcount = 100; if (mte != null) { maxcount = Utility.ToInt32(mte.Text.Trim()); } if (poste != null) { probcount = Utility.ToInt32(poste.Text.Trim()); } entry = spawner.AddEntry(str, probcount, maxcount); } if (parmte != null) { entry.Parameters = parmte.Text.Trim(); } if (propte != null) { entry.Properties = propte.Text.Trim(); } } else if (entryindex < ocount && spawner.Entries[entryindex] != null) { rementries.Add(spawner.Entries[entryindex]); } } for (var i = 0; i < rementries.Count; i++) { spawner.RemoveEntry(rementries[i]); } if (ocount == 0 && spawner.Entries.Count > 0) { spawner.Start(); } }
static MLQuestSystem() { Quests = new Dictionary <Type, MLQuest>(); QuestGivers = new Dictionary <Type, List <MLQuest> >(); Contexts = new Dictionary <PlayerMobile, MLQuestContext>(); string cfgPath = Path.Combine(Core.BaseDirectory, Path.Combine("Data", "MLQuests.cfg")); Type baseQuestType = typeof(MLQuest); Type baseQuesterType = typeof(IQuestGiver); if (File.Exists(cfgPath)) { using StreamReader sr = new StreamReader(cfgPath); string line; while ((line = sr.ReadLine()) != null) { if (line.Length == 0 || line.StartsWith("#")) { continue; } string[] split = line.Split('\t'); Type type = AssemblyHandler.FindFirstTypeForName(split[0]); if (type == null || !baseQuestType.IsAssignableFrom(type)) { if (Debug) { Console.WriteLine("Warning: {1} quest type '{0}'", split[0], type == null ? "Unknown" : "Invalid"); } continue; } MLQuest quest = null; try { quest = ActivatorUtil.CreateInstance(type) as MLQuest; } catch { // ignored } if (quest == null) { continue; } Register(type, quest); for (int i = 1; i < split.Length; ++i) { Type questerType = AssemblyHandler.FindFirstTypeForName(split[i]); if (questerType == null || !baseQuesterType.IsAssignableFrom(questerType)) { if (Debug) { Console.WriteLine("Warning: {1} quester type '{0}'", split[i], questerType == null ? "Unknown" : "Invalid"); } continue; } RegisterQuestGiver(quest, questerType); } } } }
public static void ProfileWorld(string type, string opFile) { try { var types = new List <Type>(); using (var bin = new BinaryReader( new FileStream( string.Format("Saves/{0}/{0}.tdb", type), FileMode.Open, FileAccess.Read, FileShare.Read ) )) { var count = bin.ReadInt32(); for (var i = 0; i < count; ++i) { types.Add(AssemblyHandler.FindFirstTypeForName(bin.ReadString())); } } long total = 0; var table = new Dictionary <Type, int>(); using (var bin = new BinaryReader( new FileStream( string.Format("Saves/{0}/{0}.idx", type), FileMode.Open, FileAccess.Read, FileShare.Read ) )) { var count = bin.ReadInt32(); for (var i = 0; i < count; ++i) { var typeID = bin.ReadInt32(); var serial = bin.ReadInt32(); var pos = bin.ReadInt64(); var length = bin.ReadInt32(); var objType = types[typeID]; while (objType != null && objType != typeof(object)) { table[objType] = length + (table.TryGetValue(objType, out var value) ? value : 0); objType = objType.BaseType; total += length; } } } var list = table.ToList(); list.Sort(new CountSorter()); using var op = new StreamWriter(opFile); op.WriteLine("# Profile of world {0}", type); op.WriteLine("# Generated on {0}", DateTime.UtcNow); op.WriteLine(); op.WriteLine(); list.ForEach( kvp => op.WriteLine("{0}\t{1:F2}%\t{2}", kvp.Value, 100.0 * kvp.Value / total, kvp.Key) ); } catch { // ignored } }
public static void Invoke( Mobile from, Point3D start, Point3D end, string[] args, List <Container> packs = null, bool outline = false, bool mapAvg = false ) { var sb = new StringBuilder(); sb.AppendFormat("{0} {1} building ", from.AccessLevel, CommandLogging.Format(from)); if (start == end) { sb.AppendFormat("at {0} in {1}", start, from.Map); } else { sb.AppendFormat("from {0} to {1} in {2}", start, end, from.Map); } sb.Append(':'); for (var i = 0; i < args.Length; ++i) { sb.AppendFormat(" \"{0}\"", args[i]); } CommandLogging.WriteLine(from, sb.ToString()); var name = args[0]; FixArgs(ref args); string[,] props = null; for (var i = 0; i < args.Length; ++i) { if (Insensitive.Equals(args[i], "set")) { var remains = args.Length - i - 1; if (remains >= 2) { props = new string[remains / 2, 2]; remains /= 2; for (var j = 0; j < remains; ++j) { props[j, 0] = args[i + j * 2 + 1]; props[j, 1] = args[i + j * 2 + 2]; } FixSetString(ref args, i); } break; } } var type = AssemblyHandler.FindFirstTypeForName(name); if (!IsEntity(type)) { from.SendMessage("No type with that name was found."); return; } var time = DateTime.UtcNow; var built = BuildObjects(from, type, start, end, args, props, packs, outline, mapAvg); if (built > 0) { from.SendMessage( "{0} object{1} generated in {2:F1} seconds.", built, built != 1 ? "s" : "", (DateTime.UtcNow - time).TotalSeconds ); } else { SendUsage(type, from); } }