Ejemplo n.º 1
0
    public void Test_PlayerStartsWithEmptyInventory()
    {
        PlayerInventoryClass inventory = new PlayerInventoryClass();

        Assert.IsEmpty(inventory.GetCollectedItems(), "Player didn't start with an empty inventory!");
        Assert.IsNull(inventory.GetEquippedWeapon(), "Player didn't start without a weapon!");
    }
Ejemplo n.º 2
0
    public void Test_PlayerCanFindCollectItemsInInventory()
    {
        PlayerInventoryClass inventory = new PlayerInventoryClass();
        Item item = ScriptableObject.CreateInstance <Item>();

        inventory.CollectItem(item);

        Assert.IsTrue(inventory.PlayerHasItem(item), "Player didn't find the collected item in the inventory!");
    }
Ejemplo n.º 3
0
    public void Test_PlayerCanEquipWeapon()
    {
        Weapon weapon = ScriptableObject.CreateInstance <Weapon>();
        PlayerInventoryClass inventory = new PlayerInventoryClass();

        inventory.EquipWeapon(weapon);

        Assert.IsNotNull(inventory.GetEquippedWeapon(), "Player didn't equip a weapon!");
    }
Ejemplo n.º 4
0
    public void Test_PlayerCanCollectItems()
    {
        PlayerInventoryClass inventory = new PlayerInventoryClass();
        Item item = ScriptableObject.CreateInstance <Item>();

        inventory.CollectItem(item);

        Assert.IsNotEmpty(inventory.GetCollectedItems(), "Player wasn't able to collect an item into the inventory!");
        Assert.IsTrue(inventory.PlayerHasItem(item), "Player doesn't have the collected item in the inventory!");
    }
Ejemplo n.º 5
0
    public void InventoryUIButtonClick(int index)
    {
        PlayerInventoryClass inventory = GameCtr.player.GetPlayerInventory();

        if (index < inventory.items.Count)
        {
            inventory.UseItem(index);
        }
        UpdateInventoryUI();
    }
Ejemplo n.º 6
0
    public void Test_PlayerInventoryCannotCollectMoreItemsWhenFull()
    {
        PlayerInventoryClass inventory = new PlayerInventoryClass();

        inventory.MaxItemSlots = 0;
        Item item = ScriptableObject.CreateInstance <Item>();

        inventory.CollectItem(item);

        Assert.IsEmpty(inventory.items);
        LogAssert.Expect(LogType.Warning, "Inventory full, could not collect item!");
    }
Ejemplo n.º 7
0
    public void Test_PlayerCanRemoveItem()
    {
        PlayerInventoryClass inventory = new PlayerInventoryClass();
        Item item = ScriptableObject.CreateInstance <Item>();

        inventory.CollectItem(item);

        Assert.IsNotEmpty(inventory.GetCollectedItems(), "Player wasn't able to collect an item into the inventory!");

        inventory.RemoveItem(item);

        Assert.IsEmpty(inventory.GetCollectedItems(), "Player wasn't able to remove an item from the inventory!");
    }
Ejemplo n.º 8
0
    public void Test_PlayerInventoryCanCollectMoreItemsWhenStillSpace()
    {
        PlayerInventoryClass inventory = new PlayerInventoryClass();

        inventory.MaxItemSlots = 2;
        Item item = ScriptableObject.CreateInstance <Item>();

        inventory.CollectItem(item);

        Assert.IsNotEmpty(inventory.items);
        Assert.IsTrue(inventory.PlayerHasItem(item));
        LogAssert.NoUnexpectedReceived();
    }
Ejemplo n.º 9
0
    public void Test_PlayerInventoryDoesntRemoveItemsThatStillHaveUsesLeft()
    {
        PlayerInventoryClass inventory = new PlayerInventoryClass();
        PlayerStatsClass     stats     = new PlayerStatsClass();
        Item item = ScriptableObject.CreateInstance <Item>();

        inventory.CollectItem(item);

        Assert.IsNotEmpty(inventory.GetCollectedItems(), "Player wasn't able to collect an item into the inventory!");

        item.Use(stats);

        Assert.IsNotEmpty(inventory.GetCollectedItems(), "Player inventory auto-removed an item that still had uses left!");
    }
