コード例 #1
0
ファイル: Mod.cs プロジェクト: libraryaddict/CookingSkill
        // Modifies the item based on professions and stuff
        // Returns for whether or not we should consume the ingredients
        public static bool onCook(CraftingRecipe recipe, Item item, List <Chest> additionalItems)
        {
            if (recipe.isCookingRecipe && item is SObject obj)
            {
                int amtCrafted = 0;
                if (Game1.player.recipesCooked.ContainsKey(obj.ParentSheetIndex))
                {
                    amtCrafted = Game1.player.recipesCooked[obj.ParentSheetIndex];
                }
                Random rand = new Random((int)(Game1.stats.daysPlayed + Game1.uniqueIDForThisGame + (uint)obj.ParentSheetIndex + (uint)amtCrafted));

                obj.Edibility = (int)(obj.Edibility * getEdibilityMultiplier());

                if (Game1.player.HasCustomProfession(Skill.ProfessionSellPrice))
                {
                    obj.Price = (int)(obj.Price * 1.2);
                }

                if (Game1.player.HasCustomProfession(Skill.ProfessionSilver))
                {
                    obj.Quality = 1;
                }

                var used = new List <NewCraftingPage.ConsumedItem>();
                NewCraftingPage.myConsumeIngredients(recipe, additionalItems, false, used);

                int total = 0;
                foreach (NewCraftingPage.ConsumedItem ingr in used)
                {
                    total += ingr.amt;
                }

                for (int iq = 1; iq <= SObject.bestQuality; ++iq)
                {
                    if (iq == 3)
                    {
                        continue;          // Not a real quality
                    }
                    double chance = 0;
                    foreach (NewCraftingPage.ConsumedItem ingr in used)
                    {
                        if (ingr.item.Quality >= iq)
                        {
                            chance += (1.0 / total) * ingr.amt;
                        }
                    }

                    if (rand.NextDouble() < chance)
                    {
                        obj.Quality = iq;
                    }
                }

                return(rand.NextDouble() >= getNoConsumeChance());
            }

            return(true);
        }
コード例 #2
0
        private void clickCraftingRecipe(ClickableTextureComponent c, bool playSound = true)
        {
            Item obj = this.pagesOfCraftingRecipes[this.currentCraftingPage][c].createItem();
            /////
            bool    consume  = Mod.onCook(this.pagesOfCraftingRecipes[this.currentCraftingPage][c], obj, _materialContainers);
            SObject heldObj  = this.heldItem as SObject;
            SObject itemObj  = obj as SObject;
            bool    didCraft = false;

            /////
            Game1.player.checkForQuestComplete((NPC)null, -1, -1, obj, (string)null, 2, -1);
            if (this.heldItem == null)
            {
                /////
                if (consume)
                {
                    NewCraftingPage.myConsumeIngredients(this.pagesOfCraftingRecipes[this.currentCraftingPage][c], this._materialContainers);
                }
                didCraft = true;
                /////
                this.heldItem = obj;
                if (playSound)
                {
                    Game1.playSound("coin");
                }
            }
            else if (this.heldItem.Name.Equals(obj.Name) && this.heldItem.Stack + this.pagesOfCraftingRecipes[this.currentCraftingPage][c].numberProducedPerCraft - 1 < this.heldItem.maximumStackSize())
            {
                this.heldItem.Stack += this.pagesOfCraftingRecipes[this.currentCraftingPage][c].numberProducedPerCraft;
                /////
                if (consume)
                {
                    NewCraftingPage.myConsumeIngredients(this.pagesOfCraftingRecipes[this.currentCraftingPage][c], this._materialContainers);
                }
                didCraft = true;
                /////
                if (playSound)
                {
                    Game1.playSound("coin");
                }
            }
            /////
            if (!didCraft)
            {
                return;
            }
            /////
            if (!this.cooking && Game1.player.craftingRecipes.ContainsKey(this.pagesOfCraftingRecipes[this.currentCraftingPage][c].name))
            {
                Game1.player.craftingRecipes[this.pagesOfCraftingRecipes[this.currentCraftingPage][c].name] += this.pagesOfCraftingRecipes[this.currentCraftingPage][c].numberProducedPerCraft;
            }
            if (this.cooking)
            {
                Game1.player.cookedRecipe((int)((NetFieldBase <int, NetInt>) this.heldItem.parentSheetIndex));
                /////
                Game1.player.AddCustomSkillExperience(Mod.skill, itemObj.Edibility);
                /////
            }
            if (!this.cooking)
            {
                Game1.stats.checkForCraftingAchievements();
            }
            else
            {
                Game1.stats.checkForCookingAchievements();
            }
            if (!Game1.options.gamepadControls || this.heldItem == null || !Game1.player.couldInventoryAcceptThisItem(this.heldItem))
            {
                return;
            }
            Game1.player.addItemToInventoryBool(this.heldItem, false);
            this.heldItem = (Item)null;
        }
