Example #1
0
 public static void UpdateExistingItem(Item.WINDOW window, Item.WINDOW lastWindow, Item item)
 {
     if (window == Item.WINDOW.EQUIPABLES && item.data.type == ITEM_TYPES.WEAPON)
     {
         PlayerEquip.EquipWeapon(item.data.vnum);
     }
 }
Example #2
0
 public Item getItemAtPosition(int pos, Item.WINDOW window)
 {
     for (int i = 0; i < items.Count; i++)
     {
         if (items[i].window == window && items[i].position == pos)
         {
             return(items[i]);
         }
     }
     return(null);
 }
Example #3
0
    public static int AddItemToPlayer(Player player, Item.WINDOW window, int vnum, int count)
    {
        if (count <= 0)
        {
            count = 1;
        }
        if (count > Config.MaxStackItems)
        {
            count = Config.MaxStackItems;
        }

        if (Config.Items[vnum].stacks)
        {
            if (!player.inventory.hasSpaceForItem())
            {
                return(-1);
            }

            if (!player.inventory.HasItem(vnum))
            {
                player.inventory.AddItemToInventory(vnum, count, window);
            }
            else
            {
                if (player.inventory.GetItemWithLowestAmountById(vnum, window).count + count > Config.MaxStackItems)
                {
                    int current = Config.MaxStackItems - player.inventory.GetItemWithLowestAmountById(vnum, window).count;
                    player.inventory.AddCountToItem(player.inventory.GetItemWithLowestAmountById(vnum, window), current, window);
                    player.inventory.AddItemToInventory(vnum, count - current, window);
                }
                else
                {
                    player.inventory.AddCountToItem(player.inventory.GetItemWithLowestAmountById(vnum, window), count, window);
                }
            }
        }
        else
        {
            for (int i = 0; i < count; i++)
            {
                if (!player.inventory.hasSpaceForItem())
                {
                    return(-1);
                }
                player.inventory.AddItemToInventory(vnum, 1, window);
            }
        }

        player.UpdateClientInventory();
        player.UpdateStats();
        return(0);
    }
Example #4
0
    public void AddCountToItem(Item item, int count, Item.WINDOW window)
    {
        for (int i = 0; i < items.Count; i++)
        {
            if (items[i] == item && items[i].window == window)
            {
                items[i].count += count;
                break;
            }
        }

        ChatHandler.sendLocalChatMessage(owner.client.cid, $"You have received x{count} {item.data.name}");
    }
Example #5
0
    public void AddItemToInventory(int vnum, int count, Item.WINDOW window)
    {
        int newPos = getAppropriateWindowPositionForItem(window, vnum);

        if (!Config.Items[vnum].stacks && count > 1)
        {
            count = 1;
        }

        Item nItem = new Item(owner.data.pid, window, newPos, Config.Items[vnum], -1, count);

        items.Add(nItem);
        ChatHandler.sendLocalChatMessage(owner.client.cid, $"You have received x{count} {Config.Items[vnum].name}");
    }
Example #6
0
    public static void ChangeItemPosition(int fromClient, Packet packet)
    {
        int  cid    = packet.ReadInt();
        int  sid    = packet.ReadInt();
        long iid    = packet.ReadLong();
        int  newPos = packet.ReadInt();

        Item.WINDOW window = (Item.WINDOW)packet.ReadInt();
        if (!Security.Validate(cid, fromClient, sid))
        {
            return;
        }
        Server.the_core.Clients[cid].player.inventory.ChangeItemPosition(iid, newPos, window);
    }
Example #7
0
 private bool slotOccupied(int slot, Item.WINDOW window)
 {
     for (int i = 0; i < items.Count; i++)
     {
         if (items[i].window != window)
         {
             continue;
         }
         if (items[i].position == slot)
         {
             return(true);
         }
     }
     return(false);
 }
Example #8
0
    public int getAppropriateWindowPositionForItem(Item.WINDOW window, int vnum)
    {
        if (window == Item.WINDOW.INVENTORY)
        {
            for (int i = 0; i < inventory_size; i++)
            {
                if (!slotOccupied(i, window))
                {
                    return(i + 1);
                }
            }
        }

        return(1);
    }
