예제 #1
0
 void CmdEquipItem(int slot)
 {
     if (items[slot] is Equipment)
     {
         equipmentManager.Equip((Equipment)items[slot]);
         RpcEquipItem(slot);
         Remove(items[slot]);
     }
 }
예제 #2
0
    /// <summary>
    /// Determines what happens when clicking on the equipment slot
    /// </summary>
    public void OnCLick()
    {
        if (InventoryScript.instance.FromSlot == null)
        {
            // if I have nothing in my hand
            if (HandScript.instance.MyMoveable == null)
            {
                HandScript.instance.TakeMoveable(equipment as IMoveable);
                InventoryScript.instance.FromEqippedSlot = this;
            }
        }

        else if (InventoryScript.instance.FromSlot != null)
        {
            bool matchingSlot = equipManager.CheckIfSlotMatchesType(slotId, HandScript.instance.MyMoveable as Equipment);

            if (matchingSlot)
            {
                bool equipSuccess = equipManager.Equip(HandScript.instance.MyMoveable as Equipment);

                if (equipSuccess)
                {
                    HandScript.instance.Drop();
                    InventoryScript.instance.FromSlot.Clear();
                    InventoryScript.instance.FromSlot = null;
                }
            }
        }
    }
예제 #3
0
    public override void Slot(UIItem uIItem)
    {
        Equipable ep = (Equipable)uIItem.LinkedItem;

        if (ep == null)
        {
            Debug.Log("The item " + ep.name + " is not an equipable");
            return;
        }

        if (equipableType == ep.equipableType)
        {
            base.Slot(uIItem);

            uIItem.RemoveFromWindow();
            equipment.AddGraphics(uIItem.Graphics);

            uIItem.RectTransform.SetParent(_rectTransform);
            uIItem.RectTransform.anchoredPosition = Vector3.zero;
            uIItem.SetState(this, true, true, true, false);

            equipmentManager.Equip(ep);

            if (Equipable.IsHand(equipableType))
            {
                uIItem.SizeUI(new Vector2Int((int)size, (int)size));
            }
            Debug.Log("The item " + ep.name + " was sloted in equipment");
        }
        else
        {
            Debug.Log("The item " + ep.name + " is not of the equipment type " + equipableType.ToString());
        }
    }
예제 #4
0
    public void OnLoad()
    {
        PlayerPasser     loadedplayer = FindObjectOfType <PlayerPasser>();
        PlayerStats      stats        = player.GetComponent <PlayerStats>();
        EquipmentManager equipmanager = player.GetComponent <EquipmentManager>();
        Inventory        inventory    = player.GetComponent <Inventory>();
        PlayerAnimator   animator     = player.GetComponent <PlayerAnimator>();

        stats.id            = loadedplayer.playerid;
        stats.CharacterName = loadedplayer.CharacterName;
        stats.coins         = loadedplayer.coins;
        stats.level         = loadedplayer.level;
        stats.currentHealth = loadedplayer.currentHealth;
        stats.maxHealth     = loadedplayer.maxHealth;
        stats.maxExp        = loadedplayer.maxExp;
        stats.currentExp    = loadedplayer.currentExp;
        stats.currentMana   = loadedplayer.currentMana;
        stats.maxMana       = loadedplayer.maxMana;
        stats.defense.SetValue(loadedplayer.defense);
        stats.strength.SetValue(loadedplayer.strength);
        stats.dexterity.SetValue(loadedplayer.dexterity);
        stats.intelligence.SetValue(loadedplayer.intelligence);

        for (int i = 0; i < loadedplayer.equipmentlist.Count; i++)
        {
            equipmanager.Equip(loadedplayer.equipmentlist[i]);
            animator.OnEquipmentChanged(loadedplayer.equipmentlist[i], null);
        }
        foreach (Item item in loadedplayer.itemlist)
        {
            inventory.Add(item);
        }
    }
