Exemplo n.º 1
0
 public void Setup()
 {
     basicStat    = new Stat(10, 0, 10);
     modifiedStat = new Stat(1);
     modifiedStat.AddModifier(new Modifier(4));
     modifiedStat.AddModifier(new Modifier(-3));
 }
Exemplo n.º 2
0
    public void RemoveAllModifiersFromSource_Test()
    {
        object source1 = new object();
        object source2 = new object();
        Stat   stat    = new Stat();

        StatModifier[] mods = new StatModifier[]
        {
            new StatModifier(StatType.Strength, StatModifierType.Flat, 50f, source1),
            new StatModifier(StatType.Strength, StatModifierType.PercentAdd, 0.8f, source2),
            new StatModifier(StatType.Strength, StatModifierType.PercentMult, 1.0f, source2),
        };
        foreach (var m in mods)
        {
            stat.AddModifier(m);
        }

        Assert.That(stat.StatModifiers.Count, Is.EqualTo(3));

        stat.RemoveAllModifiersFromSource(source2);

        Assert.That(stat.StatModifiers.Count, Is.EqualTo(1));

        foreach (var m in stat.StatModifiers)
        {
            Assert.That(m.Source, Is.Not.EqualTo(source2));
        }
    }
Exemplo n.º 3
0
    public void RemoveModifier_Test()
    {
        StatModifier mod1 = new StatModifier(StatType.Strength, StatModifierType.Flat, 10f);
        StatModifier mod2 = new StatModifier(StatType.Strength, StatModifierType.PercentAdd, 0.05f);
        Stat         stat = new Stat();

        stat.AddModifier(mod1);
        stat.AddModifier(mod2);

        Assert.That(stat.StatModifiers.Count, Is.EqualTo(2));

        stat.RemoveModifier(mod1);

        Assert.That(stat.StatModifiers.Count, Is.EqualTo(1));
        Assert.That(stat.StatModifiers, Is.Not.Contains(mod1));
    }
    /*
     * Function: OnGemChanged
     * Parameters: newItem, oldItem
     * Description: when a new gem is equiped, the stats for the given skill are updated
     * and the stats for the old gem are removed if one was equiped.
     */
    public void OnGemChanged(Equipment newItem, Equipment oldItem)
    {
        if (newItem != null)
        {
            Damage.AddModifier(newItem.damageModifier);
            //armor.AddModifier(newItem.armorModifier);
            RageCost.AddModifier(newItem.rageModifier);
            //AttackSpeed.AddModifier(newItem.attackspeedModifier);
            Cooldown.AddModifier(newItem.cooldownModifier);
            Lifesteal.AddModifier(newItem.lifestealModifier);
            Radius.AddModifier(newItem.radiusModifier);
            LastTime.AddModifier(newItem.lastTimeModifier);
        }

        if (oldItem != null)
        {
            //armor.RemoveModifier(oldItem.armorModifier);
            Damage.RemoveModifier(oldItem.damageModifier);
            RageCost.RemoveModifier(oldItem.rageModifier);
            //AttackSpeed.RemoveModifier(oldItem.attackspeedModifier);
            Cooldown.RemoveModifier(oldItem.cooldownModifier);
            Lifesteal.RemoveModifier(oldItem.lifestealModifier);
            Radius.RemoveModifier(oldItem.radiusModifier);
            LastTime.RemoveModifier(oldItem.lastTimeModifier);
        }
    }
Exemplo n.º 5
0
    public void Init(float moveSpeed)
    {
        activeArea    = AreaController.instance.active_area;
        speed         = new Stat(moveSpeed, StatType.MoveSpeed);
        curTile       = activeArea.GetTile(transform.position);
        aI_Controller = GetComponent <AI_Controller>();

        // Modify this unit's speed to add randomness to each unit
        speed.AddModifier(Random.Range(-0.5f, 0.5f));
    }
Exemplo n.º 6
0
 public void ToggleOutput()
 {
     if (_goldOutput.ModifierCount == 0)
     {
         _goldOutput.AddModifier(_goldOutputModifier);
     }
     else
     {
         _goldOutput.ClearMods();
     }
 }
Exemplo n.º 7
0
 public void ToggleCapacity()
 {
     if (_goldCapacity.ModifierCount == 0)
     {
         _goldCapacity.AddModifier(_goldCapacityModifier);
     }
     else
     {
         _goldCapacity.ClearMods();
     }
 }
