コード例 #1
0
 private static bool canSmith(Player p, SmithBar item)
 {
     if (p == null || item == null)
     {
         return(false);
     }
     if (item.getAmount() <= 0)
     {
         return(false);
     }
     if (!p.getInventory().hasItem(HAMMER))
     {
         p.getPackets().sendMessage("You need a hammer if you wish to smith.");
         return(false);
     }
     if (p.getSkills().getGreaterLevel(Skills.SKILL.SMITHING) < item.getLevel())
     {
         p.getPackets().sendMessage("You need a Smithing level of " + item.getLevel() + " to make that item.");
         return(false);
     }
     if (!p.getInventory().hasItemAmount(item.getBarType(), item.getBarAmount()))
     {
         p.getPackets().sendMessage("You don't have enough bars to make that item.");
         return(false);
     }
     return(true);
 }
コード例 #2
0
        public static void smithItem(Player p, int button, int offset, bool newSmith)
        {
            int index = -1;

            if (!newSmith && p.getTemporaryAttribute("smithingItem") == null)
            {
                return;
            }
            if (newSmith)
            {
                if (p.getTemporaryAttribute("smithingBarType") == null)
                {
                    return;
                }
                index = (int)p.getTemporaryAttribute("smithingBarType");
                if (index == -1)
                {
                    return;
                }
                object[][] variables    = getInterfaceVariables(p, index);
                int        amountToMake = -1;
                int        item         = -1;
                for (int i = 6; i > 0; i--)
                {
                    for (int j = 0; j < variables.Length; j++)
                    {
                        if ((int)variables[j][6] + i == button)
                        {
                            offset = i;
                            item   = j;
                            break;
                        }
                    }
                }
                if (offset == 4)
                {
                    p.getPackets().displayEnterAmount();
                    p.setTemporaryAttribute("interfaceVariable", new EnterVariable(300, button));
                }
                else
                if (offset == 3)
                {
                    amountToMake = 28;
                }
                else
                if (offset == 5)
                {
                    amountToMake = 5;
                }
                else
                if (offset == 6)
                {
                    amountToMake = 1;
                }
                if (offset >= 400)
                {
                    amountToMake = offset - 400;
                }
                p.setTemporaryAttribute("smithingItem", new SmithBar(BARS[index], (int)variables[item][3], (int)variables[item][1], (int)variables[item][4], (int)variables[item][0], (int)variables[item][2], amountToMake));
            }
            SmithBar smithbar = (SmithBar)p.getTemporaryAttribute("smithingItem");

            if (!canSmith(p, smithbar))
            {
                return;
            }
            p.getPackets().closeInterfaces();
            p.setLastAnimation(new Animation(898));
            for (int i = 0; i < smithbar.getBarAmount(); i++)
            {
                if (!p.getInventory().deleteItem(smithbar.getBarType()))
                {
                    return;
                }
            }
            if (p.getInventory().addItem(smithbar.getFinishedItem(), smithbar.getFinishedItemAmount()))
            {
                p.getSkills().addXp(Skills.SKILL.SMITHING, smithbar.getXp());
            }
            smithbar.decreaseAmount();
            if (smithbar.getAmount() >= 1)
            {
                Event smithMoreItemEvent = new Event(1500);
                smithMoreItemEvent.setAction(() => {
                    smithItem(p, -1, 1, false);
                    smithMoreItemEvent.stop();
                });
                Server.registerEvent(smithMoreItemEvent);
            }
        }