예제 #1
0
    /**
     * Remove the given item
     *
     * Arguments
     * - Item item - The item to be removed/dropped
     * - bool toSetActive - check if this item was meant to be set active
     */
    public void RemoveItem(Item item, bool toSetActive)
    {
        int itemIndex; // The index of the given item
        InventoryUISlotScript uiSlotScript; // The ui slot script

        if (item == null)
            return; // No item given

        itemIndex = getIndex(item);
        if (itemIndex == -1)
            return; // This player doesn't have the item

        // Set game object to be behind the player and set it to active
        if (toSetActive) {
            if (physicalItems[itemIndex].GetComponent<PhotonView>() == null) { // No Photon View
                physicalItems[itemIndex].SetActive(true);
                physicalItems[itemIndex].transform.position =
                    new Vector3(transformComponent.position.x, (float)0.0,
                                transformComponent.position.z);
            } else { // Set this player to be active
                physicalItems[itemIndex].GetComponent<PhotonView>().RPC(
                    "SetActive",
                    PhotonTargets.All,
                    new object[] {true}
                );
                physicalItems[itemIndex].GetComponent<PhotonView>().RPC(
                    "SetPosition",
                    PhotonTargets.All,
                    new object[] {transformComponent.position.x, transformComponent.position.z}
                );
            }

            // Add item to list of recently dropped items
            droppedItems.Add(physicalItems[itemIndex]);
        }

        // Remove effects if the item has some turn effects
        if (item.GetTurnEffects() != null)
            foreach (Effect turnEffect in item.GetTurnEffects())
                DetachTurnEffect(turnEffect);

        // Remove the item from the ui slot
        uiSlotScript = InventoryUI[itemIndex].GetComponent<InventoryUISlotScript>();
        uiSlotScript.RemoveItem();

        // Set inventory references to null
        inventory[itemIndex] = null;
        physicalItems[itemIndex] = null;

        // Reset item to have default values
        item.ResetCoolDownSetting();
        item.ResetUsePerTurn();
        item.ResetCoolDown();

        // Find next available spot
        availableSpot = 0;
        while (availableSpot != 8 && inventory[availableSpot] != null)
            availableSpot++;
    }