Exemplo n.º 1
0
    public void Test_PlayerDoesntMoveWithoutInput()
    {
        PlayerStatsClass    stats         = new PlayerStatsClass();
        IUnityStaticService staticService = CreateUnityService(1, 0, 0);

        Vector3 calculatedMovement = stats.CalcMovement(staticService.GetInputAxis("Horizontal"), staticService.GetInputAxis("Vertical"), staticService.GetDeltaTime());

        Assert.Zero(calculatedMovement.magnitude, "Player moved without input!");
    }
Exemplo n.º 2
0
    public void Test_PlayerPointsCannotDropBelowZero()
    {
        PlayerStatsClass stats      = new PlayerStatsClass();
        const int        lostPoints = -10;

        stats.ModifyPoints(lostPoints);

        Assert.Zero(stats.GetCurrentPoints(), "Player lost more points that he had and dropped below zero!");
    }
Exemplo n.º 3
0
    public void Test_PlayerCanGainPoints()
    {
        PlayerStatsClass stats        = new PlayerStatsClass();
        const int        gainedPoints = 10;
        int expectedPoints            = stats.GetCurrentPoints() + gainedPoints;

        stats.ModifyPoints(gainedPoints);

        Assert.AreEqual(expectedPoints, stats.GetCurrentPoints(), "Player didn't gain the expected amount of points!");
        Assert.NotZero(stats.GetCurrentPoints(), "Player didn't gain any points!");
    }
Exemplo n.º 4
0
    public void Test_PlayerCanLosePoints()
    {
        PlayerStatsClass stats        = new PlayerStatsClass();
        const int        gainedPoints = 20;
        const int        lostPoints   = -10;
        int expectedPoints            = stats.GetCurrentPoints() + gainedPoints + lostPoints;

        stats.ModifyPoints(gainedPoints);
        stats.ModifyPoints(lostPoints);

        Assert.AreEqual(expectedPoints, stats.GetCurrentPoints(), "Player didn't lose the expected amount of points!");
        Assert.AreNotEqual(gainedPoints, stats.GetCurrentPoints(), "Player didn't lose any points!");
    }
Exemplo n.º 5
0
    public void Test_PlayerStatsHasDeclaredOwnShowDodgeFunction()
    {
        PlayerStatsClass stats          = new PlayerStatsClass();
        IPlayer          mockPlayer     = Substitute.For <IPlayer>();
        IGameController  mockController = Substitute.For <IGameController>();

        mockPlayer.GetGameController().Returns(mockController);
        stats.SetPlayerAddition(mockPlayer);

        stats.ShowDodge();

        LogAssert.NoUnexpectedReceived();
    }
Exemplo n.º 6
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>();
        }
    }
Exemplo n.º 7
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!");
    }
Exemplo n.º 8
0
    public void Test_ItemCannotBeUsedMoreThanMaxUses()
    {
        PlayerStatsClass stats = new PlayerStatsClass();
        Item             item  = ScriptableObject.CreateInstance <Item>();

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

        item.Use(stats);

        Assert.Zero(item.GetUsesLeft(), "Item could be used even though it had 0 uses left!");
        LogAssert.Expect(LogType.Warning, "Tried to use item when it had 0 uses left. No effect!");
    }
Exemplo n.º 9
0
    public void Test_PlayerCantMoveWhileInBattle()
    {
        PlayerStatsClass    stats         = new PlayerStatsClass();
        IUnityStaticService staticService = CreateUnityService(1, 1, 1);
        IGameController     ctr           = Substitute.For <IGameController>();

        ctr.IsInBattle().Returns(true);
        IPlayer mockPlayer = Substitute.For <IPlayer>();

        mockPlayer.GetGameController().Returns(ctr);
        stats.SetPlayerAddition(mockPlayer);

        Vector3 calculatedMovement = stats.CalcMovement(staticService.GetInputAxis("Horizontal"), staticService.GetInputAxis("Vertical"), staticService.GetDeltaTime());

        Assert.Zero(calculatedMovement.magnitude, "Player was able to move while in battle!");
    }
