예제 #1
0
 // Use this for initialization
 void Start()
 {
     inventory = GetComponent <InventoryScript>();
     inventory.AddItem(ItemType.StrategyCard_Offense, 1);
     inventory.AddItem(ItemType.StrategyCard_Defense, 1);
     inventory.AddItem(ItemType.StrategyCard_Flank, 1);
     inventory.AddItem(ItemType.StrategyCard_Inflitrate, 1);
     inventory.AddItem(ItemType.StrategyCard_Suppress, 1);
 }
예제 #2
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
         inventory.AddItem(item);
     }
 }
예제 #3
0
    void OnTriggerStay(Collider other)
    {
        if (other.GetComponent <ResourceScript> () && Input.GetMouseButtonDown(0))
        {
            ResourceScript rs = other.GetComponent <ResourceScript>();

            rs.Gather(50);

            playerInventory.AddItem(rs.resourceType, 50);
        }

        if (CheckForDroppedItems(other))
        {
            return;
        }
    }
    public void OnTriggerEnter(Collider other)
    {
        var item = other.GetComponent <Item>();

        if (item)
        {
            inventory.AddItem(item.item, 1);
            Destroy(other.gameObject);
        }
    }
 private void Update()
 {
     if (Input.GetButtonDown("Interact") && currentInterObj)
     {
         if (currentInterObjScript.inventory)
         {
             inventory.AddItem(currentInterObj);
         }
     }
 }
    public bool AddItem(Item item)
    {
        bool success = false;

        if (inventory.AddItem(item))
        {
            UpdateWeightText(weightText);
            success = true;
        }

        return(success);
    }
예제 #7
0
    public void BuyItem(int itemNo)
    {
        int    value;
        string itemName = shopItems[itemNo].name;

        switch (itemName)
        {
        case "Infinitium Metal":
            value = 2;
            if (PlayerData.coins >= value)
            {
                PlayerData.metals[13]++;
                inventoryScript.AddItem(itemName, shopItems[itemNo].sprite, PlayerData.metals[13]);
                PlayerData.coins -= value;
            }
            else
            {
                break;
            }
            break;

        case "Mystical Metal":
            value = 1;
            if (PlayerData.coins >= value)
            {
                PlayerData.metals[12]++;
                inventoryScript.AddItem(itemName, shopItems[itemNo].sprite, PlayerData.metals[12]);
                PlayerData.coins -= value;
            }
            else
            {
                break;
            }
            break;

        default:
            break;
        }
    }
예제 #8
0
 void OnTriggerStay(Collider other)
 {
     if ((other.gameObject.tag == "DigSpot") && (Input.GetKeyDown(KeyCode.RightShift)))
     {
         var item = other.GetComponent <Item>();
         if (item)
         {
             inventory.AddItem(item.item, 1);
             Destroy(other.gameObject);
         }
         Destroy(other.gameObject);
         movementScript.dogDug();
     }
 }
예제 #9
0
    /// <summary>
    /// This function will add the item to this slot, but if the slot is full it's going to recall the additem again
    /// </summary>
    /// <param name="_item">The added item</param>
    /// <returns></returns>
    public bool Slot_AddItem(Item _item, int _amount)
    {
        // The slot is empty!
        if (heldItem == null)
        {
            heldItem   = _item;
            itemAmount = _amount;

            UpdateSlot();
            return(true);
        }

        // If we are aren't overadding, basically ( How much we have + adding.amount < Max Stack )
        //Same item?		  Is it stackable?	    Well, do we have space to add?
        else if (heldItem.name == _item.name && heldItem.StackAble && itemAmount + _amount <= heldItem.StackSize)
        {
            itemAmount += _amount;

            UpdateSlot();
            return(true);
        }

        // If we are trying to add more than it can hold, this will recall a function from the
        // inventory script, from where it will selfCall.
        else if (heldItem == _item && heldItem.StackAble && itemAmount + _amount > heldItem.StackSize && itemAmount != heldItem.StackSize)
        {
            //Recall the add function using the stack difference from the inventory.
            // Stack difference = itemAmount + _item.amount - heldItem.StackSize
            if (InventoryScript.Singleton.DebugMode)
            {
                Debug.Log("The" + _item + "has been added in slot " + gameObject.name + "can't stack anymore, recalling...");
            }

            int calculus = _amount + itemAmount - _item.StackSize;
            itemAmount = heldItem.StackSize;

            UpdateSlot();

            if (InventoryScript.Singleton.DebugMode)
            {
                InventoryScript.Singleton.AddItem(_item, (calculus));
            }
            else
            {
                ParentedInventory.AddItem(_item, (calculus));
            }



            return(true);
        }

        // If everything else fails!
        else
        {
            if (InventoryScript.Singleton.DebugMode)
            {
                Debug.Log("The " + _item + "cannot be added in slot " + gameObject.name + "! Wrong type, or can't stack anymore.");
            }

            UpdateSlot();
            return(false);
        }
    }
