Ejemplo n.º 1
0
        private static float FriendlyFireConeTargetScoreOffset(IAttackTarget target, IAttackTargetSearcher searcher, Verb verb)
        {
            Pawn  pawn = searcher.Thing as Pawn;
            float result;

            if (pawn == null)
            {
                result = 0f;
            }
            else if (pawn.RaceProps.intelligence < Intelligence.ToolUser)
            {
                result = 0f;
            }
            else if (pawn.RaceProps.IsMechanoid)
            {
                result = 0f;
            }
            else
            {
                Verb_Shoot verb_Shoot = verb as Verb_Shoot;
                if (verb_Shoot == null)
                {
                    result = 0f;
                }
                else
                {
                    ThingDef defaultProjectile = verb_Shoot.verbProps.defaultProjectile;
                    if (defaultProjectile == null)
                    {
                        result = 0f;
                    }
                    else if (defaultProjectile.projectile.flyOverhead)
                    {
                        result = 0f;
                    }
                    else
                    {
                        Map                   map    = pawn.Map;
                        ShotReport            report = ShotReport.HitReportFor(pawn, verb, (Thing)target);
                        float                 a      = VerbUtility.CalculateAdjustedForcedMiss(verb.verbProps.forcedMissRadius, report.ShootLine.Dest - report.ShootLine.Source);
                        float                 radius = Mathf.Max(a, 1.5f);
                        IntVec3               dest2  = report.ShootLine.Dest;
                        IEnumerable <IntVec3> source = from dest in GenRadial.RadialCellsAround(dest2, radius, true)
                                                       where dest.InBounds(map)
                                                       select dest;
                        IEnumerable <ShootLine> source2 = from dest in source
                                                          select new ShootLine(report.ShootLine.Source, dest);
                        IEnumerable <IntVec3> source3    = source2.SelectMany((ShootLine line) => line.Points().Concat(line.Dest).TakeWhile((IntVec3 pos) => pos.CanBeSeenOverFast(map)));
                        IEnumerable <IntVec3> enumerable = source3.Distinct <IntVec3>();
                        float num = 0f;
                        foreach (IntVec3 c in enumerable)
                        {
                            float num2 = VerbUtility.DistanceInterceptChance(report.ShootLine.Source.ToVector3Shifted(), c, ((Thing)target).Position);
                            if (num2 > 0f)
                            {
                                List <Thing> thingList = c.GetThingList(map);
                                for (int i = 0; i < thingList.Count; i++)
                                {
                                    Thing thing = thingList[i];
                                    if (thing is IAttackTarget && thing != target)
                                    {
                                        float num3;
                                        if (thing == searcher)
                                        {
                                            num3 = 40f;
                                        }
                                        else if (thing is Pawn)
                                        {
                                            num3 = ((!thing.def.race.Animal) ? 18f : 7f);
                                        }
                                        else
                                        {
                                            num3 = 10f;
                                        }
                                        num3 *= num2;
                                        if (searcher.Thing.HostileTo(thing))
                                        {
                                            num3 *= 0.6f;
                                        }
                                        else
                                        {
                                            num3 *= -1f;
                                        }
                                        num += num3;
                                    }
                                }
                            }
                        }
                        result = num;
                    }
                }
            }
            return(result);
        }