public RareAddonDeed(string name, string sourcefile) { Name = name; SourceFile = sourcefile; RareAddonEntry test = RareSystem.GetRareAddonEntry(name, sourcefile); if (test == null) { // specification in file not found Delete(); } }
public override void Deserialize(GenericReader reader) { base.Deserialize(reader); // must have all files parsed first if (RareSystem.ParsedFiles == null) { RareSystem.LoadRareConfigs(); } int version = reader.ReadEncodedInt(); SourceFile = reader.ReadString(); RareAddonEntry rareAddonEntry = RareSystem.GetRareAddonEntry(Name, SourceFile); if (rareAddonEntry == null) { // specification in file not found Delete(); } }
public RareAddon(string name, string sourcefile) { Name = name; SourceFile = sourcefile; RareAddonEntry rareAddonEntry = RareSystem.GetRareAddonEntry(name, sourcefile); if (rareAddonEntry == null) { // specification in file not found Delete(); return; } foreach (RareAddonComponentEntry component in rareAddonEntry.Components) { AddonComponent newAddonComponent = new AddonComponent(component.ItemID) { Hue = component.Hue, Visible = component.Visible }; AddComponent(newAddonComponent, component.X, component.Y, component.Z); } RaresFile.AddScriptAttachments(this, rareAddonEntry.ScriptFiles); }
public RaresFile(string sourceFile) { SourceFile = sourceFile; try { StreamReader file = new StreamReader(RareSystem.RaresFolder + Path.DirectorySeparatorChar + SourceFile); string line = null; int lineNumber = 0; while ((line = file.ReadLine()) != null) { lineNumber++; line = line.Trim(); if (line.StartsWith("#") || line == String.Empty || line.Length == 0) { continue; } int commentIndex = line.IndexOf('#'); if (commentIndex != -1) { line = line.Substring(0, commentIndex); } int entrySpawnProbability = 1; var scriptFiles = new List <string>(); int scriptIndex = line.IndexOf('$'); // |5234 0x38 $10 alan\ps\go.txt #apple ... 10 is the entrySpawnProbability (10x as probable spawning as no weighting or empty, must come first after $, and then scripts) if (scriptIndex != -1) { string scriptLine = line.Substring(scriptIndex + 1); line = line.Substring(0, scriptIndex); var split = scriptLine.Split(); int newSpawnProbability = 1; foreach (string t in split) { if (t == string.Empty) { continue; } if (newSpawnProbability == 1) // not assigned yet { try { newSpawnProbability = int.Parse(t); // successfully got an int } catch // it's a script string { scriptFiles.Add(t); } } else { // assume it's a script string if newSpawnProbability already been found scriptFiles.Add(t); } } entrySpawnProbability = newSpawnProbability; } var args = line.Split('|'); try { if (args.Length == 1) { throw new Exception( "Rares entry \"" + line + "\" in " + SourceFile + " line number " + lineNumber + " did not have at least a single | character!"); } string name = args[0].Trim(); if (name == "") { name = null; } if (args.Length == 2) { // it's a single item rare var itemArgs = (args[1].Trim()).Split(); int itemID = itemArgs[0].StartsWith("0x") ? Convert.ToInt32(itemArgs[0].Substring(2), 16) : int.Parse(itemArgs[0]); int hue = itemArgs.Length > 1 ? (itemArgs[1].StartsWith("0x") ? Convert.ToInt32(itemArgs[1].Substring(2), 16) : int.Parse(itemArgs[1])) : 0; Rares.Add(new RareEntry(name, itemID, hue, entrySpawnProbability, scriptFiles)); } else { // it's an addon RareAddonEntry newAddonEntry = new RareAddonEntry(name, SourceFile, entrySpawnProbability, scriptFiles); for (int i = 1; i < args.Length; i++) { var componentArgs = (args[i].Trim()).Split(); newAddonEntry.AddAddonComponentEntry(componentArgs); } RareAddons.Add(newAddonEntry); } } catch (Exception e) { string msg = DateTime.UtcNow + ": ERROR on line number " + lineNumber + ": " + e.Message; Console.WriteLine(msg); //LoggingCustom.Log("ERROR-RareSystem.txt", msg); } } file.Close(); } catch { //LoggingCustom.Log("ERROR-RareSystem.txt", DateTime.UtcNow + ": ERROR: " + e.Message); } }
public RareAddonDeed(RareAddonEntry entry) { SourceFile = entry.SourceFile; Name = entry.Name; }
public RaresFile(string sourceFile) { SourceFile = sourceFile; try { StreamReader file = new StreamReader(RareSystem.RaresFolder + Path.DirectorySeparatorChar + SourceFile); string line = null; int lineNumber = 0; while ((line = file.ReadLine()) != null) { lineNumber++; line = line.Trim(); if (line.StartsWith("#") || line == String.Empty || line.Length == 0) { continue; } int commentIndex = line.IndexOf('#'); if (commentIndex != -1) { line = line.Substring(0, commentIndex); } int entrySpawnProbability = 1; var scriptFiles = new List<string>(); int scriptIndex = line.IndexOf('$'); // |5234 0x38 $10 alan\ps\go.txt #apple ... 10 is the entrySpawnProbability (10x as probable spawning as no weighting or empty, must come first after $, and then scripts) if (scriptIndex != -1) { string scriptLine = line.Substring(scriptIndex + 1); line = line.Substring(0, scriptIndex); var split = scriptLine.Split(); int newSpawnProbability = 1; foreach (string t in split) { if (t == string.Empty) { continue; } if (newSpawnProbability == 1) // not assigned yet { try { newSpawnProbability = int.Parse(t); // successfully got an int } catch // it's a script string { scriptFiles.Add(t); } } else { // assume it's a script string if newSpawnProbability already been found scriptFiles.Add(t); } } entrySpawnProbability = newSpawnProbability; } var args = line.Split('|'); try { if (args.Length == 1) { throw new Exception( "Rares entry \"" + line + "\" in " + SourceFile + " line number " + lineNumber + " did not have at least a single | character!"); } string name = args[0].Trim(); if (name == "") { name = null; } if (args.Length == 2) { // it's a single item rare var itemArgs = (args[1].Trim()).Split(); int itemID = itemArgs[0].StartsWith("0x") ? Convert.ToInt32(itemArgs[0].Substring(2), 16) : int.Parse(itemArgs[0]); int hue = itemArgs.Length > 1 ? (itemArgs[1].StartsWith("0x") ? Convert.ToInt32(itemArgs[1].Substring(2), 16) : int.Parse(itemArgs[1])) : 0; Rares.Add(new RareEntry(name, itemID, hue, entrySpawnProbability, scriptFiles)); } else { // it's an addon RareAddonEntry newAddonEntry = new RareAddonEntry(name, SourceFile, entrySpawnProbability, scriptFiles); for (int i = 1; i < args.Length; i++) { var componentArgs = (args[i].Trim()).Split(); newAddonEntry.AddAddonComponentEntry(componentArgs); } RareAddons.Add(newAddonEntry); } } catch (Exception e) { string msg = DateTime.UtcNow + ": ERROR on line number " + lineNumber + ": " + e.Message; Console.WriteLine(msg); //LoggingCustom.Log("ERROR-RareSystem.txt", msg); } } file.Close(); } catch { //LoggingCustom.Log("ERROR-RareSystem.txt", DateTime.UtcNow + ": ERROR: " + e.Message); } }