Exemplo n.º 8
0
    public void UpdatesWhenStatModifierUpdates_Test()
    {
        StatSheet    sheet    = new StatSheet();
        Stat         strength = sheet.Get(StatType.Strength);
        StatModifier mod      = new StatModifier(StatType.Strength, StatModifierType.Flat, 9f);

        Assert.That(strength.Value, Is.EqualTo(0f));
        strength.AddModifier(mod);
        Assert.That(strength.Value, Is.EqualTo(9f));
        mod.Value = 42f;
        Assert.That(strength.Value, Is.EqualTo(42f));
    }
Exemplo n.º 9
0
    public void AddModifier_Test()
    {
        StatModifier mod  = new StatModifier(StatType.Strength, StatModifierType.Flat, 10f);
        Stat         stat = new Stat();

        Assert.That(stat.StatModifiers.Count, Is.EqualTo(0));

        stat.AddModifier(mod);

        Assert.That(stat.StatModifiers, Contains.Item(mod));
        Assert.That(stat.StatModifiers.Count, Is.EqualTo(1));
    }
    void OnEquipmentChanged(Equipment newItem, Equipment oldItem)
    {
        if (newItem != null)
        {
            skill.AddModifier(newItem.bonusCrim);
        }

        if (oldItem != null)
        {
            skill.RemoveModifier(oldItem.bonusCrim);
        }
    }
Exemplo n.º 11
0
 /// <summary>
 /// Toggles output modifier on output stat
 /// </summary>
 public void ToggleOutput()
 {
     if (_goldOutput.ModifierCount == 0)
     {
         Debug.Log("ToggleOutput() Adding output modifier");
         _goldOutput.AddModifier(_goldOutputModifier);
     }
     else
     {
         Debug.Log("ToggleOutput() Removing modifiers");
         _goldOutput.ClearMods();
     }
 }
Exemplo n.º 12
0
        public void ModifierPriorityTest()
        {
            Stat hp = new Stat(0, 100, 50, true);

            StatModifierMultiplication mod1 = new StatModifierMultiplication("mod1", 0.5, priority: 1);

            hp.AddModifier(mod1);
            Assert.AreEqual(75, hp.GetCurrent());

            StatModifierMultiplication mod2 = new StatModifierMultiplication("mod2", 0.5, priority: 1);

            hp.AddModifier(mod2);
            Assert.AreEqual(100, hp.GetCurrent()); // because these have the same priority,
            // they don't see eachother's effects (e.g. we get 50 + 50*0.5 + 50*0.5, NOT 50 + 50*0.5 + 75*0.5

            hp.RemoveModifier("mod2");
            Assert.AreEqual(75, hp.GetCurrent());
            StatModifierMultiplication mod3 = new StatModifierMultiplication("mod3", -0.2, priority: 0);

            hp.AddModifier(mod3);
            Assert.AreEqual(60, hp.GetCurrent()); // because this one has a lower priority, it happens AFTER mod1
            // so we get 50 + 50*0.5 = 75, then 75 + 75*-0.2 = 60
        }
Exemplo n.º 13
0
    private void OnEquipmentChanged(Equipment newItem, Equipment oldItem)
    {
        if (newItem != null)
        {
            armor.AddModifier(newItem.armorModifier);
            damage.AddModifier(newItem.damageModifier);
        }

        if (oldItem != null)
        {
            armor.RemoveModifier(oldItem.armorModifier);
            damage.RemoveModifier(oldItem.damageModifier);
        }
    }
Exemplo n.º 14
0
    public override void Use(Being target)
    {
        Stat actualTargetStat = target.GetStat(targetStat);

        if (actualTargetStat == null)
        {
            Debug.Log(target.beingName + " has no " + targetStat + "!");
            return;
        }

        StatModifier sm = new StatModifier(value, modifierType);

        actualTargetStat.AddModifier(sm);
    }
