Refactor PreceptDef_RequirementExtended into DefModExtension

This commit is contained in:
amevarashi 2022-06-05 16:23:42 +05:00
parent 11b427fe44
commit 80c4c34131
4 changed files with 29 additions and 19 deletions

View file

@ -1,10 +1,11 @@
using RimWorld;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Verse;
namespace RJWSexperience.Ideology
{
public class PreceptDef_RequirementExtended : PreceptDef
public class PreceptDefExtension_MultipleMemesRequired : DefModExtension
{
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public List<MemeDef> requiredAllMemes = new List<MemeDef>();

View file

@ -48,18 +48,23 @@ namespace RJWSexperience.Ideology
{
public static void Postfix(PreceptDef precept, bool checkDuplicates, ref IdeoFoundation __instance, ref AcceptanceReport __result)
{
if (precept is PreceptDef_RequirementExtended def && !def.requiredAllMemes.NullOrEmpty())
{
for (int i = 0; i < def.requiredAllMemes.Count; i++)
{
if (!__instance.ideo.memes.Contains(def.requiredAllMemes[i]))
{
List<string> report = new List<string>();
foreach (MemeDef meme in def.requiredAllMemes) report.Add(meme.LabelCap);
PreceptDefExtension_MultipleMemesRequired extension = precept.GetModExtension<PreceptDefExtension_MultipleMemesRequired>();
__result = new AcceptanceReport("RequiresMeme".Translate() + ": " + report.ToCommaList());
return;
}
if (extension == null)
return;
if (extension.requiredAllMemes.NullOrEmpty())
return;
for (int i = 0; i < extension.requiredAllMemes.Count; i++)
{
if (!__instance.ideo.memes.Contains(extension.requiredAllMemes[i]))
{
List<string> report = new List<string>();
foreach (MemeDef meme in extension.requiredAllMemes) report.Add(meme.LabelCap);
__result = new AcceptanceReport("RequiresMeme".Translate() + ": " + report.ToCommaList());
return;
}
}
}

View file

@ -46,7 +46,7 @@
<Compile Include="Ideology\GoodwillSituationWorker_MemeCompatibility.cs" />
<Compile Include="Harmony.cs" />
<Compile Include="Ideology\Keyed.cs" />
<Compile Include="Ideology\PreceptDef_RequirementExtended.cs" />
<Compile Include="Ideology\PreceptDefExtension_MultipleMemesRequired.cs" />
<Compile Include="Ideology\Rituals\JobGiver_GangbangConsensual.cs" />
<Compile Include="Ideology\Rituals\LordJob_Rituals.cs" />
<Compile Include="Ideology\RJW_Patch_Ideo.cs" />

View file

@ -48,7 +48,7 @@
</requiredMemes>
</PreceptDef>
<RJWSexperience.Ideology.PreceptDef_RequirementExtended>
<PreceptDef>
<defName>AnimalGangbangCeremony</defName>
<label>animal gangbang</label>
<description>A ritualistic gangbang where animals rape a victim.</description>
@ -65,11 +65,15 @@
<receivesExpectationsQualityOffset>true</receivesExpectationsQualityOffset>
<canGenerateAsSpecialPrecept>false</canGenerateAsSpecialPrecept>
<allowStackingRitualObligationAlerts>true</allowStackingRitualObligationAlerts>
<requiredAllMemes>
<li>Rapist</li>
<li>Zoophile</li>
</requiredAllMemes>
</RJWSexperience.Ideology.PreceptDef_RequirementExtended>
<modExtensions>
<li Class="RJWSexperience.Ideology.PreceptDefExtension_MultipleMemesRequired">
<requiredAllMemes>
<li>Rapist</li>
<li>Zoophile</li>
</requiredAllMemes>
</li>
</modExtensions>
</PreceptDef>
<PreceptDef>
<defName>AnimalGangbangCeremony_Consensual</defName>