public static void Serialize(XmlWriter xWrite, LootSet contents) { XmlSerializer Writer = new XmlSerializer(contents.GetType()); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", "http://www.hybrasyl.com/XML/Loot"); Writer.Serialize(xWrite, contents, ns); }
public static Loot CalculateLoot(LootSet set, int rolls, float chance) { var loot = new Loot(0, 0); var tables = new List <LootTable>(); // If rolls == 0, all tables fire if (rolls == 0) { tables.AddRange(set.Table); GameLog.SpawnInfo("Processing loot set {Name}: set rolls == 0, looting", set.Name); } for (var x = 0; x < rolls; x++) { if (Roll() <= chance) { GameLog.SpawnInfo("Processing loot set {Name}: set hit, looting", set.Name); // Ok, the set fired. Check the subtables, which can have independent chances. // If no chance is present, we simply award something from each table in the set. // Note that we do table processing last! We just find the tables that fire here. foreach (var setTable in set.Table) { // Rolls == 0 (default) means the table is automatically used. if (setTable.Rolls == 0) { tables.Add(setTable); GameLog.SpawnInfo("Processing loot set {Name}: setTable rolls == 0, looting", set.Name); continue; } // Did the subtable hit? for (var y = 0; y < setTable.Rolls; y++) { if (!(Roll() <= setTable.Chance)) { continue; } tables.Add(setTable); GameLog.SpawnInfo("Processing loot set {Name}: set subtable hit, looting ", set.Name); } } } else { GameLog.SpawnInfo("Processing loot set {Name}: Set subtable missed", set.Name); } } return(tables.Aggregate(loot, (current, table) => current + CalculateTable(table))); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } LootSet = await _context.LootSets.FindAsync(id); if (LootSet == null) { return(NotFound()); } return(Page()); }
public static LootSet Deserialize(XmlReader reader, LootSet contents = null) { //reader.Settings.IgnoreWhitespace = false; if (contents == null) { contents = new LootSet(); } XmlSerializer XmlSerial = new XmlSerializer(contents.GetType()); if (XmlSerial.CanDeserialize(reader)) { var xContents = XmlSerial.Deserialize(reader); contents = (LootSet)xContents; } return(contents); }
// To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD public async Task <IActionResult> OnPostAsync() { var emptyLootSet = new LootSet(); if (await TryUpdateModelAsync <LootSet>( emptyLootSet, "lootset", // Prefix for form value. d => d.Name, d => d.Description)) { _context.LootSets.Add(emptyLootSet); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } return(Page()); }