Exemplo n.º 15
0
        public void ModifierStatTest()
        {
            Stat hp = new Stat(0, 100, 100, false);

            StatModifierAddition mod1 = new StatModifierAddition("mod1", 10);

            hp.AddModifier(mod1);

            Assert.AreEqual(100, hp.GetCurrent()); // not allowed to overflow from mods
            hp.AllowedToOverflowFromModifiers = true;
            Assert.AreEqual(110, hp.GetCurrent()); // if we flip overflow to true, should overflow from mods

            StatModifierAddition mod2 = new StatModifierAddition("mod2", -20);

            hp.AddModifier(mod2);
            Assert.AreEqual(90, hp.GetCurrent());

            hp.RemoveModifier("mod1");
            Assert.AreEqual(80, hp.GetCurrent()); // if we remove mod1, we should see its effect go away

            hp.RemoveModifier("mod2");
            Assert.AreEqual(100, hp.GetCurrent()); // similarly with mod2
        }
Exemplo n.º 16
0
    /// <summary>
    /// Apply a specific ModifierType to the playerStats
    /// </summary>
    private void ApplyStat(Modifier modifier, object source)
    {
        switch (modifier.statToModify)
        {
        case PlayerStatModifier.maxHealth:
            maxHealth.AddModifier(Mathf.RoundToInt(modifier.value), source, modifier.modifierType);
            if (modifier.modifierType == StatModifierType.linear)
            {
                Heal(Mathf.RoundToInt(modifier.value));
            }
            health = Mathf.Clamp(health, 0, maxHealth.GetValue());
            break;

        case PlayerStatModifier.minAttack:
            minAttack.AddModifier(Mathf.RoundToInt(modifier.value), source, modifier.modifierType);
            break;

        case PlayerStatModifier.maxAttack:
            maxAttack.AddModifier(Mathf.RoundToInt(modifier.value), source, modifier.modifierType);
            break;

        case PlayerStatModifier.defense:
            defense.AddModifier(Mathf.RoundToInt(modifier.value), source, modifier.modifierType);
            break;

        case PlayerStatModifier.hitSpeed:
            hitDelay.AddModifier(modifier.value, source, modifier.modifierType);
            break;

        case PlayerStatModifier.maxFocus:
            maxFocus.AddModifier(Mathf.RoundToInt(modifier.value), source, modifier.modifierType);
            break;

        case PlayerStatModifier.damage:
            DamagePlayerDirectly(Mathf.RoundToInt(modifier.value));
            break;

        case PlayerStatModifier.healing:
            Heal(modifier.value);
            break;

        case PlayerStatModifier.movementDelay:
            movementDelay.AddModifier(modifier.value, source, modifier.modifierType);
            break;

        default:
            break;
        }
    }
Exemplo n.º 17
0
    void ReadBaseStats()
    {
        //Warrior
        damage.AddModifier(baseStats.strength.GetValue());

        // Caster
        damage.AddModifier(baseStats.intelligence.GetValue());

        // Armor
        armor.AddModifier(baseStats.dexterity.GetValue());

        maxHealth = baseStats.maxHealth;

        currentHealth = maxHealth.GetValue();
        if (healthbar != null)
        {
            healthbar.SetMaxHealth(maxHealth.GetValue());
        }

        if (levelBox != null)
        {
            levelBox.GetComponentInChildren <TMPro.TextMeshProUGUI>().SetText(baseStats.level.GetValue().ToString());
        }
    }
Exemplo n.º 18
0
    private void ScaleToDifficulty()
    {
        if (this is PlayerStats || GameManager.Instance.difficulty == Difficulty.Normal)
        {
            return;
        }

        if (GameManager.Instance.difficulty == Difficulty.Hard)
        {
            healthDifficultyMod      = Mathf.RoundToInt(health.GetValue() * 0.5f);
            attackPowerDifficultyMod = Mathf.RoundToInt(attackPower.GetValue() * 0.5f);
            health.AddModifier(healthDifficultyMod);
            attackPower.AddModifier(attackPowerDifficultyMod);
        }
        else if (GameManager.Instance.difficulty == Difficulty.Easy)
        {
            healthDifficultyMod      = -Mathf.RoundToInt(health.GetValue() * 0.5f);
            attackPowerDifficultyMod = -Mathf.RoundToInt(attackPower.GetValue() * 0.5f);
            health.AddModifier(healthDifficultyMod);
            attackPower.AddModifier(attackPowerDifficultyMod);
        }

        UpdateStats();
    }