예제 #5
0
파일: Menu.cs 프로젝트: MHatfull/Simulator
 private void OnInventorySlotClicked(Collectable collectable)
 {
     if (collectable is Equipment)
     {
         _equipmentManager.Equip((Equipment)collectable);
         _inventoryManager.Remove(collectable);
     }
 }
예제 #6
0
    /// <summary>
    /// Equips the item.
    /// </summary>
    /// <param name="obj">The GameObject (Player) that wants to execute this action.</param>
    /// <returns>Returns true if the item was equipped successfully, false otherwise.</returns>
    public override bool Execute(GameObject obj)
    {
        invPanel = GameObject.FindGameObjectWithTag("InventoryPanel").GetComponent <InventoryPanel>();
        eqPanel  = GameObject.FindGameObjectWithTag("EquipmentPanel").GetComponent <EquipmentPanel>();
        EquipmentManager equipManager = eqPanel.Manager;
        UsableItem       useItem      = toEquip as UsableItem;
        EquippableItem   equipItem    = toEquip as EquippableItem;

        if (equipItem != null)
        {
            EquippableItem currentlyEquipped = equipManager.DeEquip(equipItem.Slot);
            Debug.Log(equipItem);
            invPanel.ManagedInventory.RemoveItem(toEquip);
            if (currentlyEquipped == null || invPanel.ManagedInventory.AddItem(currentlyEquipped) == null)
            {
                // eqPanel.Manager = equipManager;
                equipManager.Equip(equipItem); // this should not fail
                return(true);
            }
            else
            {
                invPanel.ManagedInventory.AddItem(equipItem);
                equipManager.Equip(currentlyEquipped);
                return(false);
            }
        }
        else if (useItem != null)
        {
            bool yay = false;
            for (int i = 0; i < equipManager.GetHotbarItemsSize(); i++)
            {
                yay = equipManager.AddHotBarItem(useItem, i);
                if (yay)
                {
                    invPanel.ManagedInventory.RemoveItem(useItem);
                    break;
                }
            }
            return(yay);
        }
        else
        {
            throw new UnityException("WTF are you trying to equip my man");
        }
    }
예제 #7
0
    public void LoadEquipment()
    {
        EquipmentData data = SaveSystem.LoadEquipment();

        for (int i = 0; i < data.equipment.Length; i++)
        {
            if (data.equipment[i] != null)
            {
                equipmentManager.Equip(Resources.Load(data.equipmentSlot[i] + "/" + data.equipment[i]) as Equipment, false);
                DropdownManager.instance.LoadEquipment(data.equipment[i], data.equipmentSlot[i]);
            }
        }
    }
예제 #8
0
    private void Interact()
    {
        RaycastHit hit;

        if (Physics.Raycast(camera.transform.position, camera.transform.forward, out hit, interactionDistance, interactionLayerMask))
        {
            Equipment equipment = hit.collider.GetComponentInParent <Equipment>();
            if (equipment)
            {
                equipmentManager.Equip(equipment);
            }
        }
    }
예제 #9
0
    public override void Use()
    {
        switch (classRequired)
        {
        case ClassRequired.Warrior:
            equipmentManager = GameObject.Find("Warrior").GetComponent <EquipmentManager>();
            break;

        case ClassRequired.Rogue:
            equipmentManager = GameObject.Find("Rogue").GetComponent <EquipmentManager>();
            break;

        case ClassRequired.Mage:
            equipmentManager = GameObject.Find("Mage").GetComponent <EquipmentManager>();
            break;

        case ClassRequired.Paladin:
            equipmentManager = GameObject.Find("Paladin").GetComponent <EquipmentManager>();
            break;
        }
        base.Use();
        equipmentManager.Equip(this);
        RemoveFromInventory();
    }
예제 #10
0
    public void Equip(EquiptmentSO eq)
    {
        equipmentManager.Equip(eq, eq.type);

        Remove(eq);
    }
