public static bool RaceAllowsSurgery(this ThingDef alienDef, RecipeDef recipeDef) { ThingDef ingredientDef = recipeDef.fixedIngredientFilter?.AnyAllowedDef; ThingDef productDef = recipeDef.ProducedThingDef; ThingDef bloodDef = alienDef.GetBloodDef(); //null coalescing is schweet. Screw you spaghetti code return(ingredientDef == bloodDef || productDef == bloodDef || (ingredientDef?.GetCompProperties <CompProperties_RestrictUsableByRace>()?.allowedRaces?.Contains(alienDef) ?? productDef?.GetCompProperties <CompProperties_RestrictUsableByRace>()?.allowedRaces?.Contains(alienDef) ?? false)); }
private static RecipeDef GenerateRacialSurgery(ThingDef pawnDef, RecipeDef original) { RecipeDef newDef = new RecipeDef(); newDef.label = original.label; newDef.description = original.description; newDef.workerClass = original.workerClass; newDef.jobString = original.jobString; newDef.anesthetize = original.anesthetize; newDef.workAmount = original.workAmount; newDef.isViolation = original.isViolation; newDef.targetsBodyPart = original.targetsBodyPart; newDef.skillRequirements = original.skillRequirements; newDef.surgerySuccessChanceFactor = original.surgerySuccessChanceFactor; newDef.dontShowIfAnyIngredientMissing = original.dontShowIfAnyIngredientMissing; newDef.defName = original.defName + "_" + pawnDef.defName; newDef.modContentPack = original.modContentPack; //does this matter? newDef.researchPrerequisite = original.researchPrerequisite; //set up ingredients and products ThingDef bloodDef = pawnDef.GetBloodDef(); if (original.defName == "TakeBlood") { newDef.products = new List <ThingDefCountClass> { new ThingDefCountClass(bloodDef, 1) }; } else if (original.defName == "GiveBlood") { IngredientCount ingredientCount = new IngredientCount(); ingredientCount.SetBaseCount(1); ingredientCount.filter.SetAllow(bloodDef, true); newDef.ingredients.Add(ingredientCount); newDef.fixedIngredientFilter.SetAllow(bloodDef, true); } //newDef.recipeUsers.Add(pawn); pawnDef.recipes.Add(newDef); return(newDef); }