Exemple #1
0
    public void Use(FighterStatsClass user, IGameController gameCtr = null)
    {
        if (usesLeft == 0)
        {
            Debug.LogWarning("Tried to use item when it had 0 uses left. No effect!");
            return;
        }
        if (user == null)
        {
            Debug.LogWarning("Tried to use item without a user. No effect!");
            return;
        }

        switch (type)
        {
        case ItemType.AttackBoost:
            user.AddLastingDamageBoost("Boost Item", 1.2f);
            if (gameCtr != null)
            {
                SoundEffectControl sfx = gameCtr.GetSFXControl();
                if (sfx != null)
                {
                    sfx.Boost();
                }
            }
            break;

        case ItemType.Healing:
            user.GetHealedBy(80);

            if (gameCtr != null)
            {
                SoundEffectControl sfx = gameCtr.GetSFXControl();
                if (sfx != null)
                {
                    sfx.Heal();
                }
            }
            break;

        case ItemType.DealDamage:
            if (gameCtr != null)
            {
                gameCtr.PlayerThrowBomb();
            }
            break;

        default:
            Debug.LogWarning("There was no behavior specified for item of type " + type.ToString());
            break;
        }
        usesLeft--;
    }
Exemple #2
0
    public void Test_FighterCanReceiveMultipleLastingDamageBoosts()
    {
        FighterStatsClass stats = new FighterStatsClass();
        int normalDamage        = stats.GetCurrentAttackDamage();

        string sourceA = "Item A";
        float  boostA  = 0.2f;

        stats.AddLastingDamageBoost(sourceA, boostA);
        int firstBoostDamage = stats.GetCurrentAttackDamage();

        string sourceB = "Item B";
        float  boostB  = 0.2f;

        stats.AddLastingDamageBoost(sourceB, boostB);
        int secondBoostDamage = stats.GetCurrentAttackDamage();

        Assert.Contains(sourceA, stats.lastingDamageBoosts.Keys, "Lasting damage boosts don't contain a boost from source A!");
        Assert.Contains(sourceB, stats.lastingDamageBoosts.Keys, "Lasting damage boosts don't contain a boost from source B!");
        Assert.Less(normalDamage, firstBoostDamage, "First lasting damage boost didn't increase attack damage!");
        Assert.Less(firstBoostDamage, secondBoostDamage, "Second lasting damage boost didn't increase attack damage");
    }
Exemple #3
0
    public void Test_FighterCanReceiveLastingDamageBoost()
    {
        FighterStatsClass stats = new FighterStatsClass();
        int oldDamage           = stats.GetCurrentAttackDamage();

        string source = "Weapon X";
        float  boost  = 0.2f;

        stats.AddLastingDamageBoost(source, boost);

        int newDamage = stats.GetCurrentAttackDamage();

        Assert.Less(oldDamage, newDamage, "Lasting damage boost didn't increase attack damage!");
    }
Exemple #4
0
    public void Test_FighterCanReceiveOnlyOneLastingDamageBoostFromSameSource()
    {
        FighterStatsClass stats = new FighterStatsClass();

        string sourceA = "Item A";
        float  boostA  = 0.2f;

        stats.AddLastingDamageBoost(sourceA, boostA);
        int boostedDamage = stats.GetCurrentAttackDamage();

        try
        {
            stats.AddLastingDamageBoost(sourceA, boostA);
            Assert.Fail("Managed to add two lasting damage boosts from the same source without ArgumentException, that shouldn't be possible.");
        }
        catch (System.ArgumentException)
        {
            // do nothing - we expected ArgumentException
        }
        int damageAfterAttemptedDuplication = stats.GetCurrentAttackDamage();

        LogAssert.Expect(LogType.Warning, "Fighter cannot receive multiple lasting damage boosts from the same source. Attacke damage will not be modified.");
        Assert.AreEqual(boostedDamage, damageAfterAttemptedDuplication, "Managed to add two lasting damage boosts from the same source and increase damage with both, that shouldn't be possible.");
    }
Exemple #5
0
    public void Test_FighterCanRemoveLastingDamageBoost()
    {
        FighterStatsClass stats = new FighterStatsClass();
        int normalDamage        = stats.GetCurrentAttackDamage();

        string sourceA = "Item A";
        float  boostA  = 0.2f;

        stats.AddLastingDamageBoost(sourceA, boostA);

        stats.RemoveLastingDamageBoost(sourceA);
        int damageAfterRemoval = stats.GetCurrentAttackDamage();

        Assert.IsEmpty(stats.lastingDamageBoosts.Keys, "Lasting damage boosts still contain a boost after it was removed!");
        Assert.AreEqual(normalDamage, damageAfterRemoval, "Lasting damage boost couldn't be removed!");
    }
Exemple #6
0
    public void Test_FighterCannotRemoveNonexistantLastingDamageBoost()
    {
        FighterStatsClass stats = new FighterStatsClass();

        string sourceA = "Item A";
        float  boostA  = 0.2f;

        stats.AddLastingDamageBoost(sourceA, boostA);
        int boostedDamage = stats.GetCurrentAttackDamage();

        stats.RemoveLastingDamageBoost("wrongSource");
        int damageAfterAttemptedRemoval = stats.GetCurrentAttackDamage();

        Assert.AreEqual(boostedDamage, damageAfterAttemptedRemoval, "Attack damage was modified after trying to remove a non-existant lasting damage boost!");
        Assert.IsNotEmpty(stats.lastingDamageBoosts.Keys, "Lasting damage boost of different source was removed when trying to remove one of a non-existant source!");
        LogAssert.Expect(LogType.Warning, "Fighter cannot remove lasting damage boost of a source that never gave him a boost. Attacke damage will not be modified.");
    }