RJW-Sexperience/RJWSexperience/IdeologyAddon/Ideology/Rituals/RitualOutcomeComps.cs

87 lines
3 KiB
C#
Raw Normal View History

2022-04-15 16:46:29 +00:00
using RimWorld;
using System.Diagnostics.CodeAnalysis;
2021-07-30 17:25:46 +00:00
using Verse;
2021-08-21 16:29:59 +00:00
namespace RJWSexperience.Ideology
2021-07-30 17:25:46 +00:00
{
2022-04-15 16:46:29 +00:00
public class RitualOutcomeComp_HediffBased : RitualOutcomeComp_QualitySingleOffset
{
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public HediffDef hediffDef = null;
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public float minSeverity = 0;
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public string roleId = "";
2021-07-30 17:25:46 +00:00
2022-04-15 16:46:29 +00:00
protected override string LabelForDesc => label;
public override bool DataRequired => false;
2021-07-30 17:25:46 +00:00
public override bool Applies(LordJob_Ritual ritual)
{
Pawn victim = null;
2022-04-15 16:46:29 +00:00
foreach (RitualRole ritualRole in ritual.assignments.AllRolesForReading)
{
if (ritualRole?.id.Contains(roleId) == true)
2021-07-30 17:25:46 +00:00
{
victim = ritual.assignments.FirstAssignedPawn(ritualRole);
}
}
if (victim != null && hediffDef != null)
2022-04-15 16:46:29 +00:00
{
2021-07-30 17:25:46 +00:00
Hediff hediff = victim.health.hediffSet.GetFirstHediffOfDef(hediffDef);
if (hediff?.Severity >= minSeverity)
2022-04-15 16:46:29 +00:00
{
2021-07-30 17:25:46 +00:00
return true;
2022-04-15 16:46:29 +00:00
}
}
2021-07-30 17:25:46 +00:00
return false;
}
2021-09-12 08:54:15 +00:00
public override ExpectedOutcomeDesc GetExpectedOutcomeDesc(Precept_Ritual ritual, TargetInfo ritualTarget, RitualObligation obligation, RitualRoleAssignments assignments, RitualOutcomeComp_Data data)
2021-07-30 17:25:46 +00:00
{
return new ExpectedOutcomeDesc
{
label = LabelForDesc.CapitalizeFirst(),
present = false,
uncertainOutcome = true,
effect = ExpectedOffsetDesc(true, -1f),
quality = qualityOffset,
positive = true
};
}
}
public class RitualOutcomeComp_NeedBased : RitualOutcomeComp_QualitySingleOffset
{
2022-04-15 16:46:29 +00:00
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public NeedDef needDef = null;
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public float minAvgNeed = 0;
2021-07-30 17:25:46 +00:00
protected override string LabelForDesc => label;
public override bool DataRequired => false;
public override bool Applies(LordJob_Ritual ritual)
{
float avgNeed = 0;
foreach (Pawn pawn in ritual.assignments.AllPawns)
{
avgNeed += pawn.needs?.TryGetNeed(needDef)?.CurLevel ?? 0f;
}
avgNeed /= ritual.assignments.AllPawns.Count;
2022-04-15 16:46:29 +00:00
return avgNeed >= minAvgNeed;
2021-07-30 17:25:46 +00:00
}
2021-09-12 08:54:15 +00:00
public override ExpectedOutcomeDesc GetExpectedOutcomeDesc(Precept_Ritual ritual, TargetInfo ritualTarget, RitualObligation obligation, RitualRoleAssignments assignments, RitualOutcomeComp_Data data)
2021-07-30 17:25:46 +00:00
{
return new ExpectedOutcomeDesc
{
label = LabelForDesc.CapitalizeFirst(),
present = false,
uncertainOutcome = true,
effect = ExpectedOffsetDesc(true, -1f),
quality = qualityOffset,
positive = true
};
}
}
}