Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Poisen Logic for 1.5 #831

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using HarmonyLib;
using ProjectRimFactory.SAL3.Things.Assemblers;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit; // for OpCodes in Harmony Transpiler
using System.Runtime.CompilerServices;
using Verse;

namespace ProjectRimFactory.Common.HarmonyPatches
{

// Building_SimpleAssembler assembler -> Use the Room of The output cell instead of the Pawn
// .def.defName == "PRF_SelfCookerIII" -> Skip
[HarmonyPatch(typeof(CompFoodPoisonable), "Notify_RecipeProduced")]
class Patch_CompFoodPoisonable_Notify_RecipeProduced
{
public static bool Prefix(CompFoodPoisonable __instance, Pawn pawn)
{
if (AssemblerRefrence is null) return true;
if (AssemblerRefrence.def.defName == "PRF_SelfCookerIII") return false;
if (AssemblerRefrence is not Building_SimpleAssembler) return true;
if (Rand.Chance(RegionAndRoomQuery.RoomAt(AssemblerRefrence.OutputCell(),
AssemblerRefrence.Map, RegionType.Set_Passable)?.
GetStat(RoomStatDefOf.FoodPoisonChance) ?? RoomStatDefOf.FoodPoisonChance.roomlessScore))
{
__instance.SetPoisoned(FoodPoisonCause.FilthyKitchen);
}
return false;
}

public static Building_ProgrammableAssembler AssemblerRefrence = null;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -438,43 +438,57 @@ protected virtual void ProduceItems()
}
// GenRecipe handles creating any bonus products
if (this.def == PRFDefOf.PRF_Recycler) Patch_Thing_SmeltProducts.RecyclerProducingItems = true;
Patch_CompFoodPoisonable_Notify_RecipeProduced.AssemblerRefrence = this;
IEnumerable<Thing> products = GenRecipe.MakeRecipeProducts(currentBillReport.bill.recipe, buildingPawn, currentBillReport.selected, ProjectSAL_Utilities.CalculateDominantIngredient(currentBillReport.bill.recipe, currentBillReport.selected), this);
foreach (Thing thing in products)
{
PostProcessRecipeProduct(thing);
thingQueue.Add(thing);
}
Patch_CompFoodPoisonable_Notify_RecipeProduced.AssemblerRefrence = null;
Patch_Thing_SmeltProducts.RecyclerProducingItems = false;

// Consume the Input
for (int i = 0; i < currentBillReport.selected.Count; i++)
{
if (currentBillReport.selected[i] is Corpse c)
{
if (c.InnerPawn?.apparel != null)
{
List<Apparel> apparel = new List<Apparel>(c.InnerPawn.apparel.WornApparel);
for (int j = 0; j < apparel.Count; j++)
{
thingQueue.Add(apparel[j]);
c.InnerPawn.apparel.Remove(apparel[j]);
}
}
if (c.InnerPawn.inventory?.innerContainer != null)
{
List<Thing> things = c.InnerPawn.inventory.innerContainer.ToList();
for (int j = 0; j < things.Count; j++)
{
thingQueue.Add(things[j]);
c.InnerPawn.inventory.innerContainer.Remove(things[j]);
}
}

}
currentBillReport.bill.recipe.Worker.ConsumeIngredient(currentBillReport.selected[i], currentBillReport.bill.recipe, Map);

var selected = currentBillReport.selected[i];
TryGetCorpseItems(selected);
currentBillReport.bill.recipe.Worker.ConsumeIngredient(selected, currentBillReport.bill.recipe, Map);
}

thingQueue.AddRange(from Thing t in currentBillReport.selected where t.Spawned select t);
}

/// <summary>
/// Checks if <paramref name="selected"/> is a <see cref="Corpse"/>
/// If so adds all attached Things to the <see cref="thingQueue"/>
/// </summary>
/// <param name="selected">a processed Item</param>
private void TryGetCorpseItems(Thing selected)
{
if (selected is not Corpse c) return;
var innerPawn = c.InnerPawn;
if (innerPawn is null) return;

if (innerPawn.apparel != null)
{
List<Apparel> apparel = new List<Apparel>(innerPawn.apparel.WornApparel);
for (int j = 0; j < apparel.Count; j++)
{
thingQueue.Add(apparel[j]);
innerPawn.apparel.Remove(apparel[j]);
}
}
if (innerPawn.inventory?.innerContainer != null)
{
List<Thing> things = innerPawn.inventory.innerContainer.ToList();
for (int j = 0; j < things.Count; j++)
{
thingQueue.Add(things[j]);
innerPawn.inventory.innerContainer.Remove(things[j]);
}
}
}

public override string GetInspectString()
{
Expand Down