using RimWorld;
using Verse;
namespace BlaxLaws
{
///
/// 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.
///
public class Law : IExposable
{
/// Unique in the save, never reused. 0 until Lawbook adds the row.
public int id;
/// The catalogue entry: "Ate/WakeUp", "Break/@anyDrugBinge" (ActKey).
public string actKey;
/// The entry's label when the row was written, shown while the entry is missing.
public string savedLabel;
/// The entry's source when the row was written: "Core", "Ideology" or a mod's name.
public string savedMod;
/// The entry's source package id when the row was written ("ludeon.rimworld.ideology").
public string savedPackageId;
/// Drug binge rows only: DrugOptions ("@any", "@hard", "@social" or a ChemicalDef defName). Null otherwise.
public string option;
public LawStage stage = LawStage.DidIt;
public LawSeverity severity = LawSeverity.Moderate;
/// The PunishmentDef's defName ("Warn", "Jail").
public string punishment = "Warn";
/// 1 to 50; used by punishments with usesDays.
public int days = 3;
public bool enabled = true;
/// The category id, the first part of the act key.
public string CategoryId => ActKey.CategoryOf(actKey);
/// The catalogue entry, or null while it is missing.
public ActEntry Entry => ActCatalogue.Get(actKey);
public bool Resolves => Entry != null;
/// The punishment's def, or null when a later release's punishment was saved and is gone.
public PunishmentDef PunishmentDef => punishment.NullOrEmpty() ? null : DefDatabase.GetNamedSilentFail(punishment);
/// The label the lawbook shows: the entry's, the saved one while missing, else the key.
public string Label => Entry?.label ?? (savedLabel.NullOrEmpty() ? actKey : savedLabel);
/// "Needs Ideology" or "Missing: Core" while the entry is missing, else null.
public string MissingText => Resolves ? null : DlcSupport.MissingText(savedMod, savedPackageId);
/// The sentence or guilt length in ticks.
public int DaysTicks => days * GenDate.TicksPerDay;
/// Whether this row has the given key (option compared as DrugOptions only for rows that keep one).
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)");
}
}