예제 #1
0
    private void EquipItem(EquipableItem pickedUpItem, bool swapItems)
    {
        EquipableItem equippedItem;

        equipInventory.TryGetValue(pickedUpItem.equipSlot, out equippedItem);

        if (equippedItem == null && !swapItems)
        {
            equipInventory[pickedUpItem.equipSlot] = pickedUpItem;
            pickedUpItem.transform.SetParent(getEquipmentSlot(pickedUpItem.equipSlot).transform);
            pickedUpItem.setInventoryManager(this);
            pickedUpItem.setItemState(Item.ItemState.Equiped);
        }
        else if (swapItems)
        {
            Item tempItem = equipInventory[pickedUpItem.equipSlot];
            inventory[inventory.IndexOf(pickedUpItem)] = tempItem;

            if (tempItem != null)
            {
                tempItem.transform.SetParent(inventorySlots[inventory.IndexOf(tempItem)].transform);
                tempItem.setItemState(Item.ItemState.InInventory);
            }

            equipInventory[pickedUpItem.equipSlot] = null;

            EquipItem(pickedUpItem, false);
        }
        else
        {
            AddToInventory(pickedUpItem);
        }
    }
예제 #2
0
    public void UpdateStats()
    {
        CharacterStats statsCopy = null;

        if (selectedCharacter.currentEquipment.currentArmor != null && selectedItem != null && selectedItem.equipType.Equals(EquipType.Armor))
        {
            EquipableItem currentArmor   = selectedCharacter.currentEquipment.currentArmor;
            StatName      statToDecrease = currentArmor.characterStat;

            statsCopy = ApplyValue(statToDecrease, selectedCharacter.charStats, -currentArmor.value);
        }
        else if (selectedCharacter.currentEquipment.currentWeapon != null && selectedItem != null && selectedItem.equipType.Equals(EquipType.Weapon))
        {
            EquipableItem currentWeapon  = selectedCharacter.currentEquipment.currentWeapon;
            StatName      statToDecrease = currentWeapon.characterStat;

            statsCopy = ApplyValue(statToDecrease, selectedCharacter.charStats, -currentWeapon.value);
        }
        else
        {
            statsCopy = selectedCharacter.charStats;
        }

        PrintUpdatedStats(statsCopy);
    }
예제 #3
0
    public bool IsEquipped(EquipableItem item)
    {
        if (helmet == item)
        {
            return(true);
        }
        if (chest == item)
        {
            return(true);
        }
        if (boots == item)
        {
            return(true);
        }
        if (gloves == item)
        {
            return(true);
        }
        if (weapon == item)
        {
            return(true);
        }
        if (accessory == item)
        {
            return(true);
        }

        return(false);
    }
예제 #4
0
    public void Deserialize(string repr, PlayerComponent owner)
    {
        this.Clear();
        int pos = 0;

        repr = repr.Trim(';');
        string[] savedItems = repr.Split(';');
        for (int i = 1; i < savedItems.Length; i++)
        {
            if (savedItems[i] != "")
            {
                if (HardcodedItems.items[savedItems[i]] is EquipableItem)
                {
                    items[pos] = new EquipableItem(HardcodedItems.items[savedItems[i]] as EquipableItem);
                }
                else
                {
                    items[pos] = new UsableItem((UsableItem)HardcodedItems.items[savedItems[i]]);
                }

                items[pos].SetOwner(owner);
                items[pos].inventoryPlace = pos;
            }
            pos++;
        }
    }
예제 #5
0
 private void UnequipItem(EquipableItem equipableItem)
 {
     if (equipableItem != null)
     {
         equipableItem.UnequipItem(selectedCharacter);
     }
 }
예제 #6
0
    void LoadCharacterData(PlayableCharacter character)
    {
        CharacterStats characterStats = character.charStats;

        //Character base
        avatarImage.sprite = characterStats.avatar;
        EquipableItem weapon = character.currentEquipment.currentWeapon;

        if (weapon != null)
        {
            charWeaponText.text = weapon.itemName;
        }
        else
        {
            charWeaponText.text = "";
        }

        EquipableItem armor = character.currentEquipment.currentArmor;

        if (armor != null)
        {
            charArmorText.text = armor.itemName;
        }
        else
        {
            charArmorText.text = "";
        }
        //Character stats
        currentAttackText.text  = characterStats.totalAttack.ToString();
        currentDefenseText.text = characterStats.totalDefense.ToString();
        currentSpeedText.text   = characterStats.totalSpeed.ToString();
        currentMagicText.text   = characterStats.totalMagic.ToString();

        PrintUpdatedStats(characterStats);
    }
