Skip to content

Commit

Permalink
negative consequences for overdrive module
Browse files Browse the repository at this point in the history
  • Loading branch information
rheirman committed Mar 29, 2019
1 parent 2b1d4ad commit 9fd573a
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 10 deletions.
Binary file modified Assemblies/WhatTheHack.dll
Binary file not shown.
36 changes: 36 additions & 0 deletions Defs/HediffDefs/Hediffs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,42 @@
</modExtensions>
</HediffDef>

<HediffDef>
<defName>WTH_Overdrive_GoneTooFar</defName>
<hediffClass>HediffWithComps</hediffClass>
<isBad>true</isBad>
<label>overdriving too much</label>
<maxSeverity>1.0</maxSeverity>
<comps>
<li Class="HediffCompProperties_SeverityPerDay">
<severityPerDay>-12</severityPerDay>
</li>
<li Class="HediffCompProperties_Effecter">
<stateEffecter>WTH_Overdrive</stateEffecter>
</li>
</comps>
<stages>
<li>
<capMods>
<li>
<capacity>Moving</capacity>
<offset>2.0</offset>
</li>
<li>
<capacity>Consciousness</capacity>
<offset>-0.2</offset>
</li>
</capMods>
</li>
</stages>
<modExtensions>
<li Class="WhatTheHack.DefModExtension_Hediff">
<firingRateOffset>-1</firingRateOffset>
<powerRateOffset>15</powerRateOffset>
</li>
</modExtensions>
</HediffDef>

<HediffDef>
<defName>WTH_RepairModule</defName>
<label>repair module</label>
Expand Down
5 changes: 3 additions & 2 deletions Defs/JobDefs/Jobs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@
<JobDef>
<defName>WTH_Ability_Overdrive</defName>
<reportString>Using overdrive ability</reportString>
<driverClass>WhatTheHack.Jobs.JobDriver_MechanoidAbility</driverClass>
<driverClass>WhatTheHack.Jobs.JobDriver_MechanoidAbility_Overdrive</driverClass>
<casualInterruptible>false</casualInterruptible>
<modExtensions>
<li Class="WhatTheHack.DefModExtension_Ability">
<warmupTicks>150</warmupTicks>
<powerDrain>10</powerDrain>
<powerDrain>30</powerDrain>
<hediffSelf>WTH_Overdrive</hediffSelf>
<failChance>0.15</failChance>
</li>
</modExtensions>
</JobDef>
Expand Down
6 changes: 5 additions & 1 deletion Languages/English/Keyed/WhatTheHack_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,11 @@ You can repeat this operation as many times as needed as a means to get more mec
<WTH_Explanation_PowerFromFuel>Power from fuel</WTH_Explanation_PowerFromFuel>
<WTH_Explanation_ConsumptionRate>Consumption rate of platform</WTH_Explanation_ConsumptionRate>
<WTH_Explanation_RepairConsumptionModifier>Repair consumption modifier (set in mod settings)</WTH_Explanation_RepairConsumptionModifier>

<WTH_Letter_OverdriveFailed1_Description>Something snapped in the head of the mechanoid named {0} due to its overdrive module overdriving past hardware safety limits and causing short-circuits instead of overdriving the mechanoid. Urgent maintenance is needed.</WTH_Letter_OverdriveFailed1_Description>
<WTH_Letter_MediumMaintenanceDamage_Label>Hardware hack damaged</WTH_Letter_MediumMaintenanceDamage_Label>
<WTH_Letter_MediumMaintenanceDamage_Description>To overdrive module pushed the hardware limits of the mechanoid named {0} slightly too far, possibly damaging the hardware hacks performed on the mechanoid instead of overdriving it. Maintenance is needed soon.</WTH_Letter_MediumMaintenanceDamage_Description>
<WTH_Letter_OverdiveGoneTooFar_Label>Overdrive gone too far</WTH_Letter_OverdiveGoneTooFar_Label>
<WTH_Letter_OverdiveGoneTooFar_Description>As an unintended side effect of the high currents drawn by the overdrive module of the mechanoid named {0}, the overdrive module itself is actually overdriving! The module has a much greater effect than intended, though it also drains insane amounts of power. This can be dangerous for mechanoids with damaged internals.</WTH_Letter_OverdiveGoneTooFar_Description>
<!-- end added in v1.2 -->


