-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
229 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
using System.Xml; | ||
using System.Xml.Serialization; | ||
using Newtonsoft.Json; | ||
using Scdb.Xml; | ||
using scdb.Xml.Entities; | ||
using scdb.Xml.Lootgeneration; | ||
|
||
namespace Loader | ||
{ | ||
public class LootLoader | ||
{ | ||
public string OutputFolder { get; set; } | ||
public string DataRoot { get; set; } | ||
|
||
public Dictionary<string, LootArchetype> LoadArchetypes() | ||
{ | ||
Directory.CreateDirectory(Path.Combine(OutputFolder, "loot")); | ||
Directory.CreateDirectory(Path.Combine(OutputFolder, "loot", "archetypes")); | ||
|
||
var output = new Dictionary<string, LootArchetype>(); | ||
|
||
|
||
var path = Path.Combine(DataRoot, Path.Join("Data", "Libs", "Foundry", "Records", "lootgeneration")); | ||
|
||
foreach (var entityFilename in Directory.EnumerateFiles(Path.Join(path, "lootarchetypes"), "*.xml")) | ||
{ | ||
var archetype = Parse<LootArchetype>(entityFilename); | ||
output.Add(archetype.__ref, archetype); | ||
File.WriteAllText(Path.Combine(OutputFolder, "loot", "archetypes", $"{archetype.ClassName.ToLower()}.json"), JsonConvert.SerializeObject(archetype)); | ||
} | ||
|
||
return output; | ||
} | ||
|
||
public Dictionary<string, LootTable> LoadTables() | ||
{ | ||
Directory.CreateDirectory(Path.Combine(OutputFolder, "loot")); | ||
Directory.CreateDirectory(Path.Combine(OutputFolder, "loot", "tables")); | ||
|
||
var output = new Dictionary<string, LootTable>(); | ||
|
||
var path = Path.Combine(DataRoot, Path.Join("Data", "Libs", "Foundry", "Records", "lootgeneration")); | ||
|
||
foreach (var entityFilename in Directory.EnumerateFiles(Path.Join(path, "loottables"), "*.xml", SearchOption.AllDirectories)) | ||
{ | ||
var lootTable = Parse<LootTable>(entityFilename); | ||
output.Add(lootTable.__ref, lootTable); | ||
File.WriteAllText(Path.Combine(OutputFolder, "loot", "tables", $"{lootTable.ClassName.ToLower()}.json"), JsonConvert.SerializeObject(lootTable)); | ||
} | ||
|
||
return output; | ||
} | ||
|
||
T Parse<T>(string xmlFilename) where T : ClassBase | ||
{ | ||
string rootNodeName; | ||
using (var reader = XmlReader.Create(new StreamReader(xmlFilename))) | ||
{ | ||
reader.MoveToContent(); | ||
rootNodeName = reader.Name; | ||
} | ||
|
||
var split = rootNodeName.Split('.'); | ||
string className = split[split.Length - 1]; | ||
|
||
var xml = File.ReadAllText(xmlFilename); | ||
var doc = new XmlDocument(); | ||
doc.LoadXml(xml); | ||
|
||
var serialiser = new XmlSerializer(typeof(T), new XmlRootAttribute { ElementName = rootNodeName }); | ||
using (var stream = new XmlNodeReader(doc)) | ||
{ | ||
var entity = (T)serialiser.Deserialize(stream); | ||
entity.ClassName = className; | ||
return entity; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Collections.Generic; | ||
using scdb.Xml.Lootgeneration; | ||
|
||
namespace Loader; | ||
|
||
public class LootService | ||
{ | ||
public Dictionary<string, LootArchetype> archetypes; | ||
public Dictionary<string, LootTable> tables; | ||
|
||
public LootService(Dictionary<string, LootArchetype> archetypes, Dictionary<string, LootTable> tables) | ||
{ | ||
this.archetypes = archetypes; | ||
this.tables = tables; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System.Xml; | ||
using System.Xml.Serialization; | ||
using scdb.Xml.Entities; | ||
|
||
namespace scdb.Xml.Lootgeneration | ||
{ | ||
public class LootArchetype: ClassBase | ||
{ | ||
public ExcludedTags excludedTags; | ||
|
||
public PrimaryOrGroup primaryOrGroup; | ||
public SecondaryOrGroups secondaryOrGroups; | ||
} | ||
|
||
|
||
public class ExcludedTags | ||
{ | ||
public Reference[] tags; | ||
} | ||
|
||
public class PrimaryOrGroup | ||
{ | ||
[XmlAttribute] public string __type; | ||
public LootArchetypeEntry_Primary[] entries; | ||
} | ||
|
||
|
||
public class SecondaryOrGroups | ||
{ | ||
public LootArchetypeOrGroup_Secondary LootArchetypeOrGroup_Secondary; | ||
} | ||
|
||
public class LootArchetypeEntry | ||
{ | ||
[XmlAttribute] public string name; | ||
[XmlAttribute] public string groupName; | ||
[XmlAttribute] public string tag; | ||
[XmlAttribute] public double weight; | ||
[XmlAttribute] public string __type; | ||
public AdditionalTags additionalTags; | ||
public OptionalData optionalData; | ||
} | ||
|
||
public class LootArchetypeEntry_Primary : LootArchetypeEntry; | ||
|
||
public class LootArchetypeEntry_Secondary | ||
{ | ||
[XmlAttribute] public string tag; | ||
[XmlAttribute] public double weight; | ||
[XmlAttribute] public string __type; | ||
}; | ||
|
||
public class LootArchetypeOrGroup_Secondary | ||
{ | ||
|
||
public LootArchetypeEntry_Secondary[] entries; | ||
}; | ||
|
||
public class OptionalData | ||
{ | ||
public EntryOptionalData_StackSize EntryOptionalData_StackSize; | ||
public EntryOptionalData_SpawnWith EntryOptionalData_SpawnWith; | ||
} | ||
|
||
public class EntryOptionalData_StackSize | ||
{ | ||
[XmlAttribute] public double min; | ||
[XmlAttribute] public double max; | ||
} | ||
|
||
public class EntryOptionalData_SpawnWith: EntryOptionalData_StackSize | ||
{ | ||
[XmlAttribute] public string name; | ||
[XmlAttribute] public string mode; | ||
|
||
public TagsToMatch tagsToMatch; | ||
} | ||
|
||
public class PnTags | ||
{ | ||
public Reference[] positiveTags; | ||
public Reference[] negativeTags; | ||
} | ||
|
||
public class AdditionalTags : PnTags; | ||
|
||
public class TagsToMatch : PnTags; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Xml; | ||
using System.Xml.Serialization; | ||
using scdb.Xml.Entities; | ||
|
||
namespace scdb.Xml.Lootgeneration | ||
{ | ||
public class LootTable: ClassBase | ||
{ | ||
public WeightedLootArchetype[] lootArchetypes; | ||
} | ||
|
||
public class WeightedLootArchetype | ||
{ | ||
[XmlAttribute] public string archetype; | ||
[XmlAttribute] public double weight; | ||
public NumberOfResultsConstraints numberOfResultsConstraints; | ||
} | ||
|
||
public class NumberOfResultsConstraints | ||
{ | ||
[XmlAttribute] public double minResults; | ||
[XmlAttribute] public double maxResults; | ||
|
||
} | ||
} |