예제 #7
0
    public void Dequip(EquipableItem item)
    {
        if (helmet == item)
        {
            helmet = null;
        }
        if (chest == item)
        {
            chest = null;
        }
        if (gloves == item)
        {
            gloves = null;
        }
        if (boots == item)
        {
            boots = null;
        }
        if (weapon == item)
        {
            weapon = null;
        }
        if (accessory == item)
        {
            accessory = null;
        }

        if (OnChange != null)
        {
            Debug.Log("hero equipment changed");
            OnChange.Invoke(this);
        }
    }
    public void Equip(EquipableItem equipable)
    {
        if (_currentEquipableItem == null)
        {
            currentEquipmentObject = Instantiate(equipable.Prefab, Camera.main.transform);
            _currentEquipableItem  = equipable;
            return;
        }

        //We have an item already equiped
        if (_currentEquipableItem.Equals(equipable))
        {
            Destroy(currentEquipmentObject);
            currentEquipmentObject = null;
            _currentEquipableItem  = null;
            return;
        }
        else
        {
            Destroy(currentEquipmentObject);
            currentEquipmentObject = null;
            _currentEquipableItem  = null;
            currentEquipmentObject = Instantiate(equipable.Prefab, Camera.main.transform);
            _currentEquipableItem  = equipable;
        }
    }
    private void UpdateBackground()
    {
        int key = 1;

        foreach (Transform slot in transform)
        {
            // Get the respective item from inventory.
            EquipableItem item = inventory.GetItemAt(key);

            // Get the cooldown background.
            Image image = slot.Find("cooldown").GetComponent <Image>();

            // If the item is still cooling down, show a gray background
            // with its size based on the cooldown time.
            if (item != null && inventory.getTimeUntilNextUse(item) > 0)
            {
                image.enabled = true;
                float ratio = inventory.getTimeUntilNextUse(item) / item.Cooldown;
                image.rectTransform.localScale = new Vector3(1, ratio, 1);
                image.sprite = cooldownBackground;
            }
            else
            {
                image.enabled = false;
            }
            key++;
        }
    }
예제 #10
0
    public void ShowTooltips(EquipableItem item)
    {
        ItemName.text = item.ItemName;
        ItemSlot.text = item.equipmentType.ToString();

        sb.Length = 0;

        AddStats(item.hpFlat, "Hp");
        AddStats(item.hpPercent, "Hp %");
        AddStats(item.hpRegenFlat, "Hp Regeneration");
        AddStats(item.hpRegenPercent, "Hp Regeneration %");
        AddStats(item.moveSpeed, "Movement Speed");
        AddStats(item.armor, "Armor");
        AddStats(item.fireResist, "Fire Resistance");
        AddStats(item.waterResist, "Water Resistance");
        AddStats(item.airResist, "Air Resistance");
        AddStats(item.attackSpeed, "Attack Speed");
        AddStats(item.castSpeed, "Cast Speed");
        AddStats(item.globalDamage, "Damage %");
        AddStats(item.physicalDmgFlat, "Physical Damage");
        AddStats(item.physicalDmgPercent, "Physical Damage %");
        AddStats(item.fireDamageFlat, "Fire Damage");
        AddStats(item.waterDamageFlat, "Water Damage");
        AddStats(item.airDamageFlat, "Air Damage");
        AddStats(item.fireDamagePercent, "Fire Damage %");
        AddStats(item.waterDamagePercent, "Water Damage %");
        AddStats(item.airDamagePercent, "Air Damage %");


        ItemStats.text = sb.ToString();
        gameObject.SetActive(true);
    }
