Exemple #1
0
        /// <summary>
        /// Completes skill, creating the item.
        /// </summary>
        /// <param name="creature"></param>
        /// <param name="skill"></param>
        /// <param name="packet"></param>
        public void Complete(Creature creature, Skill skill, Packet packet)
        {
            var unkInt = packet.GetInt();

            // Get recipe and create item
            Item item    = null;
            var  success = false;
            var  recipe  = AuraData.CookingDb.Find(creature.Temp.CookingMethod, creature.Temp.CookingIngredients.Select(a => a.Item.Info.Id));

            if (recipe != null)
            {
                // Get judgement
                var judgement = this.JudgeQuality(recipe, creature.Temp.CookingIngredients);
                if (judgement.Quality >= SuccessMinQuality)
                {
                    var quality = (int)judgement.Quality;
                    var rating  = this.GetRating((int)judgement.Quality);

                    // Create food if quality was good enough
                    item = new Item(recipe.ItemId);
                    item.MetaData1.SetInt("QUAL", quality);
                    item.MetaData1.SetString("MKNAME", creature.Name);
                    item.MetaData1.SetShort("MKSLV", (short)skill.Info.Rank);
                    item.MetaData1.SetString("MKACT", creature.Temp.CookingMethod);

                    // Notice
                    var msg = "";
                    if (judgement.Quality > 75)
                    {
                        msg += Localization.Get("You just made a delicious dish!");
                    }
                    else if (judgement.Quality > 55)
                    {
                        msg += Localization.Get("You just made a tasty dish!");
                    }
                    else if (judgement.Quality > 35)
                    {
                        msg += Localization.Get("You just made an edible dish.");
                    }
                    else if (judgement.Quality > -35)
                    {
                        msg += Localization.Get("You just made a pretty unappetizing dish...");
                    }
                    else
                    {
                        msg += Localization.Get("You just made a dish... that you probably shouldn't eat. Yuck!");
                    }

                    // Help message
                    if (judgement.HelpItem != null)
                    {
                        var rnd     = RandomProvider.Get();
                        var helpmsg = "";
                        if (judgement.HelpAmount < 0)
                        {
                            helpmsg += Localization.Get("There may have been {1:0.0}%-{2:0.0}% less {0} than required.");
                        }
                        else
                        {
                            helpmsg += Localization.Get("There may have been {1:0.0}%-{2:0.0}% more {0} than required.");
                        }

                        var name   = judgement.HelpItem.Data.Name;
                        var amount = Math.Abs(judgement.HelpAmount) * 100;
                        var min    = (amount - rnd.NextDouble());
                        var max    = (amount + rnd.NextDouble());

                        msg += string.Format("\n" + helpmsg, name, min, max);
                    }

                    Send.Notice(creature, msg);

                    this.OnSuccessfulCooking(creature, skill, creature.Temp.CookingMethod, item, rating);

                    success = true;
                }
            }
            else
            {
                //Log.Debug("Recipe not found");
                //Log.Debug("Method: " + creature.Temp.CookingMethod);
                //Log.Debug("Ingredients:");
                //foreach (var ingredient in creature.Temp.CookingIngredients)
                //	Log.Debug("- " + ingredient.Item.Info.Id);
            }

            // Create food waste if nothing halfway decent was created
            if (success)
            {
                item = new Item(FoodWasteItemId);
                Send.Notice(creature, Localization.Get("Cooking failed"));
            }

            // Remove ingredient items
            // According to the Wiki the whole stack gets removed.
            foreach (var ingredient in creature.Temp.CookingIngredients)
            {
                creature.Inventory.Remove(ingredient.Item);
            }

            // Replace bottled goods with empty bottles
            foreach (var ingredient in creature.Temp.CookingIngredients)
            {
                if (ingredient.Item.HasTag("/milk/|/water/"))
                {
                    creature.Inventory.Add(new Item(EmptyBottleItemId), true);
                }
            }

            // Add item to inv
            creature.Inventory.Add(item, true);

            // Cooking event
            ChannelServer.Instance.Events.OnCreatureCookedMeal(new CookingEventArgs(creature, recipe, success, item));

            // Effects and response
            Send.AcquireInfo2Cooking(creature, item.EntityId, item.Info.Id, success);
            Send.Effect(creature, Effect.Cooking, (byte)0, (byte)(success ? 4 : 1));

            Send.SkillComplete(creature, skill.Info.Id, unkInt);
        }