165 lines
6.6 KiB
C#
165 lines
6.6 KiB
C#
using System;
|
|
using RimWorld;
|
|
using Verse;
|
|
|
|
namespace BlaxLaws
|
|
{
|
|
/// <summary>
|
|
/// Act keys: how the save names a catalogue entry. "Category/defName" for a single def
|
|
/// ("Ate/WakeUp", "Break/FireStartingSpree", "Special/SetFire"), "Category/@group" for a group
|
|
/// ("Ate/@humanMeat", "Break/@anyDrugBinge"). The category is an ActCategoryDef's defName, the group
|
|
/// id an ActGroup's id. Keys are only ever added, never renamed: a saved row names its entry by key.
|
|
/// </summary>
|
|
public static class ActKey
|
|
{
|
|
public const char Separator = '/';
|
|
public const string GroupPrefix = "@";
|
|
|
|
public static string Of(string categoryId, string name) => categoryId + Separator + name;
|
|
|
|
public static string Of(string categoryId, Def def) => Of(categoryId, def.defName);
|
|
|
|
/// <summary>A group key; the id may come with or without its "@".</summary>
|
|
public static string OfGroup(string categoryId, string groupId) =>
|
|
Of(categoryId, groupId.StartsWith(GroupPrefix) ? groupId : GroupPrefix + groupId);
|
|
|
|
/// <summary>"Ate" for "Ate/WakeUp", null for a key without a separator.</summary>
|
|
public static string CategoryOf(string key)
|
|
{
|
|
if (key.NullOrEmpty())
|
|
return null;
|
|
int i = key.IndexOf(Separator);
|
|
return i <= 0 ? null : key.Substring(0, i);
|
|
}
|
|
|
|
/// <summary>"WakeUp" for "Ate/WakeUp", "@humanMeat" for "Ate/@humanMeat", null for a key without a separator.</summary>
|
|
public static string NameOf(string key)
|
|
{
|
|
if (key.NullOrEmpty())
|
|
return null;
|
|
int i = key.IndexOf(Separator);
|
|
return i < 0 || i == key.Length - 1 ? null : key.Substring(i + 1);
|
|
}
|
|
|
|
public static bool IsGroup(string key) => NameOf(key)?.StartsWith(GroupPrefix) ?? false;
|
|
|
|
public static bool TryParse(string key, out string categoryId, out string name)
|
|
{
|
|
categoryId = CategoryOf(key);
|
|
name = NameOf(key);
|
|
return categoryId != null && name != null;
|
|
}
|
|
}
|
|
|
|
/// <summary>The categories' ids: the defNames of the ActCategoryDefs in Defs/BlaxLaws_Categories.xml.</summary>
|
|
public static class ActCategories
|
|
{
|
|
public const string Break = "Break";
|
|
public const string Ate = "Ate";
|
|
public const string Used = "Used";
|
|
public const string Interaction = "Interaction";
|
|
public const string RecordedAct = "RecordedAct";
|
|
public const string Record = "Record";
|
|
public const string Bill = "Bill";
|
|
public const string Special = "Special";
|
|
|
|
public static readonly string[] All = { Break, Ate, Used, Interaction, RecordedAct, Record, Bill, Special };
|
|
}
|
|
|
|
/// <summary>The special acts' ids: the defNames of the ActDefs in Defs/BlaxLaws_Acts.xml.</summary>
|
|
public static class SpecialActs
|
|
{
|
|
public const string SetFire = "SetFire";
|
|
public const string DisplayedCorpse = "DisplayedCorpse";
|
|
public const string StartedSocialFight = "StartedSocialFight";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Group ids the catalogue package registers (design: "Act catalogue and detection", the Groups column).
|
|
/// Each is unique within its category; the key is ActKey.OfGroup(category, id).
|
|
/// </summary>
|
|
public static class ActGroups
|
|
{
|
|
/// <summary>The category's "any": every entry of it. The least specific row.</summary>
|
|
public const string Any = "@any";
|
|
|
|
// Mental breaks
|
|
public const string AnyDrugBinge = "@anyDrugBinge";
|
|
public const string AnyTantrum = "@anyTantrum";
|
|
public const string AnyInsultingSpree = "@anyInsultingSpree";
|
|
public const string AnyAggressive = "@anyAggressive";
|
|
|
|
// Ate
|
|
public const string AnyDrug = "@anyDrug";
|
|
public const string HardDrugs = "@hardDrugs";
|
|
public const string SocialDrugs = "@socialDrugs";
|
|
public const string MedicalDrugs = "@medicalDrugs";
|
|
public const string AnyMeat = "@anyMeat";
|
|
public const string RawMeatOrCorpse = "@rawMeatOrCorpse";
|
|
public const string HumanMeat = "@humanMeat";
|
|
public const string InsectMeat = "@insectMeat";
|
|
public const string RawFood = "@rawFood";
|
|
public const string AnyMeal = "@anyMeal";
|
|
|
|
// Social interactions
|
|
public const string InsultOrSlight = "@insultOrSlight";
|
|
|
|
// Bills
|
|
public const string AnySurgery = "@anySurgery";
|
|
}
|
|
|
|
/// <summary>
|
|
/// The option of a drug binge row: which drug counts. "@any", "@hard", "@social", or a ChemicalDef's
|
|
/// defName. Rows of other entries keep a null option.
|
|
/// </summary>
|
|
public static class DrugOptions
|
|
{
|
|
public const string Any = "@any";
|
|
public const string Hard = "@hard";
|
|
public const string Social = "@social";
|
|
|
|
/// <summary>Null and "" read as Any.</summary>
|
|
public static string Normalize(string option) => option.NullOrEmpty() ? Any : option;
|
|
|
|
/// <summary>
|
|
/// The option's rank for "the most specific row wins": one chemical 3, hard or social 2, any 1.
|
|
/// </summary>
|
|
public static int Rank(string option)
|
|
{
|
|
string o = Normalize(option);
|
|
if (o == Any)
|
|
return 1;
|
|
return o == Hard || o == Social ? 2 : 3;
|
|
}
|
|
|
|
/// <summary>Whether the dose (or the binge's chosen chemical) in the act counts under the option.</summary>
|
|
public static bool Matches(string option, ActEvent act)
|
|
{
|
|
string o = Normalize(option);
|
|
if (o == Any)
|
|
return true;
|
|
if (act == null)
|
|
return false;
|
|
if (o == Hard)
|
|
return act.drugCategory == DrugCategory.Hard;
|
|
if (o == Social)
|
|
return act.drugCategory == DrugCategory.Social;
|
|
return act.chemical != null && act.chemical.defName == o;
|
|
}
|
|
|
|
/// <summary>The option's label: "Any drug", "Hard drugs", "Social drugs" or the chemical's label.</summary>
|
|
public static string Label(string option)
|
|
{
|
|
string o = Normalize(option);
|
|
if (o == Any)
|
|
return "BlaxLaws_DrugOption_Any".Translate();
|
|
if (o == Hard)
|
|
return "BlaxLaws_DrugOption_Hard".Translate();
|
|
if (o == Social)
|
|
return "BlaxLaws_DrugOption_Social".Translate();
|
|
ChemicalDef chem = DefDatabase<ChemicalDef>.GetNamedSilentFail(o);
|
|
return chem != null ? chem.LabelCap.ToString() : o;
|
|
}
|
|
}
|
|
}
|