This commit is contained in:
ProjectKoi-Kalo\Kalo 2025-07-03 17:50:31 +08:00
parent a41d8608dc
commit 1574d92416
229 changed files with 37931 additions and 2 deletions

View File

@ -128,7 +128,7 @@
<label>Maintenance (required)</label>
<description>I can't move my body well.</description>
<baseMoodEffect>-5</baseMoodEffect>
</li>
</li>
<li>
<visible>false</visible>
</li>
@ -136,7 +136,7 @@
<label>Maintenance (flawless)</label>
<description>I feel like I'm made new!</description>
<baseMoodEffect>5</baseMoodEffect>
</li>
</li>
</stages>
</ThoughtDef>
</Defs>

View File

@ -0,0 +1,530 @@
<?xml version="1.0" encoding="utf-8"?>
<Defs>
<!--오토마톤 메크링크-->
<ThingDef ParentName="MechanitorImplantBase">
<defName>PN_Mechlink</defName>
<label>automaton mechlink</label>
<description>This is a modified mechlink for automaton.</description>
<thingClass>Mechlink</thingClass>
<descriptionHyperlinks>
<HediffDef>MechlinkImplant</HediffDef>
</descriptionHyperlinks>
<statBases>
<MaxHitPoints>100</MaxHitPoints>
<Beauty>-4</Beauty>
<Mass>1</Mass>
<MarketValue>500</MarketValue>
<DeteriorationRate>0</DeteriorationRate>
</statBases>
<graphicData>
<texPath>Things/Pawn/Humanlike/Apparel/Mechlink</texPath>
<graphicClass>Graphic_Single</graphicClass>
<drawSize>0.65</drawSize>
</graphicData>
<comps>
<li Class="CompProperties_Forbiddable" />
<li Class="CompProperties_Usable">
<compClass>CompUsableImplant</compClass>
<useJob>InstallMechlink</useJob>
<useLabel>Install {0_label} to become mechanitor</useLabel>
</li>
<li Class="CompProperties_UseEffectInstallImplant">
<compClass>CompUseEffect_InstallImplantMechlink</compClass>
<hediffDef>MechlinkImplant</hediffDef>
<bodyPart>PNBrain</bodyPart>
<requiresPsychicallySensitive>true</requiresPsychicallySensitive>
</li>
<li Class="CompProperties_UseEffectPlaySound">
<soundOnUsed>MechlinkInstalled</soundOnUsed>
</li>
</comps>
</ThingDef>
<RecipeDef>
<defName>PN_Make_Mechlink_Automaton</defName>
<label>make automaton mechlink</label>
<description>make automaton mechlink</description>
<jobString>Making automaton mechlink.</jobString>
<workSpeedStat>GeneralLaborSpeed</workSpeedStat>
<effectWorking>Cook</effectWorking>
<soundWorking>Recipe_Machining</soundWorking>
<workAmount>2000</workAmount>
<allowMixingIngredients>true</allowMixingIngredients>
<recipeUsers>
<li>PN_AutomatonBench</li>
</recipeUsers>
<ingredients>
<li>
<filter>
<thingDefs>
<li>Mechlink</li>
</thingDefs>
</filter>
<count>1</count>
</li>
<li>
<filter>
<thingDefs>
<li>ComponentIndustrial</li>
</thingDefs>
</filter>
<count>2</count>
</li>
</ingredients>
<products>
<PN_Mechlink>1</PN_Mechlink>
</products>
<skillRequirements>
<Crafting>6</Crafting>
</skillRequirements>
<workSkill>Crafting</workSkill>
<researchPrerequisite>PNRP_Mechlink</researchPrerequisite>
</RecipeDef>
<!--오토마톤 서브링크-->
<ThingDef Abstract="True" Name="PN_MechanitorImplantBase" ParentName="MechanitorImplantBase">
<statBases>
<MaxHitPoints>100</MaxHitPoints>
<Beauty>-4</Beauty>
<Mass>1</Mass>
<MarketValue>1200</MarketValue>
<DeteriorationRate>0</DeteriorationRate>
<WorkToMake>3200</WorkToMake>
</statBases>
<graphicData>
<texPath>Things/Item/Health/HealthItem</texPath>
<graphicClass>Graphic_Single</graphicClass>
<drawSize>0.80</drawSize>
<color>(247,180,130)</color>
</graphicData>
<comps>
<li Class="CompProperties_Forbiddable"/>
</comps>
<tradeability>None</tradeability>
</ThingDef>
<ThingDef Abstract="True" Name="PN_ControlSublinkBase" ParentName="PN_MechanitorImplantBase">
<descriptionHyperlinks>
<HediffDef>ControlSublinkImplant</HediffDef>
</descriptionHyperlinks>
<statBases>
<MaxInstallCount>3</MaxInstallCount>
</statBases>
</ThingDef>
<ThingDef ParentName="PN_ControlSublinkBase">
<defName>PN_ControlSublink</defName>
<label>automaton control sublink (standard)</label>
<description>This is a modified control sublink (standard) for automaton.</description>
<costList>
<SignalChip>1</SignalChip>
<ComponentIndustrial>4</ComponentIndustrial>
</costList>
<comps>
<li Class="CompProperties_Usable">
<compClass>CompUsableImplant</compClass>
<useJob>UseItem</useJob>
<useLabel>Implant sublink</useLabel>
<userMustHaveHediff>MechlinkImplant</userMustHaveHediff>
</li>
<li Class="CompProperties_UseEffectInstallImplant">
<hediffDef>ControlSublinkImplant</hediffDef>
<bodyPart>PNBrain</bodyPart>
<canUpgrade>true</canUpgrade>
<maxSeverity>3</maxSeverity>
</li>
</comps>
</ThingDef>
<ThingDef ParentName="PN_ControlSublinkBase">
<defName>PN_ControlSublinkHigh</defName>
<label>automaton control sublink (high)</label>
<description>This is a modified control sublink (high) for automaton.</description>
<costList>
<PowerfocusChip>1</PowerfocusChip>
<ComponentIndustrial>3</ComponentIndustrial>
<ComponentSpacer>3</ComponentSpacer>
</costList>
<comps>
<li Class="CompProperties_Usable">
<compClass>CompUsableImplant</compClass>
<useJob>UseItem</useJob>
<useLabel>Implant high sublink</useLabel>
<userMustHaveHediff>MechlinkImplant</userMustHaveHediff>
</li>
<li Class="CompProperties_UseEffectInstallImplant">
<hediffDef>ControlSublinkImplant</hediffDef>
<bodyPart>PNBrain</bodyPart>
<canUpgrade>true</canUpgrade>
<requiresExistingHediff>true</requiresExistingHediff>
<minSeverity>3</minSeverity>
</li>
</comps>
</ThingDef>
<RecipeDef>
<defName>PN_Make_ControlSublink_Automaton</defName>
<label>make automaton sublink (standard)</label>
<description>make automaton sublink</description>
<jobString>Making automaton sublink.</jobString>
<workSpeedStat>GeneralLaborSpeed</workSpeedStat>
<effectWorking>Cook</effectWorking>
<soundWorking>Recipe_Machining</soundWorking>
<workAmount>2000</workAmount>
<allowMixingIngredients>true</allowMixingIngredients>
<recipeUsers>
<li>PN_AutomatonBench</li>
</recipeUsers>
<ingredients>
<li>
<filter>
<thingDefs>
<li>ControlSublink</li>
</thingDefs>
</filter>
<count>1</count>
</li>
<li>
<filter>
<thingDefs>
<li>ComponentIndustrial</li>
</thingDefs>
</filter>
<count>2</count>
</li>
</ingredients>
<products>
<PN_ControlSublink>1</PN_ControlSublink>
</products>
<skillRequirements>
<Crafting>6</Crafting>
</skillRequirements>
<workSkill>Crafting</workSkill>
<researchPrerequisite>PNRP_Mechlink</researchPrerequisite>
</RecipeDef>
<RecipeDef>
<defName>PN_Make_PN_ControlSublinkHigh_Automaton</defName>
<label>make automaton sublink (high)</label>
<description>make automaton sublink</description>
<jobString>Making automaton sublink.</jobString>
<workSpeedStat>GeneralLaborSpeed</workSpeedStat>
<effectWorking>Cook</effectWorking>
<soundWorking>Recipe_Machining</soundWorking>
<workAmount>2000</workAmount>
<allowMixingIngredients>true</allowMixingIngredients>
<recipeUsers>
<li>PN_AutomatonBench</li>
</recipeUsers>
<ingredients>
<li>
<filter>
<thingDefs>
<li>ControlSublinkHigh</li>
</thingDefs>
</filter>
<count>1</count>
</li>
<li>
<filter>
<thingDefs>
<li>ComponentIndustrial</li>
</thingDefs>
</filter>
<count>2</count>
</li>
</ingredients>
<products>
<PN_ControlSublinkHigh>1</PN_ControlSublinkHigh>
</products>
<skillRequirements>
<Crafting>6</Crafting>
</skillRequirements>
<workSkill>Crafting</workSkill>
<researchPrerequisite>PNRP_Mechlink</researchPrerequisite>
</RecipeDef>
<!-- Remote repairer -->
<ThingDef ParentName="PN_MechanitorImplantBase">
<defName>PN_RemoteRepairer</defName>
<label>automaton remote repairer</label>
<description>This is a modified remote repairer for automaton.</description>
<descriptionHyperlinks>
<HediffDef>RemoteRepairerImplant</HediffDef>
</descriptionHyperlinks>
<costList>
<PowerfocusChip>1</PowerfocusChip>
<ComponentIndustrial>6</ComponentIndustrial>
</costList>
<statBases>
<MaxInstallCount>3</MaxInstallCount>
</statBases>
<comps>
<li Class="CompProperties_Usable">
<compClass>CompUsableImplant</compClass>
<useJob>UseItem</useJob>
<useLabel>Implant {0_label}</useLabel>
<userMustHaveHediff>MechlinkImplant</userMustHaveHediff>
</li>
<li Class="CompProperties_UseEffectInstallImplant">
<hediffDef>RemoteRepairerImplant</hediffDef>
<bodyPart>PNBrain</bodyPart>
<canUpgrade>true</canUpgrade>
</li>
</comps>
</ThingDef>
<RecipeDef>
<defName>PN_Make_PN_RemoteRepairer_Automaton</defName>
<label>make automaton remote repairer</label>
<description>make automaton remote repairer</description>
<jobString>Making automaton remote repairer.</jobString>
<workSpeedStat>GeneralLaborSpeed</workSpeedStat>
<effectWorking>Cook</effectWorking>
<soundWorking>Recipe_Machining</soundWorking>
<workAmount>2000</workAmount>
<allowMixingIngredients>true</allowMixingIngredients>
<recipeUsers>
<li>PN_AutomatonBench</li>
</recipeUsers>
<ingredients>
<li>
<filter>
<thingDefs>
<li>RemoteRepairer</li>
</thingDefs>
</filter>
<count>1</count>
</li>
<li>
<filter>
<thingDefs>
<li>ComponentIndustrial</li>
</thingDefs>
</filter>
<count>2</count>
</li>
</ingredients>
<products>
<PN_RemoteRepairer>1</PN_RemoteRepairer>
</products>
<skillRequirements>
<Crafting>6</Crafting>
</skillRequirements>
<workSkill>Crafting</workSkill>
<researchPrerequisite>PNRP_Mechlink</researchPrerequisite>
</RecipeDef>
<!-- Mech gestation processorr -->
<ThingDef ParentName="PN_MechanitorImplantBase">
<defName>PN_MechFormfeeder</defName>
<label>automaton mech gestation processor</label>
<description>This is a modified mech gestation processor for automaton.</description>
<descriptionHyperlinks>
<HediffDef>MechFormfeederImplant</HediffDef>
</descriptionHyperlinks>
<costList>
<SignalChip>1</SignalChip>
<ComponentIndustrial>6</ComponentIndustrial>
</costList>
<statBases>
<MaxInstallCount>6</MaxInstallCount>
</statBases>
<comps>
<li Class="CompProperties_Usable">
<compClass>CompUsableImplant</compClass>
<useJob>UseItem</useJob>
<useLabel>Implant {0_label}</useLabel>
<userMustHaveHediff>MechlinkImplant</userMustHaveHediff>
</li>
<li Class="CompProperties_UseEffectInstallImplant">
<hediffDef>MechFormfeederImplant</hediffDef>
<bodyPart>PNBrain</bodyPart>
<canUpgrade>true</canUpgrade>
</li>
</comps>
</ThingDef>
<RecipeDef>
<defName>PN_Make_PN_MechFormfeeder_Automaton</defName>
<label>make automaton mech gestation processor</label>
<description>make automaton mech gestation processor</description>
<jobString>Making automaton mech gestation processor.</jobString>
<workSpeedStat>GeneralLaborSpeed</workSpeedStat>
<effectWorking>Cook</effectWorking>
<soundWorking>Recipe_Machining</soundWorking>
<workAmount>2000</workAmount>
<allowMixingIngredients>true</allowMixingIngredients>
<recipeUsers>
<li>PN_AutomatonBench</li>
</recipeUsers>
<ingredients>
<li>
<filter>
<thingDefs>
<li>MechFormfeeder</li>
</thingDefs>
</filter>
<count>1</count>
</li>
<li>
<filter>
<thingDefs>
<li>ComponentIndustrial</li>
</thingDefs>
</filter>
<count>2</count>
</li>
</ingredients>
<products>
<PN_MechFormfeeder>1</PN_MechFormfeeder>
</products>
<skillRequirements>
<Crafting>6</Crafting>
</skillRequirements>
<workSkill>Crafting</workSkill>
<researchPrerequisite>PNRP_Mechlink</researchPrerequisite>
</RecipeDef>
<!-- Remote shielder -->
<ThingDef ParentName="PN_MechanitorImplantBase">
<defName>PN_RemoteShielder</defName>
<label>automaton remote shielder</label>
<description>This is a modified remote shielder for automaton.</description>
<descriptionHyperlinks>
<HediffDef>RemoteShielderImplant</HediffDef>
</descriptionHyperlinks>
<costList>
<PowerfocusChip>1</PowerfocusChip>
<ComponentIndustrial>6</ComponentIndustrial>
</costList>
<statBases>
<MaxInstallCount>3</MaxInstallCount>
</statBases>
<comps>
<li Class="CompProperties_Usable">
<compClass>CompUsableImplant</compClass>
<useJob>UseItem</useJob>
<useLabel>Implant {0_label}</useLabel>
<userMustHaveHediff>MechlinkImplant</userMustHaveHediff>
</li>
<li Class="CompProperties_UseEffectInstallImplant">
<hediffDef>RemoteShielderImplant</hediffDef>
<bodyPart>PNBrain</bodyPart>
<canUpgrade>true</canUpgrade>
</li>
</comps>
</ThingDef>
<RecipeDef>
<defName>PN_Make_PN_RemoteShielder_Automaton</defName>
<label>make automaton remote shielder</label>
<description>make automaton remote shielder</description>
<jobString>Making automaton remote shielder.</jobString>
<workSpeedStat>GeneralLaborSpeed</workSpeedStat>
<effectWorking>Cook</effectWorking>
<soundWorking>Recipe_Machining</soundWorking>
<workAmount>2000</workAmount>
<allowMixingIngredients>true</allowMixingIngredients>
<recipeUsers>
<li>PN_AutomatonBench</li>
</recipeUsers>
<ingredients>
<li>
<filter>
<thingDefs>
<li>RemoteShielder</li>
</thingDefs>
</filter>
<count>1</count>
</li>
<li>
<filter>
<thingDefs>
<li>ComponentIndustrial</li>
</thingDefs>
</filter>
<count>2</count>
</li>
</ingredients>
<products>
<PN_RemoteShielder>1</PN_RemoteShielder>
</products>
<skillRequirements>
<Crafting>6</Crafting>
</skillRequirements>
<workSkill>Crafting</workSkill>
<researchPrerequisite>PNRP_Mechlink</researchPrerequisite>
</RecipeDef>
<!-- Repair probe -->
<ThingDef ParentName="PN_MechanitorImplantBase">
<defName>PN_RepairProbe</defName>
<label>automaton repair probe</label>
<description>This is a modified repair probe for automaton.</description>
<descriptionHyperlinks>
<HediffDef>RepairProbeImplant</HediffDef>
</descriptionHyperlinks>
<costList>
<NanostructuringChip>1</NanostructuringChip>
<ComponentSpacer>2</ComponentSpacer>
</costList>
<statBases>
<MaxInstallCount>6</MaxInstallCount>
</statBases>
<comps>
<li Class="CompProperties_Usable">
<compClass>CompUsableImplant</compClass>
<useJob>UseItem</useJob>
<useLabel>Implant {0_label}</useLabel>
<userMustHaveHediff>MechlinkImplant</userMustHaveHediff>
</li>
<li Class="CompProperties_UseEffectInstallImplant">
<hediffDef>RepairProbeImplant</hediffDef>
<bodyPart>PNBrain</bodyPart>
<canUpgrade>true</canUpgrade>
</li>
</comps>
</ThingDef>
<RecipeDef>
<defName>PN_Make_PN_RepairProbe_Automaton</defName>
<label>make automaton repair probe</label>
<description>make automaton repair probe</description>
<jobString>Making automaton repair probe.</jobString>
<workSpeedStat>GeneralLaborSpeed</workSpeedStat>
<effectWorking>Cook</effectWorking>
<soundWorking>Recipe_Machining</soundWorking>
<workAmount>2000</workAmount>
<allowMixingIngredients>true</allowMixingIngredients>
<recipeUsers>
<li>PN_AutomatonBench</li>
</recipeUsers>
<ingredients>
<li>
<filter>
<thingDefs>
<li>RepairProbe</li>
</thingDefs>
</filter>
<count>1</count>
</li>
<li>
<filter>
<thingDefs>
<li>ComponentIndustrial</li>
</thingDefs>
</filter>
<count>2</count>
</li>
</ingredients>
<products>
<PN_RepairProbe>1</PN_RepairProbe>
</products>
<skillRequirements>
<Crafting>6</Crafting>
</skillRequirements>
<workSkill>Crafting</workSkill>
<researchPrerequisite>PNRP_Mechlink</researchPrerequisite>
</RecipeDef>
</Defs>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Defs>
<ResearchProjectDef>
<defName>PNRP_Mechlink</defName>
<label>automaton mechlink</label>
<description>Research how to modify mechlink and sublink for use by the Automaton.</description>
<tab>PN_technology</tab>
<baseCost>300</baseCost>
<techLevel>Industrial</techLevel>
<prerequisites>
<li>PNRP_Production</li>
</prerequisites>
<researchViewX>1.0</researchViewX>
<researchViewY>4.9</researchViewY>
<tags></tags>
</ResearchProjectDef>
</Defs>

View File

@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8"?>
<Defs>
<!--메카나이터 모듈-->
<ThingDef ParentName="PN_ApparelModuleIndustrial">
<defName>PN_ArrayModule</defName>
<label>array module</label>
<description>[CAUTION]\nThis module can only be installed on compatible models.\nAlso, the module system must be stable.\n\n[compatible models list]\n\nAny model (legd), (mast), (exc)\n\nThis module increases the automaton's MechBandwidth and MechControlGroups stat.</description>
<descriptionHyperlinks>
<HediffDef>PN_ArrayModuleHediff</HediffDef>
</descriptionHyperlinks>
<costList>
<Steel>45</Steel>
<ComponentIndustrial>20</ComponentIndustrial>
<ComponentSpacer>2</ComponentSpacer>
<PN_Component>1</PN_Component>
</costList>
<recipeMaker>
<researchPrerequisite>PNRP_TierB_Module</researchPrerequisite>
<skillRequirements>
<Crafting>6</Crafting>
</skillRequirements>
</recipeMaker>
<apparel>
<tags></tags>
</apparel>
<comps>
<li Class="CompProperties_CauseHediff_Apparel">
<hediff>PN_ArrayModuleHediff</hediff>
<part>PNTorso</part>
</li>
</comps>
</ThingDef>
<HediffDef ParentName="PN_ApparelIndustrialModuleHediffBase">
<defName>PN_ArrayModuleHediff</defName>
<label>array module</label>
<description>The hediff created by installing array module.</description>
<descriptionHyperlinks>
<ThingDef>PN_ArrayModule</ThingDef>
</descriptionHyperlinks>
<stages>
<li>
<statOffsets>
<MechBandwidth>6</MechBandwidth>
<MechControlGroups>1</MechControlGroups>
</statOffsets>
</li>
</stages>
<comps></comps>
</HediffDef>
<ThingDef ParentName="PN_ApparelModuleSpacer">
<defName>PN_IntegratorModule</defName>
<label>integrator module</label>
<description>[CAUTION]\nThis module can only be installed on compatible models.\nAlso, the module system must be stable.\n\n[compatible models list]\n\nAny model (legd)\n\nThis module increases the automaton's MechBandwidth and MechControlGroups stat.</description>
<descriptionHyperlinks>
<HediffDef>PN_IntegratorModuleHediff</HediffDef>
</descriptionHyperlinks>
<costList>
<Plasteel>45</Plasteel>
<ComponentIndustrial>12</ComponentIndustrial>
<ComponentSpacer>9</ComponentSpacer>
<PN_Component>3</PN_Component>
<SignalChip>2</SignalChip>
<PowerfocusChip>1</PowerfocusChip>
</costList>
<recipeMaker>
<researchPrerequisite>PNRP_TierC_Module</researchPrerequisite>
<skillRequirements>
<Crafting>6</Crafting>
</skillRequirements>
</recipeMaker>
<apparel>
<tags></tags>
</apparel>
<comps>
<li Class="CompProperties_CauseHediff_Apparel">
<hediff>PN_IntegratorModuleHediff</hediff>
<part>PNTorso</part>
</li>
</comps>
</ThingDef>
<HediffDef ParentName="PN_ApparelSpacerModuleHediffBase">
<defName>PN_IntegratorModuleHediff</defName>
<label>integrator module</label>
<description>The hediff created by installing integrator module.</description>
<descriptionHyperlinks>
<ThingDef>PN_IntegratorModule</ThingDef>
</descriptionHyperlinks>
<stages>
<li>
<statOffsets>
<MechBandwidth>18</MechBandwidth>
<MechControlGroups>1</MechControlGroups>
</statOffsets>
</li>
</stages>
<comps></comps>
</HediffDef>
</Defs>

View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8" ?>
<Defs>
<HediffDef ParentName="PN_AddedBodyPartBase">
<defName>PN_DetoxifierOilFilter</defName>
<label>detoxifier Oil Filter</label>
<labelNoun>a detoxifier oil filter</labelNoun>
<description>An advanced Oil Filter. Using PNL Industry technology, it can rapidly remove a vast range of toxins from the fuel, making it effective against environmental toxins, venoms, and injected poisons.</description>
<descriptionHyperlinks>
<ThingDef>DetoxifierKidney</ThingDef>
</descriptionHyperlinks>
<spawnThingOnRemoved>DetoxifierKidney</spawnThingOnRemoved>
<addedPartProps>
<solid>true</solid>
<partEfficiency>1.1</partEfficiency>
<betterThanNatural>true</betterThanNatural>
</addedPartProps>
<stages>
<li>
<statOffsets>
<ToxicResistance>0.5</ToxicResistance>
</statOffsets>
</li>
</stages>
</HediffDef>
<RecipeDef ParentName="PN_SurgeryInstallImplantBase">
<defName>PN_InstallDetoxifierOilFilter</defName>
<label>install detoxifier Oil Filter</label>
<description>Install a detoxifier oil filter.</description>
<descriptionHyperlinks>
<ThingDef>DetoxifierKidney</ThingDef>
<HediffDef>PN_DetoxifierOilFilter</HediffDef>
</descriptionHyperlinks>
<jobString>Installing detoxifier oil filter.</jobString>
<ingredients>
<li>
<filter>
<thingDefs>
<li>DetoxifierKidney</li>
</thingDefs>
</filter>
<count>1</count>
</li>
</ingredients>
<fixedIngredientFilter>
<thingDefs>
<li>DetoxifierKidney</li>
</thingDefs>
</fixedIngredientFilter>
<appliedOnFixedBodyParts>
<li>PNKidney</li>
</appliedOnFixedBodyParts>
<addsHediff>PN_DetoxifierOilFilter</addsHediff>
<deathOnFailedSurgeryChance>0</deathOnFailedSurgeryChance>
</RecipeDef>
<RecipeDef ParentName="PN_SurgeryRemoveImplantBase">
<defName>PN_RemoveDetoxifierOilFilter</defName>
<label>remove detoxifier Oil Filter</label>
<description>Remove detoxifier Oil Filter.</description>
<descriptionHyperlinks>
<ThingDef>DetoxifierKidney</ThingDef>
<HediffDef>PN_DetoxifierOilFilter</HediffDef>
</descriptionHyperlinks>
<jobString>Removing detoxifier Oil Filter.</jobString>
<removesHediff>PN_DetoxifierOilFilter</removesHediff>
</RecipeDef>
</Defs>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MoharHediffs", "MoharHediffs\MoharHediffs.csproj", "{7ACFB1B0-3B20-48B9-BA73-48DD6353ABED}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7ACFB1B0-3B20-48B9-BA73-48DD6353ABED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7ACFB1B0-3B20-48B9-BA73-48DD6353ABED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7ACFB1B0-3B20-48B9-BA73-48DD6353ABED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7ACFB1B0-3B20-48B9-BA73-48DD6353ABED}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using RimWorld;
using Verse;
namespace MoharHediffs
{
public class ActivityRestriction
{
public bool HasPostureRestriction
{
get
{
return !this.allowedPostures.NullOrEmpty<PawnPosture>();
}
}
public bool HasJobRestriction
{
get
{
return !this.allowedJobs.NullOrEmpty<JobDef>();
}
}
public bool HasAllowedRotation
{
get
{
return !this.allowedRotation.NullOrEmpty<Rot4>();
}
}
public bool onlyWhenMoving = true;
public List<PawnPosture> allowedPostures;
public List<JobDef> allowedJobs;
public List<Rot4> allowedRotation;
}
}

View File

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using Verse;
namespace MoharHediffs
{
public class BodyPartCondition
{
public bool HasLabel
{
get
{
return !this.bodyPartLabel.NullOrEmpty<string>();
}
}
public bool HasDef
{
get
{
return !this.bodyPartDef.NullOrEmpty<BodyPartDef>();
}
}
public bool HasTag
{
get
{
return !this.bodyPartTag.NullOrEmpty<BodyPartTagDef>();
}
}
public bool HasBPCondition
{
get
{
return this.HasLabel || this.HasDef || this.HasTag;
}
}
public List<string> bodyPartLabel;
public List<BodyPartDef> bodyPartDef;
public List<BodyPartTagDef> bodyPartTag;
}
}

View File

@ -0,0 +1,307 @@
using System;
using System.Collections.Generic;
using System.Linq;
using RimWorld;
using Verse;
namespace MoharHediffs
{
public static class BodyPartsTools
{
public static BodyPartRecord GetBPRWithoutHediff(this Pawn pawn, BodyPartDef bpd, HediffDef hediffDef)
{
IEnumerable<BodyPartRecord> source;
bool flag = (source = from b in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null)
where b.def == bpd
select b) == null;
BodyPartRecord result;
if (flag)
{
result = null;
}
else
{
List<BodyPartRecord> bprToExclude = new List<BodyPartRecord>();
IEnumerable<Hediff> hediffs = pawn.health.hediffSet.hediffs;
Func<Hediff, bool> <>9__1;
Func<Hediff, bool> predicate;
if ((predicate = <>9__1) == null)
{
predicate = (<>9__1 = ((Hediff h) => h.def == hediffDef));
}
foreach (Hediff hediff in hediffs.Where(predicate))
{
bool flag2 = !bprToExclude.Contains(hediff.Part);
if (flag2)
{
bprToExclude.Add(hediff.Part);
}
}
bool flag3 = bprToExclude.NullOrEmpty<BodyPartRecord>();
if (flag3)
{
result = source.RandomElementWithFallback(null);
}
else
{
IEnumerable<BodyPartRecord> source2;
bool flag4 = (source2 = from b in source
where !bprToExclude.Contains(b)
select b) == null;
if (flag4)
{
result = null;
}
else
{
result = source2.RandomElementWithFallback(null);
}
}
}
return result;
}
public static bool CheckIfExistingNaturalBP(this Pawn pawn, BodyPartDef bodyPartDef, bool myDebug = false)
{
BodyPartRecord bodyPartRecord = pawn.GetBPRecord(bodyPartDef, false) ?? null;
bool flag = bodyPartRecord == null || pawn.health.hediffSet.PartIsMissing(bodyPartRecord) || pawn.health.hediffSet.AncestorHasDirectlyAddedParts(bodyPartRecord);
return !flag;
}
public static BodyPartRecord GetBPRecord(this Pawn pawn, BodyPartDef bodyPartDef, bool myDebug = false)
{
IEnumerable<BodyPartDef> enumerable = from b in DefDatabase<BodyPartDef>.AllDefs
where b == bodyPartDef
select b;
bool flag = enumerable.EnumerableNullOrEmpty<BodyPartDef>();
BodyPartRecord result;
if (flag)
{
if (myDebug)
{
string label = pawn.Label;
string str = " - GetBPRecord - did not find any ";
BodyPartDef bodyPartDef2 = bodyPartDef;
Log.Warning(label + str + ((bodyPartDef2 != null) ? bodyPartDef2.defName : null));
}
result = null;
}
else
{
BodyPartDef def = enumerable.RandomElement<BodyPartDef>();
BodyPartRecord bodyPartRecord;
pawn.RaceProps.body.GetPartsWithDef(def).TryRandomElement(out bodyPartRecord);
if (myDebug)
{
string label2 = pawn.Label;
string str2 = "GetBPRecord - DID find ";
BodyPartDef bodyPartDef3 = bodyPartDef;
Log.Warning(label2 + str2 + ((bodyPartDef3 != null) ? bodyPartDef3.defName : null));
}
result = bodyPartRecord;
}
return result;
}
public static bool IsMissingBPR(this Pawn pawn, BodyPartRecord BPR, out Hediff missingHediff)
{
bool flag = BPR == null;
bool result;
if (flag)
{
missingHediff = null;
result = false;
}
else
{
missingHediff = (from h in pawn.health.hediffSet.hediffs
where h.def == HediffDefOf.MissingBodyPart && h.Part == BPR
select h).FirstOrFallback(null);
result = (missingHediff != null);
}
return result;
}
public static bool HasMissingChildren(this Pawn pawn, BodyPartRecord bpr)
{
List<Hediff_MissingPart> missingPartsCommonAncestors = pawn.health.hediffSet.GetMissingPartsCommonAncestors();
return missingPartsCommonAncestors.Any((Hediff_MissingPart HMP) => HMP.Part == bpr);
}
public static bool IsMissingOrHasMissingChildren(this Pawn pawn, BodyPartRecord bpr)
{
return pawn.health.hediffSet.PartIsMissing(bpr) || pawn.HasMissingChildren(bpr);
}
public static IEnumerable<BodyPartRecord> GetAllBPR(this Pawn pawn, string bodyPartLabel, BodyPartDef bodyPartDef)
{
bool HasLabel = !bodyPartLabel.NullOrEmpty();
bool HasDef = bodyPartDef != null;
return from bpr in pawn.RaceProps.body.AllParts
where (!HasLabel || bpr.customLabel == bodyPartLabel) && (!HasDef || bpr.def == bodyPartDef)
select bpr;
}
public static IEnumerable<BodyPartRecord> GetAllNotMissingBPR(this Pawn pawn, string bodyPartLabel, BodyPartDef bodyPartDef)
{
bool HasLabel = !bodyPartLabel.NullOrEmpty();
bool HasDef = bodyPartDef != null;
return from bpr in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null)
where (!HasLabel || bpr.customLabel == bodyPartLabel) && (!HasDef || bpr.def == bodyPartDef)
select bpr;
}
public static BodyPartRecord GetBPRecordWithoutHediff(this Pawn pawn, string bodyPartLabel, BodyPartDef bodyPartDef, HediffDef hd, bool AllowMissing = false, bool PrioritizeMissing = false, bool AllowAddedPart = true, bool myDebug = false)
{
bool flag = hd != null;
bool flag2 = !bodyPartLabel.NullOrEmpty();
bool flag3 = bodyPartDef != null;
string text = pawn.Label + " GetBPRecordWithoutHediff - ";
if (myDebug)
{
string[] array = new string[5];
array[0] = text;
array[1] = string.Format("HasDef?{0} bodyPartDef:{1} ", flag3, (bodyPartDef != null) ? bodyPartDef.defName : null);
array[2] = string.Format("HasLabel?{0} bodyPartLabel:{1} ", flag2, bodyPartLabel);
int num = 3;
string format = "HasHediffDef?{0} Hediff:{1} ";
object arg = flag;
HediffDef hd2 = hd;
array[num] = string.Format(format, arg, (hd2 != null) ? hd2.defName : null);
array[4] = string.Format("AllowMissing:{0} PrioritizeMissing:{1} AllowAddedPart:{2}", AllowMissing, PrioritizeMissing, AllowAddedPart);
Log.Warning(string.Concat(array));
}
List<BodyPartRecord> bprToExclude = new List<BodyPartRecord>();
bool flag4 = flag;
if (flag4)
{
IEnumerable<Hediff> hediffs = pawn.health.hediffSet.hediffs;
Func<Hediff, bool> <>9__3;
Func<Hediff, bool> predicate;
if ((predicate = <>9__3) == null)
{
predicate = (<>9__3 = ((Hediff h) => h.def == hd));
}
foreach (Hediff hediff in hediffs.Where(predicate))
{
bool flag5 = !bprToExclude.Contains(hediff.Part);
if (flag5)
{
bprToExclude.Add(hediff.Part);
}
}
if (myDebug)
{
object[] array2 = new object[5];
array2[0] = text;
array2[1] = "found ";
int num2 = 2;
List<BodyPartRecord> bprToExclude2 = bprToExclude;
array2[num2] = ((bprToExclude2 != null) ? new int?(bprToExclude2.Count) : null);
array2[3] = " bpr to exclude bc they had ";
array2[4] = hd.defName;
Log.Warning(string.Concat(array2));
}
}
BodyPartRecord bodyPartRecord = null;
IEnumerable<BodyPartRecord> enumerable;
if (AllowMissing)
{
enumerable = pawn.GetAllBPR(bodyPartLabel, bodyPartDef);
if (myDebug)
{
Log.Warning(text + "Allow missing - found " + (enumerable.EnumerableNullOrEmpty<BodyPartRecord>() ? "0" : enumerable.Count<BodyPartRecord>().ToString()) + " bpr");
}
bool flag6 = PrioritizeMissing && !enumerable.EnumerableNullOrEmpty<BodyPartRecord>() && enumerable.Any((BodyPartRecord bpr) => pawn.IsMissingOrHasMissingChildren(bpr));
if (flag6)
{
enumerable = from bpr in enumerable
where pawn.IsMissingOrHasMissingChildren(bpr)
select bpr;
if (myDebug)
{
Log.Warning(text + "Prioritize Missing - found " + (enumerable.EnumerableNullOrEmpty<BodyPartRecord>() ? "0" : enumerable.Count<BodyPartRecord>().ToString()) + " bpr");
}
}
}
else
{
enumerable = pawn.GetAllNotMissingBPR(bodyPartLabel, bodyPartDef);
if (myDebug)
{
Log.Warning(text + "Not missing - found " + (enumerable.EnumerableNullOrEmpty<BodyPartRecord>() ? "0" : enumerable.Count<BodyPartRecord>().ToString()) + " bpr");
}
}
bool flag7 = enumerable.EnumerableNullOrEmpty<BodyPartRecord>();
BodyPartRecord result;
if (flag7)
{
result = null;
}
else
{
bool flag8 = !AllowAddedPart;
if (flag8)
{
Tools.Warn(text + "Trying to exlude addedpart", myDebug);
bool flag9 = enumerable.Any((BodyPartRecord bpr) => pawn.health.hediffSet.HasDirectlyAddedPartFor(bpr));
if (flag9)
{
enumerable = from bpr in enumerable
where !pawn.health.hediffSet.HasDirectlyAddedPartFor(bpr)
select bpr;
if (myDebug)
{
Log.Warning(text + "Added parts(bionics) forbidden- found " + (enumerable.EnumerableNullOrEmpty<BodyPartRecord>() ? "0" : enumerable.Count<BodyPartRecord>().ToString()) + " bpr");
}
}
else if (myDebug)
{
Log.Warning(text + "found no addedpart to exclude");
}
}
bool flag10 = bprToExclude.NullOrEmpty<BodyPartRecord>();
if (flag10)
{
enumerable.TryRandomElement(out bodyPartRecord);
}
else
{
bool flag11 = enumerable.Any((BodyPartRecord bp) => !bprToExclude.Contains(bp));
if (flag11)
{
(from bp in enumerable
where !bprToExclude.Contains(bp)
select bp).TryRandomElement(out bodyPartRecord);
}
else
{
bodyPartRecord = null;
}
}
if (myDebug)
{
Log.Warning(string.Concat(new string[]
{
pawn.Label,
"GetBPRecord - did ",
(bodyPartRecord == null) ? "not" : "",
" find with def ",
(bodyPartDef != null) ? bodyPartDef.defName : null,
" without hediff def ",
hd.defName
}));
}
result = bodyPartRecord;
}
return result;
}
public static BodyPartRecord GetBrain(this Pawn pawn)
{
BodyPartRecord result;
pawn.RaceProps.body.GetPartsWithTag(BodyPartTagDefOf.ConsciousnessSource).TryRandomElement(out result);
return result;
}
}
}

