Esempio n. 1
0
    public void AddItemToBag(string name, int amount)
    {
        int i = 0;
        OmniItemType item = OmniItems.items[OmniItems.getItem(name)].GetComponent<OmniItemType>();

        while (amount > 0)
        {

            OmniItemObject obj = bagItems[i];

            if (obj == null)
            {

                if (amount > item.max_stack)
                    bagItems[i] = new OmniItemObject(item, item.max_stack);
                else
                    bagItems[i] = new OmniItemObject(item, amount);
                amount -= item.max_stack;

            }

            else if (obj.name == name)
            {

                int stack_limit = item.max_stack;

                if (obj.stack < stack_limit)
                {

                    if (obj.stack + amount > stack_limit)
                    {
                        amount -= stack_limit - obj.stack;
                        obj.stack = item.max_stack;
                    }
                    else
                    {
                        obj.stack += amount;
                        amount = 0;
                    }

                }
            }

            else if (obj.stack == 0)
            {
                if (amount > item.max_stack)
                    bagItems[i] = new OmniItemObject(item, item.max_stack);
                else
                    bagItems[i] = new OmniItemObject(item, amount);

                amount -= item.max_stack;
            }

            i++;
            if (i > OmniInventory.Bag_MaxItems)
                i = 0;

        }
    }
Esempio n. 2
0
 void Released()
 {
     if (heldItem != null)
     {
         for (int i = 0; i < Bag_MaxItems; i++)
         {
             if (slotBounds[i % Bag_Width, i / Bag_Width].Contains(clickPos))
                 if (localBag != null)
                 {
                     InventoryEvent e = new InventoryEvent(OmniWorld.tick, localBag.id, 'm', heldId, i, heldAmt);
                     OmniEvents.AddEvent(e);
                     break;
                 }
         }
         heldItem = null;
     }
 }
Esempio n. 3
0
    public void TryMoveHeld(int from, int to, int amt)
    {
        OmniItemObject item = bagItems[to];
        if (from == to)
        {
            return;
        }

        if (item == null)
        {

            if (bagItems[from].stack - amt > 0)
            {
                bagItems[from].stack -= amt;
                bagItems[to] = new OmniItemObject(item.type, amt);
            }
            else
            {
                bagItems[to] = bagItems[from];
                bagItems[from] = null;

            }
            return;
        }

        if (item.name == bagItems[from].name)
        {

            if (item.stack + amt > item.type.max_stack)
            {

                bagItems[from].stack -= item.type.max_stack - item.stack;

                item.stack = item.type.max_stack;
                return;
            }
            else
            {
                item.stack += amt;
                bagItems[from] = null;
                return;
            }

        }
        else
        {

            if (bagItems[from].stack - amt <= 0)
            {

                bagItems[to] = bagItems[from];
                bagItems[from] = item;
                return;

            }

        }
    }
Esempio n. 4
0
    void Clicked(int button)
    {
        for (int i = 0; i < Bag_MaxItems; i++)
        {
            if (slotBounds[i % Bag_Width, i / Bag_Width].Contains(clickPos))
                if (localBag != null)
                    if(localBag.bagItems[i] != null)
                        if (localBag.bagItems[i].stack > 0)
                        {
                            if (button == 0)
                            {
                                heldItem = localBag.bagItems[i];
                                heldId = i;
                                heldAmt = localBag.bagItems[i].stack;
                                heldBounds.x = clickPos.x - (heldBounds.width / 2);
                                heldBounds.y = clickPos.y - (heldBounds.height / 2);
                            }
                            else
                            {
                                if (Network.isClient)
                                    OmniWorld.netView.RPC("eq", RPCMode.Server, Network.player, i);

                                localBag.TryEquiptItem(i);
                            }
                        }
        }
    }