using System.Collections.Generic;
using Verse;
namespace BlaxLaws
{
///
/// One entry of the act catalogue: a single def or a group. Built once per game start by ActCatalogue
/// from the category workers; never saved (rows save the key). The worker fills key, category, def or
/// group, label and source; ActCatalogue.Build fills the stage and break fields from the link table.
///
public class ActEntry
{
/// "Ate/WakeUp" or "Ate/@hardDrugs".
public string key;
public string categoryId;
/// The def's defName, or the group id with its "@".
public string name;
/// The def of a single entry; null for a group.
public Def def;
/// The group of a group entry; null for a single def.
public ActGroup group;
/// What the picker and the row show.
public string label;
/// "Core", the DLC's name or the mod's name.
public string sourceMod;
/// The source's package id, lower case.
public string sourcePackageId;
/// Break entries: a planning stage (always, for a break).
public bool hasPlanning;
/// A did-it stage: every entry outside the breaks, and a break with a link.
public bool hasDidIt = true;
/// A break hostile to the colony (berserk): no Subdue. For a group: every member is hostile.
public bool hostileBreak;
/// A drug binge entry: rows keep a drug option.
public bool hasDrugOption;
/// Break entries: the links of the entry's breaks (one for a def, the distinct links of its members for a group).
public List links = new List();
public bool IsGroup => group != null;
public bool IsBreak => categoryId == ActCategories.Break;
/// Rank for "the most specific row wins": a single def 3, a group 2, the category's "any" 1.
public int Rank => def != null ? 3 : group != null && !group.IsAny ? 2 : 1;
/// The stages the entry offers, planning first.
public IEnumerable Stages
{
get
{
if (hasPlanning)
yield return LawStage.Planning;
if (hasDidIt)
yield return LawStage.DidIt;
}
}
public bool HasStage(LawStage stage) => stage == LawStage.Planning ? hasPlanning : hasDidIt;
/// The stage a new row gets.
public LawStage FirstStage => hasPlanning ? LawStage.Planning : LawStage.DidIt;
/// Whether the act is this entry's: the same def, or a member of the group.
public bool Matches(ActEvent act)
{
if (act == null || act.categoryId != categoryId)
return false;
if (group != null)
return group.Matches(act);
return act.def != null && (act.def == def || act.def.defName == name);
}
// ---- builders for the category workers -------------------------------------------------
/// A single-def entry with the def's label and source mod.
public static ActEntry ForDef(string categoryId, Def def, string label = null)
{
return new ActEntry
{
key = ActKey.Of(categoryId, def.defName),
categoryId = categoryId,
name = def.defName,
def = def,
label = !label.NullOrEmpty() ? label : !def.label.NullOrEmpty() ? def.LabelCap.ToString() : def.defName,
sourceMod = DlcSupport.SourceName(def.modContentPack),
sourcePackageId = DlcSupport.SourcePackageId(def.modContentPack),
};
}
/// A group entry. Groups are Laws' own, so their source is Core.
public static ActEntry ForGroup(ActGroup group, string label = null)
{
return new ActEntry
{
key = group.Key,
categoryId = group.categoryId,
name = group.id,
group = group,
label = label.NullOrEmpty() ? group.Label : label,
sourceMod = DlcSupport.CoreName,
sourcePackageId = DlcSupport.CorePackageId,
};
}
public override string ToString() => key + " (" + label + ", " + sourceMod + ")";
}
}