View File

@ -0,0 +1,13 @@
using System;
using RimWorld;
using UnityEngine;
namespace MoharHediffs
{
public class BodyTypeOffset
{
public BodyTypeDef bodyType;
public Vector3 offset;
}
}

View File

@ -0,0 +1,12 @@
using System;
using RimWorld;
namespace MoharHediffs
{
public class BodyTypeSpecificities
{
public BodyTypeDef bodyTypeDef;
public DrawingSpecificities drawRules;
}
}

View File

@ -0,0 +1,11 @@
using System;
namespace MoharHediffs
{
public class ChannelColorCondition
{
public string channelName;
public int channelNum = 0;
}
}

View File

@ -0,0 +1,14 @@
using System;
using UnityEngine;
namespace MoharHediffs
{
public class ColorRange
{
public Color colorA;
public Color colorB;
public float variationPerIteration;
}
}

View File

@ -0,0 +1,11 @@
using System;
namespace MoharHediffs
{
public class CommonSettings
{
public StackSettings stack;
public FilthSettings filth;
}
}

View File

@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using Verse;
namespace MoharHediffs
{
public static class ConditionBuilder
{
public static void CopyHediffCondition(HediffCondition source, HediffCondition dest, bool debug = false)
{
string str = debug ? "CopyHediffCondition - " : "";
bool hasBodypartCondition = source.HasBodypartCondition;
if (hasBodypartCondition)
{
Tools.Warn(str + "found HasBodypartCondition, copying", debug);
bool hasDef = source.bodyPart.HasDef;
if (hasDef)
{
dest.bodyPart.bodyPartDef = source.bodyPart.bodyPartDef.ListFullCopy<BodyPartDef>();
}
bool hasLabel = source.bodyPart.HasLabel;
if (hasLabel)
{
dest.bodyPart.bodyPartLabel = source.bodyPart.bodyPartLabel.ListFullCopy<string>();
}
bool hasTag = source.bodyPart.HasTag;
if (hasTag)
{
dest.bodyPart.bodyPartTag = source.bodyPart.bodyPartTag.ListFullCopy<BodyPartTagDef>();
}
}
bool hasPawnCondition = source.HasPawnCondition;
if (hasPawnCondition)
{
Tools.Warn(str + "found HasPawnCondition, copying", debug);
bool hasRace = source.pawn.HasRace;
if (hasRace)
{
dest.pawn.race = source.pawn.race.ListFullCopy<ThingDef>();
}
bool hasGender = source.pawn.HasGender;
if (hasGender)
{
dest.pawn.gender = source.pawn.gender.ListFullCopy<Gender>();
}
dest.pawn.ageRange = source.pawn.ageRange;
}
}
public static HediffCondition GetDefaultPlusSpecificHediffCondition(HediffCondition defaultHC, HediffCondition specificHC, bool debug = false)
{
string str = debug ? "GetDefaultPlusSpecificHediffCondition - " : "";
Tools.Warn(str + "allocating answerHC", debug);
HediffCondition hediffCondition = new HediffCondition
{
bodyPart = new BodyPartCondition
{
bodyPartDef = new List<BodyPartDef>(),
bodyPartLabel = new List<string>(),
bodyPartTag = new List<BodyPartTagDef>()
},
pawn = new PawnCondition
{
race = new List<ThingDef>(),
gender = new List<Gender>()
}
};
bool flag = defaultHC != null;
if (flag)
{
Tools.Warn(str + "found defaultHC, copying", debug);
ConditionBuilder.CopyHediffCondition(defaultHC, hediffCondition, debug);
}
bool flag2 = specificHC != null;
if (flag2)
{
Tools.Warn(str + "found specificHC, copying", debug);
ConditionBuilder.CopyHediffCondition(specificHC, hediffCondition, debug);
}
return hediffCondition;
}
}
}

View File

@ -0,0 +1,115 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Verse;
namespace MoharHediffs
{
public static class ConditionValidation
{
public static bool ValidateCompatibilityOfHediffWithPawn(this PawnCondition pCon, Pawn pawn, bool debug = false)
{
string text = debug ? (pawn.LabelShort + " ValidateCompatibilityOfHediffWithPawn - ") : "";
bool hasRace = pCon.HasRace;
if (hasRace)
{
bool flag = !pCon.race.Contains(pawn.def);
if (flag)
{
Tools.Warn(text + " does not belong to the good race", debug);
return false;
}
}
bool hasGender = pCon.HasGender;
if (hasGender)
{
bool flag2 = !pCon.gender.Contains(pawn.gender);
if (flag2)
{
Tools.Warn(text + " does not belong to the good gender", debug);
return false;
}
}
bool flag3 = !pCon.ageRange.Includes((float)pawn.ageTracker.AgeBiologicalYears);
bool result;
if (flag3)
{
Tools.Warn(string.Concat(new object[]
{
text,
" does not have the good age : ",
pawn.ageTracker.AgeBiologicalYears,
" => ",
pCon.ageRange
}), debug);
result = false;
}
else
{
Tools.Warn(text + " valid ok", debug);
result = true;
}
return result;
}
public static bool InitialHediffConditionCheck(this HediffComp_AnotherRandom comp, bool debug = false)
{
string str = debug ? (comp.Pawn.LabelShort + " InitialHediffConditionCheck - ") : "";
Tools.Warn(str + " Entering", debug);
bool result = !comp.GetCompatibleItems().NullOrEmpty<HediffItem>();
Tools.Warn(str + "found anyAppliableItem:" + result.ToString(), debug);
return result;
}
public static bool GetBPRFromHediffCondition(this BodyPartCondition bpCon, Pawn pawn, out BodyPartRecord BPR, bool debug = false)
{
string text = debug ? (pawn.LabelShort + " GetBPRFromHediffCondition - ") : "";
BPR = null;
Tools.Warn(text + " Entering", debug);
bool flag = bpCon == null;
bool result;
if (flag)
{
Tools.Warn(text + " Found no condition, returning null aka body", debug);
result = true;
}
else
{
bool flag2 = !bpCon.HasBPCondition;
if (flag2)
{
Tools.Warn(text + " Found no BP condition, returning null aka body", debug);
result = true;
}
else
{
Tools.Warn(string.Concat(new string[]
{
text,
" Found BP conditions, selecting : Label:",
bpCon.HasLabel.ToString(),
"; Def:",
bpCon.HasDef.ToString(),
"; Tag:",
bpCon.HasTag.ToString()
}), debug);
IEnumerable<BodyPartRecord> enumerable = from bpr in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null)
where (!bpCon.HasLabel || bpCon.bodyPartLabel.Any((string s) => s == bpr.customLabel)) && (!bpCon.HasDef || bpCon.bodyPartDef.Any((BodyPartDef d) => d == bpr.def)) && (!bpCon.HasTag || (!bpr.def.tags.NullOrEmpty<BodyPartTagDef>() && !bpCon.bodyPartTag.Intersect(bpr.def.tags).EnumerableNullOrEmpty<BodyPartTagDef>()))
select bpr;
bool flag3 = !enumerable.EnumerableNullOrEmpty<BodyPartRecord>();
if (flag3)
{
BPR = enumerable.RandomElement<BodyPartRecord>();
result = true;
}
else
{
Tools.Warn(pawn.LabelShort + " does not have any compatible bodypart", debug);
result = false;
}
}
}
return result;
}
}
}

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using Verse;
namespace MoharHediffs
{
public class CopyPawnSettings
{
public bool HasHediffExclusion
{
get
{
return !this.excludeHediff.NullOrEmpty<HediffDef>();
}
}
public bool name = false;
public bool pawnKind = false;
public bool age = false;
public bool gender = false;
public bool melanin = false;
public bool skinColorChannel = false;
public bool bodyType = false;
public bool crownType = false;
public bool hair = false;
public bool hairColor = false;
public bool hediff = false;
public List<HediffDef> excludeHediff;
public bool excludeTendableHediffs = false;
public bool excludePermanentHediffs = false;
public bool childBS = false;
public bool adultBS = false;
public bool skills = false;
public FloatRange skillDecay = new FloatRange(1f, 1f);
public bool passions = false;
public bool traits = false;
}
}

View File

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Verse;
namespace MoharHediffs
{
public class DrawingSpecificities
{
public Vector3 GetRotationOffset(Pawn p)
{
RotationOffset rotationOffset;
bool flag = (rotationOffset = (from ro in this.rotationOffset
where ro.rot == p.Rotation
select ro).FirstOrFallback(null)) != null;
Vector3 result;
if (flag)
{
result = rotationOffset.offset;
}
else
{
result = Vector3.zero;
}
return result;
}
public FloatRange randomScale = new FloatRange(0.5f, 0.8f);
public List<RotationOffset> rotationOffset;
}
}

View File

@ -0,0 +1,113 @@
using System;
using RimWorld;
using Verse;
namespace MoharHediffs
{
public class FactionPickerParameters
{
public bool HasInheritedFaction
{
get
{
return this.inheritedFaction;
}
}
public bool HasForcedFaction
{
get
{
return this.forcedFaction != null;
}
}
public bool HasPlayerFaction
{
get
{
return this.playerFaction;
}
}
public bool HasNoFaction
{
get
{
return this.noFaction;
}
}
public bool HasDefaultPawnKindFaction
{
get
{
return this.defaultPawnKindFaction;
}
}
public bool IsLegitRandomFactionParameter()
{
int num = 0;
bool hasInheritedFaction = this.HasInheritedFaction;
checked
{
if (hasInheritedFaction)
{
num++;
}
bool hasForcedFaction = this.HasForcedFaction;
if (hasForcedFaction)
{
num++;
}
bool hasPlayerFaction = this.HasPlayerFaction;
if (hasPlayerFaction)
{
num++;
}
bool hasNoFaction = this.HasNoFaction;
if (hasNoFaction)
{
num++;
}
bool hasDefaultPawnKindFaction = this.HasDefaultPawnKindFaction;
if (hasDefaultPawnKindFaction)
{
num++;
}
return num == 1;
}
}
public void Dump()
{
Log.Warning(string.Concat(new string[]
{
"inherited:",
this.HasInheritedFaction.ToString(),
"; forced:",
this.HasForcedFaction.ToString(),
"; player:",
this.HasPlayerFaction.ToString(),
"; noFaction:",
this.HasNoFaction.ToString(),
"; defaultPawnKindFaction:",
this.HasDefaultPawnKindFaction.ToString(),
"; "
}));
}
public bool inheritedFaction = false;
public FactionDef forcedFaction = null;
public bool playerFaction = false;
public bool defaultPawnKindFaction = false;
public bool noFaction = false;
public float weight = 1f;
}
}

View File

@ -0,0 +1,161 @@
using System;
using System.Collections.Generic;
using System.Linq;
using RimWorld;
using Verse;
namespace MoharHediffs
{
public static class FactionPickerUtils
{
public static float FactionTotalWeight(this List<FactionPickerParameters> FPP)
{
float num = 0f;
for (int i = 0; i < FPP.Count; i = checked(i + 1))
{
num += FPP[i].weight;
}
return num;
}
public static void ComputeRandomFaction(this HediffComp_RandySpawnUponDeath comp)
{
bool flag = !comp.ChosenItem.HasFactionParams;
if (!flag)
{
int weightedRandomFaction = comp.GetWeightedRandomFaction();
bool flag2 = weightedRandomFaction == -1;
if (flag2)
{
bool myDebug = comp.MyDebug;
if (myDebug)
{
Log.Warning("ComputeRandomFaction - found no index");
}
}
else
{
FactionPickerParameters factionPickerParameters = comp.ChosenItem.faction[weightedRandomFaction];
bool myDebug2 = comp.MyDebug;
if (myDebug2)
{
factionPickerParameters.Dump();
}
comp.RandomFaction = comp.GetFaction(factionPickerParameters);
bool myDebug3 = comp.MyDebug;
if (myDebug3)
{
string str = "ComputeRandomFaction - found:";
Faction randomFaction = comp.RandomFaction;
Log.Warning(str + ((randomFaction != null) ? randomFaction.GetCallLabel() : null));
}
}
}
}
public static int GetWeightedRandomFaction(this HediffComp_RandySpawnUponDeath comp)
{
bool flag = !comp.HasChosenPawn || !comp.ChosenItem.HasFactionParams;
checked
{
int result;
if (flag)
{
result = -1;
}
else
{
List<FactionPickerParameters> faction = comp.ChosenItem.faction;
float num = Rand.Range(0f, faction.FactionTotalWeight());
for (int i = 0; i < faction.Count; i++)
{
bool flag2 = unchecked(num -= faction[i].weight) < 0f;
if (flag2)
{
bool myDebug = comp.MyDebug;
if (myDebug)
{
Log.Warning("GetWeightedRandomIndex : returning " + i);
}
return i;
}
}
bool myDebug2 = comp.MyDebug;
if (myDebug2)
{
Log.Warning("GetWeightedRandomFaction : failed to return proper index, returning -1");
}
result = -1;
}
return result;
}
}
public static Faction GetFaction(this HediffComp_RandySpawnUponDeath comp, FactionPickerParameters FPP)
{
FactionDef fDef = comp.GetFactionDef(FPP);
bool flag = fDef == null;
Faction result;
if (flag)
{
result = null;
}
else
{
result = (from F in Find.FactionManager.AllFactions
where F.def == fDef
select F).FirstOrFallback(null);
}
return result;
}
public static FactionDef GetFactionDef(this HediffComp_RandySpawnUponDeath comp, FactionPickerParameters FPP)
{
Pawn pawn = comp.Pawn;
bool flag = FPP.HasInheritedFaction && pawn.Faction != null;
FactionDef result;
if (flag)
{
result = pawn.Faction.def;
}
else
{
bool hasForcedFaction = FPP.HasForcedFaction;
if (hasForcedFaction)
{
result = FPP.forcedFaction;
}
else
{
bool hasPlayerFaction = FPP.HasPlayerFaction;
if (hasPlayerFaction)
{
result = Faction.OfPlayer.def;
}
else
{
bool hasNoFaction = FPP.HasNoFaction;
if (hasNoFaction)
{
result = null;
}
else
{
bool hasDefaultPawnKindFaction = FPP.HasDefaultPawnKindFaction;
if (hasDefaultPawnKindFaction)
{
PawnKindDef pawnKindToSpawn = comp.ChosenItem.pawnKindToSpawn;
result = (((pawnKindToSpawn != null) ? pawnKindToSpawn.defaultFactionType : null) ?? null);
}
else
{
result = null;
}
}
}
}
}
return result;
}
}
}

View File

@ -0,0 +1,14 @@
using System;
using Verse;
namespace MoharHediffs
{
public class FilthSettings
{
public ThingDef filthDef = null;
public IntRange filthNum = new IntRange(1, 1);
public FloatRange filthRadius = new FloatRange(1f, 1f);
}
}

View File

@ -0,0 +1,27 @@
using System;
using UnityEngine;
namespace MoharHediffs
{
public class Footprint
{
public string Dump()
{
return string.Concat(new object[]
{
"intervalDistance:",
this.intervalDistance,
"; offset:",
this.offset,
"; distanceBetweenFeet:",
this.distanceBetweenFeet
});
}
public float intervalDistance = 0.632f;
public Vector3 offset = new Vector3(0f, 0f, -0.3f);
public float distanceBetweenFeet = 0.17f;
}
}

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using Verse;
namespace MoharHediffs
{
public class GeneralSettings
{
public bool HasSomethingToSpawn
{
get
{
return !this.things.NullOrEmpty<ThingSettings>();
}
}
public bool HasDefaultSettings
{
get
{
return this.defaultSettings != null;
}
}
public void LogParams(bool myDebug = false)
{
if (myDebug)
{
Log.Warning(string.Concat(new string[]
{
"HasSomethingToSpawn:",
this.HasSomethingToSpawn.ToString(),
"; HasDefaultSettings:",
this.HasDefaultSettings.ToString(),
"; "
}));
}
}
public List<ThingSettings> things;
public CommonSettings defaultSettings;
}
}

View File

@ -0,0 +1,153 @@
using System;
using AlienRace;
using UnityEngine;
using Verse;
namespace MoharHediffs
{
public static class GfxEffects
{
public static Color ClosestColor(Pawn pawn, bool complementary = false, bool myDebug = false)
{
AlienPartGenerator.AlienComp alien = Tools.GetAlien(pawn);
bool flag = alien == null;
Color color;
if (flag)
{
color = pawn.DrawColor;
}
else
{
color = alien.GetChannel("skin").first;
if (myDebug)
{
Log.Warning(pawn.LabelShort + " is alien, color=" + color);
}
}
Color color2 = Color.blue;
float num = 1000f;
float num2 = Math.Abs(color.r - MyGfx.Purple.r) + Math.Abs(color.g - MyGfx.Purple.g) / 4f + Math.Abs(color.b - MyGfx.Purple.b);
float num3 = Math.Abs(color.r - MyGfx.Blue.r) / 2f + Math.Abs(color.g - MyGfx.Blue.g) / 2f + Math.Abs(color.b - MyGfx.Blue.b);
float num4 = Math.Abs(color.r - MyGfx.Cyan.r) / 4f + Math.Abs(color.g - MyGfx.Cyan.g) + Math.Abs(color.b - MyGfx.Cyan.b);
float num5 = Math.Abs(color.r - MyGfx.Green.r) / 2f + Math.Abs(color.g - MyGfx.Green.g) + Math.Abs(color.b - MyGfx.Green.b) / 2f;
float num6 = Math.Abs(color.r - MyGfx.Yellow.r) + Math.Abs(color.g - MyGfx.Yellow.g) + Math.Abs(color.b - MyGfx.Yellow.b) / 4f;
float num7 = Math.Abs(color.r - MyGfx.Orange.r) + Math.Abs(color.g - MyGfx.Orange.g) / 1.6f + Math.Abs(color.b - MyGfx.Orange.b) / 2.5f;
float num8 = Math.Abs(color.r - MyGfx.Red.r) + Math.Abs(color.g - MyGfx.Red.g) / 2f + Math.Abs(color.b - MyGfx.Red.b) / 2f;
if (myDebug)
{
Log.Warning(pawn.LabelShort + "'s pColor: " + color);
Log.Warning(string.Concat(new object[]
{
"purpleDiff: ",
num2,
"; blueDiff: ",
num3,
"; cyanDiff: ",
num4,
"; greenDiff: ",
num5,
"; yellowDiff: ",
num6,
"; orangeDiff: ",
num7,
"; redDiff: ",
num8
}));
}
bool flag2 = num2 < num;
if (flag2)
{
num = num2;
color2 = MyGfx.Purple;
}
bool flag3 = num3 < num;
if (flag3)
{
num = num3;
color2 = MyGfx.Blue;
}
bool flag4 = num4 < num;
if (flag4)
{
num = num4;
color2 = MyGfx.Blue;
}
bool flag5 = num5 < num;
if (flag5)
{
num = num5;
color2 = MyGfx.Green;
}
bool flag6 = num6 < num;
if (flag6)
{
num = num6;
color2 = MyGfx.Yellow;
}
bool flag7 = num7 < num;
if (flag7)
{
num = num7;
color2 = MyGfx.Orange;
}
bool flag8 = num8 < num;
if (flag8)
{
color2 = MyGfx.Red;
}
if (complementary)
{
bool flag9 = color2 == MyGfx.Purple;
if (flag9)
{
color2 = MyGfx.Yellow;
}
else
{
bool flag10 = color2 == MyGfx.Blue || color2 == MyGfx.Cyan;
if (flag10)
{
color2 = MyGfx.Orange;
}
else
{
bool flag11 = color2 == MyGfx.Green;
if (flag11)
{
color2 = MyGfx.Red;
}
else
{
bool flag12 = color2 == MyGfx.Yellow;
if (flag12)
{
color2 = MyGfx.Purple;
}
else
{
bool flag13 = color2 == MyGfx.Orange;
if (flag13)
{
color2 = MyGfx.Blue;
}
else
{
bool flag14 = color2 == MyGfx.Red;
if (flag14)
{
color2 = MyGfx.Green;
}
}
}
}
}
}
}
if (myDebug)
{
Log.Warning(complementary ? "complementary" : ("closest Color=" + color2));
}
return color2;
}
}
}

View File

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using Verse;
namespace MoharHediffs
{
public class HeDiffCompProperties_HediffExclusive : HediffCompProperties
{
public HeDiffCompProperties_HediffExclusive()
{
this.compClass = typeof(HeDiffComp_HediffExclusive);
}
public List<HediffDef> hediffToNullify;
public List<string> hediffPatternToNullify;
public HediffDef hediffToApply = null;
public BodyDef bodyDef;
public List<BodyDef> bodyDefWhiteList;
public List<BodyDef> bodyDefBlackList;
public BodyPartDef bodyPartDef;
public bool debug = false;
}
}

View File

@ -0,0 +1,341 @@
using System;
using System.Linq;
using Verse;
namespace MoharHediffs
{
public class HeDiffComp_HediffExclusive : HediffComp
{
private bool MyDebug
{
get
{
return this.Props.debug;
}
}
public HeDiffCompProperties_HediffExclusive Props
{
get
{
return (HeDiffCompProperties_HediffExclusive)this.props;
}
}
public bool HasHediffToNullify
{
get
{
return !this.Props.hediffToNullify.NullOrEmpty<HediffDef>();
}
}
public bool HasHediffPatternToNullify
{
get
{
return !this.Props.hediffPatternToNullify.NullOrEmpty<string>();
}
}
public bool HasHediffToApply
{
get
{
return this.Props.hediffToApply != null;
}
}
private bool HasWhiteList
{
get
{
return !this.Props.bodyDefWhiteList.NullOrEmpty<BodyDef>();
}
}
private bool HasBlackList
{
get
{
return !this.Props.bodyDefBlackList.NullOrEmpty<BodyDef>();
}
}
private bool WhiteListCompliant
{
get
{
return !this.HasWhiteList || this.Props.bodyDefWhiteList.Contains(base.Pawn.def.race.body);
}
}
private bool BlackListCompliant
{
get
{
return !this.HasBlackList || !this.Props.bodyDefBlackList.Contains(base.Pawn.def.race.body);
}
}
private bool HasAccessList
{
get
{
return this.HasWhiteList || this.HasBlackList;
}
}
private string DebugStr
{
get
{
return this.MyDebug ? (base.Pawn.LabelShort + " HediffExclusive " + this.parent.def.defName + " - ") : "";
}
}
private bool PatternMatch(string MyHediffDefname)
{
foreach (string value in this.Props.hediffPatternToNullify)
{
bool flag = MyHediffDefname.Contains(value);
if (flag)
{
return true;
}
}
return false;
}
public void NullifyHediff()
{
int num = 0;
checked
{
foreach (Hediff hediff in base.Pawn.health.hediffSet.hediffs)
{
Tools.Warn(string.Concat(new object[]
{
base.Pawn.Label,
" hediff #",
num,
": ",
hediff.def.defName
}), this.MyDebug);
int num2 = 0;
foreach (HediffDef hediffDef in this.Props.hediffToNullify)
{
Tools.Warn(string.Concat(new object[]
{
" Props.hediffToNullify #",
num2,
": ",
hediffDef
}), this.MyDebug);
bool flag = hediff.def == hediffDef && this.Props.hediffToApply != hediffDef;
if (flag)
{
hediff.Severity = 0f;
Tools.Warn(hediff.def.defName + " removed", this.MyDebug);
}
num2++;
}
num++;
}
}
}
public void PatternNullifyHediff()
{
int num = 0;
checked
{
foreach (Hediff hediff in base.Pawn.health.hediffSet.hediffs)
{
bool myDebug = this.MyDebug;
if (myDebug)
{
Log.Warning(string.Concat(new object[]
{
base.Pawn.LabelShort,
" hediff #",
num,
": ",
hediff.def.defName
}));
}
int num2 = 0;
foreach (string text in this.Props.hediffPatternToNullify)
{
bool myDebug2 = this.MyDebug;
if (myDebug2)
{
Log.Warning(string.Concat(new object[]
{
" Props.hediffPatternToNullify #",
num2,
": ",
text
}));
}
bool flag = this.PatternMatch(hediff.def.defName);
if (flag)
{
hediff.Severity = 0f;
Tools.Warn(hediff.def.defName + " severity = 0", this.MyDebug);
}
num2++;
}
num++;
}
}
}
public void ApplyHediff()
{
HediffDef hediffToApply = this.Props.hediffToApply;
bool flag = hediffToApply == null;
if (flag)
{
bool myDebug = this.MyDebug;
if (myDebug)
{
Log.Warning("cant find hediff called: " + this.Props.hediffToApply);
}
}
else
{
BodyPartDef bodyPartDef = (from b in DefDatabase<BodyPartDef>.AllDefs
where b == this.Props.bodyPartDef
select b).RandomElementWithFallback(null);
BodyPartRecord bodyPartRecord = null;
bool flag2 = bodyPartDef != null;
if (flag2)
{
bodyPartRecord = base.Pawn.RaceProps.body.GetPartsWithDef(bodyPartDef).RandomElementWithFallback(null);
bool flag3 = bodyPartRecord == null;
if (flag3)
{
bool myDebug2 = this.MyDebug;
if (myDebug2)
{
Log.Warning("cant find body part record called: " + this.Props.bodyPartDef.defName);
}
return;
}
}
Hediff hediff = HediffMaker.MakeHediff(hediffToApply, base.Pawn, bodyPartRecord);
bool flag4 = hediff == null;
if (flag4)
{
bool myDebug3 = this.MyDebug;
if (myDebug3)
{
Log.Warning("cant create hediff " + hediffToApply.defName + " to apply on " + this.Props.bodyPartDef.defName);
}
}
else
{
base.Pawn.health.AddHediff(hediff, bodyPartRecord, null, null);
}
}
}
public bool CheckProps()
{
string text = this.DebugStr + "ApplyHediff - ";
bool flag = this.Props.bodyDef != null;
if (flag)
{
bool flag2 = base.Pawn.def.race.body != this.Props.bodyDef;
if (flag2)
{
bool myDebug = this.MyDebug;
if (myDebug)
{
Log.Warning(string.Concat(new string[]
{
base.Pawn.Label,
" has not a bodyDef like required: ",
base.Pawn.def.race.body.ToString(),
"!=",
this.Props.bodyDef.ToString()
}));
}
return false;
}
}
bool hasAccessList = this.HasAccessList;
if (hasAccessList)
{
bool blackListCompliant = this.BlackListCompliant;
bool whiteListCompliant = this.WhiteListCompliant;
bool flag3 = !blackListCompliant || !whiteListCompliant;
if (flag3)
{
bool myDebug2 = this.MyDebug;
if (myDebug2)
{
Log.Warning(string.Concat(new string[]
{
text,
this.HasWhiteList ? string.Format("Props.BodyDefWhiteList contains {0} elements", this.Props.bodyDefWhiteList.Count) : "No whitelist",
", compliant: ",
whiteListCompliant.ToString(),
"; ",
this.HasBlackList ? string.Format("Props.BodyDefBlackList contains {0} elements", this.Props.bodyDefBlackList.Count) : "No blacklist",
", compliant:",
blackListCompliant.ToString()
}));
}
return false;
}
bool myDebug3 = this.MyDebug;
if (myDebug3)
{
Log.Warning(text + " AccessList compliant ok");
}
}
return true;
}
public override void CompPostTick(ref float severityAdjustment)
{
bool flag = base.Pawn.Negligible();
if (!flag)
{
bool flag2 = this.CheckProps();
if (flag2)
{
bool hasHediffToNullify = this.HasHediffToNullify;
if (hasHediffToNullify)
{
this.NullifyHediff();
}
bool hasHediffPatternToNullify = this.HasHediffPatternToNullify;
if (hasHediffPatternToNullify)
{
this.PatternNullifyHediff();
}
bool hasHediffToApply = this.HasHediffToApply;
if (hasHediffToApply)
{
this.ApplyHediff();
}
}
Tools.DestroyParentHediff(this.parent, this.MyDebug);
}
}
public override string CompTipStringExtra
{
get
{
string empty = string.Empty;
return empty + "This should disappear very fast";
}
}
private const int tickLimiterModulo = 60;
}
}

View File

@ -0,0 +1,24 @@
using System;
using Verse;
namespace MoharHediffs
{
public class HediffAndBodyPart
{
public HediffDef hediff;
public BodyPartDef bodyPart;
public string bodyPartLabel;
public bool prioritizeMissing = false;
public bool allowMissing = true;
public bool regenIfMissing = true;
public bool allowAddedPart = true;
public bool wholeBodyFallback = true;
}
}

View File

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using Verse;
namespace MoharHediffs
{
public class HediffCompProperties_AnotherRandom : HediffCompProperties
{
public bool HasConditionsToApplyHediffs
{
get
{
return this.conditionsToApplyHediffs != null;
}
}
public bool HasDefaultCondition
{
get
{
return this.defaultCondition != null;
}
}
public bool HasHediffPool
{
get
{
return !this.hediffPool.NullOrEmpty<HediffItem>();
}
}
public HediffCompProperties_AnotherRandom()
{
this.compClass = typeof(HediffComp_AnotherRandom);
}
public HediffCondition conditionsToApplyHediffs;
public HediffCondition defaultCondition;
public List<HediffItem> hediffPool;
public IntRange hediffToApplyNumRange = new IntRange(1, 1);
public bool excludePickedItems = true;
public bool excludeRandomlyNotApplied = false;
public bool debug = false;
public int verbosity = 1;
}
}

View File

@ -0,0 +1,21 @@
using System;
using Verse;
namespace MoharHediffs
{
public class HediffCompProperties_Filther : HediffCompProperties
{
public HediffCompProperties_Filther()
{
this.compClass = typeof(HediffComp_Filther);
}
public int MinTicksBetweenSprays = 60;
public int MaxTicksBetweenSprays = 120;
public ThingDef filthDef = null;
public bool debug = false;
}
}

