예제 #1
0
파일: Utils.cs 프로젝트: notten/REY-Mod
        public static bool HasIngredient(this Item item, Type ingredienttype, HashSet <Item> checkeditems = null, bool allergyfix = true) //stays in core as it can also be used for othere things other than allergies, also the AllergyIgnoreAttribute exists in core so theres no problem
        {
            if (checkeditems == null)
            {
                checkeditems = new HashSet <Item>();
            }
            if (checkeditems.Contains(item))
            {
                return(false);
            }
            checkeditems.Add(item);
            //Console.WriteLine(checkeditems.Count);
            if (allergyfix && ItemAttribute.Has <AllergyIgnoreAttribute>(item.Type))
            {
                return(false);
            }


            if (item.Type == ingredienttype)
            {
                return(true);
            }
            IEnumerable <Recipe> recipes = Recipe.GetRecipesForItem(item.Type);

            recipes = recipes.Where(y =>
            {
                IEnumerable <CraftingElement> recipeingredients = y.Ingredients.Where(z =>
                {
                    return(z.Item.HasIngredient(ingredienttype, checkeditems, allergyfix));
                });
                if (recipeingredients.Count() != 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            });
            if (recipes.Count() != 0)
            {
                //recipes.ForEach(x => ChatManager.ServerMessageToAllAlreadyLocalized(x.FriendlyName, false));
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
파일: Utils.cs 프로젝트: notten/REY-Mod
 public static bool IsLiquid(this Item x)
 {
     return(ItemAttribute.Has <LiquidAttribute>(x.Type));
 }
예제 #3
0
        public static bool HasIngredient(this Item item, Type ingredienttype, HashSet <Item> checkeditems = null, bool allergyfix = true) //stays in core as it can also be used for othere things other than allergies, also the AllergyIgnoreAttribute exists in core so theres no problem
        {
            if (checkeditems == null)
            {
                checkeditems = new HashSet <Item>();
            }
            if (checkeditems.Contains(item))
            {
                return(false);
            }
            checkeditems.Add(item);
            //Console.WriteLine(checkeditems.Count);
            if (allergyfix && ItemAttribute.Has <AllergyIgnoreAttribute>(item.Type))
            {
                return(false);
            }

            /*
             * I think theres a beter way than the following by just iterating through recipes and ingredients in foreach loops
             * theres no need to store the ingredients/recipes, is it?
             * Pseudocode
             * -------------------------------------------------
             * foreach Recipe
             * {
             *  foreach ingredient
             *  {
             *  if ingredient.HasIngredient return true;
             *  }
             * }
             * return false
             * -------------------------------------------------
             * That should be a bit faster
             */
            if (item.Type == ingredienttype)
            {
                return(true);
            }
            IEnumerable <Recipe> recipes = Recipe.GetRecipesForItem(item.Type);

            recipes = recipes.Where(y =>
            {
                IEnumerable <CraftingElement> recipeingredients = y.Ingredients.Where(z =>
                {
                    return(z.Item.HasIngredient(ingredienttype, checkeditems, allergyfix));
                });
                if (recipeingredients.Count() != 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            });
            if (recipes.Count() != 0)
            {
                //recipes.ForEach(x =>ChatUtils.SendMessageToAll(x.FriendlyName, false));
                return(true);
            }
            else
            {
                return(false);
            }
        }