예제 #11
0
    private void OnGrabAnimationFinished()
    {
        // Equip
        if (rightHand.name != "Name")
        {
            print("right hand equip");
            rightHand.Instance.transform.parent = rightHand.pivotPoint;
            rightHand.Instance.transform.SetPositionAndRotation(rightHand.pivotPoint.position, rightHand.pivotPoint.rotation);
        }

        if (leftHand.name != "Name")
        {
            leftHand.Instance.transform.parent = leftHand.pivotPoint;
            leftHand.Instance.transform.SetPositionAndRotation(leftHand.pivotPoint.position, leftHand.pivotPoint.rotation);
        }

        // Unequip
        if (unequippedItem != null)
        {
            print("unequip");

            unequippedItem.Instance.transform.parent = backPivot;
            unequippedItem.Instance.transform.SetPositionAndRotation(backPivot.position, backPivot.rotation);

            unequippedItem = null;
        }

        print(rightHand.name);
    }
예제 #12
0
    private void ChangeAttackAnimation_OnRemoveEvent(EquipableItem obj)
    {
        Weapon temp;
        var    targetWeapon = obj as Weapon;

        if (targetWeapon != null)
        {
            if (targetWeapon.EquipmentType == EquipmentType.MainHand)
            {
                temp = InventoryManager.Instance.equipmentPanel.GetSlot(EquipmentType.Shield).Item as Weapon;
            }
            else
            {
                temp = InventoryManager.Instance.equipmentPanel.GetSlot(EquipmentType.MainHand).Item as Weapon;
            }

            if (temp != null)
            {
                attackType = temp.attackType;
            }
            else
            {
                attackType = defaultAttackType;
            }
        }
        //Debug.Log("Change Attack animation OnRemoveEvent");
    }
예제 #13
0
    private void ChangeAttackAnimation_OnAddItemEvent(EquipableItem obj)
    {
        Weapon temp;
        var    targetWeapon = obj as Weapon;

        if (targetWeapon != null)
        {
            if (targetWeapon.EquipmentType == EquipmentType.MainHand)
            {
                temp = InventoryManager.Instance.equipmentPanel.GetSlot(EquipmentType.Shield).Item as Weapon;
            }
            else
            {
                temp = InventoryManager.Instance.equipmentPanel.GetSlot(EquipmentType.MainHand).Item as Weapon;
            }

            if (temp != null)
            {
                attackType = AttackType.TwoWeapon;
            }
            else
            {
                attackType = targetWeapon.attackType;
            }
        }
    }
예제 #14
0
    /*
     * One of the more important functions here. When in focus, this will be called
     * every frame with the stored input from InputTracking
     */
    public override void HandleInput(PlayerAction action, string inputString)
    {
        switch (action)
        {
        case PlayerAction.DROP_ITEMS:
            Player.player.inventory.Drop(inspecting.position);
            ExitAllWindows();
            break;

        case PlayerAction.EQUIP:
            EquipableItem toEquip = inspecting.held[0].equipable;
            if (toEquip != null && !toEquip.isEquipped)
            {
                UIController.singleton.OpenEquipmentEquip(inspecting);
            }
            else
            {
                //TODO: Console error of some sort?
            }
            break;

        case PlayerAction.UNEQUIP:
            EquipableItem equip = inspecting.held[0].equipable;
            if (equip != null && equip.isEquipped)
            {
                Player.player.equipment.UnequipItem(inspecting.position);     //Faster method, doesn't need a search
                ExitAllWindows();
            }
            break;
        }
    }
예제 #15
0
    /*
     * public void OnDrag(PointerEventData eventData)
     * {
     * if (ContainsItem())
     * {
     *     // display dragged item icon at mouse position
     *     charPanel.ShowDraggedItem(charPanel.items[index], index);
     *
     *     // delete the dragged item
     *     charPanel.items[index] = new Item();
     * }
     * }
     */

    bool EquipToSlot(EquipableItem draggedItem)
    {
        // * important
        // * slots index has the some order as
        // * weapon equip type enum's order

        if (index == (int)draggedItem.equipType)
        {
            // slot occupied
            if (ContainsItem())
            {
                // swap old -> new item
                // give old item back to inventory
                Item tempItem = charPanel.items[index];
                charPanel.items[index] = draggedItem;
                inventory.items[inventory.draggedItemSlotNum] = tempItem;

                draggedItem.ActiveItemEffect();
            }

            // slot empty
            else
            {
                charPanel.items[index] = draggedItem;
            }

            //inventory.HideDraggedItem();

            return(true);
        }

        Debug.Log("wrong slot!");
        return(false);
    }