コード例 #3
0
        // Modifies the item based on professions and stuff
        // Returns for whether or not we should consume the ingredients
        public static bool onCook(CraftingRecipe recipe, Item item)
        {
            if (recipe.isCookingRecipe && item is Object)
            {
                Object obj        = item as Object;
                int    amtCrafted = 0;
                if (Game1.player.recipesCooked.ContainsKey(obj.parentSheetIndex))
                {
                    amtCrafted = Game1.player.recipesCooked[obj.parentSheetIndex];
                }
                Random rand = new Random((int)(Game1.stats.daysPlayed + Game1.uniqueIDForThisGame + (uint)obj.ParentSheetIndex + (uint)amtCrafted));

                obj.edibility = (int)(obj.edibility * getEdibilityMultiplier());

                if (Game1.player.professions.Contains(PROFESSION_SELLPRICE))
                {
                    obj.price = (int)(obj.price * 1.2);
                }

                if (Game1.player.professions.Contains(PROFESSION_SILVER))
                {
                    obj.quality = 1;
                }

                var used = new List <NewCraftingPage.ConsumedItem>();
                NewCraftingPage.myConsumeIngredients(recipe, false, used);

                int total = 0;
                foreach (NewCraftingPage.ConsumedItem ingr in used)
                {
                    total += ingr.amt;
                }

                for (int iq = 1; iq <= Object.bestQuality; ++iq)
                {
                    if (iq == 3)
                    {
                        continue;          // Not a real quality
                    }
                    double chance = 0;
                    foreach (NewCraftingPage.ConsumedItem ingr in used)
                    {
                        if (ingr.item.quality >= iq)
                        {
                            chance += (1.0 / total) * ingr.amt;
                        }
                    }

                    if (rand.NextDouble() < chance)
                    {
                        obj.quality = iq;
                    }
                }

                if (rand.NextDouble() < getNoConsumeChance())
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            return(true);
        }
コード例 #4
0
        private void clickCraftingRecipe(ClickableTextureComponent c, bool playSound = true)
        {
            Item   item     = this.pagesOfCraftingRecipes[this.currentCraftingPage][c].createItem();
            bool   consume  = Mod.onCook(this.pagesOfCraftingRecipes[this.currentCraftingPage][c], item);
            Object heldObj  = this.heldItem as Object;
            Object itemObj  = item as Object;
            bool   didCraft = false;

            Game1.player.checkForQuestComplete(null, -1, -1, item, null, 2, -1);
            if (this.heldItem == null)
            {
                if (consume)
                {
                    NewCraftingPage.myConsumeIngredients(this.pagesOfCraftingRecipes[this.currentCraftingPage][c]);
                }
                didCraft      = true;
                this.heldItem = item;
                if (playSound)
                {
                    Game1.playSound("coin");
                }
            }
            else if (this.heldItem.Name.Equals(item.Name) && heldObj.quality == itemObj.quality && this.heldItem.Stack + this.pagesOfCraftingRecipes[this.currentCraftingPage][c].numberProducedPerCraft - 1 < this.heldItem.maximumStackSize())
            {
                this.heldItem.Stack += this.pagesOfCraftingRecipes[this.currentCraftingPage][c].numberProducedPerCraft;
                if (consume)
                {
                    NewCraftingPage.myConsumeIngredients(this.pagesOfCraftingRecipes[this.currentCraftingPage][c]);
                }
                didCraft = true;
                if (playSound)
                {
                    Game1.playSound("coin");
                }
            }
            if (!this.cooking && Game1.player.craftingRecipes.ContainsKey(this.pagesOfCraftingRecipes[this.currentCraftingPage][c].name))
            {
                string name = this.pagesOfCraftingRecipes[this.currentCraftingPage][c].name;
                Game1.player.craftingRecipes[name] += this.pagesOfCraftingRecipes[this.currentCraftingPage][c].numberProducedPerCraft;
            }
            if (!didCraft)
            {
                return;
            }

            if (this.cooking)
            {
                Game1.player.cookedRecipe(this.heldItem.parentSheetIndex);
                Mod.addCookingExp(itemObj.edibility);
            }
            if (!this.cooking)
            {
                Game1.stats.checkForCraftingAchievements();
            }
            else
            {
                Game1.stats.checkForCookingAchievements();
            }
            if (Game1.options.gamepadControls && this.heldItem != null && Game1.player.couldInventoryAcceptThisItem(this.heldItem))
            {
                Game1.player.addItemToInventoryBool(this.heldItem, false);
                this.heldItem = null;
            }
        }