Expand Down
4 changes: 0 additions & 4 deletions Patches/WhatTheHack.xml
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,6 @@
<Operation Class="PatchOperationAddModExtension">
<xpath>Defs/ThingDef[defName = "Mech_Centipede"]</xpath>
<value>
<!--In vanilla, centipedes always die due to the damagethreshold before being downed. This patch makes sure they are downed quicker-->
<li Class="WhatTheHack.DefModExtension_PawnCapacity">
<minForCapableMoving>0.38</minForCapableMoving>
</li>
<!--Cmon, centipedes should be able to carry more than 70-ish kilos -->
<li Class="WhatTheHack.DefModExtension_PawnMassCapacity">
<bonusMassCapacity>85</bonusMassCapacity>
Expand Down
2 changes: 1 addition & 1 deletion Source/WhatTheHack/Harmony/Pawn_JobTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private static void HackedPoorlyEvent(Pawn pawn)
{
Random rand = new Random(DateTime.Now.Millisecond);
int rndInt = rand.Next(1, 1000);
if (rndInt <= 5) //TODO: no magic number
if (rndInt <= 4) //TODO: no magic number
{
Need_Maintenance need = pawn.needs.TryGetNeed<Need_Maintenance>();
need.CurLevel = 0;
Expand Down
13 changes: 11 additions & 2 deletions Source/WhatTheHack/Jobs/JobDriver_MechanoidAbility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace WhatTheHack.Jobs
{
class JobDriver_MechanoidAbility : JobDriver
public class JobDriver_MechanoidAbility : JobDriver
{
public bool finished = false;
public override bool TryMakePreToilReservations(bool errorOnFailed)
Expand Down Expand Up @@ -49,7 +49,7 @@ protected override IEnumerable<Toil> MakeNewToils()
}
}

private void PerformAbility(DefModExtension_Ability modExt)
protected virtual void PerformAbility(DefModExtension_Ability modExt)
{
if (modExt.fuelDrain > 0 && pawn.TryGetComp<CompRefuelable>() is CompRefuelable refuelableComp)
{
Expand All @@ -59,6 +59,11 @@ private void PerformAbility(DefModExtension_Ability modExt)
{
powerNeed.CurLevel -= modExt.powerDrain;
}
if (Rand.Chance(modExt.failChance))
{
FailAbility(modExt);
return;
}
if (modExt.hediffSelf != null)
{
pawn.health.AddHediff(modExt.hediffSelf);
Expand All @@ -68,5 +73,9 @@ private void PerformAbility(DefModExtension_Ability modExt)
pawn.health.AddHediff(modExt.hediffTarget);
}
}
protected virtual void FailAbility(DefModExtension_Ability modExt)
{

}
}
}
71 changes: 71 additions & 0 deletions Source/WhatTheHack/Jobs/JobDriver_MechanoidAbility_Overdrive.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Verse;
using WhatTheHack.Needs;

namespace WhatTheHack.Jobs
{
public class JobDriver_MechanoidAbility_Overdrive : JobDriver_MechanoidAbility
{
protected override void FailAbility(DefModExtension_Ability modExt)
{
base.FailAbility(modExt);
Action[] actions = { this.GoneTooFar, this.MediumMaintenanceDamage, this.HighMaintenanceDamage};
List<Action> actionsList = actions.ToList();
Action action = actionsList.RandomElement();
action.Invoke();
}
private void GoneTooFar()
{
pawn.health.AddHediff(WTH_DefOf.WTH_Overdrive_GoneTooFar);
if(pawn.Faction == Faction.OfPlayer)
{
Find.LetterStack.ReceiveLetter("WTH_Letter_OverdiveGoneTooFar_Label".Translate(), "WTH_Letter_OverdiveGoneTooFar_Description".Translate(new object[] { pawn.Name.ToStringShort }), LetterDefOf.NeutralEvent, pawn);
}

}
private void MediumMaintenanceDamage()
{
Need_Maintenance need = pawn.needs.TryGetNeed<Need_Maintenance>();
if(need == null)
{
return;
}
if (need.CurLevel > 25)
{
need.CurLevel = 25;
}
else
{
return;
}
if(pawn.Faction == Faction.OfPlayer)
{
Find.LetterStack.ReceiveLetter("WTH_Letter_MediumMaintenanceDamage_Label".Translate(), "WTH_Letter_MediumMaintenanceDamage_Description".Translate(new object[] { pawn.Name.ToStringShort }), LetterDefOf.NegativeEvent, pawn);
}
}
private void HighMaintenanceDamage()
{
Need_Maintenance need = pawn.needs.TryGetNeed<Need_Maintenance>();
if (need == null)
{
return;
}
if (need.CurLevel > 5)
{
need.CurLevel = 5;
}
else
{
return;
}
if(pawn.Faction == Faction.OfPlayer)
{
Find.LetterStack.ReceiveLetter("WTH_Letter_HackedPoorlyEvent_Label".Translate(), "WTH_Letter_HighMaintenanceDamage_Description".Translate(new object[] { pawn.Name.ToStringShort }), LetterDefOf.ThreatBig, pawn);
}
}
}
}
1 change: 1 addition & 0 deletions Source/WhatTheHack/ModExtension/DefModExtension_Ability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class DefModExtension_Ability : DefModExtension
public int warmupTicks = 0;
public float powerDrain = 0f;
public float fuelDrain = 0f;
public float failChance = 0f;
public HediffDef hediffSelf;
public HediffDef hediffTarget;
}
Expand Down
2 changes: 2 additions & 0 deletions Source/WhatTheHack/WTH_DefOf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class WTH_DefOf
public static HediffDef WTH_OverdriveModule;
public static HediffDef WTH_ArmorModule;
public static HediffDef WTH_Overdrive;
public static HediffDef WTH_Overdrive_GoneTooFar;

public static HediffDef WTH_DestroyedModule;


Expand Down
1 change: 1 addition & 0 deletions Source/WhatTheHack/WhatTheHack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<Compile Include="Harmony\Pawn_SkillTracker.cs" />
<Compile Include="Harmony\ThingDef.cs" />
<Compile Include="Jobs\Depricated\JobDriver_Ability.cs" />
<Compile Include="Jobs\JobDriver_MechanoidAbility_Overdrive.cs" />
<Compile Include="Jobs\JobGiver_Mechanoid_Rest.cs" />
<Compile Include="Jobs\JobGiver_Work_Mechanoid.cs" />
<Compile Include="Jobs\JobGiver_Mechanoid_Ability.cs" />
Expand Down

0 comments on commit 9fd573a

Please sign in to comment.