Exemplo n.º 19
0
        // ----------------------
        // Applying modifiers
        // ----------------------

        /// <summary>
        /// Toggles capacity modifier on capacity stat
        /// </summary>
        public void ToggleCapacity()
        {
            if (_goldCapacity.ModifierCount == 0)
            {
                // We can add modifier to a stat with AddModifier method
                Debug.Log("ToggleCapacity() Adding capacity modifier");
                _goldCapacity.AddModifier(_goldCapacityModifier);
            }
            else
            {
                // We can remove all modifiers with ClearMods() method
                Debug.Log("ToggleCapacity() Removing modifiers");
                _goldCapacity.ClearMods();
            }
        }
Exemplo n.º 20
0
        public void AddModifierToStat()
        {
            string name = "sdsd";
            float value = 10.0f;
            Stat stat = new Stat(name, value);

            float modValue = 5.0f;
            string modName = "fsdhnuh";
            StatModifier mod = new StatModifier(modName, modValue);

            stat.AddModifier(mod);

            Assert.IsTrue(stat.Name == name);
            Assert.IsTrue(stat.BaseValue == value);
            Assert.IsTrue(stat.TotalValue == modValue + value);
        }
Exemplo n.º 21
0
    public void TakeDamage(int damage)
    {
        //Lessen damage by armour value
        //TODO: * damage & attack, defense modifiers by a level modifier (maybe Enum lvl : modifier %)
        damage -= defense.GetValue();
        damage  = Mathf.Clamp(damage, 0, int.MaxValue); //Prevent strong armour from causing damage to be negative

        life.AddModifier(-damage);
        Debug.Log(transform.name + " takes " + damage + " damage." + "\n\tlife: " + life.GetValue());

        //Death
        if (life.GetValue() <= 0)
        {
            Die();
        }
    }
Exemplo n.º 22
0
        void OnEquipmentChanged(Equipment newItem, Equipment oldItem)
        {
            // Add new modifiers
            if (newItem != null)
            {
                HP.AddModifier(newItem.HPModifier);
                Damage.AddModifier(newItem.DamageModifier);
            }

            // Remove old modifiers
            if (oldItem != null)
            {
                HP.RemoveModifier(oldItem.HPModifier);
                Damage.RemoveModifier(oldItem.DamageModifier);
            }
        }
Exemplo n.º 23
0
    /// <summary> Adds a stat modifier to pokemon and summons particles depending on new value. </summary>
    /// <param name="stat"> Stat to change. </param>
    /// <param name="mod"> Modifier to apply. </param>
    public void AddStatMod(StatType stat, StatModifier mod)
    {
        /* Get Stat By Type */
        Stat s = GetStat(stat);

        /* Get Current Stat Value */
        int value = s.Value;

        /* Apply Modifier */
        s.AddModifier(mod);

        /* If Value Has , Animate Particles */
        if (value != s.Value)
        {
            StartCoroutine(AnimateStatParticles(s.Color, value < s.Value));
        }
    }
Exemplo n.º 24
0
        public void AddModifierToStat()
        {
            string name  = "sdsd";
            float  value = 10.0f;
            Stat   stat  = new Stat(name, value);

            float        modValue = 5.0f;
            string       modName  = "fsdhnuh";
            StatModifier mod      = new StatModifier(modName, modValue);

            stat.AddModifier(mod);


            Assert.IsTrue(stat.Name == name);
            Assert.IsTrue(stat.BaseValue == value);
            Assert.IsTrue(stat.TotalValue == modValue + value);
        }
Exemplo n.º 25
0
    // Damage the character
    public void TakeDamage(int damage)
    {
        int armorDamage  = Mathf.Min(armor.GetValue(), damage);
        int healthDamage = Mathf.Min(CurrentHealth, damage - armorDamage);

        armor.AddModifier(-armorDamage);
        CurrentHealth -= healthDamage;
        Debug.Log(transform.name + " takes " + armorDamage + " armor damage and " + healthDamage + " health damage");

        // If we hit 0. Die.
        if (CurrentHealth <= 0)
        {
            if (OnHealthReachedZero != null)
            {
                OnHealthReachedZero();
            }
        }
    }
