90 lines
4.2 KiB
C#
90 lines
4.2 KiB
C#
|
|
using RimWorld;
|
||
|
|
using Verse;
|
||
|
|
|
||
|
|
namespace BlaxLaws
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// One row of the lawbook. Holds only names and numbers, so a row whose entry is gone (a DLC drug
|
||
|
|
/// without its DLC, a removed mod's interaction) stays, shows "Needs <DLC>" or "Missing: <mod>"
|
||
|
|
/// and works again when the mod comes back (design: "Lawbook and cases in one GameComponent").
|
||
|
|
///
|
||
|
|
/// Read the fields freely; change a row only through Lawbook, which keeps the key unique and rebuilds
|
||
|
|
/// the Watch cache. Action (actKey), Option and Stage are the row's key.
|
||
|
|
/// </summary>
|
||
|
|
public class Law : IExposable
|
||
|
|
{
|
||
|
|
/// <summary>Unique in the save, never reused. 0 until Lawbook adds the row.</summary>
|
||
|
|
public int id;
|
||
|
|
|
||
|
|
/// <summary>The catalogue entry: "Ate/WakeUp", "Break/@anyDrugBinge" (ActKey).</summary>
|
||
|
|
public string actKey;
|
||
|
|
|
||
|
|
/// <summary>The entry's label when the row was written, shown while the entry is missing.</summary>
|
||
|
|
public string savedLabel;
|
||
|
|
|
||
|
|
/// <summary>The entry's source when the row was written: "Core", "Ideology" or a mod's name.</summary>
|
||
|
|
public string savedMod;
|
||
|
|
|
||
|
|
/// <summary>The entry's source package id when the row was written ("ludeon.rimworld.ideology").</summary>
|
||
|
|
public string savedPackageId;
|
||
|
|
|
||
|
|
/// <summary>Drug binge rows only: DrugOptions ("@any", "@hard", "@social" or a ChemicalDef defName). Null otherwise.</summary>
|
||
|
|
public string option;
|
||
|
|
|
||
|
|
public LawStage stage = LawStage.DidIt;
|
||
|
|
|
||
|
|
public LawSeverity severity = LawSeverity.Moderate;
|
||
|
|
|
||
|
|
/// <summary>The PunishmentDef's defName ("Warn", "Jail").</summary>
|
||
|
|
public string punishment = "Warn";
|
||
|
|
|
||
|
|
/// <summary>1 to 50; used by punishments with usesDays.</summary>
|
||
|
|
public int days = 3;
|
||
|
|
|
||
|
|
public bool enabled = true;
|
||
|
|
|
||
|
|
/// <summary>The category id, the first part of the act key.</summary>
|
||
|
|
public string CategoryId => ActKey.CategoryOf(actKey);
|
||
|
|
|
||
|
|
/// <summary>The catalogue entry, or null while it is missing.</summary>
|
||
|
|
public ActEntry Entry => ActCatalogue.Get(actKey);
|
||
|
|
|
||
|
|
public bool Resolves => Entry != null;
|
||
|
|
|
||
|
|
/// <summary>The punishment's def, or null when a later release's punishment was saved and is gone.</summary>
|
||
|
|
public PunishmentDef PunishmentDef => punishment.NullOrEmpty() ? null : DefDatabase<PunishmentDef>.GetNamedSilentFail(punishment);
|
||
|
|
|
||
|
|
/// <summary>The label the lawbook shows: the entry's, the saved one while missing, else the key.</summary>
|
||
|
|
public string Label => Entry?.label ?? (savedLabel.NullOrEmpty() ? actKey : savedLabel);
|
||
|
|
|
||
|
|
/// <summary>"Needs Ideology" or "Missing: Core" while the entry is missing, else null.</summary>
|
||
|
|
public string MissingText => Resolves ? null : DlcSupport.MissingText(savedMod, savedPackageId);
|
||
|
|
|
||
|
|
/// <summary>The sentence or guilt length in ticks.</summary>
|
||
|
|
public int DaysTicks => days * GenDate.TicksPerDay;
|
||
|
|
|
||
|
|
/// <summary>Whether this row has the given key (option compared as DrugOptions only for rows that keep one).</summary>
|
||
|
|
public bool HasKey(string key, string opt, LawStage stg) =>
|
||
|
|
actKey == key && stage == stg && Lawbook.NormalizeOption(option) == Lawbook.NormalizeOption(opt);
|
||
|
|
|
||
|
|
public void ExposeData()
|
||
|
|
{
|
||
|
|
Scribe_Values.Look(ref id, "id");
|
||
|
|
Scribe_Values.Look(ref actKey, "actKey");
|
||
|
|
Scribe_Values.Look(ref savedLabel, "savedLabel");
|
||
|
|
Scribe_Values.Look(ref savedMod, "savedMod");
|
||
|
|
Scribe_Values.Look(ref savedPackageId, "savedPackageId");
|
||
|
|
Scribe_Values.Look(ref option, "option");
|
||
|
|
Scribe_Values.Look(ref stage, "stage", LawStage.DidIt);
|
||
|
|
Scribe_Values.Look(ref severity, "severity", LawSeverity.Moderate);
|
||
|
|
Scribe_Values.Look(ref punishment, "punishment", "Warn");
|
||
|
|
Scribe_Values.Look(ref days, "days", 3);
|
||
|
|
Scribe_Values.Look(ref enabled, "enabled", true);
|
||
|
|
}
|
||
|
|
|
||
|
|
public override string ToString() =>
|
||
|
|
"Law " + id + " " + actKey + (option != null ? " [" + option + "]" : "") + " " + stage + " " + severity + " " + punishment +
|
||
|
|
(enabled ? "" : " (off)");
|
||
|
|
}
|
||
|
|
}
|