예제 #10
0
    public bool Equip(Equipment newStatsToAdd, bool silent = false)
    {
        if (VendorWindow.IsOpen)
        {
            return(false);
        }

        int slotIndex = (int)newStatsToAdd.equipSlot;

        /// These item are set to null to start with because we invoke a callback that
        /// will remove the stats from olditem and add the stats on newitem. only populate them
        /// if we are about the replace an item.
        Equipment oldStatsToRemove = null;
        Equipment oldOffhand       = null;



        // newItem = Bow
        if (slotIndex == 3 && (int)newStatsToAdd.equipType == 1)
        {
            if (DebugControl.debugInventory)
            {
                Debug.Log("Adding Bow as a new item");
            }

            /// if player has items equipped in both main and offhand
            if (currentEquipment[3] != null && currentEquipment[4] != null)
            {
                if (DebugControl.debugInventory)
                {
                    Debug.Log("player has items equipped in both main and offhand");
                }

                oldStatsToRemove = currentEquipment[3];
                oldOffhand       = currentEquipment[4];

                stats.RemoveItemStats(oldOffhand);

                /// if there is space for the item in the inventory
                if (inventory.MyEmptySlotCount >= 2)
                {
                    ClearOffhandSlotAndUpdateVisuals(newStatsToAdd, slotIndex);
                    SaveItemInfoAndClearSlot(newStatsToAdd);
                    inventory.AddItemToFirstInvSlot(oldStatsToRemove);
                    inventory.AddItemToSecondInvSlot(oldOffhand);
                }

                else if (inventory.MyEmptySlotCount == 1)
                {
                    if (DebugControl.debugInventory)
                    {
                        Debug.Log("Have only 1 slot available");
                    }

                    SlotScript one = inventory.GetSlotScript(0);
                    SlotScript two = inventory.GetSlotScript(1);

                    SlotInfo firstSlot  = SaveItemInfoAndClearSlot(one);
                    SlotInfo secondSlot = SaveItemInfoAndClearSlot(two);

                    inventory.ClearFromSlot(newStatsToAdd.MySlot);

                    inventory.AddItemToFirstInvSlot(oldStatsToRemove);
                    inventory.AddItemToSecondInvSlot(oldOffhand);

                    if (firstSlot.slotItem != null)
                    {
                        inventory.AddItem(firstSlot.slotItem);
                    }

                    if (secondSlot.slotItem != null)
                    {
                        inventory.AddItem(secondSlot.slotItem);
                    }

                    ClearOffhandSlotAndUpdateVisuals(newStatsToAdd, slotIndex);
                }

                else if (inventory.MyEmptySlotCount < 1)
                {
                    if (DebugControl.debugInventory)
                    {
                        Debug.Log("Sending Notice that player cannot perform this action");
                    }


                    var text       = CombatTextManager.instance.FetchText(transform.position);
                    var textScript = text.GetComponent <CombatText>();
                    textScript.White("Not enough room!", transform.position);
                    text.transform.position = player.transform.position;
                    text.SetActive(true);
                    textScript.FadeOut();

                    return(false);
                }
            }

            /// Player has a main hand equipped but not a shield
            else if (currentEquipment[3] != null && currentEquipment[4] == null)
            {
                if (DebugControl.debugInventory)
                {
                    Debug.Log("Player has a main hand equipped but not a shield");
                }

                oldStatsToRemove = currentEquipment[slotIndex];

                if (inventory.MyEmptySlotCount >= 1)
                {
                    SaveItemInfoAndClearSlot(newStatsToAdd);
                    inventory.AddItemToFirstInvSlot(oldStatsToRemove);
                }

                else if (inventory.MyEmptySlotCount == 0)
                {
                    SaveItemInfoAndClearSlot(newStatsToAdd);
                    inventory.AddItem(oldStatsToRemove);
                }

                ClearOffhandSlotAndUpdateVisuals(newStatsToAdd, slotIndex);
            }

            /// Player does not have a main hand equipped but has a shield
            else if (currentEquipment[3] == null && currentEquipment[4] != null)
            {
                if (DebugControl.debugInventory)
                {
                    Debug.Log("Player does not have a main hand equipped but has a shield");
                }

                oldOffhand = currentEquipment[4];
                stats.RemoveItemStats(oldOffhand);

                if (inventory.MyEmptySlotCount >= 1)
                {
                    SaveItemInfoAndClearSlot(newStatsToAdd);
                    inventory.AddItemToSecondInvSlot(oldOffhand);
                }

                else if (inventory.MyEmptySlotCount == 0)
                {
                    SaveItemInfoAndClearSlot(newStatsToAdd);
                    inventory.AddItem(oldOffhand);
                }

                ClearOffhandSlotAndUpdateVisuals(newStatsToAdd, slotIndex);
            }

            /// Nothing equipped
            else
            {
                SaveItemInfoAndClearSlot(newStatsToAdd);
            }
        }



        // if its a shield
        else if (slotIndex == 4 && (int)newStatsToAdd.equipType == 2)
        {
            /// if player has items equipped in both main and offhand
            if (currentEquipment[3] != null && currentEquipment[4] != null)
            {
                oldStatsToRemove = currentEquipment[4];
                oldOffhand       = currentEquipment[4];

                if (inventory.MyEmptySlotCount >= 1)
                {
                    SaveItemInfoAndClearSlot(newStatsToAdd);
                    inventory.AddItemToSecondInvSlot(oldOffhand);
                }

                else if (inventory.MyEmptySlotCount == 0)
                {
                    SaveItemInfoAndClearSlot(newStatsToAdd);
                    inventory.AddItem(oldOffhand);
                }
            }

            /// Player has a main hand equipped but not a shield
            /// It could be a bow or a single melee weapon
            else if (currentEquipment[3] != null && currentEquipment[4] == null)
            {
                ///Its a bow that he has equipped
                if ((int)currentEquipment[3].equipType == 1)
                {
                    if (DebugControl.debugInventory)
                    {
                        Debug.Log("Adding Shield in place of Bow");
                    }

                    oldStatsToRemove = currentEquipment[3];

                    SaveItemInfoAndClearSlot(newStatsToAdd);
                    inventory.AddItem(oldStatsToRemove);
                    ClearMainHandSlot(newStatsToAdd, slotIndex);
                }

                else
                {
                    SaveItemInfoAndClearSlot(newStatsToAdd);
                }
            }

            /// Player does not have a main hand equipped but has a shield
            else if (currentEquipment[3] == null && currentEquipment[4] != null)
            {
                oldStatsToRemove = currentEquipment[slotIndex];
                oldOffhand       = currentEquipment[slotIndex];

                if (inventory.MyEmptySlotCount >= 1)
                {
                    SaveItemInfoAndClearSlot(newStatsToAdd);
                    inventory.AddItemToSecondInvSlot(oldOffhand);
                }

                else if (inventory.MyEmptySlotCount == 0)
                {
                    SaveItemInfoAndClearSlot(newStatsToAdd);
                    inventory.AddItem(oldOffhand);
                }
            }

            /// Nothing equipped
            else
            {
                SaveItemInfoAndClearSlot(newStatsToAdd);
            }
        }



        /// if its not a bow but you have an item in that position
        /// Mainly, equipping a melee weapon and all armor
        else if (currentEquipment[slotIndex] != null && (int)newStatsToAdd.equipType != 1)
        {
            /// is the item in that position a bow?
            if ((int)currentEquipment[slotIndex].equipType == 1)
            {
                /// remove the arrow
                visibleGear[4].sprite = null;
            }

            oldStatsToRemove = currentEquipment[slotIndex];

            if (slotIndex == 3)
            {
                SaveItemInfoAndClearSlot(newStatsToAdd);
                inventory.AddItemToFirstInvSlot(oldStatsToRemove);
            }
            else
            {
                SaveItemInfoAndClearSlot(newStatsToAdd);
                inventory.AddItem(oldStatsToRemove);
            }
        }

        /// Adding an item to a slot that has nothing in it
        else if (currentEquipment[slotIndex] == null)
        {
            if (!silent)
            {
                SaveItemInfoAndClearSlot(newStatsToAdd);
            }
        }

        // invoke the callback for change of equipment
        if (onEquipmentChanged != null)
        {
            onEquipmentChanged.Invoke(newStatsToAdd, oldStatsToRemove);
        }

        // if Item has a glow effect add it here
        if (newStatsToAdd.MyGlowSprite != null)
        {
            weaponGlowSlot.sprite = newStatsToAdd.MyGlowSprite;
        }

        // Equip the item and make the sound of equipping
        inventoryEquipment[slotIndex].AddItemVisuals(newStatsToAdd, silent);

        UpdateIteminEquipmentSlot(newStatsToAdd, slotIndex);

        return(true);
    }