public bool RemoveResourcesFromHoppers(RecipeDef recipe, List <ThingAmount> chosen) { //Log.Message( string.Format( "{0}.CompHopperUser.RemoveResourcesFromHoppers( {0}, List<ThingAmount> )", this.parent.ThingID, recipe == null ? "null" : recipe.defName ) ); var hoppers = FindHoppers(); if (hoppers.NullOrEmpty()) { return(false); } var allResources = new List <Thing>(); foreach (var hopper in hoppers) { var hopperResources = hopper.GetAllResources(ResourceSettings.filter); if (hopperResources != null) { allResources.AddRangeUnique(hopperResources); } } bool removeThings = false; if (recipe.allowMixingIngredients) { removeThings = recipe.TryFindBestRecipeIngredientsInSet_AllowMix(allResources, chosen); } else { removeThings = recipe.TryFindBestRecipeIngredientsInSet_NoMix(allResources, chosen); } if (!removeThings) { return(false); } foreach (var chosenThing in chosen) { if (chosenThing.count >= chosenThing.thing.stackCount) { chosenThing.thing.Destroy(); } else { chosenThing.thing.stackCount -= chosenThing.count; } } return(true); }
public bool EnoughResourcesInHoppers(RecipeDef recipe) { //Log.Message( string.Format( "{0}.CompHopperUser.EnoughResourcesInHoppers()", this.parent.ThingID, recipe == null ? "null" : recipe.defName ) ); var hoppers = FindHoppers(); if (hoppers.NullOrEmpty()) { return(false); } var allResources = new List <Thing>(); foreach (var hopper in hoppers) { var hopperResources = hopper.GetAllResources(ResourceSettings.filter); if (hopperResources != null) { allResources.AddRangeUnique(hopperResources); } } List <ThingAmount> chosen = new List <ThingAmount>(); if (recipe.allowMixingIngredients) { if (recipe.TryFindBestRecipeIngredientsInSet_AllowMix(allResources, chosen)) { return(true); } } else { if (recipe.TryFindBestRecipeIngredientsInSet_NoMix(allResources, chosen)) { return(true); } } return(false); }
public bool RemoveResourcesFromHoppers( RecipeDef recipe, List<ThingAmount> chosen ) { //Log.Message( string.Format( "{0}.CompHopperUser.RemoveResourcesFromHoppers( {0}, List<ThingAmount> )", this.parent.ThingID, recipe == null ? "null" : recipe.defName ) ); var hoppers = FindHoppers(); if( hoppers.NullOrEmpty() ) { return false; } var allResources = new List<Thing>(); foreach( var hopper in hoppers ) { var hopperResources = hopper.GetAllResources( ResourceSettings.filter ); if( hopperResources != null ) { allResources.AddRangeUnique( hopperResources ); } } bool removeThings = false; if( recipe.allowMixingIngredients ) { removeThings = recipe.TryFindBestRecipeIngredientsInSet_AllowMix( allResources, chosen ); } else { removeThings = recipe.TryFindBestRecipeIngredientsInSet_NoMix( allResources, chosen ); } if( !removeThings ) { return false; } foreach( var chosenThing in chosen ) { if( chosenThing.count >= chosenThing.thing.stackCount ) { chosenThing.thing.Destroy(); } else { chosenThing.thing.stackCount -= chosenThing.count; } } return true; }
public bool EnoughResourcesInHoppers( RecipeDef recipe ) { //Log.Message( string.Format( "{0}.CompHopperUser.EnoughResourcesInHoppers()", this.parent.ThingID, recipe == null ? "null" : recipe.defName ) ); var hoppers = FindHoppers(); if( hoppers.NullOrEmpty() ) { return false; } var allResources = new List<Thing>(); foreach( var hopper in hoppers ) { var hopperResources = hopper.GetAllResources( ResourceSettings.filter ); if( hopperResources != null ) { allResources.AddRangeUnique( hopperResources ); } } List<ThingAmount> chosen = new List<ThingAmount>(); if( recipe.allowMixingIngredients ) { if( recipe.TryFindBestRecipeIngredientsInSet_AllowMix( allResources, chosen ) ) { return true; } } else { if( recipe.TryFindBestRecipeIngredientsInSet_NoMix( allResources, chosen ) ) { return true; } } return false; }