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 RimWorld;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Verse;
namespace RJWSexperience.Ideology 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")] [SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public List<MemeDef> requiredAllMemes = new List<MemeDef>(); 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) public static void Postfix(PreceptDef precept, bool checkDuplicates, ref IdeoFoundation __instance, ref AcceptanceReport __result)
{ {
if (precept is PreceptDef_RequirementExtended def && !def.requiredAllMemes.NullOrEmpty()) PreceptDefExtension_MultipleMemesRequired extension = precept.GetModExtension<PreceptDefExtension_MultipleMemesRequired>();
{
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);
__result = new AcceptanceReport("RequiresMeme".Translate() + ": " + report.ToCommaList()); if (extension == null)
return; 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="Ideology\GoodwillSituationWorker_MemeCompatibility.cs" />
<Compile Include="Harmony.cs" /> <Compile Include="Harmony.cs" />
<Compile Include="Ideology\Keyed.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\JobGiver_GangbangConsensual.cs" />
<Compile Include="Ideology\Rituals\LordJob_Rituals.cs" /> <Compile Include="Ideology\Rituals\LordJob_Rituals.cs" />
<Compile Include="Ideology\RJW_Patch_Ideo.cs" /> <Compile Include="Ideology\RJW_Patch_Ideo.cs" />

View file

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