Exemplo n.º 10
0
    public void Test_PlayerMovementIsCalculatedCorrectly()
    {
        PlayerStatsClass    stats         = new PlayerStatsClass();
        IUnityStaticService staticService = CreateUnityService(1, 1, 1);

        float expectedX = staticService.GetInputAxis("Horizontal") * stats.playerSpeed * staticService.GetDeltaTime();
        float expectedY = 0;
        float expectedZ = staticService.GetInputAxis("Vertical") * stats.playerSpeed * staticService.GetDeltaTime();

        Vector3 calculatedMovement = stats.CalcMovement(staticService.GetInputAxis("Horizontal"), staticService.GetInputAxis("Vertical"), staticService.GetDeltaTime());

        Assert.NotZero(calculatedMovement.magnitude, "Player movement calculation resulted in no movement!");
        Assert.AreEqual(calculatedMovement.x, expectedX, "Player movement calculation did not return the expected x movement!");
        Assert.AreEqual(calculatedMovement.y, expectedY, "Player movement calculation did not return the expected y movement!");
        Assert.AreEqual(calculatedMovement.z, expectedZ, "Player movement calculation did not return the expected z movement!");
    }
Exemplo 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!");
    }
Exemplo n.º 12
0
    public void Test_ItemCanHealPlayer()
    {
        PlayerStatsClass stats = new PlayerStatsClass();

        stats.ReceiveDamage(50);
        int damagedHealth = stats.GetCurrentHealth();

        Item item = ScriptableObject.CreateInstance <Item>();

        item.type = ItemType.Healing;
        item.Use(stats);

        int healedHealth = stats.GetCurrentHealth();

        Assert.Greater(healedHealth, damagedHealth, "Using a healing item did not increase the players health!");
    }
Exemplo n.º 13
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!");
    }
Exemplo n.º 14
0
    public void Test_PlayerGainsPointsAfterKillingAnEnemy()
    {
        PlayerStatsClass player = new PlayerStatsClass();

        player.AttackDamage = 500;
        IGameController mockController = Substitute.For <IGameController>();

        mockController.GetPlayerStats().Returns(player);
        EnemyStatsClass enemy = new EnemyStatsClass();

        enemy.SetUpEnemyStats(mockController);


        int pointsBefore = player.GetCurrentPoints();

        player.AttackOpponent(enemy, false, true);
        int pointsAfter = player.GetCurrentPoints();

        Assert.Greater(pointsAfter, pointsBefore, "Player did not receive any points after killing an enemy!");
    }
Exemplo n.º 15
0
    public override void HandleDeath()
    {
        base.HandleDeath();
        if (GameCtr != null)
        {
            PlayerStatsClass player = GameCtr.GetPlayerStats();
            if (player != null)
            {
                player.ModifyPoints(PointsToGain);
            }
            if (GameCtr.GetCurrentEnemies() != null)
            {
                Enemy enemy = GameCtr.GetCurrentEnemies()[0];
                GameCtr.HandleDeath(enemy.transform, enemy.DeathParticle, enemy.DeathParticleLength, new Vector3(0, 0, 0));
                SoundEffectControl sfx = GameCtr.GetSFXControl();
                if (sfx != null)
                {
                    sfx.EnemyDeath();
                }

                if (lockedDoor != null)
                {
                    ItemDrop key = lockedDoor.OnEnemyDied();
                    if (key != null)
                    {
                        ItemDrop droppedKey = GameObject.Instantiate(key, enemy.transform.position, enemy.transform.rotation);
                        droppedKey.door = lockedDoor;
                    }
                    else
                    {
                        enemy.DropRandomItem();
                    }
                }
                else
                {
                    enemy.DropRandomItem();
                }
            }
        }
    }
Exemplo n.º 16
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++;
        }
    }
Exemplo n.º 17
0
    public void Test_PlayerGainsNoPointsAfterTryingToKillADeadEnemy()
    {
        PlayerStatsClass player = new PlayerStatsClass();

        player.AttackDamage = 500;
        IGameController mockController = Substitute.For <IGameController>();

        mockController.GetPlayerStats().Returns(player);
        EnemyStatsClass enemy = new EnemyStatsClass();

        enemy.SetUpEnemyStats(mockController);


        player.AttackOpponent(enemy, false, true);
        int pointsAfterFirstKill = player.GetCurrentPoints();

        player.AttackOpponent(enemy, false, true);
        int pointsAfterSecondKill = player.GetCurrentPoints();

        Assert.AreEqual(pointsAfterFirstKill, pointsAfterSecondKill, "Player received points after trying to kill an enemy that's already dead!");
        LogAssert.Expect(LogType.Warning, "Fighter tried to attack an opponent that already died. Can't attack dead opponents!");
    }
