コード例 #1
0
 /**
  * Apply effect to given item
  *
  * Arguments
  * - Item item - The item to affect
  */
 public override void ApplyEffectToItem(Item item)
 {
     Debug.Log("Item type to be applied to: " + item.GetType().ToString());
     if (!item.GetType().Equals(affectedItemType)) return; // Don't affect the item
     Debug.Log("Applying");
     switch (itemEffectType) { // Change item stats based on the effect type
     case ItemTurnEffectType.COOLDOWN: // Change cool down
         Debug.Log("Cooldown setting reduced to: " + itemEffectValue);
         item.SetCoolDownSetting(itemEffectValue);
         item.ResetCoolDown();
         break;
     case ItemTurnEffectType.EXTRAUSE: // Change number of uses
         Debug.Log("Use count changed to: " + itemEffectValue);
         item.SetUsePerTurn(itemEffectValue);
         item.SetCurrentNumberOfUses(itemEffectValue);
         break;
     default: break; // Unknown
     }
 }
コード例 #2
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++;
    }