View File

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using Verse;
namespace MoharHediffs
{
public class HediffCompProperties_HediffNullifier : HediffCompProperties
{
public HediffCompProperties_HediffNullifier()
{
this.compClass = typeof(HediffComp_HediffNullifier);
}
public int checkPeriod = 240;
public List<HediffDef> hediffToNullify;
public int limitedUsageNumber = -99;
public List<BodyPartDef> RequiredBodyPart;
public bool showMessage = false;
public string nullifyKey = "";
public bool concatUsageLimit = false;
public string limitedKey = "";
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using Verse;
namespace MoharHediffs
{
public class HediffCompProperties_HediffRandom : HediffCompProperties
{
public HediffCompProperties_HediffRandom()
{
this.compClass = typeof(HediffComp_HediffRandom);
}
public BodyDef bodyDef;
public List<HediffDef> hediffPool;
public List<int> weights;
public List<BodyPartDef> bodyPartDef;
public bool debug = false;
public bool hideBySeverity = true;
}
}

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using Verse;
namespace MoharHediffs
{
public class HediffCompProperties_InnerShine : HediffCompProperties
{
public bool HasShinePool
{
get
{
return this.HasRawShinePool || this.HasShineDefPool;
}
}
public bool HasRawShinePool
{
get
{
return !this.innerShinePool.NullOrEmpty<InnerShineItem>();
}
}
public bool HasShineDefPool
{
get
{
return !this.innerShineDefPool.NullOrEmpty<InnerShineDef>();
}
}
public HediffCompProperties_InnerShine()
{
this.compClass = typeof(HediffComp_InnerShine);
}
public List<InnerShineItem> innerShinePool;
public List<InnerShineDef> innerShineDefPool;
public bool debug;
}
}

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using Verse;
namespace MoharHediffs
{
public class HediffCompProperties_MultipleHediff : HediffCompProperties
{
public HediffCompProperties_MultipleHediff()
{
this.compClass = typeof(HediffComp_MultipleHediff);
}
public BodyDef bodyDef;
public List<BodyDef> bodyDefWhiteList;
public List<BodyDef> bodyDefBlackList;
public List<HediffAndBodyPart> hediffAndBodypart;
public bool debug = false;
}
}

View File

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using Verse;
namespace MoharHediffs
{
public class HediffCompProperties_OnTheCarpet : HediffCompProperties
{
public bool HasDefaultCondition
{
get
{
return this.defaultCondition != null;
}
}
public bool HasHediffPool
{
get
{
return !this.hediffPool.NullOrEmpty<HediffItemToRemove>();
}
}
public int ItemCount
{
get
{
return this.HasHediffPool ? this.hediffPool.Count : 0;
}
}
public HediffCompProperties_OnTheCarpet()
{
this.compClass = typeof(HediffComp_OnTheCarpet);
}
public List<HediffItemToRemove> hediffPool;
public HediffKeepingCondition defaultCondition;
public int checkPeriod = 120;
public int graceTimeBase = 120;
public bool debug = false;
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using Verse;
namespace MoharHediffs
{
public class HediffCompProperties_PostRemoveTrigger_HediffAdd : HediffCompProperties
{
public HediffCompProperties_PostRemoveTrigger_HediffAdd()
{
this.compClass = typeof(HediffComp_PostRemoveTrigger_HediffAdd);
}
public List<HediffDef> triggeredHediff;
public bool debug = false;
}
}

View File

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using Verse;
namespace MoharHediffs
{
public class HediffCompProperties_RainbowTrail : HediffCompProperties
{
public HediffCompProperties_RainbowTrail()
{
this.compClass = typeof(HediffComp_RainbowTrail);
}
public int period = 15;
public List<ThingDef> motePurpleDef;
public List<ThingDef> moteBlueDef;
public List<ThingDef> moteGreenDef;
public List<ThingDef> moteYellowDef;
public List<ThingDef> moteOrangeDef;
public List<ThingDef> moteRedDef;
public float staySameColorChance = 0.5f;
public int maxTimesSameColor = 3;
public int minTimesSameColor = 1;
public FloatRange scale = new FloatRange(0.5f, 0.8f);
public bool threeColorsGradient = false;
public HediffComp_RainbowTrail.ColorChoice colorChoice = HediffComp_RainbowTrail.ColorChoice.random;
public HediffComp_RainbowTrail.CycleKind cycleKind = HediffComp_RainbowTrail.CycleKind.circular;
public bool debug = false;
public bool hideBySeverity = true;
}
}

View File

@ -0,0 +1,45 @@
using System;
using Verse;
namespace MoharHediffs
{
public class HediffCompProperties_RandySpawnUponDeath : HediffCompProperties
{
public bool HasRequirements
{
get
{
return this.requirements != null;
}
}
public bool HasParentRedress
{
get
{
return this.redressParent != null;
}
}
public HediffCompProperties_RandySpawnUponDeath()
{
this.compClass = typeof(HediffComp_RandySpawnUponDeath);
}
public GeneralSettings settings;
public RedressSettings redressParent;
public RequirementSettings requirements;
public IntRange iterationRange = new IntRange(1, 1);
public bool excludeAlreadyPickedOptions = false;
public int spawnMaxAdjacent = -1;
public bool spawnForbidden = false;
public bool debug = false;
}
}

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using Verse;
namespace MoharHediffs
{
public class HediffCompProperties_RandySpawner : HediffCompProperties
{
public HediffCompProperties_RandySpawner()
{
this.compClass = typeof(HediffComp_RandySpawner);
}
public List<ItemParameter> itemParameters;
public int spawnMaxAdjacent = -1;
public bool spawnForbidden = false;
public bool hungerRelative = false;
public bool healthRelative = false;
public bool logNextSpawn = false;
public bool debug = false;
}
}

View File

@ -0,0 +1,55 @@
using System;
using Verse;
namespace MoharHediffs
{
public class HediffCompProperties_Spawner : HediffCompProperties
{
public HediffCompProperties_Spawner()
{
this.compClass = typeof(HediffComp_Spawner);
}
public ThingDef thingToSpawn;
public int spawnCount = 1;
public bool animalThing = false;
public PawnKindDef animalToSpawn;
public bool factionOfPlayerAnimal = false;
public float minDaysB4Next = 1f;
public float maxDaysB4Next = 2f;
public float randomGrace = 0f;
public float graceDays = 0.5f;
public int spawnMaxAdjacent = -1;
public bool spawnForbidden = false;
public bool hungerRelative = false;
public bool healthRelative = false;
public bool ageWeightedQuantity = false;
public bool ageWeightedPeriod = false;
public bool olderSmallerPeriod = false;
public bool olderBiggerQuantity = false;
public bool exponentialQuantity = false;
public int exponentialRatioLimit = 15;
public string spawnVerb = "delivery";
public bool debug = false;
}
}

View File

@ -0,0 +1,27 @@
using System;
using Verse;
namespace MoharHediffs
{
public class HediffCompProperties_Steamer : HediffCompProperties
{
public HediffCompProperties_Steamer()
{
this.compClass = typeof(HediffComp_Steamer);
}
public int MinTicksBetweenSprays = 200;
public int MaxTicksBetweenSprays = 400;
public int MinSprayDuration = 60;
public int MaxSprayDuration = 120;
public float puffingChance = 1f;
public float temperatureIncreasePerPuff = 0.5f;
public bool debug = false;
}
}

View File

@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using Verse;
namespace MoharHediffs
{
public class HediffCompProperties_TrailLeaver : HediffCompProperties
{
public bool HasRestriction
{
get
{
return this.restriction != null;
}
}
public bool HasColorRange
{
get
{
return this.colorRange != null;
}
}
public bool UsesFootPrints
{
get
{
return this.footprint != null;
}
}
public bool HasMotePool
{
get
{
return !this.motePool.NullOrEmpty<ThingDef>();
}
}
public bool HasOffset
{
get
{
return !this.offSetPerBodyType.NullOrEmpty<BodyTypeOffset>();
}
}
public bool HasRotationOffset
{
get
{
return this.rotationOffset != 0f;
}
}
public HediffCompProperties_TrailLeaver()
{
this.compClass = typeof(HediffComp_TrailLeaver);
}
public IntRange period = new IntRange(15, 25);
public List<ThingDef> motePool;
public List<BodyTypeOffset> offSetPerBodyType;
public Vector3 defaultOffset = new Vector3(0f, 0f, -0.32f);
public Restriction restriction;
public Footprint footprint;
public ColorRange colorRange;
public float rotationOffset = 0f;
public bool dynamicRotation = true;
public FloatRange randomScale = new FloatRange(0.5f, 0.8f);
public bool debug = false;
}
}

View File

@ -0,0 +1,322 @@
using System;
using System.Collections.Generic;
using Verse;
namespace MoharHediffs
{
public class HediffComp_AnotherRandom : HediffComp
{
public bool HasItems
{
get
{
return this.Props.HasHediffPool;
}
}
public int ItemNum
{
get
{
return this.Props.hediffPool.Count;
}
}
public bool MyDebug
{
get
{
return this.Props.debug;
}
}
public bool LowVerbosity
{
get
{
return this.Props.debug && this.Props.verbosity >= 1;
}
}
public bool MediumVerbosity
{
get
{
return this.Props.debug && this.Props.verbosity >= 2;
}
}
public bool HighVerbosity
{
get
{
return this.Props.debug && this.Props.verbosity >= 3;
}
}
public HediffCompProperties_AnotherRandom Props
{
get
{
return (HediffCompProperties_AnotherRandom)this.props;
}
}
public void DumpProps()
{
string text = "CheckProps";
bool flag = !this.HasItems;
if (flag)
{
Tools.Warn(text + "- HediffComp_AnotherRandom; no item found", this.MyDebug);
}
else
{
Tools.Warn(string.Concat(new object[]
{
text,
"- HediffComp_AnotherRandom; found ",
this.ItemNum,
" items"
}), this.MyDebug);
}
}
public override void CompPostMake()
{
base.CompPostMake();
string text = this.MyDebug ? (base.Pawn.LabelShort + " CompPostMake - ") : "";
bool myDebug = this.MyDebug;
if (myDebug)
{
this.DumpProps();
}
bool flag = !this.HasItems;
if (flag)
{
Tools.Warn(text + " found no item to work with, destroying ", this.MyDebug);
base.Pawn.DestroyHediff(this.parent, this.MyDebug);
this.blockAction = true;
}
else
{
Tools.Warn(string.Concat(new object[]
{
text,
" found ",
this.ItemNum,
" items to work with"
}), this.MyDebug);
bool hasConditionsToApplyHediffs = this.Props.HasConditionsToApplyHediffs;
if (hasConditionsToApplyHediffs)
{
BodyPartRecord bodyPartRecord;
bool flag2 = !this.Props.conditionsToApplyHediffs.pawn.ValidateCompatibilityOfHediffWithPawn(base.Pawn, this.MyDebug) || !this.Props.conditionsToApplyHediffs.bodyPart.GetBPRFromHediffCondition(base.Pawn, out bodyPartRecord, this.MyDebug);
if (flag2)
{
Tools.Warn(text + " is not compatible with this hediff, destroying ", this.MyDebug);
base.Pawn.DestroyHediff(this.parent, this.MyDebug);
this.blockAction = true;
return;
}
}
else
{
Tools.Warn(text + " skipped HasConditionsToApplyHediffs", this.MyDebug);
}
Tools.Warn(string.Concat(new object[]
{
text,
" checking if at least 1 hediff from ",
this.ItemNum,
" is appliable"
}), this.MyDebug);
bool flag3 = !this.InitialHediffConditionCheck(this.MyDebug);
if (flag3)
{
Tools.Warn(text + " has found no appliable item, destroying ", this.MyDebug);
base.Pawn.DestroyHediff(this.parent, this.MyDebug);
this.blockAction = true;
}
else
{
Tools.Warn(text + " found at least 1 appliable hediff", this.MyDebug);
}
}
}
public void ApplyHediff(Pawn pawn)
{
string text = this.MyDebug ? (base.Pawn.LabelShort + " - " + this.parent.def.defName + " - ApplyHediff") : "";
List<HediffItem> list = new List<HediffItem>();
int randomInRange = this.Props.hediffToApplyNumRange.RandomInRange;
List<HediffItem> list2 = this.GetCompatibleItems();
bool flag = list2.NullOrEmpty<HediffItem>();
checked
{
if (!flag)
{
Tools.Warn(string.Concat(new object[]
{
text,
"Trying to apply ",
randomInRange,
" hediffs among ",
list2.Count,
" options pool"
}), this.MyDebug);
for (int i = 0; i < randomInRange; i++)
{
string text2 = this.MyDebug ? string.Concat(new object[]
{
"[",
i,
"/",
randomInRange,
"]"
}) : "";
bool flag2 = !list.NullOrEmpty<HediffItem>();
if (flag2)
{
list2 = list2.GetRemainingItems(list);
bool flag3 = list2.NullOrEmpty<HediffItem>();
if (flag3)
{
break;
}
}
Tools.Warn(string.Concat(new object[]
{
text,
text2,
" ",
list2.Count,
" options remaining "
}), this.MyDebug);
HediffItem hediffItem = list2.PickRandomWeightedItem(false);
bool flag4 = hediffItem == null;
if (flag4)
{
Tools.Warn(text + text2 + " null hediffItem, giving up ", this.MyDebug);
break;
}
Tools.Warn(string.Concat(new object[]
{
text,
text2,
" found a hediffItem:",
(hediffItem != null) ? hediffItem.hediffDef : null,
", going on "
}), this.MyDebug);
float randomInRange2 = hediffItem.applyChance.RandomInRange;
bool flag5 = !Rand.Chance(randomInRange2);
if (flag5)
{
Tools.Warn(string.Concat(new object[]
{
text,
text2,
" rand(",
randomInRange2,
") == false, nothing is applied"
}), this.MyDebug);
bool flag6 = this.Props.excludePickedItems && this.Props.excludeRandomlyNotApplied;
if (flag6)
{
list.Add(hediffItem);
}
}
else
{
Tools.Warn(string.Concat(new object[]
{
text,
text2,
" rand(",
randomInRange2,
") == true, hediff:",
(hediffItem != null) ? hediffItem.hediffDef : null,
" will be applied"
}), this.MyDebug);
HediffDef hediffDef = hediffItem.hediffDef;
bool flag7 = hediffDef == null;
if (flag7)
{
Tools.Warn(text + text2 + "cant find hediff, giving up", this.MyDebug);
break;
}
HediffCompProperties_AnotherRandom props = this.Props;
HediffCondition defaultPlusSpecificHediffCondition = ConditionBuilder.GetDefaultPlusSpecificHediffCondition(((props != null) ? props.defaultCondition : null) ?? null, ((hediffItem != null) ? hediffItem.specificCondition : null) ?? null, this.HighVerbosity);
BodyPartRecord bodyPartRecord;
bool flag8 = !defaultPlusSpecificHediffCondition.bodyPart.GetBPRFromHediffCondition(base.Pawn, out bodyPartRecord, this.MyDebug);
if (flag8)
{
Tools.Warn(text + text2 + " could not find anything suitable, giving up", this.MyDebug);
break;
}
Hediff hediff = HediffMaker.MakeHediff(hediffDef, pawn, bodyPartRecord);
bool flag9 = hediff == null;
if (flag9)
{
Tools.Warn(text + text2 + "cant create hediff", this.MyDebug);
break;
}
hediff.Severity = hediffItem.severity.RandomInRange;
Tools.Warn(string.Concat(new object[]
{
text,
text2,
" Applying hediff:",
hediffDef.defName,
"; bpr:",
(bodyPartRecord == null) ? "body" : bodyPartRecord.def.defName,
"; severity:",
hediff.Severity
}), this.MyDebug);
pawn.health.AddHediff(hediff, bodyPartRecord, null, null);
bool excludePickedItems = this.Props.excludePickedItems;
if (excludePickedItems)
{
list.Add(hediffItem);
}
}
}
}
}
}
public override void CompPostTick(ref float severityAdjustment)
{
Pawn pawn = this.parent.pawn;
bool flag = !Tools.OkPawn(pawn);
if (!flag)
{
bool flag2 = this.blockAction;
if (flag2)
{
base.Pawn.DestroyHediff(this.parent, this.MyDebug);
}
else
{
bool hasItems = this.HasItems;
if (hasItems)
{
this.ApplyHediff(pawn);
}
base.Pawn.DestroyHediff(this.parent, this.MyDebug);
}
}
}
public override string CompTipStringExtra
{
get
{
string empty = string.Empty;
return empty + "This should disappear very fast";
}
}
private bool blockAction = false;
}
}

View File

@ -0,0 +1,64 @@
using System;
using RimWorld;
using Verse;
namespace MoharHediffs
{
public class HediffComp_Filther : HediffComp
{
public HediffCompProperties_Filther Props
{
get
{
return (HediffCompProperties_Filther)this.props;
}
}
public override void CompPostMake()
{
this.myDebug = this.Props.debug;
}
public override void CompPostTick(ref float severityAdjustment)
{
this.myPawn = this.parent.pawn;
bool flag = this.myPawn == null;
checked
{
if (flag)
{
Tools.Warn("pawn null", this.myDebug);
}
else
{
bool flag2 = this.myPawn.Map == null;
if (!flag2)
{
bool flag3 = this.Props.filthDef == null;
if (!flag3)
{
bool flag4 = this.filthTicksLeft <= 0;
if (flag4)
{
FilthMaker.TryMakeFilth(this.myPawn.Position, this.myPawn.Map, this.Props.filthDef, 1, FilthSourceFlags.None, true);
this.filthTicksLeft = (this.ticksUntilFilth = Rand.RangeInclusive(this.Props.MinTicksBetweenSprays, this.Props.MaxTicksBetweenSprays));
}
else
{
this.filthTicksLeft--;
}
}
}
}
}
}
private Pawn myPawn = null;
private int ticksUntilFilth = 500;
private int filthTicksLeft;
private bool myDebug = false;
}
}

View File

@ -0,0 +1,230 @@
using System;
using System.Linq;
using RimWorld;
using Verse;
namespace MoharHediffs
{
public class HediffComp_HediffNullifier : HediffComp
{
public HediffCompProperties_HediffNullifier Props
{
get
{
return (HediffCompProperties_HediffNullifier)this.props;
}
}
public bool RequiresAtLeastOneBodyPart
{
get
{
return !this.Props.RequiredBodyPart.NullOrEmpty<BodyPartDef>();
}
}
public bool HasMessageToDisplay
{
get
{
return this.Props.showMessage && !this.Props.nullifyKey.NullOrEmpty();
}
}
public bool DisplayLimitedUsageLeft
{
get
{
return this.HasMessageToDisplay && this.Props.concatUsageLimit && !this.Props.limitedKey.NullOrEmpty();
}
}
public bool HasHediffToNullify
{
get
{
return !this.Props.hediffToNullify.NullOrEmpty<HediffDef>();
}
}
public bool HasLimitedUsage
{
get
{
return this.Props.limitedUsageNumber != -99;
}
}
public void BlockAndDestroy()
{
Tools.DestroyParentHediff(this.parent, this.myDebug);
this.BlockPostTick = true;
}
public override void CompPostMake()
{
bool flag = this.myDebug;
if (flag)
{
Log.Warning(">>>" + this.parent.def.defName + " - CompPostMake start");
}
bool flag2 = !this.HasHediffToNullify;
if (flag2)
{
bool flag3 = this.myDebug;
if (flag3)
{
Log.Warning(this.parent.def.defName + " has no hediff to nullify, autokill");
}
this.BlockAndDestroy();
}
this.DestroyHediffIfMissingBP();
bool hasLimitedUsage = this.HasLimitedUsage;
if (hasLimitedUsage)
{
this.LimitedUsageNumber = this.Props.limitedUsageNumber;
}
}
public void DestroyHediffIfMissingBP()
{
bool flag = !this.RequiresAtLeastOneBodyPart;
if (!flag)
{
bool flag2 = false;
foreach (BodyPartDef bodyPartDef in this.Props.RequiredBodyPart)
{
bool flag3;
flag2 = (flag3 = base.Pawn.CheckIfExistingNaturalBP(bodyPartDef, false));
if (flag3)
{
break;
}
}
bool flag4 = !flag2;
if (flag4)
{
bool flag5 = this.myDebug;
if (flag5)
{
Log.Warning(base.Pawn.LabelShort + " does not have any required body part to have an active " + this.parent.def.defName + ", autokill");
}
this.BlockAndDestroy();
}
}
}
public override void CompExposeData()
{
Scribe_Values.Look<int>(ref this.LimitedUsageNumber, "LimitedUsageNumber", 0, false);
}
public override void CompPostTick(ref float severityAdjustment)
{
bool flag = !base.Pawn.IsHashIntervalTick(this.Props.checkPeriod);
checked
{
if (!flag)
{
bool flag2 = !Tools.OkPawn(base.Pawn);
if (!flag2)
{
this.DestroyHediffIfMissingBP();
bool blockPostTick = this.BlockPostTick;
if (!blockPostTick)
{
foreach (Hediff hediff in from h in base.Pawn.health.hediffSet.hediffs
where this.Props.hediffToNullify.Contains(h.def)
select h)
{
bool flag3 = this.myDebug;
if (flag3)
{
Log.Warning(base.Pawn.Label + " - " + hediff.def.defName);
}
hediff.Severity = 0f;
bool flag4 = this.myDebug;
if (flag4)
{
Log.Warning(hediff.def.defName + " severity = 0");
}
bool hasLimitedUsage = this.HasLimitedUsage;
if (hasLimitedUsage)
{
this.LimitedUsageNumber--;
bool flag5 = this.LimitedUsageNumber <= 0;
if (flag5)
{
bool flag6 = this.myDebug;
if (flag6)
{
Log.Warning(this.parent.def.defName + " has reached its limit usage, autokill");
}
Tools.DestroyParentHediff(this.parent, this.myDebug);
}
}
bool hasMessageToDisplay = this.HasMessageToDisplay;
if (hasMessageToDisplay)
{
string text = this.Props.nullifyKey.Translate(base.Pawn.LabelShort, hediff.def.label, base.Pawn.gender.GetPronoun(), base.Pawn.kindDef.race.label);
bool displayLimitedUsageLeft = this.DisplayLimitedUsageLeft;
if (displayLimitedUsageLeft)
{
text += this.Props.limitedKey.Translate(this.LimitedUsageNumber);
}
text += ".";
Messages.Message(text, MessageTypeDefOf.NeutralEvent, true);
}
}
}
}
}
}
}
public override string CompTipStringExtra
{
get
{
string text = string.Empty;
bool flag = !this.HasHediffToNullify;
string result;
if (flag)
{
result = text;
}
else
{
text += "Immune to: ";
foreach (HediffDef hediffDef in this.Props.hediffToNullify)
{
text = text + hediffDef.label + "; ";
}
bool flag2 = !this.HasLimitedUsage;
if (flag2)
{
text += " for ever";
}
else
{
text = string.Concat(new object[]
{
text,
" ",
this.LimitedUsageNumber,
" left"
});
}
result = text;
}
return result;
}
}
private int LimitedUsageNumber = 0;
private bool BlockPostTick = false;
private readonly bool myDebug = false;
}
}

View File

@ -0,0 +1,178 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Verse;
namespace MoharHediffs
{
public class HediffComp_HediffRandom : HediffComp
{
public HediffCompProperties_HediffRandom Props
{
get
{
return (HediffCompProperties_HediffRandom)this.props;
}
}
private bool myDebug
{
get
{
return this.Props.debug;
}
}
private bool HasWeights
{
get
{
return !this.Props.weights.NullOrEmpty<int>() && this.Props.weights.Count == this.Props.hediffPool.Count;
}
}
private bool HasBodyParts
{
get
{
return !this.Props.bodyPartDef.NullOrEmpty<BodyPartDef>() && this.Props.bodyPartDef.Count == this.Props.hediffPool.Count;
}
}
private bool HasHediff
{
get
{
return !this.Props.hediffPool.NullOrEmpty<HediffDef>();
}
}
private Pawn pawn
{
get
{
return this.parent.pawn;
}
}
public override void CompPostMake()
{
bool hideBySeverity = this.Props.hideBySeverity;
if (hideBySeverity)
{
this.parent.Severity = 0.05f;
}
}
public int WeightedRandomness
{
get
{
int num = 0;
checked
{
foreach (int num2 in this.Props.weights)
{
num += num2;
}
int num3 = Rand.Range(0, num);
for (int i = 0; i < this.Props.weights.Count; i++)
{
int num4 = this.Props.weights[i];
bool flag = (num3 -= num4) < 0;
if (flag)
{
return i;
}
}
return 0;
}
}
}
public void ApplyHediff(Pawn pawn)
{
bool flag = this.Props.bodyDef != null;
if (flag)
{
bool flag2 = pawn.def.race.body != this.Props.bodyDef;
if (flag2)
{
Tools.Warn(string.Concat(new string[]
{
pawn.Label,
" has not a bodyDef like required: ",
pawn.def.race.body.ToString(),
"!=",
this.Props.bodyDef.ToString()
}), this.myDebug);
return;
}
}
bool flag3 = !this.HasWeights;
int num;
if (flag3)
{
num = Rand.Range(0, this.Props.hediffPool.Count<HediffDef>());
}
else
{
num = this.WeightedRandomness;
}
bool flag4 = num < 0 || num >= this.Props.hediffPool.Count;
if (flag4)
{
Tools.Warn(num + " is out of range. Applyhediff will fail. Please report this error.", this.myDebug);
}
HediffDef hediffDef = this.Props.hediffPool[num];
bool flag5 = hediffDef == null;
if (flag5)
{
Tools.Warn("cant find hediff", this.myDebug);
}
else
{
BodyPartRecord bodyPartRecord = null;
BodyPartDef bodyPartDef = null;
bool hasBodyParts = this.HasBodyParts;
if (hasBodyParts)
{
bodyPartDef = this.Props.bodyPartDef[num];
IEnumerable<BodyPartRecord> partsWithDef = pawn.RaceProps.body.GetPartsWithDef(bodyPartDef);
bool flag6 = partsWithDef.EnumerableNullOrEmpty<BodyPartRecord>();
if (flag6)
{
Tools.Warn("cant find body part record called: " + bodyPartDef.defName, this.myDebug);
return;
}
bodyPartRecord = partsWithDef.RandomElement<BodyPartRecord>();
}
Hediff hediff = HediffMaker.MakeHediff(hediffDef, pawn, bodyPartRecord);
bool flag7 = hediff == null;
if (flag7)
{
Tools.Warn("cant create hediff " + hediffDef.defName + " to apply on " + ((bodyPartDef != null) ? bodyPartDef.defName : null), this.myDebug);
}
else
{
pawn.health.AddHediff(hediff, bodyPartRecord, null, null);
Tools.Warn("Succesfully applied " + hediffDef.defName + " to apply on " + ((bodyPartDef != null) ? bodyPartDef.defName : null), this.myDebug);
}
}
}
public override void CompPostTick(ref float severityAdjustment)
{
bool flag = !Tools.OkPawn(this.pawn);
if (!flag)
{
bool hasHediff = this.HasHediff;
if (hasHediff)
{
this.ApplyHediff(this.pawn);
}
Tools.DestroyParentHediff(this.parent, this.myDebug);
}
}
}
}

View File

@ -0,0 +1,209 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Verse;
namespace MoharHediffs
{
public class HediffComp_InnerShine : HediffComp
{
public Map MyMap
{
get
{
return base.Pawn.Map;
}
}
public bool NullMap
{
get
{
return this.MyMap == null;
}
}
public bool MyDebug
{
get
{
return this.Props.debug;
}
}
public bool HasEmptyTracer
{
get
{
return this.Tracer.NullOrEmpty<InnerShineRecord>();
}
}
public bool HasShinePool
{
get
{
return this.Props.HasShinePool;
}
}
public HediffCompProperties_InnerShine Props
{
get
{
return (HediffCompProperties_InnerShine)this.props;
}
}
public override void CompPostMake()
{
this.PropsCheck();
this.CreateTracer();
}
public override void CompPostTick(ref float severityAdjustment)
{
bool flag = base.Pawn.Negligible();
checked
{
if (flag)
{
bool myDebug = this.MyDebug;
if (myDebug)
{
Log.Warning("null pawn");
}
}
else
{
bool hasEmptyTracer = this.HasEmptyTracer;
if (hasEmptyTracer)
{
this.CreateTracer();
}
foreach (InnerShineRecord innerShineRecord in this.Tracer)
{
InnerShineItem innerShineItem = this.RetrieveISI(innerShineRecord.label);
bool flag2 = innerShineItem == null;
if (flag2)
{
bool myDebug2 = this.MyDebug;
if (myDebug2)
{
Log.Warning("Did not find ISI with label:" + innerShineRecord.label);
}
}
else
{
bool flag3 = innerShineRecord.ticksLeft <= 0;
if (flag3)
{
bool flag4 = innerShineItem.ShouldSpawnMote(innerShineRecord, base.Pawn);
if (flag4)
{
innerShineItem.TryPlaceMote(innerShineRecord, base.Pawn);
}
innerShineItem.ResetTicks(innerShineRecord);
}
else
{
innerShineRecord.ticksLeft--;
}
innerShineItem.UpdateMotes(innerShineRecord, base.Pawn, this.MyDebug);
}
}
}
}
}
public void PropsCheck()
{
bool flag = !this.HasShinePool;
checked
{
if (flag)
{
bool myDebug = this.MyDebug;
if (myDebug)
{
Log.Warning("no shine pool, giving up");
}
this.SelfDestroy();
}
else
{
bool flag2 = !this.MyDebug;
if (!flag2)
{
bool hasRawShinePool = this.Props.HasRawShinePool;
if (hasRawShinePool)
{
IEnumerable<InnerShineItem> enumerable;
bool flag3 = (enumerable = from s in this.Props.innerShinePool
where !s.HasMotePool
select s) != null;
if (flag3)
{
foreach (InnerShineItem innerShineItem in enumerable)
{
Log.Warning(innerShineItem.label + " has no mote pool");
}
}
IEnumerable<InnerShineItem> enumerable2;
bool flag4 = (enumerable2 = from s in this.Props.innerShinePool
where !s.HasDefaultDrawRules && !s.HasBodyTypeDrawRules
select s) != null;
if (flag4)
{
foreach (InnerShineItem innerShineItem2 in enumerable2)
{
Log.Warning(innerShineItem2.label + " has no default nor bodytypedef draw rules, at least one is required");
}
}
int num = 0;
foreach (InnerShineItem innerShineItem3 in this.Props.innerShinePool)
{
Log.Warning("Raw" + num.ToString("00") + " => " + innerShineItem3.Dump());
num++;
}
}
bool hasShineDefPool = this.Props.HasShineDefPool;
if (hasShineDefPool)
{
IEnumerable<InnerShineDef> enumerable3;
bool flag5 = (enumerable3 = from s in this.Props.innerShineDefPool
where !s.item.HasMotePool
select s) != null;
if (flag5)
{
foreach (InnerShineDef innerShineDef in enumerable3)
{
Log.Warning(innerShineDef.item.label + " has no mote pool");
}
}
IEnumerable<InnerShineDef> enumerable4;
bool flag6 = (enumerable4 = from s in this.Props.innerShineDefPool
where !s.item.HasDefaultDrawRules && !s.item.HasBodyTypeDrawRules
select s) != null;
if (flag6)
{
foreach (InnerShineDef innerShineDef2 in enumerable4)
{
Log.Warning(innerShineDef2.item.label + " has no default nor bodytypedef draw rules, at least one is required");
}
}
int num2 = 0;
foreach (InnerShineDef innerShineDef3 in this.Props.innerShineDefPool)
{
Log.Warning("Def" + num2.ToString("00") + " => " + innerShineDef3.item.Dump());
num2++;
}
}
}
}
}
}
public List<InnerShineRecord> Tracer;
}
}

View File

@ -0,0 +1,287 @@
using System;
using Verse;
namespace MoharHediffs
{
public class HediffComp_MultipleHediff : HediffComp
{
private bool MyDebug
{
get
{
return this.Props.debug;
}
}
private string DebugStr
{
get
{
return this.MyDebug ? (base.Pawn.LabelShort + " MultipleHediff " + this.parent.def.defName + " - ") : "";
}
}
private bool HasSingleBodyRequirement
{
get
{
return this.Props.bodyDef != null;
}
}
private bool HasWhiteList
{
get
{
return !this.Props.bodyDefWhiteList.NullOrEmpty<BodyDef>();
}
}
private bool HasBlackList
{
get
{
return !this.Props.bodyDefBlackList.NullOrEmpty<BodyDef>();
}
}
private bool WhiteListCompliant
{
get
{
return !this.HasWhiteList || this.Props.bodyDefWhiteList.Contains(base.Pawn.def.race.body);
}
}
private bool BlackListCompliant
{
get
{
return !this.HasBlackList || !this.Props.bodyDefBlackList.Contains(base.Pawn.def.race.body);
}
}
private bool HasAccessList
{
get
{
return this.HasWhiteList || this.HasBlackList;
}
}
public HediffCompProperties_MultipleHediff Props
{
get
{
return (HediffCompProperties_MultipleHediff)this.props;
}
}
public bool HasHediffToApply
{
get
{
return !this.Props.hediffAndBodypart.NullOrEmpty<HediffAndBodyPart>();
}
}
public void CheckProps()
{
string text = this.DebugStr + "CheckProps - ";
bool flag = !this.HasHediffToApply;
if (flag)
{
Tools.Warn(text + "- empty hediffAndBodypart, destroying", this.MyDebug);
base.Pawn.DestroyHediff(this.parent, false);
this.blockAction = true;
}
bool flag2 = this.HasSingleBodyRequirement && base.Pawn.def.race.body != this.Props.bodyDef;
if (flag2)
{
Tools.Warn(string.Concat(new string[]
{
text,
" has not a bodyDef like required: ",
base.Pawn.def.race.body.ToString(),
"!=",
this.Props.bodyDef.ToString()
}), this.MyDebug);
base.Pawn.DestroyHediff(this.parent, false);
this.blockAction = true;
}
bool hasAccessList = this.HasAccessList;
if (hasAccessList)
{
bool blackListCompliant = this.BlackListCompliant;
bool whiteListCompliant = this.WhiteListCompliant;
bool flag3 = !blackListCompliant || !whiteListCompliant;
if (flag3)
{
bool myDebug = this.MyDebug;
if (myDebug)
{
Log.Warning(string.Concat(new string[]
{
text,
this.HasWhiteList ? string.Format("Props.BodyDefWhiteList contains {0} elements", this.Props.bodyDefWhiteList.Count) : "No whitelist",
", compliant: ",
whiteListCompliant.ToString(),
"; ",
this.HasBlackList ? string.Format("Props.BodyDefBlackList contains {0} elements", this.Props.bodyDefBlackList.Count) : "No blacklist",
", compliant:",
blackListCompliant.ToString()
}));
}
base.Pawn.DestroyHediff(this.parent, false);
this.blockAction = true;
}
else
{
bool myDebug2 = this.MyDebug;
if (myDebug2)
{
Log.Warning(text + " AccessList compliant ok");
}
}
}
bool flag4 = this.Props.hediffAndBodypart.Any((HediffAndBodyPart habp) => habp.bodyPart != null && habp.bodyPartLabel != null);
if (flag4)
{
Tools.Warn(text + "at least one item has both a bodypart def and a bodypart label, label will be prioritized", this.MyDebug);
}
bool flag5 = this.Props.hediffAndBodypart.Any((HediffAndBodyPart habp) => habp.hediff == null);
if (flag5)
{
Tools.Warn(text + "at least one item has no hediff defined. What will happen ?", this.MyDebug);
}
}
public void BlockAndDestroy(string ErrorLog = "", bool myDebug = false)
{
Tools.Warn(ErrorLog, myDebug && !ErrorLog.NullOrEmpty());
this.blockAction = true;
Tools.DestroyParentHediff(this.parent, myDebug);
}
public override void CompPostMake()
{
base.CompPostMake();
Tools.Warn(this.DebugStr + "CompPostMake", this.MyDebug);
this.CheckProps();
}
public void ApplyHediff(Pawn pawn)
{
string text = this.DebugStr + "ApplyHediff - ";
checked
{
for (int i = 0; i < this.Props.hediffAndBodypart.Count; i++)
{
HediffDef hediff = this.Props.hediffAndBodypart[i].hediff;
BodyPartDef bodyPart = this.Props.hediffAndBodypart[i].bodyPart;
string bodyPartLabel = this.Props.hediffAndBodypart[i].bodyPartLabel;
bool prioritizeMissing = this.Props.hediffAndBodypart[i].prioritizeMissing;
bool allowMissing = this.Props.hediffAndBodypart[i].allowMissing;
bool regenIfMissing = this.Props.hediffAndBodypart[i].regenIfMissing;
bool allowAddedPart = this.Props.hediffAndBodypart[i].allowAddedPart;
bool wholeBodyFallback = this.Props.hediffAndBodypart[i].wholeBodyFallback;
bool flag = hediff == null;
if (flag)
{
Tools.Warn(text + "cant find hediff; i=" + i, true);
}
else
{
BodyPartRecord bodyPartRecord = null;
bool flag2 = bodyPartLabel != null || bodyPart != null;
if (flag2)
{
Tools.Warn(string.Concat(new string[]
{
text,
"Trying to retrieve BPR with [BP label]:",
bodyPartLabel,
" [BP def]:",
(bodyPart != null) ? bodyPart.defName : null
}), this.MyDebug);
bodyPartRecord = pawn.GetBPRecordWithoutHediff(bodyPartLabel, bodyPart, hediff, allowMissing, prioritizeMissing, allowAddedPart, this.MyDebug);
}
bool flag3 = bodyPartRecord == null;
if (flag3)
{
Tools.Warn(text + "Could not find a BPR to apply hediff, will pick whole body?" + wholeBodyFallback.ToString(), this.MyDebug);
bool flag4 = !wholeBodyFallback;
if (flag4)
{
goto IL_291;
}
}
bool flag5 = allowMissing && regenIfMissing && bodyPartRecord != null;
if (flag5)
{
Hediff hediff2;
bool flag6 = base.Pawn.IsMissingBPR(bodyPartRecord, out hediff2);
if (flag6)
{
Tools.Warn(text + "regenerating " + bodyPartRecord.customLabel, this.MyDebug);
base.Pawn.health.RemoveHediff(hediff2);
}
}
Hediff hediff3 = HediffMaker.MakeHediff(hediff, pawn, bodyPartRecord);
bool flag7 = hediff3 == null;
if (flag7)
{
Tools.Warn(string.Concat(new string[]
{
text,
"cant create hediff ",
hediff.defName,
" to apply on ",
bodyPart.defName
}), true);
}
else
{
pawn.health.AddHediff(hediff3, bodyPartRecord, null, null);
Tools.Warn(text + "Applied " + hediff.defName, this.MyDebug);
}
}
IL_291:;
}
}
}
public override void CompPostTick(ref float severityAdjustment)
{
bool flag = base.Pawn.Negligible();
if (!flag)
{
bool flag2 = this.blockAction;
if (flag2)
{
Tools.DestroyParentHediff(this.parent, this.MyDebug);
}
else
{
bool hasHediffToApply = this.HasHediffToApply;
if (hasHediffToApply)
{
this.ApplyHediff(base.Pawn);
}
base.Pawn.DestroyHediff(this.parent, this.MyDebug);
}
}
}
public override string CompTipStringExtra
{
get
{
string empty = string.Empty;
return empty + "This should disappear very fast";
}
}
private bool blockAction = false;
}
}

View File

@ -0,0 +1,146 @@
using System;
using Verse;
namespace MoharHediffs
{
public class HediffComp_OnTheCarpet : HediffComp
{
public bool HasItems
{
get
{
return this.Props.HasHediffPool;
}
}
public int ItemCount
{
get
{
return this.Props.ItemCount;
}
}
public bool MyDebug
{
get
{
return this.Props.debug;
}
}
public bool IsTimeToCheck
{
get
{
return base.Pawn.IsHashIntervalTick(this.Props.checkPeriod);
}
}
public HediffCompProperties_OnTheCarpet Props
{
get
{
return (HediffCompProperties_OnTheCarpet)this.props;
}
}
public void BlockAndDestroy(string ErrorLog = "", bool myDebug = false)
{
Tools.Warn(ErrorLog, myDebug && !ErrorLog.NullOrEmpty());
this.blockAction = true;
base.Pawn.DestroyHediff(this.parent, this.MyDebug);
}
public override void CompPostMake()
{
base.CompPostMake();
string text = this.MyDebug ? (base.Pawn.LabelShort + " " + this.parent.def.defName + " CompPostMake - ") : "";
bool flag = !this.HasItems;
if (flag)
{
Tools.Warn(text + " found no item to work with, destroying ", this.MyDebug);
base.Pawn.DestroyHediff(this.parent, this.MyDebug);
this.blockAction = true;
}
else
{
Tools.Warn(string.Concat(new object[]
{
text,
" found ",
this.ItemCount,
" items to work with"
}), this.MyDebug);
bool flag2 = !this.Props.IsPawnNeedCompatible(base.Pawn);
if (flag2)
{
Tools.Warn(text + " is not compatible with this hediff, destroying ", this.MyDebug);
base.Pawn.DestroyHediff(this.parent, this.MyDebug);
this.blockAction = true;
}
else
{
this.SetGraceTime();
Tools.Warn(text + " found something to do", this.MyDebug);
}
}
}
public void SetGraceTime()
{
this.graceTime = this.Props.graceTimeBase;
}
public override void CompExposeData()
{
base.CompExposeData();
Scribe_Values.Look<int>(ref this.graceTime, "graceTime", 0, false);
}
public override void CompPostTick(ref float severityAdjustment)
{
base.CompPostTick(ref severityAdjustment);
bool flag = base.Pawn.Negligible();
if (!flag)
{
bool flag2 = this.blockAction;
if (!flag2)
{
int num = this.graceTime;
this.graceTime = checked(num - 1);
bool flag3 = num > 0;
if (!flag3)
{
bool flag4 = false;
bool isTimeToCheck = this.IsTimeToCheck;
if (isTimeToCheck)
{
flag4 = !this.TreatRelevantHediffsAndReportIfStillHediffsToCheck();
}
bool flag5 = flag4;
if (flag5)
{
base.Pawn.DestroyHediff(this.parent, this.MyDebug);
}
}
}
}
}
public override string CompTipStringExtra
{
get
{
string empty = string.Empty;
return empty + "This should not disappear until an hediff is still there";
}
}
private bool blockAction = false;
private int graceTime = 999;
public bool foundFault = false;
}
}

View File

@ -0,0 +1,99 @@
using System;
using Verse;
namespace MoharHediffs
{
public class HediffComp_PostRemoveTrigger_HediffAdd : HediffComp
{
public HediffCompProperties_PostRemoveTrigger_HediffAdd Props
{
get
{
return (HediffCompProperties_PostRemoveTrigger_HediffAdd)this.props;
}
}
public void CheckProps()
{
bool flag = !this.HasHediffToApply;
if (flag)
{
this.blockAction = true;
Tools.DestroyParentHediff(this.parent, this.Props.debug);
}
}
public bool HasHediffToApply
{
get
{
return !this.Props.triggeredHediff.NullOrEmpty<HediffDef>();
}
}
public void ApplyHediff(Pawn pawn)
{
checked
{
for (int i = 0; i < this.Props.triggeredHediff.Count; i++)
{
HediffDef hediffDef = this.Props.triggeredHediff[i];
bool flag = hediffDef == null;
if (flag)
{
Tools.Warn("cant find hediff; i=" + i, true);
break;
}
Hediff hediff = HediffMaker.MakeHediff(hediffDef, pawn, null);
bool flag2 = hediff == null;
if (flag2)
{
Tools.Warn("cant create hediff " + hediffDef.defName, true);
break;
}
Tools.Warn("Adding " + hediffDef.defName + "for science", this.Props.debug);
pawn.health.AddHediff(hediff, null, null, null);
}
}
}
public override void CompPostPostRemoved()
{
Pawn pawn = this.parent.pawn;
bool flag = !Tools.OkPawn(pawn);
if (flag)
{
Tools.DestroyParentHediff(this.parent, this.Props.debug);
}
else
{
bool flag2 = this.blockAction;
if (!flag2)
{
Tools.Warn(this.parent.def.defName + " is no more, applying hediff", this.Props.debug);
bool hasHediffToApply = this.HasHediffToApply;
if (hasHediffToApply)
{
this.ApplyHediff(pawn);
}
}
}
}
public override string CompTipStringExtra
{
get
{
string text = string.Empty;
bool debug = this.Props.debug;
if (debug)
{
text = text + this.parent.def.defName + " is still alive, aperture science we do what we must";
}
return text;
}
}
private bool blockAction = false;
}
}

View File

@ -0,0 +1,514 @@
using System;
using System.Collections.Generic;
using RimWorld;
using UnityEngine;
using Verse;
namespace MoharHediffs
{
public class HediffComp_RainbowTrail : HediffComp
{
public HediffCompProperties_RainbowTrail Props
{
get
{
return (HediffCompProperties_RainbowTrail)this.props;
}
}
public override void CompPostMake()
{
bool hideBySeverity = this.Props.hideBySeverity;
if (hideBySeverity)
{
this.parent.Severity = 0.05f;
}
this.myDebug = this.Props.debug;
this.Init(this.myDebug);
}
public override void CompExposeData()
{
Scribe_Values.Look<int>(ref this.ticksLeft, "ticksLeft", 0, false);
Scribe_Values.Look<HediffComp_RainbowTrail.RainbowColor>(ref this.curColor, "curColor", HediffComp_RainbowTrail.RainbowColor.purple, false);
Scribe_Values.Look<int>(ref this.variation, "variation", 0, false);
Scribe_Values.Look<bool>(ref this.myDebug, "debug", false, false);
}
public override void CompPostTick(ref float severityAdjustment)
{
this.SetPawnAndMap();
bool flag = this.myPawn == null || this.myMap == null || this.blockAction;
checked
{
if (flag)
{
Tools.Warn(string.Concat(new string[]
{
"null tick - pawn: ",
(this.myPawn == null).ToString(),
"myMap: ",
(this.myMap == null).ToString(),
"blockAction: ",
this.blockAction.ToString()
}), this.myDebug);
}
else
{
bool flag2 = this.moteDef.NullOrEmpty<ThingDef>();
if (flag2)
{
Tools.Warn("empty moteDef", this.myDebug);
this.Init(this.myDebug);
}
TerrainDef terrain = this.myPawn.Position.GetTerrain(this.myPawn.Map);
bool flag3 = terrain == null || terrain.IsWater || this.myPawn.Map.snowGrid.GetDepth(this.myPawn.Position) >= 0.4f || !this.myPawn.Position.InBounds(this.myMap);
if (flag3)
{
Tools.Warn(string.Concat(new object[]
{
this.myPawn,
"'s ",
this.parent.def.defName,
" is blocked by terrain"
}), this.myDebug);
}
else
{
bool flag4 = this.ticksLeft <= 0;
if (flag4)
{
bool flag5 = this.TryPlaceMote();
if (flag5)
{
this.sameColorInRow++;
bool flag6 = this.sameColorInRow >= this.Props.minTimesSameColor || this.sameColorInRow > this.Props.maxTimesSameColor || !Rand.Chance(this.Props.staySameColorChance);
if (flag6)
{
bool threeColorsGradient = this.Props.threeColorsGradient;
if (threeColorsGradient)
{
this.NextColorThreeColors();
}
else
{
this.NextColorRainbow();
}
Tools.Warn(string.Concat(new object[]
{
this.myPawn,
"'s ",
this.parent.def.defName,
" now uses ",
this.curColor,
"after ",
this.sameColorInRow,
"puddles"
}), this.myDebug);
this.SetMoteDef();
this.sameColorInRow = 0;
}
this.Reset();
}
else
{
Tools.Warn(string.Concat(new object[]
{
this.myPawn,
"'s ",
this.parent.def.defName,
"failed to TryPlaceMote"
}), this.myDebug);
}
}
else
{
this.ticksLeft--;
}
}
}
}
}
public void SetMoteDef()
{
switch (this.curColor)
{
case HediffComp_RainbowTrail.RainbowColor.purple:
this.moteDef = this.Props.motePurpleDef;
break;
case HediffComp_RainbowTrail.RainbowColor.blue:
this.moteDef = this.Props.moteBlueDef;
break;
case HediffComp_RainbowTrail.RainbowColor.green:
this.moteDef = this.Props.moteGreenDef;
break;
case HediffComp_RainbowTrail.RainbowColor.yellow:
this.moteDef = this.Props.moteYellowDef;
break;
case HediffComp_RainbowTrail.RainbowColor.orange:
this.moteDef = this.Props.moteOrangeDef;
break;
case HediffComp_RainbowTrail.RainbowColor.red:
this.moteDef = this.Props.moteRedDef;
break;
}
}
public void NextColorRainbow()
{
checked
{
this.curColor += this.variation;
bool flag = this.Props.cycleKind == HediffComp_RainbowTrail.CycleKind.circular;
if (flag)
{
bool flag2 = this.curColor > HediffComp_RainbowTrail.RainbowColor.red;
if (flag2)
{
this.curColor = HediffComp_RainbowTrail.RainbowColor.purple;
}
else
{
bool flag3 = this.curColor < HediffComp_RainbowTrail.RainbowColor.purple;
if (flag3)
{
this.curColor = HediffComp_RainbowTrail.RainbowColor.red;
}
}
}
else
{
bool flag4 = this.Props.cycleKind == HediffComp_RainbowTrail.CycleKind.bouncing;
if (flag4)
{
bool flag5 = this.curColor > HediffComp_RainbowTrail.RainbowColor.red;
if (flag5)
{
this.variation = -1;
this.curColor = HediffComp_RainbowTrail.RainbowColor.orange;
}
else
{
bool flag6 = this.curColor < HediffComp_RainbowTrail.RainbowColor.purple;
if (flag6)
{
this.variation = 1;
this.curColor = HediffComp_RainbowTrail.RainbowColor.blue;
}
}
}
else
{
bool flag7 = this.Props.cycleKind == HediffComp_RainbowTrail.CycleKind.random;
if (flag7)
{
this.curColor = (HediffComp_RainbowTrail.RainbowColor)Rand.Range(0, 6);
}
}
}
}
}
public void NextColorThreeColors()
{
checked
{
this.curColor += this.variation;
bool flag = this.Props.cycleKind == HediffComp_RainbowTrail.CycleKind.circular;
if (flag)
{
bool flag2 = this.curColor > this.topColor;
if (flag2)
{
this.curColor = this.bottomColor;
}
else
{
bool flag3 = this.curColor < this.bottomColor;
if (flag3)
{
this.curColor = this.topColor;
}
}
}
else
{
bool flag4 = this.Props.cycleKind == HediffComp_RainbowTrail.CycleKind.bouncing;
if (flag4)
{
bool flag5 = this.curColor > this.topColor;
if (flag5)
{
this.variation = -1;
this.curColor = this.pivotColor;
}
else
{
bool flag6 = this.curColor < HediffComp_RainbowTrail.RainbowColor.purple;
if (flag6)
{
this.variation = 1;
this.curColor = this.pivotColor;
}
}
}
else
{
bool flag7 = this.Props.cycleKind == HediffComp_RainbowTrail.CycleKind.random;
if (flag7)
{
bool flag8 = Rand.Chance(0.33f);
if (flag8)
{
this.curColor = this.pivotColor;
}
else
{
bool flag9 = Rand.Chance(0.5f);
if (flag9)
{
this.curColor = this.topColor;
}
else
{
this.curColor = this.bottomColor;
}
}
}
}
}
}
}
private void SetPawnAndMap()
{
this.myPawn = this.parent.pawn;
this.myMap = this.myPawn.Map;
}
public HediffComp_RainbowTrail.RainbowColor ColorTranslation(Color myColor)
{
bool flag = myColor == MyGfx.Purple;
HediffComp_RainbowTrail.RainbowColor result;
if (flag)
{
result = HediffComp_RainbowTrail.RainbowColor.purple;
}
else
{
bool flag2 = myColor == MyGfx.Blue;
if (flag2)
{
result = HediffComp_RainbowTrail.RainbowColor.blue;
}
else
{
bool flag3 = myColor == MyGfx.Green;
if (flag3)
{
result = HediffComp_RainbowTrail.RainbowColor.green;
}
else
{
bool flag4 = myColor == MyGfx.Yellow;
if (flag4)
{
result = HediffComp_RainbowTrail.RainbowColor.yellow;
}
else
{
bool flag5 = myColor == MyGfx.Orange;
if (flag5)
{
result = HediffComp_RainbowTrail.RainbowColor.orange;
}
else
{
bool flag6 = myColor == MyGfx.Red;
if (flag6)
{
result = HediffComp_RainbowTrail.RainbowColor.red;
}
else
{
Tools.Warn(this.myPawn.LabelShort + " could not ColorTranslation, default value", this.myDebug);
result = HediffComp_RainbowTrail.RainbowColor.blue;
}
}
}
}
}
}
return result;
}
public void Init(bool myDebug = false)
{
this.SetPawnAndMap();
Tools.Warn(string.Concat(new object[]
{
this.myPawn,
"'s ",
this.parent.def.defName,
" Init"
}), myDebug);
bool flag = this.Props.motePurpleDef.NullOrEmpty<ThingDef>() || this.Props.moteBlueDef.NullOrEmpty<ThingDef>() || this.Props.moteGreenDef.NullOrEmpty<ThingDef>() || this.Props.moteYellowDef.NullOrEmpty<ThingDef>() || this.Props.moteOrangeDef.NullOrEmpty<ThingDef>() || this.Props.moteRedDef.NullOrEmpty<ThingDef>();
if (flag)
{
this.blockAction = true;
this.parent.Severity = 0f;
}
switch (this.Props.colorChoice)
{
case HediffComp_RainbowTrail.ColorChoice.pawnColor:
{
Color myColor = GfxEffects.ClosestColor(this.myPawn, false, myDebug);
this.pivotColor = (this.curColor = this.ColorTranslation(myColor));
break;
}
case HediffComp_RainbowTrail.ColorChoice.complementary:
{
Color myColor2 = GfxEffects.ClosestColor(this.myPawn, true, myDebug);
this.pivotColor = (this.curColor = this.ColorTranslation(myColor2));
break;
}
case HediffComp_RainbowTrail.ColorChoice.random:
this.pivotColor = (this.curColor = (HediffComp_RainbowTrail.RainbowColor)Rand.Range(0, 6));
break;
}
checked
{
this.bottomColor = this.pivotColor - 1;
this.topColor = this.pivotColor + 1;
bool flag2 = this.topColor > HediffComp_RainbowTrail.RainbowColor.red;
if (flag2)
{
this.topColor = HediffComp_RainbowTrail.RainbowColor.purple;
}
bool flag3 = this.bottomColor < HediffComp_RainbowTrail.RainbowColor.purple;
if (flag3)
{
this.bottomColor = HediffComp_RainbowTrail.RainbowColor.red;
}
Tools.Warn(string.Concat(new object[]
{
this.myPawn,
"'s ",
this.parent.def.defName,
" bottom: ",
this.bottomColor,
" pivot: ",
this.pivotColor,
" top: ",
this.topColor
}), myDebug);
this.SetMoteDef();
}
}
public static void PlacePuddle(Vector3 loc, Map map, float rot, float scale, ThingDef Mote_FootprintDef)
{
bool flag = !loc.ShouldSpawnMotesAt(map, true) || map.moteCounter.SaturatedLowPriority;
if (!flag)
{
MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(Mote_FootprintDef, null);
moteThrown.Scale = scale;
moteThrown.exactRotation = rot;
moteThrown.exactPosition = loc;
GenSpawn.Spawn(moteThrown, loc.ToIntVec3(), map, WipeMode.Vanish);
}
}
private bool TryPlaceMote()
{
Vector3 drawPos = this.myPawn.Drawer.DrawPos;
Vector3 normalized = (drawPos - this.lastFootprintPlacePos).normalized;
float rot = normalized.AngleFlat();
Vector3 vector = this.myPawn.TrueCenter() + HediffComp_RainbowTrail.PuddleOffset;
IntVec3 c = vector.ToIntVec3();
bool flag = c.InBounds(this.myMap);
if (flag)
{
TerrainDef terrain = c.GetTerrain(this.myPawn.Map);
bool flag2 = terrain != null;
if (flag2)
{
HediffComp_RainbowTrail.PlacePuddle(vector, this.myMap, rot, this.Props.scale.RandomInRange, this.moteDef.RandomElement<ThingDef>());
return true;
}
}
this.lastFootprintPlacePos = drawPos;
return false;
}
private void Reset()
{
this.ticksLeft = this.Props.period;
}
private Pawn myPawn = null;
private Map myMap = null;
private Vector3 lastFootprintPlacePos;
private static readonly Vector3 PuddleOffset = new Vector3(0f, 0f, -0.3f);
private int ticksLeft;
private List<ThingDef> moteDef = null;
private HediffComp_RainbowTrail.RainbowColor curColor = HediffComp_RainbowTrail.RainbowColor.purple;
private int sameColorInRow = 0;
public HediffComp_RainbowTrail.RainbowColor bottomColor;
public HediffComp_RainbowTrail.RainbowColor pivotColor;
public HediffComp_RainbowTrail.RainbowColor topColor;
private int variation = 1;
private bool blockAction = false;
private bool myDebug = false;
public enum RainbowColor
{
[Description("purple")]
purple,
[Description("blue")]
blue,
[Description("green")]
green,
[Description("yellow")]
yellow,
[Description("orange")]
orange,
[Description("red")]
red
}
public enum ColorChoice
{
[Description("pawnColor")]
pawnColor,
[Description("complementary")]
complementary,
[Description("random")]
random
}
public enum CycleKind
{
[Description("circular")]
circular,
[Description("bouncing")]
bouncing,
[Description("random")]
random
}
}
}

View File

@ -0,0 +1,587 @@
using System;
using System.Collections.Generic;
using RimWorld;
using Verse;
namespace MoharHediffs
{
public class HediffComp_RandySpawnUponDeath : HediffComp
{
public HediffCompProperties_RandySpawnUponDeath Props
{
get
{
return (HediffCompProperties_RandySpawnUponDeath)this.props;
}
}
public bool MyDebug
{
get
{
return this.Props.debug;
}
}
public bool ValidIndex
{
get
{
return this.RandomIndex != -1 && this.Props.settings.HasSomethingToSpawn && this.RandomIndex < this.NumberOfItems;
}
}
public bool ValidQuantity
{
get
{
return this.RandomQuantity > 0;
}
}
public ThingSettings ChosenItem
{
get
{
return this.ValidIndex ? this.Props.settings.things[this.RandomIndex] : null;
}
}
public bool HasRequirement
{
get
{
return this.Props.HasRequirements && this.Props.requirements.HasAtLeastOneRequirementSetting;
}
}
public bool HasHediffRequirement
{
get
{
return this.Props.HasRequirements && this.Props.requirements.HasHediffRequirement;
}
}
public bool HasThingRequirement
{
get
{
return this.Props.HasRequirements && this.Props.requirements.HasThingRequirement;
}
}
public bool HasCustomSpawn
{
get
{
bool result;
if (this.HasThingRequirement)
{
result = this.Props.requirements.thing.Any((ThingRequirementSettings t) => t.HasCustomSpawn);
}
else
{
result = false;
}
return result;
}
}
public bool HasContainerSpawn
{
get
{
bool result;
if (this.HasThingRequirement)
{
result = this.Props.requirements.thing.Any((ThingRequirementSettings t) => t.HasContainerSpawn);
}
else
{
result = false;
}
return result;
}
}
public bool HasChosenThing
{
get
{
return this.ChosenItem != null && this.ChosenItem.thingToSpawn != null;
}
}
public bool HasChosenPawn
{
get
{
return this.ChosenItem != null && (this.ChosenItem.pawnKindToSpawn != null || this.IsParentPawnKindCopier);
}
}
public bool IsParentPawnKindCopier
{
get
{
return this.ChosenItem.IsCopier && this.ChosenItem.copyParent.pawnKind;
}
}
public bool PrecedentIterationsExclusion
{
get
{
return this.Props.excludeAlreadyPickedOptions;
}
}
public bool HasColorCondition
{
get
{
return this.Props.settings.things.Any((ThingSettings t) => t.HasColorCondition);
}
}
public ThingDef ThingOfChoice
{
get
{
return this.HasChosenThing ? this.ChosenItem.thingToSpawn : null;
}
}
public List<ThingSettings> FullOptionList
{
get
{
return this.Props.settings.things;
}
}
public PawnKindDef PawnOfChoice
{
get
{
bool flag = !this.HasChosenPawn;
PawnKindDef result;
if (flag)
{
result = null;
}
else
{
bool isParentPawnKindCopier = this.IsParentPawnKindCopier;
if (isParentPawnKindCopier)
{
result = base.Pawn.kindDef;
}
else
{
result = this.ChosenItem.pawnKindToSpawn;
}
}
return result;
}
}
public bool HasFilth
{
get
{
return this.FilthToSpawn != null;
}
}
public int NumberOfItems
{
get
{
return this.Props.settings.things.Count;
}
}
public int NumberToSpawn
{
get
{
bool flag = this.HasChosenThing && this.ChosenItem.HasStackSettings;
int result;
if (flag)
{
result = this.ChosenItem.specificSettings.stack.spawnCount.RandomInRange;
}
else
{
bool hasDefaultSettings = this.Props.settings.HasDefaultSettings;
if (hasDefaultSettings)
{
result = this.Props.settings.defaultSettings.stack.spawnCount.RandomInRange;
}
else
{
result = 1;
}
}
return result;
}
}
public bool WeightedSpawn
{
get
{
bool flag = this.HasChosenThing && this.ChosenItem.HasStackSettings;
bool result;
if (flag)
{
result = this.ChosenItem.specificSettings.stack.weightedSpawnCount;
}
else
{
bool hasDefaultSettings = this.Props.settings.HasDefaultSettings;
result = (hasDefaultSettings && this.Props.settings.defaultSettings.stack.weightedSpawnCount);
}
return result;
}
}
public ThingDef FilthToSpawn
{
get
{
bool flag = this.HasChosenThing && this.ChosenItem.HasFilthSettings;
ThingDef result;
if (flag)
{
result = this.ChosenItem.specificSettings.filth.filthDef;
}
else
{
bool hasDefaultSettings = this.Props.settings.HasDefaultSettings;
if (hasDefaultSettings)
{
result = this.Props.settings.defaultSettings.filth.filthDef;
}
else
{
result = null;
}
}
return result;
}
}
public FloatRange FilthRadius
{
get
{
bool flag = this.HasChosenThing && this.ChosenItem.HasFilthSettings;
FloatRange result;
if (flag)
{
result = this.ChosenItem.specificSettings.filth.filthRadius;
}
else
{
bool hasDefaultSettings = this.Props.settings.HasDefaultSettings;
if (hasDefaultSettings)
{
result = this.Props.settings.defaultSettings.filth.filthRadius;
}
else
{
result = new FloatRange(0f, 1f);
}
}
return result;
}
}
public IntRange FilthNum
{
get
{
bool flag = this.HasChosenThing && this.ChosenItem.HasFilthSettings;
IntRange result;
if (flag)
{
result = this.ChosenItem.specificSettings.filth.filthNum;
}
else
{
bool hasDefaultSettings = this.Props.settings.HasDefaultSettings;
if (hasDefaultSettings)
{
result = this.Props.settings.defaultSettings.filth.filthNum;
}
else
{
result = new IntRange(0, 0);
}
}
return result;
}
}
public override void CompPostMake()
{
bool myDebug = this.MyDebug;
if (myDebug)
{
string[] array = new string[5];
array[0] = ">>> ";
int num = 1;
Pawn pawn = base.Pawn;
array[num] = ((pawn != null) ? pawn.Label : null);
array[2] = " - ";
array[3] = this.parent.def.defName;
array[4] = " - CompPostMake start";
Log.Warning(string.Concat(array));
}
}
public override void Notify_PawnDied(DamageInfo? dinfo, Hediff culprit = null)
{
string text = this.MyDebug ? (base.Pawn.LabelShort + " HediffComp_RandySpawnUponDeath Notify_PawnDied") : "";
bool myDebug = this.MyDebug;
if (myDebug)
{
Log.Warning(text + " Entering");
}
bool flag = false;
bool flag2 = base.Pawn.Corpse.Negligible();
if (flag2)
{
bool myDebug2 = this.MyDebug;
if (myDebug2)
{
Log.Warning(text + " Corpse is no more, cant find its position - giving up");
}
flag = true;
}
bool flag3 = this.blockSpawn;
if (flag3)
{
bool myDebug3 = this.MyDebug;
if (myDebug3)
{
Log.Warning(text + " blockSpawn for some reason- giving up");
}
flag = true;
}
Thing closestThing;
bool flag4 = !this.FulfilsRequirement(out closestThing);
if (flag4)
{
bool myDebug4 = this.MyDebug;
if (myDebug4)
{
Log.Warning(text + "not Fulfiling requirements- giving up");
}
flag = true;
}
bool flag5 = flag;
checked
{
if (flag5)
{
base.Notify_PawnDied(dinfo, culprit);
}
else
{
int randomInRange = this.Props.iterationRange.RandomInRange;
List<int> list = new List<int>();
bool myDebug5 = this.MyDebug;
if (myDebug5)
{
Log.Warning(text + "iterationNum: " + randomInRange);
}
for (int i = 0; i < randomInRange; i++)
{
bool myDebug6 = this.MyDebug;
if (myDebug6)
{
Log.Warning(string.Concat(new object[]
{
text,
" Trying to spawn ",
i,
"/",
randomInRange - 1
}));
}
bool flag6 = !this.DiceThrow(list);
if (flag6)
{
bool myDebug7 = this.MyDebug;
if (myDebug7)
{
Log.Warning(text + " DiceThrow wrong results");
}
base.Notify_PawnDied(dinfo, culprit);
return;
}
bool myDebug8 = this.MyDebug;
if (myDebug8)
{
Log.Warning(string.Concat(new object[]
{
text,
" index: ",
this.RandomIndex,
" quantity: ",
this.RandomQuantity,
" nature: ",
this.ChosenItem.ItemDump
}));
}
bool precedentIterationsExclusion = this.PrecedentIterationsExclusion;
if (precedentIterationsExclusion)
{
list.Add(this.RandomIndex);
}
bool flag7 = this.CheckShouldSpawn(closestThing);
if (flag7)
{
bool myDebug9 = this.MyDebug;
if (myDebug9)
{
Log.Warning(string.Concat(new object[]
{
text,
" Spawn ",
i,
"/",
randomInRange - 1,
" occured nature: t:",
this.ChosenItem.ItemDump
}));
}
}
bool myDebug10 = this.MyDebug;
if (myDebug10)
{
Log.Warning("#################");
}
}
bool flag8 = this.CheckShouldHandleCorpse();
if (flag8)
{
bool myDebug11 = this.MyDebug;
if (myDebug11)
{
Log.Warning(text + " Corpse handled");
}
}
base.Notify_PawnDied(dinfo, culprit);
}
}
}
public bool DiceThrow(List<int> AlreadyPickedOptions)
{
this.RandomIndex = this.GetWeightedRandomIndex(AlreadyPickedOptions);
bool flag = this.HasChosenPawn && this.ChosenItem.HasFactionParams;
if (flag)
{
this.ComputeRandomFaction();
}
this.RandomQuantity = this.ComputeSpawnCount();
bool flag2 = !this.ValidIndex;
bool result;
if (flag2)
{
this.BlockAndDestroy(">ERROR< failed to find an index for IP, check and adjust your hediff props", this.MyDebug);
result = false;
}
else
{
bool flag3 = !this.ValidQuantity;
if (flag3)
{
bool myDebug = this.MyDebug;
if (myDebug)
{
Log.Warning("random quantity: " + this.RandomQuantity + " - impossible to spawn anything");
}
result = false;
}
else
{
result = true;
}
}
return result;
}
public void BlockAndDestroy(string ErrorLog = "", bool myDebug = false)
{
bool flag = this.MyDebug && !ErrorLog.NullOrEmpty();
if (flag)
{
Log.Warning(ErrorLog);
}
this.blockSpawn = true;
Tools.DestroyParentHediff(this.parent, myDebug);
}
private bool CheckShouldSpawn(Thing closestThing)
{
bool myDebug = this.MyDebug;
if (myDebug)
{
Log.Warning(base.Pawn.LabelShort + " CheckShouldSpawn");
}
bool myDebug2 = this.MyDebug;
if (myDebug2)
{
Log.Warning(string.Concat(new object[]
{
" Trying to spawn ",
this.RandomQuantity,
" ",
this.ThingOfChoice,
"/",
this.PawnOfChoice
}));
}
Thing thing = this.HasCustomSpawn ? closestThing : base.Pawn.Corpse;
bool result = this.TryDoSpawn(thing, this.RandomQuantity);
bool myDebug3 = this.MyDebug;
if (myDebug3)
{
Log.Warning("TryDoSpawn: " + result.ToString());
}
return result;
}
private bool CheckShouldHandleCorpse()
{
Corpse corpse = base.Pawn.Corpse;
bool flag = false;
flag |= this.StripCorpse(corpse);
return flag | this.DestroyCorpse(corpse);
}
private bool blockSpawn = false;
private int RandomIndex = -1;
public Faction RandomFaction = null;
public MentalStateDef RandomMS = null;
private int RandomQuantity = 0;
public readonly float minDaysB4NextErrorLimit = 0.001f;
public readonly int spawnCountErrorLimit = 750;
public Pawn_SkillTracker rememberSkillTracker = null;
public int lastSkillUpdateTick = -1;
}
}

View File

@ -0,0 +1,450 @@
using System;
using System.Collections.Generic;
using RimWorld;
using Verse;
namespace MoharHediffs
{
public class HediffComp_RandySpawner : HediffComp
{
public HediffCompProperties_RandySpawner Props
{
get
{
return (HediffCompProperties_RandySpawner)this.props;
}
}
public bool MyDebug
{
get
{
return this.Props.debug;
}
}
public bool HasGraceDelay
{
get
{
return this.graceTicks > 0;
}
}
private float CalculatedDaysB4Next
{
get
{
return (float)this.ticksUntilSpawn / 60000f;
}
}
public ItemParameter CurIP
{
get
{
return (this.pickedItem != -1 && !this.Props.itemParameters.NullOrEmpty<ItemParameter>() && this.pickedItem < this.Props.itemParameters.Count) ? this.Props.itemParameters[this.pickedItem] : null;
}
}
public bool HasValidIP
{
get
{
return this.CurIP != null;
}
}
public bool RequiresFood
{
get
{
return this.Props.hungerRelative && base.Pawn.IsHungry(this.MyDebug);
}
}
public bool RequiresHealth
{
get
{
return this.Props.healthRelative && base.Pawn.IsInjured(this.MyDebug);
}
}
public override void CompExposeData()
{
Scribe_Values.Look<int>(ref this.ticksUntilSpawn, "ticksUntilSpawn", 0, false);
Scribe_Values.Look<int>(ref this.initialTicksUntilSpawn, "initialTicksUntilSpawn", 0, false);
Scribe_Values.Look<int>(ref this.calculatedQuantity, "calculatedQuantity", 0, false);
Scribe_Values.Look<int>(ref this.hungerReset, "LTF_hungerReset", 0, false);
Scribe_Values.Look<int>(ref this.healthReset, "LTF_healthReset", 0, false);
Scribe_Values.Look<int>(ref this.graceTicks, "graceTicks", 0, false);
Scribe_Values.Look<int>(ref this.pickedItem, "pickedItem", 0, false);
}
public override void CompPostMake()
{
string[] array = new string[5];
array[0] = ">>> ";
int num = 1;
Pawn pawn = base.Pawn;
array[num] = ((pawn != null) ? pawn.Label : null);
array[2] = " - ";
array[3] = this.parent.def.defName;
array[4] = " - CompPostMake start";
Tools.Warn(string.Concat(array), this.MyDebug);
this.DumpProps();
this.CheckProps();
this.CalculateValues();
this.CheckCalculatedValues();
this.DumpCalculatedValues();
}
public override void CompPostTick(ref float severityAdjustment)
{
bool flag = base.Pawn.Negligible();
checked
{
if (!flag)
{
bool flag2 = this.blockSpawn;
if (!flag2)
{
bool hasGraceDelay = this.HasGraceDelay;
if (hasGraceDelay)
{
this.graceTicks--;
}
else
{
bool flag3 = this.SetRequirementGraceTicks();
if (!flag3)
{
bool flag4 = this.CheckShouldSpawn();
if (flag4)
{
Tools.Warn("Reseting countdown bc spawned thing", this.MyDebug);
this.CalculateValues();
this.CheckCalculatedValues();
}
}
}
}
}
}
}
private void CalculateValues()
{
this.pickedItem = this.GetWeightedRandomIndex();
bool hasValidIP = this.HasValidIP;
if (hasValidIP)
{
this.CurIP.ComputeRandomParameters(out this.ticksUntilSpawn, out this.graceTicks, out this.calculatedQuantity);
bool hasFactionParams = this.CurIP.HasFactionParams;
if (hasFactionParams)
{
this.ComputeRandomFaction();
}
}
else
{
this.BlockAndDestroy(">ERROR< failed to find an index for IP, check and adjust your hediff props", this.MyDebug);
}
}
private void CheckCalculatedValues()
{
bool flag = this.calculatedQuantity > this.spawnCountErrorLimit;
if (flag)
{
this.BlockAndDestroy(string.Concat(new object[]
{
">ERROR< calculatedQuantity is too high: ",
this.calculatedQuantity,
"(>",
this.spawnCountErrorLimit,
"), check and adjust your hediff props"
}), this.MyDebug);
}
else
{
bool flag2 = this.CalculatedDaysB4Next < this.minDaysB4NextErrorLimit;
if (flag2)
{
this.BlockAndDestroy(string.Concat(new object[]
{
">ERROR< calculatedMinDaysB4Next is too low: ",
this.CalculatedDaysB4Next,
"(<",
this.minDaysB4NextErrorLimit,
"), check and adjust your hediff props"
}), this.MyDebug);
}
}
}
private void DumpCalculatedValues()
{
Tools.Warn(string.Concat(new object[]
{
"<<< calculatedDaysB4Next: ",
this.CalculatedDaysB4Next,
"; CalculatedQuantity: ",
this.calculatedQuantity,
"; "
}), this.MyDebug);
}
public void BlockAndDestroy(string ErrorLog = "", bool myDebug = false)
{
Tools.Warn(ErrorLog, myDebug);
this.blockSpawn = true;
Tools.DestroyParentHediff(this.parent, myDebug);
}
private bool CheckShouldSpawn()
{
checked
{
this.ticksUntilSpawn--;
bool flag = this.ticksUntilSpawn <= 0;
bool result;
if (flag)
{
bool flag2 = this.TryDoSpawn();
Tools.Warn("TryDoSpawn: " + flag2.ToString(), this.MyDebug);
bool flag3 = flag2;
if (flag3)
{
this.pickedItem = -1;
}
result = flag2;
}
else
{
result = false;
}
return result;
}
}
public bool TrySpawnPawn()
{
PawnGenerationRequest request = new PawnGenerationRequest(this.CurIP.pawnKindToSpawn, this.Itemfaction, PawnGenerationContext.NonPlayer, -1, false, this.newBorn, false, true, false, 1f, false, true, false, true, true, false, false, false, false, 0f, 0f, null, 1f, null, null, null, null, null, null, null, null, null, null, null, null, false, false, false, false, null, null, null, null, null, 0f, DevelopmentalStage.Adult, null, null, null, false, false, false, -1, 0, false);
checked
{
for (int i = 0; i < this.calculatedQuantity; i++)
{
Pawn newThing = PawnGenerator.GeneratePawn(request);
GenSpawn.Spawn(newThing, base.Pawn.Position, base.Pawn.Map, WipeMode.Vanish);
bool hasFilth = this.CurIP.HasFilth;
if (hasFilth)
{
FilthMaker.TryMakeFilth(this.parent.pawn.Position, this.parent.pawn.Map, this.CurIP.filthDef, 1, FilthSourceFlags.None, true);
}
}
return true;
}
}
public bool TryDoSpawn()
{
bool flag = base.Pawn.Negligible();
checked
{
bool result;
if (flag)
{
Tools.Warn("TryDoSpawn - pawn null", this.MyDebug);
result = false;
}
else
{
bool pawnSpawner = this.CurIP.PawnSpawner;
if (pawnSpawner)
{
result = this.TrySpawnPawn();
}
else
{
bool thingSpawner = this.CurIP.ThingSpawner;
if (thingSpawner)
{
bool flag2 = this.Props.spawnMaxAdjacent >= 0;
if (flag2)
{
int num = 0;
for (int i = 0; i < 9; i++)
{
IntVec3 c = base.Pawn.Position + GenAdj.AdjacentCellsAndInside[i];
bool flag3 = !c.InBounds(base.Pawn.Map);
if (!flag3)
{
List<Thing> thingList = c.GetThingList(base.Pawn.Map);
for (int j = 0; j < thingList.Count; j++)
{
bool flag4 = thingList[j].def == this.CurIP.thingToSpawn;
if (flag4)
{
num += thingList[j].stackCount;
bool flag5 = num >= this.Props.spawnMaxAdjacent;
if (flag5)
{
return false;
}
}
}
}
}
}
}
int k = 0;
int num2 = this.calculatedQuantity;
int num3 = 0;
while (k < this.calculatedQuantity)
{
IntVec3 intVec;
bool flag6 = this.TryFindSpawnCell(out intVec);
if (flag6)
{
Thing thing = ThingMaker.MakeThing(this.CurIP.thingToSpawn, null);
thing.stackCount = num2;
bool flag7 = thing.def.stackLimit > 0;
if (flag7)
{
bool flag8 = thing.stackCount > thing.def.stackLimit;
if (flag8)
{
thing.stackCount = thing.def.stackLimit;
}
}
k += thing.stackCount;
num2 -= thing.stackCount;
Thing t;
GenPlace.TryPlaceThing(thing, intVec, base.Pawn.Map, ThingPlaceMode.Direct, ref t, null, null, default(Rot4));
bool spawnForbidden = this.Props.spawnForbidden;
if (spawnForbidden)
{
t.SetForbidden(true, true);
}
}
bool flag9 = num3++ > 10;
if (flag9)
{
Tools.Warn("Had to break the loop", this.MyDebug);
return false;
}
}
bool flag10 = num2 <= 0;
result = flag10;
}
}
return result;
}
}
public override string CompTipStringExtra
{
get
{
string text = string.Empty;
bool flag = !this.HasValidIP || !this.Props.logNextSpawn;
string result;
if (flag)
{
result = text;
}
else
{
bool hasGraceDelay = this.HasGraceDelay;
if (hasGraceDelay)
{
bool pawnSpawner = this.CurIP.PawnSpawner;
if (pawnSpawner)
{
text = " No " + this.CurIP.pawnKindToSpawn.label + " for " + this.graceTicks.ToStringTicksToPeriod(true, false, true, true, false);
}
else
{
bool thingSpawner = this.CurIP.ThingSpawner;
if (thingSpawner)
{
text = " No " + this.CurIP.thingToSpawn.label + " for " + this.graceTicks.ToStringTicksToPeriod(true, false, true, true, false);
}
}
bool flag2 = this.hungerReset > 0;
if (flag2)
{
text += "(hunger)";
}
else
{
bool flag3 = this.healthReset > 0;
if (flag3)
{
text += "(injury)";
}
else
{
text += "(grace period)";
}
}
}
else
{
text = this.ticksUntilSpawn.ToStringTicksToPeriod(true, false, true, true, false) + " before ";
bool pawnSpawner2 = this.CurIP.PawnSpawner;
if (pawnSpawner2)
{
text += this.CurIP.pawnKindToSpawn.label;
}
else
{
bool thingSpawner2 = this.CurIP.ThingSpawner;
if (thingSpawner2)
{
text += this.CurIP.thingToSpawn.label;
}
}
text = string.Concat(new object[]
{
text,
" ",
this.CurIP.spawnVerb,
"(",
this.calculatedQuantity,
"x)"
});
}
result = text;
}
return result;
}
}
private int ticksUntilSpawn;
private int initialTicksUntilSpawn = 0;
public int graceTicks = 0;
public int calculatedQuantity;
public int hungerReset = 0;
public int healthReset = 0;
private bool blockSpawn = false;
private int pickedItem = -1;
public Faction Itemfaction = null;
public bool newBorn = false;
public readonly float minDaysB4NextErrorLimit = 0.001f;
public readonly int spawnCountErrorLimit = 750;
}
}

View File

@ -0,0 +1,778 @@
using System;
using System.Collections.Generic;
using System.Linq;
using RimWorld;
using Verse;
namespace MoharHediffs
{
public class HediffComp_Spawner : HediffComp
{
public HediffCompProperties_Spawner Props
{
get
{
return (HediffCompProperties_Spawner)this.props;
}
}
public override void CompExposeData()
{
Scribe_Values.Look<int>(ref this.ticksUntilSpawn, "ticksUntilSpawn", 0, false);
Scribe_Values.Look<int>(ref this.initialTicksUntilSpawn, "initialTicksUntilSpawn", 0, false);
Scribe_Values.Look<float>(ref this.calculatedMinDaysB4Next, "calculatedMinDaysB4Next", 0f, false);
Scribe_Values.Look<float>(ref this.calculatedMaxDaysB4Next, "calculatedMaxDaysB4Next", 0f, false);
Scribe_Values.Look<int>(ref this.calculatedQuantity, "calculatedQuantity", 0, false);
Scribe_Values.Look<int>(ref this.graceTicks, "graceTicks", 0, false);
}
public override void CompPostMake()
{
this.myDebug = this.Props.debug;
Tools.Warn(string.Concat(new string[]
{
">>> ",
this.parent.pawn.Label,
" - ",
this.parent.def.defName,
" - CompPostMake start"
}), this.myDebug);
this.TraceProps();
this.CheckProps();
this.CalculateValues();
this.CheckCalculatedValues();
this.TraceCalculatedValues();
bool flag = this.initialTicksUntilSpawn == 0;
if (flag)
{
Tools.Warn("Reseting countdown bc initialTicksUntilSpawn == 0 (comppostmake)", this.myDebug);
this.ResetCountdown();
}
}
public override void CompPostTick(ref float severityAdjustment)
{
this.pawn = this.parent.pawn;
bool flag = !Tools.OkPawn(this.pawn);
checked
{
if (!flag)
{
bool flag2 = this.blockSpawn;
if (!flag2)
{
bool flag3 = this.graceTicks > 0;
if (flag3)
{
this.graceTicks--;
}
else
{
bool flag4 = this.Props.hungerRelative && this.pawn.IsHungry(this.myDebug);
if (flag4)
{
int num = (int)(unchecked(this.RandomGraceDays() * 60000f));
this.hungerReset++;
this.graceTicks = num;
}
else
{
bool flag5 = this.Props.healthRelative && this.pawn.IsInjured(this.myDebug);
if (flag5)
{
int num2 = (int)(unchecked(this.RandomGraceDays() * 60000f));
this.healthReset++;
this.graceTicks = num2;
}
else
{
this.hungerReset = (this.healthReset = 0);
bool flag6 = this.CheckShouldSpawn();
if (flag6)
{
Tools.Warn("Reseting countdown bc spawned thing", this.myDebug);
this.CalculateValues();
this.CheckCalculatedValues();
this.ResetCountdown();
bool flag7 = Rand.Chance(this.Props.randomGrace);
if (flag7)
{
int num3 = (int)(unchecked(this.RandomGraceDays() * 60000f));
this.graceTicks = num3;
}
}
}
}
}
}
}
}
}
private void TraceProps()
{
Tools.Warn(string.Concat(new object[]
{
"Props => minDaysB4Next: ",
this.Props.minDaysB4Next,
"; maxDaysB4Next: ",
this.Props.maxDaysB4Next,
"; randomGrace: ",
this.Props.randomGrace,
"; graceDays: ",
this.Props.graceDays,
"; hungerRelative: ",
this.Props.hungerRelative.ToString(),
"; healthRelative: ",
this.Props.healthRelative.ToString(),
"; "
}), this.myDebug);
bool animalThing = this.Props.animalThing;
if (animalThing)
{
Tools.Warn(string.Concat(new string[]
{
"animalThing: ",
this.Props.animalThing.ToString(),
"; animalName: ",
this.Props.animalToSpawn.defName,
"; factionOfPlayerAnimal: ",
this.Props.factionOfPlayerAnimal.ToString(),
"; "
}), this.myDebug);
}
bool ageWeightedQuantity = this.Props.ageWeightedQuantity;
if (ageWeightedQuantity)
{
Tools.Warn(string.Concat(new string[]
{
"ageWeightedQuantity:",
this.Props.ageWeightedQuantity.ToString(),
"; olderBiggerQuantity:",
this.Props.olderBiggerQuantity.ToString(),
"; ",
this.myDebug.ToString()
}), false);
bool exponentialQuantity = this.Props.exponentialQuantity;
if (exponentialQuantity)
{
Tools.Warn(string.Concat(new object[]
{
"exponentialQuantity:",
this.Props.exponentialQuantity.ToString(),
"; exponentialRatioLimit:",
this.Props.exponentialRatioLimit,
"; "
}), this.myDebug);
}
}
bool ageWeightedPeriod = this.Props.ageWeightedPeriod;
if (ageWeightedPeriod)
{
}
Tools.Warn(string.Concat(new string[]
{
"ageWeightedPeriod:",
this.Props.ageWeightedPeriod.ToString(),
"; olderSmallerPeriod:",
this.Props.olderSmallerPeriod.ToString(),
"; ",
this.myDebug.ToString()
}), false);
}
private void CalculateValues()
{
float num = Tools.GetPawnAgeOverlifeExpectancyRatio(this.parent.pawn, this.myDebug);
num = ((num > 1f) ? 1f : num);
this.calculatedMinDaysB4Next = this.Props.minDaysB4Next;
this.calculatedMaxDaysB4Next = this.Props.maxDaysB4Next;
bool ageWeightedPeriod = this.Props.ageWeightedPeriod;
if (ageWeightedPeriod)
{
float num2 = this.Props.olderSmallerPeriod ? (-num) : num;
this.calculatedMinDaysB4Next = this.Props.minDaysB4Next * (1f + num2);
this.calculatedMaxDaysB4Next = this.Props.maxDaysB4Next * (1f + num2);
Tools.Warn(string.Concat(new object[]
{
" ageWeightedPeriod: ",
this.Props.ageWeightedPeriod.ToString(),
" ageRatio: ",
num,
" minDaysB4Next: ",
this.Props.minDaysB4Next,
" maxDaysB4Next: ",
this.Props.maxDaysB4Next,
" daysAgeRatio: ",
num2,
" calculatedMinDaysB4Next: ",
this.calculatedMinDaysB4Next,
"; calculatedMaxDaysB4Next: ",
this.calculatedMaxDaysB4Next,
"; "
}), this.myDebug);
}
this.calculatedQuantity = this.Props.spawnCount;
bool ageWeightedQuantity = this.Props.ageWeightedQuantity;
if (ageWeightedQuantity)
{
float num3 = this.Props.olderBiggerQuantity ? num : (-num);
Tools.Warn("quantityAgeRatio: " + num3, this.myDebug);
this.calculatedQuantity = checked((int)Math.Round(unchecked((double)this.Props.spawnCount * (double)(1f + num3))));
bool exponentialQuantity = this.Props.exponentialQuantity;
if (exponentialQuantity)
{
num3 = 1f - num;
bool flag = num3 == 0f;
if (flag)
{
Tools.Warn(">ERROR< quantityAgeRatio is f* up : " + num3, this.myDebug);
this.blockSpawn = true;
Tools.DestroyParentHediff(this.parent, this.myDebug);
return;
}
float num4 = this.Props.olderBiggerQuantity ? (1f / num3) : (num3 * num3);
bool flag2 = false;
bool flag3 = false;
bool flag4 = num4 > (float)this.Props.exponentialRatioLimit;
if (flag4)
{
num4 = (float)this.Props.exponentialRatioLimit;
flag2 = true;
}
this.calculatedQuantity = checked((int)Math.Round(unchecked((double)this.Props.spawnCount * (double)num4)));
bool flag5 = this.calculatedQuantity < 1;
if (flag5)
{
this.calculatedQuantity = 1;
flag3 = true;
}
Tools.Warn(string.Concat(new object[]
{
" exponentialQuantity: ",
this.Props.exponentialQuantity.ToString(),
"; expoFactor: ",
num4,
"; gotLimited: ",
flag2.ToString(),
"; gotAugmented: ",
flag3.ToString()
}), this.myDebug);
}
Tools.Warn(string.Concat(new object[]
{
"; Props.spawnCount: ",
this.Props.spawnCount,
"; calculatedQuantity: ",
this.calculatedQuantity
}), this.myDebug);
}
}
private void CheckCalculatedValues()
{
bool flag = this.calculatedQuantity > this.errorSpawnCount;
if (flag)
{
Tools.Warn(string.Concat(new object[]
{
">ERROR< calculatedQuantity is too high: ",
this.calculatedQuantity,
"(>",
this.errorSpawnCount,
"), check and adjust your hediff props"
}), this.myDebug);
this.blockSpawn = true;
Tools.DestroyParentHediff(this.parent, this.myDebug);
}
else
{
bool flag2 = this.calculatedMinDaysB4Next >= this.calculatedMaxDaysB4Next;
if (flag2)
{
Tools.Warn(">ERROR< calculatedMinDaysB4Next should be lower than calculatedMaxDaysB4Next", this.myDebug);
this.blockSpawn = true;
Tools.DestroyParentHediff(this.parent, this.myDebug);
}
else
{
bool flag3 = this.calculatedMinDaysB4Next < this.errorMinDaysB4Next;
if (flag3)
{
Tools.Warn(string.Concat(new object[]
{
">ERROR< calculatedMinDaysB4Next is too low: ",
this.Props.minDaysB4Next,
"(<",
this.errorMinDaysB4Next,
"), check and adjust your hediff props"
}), this.myDebug);
this.blockSpawn = true;
Tools.DestroyParentHediff(this.parent, this.myDebug);
}
}
}
}
private void TraceCalculatedValues()
{
Tools.Warn(string.Concat(new object[]
{
"<<< ",
this.Props.ageWeightedPeriod ? ("Props.olderMoreOften: " + this.Props.olderSmallerPeriod.ToString() + "; ") : "",
this.Props.ageWeightedQuantity ? ("Props.olderBiggerquantities: " + this.Props.olderBiggerQuantity.ToString() + "; ") : "",
" Props.minDaysB4Next: ",
this.Props.minDaysB4Next,
"; Props.maxDaysB4Next: ",
this.Props.maxDaysB4Next,
"; calculatedMinDaysB4Next: ",
this.calculatedMinDaysB4Next,
"; calculatedMaxDaysB4Next: ",
this.calculatedMaxDaysB4Next,
"; Props.spawnCount: ",
this.Props.spawnCount,
"; CalculatedQuantity: ",
this.calculatedQuantity,
"; "
}), this.myDebug);
}
private void CheckProps()
{
bool flag = this.Props.spawnCount > this.errorSpawnCount;
if (flag)
{
Tools.Warn(string.Concat(new object[]
{
"SpawnCount is too high: ",
this.Props.spawnCount,
"(>",
this.errorSpawnCount,
"), some people just want to see the world burn"
}), this.myDebug);
this.blockSpawn = true;
Tools.DestroyParentHediff(this.parent, this.myDebug);
}
else
{
bool flag2 = this.Props.minDaysB4Next >= this.Props.maxDaysB4Next;
if (flag2)
{
Tools.Warn("minDaysB4Next should be lower than maxDaysB4Next", this.myDebug);
this.blockSpawn = true;
Tools.DestroyParentHediff(this.parent, this.myDebug);
}
else
{
bool flag3 = this.Props.minDaysB4Next < this.errorMinDaysB4Next;
if (flag3)
{
Tools.Warn(string.Concat(new object[]
{
"minDaysB4Next is too low: ",
this.Props.minDaysB4Next,
"(<",
this.errorMinDaysB4Next,
"), some people just want to see the world burn"
}), this.myDebug);
this.blockSpawn = true;
Tools.DestroyParentHediff(this.parent, this.myDebug);
}
else
{
bool animalThing = this.Props.animalThing;
if (animalThing)
{
bool flag4 = this.Props.animalToSpawn == null || this.Props.animalToSpawn.defName.NullOrEmpty();
if (flag4)
{
Tools.Warn("Props.animalThing=" + this.Props.animalThing.ToString() + "; but no Props.animalName", this.myDebug);
this.blockSpawn = true;
Tools.DestroyParentHediff(this.parent, this.myDebug);
return;
}
Tools.Warn("Found animal PawnKindDef.defName=" + this.Props.animalToSpawn.defName, this.myDebug);
}
else
{
ThingDef thingDef = (from b in DefDatabase<ThingDef>.AllDefs
where b == this.Props.thingToSpawn
select b).RandomElement<ThingDef>();
bool flag5 = thingDef == null;
if (flag5)
{
Tools.Warn("Could not find Props.thingToSpawn in DefDatabase", this.myDebug);
this.blockSpawn = true;
Tools.DestroyParentHediff(this.parent, this.myDebug);
return;
}
Tools.Warn("Found ThingDef for " + this.Props.thingToSpawn.defName + "in DefDatabase", this.myDebug);
}
bool flag6 = !this.Props.ageWeightedPeriod;
if (flag6)
{
bool olderSmallerPeriod = this.Props.olderSmallerPeriod;
if (olderSmallerPeriod)
{
Tools.Warn("olderSmallerPeriod ignored since ageWeightedPeriod is false ", this.myDebug);
this.blockSpawn = true;
Tools.DestroyParentHediff(this.parent, this.myDebug);
return;
}
}
bool flag7 = !this.Props.ageWeightedQuantity;
if (flag7)
{
bool olderBiggerQuantity = this.Props.olderBiggerQuantity;
if (olderBiggerQuantity)
{
Tools.Warn("olderBiggerQuantity ignored since ageWeightedQuantity is false ", this.myDebug);
}
bool exponentialQuantity = this.Props.exponentialQuantity;
if (exponentialQuantity)
{
Tools.Warn("exponentialQuantity ignored since ageWeightedQuantity is false ", this.myDebug);
}
bool flag8 = this.Props.olderBiggerQuantity || this.Props.exponentialQuantity;
if (flag8)
{
this.blockSpawn = true;
Tools.DestroyParentHediff(this.parent, this.myDebug);
return;
}
}
bool flag9 = this.Props.exponentialQuantity && this.Props.exponentialRatioLimit > this.errorExponentialLimit;
if (flag9)
{
Tools.Warn(string.Concat(new object[]
{
"expoRatioLimit too low while expoQuantity is set: ",
this.Props.exponentialRatioLimit,
"(>",
this.errorExponentialLimit,
"), some people just want to see the world burn"
}), this.myDebug);
this.blockSpawn = true;
Tools.DestroyParentHediff(this.parent, this.myDebug);
}
}
}
}
}
private bool CheckShouldSpawn()
{
this.pawn = this.parent.pawn;
bool flag = !Tools.OkPawn(this.pawn);
checked
{
bool result;
if (flag)
{
Tools.Warn("CheckShouldSpawn pawn Null", this.myDebug);
result = false;
}
else
{
this.ticksUntilSpawn--;
bool flag2 = this.ticksUntilSpawn <= 0;
if (flag2)
{
Tools.Warn("TryDoSpawn: " + this.TryDoSpawn().ToString(), this.myDebug);
result = true;
}
else
{
result = false;
}
}
return result;
}
}
private PawnKindDef MyPawnKindDefNamed(string myDefName)
{
PawnKindDef result = null;
foreach (PawnKindDef pawnKindDef in DefDatabase<PawnKindDef>.AllDefs)
{
bool flag = pawnKindDef.defName == myDefName;
if (flag)
{
return pawnKindDef;
}
}
return result;
}
public bool TryDoSpawn()
{
this.pawn = this.parent.pawn;
bool flag = !Tools.OkPawn(this.pawn);
checked
{
bool result;
if (flag)
{
Tools.Warn("TryDoSpawn - pawn null", this.myDebug);
result = false;
}
else
{
bool animalThing = this.Props.animalThing;
if (animalThing)
{
Faction faction = this.Props.factionOfPlayerAnimal ? Faction.OfPlayer : null;
PawnGenerationRequest request = new PawnGenerationRequest(this.Props.animalToSpawn, faction, PawnGenerationContext.NonPlayer, -1, false, true, false, true, false, 1f, false, true, false, true, true, false, false, false, false, 0f, 0f, null, 1f, null, null, null, null, null, null, null, null, null, null, null, null, false, false, false, false, null, null, null, null, null, 0f, DevelopmentalStage.Adult, null, null, null, false, false, false, -1, 0, false);
for (int i = 0; i < this.calculatedQuantity; i++)
{
Pawn newThing = PawnGenerator.GeneratePawn(request);
GenSpawn.Spawn(newThing, this.parent.pawn.Position, this.parent.pawn.Map, WipeMode.Vanish);
FilthMaker.TryMakeFilth(this.parent.pawn.Position, this.parent.pawn.Map, ThingDefOf.Filth_AmnioticFluid, 1, FilthSourceFlags.None, true);
}
result = true;
}
else
{
bool flag2 = this.Props.spawnMaxAdjacent >= 0;
if (flag2)
{
int num = 0;
for (int j = 0; j < 9; j++)
{
IntVec3 c = this.pawn.Position + GenAdj.AdjacentCellsAndInside[j];
bool flag3 = !c.InBounds(this.pawn.Map);
if (!flag3)
{
List<Thing> thingList = c.GetThingList(this.pawn.Map);
for (int k = 0; k < thingList.Count; k++)
{
bool flag4 = thingList[k].def == this.Props.thingToSpawn;
if (flag4)
{
num += thingList[k].stackCount;
bool flag5 = num >= this.Props.spawnMaxAdjacent;
if (flag5)
{
return false;
}
}
}
}
}
}
int l = 0;
int num2 = this.calculatedQuantity;
int num3 = 0;
while (l < this.calculatedQuantity)
{
IntVec3 intVec;
bool flag6 = this.TryFindSpawnCell(out intVec);
if (flag6)
{
Thing thing = ThingMaker.MakeThing(this.Props.thingToSpawn, null);
thing.stackCount = num2;
bool flag7 = thing.def.stackLimit > 0;
if (flag7)
{
bool flag8 = thing.stackCount > thing.def.stackLimit;
if (flag8)
{
thing.stackCount = thing.def.stackLimit;
}
}
l += thing.stackCount;
num2 -= thing.stackCount;
Thing t;
GenPlace.TryPlaceThing(thing, intVec, this.pawn.Map, ThingPlaceMode.Direct, ref t, null, null, default(Rot4));
bool spawnForbidden = this.Props.spawnForbidden;
if (spawnForbidden)
{
t.SetForbidden(true, true);
}
}
bool flag9 = num3++ > 10;
if (flag9)
{
Tools.Warn("Had to break the loop", this.myDebug);
return false;
}
}
bool flag10 = num2 <= 0;
result = flag10;
}
}
return result;
}
}
private bool TryFindSpawnCell(out IntVec3 result)
{
this.pawn = this.parent.pawn;
bool flag = !Tools.OkPawn(this.pawn);
checked
{
bool result2;
if (flag)
{
result = IntVec3.Invalid;
Tools.Warn("TryFindSpawnCell Null - pawn null", this.myDebug);
result2 = false;
}
else
{
foreach (IntVec3 intVec in GenAdj.CellsAdjacent8Way(this.pawn).InRandomOrder(null))
{
bool flag2 = intVec.Walkable(this.pawn.Map);
if (flag2)
{
Building edifice = intVec.GetEdifice(this.pawn.Map);
bool flag3 = edifice == null || !this.Props.thingToSpawn.IsEdifice();
if (flag3)
{
Building_Door building_Door;
bool flag4 = (building_Door = (edifice as Building_Door)) == null || building_Door.FreePassage;
if (flag4)
{
bool flag5 = GenSight.LineOfSight(this.pawn.Position, intVec, this.pawn.Map, false, null, 0, 0);
if (flag5)
{
bool flag6 = false;
List<Thing> thingList = intVec.GetThingList(this.pawn.Map);
for (int i = 0; i < thingList.Count; i++)
{
Thing thing = thingList[i];
bool flag7 = thing.def.category == ThingCategory.Item;
if (flag7)
{
bool flag8 = thing.def != this.Props.thingToSpawn || thing.stackCount > this.Props.thingToSpawn.stackLimit - this.calculatedQuantity;
if (flag8)
{
flag6 = true;
break;
}
}
}
bool flag9 = !flag6;
if (flag9)
{
result = intVec;
return true;
}
}
}
}
}
}
Tools.Warn("TryFindSpawnCell Null - no spawn cell found", this.myDebug);
result = IntVec3.Invalid;
result2 = false;
}
return result2;
}
}
private void ResetCountdown()
{
this.ticksUntilSpawn = (this.initialTicksUntilSpawn = checked((int)(unchecked(this.RandomDays2wait() * 60000f))));
}
private float RandomDays2wait()
{
return Rand.Range(this.calculatedMinDaysB4Next, this.calculatedMaxDaysB4Next);
}
private float RandomGraceDays()
{
return this.Props.graceDays * Rand.Range(0f, 1f);
}
public override string CompTipStringExtra
{
get
{
string text = string.Empty;
bool flag = this.graceTicks > 0;
if (flag)
{
bool animalThing = this.Props.animalThing;
if (animalThing)
{
text = " No " + this.Props.animalToSpawn.defName + " for " + this.graceTicks.ToStringTicksToPeriod(true, false, true, true, false);
}
else
{
text = " No " + this.Props.thingToSpawn.label + " for " + this.graceTicks.ToStringTicksToPeriod(true, false, true, true, false);
}
bool flag2 = this.hungerReset > 0;
if (flag2)
{
text += "(hunger)";
}
else
{
bool flag3 = this.healthReset > 0;
if (flag3)
{
text += "(injury)";
}
else
{
text += "(grace period)";
}
}
}
else
{
text = this.ticksUntilSpawn.ToStringTicksToPeriod(true, false, true, true, false) + " before ";
bool animalThing2 = this.Props.animalThing;
if (animalThing2)
{
text += this.Props.animalToSpawn.defName;
}
else
{
text += this.Props.thingToSpawn.label;
}
text = string.Concat(new object[]
{
text,
" ",
this.Props.spawnVerb,
"(",
this.calculatedQuantity,
"x)"
});
}
return text;
}
}
private int ticksUntilSpawn;
private int initialTicksUntilSpawn = 0;
private int hungerReset = 0;
private int healthReset = 0;
private int graceTicks = 0;
private Pawn pawn = null;
private float calculatedMaxDaysB4Next = 2f;
private float calculatedMinDaysB4Next = 1f;
private int calculatedQuantity = 1;
private bool blockSpawn = false;
private bool myDebug = false;
private readonly float errorMinDaysB4Next = 0.001f;
private readonly int errorExponentialLimit = 20;
private readonly int errorSpawnCount = 750;
}
}

View File

@ -0,0 +1,80 @@
using System;
using RimWorld;
using Verse;
namespace MoharHediffs
{
public class HediffComp_Steamer : HediffComp
{
private bool MyDebug
{
get
{
return this.Props.debug;
}
}
private Map MyMap
{
get
{
return base.Pawn.Map;
}
}
public HediffCompProperties_Steamer Props
{
get
{
return (HediffCompProperties_Steamer)this.props;
}
}
public override void CompPostTick(ref float severityAdjustment)
{
bool flag = base.Pawn.Negligible();
checked
{
if (flag)
{
bool myDebug = this.MyDebug;
if (myDebug)
{
Log.Warning("null pawn");
}
}
else
{
bool flag2 = this.sprayTicksLeft <= 0;
if (flag2)
{
bool flag3 = Rand.Chance(this.Props.puffingChance);
if (flag3)
{
FleckMaker.ThrowAirPuffUp(base.Pawn.TrueCenter(), this.MyMap);
GenTemperature.PushHeat(base.Pawn.Position, this.MyMap, this.Props.temperatureIncreasePerPuff);
}
this.sprayTicksLeft = (this.ticksUntilSpray = Rand.RangeInclusive(this.Props.MinTicksBetweenSprays, this.Props.MaxTicksBetweenSprays));
}
else
{
this.sprayTicksLeft--;
}
}
}
}
public override string CompTipStringExtra
{
get
{
string empty = string.Empty;
return empty + "Puff in " + this.sprayTicksLeft.ToStringTicksToPeriod(true, false, true, true, false);
}
}
private int ticksUntilSpray = 500;
private int sprayTicksLeft;
}
}

View File

@ -0,0 +1,236 @@
using System;
using UnityEngine;
using Verse;
namespace MoharHediffs
{
public class HediffComp_TrailLeaver : HediffComp
{
public Map MyMap
{
get
{
return base.Pawn.Map;
}
}
public bool NullMap
{
get
{
return this.MyMap == null;
}
}
public bool MyDebug
{
get
{
return this.Props.debug;
}
}
public HediffCompProperties_TrailLeaver Props
{
get
{
return (HediffCompProperties_TrailLeaver)this.props;
}
}
public bool HasMotePool
{
get
{
return this.Props.HasMotePool;
}
}
public TerrainRestriction TerrainRestriction
{
get
{
return (!this.Props.HasRestriction || !this.Props.restriction.HasTerrainRestriction) ? null : this.Props.restriction.terrain;
}
}
public bool HasTerrainRestriction
{
get
{
return this.TerrainRestriction != null;
}
}
public Restriction PawnRestriction
{
get
{
return (!this.Props.HasRestriction) ? null : this.Props.restriction;
}
}
public bool HasPawnRestriction
{
get
{
return this.TerrainRestriction != null;
}
}
public override void CompPostMake()
{
this.PropsCheck();
}
public void NewPeriod()
{
this.currentPeriod = this.Props.period.RandomInRange;
}
public override void CompPostTick(ref float severityAdjustment)
{
bool flag = base.Pawn.Negligible();
if (flag)
{
bool myDebug = this.MyDebug;
if (myDebug)
{
Log.Warning("null pawn");
}
}
else
{
bool flag2 = this.currentPeriod == 0;
if (flag2)
{
this.NewPeriod();
}
bool flag3 = !base.Pawn.IsHashIntervalTick(this.currentPeriod);
if (!flag3)
{
bool flag4 = !this.IsTerrainAllowed(base.Pawn.Position.GetTerrain(this.MyMap));
if (flag4)
{
bool myDebug2 = this.MyDebug;
if (myDebug2)
{
Log.Warning("terrain does not allow motes");
}
}
else
{
bool flag5 = !this.IsPawnActivityCompatible();
if (flag5)
{
bool myDebug3 = this.MyDebug;
if (myDebug3)
{
Log.Warning("pawn activity does not allow motes");
}
}
else
{
this.TryPlaceMote();
this.NewPeriod();
}
}
}
}
}
public void PropsCheck()
{
bool flag = !this.MyDebug;
if (!flag)
{
bool flag2 = !this.HasMotePool;
if (flag2)
{
Log.Warning("Mote pool is empty, trailLeaver needs at least 1 mote");
}
bool flag3 = !this.Props.HasOffset;
if (flag3)
{
Log.Warning("no offset per body type found, will use default:" + this.Props.defaultOffset);
}
else
{
string text = "BodyTypeOffsets dump => ";
foreach (BodyTypeOffset bodyTypeOffset in this.Props.offSetPerBodyType)
{
text = string.Concat(new object[]
{
text,
bodyTypeOffset.bodyType.defName,
":",
bodyTypeOffset.offset,
"; "
});
}
Log.Warning(text);
}
bool usesFootPrints = this.Props.UsesFootPrints;
if (usesFootPrints)
{
Log.Warning("footprints => " + this.Props.footprint.Dump());
}
}
}
private void TryPlaceMote()
{
bool flag = !this.HasMotePool;
if (!flag)
{
Vector3 drawPos = base.Pawn.DrawPos;
bool flag2 = base.Pawn.Position.InBounds(this.MyMap);
if (flag2)
{
Vector3 vector;
float moteRotation = this.GetMoteRotation(drawPos, out vector);
Vector3 vector2 = drawPos + this.GetBodyTypeOffset() + this.GetFootPrintOffset(vector);
bool myDebug = this.MyDebug;
if (myDebug)
{
Log.Warning(string.Concat(new object[]
{
base.Pawn.ThingID,
" ",
this.parent.def.defName,
" TryPlaceMote - dynRot:",
this.Props.dynamicRotation.ToString(),
" footprint:",
this.Props.UsesFootPrints.ToString(),
" drawPos:",
drawPos,
" offset:",
vector2,
" rot:",
moteRotation,
" normalized:",
vector
}));
}
float randomInRange = this.Props.randomScale.RandomInRange;
ThingDef moteDef = this.Props.motePool.RandomElementWithFallback(null);
Mote mote;
bool flag3 = (mote = (vector2.TryAnyMoteSpawn(this.MyMap, moteRotation, randomInRange, moteDef, this.MyDebug) as Mote)) != null;
if (flag3)
{
this.ChangeMoteColor(mote);
}
}
this.RecordMotePos(drawPos);
}
}
public int currentPeriod = 0;
public Vector3 lastMotePos;
public Color lastColor = Color.black;
public bool lastFootprintRight;
}
}

View File

@ -0,0 +1,27 @@
using System;
namespace MoharHediffs
{
public class HediffCondition
{
public bool HasPawnCondition
{
get
{
return this.pawn != null;
}
}
public bool HasBodypartCondition
{
get
{
return this.bodyPart != null && this.bodyPart.HasBPCondition;
}
}
public PawnCondition pawn;
public BodyPartCondition bodyPart;
}
}

View File

@ -0,0 +1,159 @@
using System;
using System.Collections.Generic;
using System.Linq;
using RimWorld;
using Verse;
namespace MoharHediffs
{
public static class HediffIntersect
{
public static bool RemoveHediffAndReturnTrue(Pawn p, Hediff h, bool debug = false)
{
string warning = debug ? string.Concat(new string[]
{
p.LabelShort,
" - ",
p.def.defName,
" - RemoveHediff ",
h.def.defName
}) : "";
Tools.Warn(warning, debug);
p.health.RemoveHediff(h);
return true;
}
public static bool TreatLightCondition(this Pawn p, LightCondition LC, Hediff h, float lightLevel, bool outside, bool debug = false)
{
bool flag = (LC.RequiresLightLevel && !LC.level.Value.Includes(lightLevel)) || (LC.requiresOutside && !outside) || (LC.requiresInside && outside);
return flag && HediffIntersect.RemoveHediffAndReturnTrue(p, h, debug);
}
public static bool TreatNeedCondition(this Pawn p, List<NeedCondition> needs, Hediff h, bool debug = false)
{
string str = debug ? (p.LabelShort + " TreatNeedCondition - ") : "";
using (List<NeedCondition>.Enumerator enumerator = needs.GetEnumerator())
{
while (enumerator.MoveNext())
{
NeedCondition NC = enumerator.Current;
Tools.Warn(str + string.Format("checking {0} => {1} > x > {2}", NC.needDef.defName, NC.level.min, NC.level.max), debug);
Need need = (from n in p.needs.AllNeeds
where n.def == NC.needDef && !NC.level.Includes(n.CurLevelPercentage)
select n).FirstOrFallback(null);
bool flag = need == null;
if (!flag)
{
Tools.Warn(str + string.Format("Found {0} out of range: {1}", need.def.defName, need.CurLevelPercentage), debug);
return HediffIntersect.RemoveHediffAndReturnTrue(p, h, debug);
}
}
}
return false;
}
public static bool TreatHediffSeverityCondition(this Pawn p, List<HediffSeverityCondition> destroyingHediffs, Hediff h, bool debug = false)
{
using (List<HediffSeverityCondition>.Enumerator enumerator = destroyingHediffs.GetEnumerator())
{
while (enumerator.MoveNext())
{
HediffSeverityCondition HSC = enumerator.Current;
Hediff hediff = (from dh in p.health.hediffSet.hediffs
where dh.def == HSC.hediffDef && !HSC.acceptableSeverity.Includes(dh.Severity)
select dh).FirstOrFallback(null);
bool flag = hediff == null;
if (!flag)
{
return HediffIntersect.RemoveHediffAndReturnTrue(p, hediff, debug);
}
}
}
return false;
}
public static bool TreatRelevantHediffsAndReportIfStillHediffsToCheck(this HediffComp_OnTheCarpet comp)
{
bool myDebug = comp.MyDebug;
bool flag = false;
Pawn pawn = comp.Pawn;
string text = myDebug ? (pawn.LabelShort + " TreatRelevant - ") : "";
Tools.Warn(text + " Entering", myDebug);
float ambientTemperature = pawn.AmbientTemperature;
float lightLevel = pawn.Map.glowGrid.GroundGlowAt(pawn.Position, false, false);
Room room = pawn.GetRoom(RegionType.Set_All);
bool outside = room == null || room.PsychologicallyOutdoors;
List<Hediff> hediffs = comp.Pawn.health.hediffSet.hediffs;
checked
{
int num = hediffs.Count - 1;
while (num >= 0 && !hediffs.NullOrEmpty<Hediff>())
{
Hediff H = hediffs[num];
IEnumerable<HediffItemToRemove> hediffPool = comp.Props.hediffPool;
Func<HediffItemToRemove, bool> predicate;
Func<HediffItemToRemove, bool> <>9__0;
if ((predicate = <>9__0) == null)
{
predicate = (<>9__0 = ((HediffItemToRemove h) => h.hediffDef == H.def));
}
foreach (HediffItemToRemove hediffItemToRemove in hediffPool.Where(predicate))
{
Tools.Warn(text + " found intersect hediff: " + H.def.defName, myDebug);
HediffKeepingCondition defaultPlusSpecificHediffCondition = HediffRemovalConditionBuilder.GetDefaultPlusSpecificHediffCondition(comp.Props.defaultCondition, hediffItemToRemove.specificCondition, myDebug);
bool flag2 = false;
bool hasLightCondition = defaultPlusSpecificHediffCondition.HasLightCondition;
if (hasLightCondition)
{
Tools.Warn(text + H.def.defName + "checking light", myDebug);
flag2 = pawn.TreatLightCondition(defaultPlusSpecificHediffCondition.light, H, lightLevel, outside, myDebug);
}
else
{
bool flag3 = defaultPlusSpecificHediffCondition.HasTemperatureCondition && !defaultPlusSpecificHediffCondition.temperature.Value.Includes(ambientTemperature);
if (flag3)
{
Tools.Warn(text + H.def.defName + "checking temperature", myDebug);
flag2 = HediffIntersect.RemoveHediffAndReturnTrue(pawn, H, myDebug);
}
else
{
bool hasNeedCondition = defaultPlusSpecificHediffCondition.HasNeedCondition;
if (hasNeedCondition)
{
Tools.Warn(string.Concat(new object[]
{
text,
H.def.defName,
"checking ",
defaultPlusSpecificHediffCondition.needs.Count,
"need"
}), myDebug);
flag2 = pawn.TreatNeedCondition(defaultPlusSpecificHediffCondition.needs, H, myDebug);
}
else
{
bool hasDestroyingHediffs = defaultPlusSpecificHediffCondition.HasDestroyingHediffs;
if (hasDestroyingHediffs)
{
Tools.Warn(text + H.def.defName + "checking other hediffs", myDebug);
flag2 = pawn.TreatHediffSeverityCondition(defaultPlusSpecificHediffCondition.destroyingHediffs, H, myDebug);
}
}
}
}
flag |= !flag2;
bool flag4 = flag2;
if (flag4)
{
return true;
}
}
num--;
}
Tools.Warn(text + "exiting", myDebug);
return flag;
}
}
}
}

View File

@ -0,0 +1,26 @@
using System;
using Verse;
namespace MoharHediffs
{
public class HediffItem
{
public bool HasSpecific
{
get
{
return this.specificCondition != null;
}
}
public HediffDef hediffDef;
public FloatRange applyChance = new FloatRange(1f, 1f);
public FloatRange severity = new FloatRange(0.1f, 0.2f);
public float weight = 1f;
public HediffCondition specificCondition;
}
}

View File

@ -0,0 +1,20 @@
using System;
using Verse;
namespace MoharHediffs
{
public class HediffItemToRemove
{
public bool HasSpecificCondition
{
get
{
return this.specificCondition != null;
}
}
public HediffDef hediffDef;
public HediffKeepingCondition specificCondition;
}
}

View File

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using Verse;
namespace MoharHediffs
{
public class HediffKeepingCondition
{
public bool HasTemperatureCondition
{
get
{
return this.temperature != null;
}
}
public bool HasLightCondition
{
get
{
return this.light != null;
}
}
public bool HasNeedCondition
{
get
{
return !this.needs.NullOrEmpty<NeedCondition>();
}
}
public bool HasDestroyingHediffs
{
get
{
bool result;
if (!this.destroyingHediffs.NullOrEmpty<HediffSeverityCondition>())
{
result = this.destroyingHediffs.Any((HediffSeverityCondition dh) => !dh.HasHediffDef);
}
else
{
result = false;
}
return result;
}
}
public FloatRange? temperature = null;
public LightCondition light;
public List<NeedCondition> needs;
public List<HediffSeverityCondition> destroyingHediffs;
}
}

View File

@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Verse;
namespace MoharHediffs
{
public static class HediffRemovalConditionBuilder
{
public static void CopyHediffKeepingCondition(HediffKeepingCondition source, HediffKeepingCondition dest, bool debug = false)
{
string str = debug ? "CopyHediffCondition - " : "";
bool hasTemperatureCondition = source.HasTemperatureCondition;
if (hasTemperatureCondition)
{
Tools.Warn(str + "found HasTemperatureCondition, copying", debug);
dest.temperature = source.temperature;
}
bool hasLightCondition = source.HasLightCondition;
if (hasLightCondition)
{
Tools.Warn(str + "found HasLightCondition, copying", debug);
dest.light = new LightCondition(source.light);
}
bool hasNeedCondition = source.HasNeedCondition;
if (hasNeedCondition)
{
Tools.Warn(str + "found HasNeedCondition, copying", debug);
using (List<NeedCondition>.Enumerator enumerator = source.needs.GetEnumerator())
{
while (enumerator.MoveNext())
{
NeedCondition nc = enumerator.Current;
bool flag = dest.needs.Any((NeedCondition n) => n.needDef == nc.needDef);
if (flag)
{
(from n in dest.needs
where n.needDef == nc.needDef
select n).First<NeedCondition>().level = nc.level;
}
else
{
dest.needs.Add(new NeedCondition(nc));
}
}
}
}
bool hasDestroyingHediffs = source.HasDestroyingHediffs;
if (hasDestroyingHediffs)
{
Tools.Warn(str + "found HasDestroyingHediffs, copying", debug);
using (List<HediffSeverityCondition>.Enumerator enumerator2 = source.destroyingHediffs.GetEnumerator())
{
while (enumerator2.MoveNext())
{
HediffSeverityCondition hsc = enumerator2.Current;
bool flag2 = dest.destroyingHediffs.Any((HediffSeverityCondition dh) => dh.hediffDef == hsc.hediffDef);
if (flag2)
{
(from dh in dest.destroyingHediffs
where dh.hediffDef == hsc.hediffDef
select dh).First<HediffSeverityCondition>().acceptableSeverity = hsc.acceptableSeverity;
}
else
{
dest.destroyingHediffs.Add(new HediffSeverityCondition(hsc));
}
}
}
}
}
public static HediffKeepingCondition GetDefaultPlusSpecificHediffCondition(HediffKeepingCondition defaultHKC, HediffKeepingCondition specificHKC, bool debug = false)
{
string text = debug ? "GetDefaultPlusSpecificHediffCondition - " : "";
Tools.Warn(text + "allocating answerHC", debug);
HediffKeepingCondition hediffKeepingCondition = new HediffKeepingCondition
{
needs = new List<NeedCondition>()
};
bool flag = defaultHKC != null;
if (flag)
{
Tools.Warn(text + "found defaultHKC, copying", debug);
HediffRemovalConditionBuilder.CopyHediffKeepingCondition(defaultHKC, hediffKeepingCondition, debug);
}
bool flag2 = specificHKC != null;
if (flag2)
{
Tools.Warn(text + "found specificHKC, copying", debug);
HediffRemovalConditionBuilder.CopyHediffKeepingCondition(specificHKC, hediffKeepingCondition, debug);
}
Tools.Warn(string.Concat(new object[]
{
text,
string.Format("HasDestroyingHediffs:{0} - ", hediffKeepingCondition.HasDestroyingHediffs),
hediffKeepingCondition.HasDestroyingHediffs ? hediffKeepingCondition.destroyingHediffs.Count<HediffSeverityCondition>() : 0,
string.Format("HasLightCondition:{0} - ", hediffKeepingCondition.HasLightCondition),
hediffKeepingCondition.HasLightCondition ? ("reqIn:" + hediffKeepingCondition.light.requiresInside.ToString() + " reqOut:" + hediffKeepingCondition.light.requiresOutside.ToString()) : "",
string.Format("HasNeedCondition:{0}", hediffKeepingCondition.HasNeedCondition),
hediffKeepingCondition.HasNeedCondition ? hediffKeepingCondition.needs.Count<NeedCondition>() : 0,
string.Format("HasTemperatureCondition:{0}", hediffKeepingCondition.HasTemperatureCondition)
}), debug);
return hediffKeepingCondition;
}
}
}

View File

@ -0,0 +1,20 @@
using System;
using Verse;
namespace MoharHediffs
{
public class HediffRequirementSettings
{
public bool HasHediffDef
{
get
{
return this.hediffDef != null;
}
}
public HediffDef hediffDef;
public FloatRange severity = new FloatRange(0f, 1f);
}
}

View File

@ -0,0 +1,30 @@
using System;
using Verse;
namespace MoharHediffs
{
public class HediffSeverityCondition
{
public bool HasHediffDef
{
get
{
return this.hediffDef != null;
}
}
public HediffSeverityCondition(HediffSeverityCondition copyMe)
{
this.hediffDef = copyMe.hediffDef;
this.acceptableSeverity = copyMe.acceptableSeverity;
}
public HediffSeverityCondition()
{
}
public HediffDef hediffDef;
public FloatRange acceptableSeverity = new FloatRange(0f, 0.5f);
}
}

View File

@ -0,0 +1,25 @@
using System;
using Verse;
namespace MoharHediffs
{
public class InnerShineDef : Def
{
public override string ToString()
{
return this.defName;
}
public InnerShineDef Named(string name)
{
return DefDatabase<InnerShineDef>.GetNamed(name, true);
}
public override int GetHashCode()
{
return this.defName.GetHashCode();
}
public InnerShineItem item;
}
}

View File

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using Verse;
namespace MoharHediffs
{
public class InnerShineItem
{
public bool HasSpawningRules
{
get
{
return this.spawningRules != null;
}
}
public bool HasRestriction
{
get
{
return this.restriction != null;
}
}
public bool HasMotePool
{
get
{
return !this.motePool.NullOrEmpty<ThingDef>();
}
}
public bool HasBodyTypeDrawRules
{
get
{
return !this.bodyTypeDrawRules.NullOrEmpty<BodyTypeSpecificities>();
}
}
public bool HasDefaultDrawRules
{
get
{
return this.defaultDrawRules != null;
}
}
public bool HasColorRange
{
get
{
return this.colorRange != null;
}
}
public string Dump()
{
return string.Concat(new string[]
{
"label:",
this.label,
string.Format(" HasSpawningRules:{0} HasRestriction:{1}", this.HasSpawningRules, this.HasRestriction),
string.Format(" HasMotePool:{0} HasBodyTypeDrawRules:{1} HasDefaultDrawRules:{2}", this.HasMotePool, this.HasBodyTypeDrawRules, this.HasDefaultDrawRules),
string.Format(" HasColorRange:{0}", this.HasColorRange),
string.Format(" debug:{0}", this.debug)
});
}
public string label;
public SpawnRules spawningRules;
public List<ThingDef> motePool;
public MoteLink.Nature linkType;
public List<BodyTypeSpecificities> bodyTypeDrawRules;
public DrawingSpecificities defaultDrawRules;
public ActivityRestriction restriction;
public ColorRange colorRange;
public bool debug = false;
}
}

View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using Verse;
namespace MoharHediffs
{
public class InnerShineRecord
{
public InnerShineRecord(InnerShineItem ISI)
{
this.label = ISI.label;
this.spawned = new List<Thing>();
this.ticksLeft = ISI.NewPeriod();
this.lastColor = Color.black;
}
public string Dump
{
get
{
string format = "label:{0} spawned:{1} ticksLeft:{2} lastColor:{3}";
object[] array = new object[4];
array[0] = this.label;
int num = 1;
List<Thing> list = this.spawned;
array[num] = ((list != null) ? new int?(list.CountAllowNull<Thing>()) : null);
array[2] = this.ticksLeft;
array[3] = this.lastColor;
return string.Format(format, array);
}
}
public string label;
public List<Thing> spawned;
public int ticksLeft;
public Color lastColor;
}
}

View File

@ -0,0 +1,189 @@
using System;
using System.Linq;
using RimWorld;
using UnityEngine;
using Verse;
namespace MoharHediffs
{
public static class InnerShinerUtils
{
public static InnerShineItem RetrieveISI(this HediffComp_InnerShine comp, string label)
{
bool hasRawShinePool = comp.Props.HasRawShinePool;
if (hasRawShinePool)
{
InnerShineItem result;
bool flag = (result = (from i in comp.Props.innerShinePool
where i.label == label
select i).FirstOrFallback(null)) != null;
if (flag)
{
return result;
}
}
bool hasShineDefPool = comp.Props.HasShineDefPool;
if (hasShineDefPool)
{
InnerShineDef innerShineDef;
bool flag2 = (innerShineDef = (from i in comp.Props.innerShineDefPool
where i.item.label == label
select i).FirstOrFallback(null)) != null;
if (flag2)
{
return innerShineDef.item;
}
}
return null;
}
public static void SelfDestroy(this HediffComp_InnerShine comp)
{
comp.parent.Severity = 0f;
comp.Pawn.health.RemoveHediff(comp.parent);
}
public static void ChangeMoteColor(this InnerShineItem ISI, InnerShineRecord ISR, Mote mote)
{
bool flag = !ISI.HasColorRange || mote == null;
if (!flag)
{
bool flag2 = ISR.lastColor == Color.black;
if (flag2)
{
ISR.lastColor = ISI.colorRange.colorA;
}
ISR.lastColor = ISI.colorRange.RandomPickColor(ISR.lastColor, ISI.debug);
mote.instanceColor = ISR.lastColor;
}
}
public static void GetSpecifities(this InnerShineItem ISI, Pawn p, out Vector3 offset, out float scale)
{
offset = Vector3.zero;
scale = 1f;
Pawn_StoryTracker story = p.story;
bool flag = ((story != null) ? story.bodyType : null) == null || !ISI.HasBodyTypeDrawRules;
if (flag)
{
bool hasDefaultDrawRules = ISI.HasDefaultDrawRules;
if (hasDefaultDrawRules)
{
offset = ISI.defaultDrawRules.GetRotationOffset(p);
scale = ISI.defaultDrawRules.randomScale.RandomInRange;
}
}
else
{
BodyTypeSpecificities bodyTypeSpecificities = (from b in ISI.bodyTypeDrawRules
where b.bodyTypeDef == p.story.bodyType
select b).FirstOrFallback(null);
bool flag2 = bodyTypeSpecificities == null;
if (flag2)
{
bool hasDefaultDrawRules2 = ISI.HasDefaultDrawRules;
if (hasDefaultDrawRules2)
{
offset = ISI.defaultDrawRules.GetRotationOffset(p);
scale = ISI.defaultDrawRules.randomScale.RandomInRange;
}
}
else
{
offset = bodyTypeSpecificities.drawRules.GetRotationOffset(p);
scale = bodyTypeSpecificities.drawRules.randomScale.RandomInRange;
}
}
}
public static bool ShouldSpawnMote(this InnerShineItem ISI, InnerShineRecord ISR, Pawn p)
{
bool flag = !ISI.HasCompatibleActivity(p);
bool result;
if (flag)
{
result = false;
}
else
{
bool flag2 = ISI.HasMoteNumLimit();
result = (!flag2 || !ISR.AlreadyReachedMax(ISI.spawningRules.spawnedMax));
}
return result;
}
public static Vector3 GetDrawOffset(this InnerShineItem ISI, Pawn p)
{
Pawn_StoryTracker story = p.story;
bool flag = ((story != null) ? story.bodyType : null) == null || !ISI.HasBodyTypeDrawRules;
Vector3 result;
if (flag)
{
bool hasDefaultDrawRules = ISI.HasDefaultDrawRules;
if (hasDefaultDrawRules)
{
result = ISI.defaultDrawRules.GetRotationOffset(p);
}
else
{
result = Vector3.zero;
}
}
else
{
BodyTypeSpecificities bodyTypeSpecificities = (from b in ISI.bodyTypeDrawRules
where b.bodyTypeDef == p.story.bodyType
select b).FirstOrFallback(null);
bool flag2 = bodyTypeSpecificities == null;
if (flag2)
{
result = (ISI.HasDefaultDrawRules ? ISI.defaultDrawRules.GetRotationOffset(p) : Vector3.zero);
}
else
{
result = bodyTypeSpecificities.drawRules.GetRotationOffset(p);
}
}
return result;
}
public static bool AlreadyReachedMax(this InnerShineRecord ISR, int max)
{
bool flag = ISR.spawned.NullOrEmpty<Thing>();
return !flag && ISR.spawned.Count<Thing>() >= max;
}
public static bool HasCompatibleActivity(this InnerShineItem ISI, Pawn p)
{
bool flag = !ISI.HasRestriction;
bool result;
if (flag)
{
result = true;
}
else
{
ActivityRestriction restriction = ISI.restriction;
bool flag2 = restriction.HasPostureRestriction && !restriction.allowedPostures.Contains(p.GetPosture());
if (flag2)
{
result = false;
}
else
{
bool flag3 = restriction.HasJobRestriction && p.CurJob != null && !restriction.allowedJobs.Contains(p.CurJob.def);
if (flag3)
{
result = false;
}
else
{
bool flag4 = restriction.HasAllowedRotation && !restriction.allowedRotation.Contains(p.Rotation);
result = !flag4;
}
}
}
return result;
}
}
}

View File

@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using Verse;
namespace MoharHediffs
{
public class ItemParameter
{
public bool ThingSpawner
{
get
{
return this.thingToSpawn != null && this.pawnKindToSpawn == null;
}
}
public bool PawnSpawner
{
get
{
return this.thingToSpawn == null && this.pawnKindToSpawn != null;
}
}
public bool HasFactionParams
{
get
{
return !this.randomFactionParameters.NullOrEmpty<RandomFactionParameter>();
}
}
public bool HasGraceChance
{
get
{
return this.graceChance != 0f;
}
}
public bool HasFilth
{
get
{
return this.filthDef != null;
}
}
public void LogParams(bool myDebug = false)
{
Tools.Warn(string.Concat(new object[]
{
"ThingSpawner:",
this.ThingSpawner.ToString(),
"; ",
this.ThingSpawner ? this.thingToSpawn.defName : "",
"PawnSpawner:",
this.PawnSpawner.ToString(),
"; ",
this.PawnSpawner ? this.pawnKindToSpawn.defName : "",
"spawnCount:",
this.spawnCount,
"; weight:",
this.weight,
"; "
}), myDebug);
}
public void ComputeRandomParameters(out int calculatedTickUntilSpawn, out int calculatedGraceTicks, out int calculatedSpawnCount)
{
checked
{
calculatedTickUntilSpawn = (int)(unchecked(this.daysB4Next.RandomInRange * 60000f));
calculatedSpawnCount = this.spawnCount.RandomInRange;
calculatedGraceTicks = 0;
bool flag = this.HasGraceChance && Rand.Chance(this.graceChance);
if (flag)
{
calculatedGraceTicks = (int)(unchecked(this.graceDays.RandomInRange * 60000f));
}
}
}
public ThingDef thingToSpawn = null;
public PawnKindDef pawnKindToSpawn = null;
public IntRange spawnCount = new IntRange(1, 1);
public ThingDef filthDef = null;
public List<RandomFactionParameter> randomFactionParameters;
public FloatRange daysB4Next = new FloatRange(1f, 2f);
public float graceChance = 0f;
public FloatRange graceDays = new FloatRange(1f, 2f);
public float weight = 0f;
public string spawnVerb = "delivery";
}
}

View File

@ -0,0 +1,69 @@
using System;
using RimWorld;
using Verse;
namespace MoharHediffs
{
public static class KeepingConditionCompatibility
{
public static bool IsPawnNeedConditionCompatible(this Pawn p, HediffKeepingCondition HKC, bool debug = false)
{
string str = debug ? (p.Label + " IsPawnNeedConditionCompatible - ") : "";
bool hasNeedCondition = HKC.HasNeedCondition;
if (hasNeedCondition)
{
foreach (NeedCondition needCondition in HKC.needs)
{
bool flag = false;
foreach (Need need in p.needs.AllNeeds)
{
Tools.Warn(str + needCondition.needDef.defName + " found in pawn needs, ok", debug);
flag |= (need.def == needCondition.needDef);
}
bool flag2 = !flag;
if (flag2)
{
Tools.Warn(str + needCondition.needDef.defName + " not found in pawn needs, exiting", debug);
return false;
}
}
}
Tools.Warn(str + "is need compatible, ok", debug);
return true;
}
public static bool IsPawnNeedCompatible(this HediffCompProperties_OnTheCarpet Props, Pawn p)
{
bool debug = Props.debug;
string str = debug ? (p.Label + " IsPawnNeedCompatible - ") : "";
bool hasDefaultCondition = Props.HasDefaultCondition;
if (hasDefaultCondition)
{
Tools.Warn(str + "checking default condition", debug);
bool flag = !p.IsPawnNeedConditionCompatible(Props.defaultCondition, debug);
if (flag)
{
Tools.Warn(str + "defaultCondition not compatible with pawn, exiting", debug);
return false;
}
Tools.Warn(str + " Compatible with defaultCondition", debug);
}
foreach (HediffItemToRemove hediffItemToRemove in Props.hediffPool)
{
bool hasSpecificCondition = hediffItemToRemove.HasSpecificCondition;
if (hasSpecificCondition)
{
Tools.Warn(str + "checking " + hediffItemToRemove.hediffDef.defName + " specific condition", debug);
bool flag2 = !p.IsPawnNeedConditionCompatible(hediffItemToRemove.specificCondition, debug);
if (flag2)
{
Tools.Warn(str + "specificCondition not compatible with pawn, exiting", debug);
return false;
}
Tools.Warn(str + " Compatible with specificCondition", debug);
}
}
return true;
}
}
}

View File

@ -0,0 +1,29 @@
using System;
using Verse;
namespace MoharHediffs
{
public class LightCondition
{
public bool RequiresLightLevel
{
get
{
return this.level != null;
}
}
public LightCondition(LightCondition copyMe)
{
this.requiresInside = copyMe.requiresInside;
this.requiresOutside = copyMe.requiresOutside;
this.level = copyMe.level;
}
public bool requiresOutside = true;
public bool requiresInside = false;
public FloatRange? level;
}
}

View File

@ -0,0 +1,24 @@
using System;
using Verse;
namespace MoharHediffs
{
public class MentalStateOption
{
public void Dump()
{
Log.Warning(string.Concat(new object[]
{
"MentalStateDef:",
this.mentalDef.defName,
"; weight:",
this.weight,
"; "
}));
}
public MentalStateDef mentalDef;
public float weight = 1f;
}
}

View File

@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using RimWorld;
using Verse;
namespace MoharHediffs
{
public static class MentalStatePicker
{
public static float MSTotalWeight(this List<MentalStateOption> MSO)
{
float num = 0f;
for (int i = 0; i < MSO.Count; i = checked(i + 1))
{
num += MSO[i].weight;
}
return num;
}
public static void ComputeRandomMentalState(this HediffComp_RandySpawnUponDeath comp)
{
bool flag = !comp.ChosenItem.HasMentalStateParams;
if (!flag)
{
MentalStateDef weightedRandomMentalState = comp.GetWeightedRandomMentalState();
bool flag2 = weightedRandomMentalState == null;
if (flag2)
{
bool myDebug = comp.MyDebug;
if (myDebug)
{
Log.Warning("ComputeRandomMentalState - found no MentalStateDef");
}
}
else
{
comp.RandomMS = weightedRandomMentalState;
bool myDebug2 = comp.MyDebug;
if (myDebug2)
{
string str = "ComputeRandomFaction - found:";
Faction randomFaction = comp.RandomFaction;
Log.Warning(str + ((randomFaction != null) ? randomFaction.GetCallLabel() : null));
}
}
}
}
public static MentalStateDef GetWeightedRandomMentalState(this HediffComp_RandySpawnUponDeath comp)
{
bool flag = !comp.HasChosenPawn || !comp.ChosenItem.HasMentalStateParams;
checked
{
MentalStateDef result;
if (flag)
{
result = null;
}
else
{
List<MentalStateOption> mentalState = comp.ChosenItem.mentalState;
float num = Rand.Range(0f, mentalState.MSTotalWeight());
for (int i = 0; i < mentalState.Count; i++)
{
bool flag2 = unchecked(num -= mentalState[i].weight) < 0f;
if (flag2)
{
bool myDebug = comp.MyDebug;
if (myDebug)
{
Log.Warning("GetWeightedRandomIndex : returning " + i);
}
return mentalState[i].mentalDef;
}
}
bool myDebug2 = comp.MyDebug;
if (myDebug2)
{
Log.Warning("GetWeightedRandomMentalState : failed to return proper index, returning null");
}
result = null;
}
return result;
}
}
}
}

View File

@ -0,0 +1,151 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7ACFB1B0-3B20-48B9-BA73-48DD6353ABED}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MoharHediffs</RootNamespace>
<AssemblyName>MoharHediffs</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="AlienRace" />
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\..\..\..\..\..\..\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="MoharGfx">
<HintPath>..\..\..\..\..\..\..\..\..\..\Steam\steamapps\workshop\content\294100\2057001924\1.5\Assemblies\MoharGfx.dll</HintPath>
</Reference>
<Reference Include="System.Core">
<HintPath>..\..\..\..\..\..\..\..\..\..\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\System.Core.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\..\..\..\..\..\..\..\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
<Compile Include="ActivityRestriction.cs" />
<Compile Include="BodyPartCondition.cs" />
<Compile Include="BodyPartsTools.cs" />
<Compile Include="BodyTypeOffset.cs" />
<Compile Include="BodyTypeSpecificities.cs" />
<Compile Include="ChannelColorCondition.cs" />
<Compile Include="ColorRange.cs" />
<Compile Include="CommonSettings.cs" />
<Compile Include="ConditionBuilder.cs" />
<Compile Include="ConditionValidation.cs" />
<Compile Include="CopyPawnSettings.cs" />
<Compile Include="DrawingSpecificities.cs" />
<Compile Include="FactionPickerParameters.cs" />
<Compile Include="FactionPickerUtils.cs" />
<Compile Include="FilthSettings.cs" />
<Compile Include="Footprint.cs" />
<Compile Include="GeneralSettings.cs" />
<Compile Include="GfxEffects.cs" />
<Compile Include="HediffAndBodyPart.cs" />
<Compile Include="HediffCompProperties_AnotherRandom.cs" />
<Compile Include="HediffCompProperties_Filther.cs" />
<Compile Include="HeDiffCompProperties_HediffExclusive.cs" />
<Compile Include="HediffCompProperties_HediffNullifier.cs" />
<Compile Include="HediffCompProperties_HediffRandom.cs" />
<Compile Include="HediffCompProperties_InnerShine.cs" />
<Compile Include="HediffCompProperties_MultipleHediff.cs" />
<Compile Include="HediffCompProperties_OnTheCarpet.cs" />
<Compile Include="HediffCompProperties_PostRemoveTrigger_HediffAdd.cs" />
<Compile Include="HediffCompProperties_RainbowTrail.cs" />
<Compile Include="HediffCompProperties_RandySpawner.cs" />
<Compile Include="HediffCompProperties_RandySpawnUponDeath.cs" />
<Compile Include="HediffCompProperties_Spawner.cs" />
<Compile Include="HediffCompProperties_Steamer.cs" />
<Compile Include="HediffCompProperties_TrailLeaver.cs" />
<Compile Include="HediffComp_AnotherRandom.cs" />
<Compile Include="HediffComp_Filther.cs" />
<Compile Include="HeDiffComp_HediffExclusive.cs" />
<Compile Include="HediffComp_HediffNullifier.cs" />
<Compile Include="HediffComp_HediffRandom.cs" />
<Compile Include="HediffComp_InnerShine.cs" />
<Compile Include="HediffComp_MultipleHediff.cs" />
<Compile Include="HediffComp_OnTheCarpet.cs" />
<Compile Include="HediffComp_PostRemoveTrigger_HediffAdd.cs" />
<Compile Include="HediffComp_RainbowTrail.cs" />
<Compile Include="HediffComp_RandySpawner.cs" />
<Compile Include="HediffComp_RandySpawnUponDeath.cs" />
<Compile Include="HediffComp_Spawner.cs" />
<Compile Include="HediffComp_Steamer.cs" />
<Compile Include="HediffComp_TrailLeaver.cs" />
<Compile Include="HediffCondition.cs" />
<Compile Include="HediffIntersect.cs" />
<Compile Include="HediffItem.cs" />
<Compile Include="HediffItemToRemove.cs" />
<Compile Include="HediffKeepingCondition.cs" />
<Compile Include="HediffRemovalConditionBuilder.cs" />
<Compile Include="HediffRequirementSettings.cs" />
<Compile Include="HediffSeverityCondition.cs" />
<Compile Include="InnerShineDef.cs" />
<Compile Include="InnerShineItem.cs" />
<Compile Include="InnerShineRecord.cs" />
<Compile Include="InnerShinerUtils.cs" />
<Compile Include="ItemParameter.cs" />
<Compile Include="KeepingConditionCompatibility.cs" />
<Compile Include="LightCondition.cs" />
<Compile Include="MentalStateOption.cs" />
<Compile Include="MentalStatePicker.cs" />
<Compile Include="MoteColorChangeUtils.cs" />
<Compile Include="MoteLink.cs" />
<Compile Include="MoteSpawnUtils.cs" />
<Compile Include="MyDefs.cs" />
<Compile Include="MyGfx.cs" />
<Compile Include="NeedCondition.cs" />
<Compile Include="NoMsgRandHediffGiver.cs" />
<Compile Include="ParametersHandlingsUtils.cs" />
<Compile Include="PawnCondition.cs" />
<Compile Include="PawnCopyUtils.cs" />
<Compile Include="PawnRedressUtils.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RandomFactionParameter.cs" />
<Compile Include="RandomPicker.cs" />
<Compile Include="RandyPickerUtils.cs" />
<Compile Include="RandySpawnerUtils.cs" />
<Compile Include="RedressSettings.cs" />
<Compile Include="RequirementSettings.cs" />
<Compile Include="RequirementUtils.cs" />
<Compile Include="Restriction.cs" />
<Compile Include="RotationOffset.cs" />
<Compile Include="SpawnerUtils.cs" />
<Compile Include="SpawnRules.cs" />
<Compile Include="StackCalculator.cs" />
<Compile Include="StackSettings.cs" />
<Compile Include="TerrainRestriction.cs" />
<Compile Include="ThingRequirementSettings.cs" />
<Compile Include="ThingSettings.cs" />
<Compile Include="Tools.cs" />
<Compile Include="TracerUtils.cs" />
<Compile Include="TrailUtils.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,63 @@
using System;
using UnityEngine;
using Verse;
namespace MoharHediffs
{
public static class MoteColorChangeUtils
{
public static int GetProgressSign(float limA, float limB, float val)
{
bool flag = val <= limA && limA < limB;
int result;
if (flag)
{
result = 1;
}
else
{
bool flag2 = val >= limB && limB > limA;
if (flag2)
{
result = -1;
}
else
{
result = (Rand.Chance(0.5f) ? 1 : -1);
}
}
return result;
}
public static Color RandomPickColor(this ColorRange colorRange, Color oldColor, bool debug = false)
{
float variationPerIteration = colorRange.variationPerIteration;
float num = Rand.Range(0f, variationPerIteration);
float num2 = Rand.Range(0f, variationPerIteration - num);
float num3 = variationPerIteration - num - num2;
int progressSign = MoteColorChangeUtils.GetProgressSign(colorRange.colorA.r, colorRange.colorB.r, oldColor.r);
int progressSign2 = MoteColorChangeUtils.GetProgressSign(colorRange.colorA.g, colorRange.colorB.g, oldColor.g);
int progressSign3 = MoteColorChangeUtils.GetProgressSign(colorRange.colorA.b, colorRange.colorB.b, oldColor.b);
float num4 = Math.Abs(colorRange.colorA.r - colorRange.colorB.r) * num * (float)progressSign;
float num5 = Math.Abs(colorRange.colorA.g - colorRange.colorB.g) * num2 * (float)progressSign3;
float num6 = Math.Abs(colorRange.colorA.b - colorRange.colorB.b) * num3 * (float)progressSign2;
Color result = new Color((oldColor.r + num4).Clamp(colorRange.colorA.r, colorRange.colorB.r), (oldColor.g + num5).Clamp(colorRange.colorA.g, colorRange.colorB.g), (oldColor.b + num6).Clamp(colorRange.colorA.b, colorRange.colorB.b));
return result;
}
public static void ChangeMoteColor(this HediffComp_TrailLeaver comp, Mote mote)
{
bool flag = !comp.Props.HasColorRange || mote == null;
if (!flag)
{
bool flag2 = comp.lastColor == Color.black;
if (flag2)
{
comp.lastColor = comp.Props.colorRange.colorA;
}
comp.lastColor = comp.Props.colorRange.RandomPickColor(comp.lastColor, comp.MyDebug);
mote.instanceColor = comp.lastColor;
}
}
}
}

View File

@ -0,0 +1,33 @@
using System;
using RimWorld;
using UnityEngine;
using Verse;
namespace MoharHediffs
{
public static class MoteLink
{
public static Vector3 GetLinkOffset(this Pawn p, MoteLink.Nature linkType)
{
Vector3 result;
if (linkType != MoteLink.Nature.head)
{
if (linkType != MoteLink.Nature.body)
{
}
result = Vector3.zero;
}
else
{
result = p.Drawer.renderer.BaseHeadOffsetAt((p.GetPosture() == PawnPosture.Standing) ? Rot4.North : p.Drawer.renderer.LayingFacing()).RotatedBy(p.Drawer.renderer.BodyAngle(PawnRenderFlags.Cache));
}
return result;
}
public enum Nature
{
head,
body
}
}
}

View File

@ -0,0 +1,111 @@
using System;
using MoharGfx;
using UnityEngine;
using Verse;
namespace MoharHediffs
{
public static class MoteSpawnUtils
{
public static Thing TryMoteSpawn(this Vector3 loc, Map map, float rot, float scale, ThingDef moteDef, bool debug = false)
{
bool flag = loc.ForbiddenMote(map);
Thing result;
if (flag)
{
result = null;
}
else
{
bool flag2 = moteDef == null;
if (flag2)
{
if (debug)
{
Log.Warning("null mote");
}
result = null;
}
else
{
MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(moteDef, null);
bool flag3 = moteThrown == null;
if (flag3)
{
result = null;
}
else
{
moteThrown.Scale = scale;
moteThrown.exactRotation = rot;
moteThrown.exactPosition = loc;
result = GenSpawn.Spawn(moteThrown, loc.ToIntVec3(), map, WipeMode.Vanish);
}
}
}
return result;
}
public static Thing TryAnyMoteSpawn(this Vector3 loc, Map map, float rot, float scale, ThingDef moteDef, bool debug = false)
{
bool flag = loc.ForbiddenMote(map);
Thing result;
if (flag)
{
result = null;
}
else
{
bool flag2 = moteDef == null;
if (flag2)
{
if (debug)
{
Log.Warning("null mote");
}
result = null;
}
else
{
Type thingClass = moteDef.thingClass;
bool flag3 = thingClass == typeof(CustomTransformation_Mote);
if (flag3)
{
CustomTransformation_Mote mote = (CustomTransformation_Mote)ThingMaker.MakeThing(moteDef, null);
result = mote.FinalizeMoteSpawn(loc, map, rot, scale);
}
else
{
bool flag4 = thingClass == typeof(MoteThrown);
if (flag4)
{
MoteThrown mote2 = (MoteThrown)ThingMaker.MakeThing(moteDef, null);
result = mote2.FinalizeMoteSpawn(loc, map, rot, scale);
}
else
{
result = null;
}
}
}
}
return result;
}
public static Thing FinalizeMoteSpawn(this CustomTransformation_Mote mote, Vector3 loc, Map map, float rot, float scale)
{
mote.Scale = scale;
mote.exactRotation = rot;
mote.exactPosition = loc;
return GenSpawn.Spawn(mote, loc.ToIntVec3(), map, WipeMode.Vanish);
}
public static Thing FinalizeMoteSpawn(this MoteThrown mote, Vector3 loc, Map map, float rot, float scale)
{
mote.Scale = scale;
mote.exactRotation = rot;
mote.exactPosition = loc;
return GenSpawn.Spawn(mote, loc.ToIntVec3(), map, WipeMode.Vanish);
}
}
}

View File

@ -0,0 +1,9 @@
using System;
namespace MoharHediffs
{
public static class MyDefs
{
public static int OneYearTicks = 3600000;
}
}

View File

@ -0,0 +1,24 @@
using System;
using UnityEngine;
using Verse;
namespace MoharHediffs
{
[StaticConstructorOnStartup]
public class MyGfx
{
public static Color Purple = new Color(1f, 0f, 1f);
public static Color Blue = new Color(0f, 0f, 1f);
public static Color Cyan = new Color(0f, 1f, 1f);
public static Color Green = new Color(0f, 1f, 0f);
public static Color Yellow = new Color(1f, 1f, 0f);
public static Color Orange = new Color(1f, 0.6f, 0f);
public static Color Red = new Color(1f, 0f, 1f);
}
}

View File

@ -0,0 +1,23 @@
using System;
using RimWorld;
using Verse;
namespace MoharHediffs
{
public class NeedCondition
{
public NeedCondition(NeedCondition copyMe)
{
this.needDef = copyMe.needDef;
this.level = copyMe.level;
}
public NeedCondition()
{
}
public NeedDef needDef;
public FloatRange level;
}
}

View File

@ -0,0 +1,19 @@
using System;
using Verse;
namespace MoharHediffs
{
public class NoMsgRandHediffGiver : HediffGiver
{
public override void OnIntervalPassed(Pawn pawn, Hediff cause)
{
bool flag = Rand.MTBEventOccurs(this.mtbDays, 60000f, 60f);
if (flag)
{
base.TryApply(pawn, null);
}
}
public float mtbDays;
}
}

View File

@ -0,0 +1,96 @@
using System;
using System.Linq;
using RimWorld;
using UnityEngine;
using Verse;
namespace MoharHediffs
{
public static class ParametersHandlingsUtils
{
public static bool IsTerrainAllowed(this HediffComp_TrailLeaver comp, TerrainDef terrain)
{
bool flag = terrain == null || comp.NullMap;
bool result;
if (flag)
{
result = false;
}
else
{
bool flag2 = !comp.HasTerrainRestriction;
if (flag2)
{
result = true;
}
else
{
TerrainRestriction terrainRestriction = comp.TerrainRestriction;
bool flag3 = !terrainRestriction.allowedInWater && terrain.IsWater;
if (flag3)
{
result = false;
}
else
{
bool flag4 = terrainRestriction.HasRelevantSnowRestriction && !terrainRestriction.allowedSnowDepth.Includes(comp.MyMap.snowGrid.GetDepth(comp.Pawn.Position));
if (flag4)
{
result = false;
}
else
{
bool flag5 = terrainRestriction.HasForbiddenTerrains && terrainRestriction.forbiddenTerrains.Contains(terrain);
result = !flag5;
}
}
}
}
return result;
}
public static bool IsPawnActivityCompatible(this HediffComp_TrailLeaver comp)
{
bool flag = !comp.HasPawnRestriction;
bool result;
if (flag)
{
result = true;
}
else
{
Restriction pawnRestriction = comp.PawnRestriction;
bool flag2 = pawnRestriction.HasPostureRestriction && !pawnRestriction.allowedPostures.Contains(comp.Pawn.GetPosture());
if (flag2)
{
result = false;
}
else
{
bool flag3 = pawnRestriction.onlyWhenMoving && !comp.Pawn.pather.MovingNow;
result = !flag3;
}
}
return result;
}
public static Vector3 GetBodyTypeOffset(this HediffComp_TrailLeaver comp)
{
Pawn_StoryTracker story = comp.Pawn.story;
bool flag = ((story != null) ? story.bodyType : null) == null || !comp.Props.HasOffset;
Vector3 result;
if (flag)
{
result = comp.Props.defaultOffset;
}
else
{
BodyTypeOffset bodyTypeOffset = (from b in comp.Props.offSetPerBodyType
where b.bodyType == comp.Pawn.story.bodyType
select b).FirstOrFallback(null);
result = ((bodyTypeOffset == null) ? comp.Props.defaultOffset : bodyTypeOffset.offset);
}
return result;
}
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using Verse;
namespace MoharHediffs
{
public class PawnCondition
{
public bool HasRace
{
get
{
return !this.race.NullOrEmpty<ThingDef>();
}
}
public bool HasGender
{
get
{
return !this.gender.NullOrEmpty<Gender>();
}
}
public List<ThingDef> race;
public FloatRange ageRange = new FloatRange(0f, 999f);
public List<Gender> gender;
}
}

View File

@ -0,0 +1,344 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AlienRace;
using RimWorld;
using UnityEngine;
using Verse;
namespace MoharHediffs
{
public static class PawnCopyUtils
{
public static void SetAge(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn)
{
ThingSettings chosenItem = comp.ChosenItem;
bool flag = chosenItem.IsCopier && chosenItem.copyParent.age;
if (flag)
{
LifeStageDef LSDef = comp.Pawn.ageTracker.CurLifeStage;
LifeStageAge lifeStageAge = (from LS in comp.Pawn.def.race.lifeStageAges
where LS.def == LSDef
select LS).FirstOrFallback(null);
bool flag2 = lifeStageAge == null;
if (!flag2)
{
newPawn.ageTracker.AgeBiologicalTicks = checked((long)(unchecked(lifeStageAge.minAge * (float)MyDefs.OneYearTicks)));
newPawn.ageTracker.AgeChronologicalTicks = Math.Max(comp.Pawn.ageTracker.AgeBiologicalTicks, comp.Pawn.ageTracker.AgeChronologicalTicks);
}
}
else
{
newPawn.ageTracker.AgeBiologicalTicks = (long)(checked(MyDefs.OneYearTicks * chosenItem.biologicalAgeRange.RandomInRange));
newPawn.ageTracker.AgeChronologicalTicks = checked(unchecked((long)(checked(MyDefs.OneYearTicks * chosenItem.chronologicalAgeRange.RandomInRange))) + newPawn.ageTracker.AgeBiologicalTicks);
}
}
public static void SetName(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn)
{
bool name = comp.ChosenItem.copyParent.name;
if (name)
{
newPawn.Name = comp.Pawn.Name;
}
}
public static void SetGender(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn)
{
bool gender = comp.ChosenItem.copyParent.gender;
if (gender)
{
newPawn.gender = comp.Pawn.gender;
}
}
public static void SetMelanin(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn)
{
bool melanin = comp.ChosenItem.copyParent.melanin;
if (melanin)
{
newPawn.story.SkinColorBase = comp.Pawn.story.SkinColorBase;
}
}
public static void SetAlienSkinColor(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn)
{
AlienPartGenerator.AlienComp alienComp = comp.Pawn.TryGetComp<AlienPartGenerator.AlienComp>();
AlienPartGenerator.AlienComp alienComp2 = (newPawn != null) ? newPawn.TryGetComp<AlienPartGenerator.AlienComp>() : null;
bool flag = alienComp == null || alienComp2 == null;
if (!flag)
{
Color first = alienComp.GetChannel("skin").first;
Color second = alienComp.GetChannel("skin").second;
alienComp2.GetChannel("skin").first = first;
alienComp2.GetChannel("skin").second = second;
}
}
public static void SetAlienBodyAndHeadType(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn)
{
bool flag = !comp.Pawn.IsAlien() || !newPawn.IsAlien();
if (!flag)
{
AlienPartGenerator.AlienComp alienComp = comp.Pawn.TryGetComp<AlienPartGenerator.AlienComp>();
AlienPartGenerator.AlienComp alienComp2 = (newPawn != null) ? newPawn.TryGetComp<AlienPartGenerator.AlienComp>() : null;
bool flag2 = alienComp == null || alienComp2 == null;
if (!flag2)
{
newPawn.story.headType = comp.Pawn.story.headType;
alienComp2.headMaskVariant = alienComp.headMaskVariant;
alienComp2.headVariant = alienComp.headVariant;
newPawn.story.bodyType = comp.Pawn.story.bodyType;
alienComp2.bodyMaskVariant = alienComp.bodyMaskVariant;
alienComp2.bodyVariant = alienComp.bodyVariant;
}
}
}
public static void SetHair(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn)
{
bool hair = comp.ChosenItem.copyParent.hair;
if (hair)
{
newPawn.story.hairDef = comp.Pawn.story.hairDef;
}
}
public static void SetHairColor(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn)
{
bool hairColor = comp.ChosenItem.copyParent.hairColor;
if (hairColor)
{
newPawn.story.HairColor = comp.Pawn.story.HairColor;
}
}
public static void SetHediff(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn)
{
bool flag = !comp.ChosenItem.copyParent.hediff;
if (!flag)
{
newPawn.health.hediffSet.hediffs = new List<Hediff>();
List<Hediff> hediffs = comp.ChosenItem.copyParent.HasHediffExclusion ? (from h in comp.Pawn.health.hediffSet.hediffs.ListFullCopy<Hediff>()
where !comp.ChosenItem.copyParent.excludeHediff.Contains(h.def) && (!comp.ChosenItem.copyParent.excludeTendableHediffs || !h.def.tendable) && (!comp.ChosenItem.copyParent.excludePermanentHediffs || h.TryGetComp<HediffComp_GetsPermanent>() == null)
select h).ToList<Hediff>() : comp.Pawn.health.hediffSet.hediffs.ListFullCopy<Hediff>();
newPawn.health.hediffSet.hediffs = hediffs;
}
}
public static void SetSkills(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn, bool debug = false)
{
bool flag = !comp.ChosenItem.copyParent.skills;
checked
{
if (!flag)
{
string text = newPawn.LabelShort + " - SetSkills - ";
for (int i = 0; i < newPawn.skills.skills.Count; i++)
{
float randomInRange = comp.ChosenItem.copyParent.skillDecay.RandomInRange;
int num = (int)(unchecked((float)comp.Pawn.skills.skills[i].levelInt * randomInRange));
if (debug)
{
Log.Warning(string.Concat(new object[]
{
text,
" browsing ",
comp.Pawn.skills.skills[i].def.defName,
" ori: ",
comp.Pawn.skills.skills[i].levelInt,
" new: ",
newPawn.skills.skills[i].levelInt,
" decayRatio: ",
randomInRange,
" wantedSkill: ",
num
}));
}
bool flag2 = num > newPawn.skills.skills[i].levelInt;
if (flag2)
{
if (debug)
{
Log.Warning(text + "Calling gainskill");
}
comp.GainSkill(newPawn, num, i, debug);
}
else
{
bool flag3 = num < newPawn.skills.skills[i].levelInt;
if (flag3)
{
if (debug)
{
Log.Warning(text + "Calling loseskill");
}
comp.LoseSkill(newPawn, num, i, debug);
}
}
if (debug)
{
Log.Warning(string.Concat(new object[]
{
text,
" copied skill [",
i,
"]:",
comp.Pawn.skills.skills[i].def.defName,
" new: ",
newPawn.skills.skills[i].levelInt
}));
}
}
}
}
}
public static void GainSkill(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn, int wantedLevel, int index, bool debug = false)
{
string text = newPawn.LabelShort + " - GainSkill - ";
if (debug)
{
Log.Warning(text + "Entering");
}
int num = 20;
checked
{
while (wantedLevel > newPawn.skills.skills[index].levelInt && num > 0)
{
float xpRequiredForLevelUp = newPawn.skills.skills[index].XpRequiredForLevelUp;
if (debug)
{
Log.Warning(string.Concat(new object[]
{
text,
" loop: ",
num,
" xpInjected: ",
xpRequiredForLevelUp,
" ori: ",
comp.Pawn.skills.skills[index].levelInt,
" new: ",
newPawn.skills.skills[index].levelInt
}));
}
newPawn.skills.skills[index].Learn(xpRequiredForLevelUp, true, false);
num--;
}
}
}
public static void LoseSkill(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn, int wantedLevel, int index, bool debug = false)
{
string text = newPawn.LabelShort + " - LoseSkill - ";
if (debug)
{
Log.Warning(text + "Entering");
}
int num = 20;
checked
{
while (wantedLevel < newPawn.skills.skills[index].levelInt && num > 0)
{
float num2 = (float)(0 - newPawn.skills.skills[index].levelInt * 1000);
if (debug)
{
Log.Warning(string.Concat(new object[]
{
text,
" loop: ",
num,
" xpInjected: ",
num2,
" ori: ",
comp.Pawn.skills.skills[index].levelInt,
" new: ",
newPawn.skills.skills[index].levelInt
}));
}
newPawn.skills.skills[index].Learn(num2, true, false);
num--;
}
}
}
public static void SetPassions(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn, bool debug = false)
{
bool flag = !comp.ChosenItem.copyParent.passions;
checked
{
if (!flag)
{
for (int i = 0; i < newPawn.skills.skills.Count; i++)
{
newPawn.skills.skills[i].passion = comp.Pawn.skills.skills[i].passion;
}
}
}
}
public static void InitRememberBackstories(out BackstoryDef childBS, out BackstoryDef adultBS)
{
BackstoryDef backstoryDef;
adultBS = (backstoryDef = null);
childBS = backstoryDef;
}
public static void ResetBackstories(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn)
{
newPawn.story.Childhood = null;
newPawn.story.Adulthood = null;
}
public static void RememberBackstories(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn, out BackstoryDef childBS, out BackstoryDef adultBS)
{
childBS = newPawn.story.Childhood;
adultBS = newPawn.story.Adulthood;
}
public static void ReinjectBackstories(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn, BackstoryDef childBS, BackstoryDef adultBS)
{
newPawn.story.Childhood = childBS;
newPawn.story.Adulthood = adultBS;
}
public static void SetBackstories(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn)
{
bool childBS = comp.ChosenItem.copyParent.childBS;
if (childBS)
{
newPawn.story.Childhood = comp.Pawn.story.Childhood;
}
bool adultBS = comp.ChosenItem.copyParent.adultBS;
if (adultBS)
{
newPawn.story.Adulthood = comp.Pawn.story.Adulthood;
}
}
public static void SetTraits(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn)
{
bool flag = !comp.ChosenItem.copyParent.traits;
checked
{
if (!flag)
{
for (int i = newPawn.story.traits.allTraits.Count - 1; i >= 0; i--)
{
newPawn.story.traits.allTraits.RemoveAt(i);
}
newPawn.story.traits.allTraits = comp.Pawn.story.traits.allTraits.ListFullCopy<Trait>();
}
}
}
public static void UpdateDisabilities(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn)
{
bool flag = newPawn.skills == null;
if (!flag)
{
newPawn.skills.Notify_SkillDisablesChanged();
}
}
}
}

View File

@ -0,0 +1,63 @@
using System;
using Verse;
namespace MoharHediffs
{
public static class PawnRedressUtils
{
public static void DestroyInventory(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn)
{
bool destroyInventory = comp.ChosenItem.redressNewPawn.destroyInventory;
if (destroyInventory)
{
newPawn.inventory.innerContainer.ClearAndDestroyContents(DestroyMode.Vanish);
}
}
public static void DestroyEquipment(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn)
{
bool destroyEquipment = comp.ChosenItem.redressNewPawn.destroyEquipment;
if (destroyEquipment)
{
newPawn.equipment.DestroyAllEquipment(DestroyMode.Vanish);
}
}
public static void DestroyApparel(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn)
{
bool destroyApparel = comp.ChosenItem.redressNewPawn.destroyApparel;
if (destroyApparel)
{
newPawn.apparel.DestroyAll(DestroyMode.Vanish);
}
}
public static bool StripCorpse(this HediffComp_RandySpawnUponDeath comp, Corpse corpse)
{
bool result = false;
bool flag = comp.Props.HasParentRedress && comp.Props.redressParent.strip && !corpse.Negligible();
if (flag)
{
result = true;
bool flag2 = corpse.AnythingToStrip();
if (flag2)
{
corpse.Strip(true);
}
}
return result;
}
public static bool DestroyCorpse(this HediffComp_RandySpawnUponDeath comp, Corpse corpse)
{
bool result = false;
bool flag = comp.Props.HasParentRedress && comp.Props.redressParent.destroyCorpse && !corpse.Negligible();
if (flag)
{
result = true;
corpse.DeSpawn(DestroyMode.Vanish);
}
return result;
}
}
}

View File

@ -0,0 +1,9 @@
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
[assembly: AssemblyVersion("0.0.0.0")]
[assembly: AssemblyTitle("MoharHediffs")]
[assembly: AssemblyProduct("MoharHediffs")]

View File

@ -0,0 +1,96 @@
using System;
using RimWorld;
namespace MoharHediffs
{
public class RandomFactionParameter
{
public bool HasInheritedFaction
{
get
{
return this.inheritedFaction;
}
}
public bool HasForcedFaction
{
get
{
return this.forcedFaction != null;
}
}
public bool HasPlayerFaction
{
get
{
return this.playerFaction;
}
}
public bool HasNoFaction
{
get
{
return this.noFaction;
}
}
public bool HasDefaultPawnKindFaction
{
get
{
return this.defaultPawnKindFaction;
}
}
public bool IsLegitRandomFactionParameter()
{
int num = 0;
bool hasInheritedFaction = this.HasInheritedFaction;
checked
{
if (hasInheritedFaction)
{
num++;
}
bool hasForcedFaction = this.HasForcedFaction;
if (hasForcedFaction)
{
num++;
}
bool hasPlayerFaction = this.HasPlayerFaction;
if (hasPlayerFaction)
{
num++;
}
bool hasNoFaction = this.HasNoFaction;
if (hasNoFaction)
{
num++;
}
bool hasDefaultPawnKindFaction = this.HasDefaultPawnKindFaction;
if (hasDefaultPawnKindFaction)
{
num++;
}
return num == 1;
}
}
public bool inheritedFaction = false;
public FactionDef forcedFaction = null;
public bool playerFaction = false;
public bool defaultPawnKindFaction = false;
public bool noFaction = false;
public bool newBorn = false;
public float weight;
}
}

View File

@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Verse;
namespace MoharHediffs
{
public static class RandomPicker
{
public static List<HediffItem> GetCompatibleItems(this HediffComp_AnotherRandom comp)
{
List<HediffItem> list = new List<HediffItem>();
foreach (HediffItem hediffItem in comp.Props.hediffPool)
{
HediffCompProperties_AnotherRandom props = comp.Props;
HediffCondition defaultPlusSpecificHediffCondition = ConditionBuilder.GetDefaultPlusSpecificHediffCondition(((props != null) ? props.defaultCondition : null) ?? null, ((hediffItem != null) ? hediffItem.specificCondition : null) ?? null, comp.HighVerbosity);
BodyPartRecord bodyPartRecord;
bool flag = defaultPlusSpecificHediffCondition.HasBodypartCondition ? defaultPlusSpecificHediffCondition.bodyPart.GetBPRFromHediffCondition(comp.Pawn, out bodyPartRecord, false) : (!defaultPlusSpecificHediffCondition.HasPawnCondition || defaultPlusSpecificHediffCondition.pawn.ValidateCompatibilityOfHediffWithPawn(comp.Pawn, false));
if (flag)
{
list.Add(hediffItem);
}
}
bool flag2 = !list.NullOrEmpty<HediffItem>();
List<HediffItem> result;
if (flag2)
{
result = list;
}
else
{
result = null;
}
return result;
}
public static List<HediffItem> GetRemainingItems(this List<HediffItem> hediffItems, List<HediffItem> AlreadyPickedItems)
{
return (from hi in hediffItems
where !AlreadyPickedItems.Contains(hi)
select hi).ToList<HediffItem>();
}
public static float GetWeight(this List<HediffItem> HL)
{
float num = 0f;
foreach (HediffItem hediffItem in HL)
{
num += hediffItem.weight;
}
return num;
}
public static HediffItem PickRandomWeightedItem(this List<HediffItem> HL, bool debug = false)
{
float weight = HL.GetWeight();
float num = Rand.Range(0f, weight);
checked
{
for (int i = 0; i < HL.Count; i++)
{
bool flag = unchecked(num -= HL[i].weight) < 0f;
if (flag)
{
Tools.Warn("PickRandomWeightedItem : returning " + i, debug);
return HL[i];
}
}
return null;
}
}
}
}

View File

@ -0,0 +1,281 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AlienRace;
using UnityEngine;
using Verse;
namespace MoharHediffs
{
public static class RandyPickerUtils
{
public static float ThingsTotalWeight(this HediffComp_RandySpawnUponDeath comp, List<ThingSettings> TSList)
{
string text = comp.MyDebug ? (comp.Pawn.LabelShort + " ThingsTotalWeight ") : "";
bool myDebug = comp.MyDebug;
if (myDebug)
{
Log.Warning(text + " searching total weights thing list");
}
float num = 0f;
for (int i = 0; i < TSList.Count; i = checked(i + 1))
{
num += TSList[i].weight;
}
bool myDebug2 = comp.MyDebug;
if (myDebug2)
{
Log.Warning(text + " found: " + num);
}
return num;
}
public static bool SameColorAs(this Color colorA, Color colorB)
{
bool flag = (double)Math.Abs(colorA.r - colorB.r) < 0.01;
bool flag2 = (double)Math.Abs(colorA.g - colorB.g) < 0.01;
bool flag3 = (double)Math.Abs(colorA.b - colorB.b) < 0.01;
bool flag4 = (double)Math.Abs(colorA.a - colorB.a) < 0.01;
return flag && flag2 && flag3 && flag4;
}
public static Color PickAlienColor(this AlienPartGenerator.AlienComp a, string channelName, int channelNum)
{
return (channelNum == 1) ? a.GetChannel(channelName).first : ((channelNum == 2) ? a.GetChannel(channelName).second : Color.white);
}
public static Color PickStuffColor(this ThingDef tDef)
{
StuffProperties stuffProps = tDef.stuffProps;
bool flag;
if (stuffProps == null)
{
flag = false;
}
else
{
Color color = stuffProps.color;
flag = true;
}
bool flag2 = flag;
Color result;
if (flag2)
{
result = tDef.stuffProps.color;
}
else
{
ThingDefCountClass thingDefCountClass = tDef.butcherProducts.FirstOrDefault<ThingDefCountClass>() ?? null;
bool flag3 = thingDefCountClass == null;
if (flag3)
{
result = Color.black;
}
else
{
ThingDef thingDef = thingDefCountClass.thingDef;
bool flag4;
if (thingDef == null)
{
flag4 = true;
}
else
{
StuffProperties stuffProps2 = thingDef.stuffProps;
Color? color2 = (stuffProps2 != null) ? new Color?(stuffProps2.color) : null;
flag4 = (color2 == null);
}
bool flag5 = flag4;
if (flag5)
{
result = Color.black;
}
else
{
result = thingDef.stuffProps.color;
}
}
}
return result;
}
public static List<ThingSettings> ThingSettingsWithColor(this HediffComp_RandySpawnUponDeath comp)
{
string text = comp.MyDebug ? (comp.Pawn.LabelShort + " ThingSettingsWithColor -") : "";
bool myDebug = comp.MyDebug;
if (myDebug)
{
Log.Warning(text + " creating thing list with color");
}
bool flag = !comp.HasColorCondition || !comp.Pawn.IsAlien();
List<ThingSettings> result;
if (flag)
{
bool myDebug2 = comp.MyDebug;
if (myDebug2)
{
Log.Warning(text + "Found no color condition or pawn is not alien");
}
result = null;
}
else
{
AlienPartGenerator.AlienComp alien = Tools.GetAlien(comp.Pawn);
bool flag2 = alien == null;
if (flag2)
{
bool myDebug3 = comp.MyDebug;
if (myDebug3)
{
Log.Warning(text + "Found no AlienPartGenerator.AlienComp");
}
result = null;
}
else
{
bool myDebug4 = comp.MyDebug;
if (myDebug4)
{
Log.Warning(string.Concat(new object[]
{
text,
"colors=> skin.first:",
alien.GetChannel("skin").first,
" skin.second:",
alien.GetChannel("skin").second
}));
}
List<ThingSettings> list = (from t in comp.FullOptionList
where t.IsThingSpawner && t.HasColorCondition
select t).ToList<ThingSettings>();
bool myDebug5 = comp.MyDebug;
if (myDebug5)
{
Log.Warning("Option num:" + list.Count);
}
Color PawnColor = alien.GetChannel("skin").first;
foreach (ThingSettings thingSettings in list)
{
bool myDebug6 = comp.MyDebug;
if (myDebug6)
{
Log.Warning(string.Concat(new object[]
{
" TS.Def: ",
thingSettings.thingToSpawn.defName,
"; TS.color: ",
thingSettings.thingToSpawn.PickStuffColor(),
"; P.color: ",
PawnColor,
"; equals: ",
PawnColor.SameColorAs(thingSettings.thingToSpawn.PickStuffColor()).ToString()
}));
}
}
List<ThingSettings> list2 = new List<ThingSettings>();
list2 = (from t in comp.FullOptionList
where t.IsThingSpawner && t.HasColorCondition && PawnColor.SameColorAs(t.thingToSpawn.PickStuffColor())
select t).ToList<ThingSettings>();
bool myDebug7 = comp.MyDebug;
if (myDebug7)
{
Log.Warning(string.Concat(new object[]
{
text,
"Found ",
list2.Count,
" things with color"
}));
}
result = list2;
}
}
return result;
}
public static List<ThingSettings> ThingSettingsWithExclusion(this HediffComp_RandySpawnUponDeath comp, List<ThingSettings> TSList, List<int> AlreadyPickedOptions)
{
List<ThingSettings> list = new List<ThingSettings>();
list = comp.Props.settings.things.ListFullCopy<ThingSettings>();
foreach (int index in AlreadyPickedOptions)
{
list.RemoveAt(index);
}
return list;
}
public static int GetWeightedRandomIndex(this HediffComp_RandySpawnUponDeath comp, List<int> AlreadyPickedOptions)
{
bool flag = !comp.Props.settings.HasSomethingToSpawn;
int result;
if (flag)
{
result = -1;
}
else
{
bool hasColorCondition = comp.HasColorCondition;
List<ThingSettings> list;
if (hasColorCondition)
{
list = comp.ThingSettingsWithColor();
}
else
{
list = comp.FullOptionList;
}
bool flag2 = !AlreadyPickedOptions.NullOrEmpty<int>();
if (flag2)
{
list = comp.ThingSettingsWithExclusion(list, AlreadyPickedOptions);
}
float num = Rand.Range(0f, comp.ThingsTotalWeight(list));
int i = 0;
while (i < list.Count)
{
bool flag3 = (num -= list[i].weight) < 0f;
checked
{
if (flag3)
{
bool myDebug = comp.MyDebug;
if (myDebug)
{
Log.Warning("GetWeightedRandomIndex : returning thing " + i);
}
bool flag4 = AlreadyPickedOptions.NullOrEmpty<int>() && !comp.HasColorCondition;
if (flag4)
{
return i;
}
int num2 = comp.Props.settings.things.IndexOf(list[i]);
bool myDebug2 = comp.MyDebug;
if (myDebug2)
{
Log.Warning(string.Concat(new object[]
{
"GetWeightedRandomIndex : returning thing ",
i,
" normalized:",
num2
}));
}
return num2;
}
else
{
i++;
}
}
}
bool myDebug3 = comp.MyDebug;
if (myDebug3)
{
Log.Warning("GetWeightedRandomIndex : failed to return proper index, returning -1");
}
result = -1;
}
return result;
}
}
}

View File

@ -0,0 +1,348 @@
using System;
using System.Collections.Generic;
using System.Linq;
using RimWorld;
using Verse;
namespace MoharHediffs
{
public static class RandySpawnerUtils
{
public static float TotalWeight(this HediffComp_RandySpawner comp)
{
float num = 0f;
List<ItemParameter> itemParameters = comp.Props.itemParameters;
for (int i = 0; i < itemParameters.Count; i = checked(i + 1))
{
num += itemParameters[i].weight;
}
return num;
}
public static float TotalWeight(this List<RandomFactionParameter> RFP)
{
float num = 0f;
for (int i = 0; i < RFP.Count; i = checked(i + 1))
{
num += RFP[i].weight;
}
return num;
}
public static void ComputeRandomFaction(this HediffComp_RandySpawner comp)
{
bool hasFactionParams = comp.CurIP.HasFactionParams;
if (hasFactionParams)
{
int weightedRandomFaction = comp.GetWeightedRandomFaction();
bool flag = weightedRandomFaction == -1;
if (flag)
{
Tools.Warn("ComputeRandomFaction - found no index", comp.MyDebug);
}
else
{
comp.newBorn = comp.CurIP.randomFactionParameters[weightedRandomFaction].newBorn;
RandomFactionParameter rfp = comp.CurIP.randomFactionParameters[weightedRandomFaction];
comp.Itemfaction = comp.GetFaction(rfp);
string str = "ComputeRandomFaction - found:";
Faction itemfaction = comp.Itemfaction;
Tools.Warn(str + ((itemfaction != null) ? itemfaction.GetCallLabel() : null), comp.MyDebug);
}
}
}
public static int GetWeightedRandomIndex(this HediffComp_RandySpawner comp)
{
float num = Rand.Range(0f, comp.TotalWeight());
List<ItemParameter> itemParameters = comp.Props.itemParameters;
checked
{
for (int i = 0; i < itemParameters.Count; i++)
{
bool flag = unchecked(num -= itemParameters[i].weight) < 0f;
if (flag)
{
Tools.Warn("GetWeightedRandomIndex : returning " + i, comp.MyDebug);
return i;
}
}
Tools.Warn("GetWeightedRandomIndex : failed to return proper index, returning -1", comp.MyDebug);
return -1;
}
}
public static int GetWeightedRandomFaction(this HediffComp_RandySpawner comp)
{
bool flag = !comp.HasValidIP || !comp.CurIP.HasFactionParams;
checked
{
int result;
if (flag)
{
result = -1;
}
else
{
List<RandomFactionParameter> randomFactionParameters = comp.CurIP.randomFactionParameters;
float num = Rand.Range(0f, randomFactionParameters.TotalWeight());
for (int i = 0; i < randomFactionParameters.Count; i++)
{
bool flag2 = unchecked(num -= randomFactionParameters[i].weight) < 0f;
if (flag2)
{
Tools.Warn("GetWeightedRandomIndex : returning " + i, comp.MyDebug);
return i;
}
}
Tools.Warn("GetWeightedRandomFaction : failed to return proper index, returning -1", comp.MyDebug);
result = -1;
}
return result;
}
}
public static bool SetRequirementGraceTicks(this HediffComp_RandySpawner comp)
{
bool requiresFood = comp.RequiresFood;
bool requiresHealth = comp.RequiresHealth;
bool flag = requiresFood || requiresHealth;
checked
{
bool result;
if (flag)
{
bool flag2 = requiresFood;
if (flag2)
{
comp.hungerReset++;
}
else
{
comp.healthReset++;
}
bool hasValidIP = comp.HasValidIP;
if (hasValidIP)
{
comp.graceTicks = (int)(unchecked(comp.CurIP.graceDays.RandomInRange * 60000f));
}
result = true;
}
else
{
comp.hungerReset = (comp.healthReset = 0);
result = false;
}
return result;
}
}
public static void CheckProps(this HediffComp_RandySpawner comp)
{
bool flag = comp.Props.itemParameters.NullOrEmpty<ItemParameter>();
if (flag)
{
comp.BlockAndDestroy(comp.Pawn.Label + " props: no itemParameters - giving up", comp.MyDebug);
}
checked
{
for (int i = 0; i < comp.Props.itemParameters.Count; i++)
{
ItemParameter itemParameter = comp.Props.itemParameters[i];
bool flag2 = itemParameter.spawnCount.min > comp.spawnCountErrorLimit || itemParameter.spawnCount.max > comp.spawnCountErrorLimit;
if (flag2)
{
comp.BlockAndDestroy(comp.Pawn.Label + " props: SpawnCount is too high: >" + comp.spawnCountErrorLimit, comp.MyDebug);
break;
}
bool flag3 = itemParameter.daysB4Next.min < comp.minDaysB4NextErrorLimit;
if (flag3)
{
comp.BlockAndDestroy(string.Concat(new object[]
{
comp.Pawn.Label,
" props: minDaysB4Next is too low: ",
itemParameter.daysB4Next.min,
"<",
comp.minDaysB4NextErrorLimit
}), comp.MyDebug);
break;
}
bool flag4 = !itemParameter.ThingSpawner && !itemParameter.PawnSpawner;
if (flag4)
{
comp.BlockAndDestroy(comp.Pawn.Label + " props: not a thing nor pawn spawner bc no def for either", comp.MyDebug);
break;
}
bool hasFactionParams = itemParameter.HasFactionParams;
if (hasFactionParams)
{
foreach (RandomFactionParameter randomFactionParameter in itemParameter.randomFactionParameters)
{
bool flag5 = !randomFactionParameter.IsLegitRandomFactionParameter();
if (flag5)
{
comp.BlockAndDestroy(comp.Pawn.Label + " faction props: invalid faction params", comp.MyDebug);
return;
}
}
}
}
}
}
public static void DumpProps(this HediffComp_RandySpawner comp)
{
Tools.Warn(string.Concat(new string[]
{
"hungerRelative: ",
comp.Props.hungerRelative.ToString(),
"; healthRelative: ",
comp.Props.healthRelative.ToString(),
"; "
}), comp.MyDebug);
checked
{
for (int i = 0; i < comp.Props.itemParameters.Count; i++)
{
ItemParameter itemParameter = comp.Props.itemParameters[i];
itemParameter.LogParams(comp.MyDebug);
}
}
}
public static bool TryFindSpawnCell(this HediffComp_RandySpawner comp, out IntVec3 result)
{
Pawn pawn = comp.Pawn;
ThingDef thingToSpawn = comp.CurIP.thingToSpawn;
bool flag = pawn.Negligible();
checked
{
bool result2;
if (flag)
{
result = IntVec3.Invalid;
Tools.Warn("TryFindSpawnCell Null - pawn null", comp.MyDebug);
result2 = false;
}
else
{
foreach (IntVec3 intVec in GenAdj.CellsAdjacent8Way(pawn).InRandomOrder(null))
{
bool flag2 = intVec.Walkable(pawn.Map);
if (flag2)
{
Building edifice = intVec.GetEdifice(pawn.Map);
bool flag3 = edifice == null || !thingToSpawn.IsEdifice();
if (flag3)
{
Building_Door building_Door;
bool flag4 = (building_Door = (edifice as Building_Door)) == null || building_Door.FreePassage;
if (flag4)
{
bool flag5 = GenSight.LineOfSight(pawn.Position, intVec, pawn.Map, false, null, 0, 0);
if (flag5)
{
bool flag6 = false;
List<Thing> thingList = intVec.GetThingList(pawn.Map);
for (int i = 0; i < thingList.Count; i++)
{
Thing thing = thingList[i];
bool flag7 = thing.def.category == ThingCategory.Item;
if (flag7)
{
bool flag8 = thing.def != thingToSpawn || thing.stackCount > thingToSpawn.stackLimit - comp.calculatedQuantity;
if (flag8)
{
flag6 = true;
break;
}
}
}
bool flag9 = !flag6;
if (flag9)
{
result = intVec;
return true;
}
}
}
}
}
}
Tools.Warn("TryFindSpawnCell Null - no spawn cell found", comp.MyDebug);
result = IntVec3.Invalid;
result2 = false;
}
return result2;
}
}
public static Faction GetFaction(this HediffComp_RandySpawner comp, RandomFactionParameter RFP)
{
FactionDef fDef = comp.GetFactionDef(RFP);
bool flag = fDef == null;
Faction result;
if (flag)
{
result = null;
}
else
{
result = (from F in Find.FactionManager.AllFactions
where F.def == fDef
select F).FirstOrFallback(null);
}
return result;
}
public static FactionDef GetFactionDef(this HediffComp_RandySpawner comp, RandomFactionParameter RFP)
{
Pawn pawn = comp.Pawn;
bool hasInheritedFaction = RFP.HasInheritedFaction;
FactionDef result;
if (hasInheritedFaction)
{
result = pawn.Faction.def;
}
else
{
bool hasForcedFaction = RFP.HasForcedFaction;
if (hasForcedFaction)
{
result = RFP.forcedFaction;
}
else
{
bool hasPlayerFaction = RFP.HasPlayerFaction;
if (hasPlayerFaction)
{
result = Faction.OfPlayerSilentFail.def;
}
else
{
bool hasNoFaction = RFP.HasNoFaction;
if (hasNoFaction)
{
result = null;
}
else
{
bool hasDefaultPawnKindFaction = RFP.HasDefaultPawnKindFaction;
if (hasDefaultPawnKindFaction)
{
PawnKindDef pawnKindToSpawn = comp.CurIP.pawnKindToSpawn;
result = (((pawnKindToSpawn != null) ? pawnKindToSpawn.defaultFactionType : null) ?? null);
}
else
{
result = null;
}
}
}
}
}
return result;
}
}
}

View File

@ -0,0 +1,17 @@
using System;
namespace MoharHediffs
{
public class RedressSettings
{
public bool destroyApparel = false;
public bool destroyEquipment = false;
public bool destroyInventory = false;
public bool strip = false;
public bool destroyCorpse = false;
}
}

View File

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using Verse;
namespace MoharHediffs
{
public class RequirementSettings
{
public bool HasHediffRequirement
{
get
{
bool result;
if (!this.hediff.NullOrEmpty<HediffRequirementSettings>())
{
result = this.hediff.Any((HediffRequirementSettings h) => h.HasHediffDef);
}
else
{
result = false;
}
return result;
}
}
public bool HasThingRequirement
{
get
{
bool result;
if (!this.thing.NullOrEmpty<ThingRequirementSettings>())
{
result = this.thing.Any((ThingRequirementSettings t) => t.HasThingDef);
}
else
{
result = false;
}
return result;
}
}
public bool HasAtLeastOneRequirementSetting
{
get
{
return this.HasHediffRequirement || this.HasThingRequirement;
}
}
public bool HasContainerSpawn
{
get
{
bool result;
if (this.HasThingRequirement)
{
result = this.thing.Any((ThingRequirementSettings t) => t.HasContainerSpawn);
}
else
{
result = false;
}
return result;
}
}
public List<HediffRequirementSettings> hediff;
public List<ThingRequirementSettings> thing;
}
}

View File

@ -0,0 +1,177 @@
using System;
using System.Collections.Generic;
using System.Linq;
using RimWorld;
using Verse;
namespace MoharHediffs
{
public static class RequirementUtils
{
public static bool FulfilsSeverityRequirement(this HediffComp_RandySpawnUponDeath comp)
{
string text = comp.MyDebug ? (comp.Pawn.LabelShort + " FulfilsSeverityRequirement - ") : "";
bool myDebug = comp.MyDebug;
if (myDebug)
{
Log.Warning(text + "Entering");
}
bool flag = comp.Pawn == null || !comp.HasHediffRequirement;
bool result;
if (flag)
{
bool myDebug2 = comp.MyDebug;
if (myDebug2)
{
Log.Warning(text + " null pawn or no requirement");
}
result = false;
}
else
{
bool flag2 = true;
using (List<HediffRequirementSettings>.Enumerator enumerator = comp.Props.requirements.hediff.GetEnumerator())
{
while (enumerator.MoveNext())
{
HediffRequirementSettings HRS = enumerator.Current;
bool flag3 = HRS.hediffDef == null;
if (!flag3)
{
IEnumerable<Hediff> enumerable = from h in comp.Pawn.health.hediffSet.hediffs
where h.def == HRS.hediffDef && h.Severity >= HRS.severity.min && h.Severity <= HRS.severity.max
select h;
bool flag4 = !enumerable.EnumerableNullOrEmpty<Hediff>();
flag2 = (flag2 && flag4);
bool flag5 = !flag4;
if (flag5)
{
bool myDebug3 = comp.MyDebug;
if (myDebug3)
{
Log.Warning(text + " did not find " + HRS.hediffDef);
}
return false;
}
}
}
}
result = flag2;
}
return result;
}
public static bool FulfilsThingRequirement(this HediffComp_RandySpawnUponDeath comp, Corpse corpse, out Thing closestThing)
{
RequirementUtils.<>c__DisplayClass1_0 CS$<>8__locals1 = new RequirementUtils.<>c__DisplayClass1_0();
CS$<>8__locals1.corpse = corpse;
string text = comp.MyDebug ? (comp.Pawn.LabelShort + " FulfilsThingRequirement - ") : "";
bool myDebug = comp.MyDebug;
if (myDebug)
{
Log.Warning(text + "Entering");
}
closestThing = null;
bool flag = CS$<>8__locals1.corpse.Negligible() || !comp.HasThingRequirement;
bool result;
if (flag)
{
bool myDebug2 = comp.MyDebug;
if (myDebug2)
{
Log.Warning(text + " negligeable corpse or no requirement");
}
result = false;
}
else
{
bool flag2 = true;
using (List<ThingRequirementSettings>.Enumerator enumerator = comp.Props.requirements.thing.GetEnumerator())
{
while (enumerator.MoveNext())
{
RequirementUtils.<>c__DisplayClass1_1 CS$<>8__locals2 = new RequirementUtils.<>c__DisplayClass1_1();
CS$<>8__locals2.CS$<>8__locals1 = CS$<>8__locals1;
CS$<>8__locals2.TRS = enumerator.Current;
bool flag3 = CS$<>8__locals2.TRS.thingDef == null;
if (!flag3)
{
CompRefuelable fuelComp = null;
CompPowerTrader powerComp = null;
IEnumerable<Thing> enumerable = from t in Find.CurrentMap.spawnedThings
where t.def == CS$<>8__locals2.TRS.thingDef && t.Position.DistanceTo(CS$<>8__locals2.CS$<>8__locals1.corpse.Position) <= CS$<>8__locals2.TRS.distance.max && t.Position.DistanceTo(CS$<>8__locals2.CS$<>8__locals1.corpse.Position) >= CS$<>8__locals2.TRS.distance.min && (!CS$<>8__locals2.TRS.sameFaction || CS$<>8__locals2.CS$<>8__locals1.corpse.InnerPawn.Faction == t.Faction) && (!CS$<>8__locals2.TRS.needsFueled || ((fuelComp = t.TryGetComp<CompRefuelable>()) != null && fuelComp.HasFuel)) && (!CS$<>8__locals2.TRS.needsPowered || ((powerComp = t.TryGetComp<CompPowerTrader>()) != null && powerComp.PowerOn))
select t;
bool flag4 = !enumerable.EnumerableNullOrEmpty<Thing>();
bool flag5 = flag4 && (CS$<>8__locals2.TRS.spawnClose || CS$<>8__locals2.TRS.spawnInside);
if (flag5)
{
IEnumerable<Thing> source = enumerable;
Func<Thing, float> selector;
if ((selector = CS$<>8__locals2.CS$<>8__locals1.<>9__1) == null)
{
selector = (CS$<>8__locals2.CS$<>8__locals1.<>9__1 = ((Thing t) => t.Position.DistanceTo(CS$<>8__locals2.CS$<>8__locals1.corpse.Position)));
}
closestThing = source.MinBy(selector);
}
flag2 = (flag2 && flag4);
bool flag6 = !flag4;
if (flag6)
{
bool myDebug3 = comp.MyDebug;
if (myDebug3)
{
Log.Warning(text + " did not find " + CS$<>8__locals2.TRS.thingDef);
}
return false;
}
}
}
}
result = flag2;
}
return result;
}
public static bool FulfilsRequirement(this HediffComp_RandySpawnUponDeath comp, out Thing closestThing)
{
closestThing = null;
bool flag = !comp.HasRequirement;
bool result;
if (flag)
{
result = true;
}
else
{
bool flag2 = comp.HasHediffRequirement && !comp.FulfilsSeverityRequirement();
if (flag2)
{
bool myDebug = comp.MyDebug;
if (myDebug)
{
Log.Warning("hediff requirements not fulfiled");
}
result = false;
}
else
{
bool flag3 = comp.HasThingRequirement && !comp.FulfilsThingRequirement(comp.Pawn.Corpse, out closestThing);
if (flag3)
{
bool myDebug2 = comp.MyDebug;
if (myDebug2)
{
Log.Warning("thing requirements not fulfiled");
}
result = false;
}
else
{
result = true;
}
}
}
return result;
}
}
}

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using RimWorld;
using Verse;
namespace MoharHediffs
{
public class Restriction
{
public bool HasTerrainRestriction
{
get
{
return this.terrain != null;
}
}
public bool HasPostureRestriction
{
get
{
return !this.allowedPostures.NullOrEmpty<PawnPosture>();
}
}
public bool onlyWhenMoving = true;
public List<PawnPosture> allowedPostures;
public TerrainRestriction terrain;
}
}

View File

@ -0,0 +1,13 @@
using System;
using UnityEngine;
using Verse;
namespace MoharHediffs
{
public class RotationOffset
{
public Rot4 rot;
public Vector3 offset;
}
}

View File

@ -0,0 +1,20 @@
using System;
using Verse;
namespace MoharHediffs
{
public class SpawnRules
{
public bool IsUnlimited
{
get
{
return this.spawnedMax <= 0;
}
}
public int spawnedMax = 2;
public IntRange period = new IntRange(15, 25);
}
}

View File

@ -0,0 +1,372 @@
using System;
using System.Collections.Generic;
using RimWorld;
using Verse;
namespace MoharHediffs
{
public static class SpawnerUtils
{
public static bool TrySpawnPawn(this HediffComp_RandySpawnUponDeath comp, Thing refThing, int randomQuantity)
{
string text = comp.MyDebug ? (comp.Pawn.LabelShort + " TrySpawnPawn ") : "";
ThingSettings chosenItem = comp.ChosenItem;
IntVec3 position = refThing.Position;
Map map = refThing.Map;
PawnKindDef pawnOfChoice = comp.PawnOfChoice;
PawnGenerationRequest request = chosenItem.newBorn ? new PawnGenerationRequest(pawnOfChoice, comp.RandomFaction, PawnGenerationContext.NonPlayer, -1, false, false, false, true, false, 0f, false, true, false, false, false, false, false, false, false, 0f, 0f, null, 0f, null, null, null, null, null, new float?(0f), new float?(0f), null, null, null, null, null, false, false, false, false, null, null, null, null, null, 0f, DevelopmentalStage.Adult, null, null, null, false, false, false, -1, 0, false) : new PawnGenerationRequest(pawnOfChoice, comp.RandomFaction, PawnGenerationContext.NonPlayer, -1, false, false, false, true, false, 0f, false, true, false, false, false, false, false, false, false, 0f, 0f, null, 0f, null, null, null, null, null, null, null, null, null, null, null, null, false, false, false, false, null, null, null, null, null, 0f, DevelopmentalStage.Adult, null, null, null, false, false, false, -1, 0, false);
checked
{
for (int i = 0; i < randomQuantity; i++)
{
Pawn pawn = PawnGenerator.GeneratePawn(request);
comp.SetAge(pawn);
bool isCopier = chosenItem.IsCopier;
if (isCopier)
{
comp.SetName(pawn);
comp.SetGender(pawn);
comp.SetMelanin(pawn);
comp.SetAlienSkinColor(pawn);
comp.SetAlienBodyAndHeadType(pawn);
comp.SetHair(pawn);
comp.SetHairColor(pawn);
comp.SetHediff(pawn);
BackstoryDef backstoryDef;
BackstoryDef backstoryDef2;
PawnCopyUtils.InitRememberBackstories(out backstoryDef, out backstoryDef2);
bool flag = comp.ChosenItem.copyParent.passions || comp.ChosenItem.copyParent.traits;
if (flag)
{
comp.RememberBackstories(pawn, out backstoryDef, out backstoryDef2);
comp.ResetBackstories(pawn);
comp.SetPassions(pawn, false);
comp.SetSkills(pawn, false);
comp.SetTraits(pawn);
}
bool flag2 = backstoryDef != null || backstoryDef2 != null;
if (flag2)
{
comp.ReinjectBackstories(pawn, backstoryDef, backstoryDef2);
}
comp.SetBackstories(pawn);
comp.UpdateDisabilities(pawn);
}
bool isRedresser = chosenItem.IsRedresser;
if (isRedresser)
{
comp.DestroyApparel(pawn);
comp.DestroyEquipment(pawn);
comp.DestroyInventory(pawn);
}
bool hasContainerSpawn = comp.HasContainerSpawn;
if (hasContainerSpawn)
{
Building_Casket building_Casket;
bool flag3 = (building_Casket = (refThing as Building_Casket)) != null;
if (flag3)
{
bool flag4 = !building_Casket.TryAcceptThing(pawn, true);
if (flag4)
{
bool myDebug = comp.MyDebug;
if (myDebug)
{
Log.Warning(string.Concat(new string[]
{
text,
" tried to add ",
pawn.LabelShort,
" to ",
refThing.Label,
", but failed"
}));
}
}
}
}
else
{
GenSpawn.Spawn(pawn, position, map, WipeMode.Vanish);
}
bool hasMentalStateParams = comp.ChosenItem.HasMentalStateParams;
if (hasMentalStateParams)
{
comp.ComputeRandomMentalState();
bool flag5 = comp.RandomMS != null;
if (flag5)
{
pawn.mindState.mentalStateHandler.TryStartMentalState(comp.RandomMS, null, false, false, false, null, true, false, false);
}
}
comp.TrySpawnAllFilth(refThing, false);
bool myDebug2 = comp.MyDebug;
if (myDebug2)
{
Log.Warning("------------------");
}
}
return true;
}
}
public static void TrySpawnAllFilth(this HediffComp_RandySpawnUponDeath comp, Thing refThing, bool debug = false)
{
if (debug)
{
Log.Warning(comp.Pawn.LabelShort + " - TrySpawnAllFilth");
}
bool flag = !comp.HasFilth;
checked
{
if (flag)
{
if (debug)
{
Log.Warning("no filth found");
}
}
else
{
int randomInRange = comp.FilthNum.RandomInRange;
for (int i = 0; i < randomInRange; i++)
{
if (debug)
{
Log.Warning(string.Concat(new object[]
{
"filth ",
i,
"/",
randomInRange,
" - fDef:",
comp.FilthToSpawn,
" - pos:",
refThing.Position,
" - map null?",
(refThing.Map == null).ToString()
}));
}
SpawnerUtils.TrySpawnFilth(refThing, comp.FilthRadius.RandomInRange, comp.FilthToSpawn);
}
}
}
}
public static void TrySpawnFilth(Thing refT, float filthRadius, ThingDef filthDef)
{
IntVec3 c;
bool flag;
if (refT.Map != null)
{
flag = CellFinder.TryFindRandomReachableNearbyCell(refT.Position, refT.Map, filthRadius, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false, false, false), (IntVec3 x) => x.Standable(refT.Map), (Region x) => true, out c, 999999);
}
else
{
flag = false;
}
bool flag2 = flag;
if (flag2)
{
FilthMaker.TryMakeFilth(c, refT.Map, filthDef, 1, FilthSourceFlags.None, true);
}
}
public static bool TrySpawnThing(this HediffComp_RandySpawnUponDeath comp, Thing thing, int randomQuantity)
{
Map map = thing.Map;
bool flag = comp.Props.spawnMaxAdjacent >= 0;
checked
{
if (flag)
{
int num = 0;
for (int i = 0; i < 9; i++)
{
IntVec3 c = thing.Position + GenAdj.AdjacentCellsAndInside[i];
bool flag2 = !c.InBounds(map);
if (!flag2)
{
List<Thing> thingList = c.GetThingList(map);
for (int j = 0; j < thingList.Count; j++)
{
bool flag3 = thingList[j].def == comp.ChosenItem.thingToSpawn;
if (flag3)
{
num += thingList[j].stackCount;
bool flag4 = num >= comp.Props.spawnMaxAdjacent;
if (flag4)
{
return false;
}
}
}
}
}
}
int k = 0;
int num2 = randomQuantity;
int num3 = 0;
while (k < randomQuantity)
{
IntVec3 intVec;
bool flag5 = comp.TryFindSpawnCell(thing, randomQuantity, map, out intVec);
if (flag5)
{
Thing thing2 = ThingMaker.MakeThing(comp.ChosenItem.thingToSpawn, null);
thing2.stackCount = num2;
bool flag6 = thing2.def.stackLimit > 0;
if (flag6)
{
bool flag7 = thing2.stackCount > thing2.def.stackLimit;
if (flag7)
{
thing2.stackCount = thing2.def.stackLimit;
}
}
k += thing2.stackCount;
num2 -= thing2.stackCount;
Thing t;
GenPlace.TryPlaceThing(thing2, intVec, map, ThingPlaceMode.Direct, ref t, null, null, default(Rot4));
bool spawnForbidden = comp.Props.spawnForbidden;
if (spawnForbidden)
{
t.SetForbidden(true, true);
}
}
bool flag8 = num3++ > 10;
if (flag8)
{
bool myDebug = comp.MyDebug;
if (myDebug)
{
Log.Warning("Had to break the loop");
}
return false;
}
}
return num2 <= 0;
}
}
public static bool TryDoSpawn(this HediffComp_RandySpawnUponDeath comp, Thing thing, int randomQuantity)
{
bool flag = thing.Negligible();
bool result;
if (flag)
{
bool myDebug = comp.MyDebug;
if (myDebug)
{
Log.Warning("TryDoSpawn - negligeable");
}
result = false;
}
else
{
bool hasChosenPawn = comp.HasChosenPawn;
if (hasChosenPawn)
{
bool myDebug2 = comp.MyDebug;
if (myDebug2)
{
Log.Warning("TryDoSpawn -> TrySpawnPawn");
}
result = comp.TrySpawnPawn(thing, randomQuantity);
}
else
{
bool hasChosenThing = comp.HasChosenThing;
if (hasChosenThing)
{
bool myDebug3 = comp.MyDebug;
if (myDebug3)
{
Log.Warning("TryDoSpawn -> TrySpawnPawn");
}
result = comp.TrySpawnThing(thing, randomQuantity);
}
else
{
result = false;
}
}
}
return result;
}
public static bool TryFindSpawnCell(this HediffComp_RandySpawnUponDeath comp, Thing refThing, int randomQuantity, Map map, out IntVec3 result)
{
ThingDef thingToSpawn = comp.ChosenItem.thingToSpawn;
bool flag = refThing.Negligible();
checked
{
bool result2;
if (flag)
{
result = IntVec3.Invalid;
bool myDebug = comp.MyDebug;
if (myDebug)
{
Log.Warning("TryFindSpawnCell Null - pawn null");
}
result2 = false;
}
else
{
foreach (IntVec3 intVec in GenAdj.CellsAdjacent8Way(refThing).InRandomOrder(null))
{
bool flag2 = intVec.Walkable(map);
if (flag2)
{
Building edifice = intVec.GetEdifice(map);
bool flag3 = edifice == null || !thingToSpawn.IsEdifice();
if (flag3)
{
Building_Door building_Door;
bool flag4 = (building_Door = (edifice as Building_Door)) == null || building_Door.FreePassage;
if (flag4)
{
bool flag5 = GenSight.LineOfSight(refThing.Position, intVec, map, false, null, 0, 0);
if (flag5)
{
bool flag6 = false;
List<Thing> thingList = intVec.GetThingList(map);
for (int i = 0; i < thingList.Count; i++)
{
Thing thing = thingList[i];
bool flag7 = thing.def.category == ThingCategory.Item;
if (flag7)
{
bool flag8 = thing.def != thingToSpawn || thing.stackCount > thingToSpawn.stackLimit - randomQuantity;
if (flag8)
{
flag6 = true;
break;
}
}
}
bool flag9 = !flag6;
if (flag9)
{
result = intVec;
return true;
}
}
}
}
}
}
bool myDebug2 = comp.MyDebug;
if (myDebug2)
{
Log.Warning("TryFindSpawnCell Null - no spawn cell found");
}
result = IntVec3.Invalid;
result2 = false;
}
return result2;
}
}
}
}

View File

@ -0,0 +1,49 @@
using System;
using RimWorld;
using Verse;
namespace MoharHediffs
{
public static class StackCalculator
{
public static float CompletudeRatio(this Pawn pawn, bool myDebug = false)
{
float statValue = pawn.GetStatValue(StatDefOf.MeatAmount, true, -1);
float statValueFromList = pawn.def.statBases.GetStatValueFromList(StatDefOf.MeatAmount, 75f);
bool flag = statValueFromList == 0f;
float num;
if (flag)
{
num = pawn.health.summaryHealth.SummaryHealthPercent;
}
else
{
num = statValue / statValueFromList;
}
if (myDebug)
{
Log.Warning(string.Concat(new object[]
{
"pawnWeightedMeat:",
statValue,
"; pawnBasisMeat:",
statValueFromList,
"=> ratio:",
num
}));
}
return num;
}
public static int ComputeSpawnCount(this HediffComp_RandySpawnUponDeath comp)
{
float num = (float)comp.NumberToSpawn;
bool weightedSpawn = comp.WeightedSpawn;
if (weightedSpawn)
{
num *= comp.Pawn.CompletudeRatio(false);
}
return checked((int)num);
}
}
}

Some files were not shown because too many files have changed in this diff Show More