Skip to content

Commit

Permalink
cleanup + mech hacking facility working again
Browse files Browse the repository at this point in the history
  • Loading branch information
rheirman committed Mar 29, 2020
1 parent 81e95b2 commit f668e22
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 11 deletions.
Binary file modified 1.1/Assemblies/WhatTheHack.dll
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public static bool ShouldReload(Pawn p)
//For mechanoids replace the check of is p.RaceProps.HumanLike by custom logic
if (p.RaceProps.IsMechanoid && p.IsHacked())
{
Log.Message("mech should reload called");
//return true when a mechanoid is hacked and does not have much ammo.
ThingComp inventory = TryGetCompByTypeName(p, "CompInventory", "CombatExtended");
ThingWithComps eq = p.equipment.Primary;
Expand All @@ -90,7 +89,6 @@ public static bool ShouldReload(Pawn p)
{
p.equipment.AddEquipment(eq.SplitOff(1) as ThingWithComps);
}
Log.Message("mech should reload returning true");
return true;
}
}
Expand Down
8 changes: 4 additions & 4 deletions 1.1/Source/WhatTheHack/Harmony/CompLongRangeMineralScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ static bool Prefix(CompLongRangeMineralScanner __instance, Pawn worker)
}
if (thing == WTH_DefOf.WTH_MechanoidParts)
{
Log.Message("thing scanned is mech parts!");
// Traverse.Create(__instance).Field("daysWorkingSinceLastMinerals").SetValue(0f);
if (!TileFinder.TryFindNewSiteTile(out int tile, MinDistance, MaxDistance, true, false))
return false;
Log.Message("found new site tile");

Slate slate = new Slate();
slate.Set<Map>("map", worker.Map, false);
slate.Set<ThingDef>("targetMineable", thing, false);
slate.Set<Pawn>("worker", worker, false);

Log.Message("generating WTH_LongRangeMineralScannerMechParts quest");
if (!WTH_DefOf.WTH_LongRangeMineralScannerMechParts.CanRun(slate))
{
return true;
}
Quest quest = QuestUtility.GenerateQuestAndMakeAvailable(WTH_DefOf.WTH_LongRangeMineralScannerMechParts, slate);
Find.LetterStack.ReceiveLetter(quest.name, quest.description, LetterDefOf.PositiveEvent, null, null, quest, null, null);
return false;
Expand Down
1 change: 1 addition & 0 deletions 1.1/Source/WhatTheHack/Harmony/GenSpawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ static bool Prefix(ref Thing newThing, ref WipeMode wipeMode, bool respawningAft

static void Postfix(ref Thing newThing, bool respawningAfterLoad)
{

AddBatteryHediffIfNeeded(newThing);
RemoveConditionalComps(newThing);
if (respawningAfterLoad)
Expand Down
1 change: 0 additions & 1 deletion 1.1/Source/WhatTheHack/Harmony/JobDriver_Wear.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ static bool Prefix(ref JobDriver_Wear __instance)
{
if (BothBelts(apparel.def, wornApp.def))
{
Log.Message("drop belt!");
bool forbid = __instance.pawn.Faction != null && __instance.pawn.Faction.HostileTo(Faction.OfPlayer);
Apparel apparel2;
if (!__instance.pawn.apparel.TryDrop(wornApp, out apparel2, __instance.pawn.PositionHeld, forbid))
Expand Down
1 change: 0 additions & 1 deletion 1.1/Source/WhatTheHack/Harmony/Selector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
CodeInstruction instruction = instructionsList[i];
if (instruction.operand as MethodInfo == typeof(Pawn).GetMethod("get_RaceProps"))
{
Log.Message("replacing get_RaceProps!");
yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Selector_SelectInsideDragbox), "IsHumanLikeOrHacked", new Type[] {typeof(Pawn)}));//Injected code
}
else if(instruction.operand as MethodInfo == AccessTools.Method(typeof(RaceProperties), "get_Humanlike"))
Expand Down
9 changes: 7 additions & 2 deletions 1.1/Source/WhatTheHack/Jobs/JobDriver_Mechanoid_Rest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected override IEnumerable<Toil> MakeNewToils()
toil.defaultCompleteMode = ToilCompleteMode.Never;
toil.initAction = delegate
{

if ((pawn.health.hediffSet.HasNaturallyHealingInjury() || pawn.OnHackingTable()))
{
pawn.jobs.posture = PawnPosture.LayingInBed;
Expand All @@ -52,14 +53,17 @@ protected override IEnumerable<Toil> MakeNewToils()
this.job.checkOverrideOnExpire = true;
pawn.ClearAllReservations();
pawn.Position = RestingPlace.GetSleepingSlotPos(RestingPlace is Building_HackingTable ? Building_HackingTable.SLOTINDEX : Building_BaseMechanoidPlatform.SLOTINDEX);

};

toil.tickAction = delegate
{
{

if (RestingPlace is Building_BaseMechanoidPlatform && pawn.ownership.OwnedBed != RestingPlace)
{
ReadyForNextToil();
}
if (RestingPlace.TryGetComp<CompAssignableToPawn_Bed>().AssignedPawns.FirstOrDefault((Pawn p) => p != pawn) is Pawn otherPawn)
if (RestingPlace.TryGetComp<CompAssignableToPawn_Bed>() is CompAssignableToPawn_Bed compAssignable && compAssignable.AssignedPawns.FirstOrDefault((Pawn p) => p != pawn) is Pawn otherPawn)
{
pawn.ownership.UnclaimBed();
ReadyForNextToil();
Expand All @@ -75,6 +79,7 @@ protected override IEnumerable<Toil> MakeNewToils()
RotateToSouth();
}
};

yield return toil;

}
Expand Down
1 change: 0 additions & 1 deletion 1.1/Source/WhatTheHack/WhatTheHack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
<Compile Include="Comps\CompProperties_DataLevel.cs" />
<Compile Include="Comps\CompDataLevel.cs" />
<Compile Include="Comps\CompProperties_Overlays.cs" />
<Compile Include="Harmony\CaravanUtility.cs" />
<Compile Include="Harmony\HediffStatsUtility.cs" />
<Compile Include="Harmony\JobDriver_Wear.cs" />
<Compile Include="Harmony\PawnUIOverlay.cs" />
Expand Down

0 comments on commit f668e22

Please sign in to comment.