예제 #16
0
    public void ShowUpdatedStats(EquipableItem item)
    {
        //Mirar si el pj tiene un objeto equipado en la casilla correspondiente
        //En caso afirmativo se deja como si no tuviera nada (usando variable a parte)
        CharacterStats statsCopy = null;

        if (selectedCharacter.currentEquipment.currentArmor != null && item.equipType.Equals(EquipType.Armor))
        {
            EquipableItem currentArmor   = selectedCharacter.currentEquipment.currentArmor;
            StatName      statToDecrease = currentArmor.characterStat;

            statsCopy = ApplyValue(statToDecrease, selectedCharacter.charStats, -currentArmor.value);
        }
        if (selectedCharacter.currentEquipment.currentWeapon != null && item.equipType.Equals(EquipType.Weapon))
        {
            EquipableItem currentWeapon  = selectedCharacter.currentEquipment.currentWeapon;
            StatName      statToDecrease = currentWeapon.characterStat;

            statsCopy = ApplyValue(statToDecrease, selectedCharacter.charStats, -currentWeapon.value);
        }

        //Se añade lo que se aplicaría y se muestra en el resultado actualizado
        if (statsCopy == null)
        {
            statsCopy = InitStatsCopy(selectedCharacter.charStats);
        }
        statsCopy = ApplyValue(item.characterStat, statsCopy, item.value);
        PrintUpdatedStats(statsCopy);
    }
예제 #17
0
    public void MonsterToFloor(int index)
    {
        Inventory onFloor = Map.current.GetTile(monster.location).inventory;

        ItemStack stack = Items[index];

        if (stack == null)
        {
            return;                //Quick cutout
        }
        EquipableItem equip = stack.held[0].equipable;

        if (equip && equip.isEquipped)
        {
            //TODO: Figure out if we should abort the drop, or just unequip

            //For now, just unequip it
            equip.Unequip();
        }

        foreach (Item i in stack.held)
        {
            i.Drop();
            i.SetLocation(monster.location);
        }

        onFloor.Add(stack);
        RemoveAt(index);
    }
예제 #18
0
    public void Equip(EquipableItem item)
    {
        if (Inventory.RemoveItem(item))
        {
            EquipableItem previousItem;
            if (EquipmentPanel.AddItem(item, out previousItem))
            {
                if (previousItem != null)
                {
                    Inventory.AddItem(previousItem);
                    previousItem.Unequip(this);
                    statPanel.UpdateStatValues();
                }
                item.Equip(this);
                statPanel.UpdateStatValues();

                if (item.equipmentType == EquipmentType.Weapon)
                {
                    string[] name = item.ItemName.Split(' ');
                    if (name[0] == "Sword" || name[0] == "Staff" || name[0] == "Bow")
                    {
                        player.SwapWeapons(name[0]);
                    }
                    else
                    {
                        player.SwapWeapons(name[1]);
                    }
                }
            }
            else
            {
                Inventory.AddItem(item);
            }
        }
    }
예제 #19
0
 public void UnEquip(EquipableItem item)
 {
     if (!inventory.IsFull() && equipmentPanel.RemoveItem(item))
     {
         inventory.AddItem(item);
     }
 }
예제 #20
0
    private void Clear()
    {
        m_SelectedEquipment = null;

        for (int i = 0; i < m_PartyRoot.transform.childCount; ++i)
        {
            var cur = m_PartyRoot.transform.GetChild(i).gameObject;

            if (!m_DoNotDestroyList.Contains(cur))
            {
                Destroy(cur);
            }
        }

        for (int i = 0; i < m_EquipmentRoot.transform.childCount; ++i)
        {
            var cur = m_EquipmentRoot.transform.GetChild(i).gameObject;

            if (!m_DoNotDestroyList.Contains(cur))
            {
                Destroy(cur);
            }
        }

        for (int i = 0; i < m_ItemsRoot.transform.childCount; ++i)
        {
            var cur = m_ItemsRoot.transform.GetChild(i).gameObject;

            if (!m_DoNotDestroyList.Contains(cur))
            {
                Destroy(cur);
            }
        }
    }
