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

96 lines
2.5 KiB
C#
Raw Normal View History

2021-07-30 17:25:46 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RimWorld;
using Verse;
using rjw;
2021-08-21 16:29:59 +00:00
namespace RJWSexperience.Ideology
2021-07-30 17:25:46 +00:00
{
public class RitualOutcomeComp_HediffBased : RitualOutcomeComp_QualitySingleOffset
{
HediffDef hediffDef = null;
float minSeverity = 0;
string roleId = "";
protected override string LabelForDesc => label;
public override bool DataRequired => false;
public override bool Applies(LordJob_Ritual ritual)
{
Pawn victim = null;
foreach(RitualRole ritualRole in ritual.assignments.AllRolesForReading)
{
if (ritualRole != null && ritualRole.id.Contains(roleId))
{
victim = ritual.assignments.FirstAssignedPawn(ritualRole);
}
}
if (victim != null && hediffDef != null)
{
Hediff hediff = victim.health.hediffSet.GetFirstHediffOfDef(hediffDef);
if (hediff?.Severity >= minSeverity)
{
return true;
}
}
return false;
}
2021-09-12 08:54:15 +00:00
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
};
}
}
public class RitualOutcomeComp_NeedBased : RitualOutcomeComp_QualitySingleOffset
{
NeedDef needDef = null;
float minAvgNeed = 0;
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;
if (avgNeed >= minAvgNeed) return true;
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
};
}
}
}