Example #1
0
        public static void completePotion(Player p, int amount, bool newMix)
        {
            if (newMix && p.getTemporaryAttribute("completePotion") == null)
            {
                return;
            }
            if (!newMix && p.getTemporaryAttribute("herbloreItem") == null)
            {
                return;
            }
            if (newMix)
            {
                if (p.getTemporaryAttribute("completePotion") == null)
                {
                    return;
                }
                int index = (int)p.getTemporaryAttribute("completePotion");
                p.setTemporaryAttribute("herbloreItem", new Potion(END_POTION[index], UNFINISHED[index], SECONDARY[index], POTION_LEVEL[index], POTION_XP[index], amount));
            }
            Potion item = (Potion)p.getTemporaryAttribute("herbloreItem");

            if (item == null || p == null || item.getAmount() <= 0)
            {
                resetAllHerbloreVariables(p);
                return;
            }
            if (!p.getInventory().hasItem(item.getSecondary()) || !p.getInventory().hasItem(item.getUnfinished()))
            {
                resetAllHerbloreVariables(p);
                return;
            }
            if (p.getSkills().getGreaterLevel(Skills.SKILL.HERBLORE) < item.getLevel())
            {
                p.getPackets().sendMessage("You need a Herblore level of " + item.getLevel() + " to make that potion.");
                resetAllHerbloreVariables(p);
                return;
            }
            string s = ItemData.forId(item.getFinished()).getName().Replace("(3)", "");

            if (p.getInventory().deleteItem(item.getUnfinished()) && p.getInventory().deleteItem(item.getSecondary()))
            {
                if (p.getInventory().addItem(item.getFinished()))
                {
                    item.decreaseAmount();
                    p.setLastAnimation(new Animation(MIX_ANIMATION));
                    p.getSkills().addXp(Skills.SKILL.HERBLORE, item.getXp());
                    p.getPackets().sendMessage("You add the ingredient into the murky vial, you have completed the potion.");
                    p.getPackets().closeInterfaces();
                }
            }
            if (item.getAmount() >= 1)
            {
                Event completeMorePotionsEvent = new Event(750);
                completeMorePotionsEvent.setAction(() =>
                {
                    completePotion(p, item.getAmount(), false);
                    completeMorePotionsEvent.stop();
                });
                Server.registerEvent(completeMorePotionsEvent);
            }
        }