Ejemplo n.º 10
0
    void Start()
    {
        if (GameCtr == null)
        {
            GameCtr = FindObjectOfType <GameController>();
        }

        if (stats == null)
        {
            stats = new PlayerStatsClass();
        }
        stats.SetUpPlayerStats(this);
        if (inventory == null)
        {
            inventory = new PlayerInventoryClass();
        }
        inventory.SetUpInventory(this);

        if (staticService == null)  // only setup staticServe anew if it's not there already (a playmode test might have set a substitute object here that we don't want to replace)
        {
            staticService = new UnityStaticService();
        }

        foreach (Item i in inventory.items)
        {
            if (i != null)
            {
                i.SetUpItem();
            }
        }

        if (healthBar != null)
        {
            healthBar.transform.parent.gameObject.SetActive(false);
        }
        if (turnTimeBar != null)
        {
            turnTimeBar.transform.parent.gameObject.SetActive(false);
        }

        if (stats.dodged != null)
        {
            stats.dodged.SetActive(false);
        }

        if (charContr == null)
        {
            charContr = GetComponent <CharacterController>();
        }
    }
Ejemplo n.º 11
0
    public void Test_PlayerInventoryRemovesItemsWithNoMoreUsesLeft()
    {
        PlayerInventoryClass inventory = new PlayerInventoryClass();
        PlayerStatsClass     stats     = new PlayerStatsClass();
        Item item = ScriptableObject.CreateInstance <Item>();

        inventory.CollectItem(item);

        Assert.IsNotEmpty(inventory.GetCollectedItems(), "Player wasn't able to collect an item into the inventory!");

        item.Use(stats);
        item.Use(stats);
        item.Use(stats);

        Assert.IsEmpty(inventory.GetCollectedItems(), "Player inventory didn't auto-remove item with no more uses left!");
    }
Ejemplo n.º 12
0
    public void Test_PlayerReceivesDamageIncreaseFromEquippedWeapon()
    {
        Weapon               weapon    = ScriptableObject.CreateInstance <Weapon>();
        PlayerStatsClass     stats     = new PlayerStatsClass();
        PlayerInventoryClass inventory = new PlayerInventoryClass();

        int damageWithoutWeapon = stats.GetCurrentAttackDamage();

        inventory.EquipWeapon(weapon);

        IPlayer mockPlayer = Substitute.For <IPlayer>();

        mockPlayer.GetAllDamageBonus().Returns(inventory.GetEquippedWeapon().damage);
        stats.SetPlayerAddition(mockPlayer);

        int damageAfterEquip = stats.GetCurrentAttackDamage();

        Assert.IsNotNull(inventory.GetEquippedWeapon(), "Player didn't equip the weapon!");
        Assert.Greater(damageAfterEquip, damageWithoutWeapon, "Player damage did not increase after equipping a weapon!");
    }
Ejemplo n.º 13
0
    public void UpdateSlotInteractability()
    {
        int index = 0;

        if (slots == null)
        {
            return;
        }

        foreach (Button slot in slots)
        {
            PlayerInventoryClass inventory = GameCtr.player.GetPlayerInventory();
            if (slot != null &&
                inventory != null &&
                GameCtr != null)
            {
                if (GameCtr.player.stats.CanAct() &&
                    index < inventory.items.Count)
                {
                    slot.interactable = true;

                    Item item = inventory.items[index];
                    if (item != null &&
                        item.type == ItemType.AttackBoost)
                    {
                        PlayerStatsClass stats = GameCtr.player.GetPlayerStats();
                        if (stats != null && stats.lastingDamageBoosts.ContainsKey("Boost Item"))
                        {
                            slot.interactable = false;
                        }
                    }
                }
                else
                {
                    slot.interactable = false;
                }
            }
            index++;
        }
    }
Ejemplo n.º 14
0
    public void UpdateInventoryUI()
    {
        int index = 0;

        if (slots == null)
        {
            return;
        }

        foreach (Button slot in slots)
        {
            PlayerInventoryClass inventory = GameCtr.player.GetPlayerInventory();
            if (slot != null &&
                inventory != null)     // todo: what does MaxItemCounts control?
            {
                if (slot.transform.GetChild(0) != null)
                {
                    Image img = GetImageOfSlot(slot);
                    if (img != null)
                    {
                        if (index < inventory.items.Count)
                        {
                            Item item = inventory.items[index];
                            if (item != null)
                            {
                                img.sprite  = item.GetIcon();
                                img.enabled = true;
                            }
                            else
                            {
                                img.enabled = false;
                            }
                        }
                        else
                        {
                            img.enabled = false;
                        }
                    }
                }

                if (slot.transform.GetChild(1) != null)
                {
                    TextMeshProUGUI uses = GetUsesTextOfSlot(slot);
                    if (uses != null)
                    {
                        if (index < inventory.items.Count)
                        {
                            Item item = inventory.items[index];
                            if (item != null)
                            {
                                uses.text = item.GetUsesLeft().ToString();
                            }
                            else
                            {
                                uses.text = "";
                            }
                        }
                        else
                        {
                            uses.text = "";
                        }
                    }
                }
            }
            index++;
        }
    }