コード例 #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!");
    }
コード例 #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!");
    }
コード例 #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!");
    }
コード例 #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!");
    }
コード例 #5
0
ファイル: InventoryUI.cs プロジェクト: LuisaPaetzold/ttgd
    public void InventoryUIButtonClick(int index)
    {
        PlayerInventoryClass inventory = GameCtr.player.GetPlayerInventory();

        if (index < inventory.items.Count)
        {
            inventory.UseItem(index);
        }
        UpdateInventoryUI();
    }
コード例 #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!");
    }
コード例 #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!");
    }
コード例 #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();
    }
コード例 #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!");
    }
コード例 #10
0
ファイル: Player.cs プロジェクト: LuisaPaetzold/ttgd
    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>();
        }
    }
コード例 #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!");
    }
コード例 #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!");
    }
コード例 #13
0
ファイル: InventoryUI.cs プロジェクト: LuisaPaetzold/ttgd
    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++;
        }
    }
コード例 #14
0
ファイル: InventoryUI.cs プロジェクト: LuisaPaetzold/ttgd
    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++;
        }
    }