Exemplo n.º 26
0
    public override void Ability(Ship target)
    {
        switch (propertyObject)
        {
        case PropertyObject.Ship:
            Stat modifyStat = (Stat)target.properties.GetType().GetField(parameter).GetValue(target.properties);
            modifyStat.AddModifier(new StatModifier(Effect, modifierType));
            break;

        //case PropertyObject.Attack:
        //    //TODO
        //    break;
        case PropertyObject.Movement:
            //TODO
            break;
        }
        throw new System.NotImplementedException();
    }
Exemplo n.º 27
0
    public void UpdatesWhenDependentStatUpdates_Test()
    {
        StatSheet sheet = new StatSheet();

        Stat dexterity = sheet.Get(StatType.Dexterity);

        dexterity.BaseValue = 100f;

        Stat crit = sheet.Get(StatType.CriticalHit);

        Assert.That(dexterity.Value, Is.EqualTo(100f));
        Assert.That(crit.BaseValue, Is.EqualTo(0f));
        Assert.That(crit.Value, Is.EqualTo(15f));

        dexterity.AddModifier(new StatModifier(StatType.Strength, StatModifierType.Flat, 100f));

        Assert.That(dexterity.Value, Is.EqualTo(200f));
        Assert.That(crit.Value, Is.EqualTo(30f));
    }
Exemplo n.º 28
0
    private void UpdateStat(IMessage message)
    {
        StatMessage updateInfo = message as StatMessage;

        if (updateInfo == null)
        {
            throw new System.Exception("A handler was provided an incorrect IMessage");
        }

        if (stats.ContainsKey(updateInfo.TargetStat))
        {
            stats[updateInfo.TargetStat].AddModifier(updateInfo.Modifier);
        }
        else
        {
            Stat stat = new Stat(0f);
            stat.AddModifier(updateInfo.Modifier);
            stats.Add(updateInfo.TargetStat, stat);
        }
    }
Exemplo n.º 29
0
    public void OnEquipmentChanged(Equipment newItem, Equipment oldItem)
    {
        if (newItem != null)
        {
            warmth.AddModifier(newItem.warmthMod);
            damage.AddModifier(newItem.damageMod);
            armor.AddModifier(newItem.armorMod);
        }
        if (oldItem != null)
        {
            warmth.RemoveModifier(oldItem.warmthMod);
            damage.RemoveModifier(oldItem.damageMod);
            armor.RemoveModifier(oldItem.armorMod);
        }

        if (onStatChanged != null)
        {
            onStatChanged.Invoke();
        }
    }
Exemplo n.º 30
0
        void OnEquipmentChanged(Equipment _newItem, Equipment _oldItem)
        {
            if (_newItem != null)
            {
                maxArmour.AddModifier(_newItem.armorModifier);
                damage.AddModifier(_newItem.damageModifier);
                lightLevel.AddModifier(_newItem.lightLevelModifier);
                maxPower.AddModifier(_newItem.powerModifier);
                maxSpeed.AddModifier(_newItem.speedModifier);
            }

            if (_oldItem != null)
            {
                maxArmour.RemoveModifier(_oldItem.armorModifier);
                damage.RemoveModifier(_oldItem.damageModifier);
                lightLevel.RemoveModifier(_oldItem.lightLevelModifier);
                maxPower.RemoveModifier(_oldItem.powerModifier);
                maxSpeed.RemoveModifier(_oldItem.speedModifier);
            }
        }
Exemplo n.º 31
0
    /// <summary>
    /// Method Listening to the ONequipment changed method on inventoryscript
    /// In order to correctly remove or add modifiers that gear may have
    /// </summary>
    /// <param name="newItem"></param>
    /// <param name="oldItem"></param>
    private void OnEquipmentChanged(Equipment newItem, Equipment oldItem)
    {
        if (oldItem != null)
        {
            armor.RemoveModifier(oldItem.armorModifier);
            damage.RemoveModifier(oldItem.damageModifier);
            Sta.RemoveModifier(oldItem.sta);
            Str.RemoveModifier(oldItem.str);
            Agi.RemoveModifier(oldItem.agi);
        }

        if (newItem != null)
        {
            armor.AddModifier(newItem.armorModifier);
            damage.AddModifier(newItem.damageModifier);
            Sta.AddModifier(newItem.sta);
            Str.AddModifier(newItem.str);
            Agi.AddModifier(newItem.agi);
        }

        UpdateUiStats();
    }