-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
180 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
731735894 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
Source/ReclaimFabric/SpecialThingFilterWorker_ReclaimClothing.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.