Ejemplo n.º 1
0
    public ItemReturn removeItemFromSlot(Vector2 slot)
    {
        InventoryItemSlot sl         = inventory[getIndexForSlot(slot)];
        InventoryItemSlot actualSlot = sl.itemSlot;

        if (actualSlot == null)
        {
            return(new ItemReturn());
        }
        Vector2 actualSlotVec = getSlotForIndex(actualSlot.index);
        Item    i             = actualSlot.getItem();

        foreach (InventoryItemSlot slots in actualSlot.otherSlots)
        {
            slots.removeItem();
        }
        actualSlot.removeItem();
        return(new ItemReturn(i, slot - actualSlotVec));
    }
Ejemplo n.º 2
0
    public static void deselectItem(Character characterSheet, MapGenerator mapGenerator, Unit u)
    {
        Vector3 mousePos = Input.mousePosition;

        mousePos.y = Screen.height - mousePos.y;
        Tile t = (mapGenerator != null && u != null ? mapGenerator.tiles[(int)u.position.x, (int)-u.position.y] : null);

        foreach (InventorySlot slot in inventorySlots)
        {
            Rect r = UnitGUI.getInventorySlotRect(slot);
            if (r.Contains(mousePos))
            {
                Vector2 v2 = getIndexOfSlot(slot);
                Vector2 v  = v2 - selectedCell;
                Debug.Log(v);
                if (characterSheet.characterSheet.inventory.canInsertItemInSlot(selectedItem, v))
                {
                    if (selectedItemWasInSlot == InventorySlot.None)
                    {
                        t.removeItem(selectedItem, 1);
                        u.useMinor(MinorType.Loot, false, false);
                    }
                    characterSheet.characterSheet.inventory.insertItemInSlot(selectedItem, v);
                    selectedItem = null;
                    return;
                }
                else
                {
                    InventoryItemSlot invSlot = characterSheet.characterSheet.inventory.inventory[Inventory.getIndexForSlot(v2)];
                    Item invSlotItem          = invSlot.getItem();
                    if (invSlotItem != null && characterSheet.characterSheet.inventory.itemCanStackWith(invSlotItem, selectedItem))
                    {
                        if (selectedItemWasInSlot == InventorySlot.None)
                        {
                            t.removeItem(selectedItem, 1);
                            u.useMinor(MinorType.Loot, false, false);
                        }
                        characterSheet.characterSheet.inventory.stackItemWith(invSlotItem, selectedItem);
                        selectedItem = null;
                        return;
                    }
                }
                break;
            }
        }

/*		if (GameGUI.looting && !(mousePos.x < groundX || mousePos.y < groundY || mousePos.x > groundX + groundWidth || mousePos.y > groundY + groundHeight))  {
 *                      if (selectedItemWasInSlot!=InventorySlot.None && selectedItem!=null)  {
 *                              while (selectedItem.stackSize() > 1) t.addItem(selectedItem.popStack());
 *                              t.addItem(selectedItem);
 *              u.useMinor(MinorType.Loot, false, false);
 *                              //		characterSheet.characterSheet.inventory.removeItemFromSlot(getInventorySlotPos(selectedItemWasInSlot));
 *                      }
 *              }
 *              else if (selectedItemWasInSlot!=InventorySlot.None)  {
 *                      if (characterSheet.characterSheet.inventory.canInsertItemInSlot(selectedItem, getIndexOfSlot(selectedItemWasInSlot)))  {
 *                              characterSheet.characterSheet.inventory.insertItemInSlot(selectedItem, getIndexOfSlot(selectedItemWasInSlot));
 *                      }
 *                      else  {
 *                              int slot1 = getLinearIndexFromIndex(getIndexOfSlot(selectedItemWasInSlot));
 *                              if (slot1 > -1 && characterSheet.characterSheet.inventory.itemCanStackWith(characterSheet.characterSheet.inventory.inventory[slot1].getItem(),selectedItem))  {
 *                                      characterSheet.characterSheet.inventory.stackItemWith(characterSheet.characterSheet.inventory.inventory[slot1].getItem(),selectedItem);
 *                              }
 *                      }
 *              }*/
        selectedItem = null;
    }