Пример #1
0
        private void CalculateChance()
        {
            if (calculated)
            {
                return;
            }
            calculated = true;

            float coverDodgeBonus  = 0;
            float exposedCritBonus = 0;

            //if cover system is enabled, get the dodge and crit bonus
            if (GameControl.EnableCover())
            {
                coverType = CoverSystem.GetCoverType(srcUnit.tile, tgtUnit.tile);
                if (coverType == CoverSystem._CoverType.Half)
                {
                    coverDodgeBonus = CoverSystem.GetHalfCoverDodgeBonus();
                }
                else if (coverType == CoverSystem._CoverType.Full)
                {
                    coverDodgeBonus = CoverSystem.GetFullCoverDodgeBonus();
                }
                else
                {
                    exposedCritBonus = CoverSystem.GetExposedCritChanceBonus();
                }
            }

            //calculate the hit chance
            float hit = !isMelee?srcUnit.GetHitChance() : srcUnit.GetHitChanceMelee();

            float dodge = tgtUnit.GetDodgeChance() + coverDodgeBonus;

            hitChance = Mathf.Clamp(hit - dodge, 0f, 1f);

            //calculate the critical chance
            float critHit   = (!isMelee ? srcUnit.GetCritChance() : srcUnit.GetCritChanceMelee()) + exposedCritBonus;
            float critAvoid = tgtUnit.GetCritAvoidance();

            critChance = Mathf.Clamp(critHit - critAvoid, 0f, 1f);

            //calculate stun chance
            float stunHit   = srcUnit.GetStunChance();
            float stunAvoid = tgtUnit.GetStunAvoidance();

            stunChance = Mathf.Clamp(stunHit - stunAvoid, 0f, 1f);

            //calculate silent chance
            float silentHit   = srcUnit.GetSilentChance();
            float silentAvoid = tgtUnit.GetSilentAvoidance();

            silentChance = Mathf.Clamp(silentHit - silentAvoid, 0f, 1f);

            if (isOverwatch)
            {
                hitChance -= GameControl.GetOverwatchHitPenalty();
                critHit   -= GameControl.GetOverwatchCritPenalty();
            }

            //check if flanking is enabled an applicable in this instance
            if (GameControl.EnableFlanking())
            {
                //Vector2 dir=new Vector2(srcUnit.tile.pos.x-tgtUnit.tile.pos.x, srcUnit.tile.pos.z-tgtUnit.tile.pos.z);
                float      angleTH        = 180 - Mathf.Min(180, GameControl.GetFlankingAngle());
                Quaternion attackRotation = Quaternion.LookRotation(tgtUnit.tile.GetPos() - srcUnit.tile.GetPos());
                //Debug.Log(Quaternion.Angle(attackRotation, tgtUnit.thisT.rotation)+"    "+angleTH);
                if (Quaternion.Angle(attackRotation, tgtUnit.thisT.rotation) < angleTH)
                {
                    flanked = true;
                }
            }
        }