Ejemplo n.º 1
0
 public int GetItemSlot(_CoreItem item)
 {
     for (int slot = 0; slot < coreItems.Length; slot++) {
         if (coreItems.Get(slot) == item)
             return slot;
     }
     return -1;
 }
Ejemplo n.º 2
0
 public int GetItemSlot(_CoreItem item)
 {
     for (int slot = 0; slot < coreItems.Length; slot++)
     {
         if (coreItems.Get(slot) == item)
         {
             return(slot);
         }
     }
     return(-1);
 }
Ejemplo n.º 3
0
    /// <summary>
    /// Equip an item from the inventory.
    /// </summary>
    public void Equip(int slot)
    {
        _CoreItem item = coreItems.Get(slot);

        if (item == equipped && item != null)
        {
            return;
        }

        // If theres already an item equipped
        Unequip();

        // Move it
        if (item != null)
        {
            MoveToEquipped(item);
        }
    }
Ejemplo n.º 4
0
    public void OnLoad(Dictionary <string, object> data)
    {
        // Goto position
        exitID = (int)data["player@exitID"];

        SpawnPoint exit = SpawnPoint.GetFromID(exitID);

        if (exit)
        {
            transform.position = exit.transform.position;
            transform.rotation = exit.transform.rotation;
        }

        // Load coreitems
        PlayerInventory inventory    = FindObjectOfType <PlayerInventory>();
        ItemData        equippedData = (ItemData)data["player@equipped"];

        for (int i = 0; i < inventory.coreItems.Length; i++)
        {
            ItemData itemData = (ItemData)data["player@coreItem#" + i];
            if (itemData.prefab == null)
            {
                continue;
            }

            GameObject clone = Instantiate(ItemDataBase.GetPrefab(itemData.prefab)) as GameObject;

            UniqueId uuid = clone.GetComponent <UniqueId>();
            uuid.uniqueId = itemData.uuid;

            _CoreItem item = clone.GetComponent <_CoreItem>();

            if (equippedData.uuid == itemData.uuid)
            {
                // Send to equipped
                inventory.coreItems[item.targetSlot] = item;
                inventory.MoveToEquipped(item);
                item.OnPickup();
                equippedData.prefab = null;
            }
            else
            {
                // Send to inventory
                inventory.coreItems[item.targetSlot] = item;
                inventory.MoveToInventory(item);
                item.OnPickup();
            }
        }

        if (equippedData.prefab != null)
        {
            // Spawn as equipped
            GameObject clone = Instantiate(ItemDataBase.GetPrefab(equippedData.prefab)) as GameObject;

            UniqueId uuid = clone.GetComponent <UniqueId>();
            uuid.uniqueId = equippedData.uuid;

            _Item item = clone.GetComponent <_Item>();

            inventory.MoveToEquipped(item);
            item.OnPickup();
        }
    }
Ejemplo n.º 5
0
    void SetHUDVisable(bool state)
    {
        // Don't allow inventory when holding point
        if (pushing && pushing.hasPoint)
        {
            state = false;
        }
        // Don't allow inventory when talking to NPC
        if (interaction && interaction.talkingTo != null)
        {
            state = false;
        }
        // Don't allow inventory when auto-moving
        if (movement && movement.autoMoveTowards.HasValue)
        {
            state = false;
        }
        // Ignore if set to same state
        if (isOpen == state)
        {
            return;
        }

        // Unequip core item on open
        if (state && inventory && inventory.equipped is _CoreItem)
        {
            inventory.Unequip();
        }

        // Loop each slot
        for (int slot = 0; slot < inventory.coreItems.Length; slot++)
        {
            // Update the leaves
            if (state)
            {
                // Add leaves
                GameObject clone = Instantiate(leavesPrefab) as GameObject;

                clone.transform.SetParent(leavesParent);
                clone.transform.localPosition    = Vector3.zero;
                clone.transform.localScale       = Vector3.one;
                clone.transform.localEulerAngles = new Vector3(0, 0, -slot * 90);

                Animator  anim = clone.GetComponentInChildren <Animator>();
                _CoreItem item = inventory.coreItems.Get(slot);

                anim.SetBool("Open", item != null);
                anim.SetBool("Slow", false);

                if (item != null)
                {
                    GUILeaf leaf = anim.GetComponentInChildren <GUILeaf>();
                    leaf.previewPrefab = item.preview;
                }

                leaves[slot] = anim;
            }
            else
            {
                // Remove leaves
                Destroy(leaves[slot].transform.parent.gameObject);
            }
        }

        isOpen          = state;
        mouseStartDelta = CalcMouseDelta();
    }