Пример #1
0
        public static ShotReport HitReportFor(Thing caster, Verb verb, LocalTargetInfo target)
        {
            Pawn       pawn   = caster as Pawn;
            IntVec3    cell   = target.Cell;
            ShotReport result = default(ShotReport);

            result.distance = (cell - caster.Position).LengthHorizontal;
            result.target   = target.ToTargetInfo(caster.Map);
            float f = (float)((pawn == null) ? 0.95999997854232788 : pawn.GetStatValue(StatDefOf.ShootingAccuracy, true));

            result.factorFromShooterAndDist = Mathf.Pow(f, result.distance);
            if (result.factorFromShooterAndDist < 0.020099999383091927)
            {
                result.factorFromShooterAndDist = 0.0201f;
            }
            result.factorFromEquipment = verb.verbProps.GetHitChanceFactor(verb.ownerEquipment, result.distance);
            result.covers = CoverUtility.CalculateCoverGiverSet(cell, caster.Position, caster.Map);
            result.coversOverallBlockChance = CoverUtility.CalculateOverallBlockChance(cell, caster.Position, caster.Map);
            result.coveringGas = null;
            ShootLine shootLine = default(ShootLine);

            if (verb.TryFindShootLineFromTo(verb.caster.Position, target, out shootLine))
            {
                foreach (IntVec3 item in shootLine.Points())
                {
                    Thing gas = item.GetGas(caster.Map);
                    if (gas != null && (result.coveringGas == null || result.coveringGas.gas.accuracyPenalty < gas.def.gas.accuracyPenalty))
                    {
                        result.coveringGas = gas.def;
                    }
                }
            }
            if (!caster.Position.Roofed(caster.Map) && !target.Cell.Roofed(caster.Map))
            {
                result.factorFromWeather = caster.Map.weatherManager.CurWeatherAccuracyMultiplier;
            }
            else
            {
                result.factorFromWeather = 1f;
            }
            result.factorFromTargetSize = 1f;
            if (target.HasThing)
            {
                Pawn pawn2 = target.Thing as Pawn;
                if (pawn2 != null)
                {
                    result.factorFromTargetSize = pawn2.BodySize;
                }
                else
                {
                    result.factorFromTargetSize = (float)(target.Thing.def.fillPercent * 1.7000000476837158);
                }
                result.factorFromTargetSize = Mathf.Clamp(result.factorFromTargetSize, 0.5f, 2f);
            }
            result.forcedMissRadius = verb.verbProps.forcedMissRadius;
            return(result);
        }
Пример #2
0
        public static ShotReport HitReportFor(Thing caster, Verb verb, LocalTargetInfo target)
        {
            IntVec3    cell   = target.Cell;
            ShotReport result = default(ShotReport);

            result.distance = (cell - caster.Position).LengthHorizontal;
            result.target   = target.ToTargetInfo(caster.Map);
            result.factorFromShooterAndDist = HitFactorFromShooter(caster, result.distance);
            result.factorFromEquipment      = verb.verbProps.GetHitChanceFactor(verb.EquipmentSource, result.distance);
            result.covers = CoverUtility.CalculateCoverGiverSet(target, caster.Position, caster.Map);
            result.coversOverallBlockChance = CoverUtility.CalculateOverallBlockChance(target, caster.Position, caster.Map);
            result.coveringGas = null;
            if (verb.TryFindShootLineFromTo(verb.caster.Position, target, out result.shootLine))
            {
                foreach (IntVec3 item in result.shootLine.Points())
                {
                    Thing gas = item.GetGas(caster.Map);
                    if (gas != null && (result.coveringGas == null || result.coveringGas.gas.accuracyPenalty < gas.def.gas.accuracyPenalty))
                    {
                        result.coveringGas = gas.def;
                    }
                }
            }
            else
            {
                result.shootLine = new ShootLine(IntVec3.Invalid, IntVec3.Invalid);
            }
            if (!caster.Position.Roofed(caster.Map) || !target.Cell.Roofed(caster.Map))
            {
                result.factorFromWeather = caster.Map.weatherManager.CurWeatherAccuracyMultiplier;
            }
            else
            {
                result.factorFromWeather = 1f;
            }
            if (target.HasThing)
            {
                Pawn pawn = target.Thing as Pawn;
                if (pawn != null)
                {
                    result.factorFromTargetSize = pawn.BodySize;
                }
                else
                {
                    result.factorFromTargetSize = target.Thing.def.fillPercent * (float)target.Thing.def.size.x * (float)target.Thing.def.size.z * 2.5f;
                }
                result.factorFromTargetSize = Mathf.Clamp(result.factorFromTargetSize, 0.5f, 2f);
            }
            else
            {
                result.factorFromTargetSize = 1f;
            }
            result.forcedMissRadius = verb.verbProps.forcedMissRadius;
            return(result);
        }