Skip to content

Commit

Permalink
A17 update
Browse files Browse the repository at this point in the history
  • Loading branch information
Skullywag committed Jun 24, 2017
1 parent 2475de9 commit 87420c0
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 192 deletions.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<ModMetaData>
<name>ReclaimFabric</name>
<author>Skullywag</author>
<targetVersion>0.16.1393</targetVersion>
<targetVersion>0.17.1546</targetVersion>
<description>Allows tailors to reclaim fabric from clothing.</description>
</ModMetaData>
1 change: 1 addition & 0 deletions About/PublishedFileId.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
731735894
Binary file added Assemblies/0Harmony.dll
Binary file not shown.
8 changes: 4 additions & 4 deletions Defs/RecipeDefs/RecycleApparel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<RecipeDef>
<defName>ReclaimFabric</defName>
<recipeWorker>ReclaimFabric.RecipeWorker_ReclaimClothing</recipeWorker>
<label>Reclaim Fabric</label>
<description>Reclaims fabrics and leathers from clothing, the amount returned is based on the items condition and tailor skill.</description>
<jobString>Reclaiming fabrics.</jobString>
Expand All @@ -25,15 +26,14 @@
<count>1</count>
</li>
</ingredients>
<specialProducts>
<li>Smelted</li>
</specialProducts>
<fixedIngredientFilter>
<categories>
<li>Apparel</li>
</categories>
<disallowedSpecialFilters>
<li>AllowNoIngredients</li>
<li>SpecialThingFilterWorker_ReclaimAdvancedArmor</li>
<li>SpecialThingFilterWorker_ReclaimArmor</li>
<li>SpecialThingFilterWorker_ReclaimEnergyShields</li>
</disallowedSpecialFilters>
</fixedIngredientFilter>
<workSkill>Crafting</workSkill>
Expand Down
Binary file modified Source/.vs/ReclaimFabric/v14/.suo
Binary file not shown.
29 changes: 0 additions & 29 deletions Source/ReclaimFabric/Bootstrap.cs

This file was deleted.

118 changes: 0 additions & 118 deletions Source/ReclaimFabric/Detours.cs

This file was deleted.

45 changes: 45 additions & 0 deletions Source/ReclaimFabric/RecipeWorker_ReclaimClothing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using RimWorld;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Verse;
using UnityEngine;
using Verse.AI;

namespace ReclaimFabric
{
public class RecipeWorker_ReclaimClothing : RecipeWorker
{
public RecipeDef recipe;

public override void ConsumeIngredient(Thing ingredient, RecipeDef recipe, Map map)
{
var costListAdj = ingredient.CostListAdjusted();
if (ingredient.def.IsClothes())
{
var resList = ingredient.Map.reservationManager.GetFieldViaReflection<List<object>>("Reservations");
var match = resList.Find(o => o.GetFieldViaReflection<object>("target") == ingredient);
Pawn crafter = match.GetFieldViaReflection<Pawn>("claimant");
float skillPerc = ((float)crafter.skills.GetSkill(SkillDefOf.Crafting).Level / 20);
float num = Mathf.Lerp(0.5f, 1.5f, skillPerc);
float healthPerc = ((float)ingredient.HitPoints / (float)ingredient.MaxHitPoints);
float num1 = Mathf.Lerp(0f, 0.4f, healthPerc);
foreach (var thingCost in costListAdj)
{
if (!thingCost.thingDef.intricate)
{
var PercentMaxLimit = (float)thingCost.count * num1;
var mainSmeltProductCount = (PercentMaxLimit * num);
if (mainSmeltProductCount > 0)
{
var resultantSmeltedThing = ThingMaker.MakeThing(thingCost.thingDef, null);
resultantSmeltedThing.stackCount = (int)mainSmeltProductCount;
yield return resultantSmeltedThing;
}
}
}
}
ingredient.Destroy(DestroyMode.Vanish);
}
}
}
14 changes: 9 additions & 5 deletions Source/ReclaimFabric/ReclaimFabric.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp, Version=0.15.6089.27073, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="0Harmony">
<HintPath>..\..\Assemblies\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp, Version=0.16.6198.16321, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\RimWorld1393Win_Data\Managed\Assembly-CSharp.dll</HintPath>
<HintPath>..\..\..\..\RimWorld1557Win_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -44,18 +47,19 @@
<Reference Include="System.Xml" />
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\RimWorld1393Win_Data\Managed\UnityEngine.dll</HintPath>
<HintPath>..\..\..\..\RimWorld1557Win_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Bootstrap.cs" />
<Compile Include="Detours.cs" />
<Compile Include="Helper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RecipeWorker_ReclaimClothing.cs" />
<Compile Include="SpecialThingFilterWorker_ReclaimAdvancedArmor.cs" />
<Compile Include="SpecialThingFilterWorker_ReclaimClothing.cs" />
<Compile Include="SpecialThingFilterWorker_ReclaimArmor.cs" />
<Compile Include="SpecialThingFilterWorker_ReclaimEnergyShields.cs" />
<Compile Include="SpecialThingFilterWorker_NoIngredients.cs" />
<Compile Include="Util.cs" />
<Compile Include="_Thing_ReclaimFabric.cs" />
</ItemGroup>
<ItemGroup />
Expand Down
21 changes: 21 additions & 0 deletions Source/ReclaimFabric/SpecialThingFilterWorker_ReclaimClothing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Verse;

namespace ReclaimFabric
{

public class SpecialThingFilterWorker_ReclaimClothing : SpecialThingFilterWorker
{

public override bool Matches( Thing t )
{
return AlwaysMatches( t.def );
}

public override bool AlwaysMatches( ThingDef def )
{
return def.IsClothes();
}

}

}
56 changes: 56 additions & 0 deletions Source/ReclaimFabric/Util.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Reflection;
using UnityEngine;
using Verse;

namespace ReclaimFabric
{
static class Util
{
public static T GetFieldViaReflection<T>(this object obj, string name) where T : class
{
FieldInfo finfo = obj.GetType().GetField(name, BindingFlags.NonPublic | BindingFlags.Instance);
if (finfo == null)
{
Log.Error(string.Format("Failed to find field {0} in type {1}", name, obj.GetType()));
return default(T);
}

return finfo.GetValue(obj) as T;
}

public static T GetStaticFieldViaReflection<T>(this Type type, string name) where T : class
{
FieldInfo finfo = type.GetField(name, BindingFlags.NonPublic | BindingFlags.Static);
if (finfo == null)
{
Log.Error(string.Format("Failed to find field {0} in type {1}", name, type));
return default(T);
}

return finfo.GetValue(null) as T;
}

public static void SetFieldViaReflection<T>(this object obj, string name, T element)
{
FieldInfo finfo = obj.GetType().GetField(name, BindingFlags.NonPublic | BindingFlags.Instance);
if (finfo == null)
{
Log.Error(string.Format("Failed to find field {0} in type {1}", name, obj.GetType()));
return;
}

finfo.SetValue(obj, element);
}

public static void CallMethodViaReflection(this object obj, string name, params object[] param)
{
obj.GetType().GetMethod(name, BindingFlags.NonPublic | BindingFlags.Instance).Invoke(obj, param);
}

public static T CallStaticMethodViaReflection<T>(this Type type, string name, params object[] param)
{
return (T)type.GetMethod(name, BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, param);
}
}
}
Loading

0 comments on commit 87420c0

Please sign in to comment.