예제 #11
0
 public override void PickUp(GameObject entity)
 {
     base.PickUp(entity);
     equipmentManager = entity.GetComponentInChildren <EquipmentManager>();
     equipmentManager.Equip(this);
 }
예제 #12
0
 public override void Use()
 {
     base.Use();
     equipmentManager.Equip(this);
     RemoveFromInventory();
 }
예제 #13
0
    private void Draw()
    {
        GameObject panel = inventoryUI.transform.GetChild(0).gameObject;

        // Clean panel first
        foreach (Transform child in panel.transform)
        {
            Destroy(child.gameObject);
        }

        // Store reference for performance
        List <ScriptableItem> inventoryItems = inventory.ListAll();

        List <ScriptableItem> visited        = new List <ScriptableItem>();
        List <GameObject>     visitedButtons = new List <GameObject>();

        foreach (ScriptableItem item in inventoryItems)
        {
            GameObject itemButton = null;

            int visitedIndex = item.stackable ? visited.FindIndex(entry => entry.name == item.name) : -1;

            // Check if visited contains this item
            if (visitedIndex != -1)
            {
                GameObject stackCounter = FindNestedGameObjectByTag(visitedButtons[visitedIndex], Constants.UI_INVENTORY_STACK);
                itemButton = visitedButtons[visitedIndex];

                // Count all existing items so far
                int count = inventoryItems.FindAll(inventoryItem => inventoryItem.name == visited[visitedIndex].name).Count;

                stackCounter.GetComponent <Text>().text = "x" + count;
            }
            else
            {
                // Register item in visited list for stackable cases
                visited.Add(item);

                // Instantiate Item Button
                itemButton = Instantiate(itemButtonPrefab);
                visitedButtons.Add(itemButton);
            }

            // Icon imagery logic
            GameObject sprite = FindNestedGameObjectByTag(itemButton, Constants.UI_INVENTORY_IMAGE);
            if (sprite != null)
            {
                sprite.GetComponent <Image>().sprite = item.icon;
            }

            // Parent item button to panel
            itemButton.transform.SetParent(panel.transform);

            // @ Equippable Item Logic
            if (item.graphic != null)
            {
                // @ If item is already equipped, show Equipped banner
                ScriptableItem equippedItem = equipmentManager.GetEquippedItem(item.slot);

                GameObject equippedBanner = FindNestedGameObjectByTag(itemButton, Constants.UI_INVENTORY_EQUIPPED);
                equippedBanner.SetActive(false);

                if (equippedItem == item)
                {
                    // Search for the Equipped Banner and activate it
                    equippedBanner?.SetActive(true);
                }

                itemButton.GetComponent <Button>().onClick.AddListener(() => {
                    // @Is Item equipped already?
                    if (equippedItem == item)
                    {
                        equipmentManager.Unequip(item.slot);
                        equippedBanner?.SetActive(false);
                    }
                    else
                    {
                        equipmentManager.Equip(item.slot, item);
                        equippedBanner?.SetActive(true);
                    }

                    // Redraw
                    Draw();
                });
            }
        }
    }
예제 #14
0
    public void EquipmentEquip()
    {
        // Test chest plate is equipped to chest slot.
        Assert.IsTrue(equips.Equip(chestPlate));
        EquippableItem chestAgain = equips.GetEquippedItem(EquipmentManager.EquipSlot.CHEST);

        Assert.IsNotNull(chestAgain);
        Assert.IsInstanceOf <ArmorItem>(chestAgain);
        Assert.AreEqual(10, ((ArmorItem)chestAgain).Armor);

        // Test that the ring is equipped to the ring slot.
        Assert.IsTrue(equips.Equip(ring));
        EquippableItem ringAgain = equips.GetEquippedItem(EquipmentManager.EquipSlot.RING);

        Assert.IsNotNull(ringAgain);

        // Test that an item cannot be equipped to a slot with an item already.
        Assert.IsFalse(equips.Equip(chestPlate));
    }