Example #9
0
    public void UseItemAtPosition(int pos, Item.WINDOW window)
    {
        Item targetItem = getItemAtPosition(pos, window);

        if (targetItem == null)
        {
            return;
        }

        if (targetItem.data.type == ITEM_TYPES.NONE)
        {
            ChatHandler.sendLocalChatMessage(owner.client.cid, "This item can't be used.");
            return;
        }

        targetItem.Use();
    }
Example #10
0
    public Item GetItemWithLowestAmountById(int id, Item.WINDOW window)
    {
        int lowest = 999;
        int key    = -1;

        for (int i = 0; i < items.Count; i++)
        {
            if (items[i].data.vnum == id && items[i].window == window)
            {
                if (items[i].count < lowest)
                {
                    lowest = items[i].count;
                    key    = i;
                }
            }
        }

        return(items[key]);
    }
Example #11
0
    private static async Task <Item[]> getPlayerInventoryFromDatabase(int pid)
    {
        List <Item>           list    = new List <Item>();
        List <MySqlParameter> _params = new List <MySqlParameter>()
        {
            MySQL_Param.Parameter("?pid", pid),
        };
        DataTable rows = await Server.DB.QueryAsync("SELECT * FROM [[player]].item WHERE `owner`=?pid AND (`window`='INVENTORY' OR `window`='EQUIPABLES')", _params);

        for (int i = 0; i < rows.Rows.Count; i++)
        {
            long.TryParse(rows.Rows[i]["id"].ToString(), out long iid);
            Int32.TryParse(rows.Rows[i]["vnum"].ToString(), out int vnum);
            Item.WINDOW window = (Item.WINDOW)Enum.Parse(typeof(Item.WINDOW), rows.Rows[i]["window"].ToString());
            Int32.TryParse(rows.Rows[i]["count"].ToString(), out int count);
            Int32.TryParse(rows.Rows[i]["pos"].ToString(), out int pos);
            Item nItem = new Item(pid, window, pos, Config.Items[vnum], iid, count);
            list.Add(nItem);
        }
        return(list.ToArray());
    }
Example #12
0
    public void ChangeItemPosition(long iid, int newPos, Item.WINDOW window)
    {
        for (int i = 0; i < items.Count; i++)
        {
            if (items[i].iid == iid)
            {
                if (window != items[i].window)
                {
                    if (slotOccupied(newPos, window))
                    {
                        return;
                    }

                    Logger.ItemLog(items[i].data.vnum, iid, $"MOVE,{window.ToString()},{items[i].position},{newPos}");
                    items[i].window   = window;
                    items[i].position = newPos;
                    owner.UpdateClientInventory();
                }
                else
                {
                    if (slotOccupied(newPos, window))
                    {
                        Item toMoveItem       = items[i];
                        Item itemInTargetSlot = null;
                        for (int x = 0; x < items.Count; x++)
                        {
                            if (items[x].position == newPos)
                            {
                                itemInTargetSlot = items[x];
                                break;
                            }
                        }

                        if (itemInTargetSlot == null)
                        {
                            return;
                        }

                        if (toMoveItem.iid == itemInTargetSlot.iid)
                        {
                            Logger.Syslog("do nothing?...");

                            /*
                             * Logger.ItemLog(items[i].data.vnum, iid, $"MOVE,{window.ToString()},{items[i].position},{newPos}");
                             * if (items[i].position != newPos)
                             *  items[i].position = newPos;
                             * owner.UpdateClientInventory();
                             * owner.UpdateStats();
                             */
                        }
                        else
                        {
                            Logger.ItemLog(items[i].data.vnum, iid, $"MOVE,{window.ToString()},{items[i].position},{newPos}");
                            itemInTargetSlot.position = items[i].position;
                            items[i].position         = newPos;
                            owner.UpdateClientInventory();
                            owner.UpdateStats();
                        }
                    }
                    else
                    {
                        Logger.ItemLog(items[i].data.vnum, iid, $"MOVE,{window.ToString()},{items[i].position},{newPos}");
                        items[i].position = newPos;
                        owner.UpdateClientInventory();
                        owner.UpdateStats();
                    }
                }

                return;
            }
        }
    }