示例#1
0
        //do the stats processing
        public void Process()
        {
            if (processed)
            {
                return;
            }

            if (isAbility)              //if this instance is for ability, then there's no need to calculate the rest of the stats
            {
                if (Random.Range(0f, 1f) > hitChance)
                {
                    missed = true;
                    return;
                }
            }

            processed = true;

            //first determine all the chances and condition
            CalculateChance();

            //if the attack missed, skip the rest of the calculation
            if (Random.Range(0f, 1f) > hitChance)
            {
                missed = true;
                return;
            }

            //get the base damage
            if (!isMelee)
            {
                damage = Random.Range(srcUnit.GetDamageMin(), srcUnit.GetDamageMax());
            }
            else
            {
                damage = Random.Range(srcUnit.GetDamageMinMelee(), srcUnit.GetDamageMaxMelee());
            }

            //modify the damage with damage to armor modifier
            int armorType  = tgtUnit.armorType;
            int damageType = srcUnit.damageType;

            damageTableModifier = DamageTable.GetModifier(armorType, damageType);
            damage *= damageTableModifier;

            //if this is a counter attack, modify the damage with counter modifier
            if (isCounter)
            {
                damage *= GameControl.GetCounterDamageMultiplier();
            }

            //this the target is flanked, apply the flanking bonus
            if (!isCounter && flanked)
            {
                flankingBonus = 1 + GameControl.GetFlankingBonus() + srcUnit.GetFlankingBonus() - tgtUnit.GetFlankedModifier();
                damage       *= flankingBonus;
            }

            //if the attack crits, add the critical multiplier
            if (Random.Range(0f, 1f) < critChance)
            {
                critical = true;
                damage  *= srcUnit.GetCritMultiplier();
                //damage*=!isMelee ? srcUnit.GetCritMultiplier() : srcUnit.GetCritMultiplierMelee();
            }

            //if the attack stuns the target, get the stun duration
            if (Random.Range(0f, 1f) < stunChance)
            {
                stunned = true;
                stun    = srcUnit.GetStunDuration();
            }

            //if the attack stuns the target, get the stun duration
            if (Random.Range(0f, 1f) < silentChance)
            {
                silenced = true;
                silent   = srcUnit.GetSilentDuration();
            }

            //check if the unit is destroyed in this instance and make the destroyed flag according
            if (damage > tgtUnit.HP)
            {
                destroyed = true;
            }

            //Debug.Log("Damage: "+damage);
            //new TextOverlay(tgtUnit.GetTargetT().position, damage.ToString("f0"), Color.white);
        }