4 using System.Collections.Generic;
9 internal abstract class TalentMigration
11 private readonly Version version;
13 private delegate TalentMigration TalentMigrationCtor(Version version, ContentXElement element);
15 private static readonly Dictionary<Identifier, TalentMigrationCtor> migrationTemplates =
18 [
new Identifier(
"AddStat")] =
19 static (version, element) =>
new TalentMigrationAddStat(version, element),
21 [
new Identifier(
"UpdateStatIdentifier")] =
22 static (version, element) =>
new TalentMigrationUpdateStatIdentifier(version, element)
25 public bool TryApply(Version savedVersion, CharacterInfo info)
27 if (version <= savedVersion) {
return false; }
32 protected abstract void Apply(CharacterInfo info);
34 protected TalentMigration(Version targetVersion)
36 version = targetVersion;
39 public static TalentMigration FromXML(ContentXElement element)
41 Version? version = XMLExtensions.GetAttributeVersion(element,
"version",
null);
45 throw new Exception(
"Talent migration version not defined.");
48 Identifier name = element.Name.ToString().ToIdentifier();
50 if (!migrationTemplates.TryGetValue(name, out TalentMigrationCtor? ctor))
52 throw new Exception($
"Unknown talent migration type: {name}.");
55 return ctor(version, element);
62 internal sealed
class TalentMigrationAddStat : TalentMigration
68 public Identifier StatIdentifier {
get;
set; }
71 public float Value {
get;
set; }
74 public bool RemoveOnDeath {
get;
set; }
76 public TalentMigrationAddStat(Version targetVersion, ContentXElement element) : base(targetVersion)
77 => SerializableProperty.DeserializeProperties(this, element);
79 protected override void Apply(CharacterInfo info)
81 info.ChangeSavedStatValue(StatType, Value, StatIdentifier, RemoveOnDeath);
88 internal class TalentMigrationUpdateStatIdentifier : TalentMigration
91 public Identifier Old {
get;
set; }
94 public Identifier New {
get;
set; }
96 public TalentMigrationUpdateStatIdentifier(Version targetVersion, ContentXElement element) : base(targetVersion)
97 => SerializableProperty.DeserializeProperties(this, element);
99 protected override void Apply(CharacterInfo info)
101 foreach (SavedStatValue statValue
in info.SavedStatValues.Values.SelectMany(
static s => s))
103 if (statValue.StatIdentifier != Old) {
continue; }
105 statValue.StatIdentifier = New;
StatTypes
StatTypes are used to alter several traits of a character. They are mostly used by talents.