예제 #21
0
    public bool RemoveItem(EquipableItem item, out List <Item> PreItems)
    {
        PreItems = null;
        var target = EquipmentSlots.FirstOrDefault(s => s.EquipmentType == item.EquipmentType);

        if (target.Item != null)
        {
            OnRemoveItemEvent?.Invoke(item);
            target.Amount = 0;
            target.Item   = null;
            return(true);
        }
        //for (int i = 0; i < EquipmentSlots.Length; i++)
        //{
        //    if (EquipmentSlots[i].Item == item)
        //    {
        //        //                CharacterScript.Instance.characterState.Remove(item.state);
        //        //PlayerVisualScript.Instance.RemoveItemVisual(item);
        //        OnRemoveItemEvent?.Invoke(item);
        //        EquipmentSlots[i].Item = null;
        //        return true;
        //    }
        //}

        return(false);
    }
예제 #22
0
    // Returns the strongest weapon in the inventory of a given type.
    public IItem GetStrongestWeapon(EquipableItem itemType)
    {
        IItem topPick       = null;
        int   topPickDamage = 0;

        foreach (KeyValuePair <int, int> itemPair in items)
        {
            IItem item = itemManager.GetItem(itemPair.Key);

            if (item.HasBehavior(ItemBehaviorType.EQUIPABLE))
            {
                EquipableItemBehavior behavior = (EquipableItemBehavior)item.GetBehavior(ItemBehaviorType.EQUIPABLE);

                if (behavior.itemType == itemType)
                {
                    if (behavior.item.Damage > topPickDamage)
                    {
                        topPick = item;
                    }
                }
            }
        }

        return(topPick);
    }
예제 #23
0
 public void Unequip(EquipableItem itemSlot)
 {
     if (!inventory.IsInvFull() && equipmentPanel.DeleteItem(itemSlot))
     {
         itemSlot.Unequip(this);
         Inventory.instance.AddItem(itemSlot);
     }
 }
예제 #24
0
 public void ShowUpdatedStats()
 {
     if (item == null)
     {
         item = (EquipableItem)ItemsList.items.Find(p => p.itemName.Equals(nameText.text));
     }
     menuController.ShowUpdatedStats(item);
 }
예제 #25
0
 public void OnPawnSelected(Pawn pawn)
 {
     if (m_SelectedEquipment != null)
     {
         m_Inventory.EquipTo(pawn, m_SelectedEquipment);
         m_SelectedEquipment = null;
     }
 }
예제 #26
0
 public void SetupItemButton(EquipableItem receivedItem, GeneralUiManager ui)
 {
     item           = receivedItem;
     uiManager      = ui;
     itemName.text  = item.itemName;
     itemPrice.text = item.price.ToString();
     itemRef        = new ItemReference(item.itemId, item.quantityHeld, item.itemType);
 }
예제 #27
0
 public void SetSelectedArmor()
 {
     if (charArmorText.text != null && !charArmorText.text.Equals(""))
     {
         selectedItem = selectedCharacter.currentEquipment.currentArmor;
         StartCoroutine("SelectButton", equipPanelSelectedButton);
     }
 }
예제 #28
0
    private void EquipItem(EquipableItem item)
    {
        UnequipItem(equippedItem);

        GetComponent <Animator>().SetTrigger("Grabbing");

        equippedItem = item;
    }
예제 #29
0
 //equip item to character
 public void EquipItem(EquipableItem itemToEquip)
 {
     gcReference.EquipInventoryItem(itemToEquip, actualCharacterToEquip);
     for (int cont = 0; cont < equipmentPanelButtons.Count; cont++)
     {
         SetEquipableItemToButton(equipmentPanelButtons[cont]);
     }
 }
예제 #30
0
//Method to Remove Weapon
    public void RemoveItem(EquipableItem item)
    {
        player.GetComponent <Player>().damage -= item.StrengthBonus;
        player.GetComponent <PlayerMovement>().movementSpeed -= item.AgilityBonus;
        items.RemoveAt(0);
        items.Insert(0, null);
        RefreshUI();
        return;
    }
 //Adding an item
 public void collectItem(EquipableItem item)
 {
     equipableItems.Add(item);
 }
 //Removing an item
 public void removeItem(EquipableItem item)
 {
     equipableItems.Remove(item);
 }
 public void add(WeaponSlot slot, EquipableItem item)
 {
     equippedWeapons.Add(slot, item);
 }