Exemplo n.º 18
0
    void Start()
    {
        player      = FindObjectOfType <Player>();
        playerStats = player.stats;

        musicControl = FindObjectOfType <MusicControl>();
        sfxControl   = FindObjectOfType <SoundEffectControl>();

        battleUI      = GameObject.Find("BattleUI");
        attackBtn     = GameObject.Find("AttackBtn");
        chargeBtn     = GameObject.Find("ChargeBtn");
        fleeBtn       = GameObject.Find("FleeBtn");
        redX          = GameObject.Find("X");
        gameUI        = GameObject.Find("GameUI");
        gameOverUI    = GameObject.Find("GameOverUI");
        introUI       = GameObject.Find("IntroUI");
        blackScreenUI = GameObject.Find("BlackScreenUI");
        gameEndUI     = GameObject.Find("GameEndUI");
        inventoryUI   = GameObject.Find("InventoryUI");

        if (battleUI != null)
        {
            battleUI.SetActive(false);
        }
        if (attackBtn != null)
        {
            attackBtnScript = attackBtn.GetComponent <Button>();
            if (attackBtnScript != null)
            {
                attackBtnScript.interactable = false;
                if (attackBtnScript.transform.childCount > 0)
                {
                    Transform textObject = attackBtnScript.transform.GetChild(0);
                    if (textObject != null)
                    {
                        attackBtnText = textObject.GetComponent <TextMeshProUGUI>();
                    }
                }
            }
        }
        if (chargeBtn != null)
        {
            chargeBtnScript = chargeBtn.GetComponent <Button>();
            if (chargeBtnScript != null)
            {
                chargeBtnScript.interactable = false;
                if (chargeBtnScript.transform.childCount > 0)
                {
                    Transform textObject = chargeBtnScript.transform.GetChild(0);
                    if (textObject != null)
                    {
                        chargeBtnText = textObject.GetComponent <TextMeshProUGUI>();
                    }
                }
            }
        }
        if (fleeBtn != null)
        {
            fleeBtnScript = fleeBtn.GetComponent <Button>();
            if (fleeBtnScript != null)
            {
                fleeBtnScript.interactable = false;
            }
        }

        if (gameUI != null)
        {
            Transform textObj = gameUI.transform.Find("PointsText");
            if (textObj != null)
            {
                pointsText = textObj.gameObject.GetComponent <TextMeshProUGUI>();
                if (pointsText != null)
                {
                    pointsText.text = "0";
                }
            }
        }
        if (gameOverUI != null)
        {
            gameOverUI.SetActive(false);
        }
        if (blackScreenUI != null)
        {
            Transform blackImg = blackScreenUI.transform.GetChild(0);
            if (blackImg != null)
            {
                black = blackImg.GetComponent <Image>();
                if (black != null)
                {
                    black.gameObject.SetActive(true);
                    //black.CrossFadeAlpha(0, introFadeDuration, true);
                }
            }
        }
        if (introUI != null)
        {
            Transform bg = introUI.transform.GetChild(0);
            if (bg != null)
            {
                introBg = bg.GetComponent <Image>();
                if (introBg != null)
                {
                    introBg.gameObject.SetActive(true);
                    introBg.CrossFadeAlpha(1, introFadeDuration, true);

                    introText = introBg.GetComponentInChildren <TextMeshProUGUI>();
                    if (introText != null)
                    {
                        introText.gameObject.SetActive(true);
                        introText.CrossFadeAlpha(1, introFadeDuration, true);
                    }
                }
            }
        }
        if (gameEndUI != null)
        {
            Transform whiteImg = gameEndUI.transform.GetChild(0);
            if (whiteImg != null)
            {
                white = whiteImg.GetComponent <Image>();
                if (white != null)
                {
                    white.gameObject.SetActive(true);
                    white.CrossFadeAlpha(0, 0, true);
                    endText = white.GetComponentInChildren <TextMeshProUGUI>();
                    if (endText != null)
                    {
                        endText.gameObject.SetActive(true);
                        endText.CrossFadeAlpha(0, 0, true);
                    }
                }
            }
        }
        if (inventoryUI != null)
        {
            inventoryUI.SetActive(false);
        }

        if (gameCam == null)
        {
            gameCam = FindObjectOfType <CameraFollow>();
        }

        if (NormalRoom != null)
        {
            NormalRoom.SetActive(true);
        }
        if (BrokenRoom != null)
        {
            BrokenRoom.SetActive(false);
        }
    }