Exemplo n.º 1
0
        public static bool IsVoidsEverywhereInShootingLine(ShootLine resultingLine, Map map, Thing caster, Thing target)
        {
            var points = resultingLine.Points().ToList();

            if (points.Count > 2)
            {
                for (int i = 0; i < points.Count; i++)
                {
                    if (IntVec3Utility.DistanceTo(caster.Position, points[i]) >= 2)
                    {
                        if (points[i].GetTerrain(map) != ZLevelsDefOf.ZL_OutsideTerrain)
                        {
                            ZLogger.Message("1: " + caster + " - " + i + " - " + points[i] + " - " + points[i].GetTerrain(map) + " - " + map, true);
                            return(false);
                        }
                    }
                }
                if (resultingLine.dest.GetCover(map)?.def?.Fillage == FillCategory.Full)
                {
                    ZLogger.Message("3: " + caster + " - " + resultingLine.dest + " - " + resultingLine.dest.GetCover(map) + " - " + map, true);
                    return(false);
                }
            }
            else
            {
                for (int i = 0; i < points.Count; i++)
                {
                    if (points[i] != resultingLine.Source)
                    {
                        if (points[i].GetTerrain(map) != ZLevelsDefOf.ZL_OutsideTerrain)
                        {
                            ZLogger.Message("4: " + caster + " - " + i + " - " + points[i] + " - " + points[i].GetTerrain(map) + " - " + map, true);
                            return(false);
                        }
                    }
                }
                if (resultingLine.dest.GetCover(map)?.def?.Fillage == FillCategory.Full)
                {
                    ZLogger.Message("5: " + caster + " - " + resultingLine.dest + " - " + resultingLine.dest.GetCover(map) + " - " + map, true);
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 2
0
 // Token: 0x0600003F RID: 63 RVA: 0x0000397C File Offset: 0x00001B7C
 internal void FindBestRefuel(Pawn pilot, ThingDef FuelItem, int FuelMax, int Fuel, out Thing targ)
 {
     targ = null;
     if ((pilot?.Map) != null)
     {
         List <Thing> listfuel   = pilot?.Map.listerThings.ThingsOfDef(FuelItem);
         int          fuelneeded = FuelMax - Fuel;
         if (fuelneeded > FuelItem.stackLimit)
         {
             fuelneeded = FuelItem.stackLimit;
         }
         if (listfuel.Count > 0)
         {
             Thing besttarg   = null;
             float bestpoints = 0f;
             for (int i = 0; i < listfuel.Count; i++)
             {
                 Thing targchk = listfuel[i];
                 if (!ForbidUtility.IsForbidden(targchk, pilot) && ((targchk?.Faction) == null || targchk.Faction.IsPlayer) && ReservationUtility.CanReserveAndReach(pilot, targchk, PathEndMode.ClosestTouch, Danger.None, 1, -1, null, false))
                 {
                     float targpoints;
                     if (targchk.stackCount >= fuelneeded)
                     {
                         targpoints = (float)targchk.stackCount / IntVec3Utility.DistanceTo(pilot.Position, targchk.Position);
                     }
                     else
                     {
                         targpoints = (float)targchk.stackCount / (IntVec3Utility.DistanceTo(pilot.Position, targchk.Position) * 2f);
                     }
                     if (targpoints > bestpoints)
                     {
                         besttarg   = targchk;
                         bestpoints = targpoints;
                     }
                 }
             }
             if (besttarg != null)
             {
                 targ = besttarg;
             }
         }
     }
 }
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            // Get nearest reachable medical spaceship.
            float minDistance = 99999f;
            Building_SpaceshipMedical nearestMedicalSpaceship = null;

            foreach (Thing spaceship in pawn.Map.listerThings.ThingsOfDef(Util_Spaceship.SpaceshipMedical))
            {
                float distance = IntVec3Utility.DistanceTo(t.Position, spaceship.Position);
                if ((distance < minDistance) &&
                    pawn.CanReach(spaceship, this.PathEndMode, Danger.Deadly))
                {
                    minDistance             = distance;
                    nearestMedicalSpaceship = spaceship as Building_SpaceshipMedical;
                }
            }
            return(new Job(Util_JobDefOf.TransferToMedibay, t, nearestMedicalSpaceship)
            {
                count = 1
            });
        }
Exemplo n.º 4
0
        public static Pawn GetNearestReachableDownedPawn(Pawn carrier)
        {
            Pawn  nearestDownedPawn = null;
            float minDistance       = 99999f;

            foreach (Pawn downedPawn in carrier.Map.mapPawns.FreeHumanlikesSpawnedOfFaction(carrier.Faction))
            {
                if (downedPawn.Downed)
                {
                    if (carrier.CanReserveAndReach(downedPawn, PathEndMode.OnCell, Danger.Some))
                    {
                        float distance = IntVec3Utility.DistanceTo(carrier.Position, downedPawn.Position);
                        if (distance < minDistance)
                        {
                            minDistance       = distance;
                            nearestDownedPawn = downedPawn;
                        }
                    }
                }
            }
            return(nearestDownedPawn);
        }
Exemplo n.º 5
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            //Log.Message(pawn + " - " + pawn.mindState.duty);
            if (!pawn.HostileTo(Faction.OfPlayer))
            {
                //Log.Message("0 - " + pawn + " - null", true);
                return(null);
            }

            if (RCellFinder.TryFindBestExitSpot(pawn, out IntVec3 spot))
            {
                //Log.Message(pawn + " found spot: " + spot, true);
                if (TryFindBestItemToSteal(pawn.Position, pawn.Map, 50f, out Thing item, pawn))                // && !GenAI.InDangerousCombat(pawn))
                {
                    Job job = JobMaker.MakeJob(JobDefOf.Steal);
                    job.targetA       = item;
                    job.targetB       = spot;
                    job.canBashDoors  = true;
                    job.canBashFences = true;
                    job.count         = Mathf.Min(item.stackCount, (int)(pawn.GetStatValue(StatDefOf.CarryingCapacity) / item.def.VolumePerUnit));
                    //Log.Message("3 - " + pawn + " - " + job, true);
                    return(job);
                }
                //Log.Message(pawn + " cant find item to steal", true);
            }
            bool     flag     = pawn.natives.IgniteVerb != null && pawn.natives.IgniteVerb.IsStillUsableBy(pawn) && pawn.HostileTo(Faction.OfPlayer);
            CellRect cellRect = CellRect.CenteredOn(pawn.Position, 5);

            for (int i = 0; i < 35; i++)
            {
                IntVec3 randomCell = cellRect.RandomCell;
                if (!randomCell.InBounds(pawn.Map))
                {
                    continue;
                }
                Building edifice = randomCell.GetEdifice(pawn.Map);
                if (edifice != null && TrashUtility.ShouldTrashBuilding(pawn, edifice) && GenSight.LineOfSight(pawn.Position, randomCell, pawn.Map))
                {
                    Job job = TrashJob(pawn, edifice);
                    if (job != null)
                    {
                        //Log.Message("1 - " + pawn + " - " + job, true);
                        return(job);
                    }
                }
                if (flag)
                {
                    Plant plant = randomCell.GetPlant(pawn.Map);
                    if (plant != null && TrashUtility.ShouldTrashPlant(pawn, plant) && GenSight.LineOfSight(pawn.Position, randomCell, pawn.Map))
                    {
                        Job job2 = TrashJob(pawn, plant);
                        if (job2 != null)
                        {
                            //Log.Message("2 - " + pawn + " - " + job2, true);

                            return(job2);
                        }
                    }
                }
            }

            List <Building> allBuildingsColonist = pawn.Map.listerBuildings.allBuildingsColonist;

            if (allBuildingsColonist.Count == 0)
            {
                //Log.Message("4 - " + pawn + " - null", true);
                return(null);
            }
            foreach (var building in allBuildingsColonist.OrderBy(x => IntVec3Utility.DistanceTo(x.Position, pawn.Position)).Take(10).InRandomOrder())
            {
                if (TrashUtility.ShouldTrashBuilding(pawn, building, true) && pawn.CanReach(building, PathEndMode.Touch, Danger.None))
                {
                    Job job = TrashJob(pawn, building, true);
                    if (job != null)
                    {
                        //Log.Message("5 - " + pawn + " - " + job, true);
                        return(job);
                    }
                }
            }
            if (RCellFinder.TryFindBestExitSpot(pawn, out IntVec3 spot2))
            {
                //Log.Message(pawn + " found spot: " + spot2, true);
                if (TryFindBestItemToSteal(pawn.Position, pawn.Map, 100f, out Thing item, pawn, danger: Danger.None))                // && !GenAI.InDangerousCombat(pawn))
                {
                    Job job = JobMaker.MakeJob(JobDefOf.Steal);
                    job.targetA       = item;
                    job.targetB       = spot2;
                    job.canBashDoors  = true;
                    job.canBashFences = true;
                    job.count         = Mathf.Min(item.stackCount, (int)(pawn.GetStatValue(StatDefOf.CarryingCapacity) / item.def.VolumePerUnit));
                    //Log.Message("6 - " + pawn + " - " + job, true);
                    return(job);
                }
                //Log.Message(pawn + " cant find item to steal", true);
            }
            //Log.Message("7 - " + pawn + " - null", true);
            return(null);
        }
Exemplo n.º 6
0
        public static IEnumerable <Map> GetAllMapsInClosestOrder(Thing thing, Map oldMap, IntVec3 oldPosition, bool skipOldMap = false, bool dontCheckForStairs = false)
        {
            bool cantGoDown = false;
            bool cantGoUP   = false;
            var  zTracker   = ZTracker;
            var  jobTracker = thing is Pawn p?zTracker.jobTracker.TryGetValue(p, out var value) ? value : null : null;

            foreach (var otherMap in zTracker.GetAllMapsInClosestOrder(oldMap))
            {
                if (!dontCheckForStairs)
                {
                    var stairs         = new List <Building_Stairs>();
                    var otherMapZIndex = zTracker.GetZIndexFor(otherMap);
                    var oldMapZIndex   = zTracker.GetZIndexFor(oldMap);

                    if (otherMapZIndex > oldMapZIndex && !cantGoUP) // old map is lower than other map
                    {
                        Map lowerMap = zTracker.GetLowerLevel(otherMap.Tile, otherMap);
                        if (lowerMap != null)
                        {
                            stairs = zTracker.stairsUp[lowerMap]; // fetching stairs from lower map, in this case from map below than other map
                        }
                        else
                        {
                            ZLogger.Error("Lower map is null in " + zTracker.GetMapInfo(otherMap));
                        }
                    }
                    else if (otherMapZIndex < oldMapZIndex && !cantGoDown) // other map is lower than old map
                    {
                        Map upperMap = zTracker.GetUpperLevel(otherMap.Tile, otherMap);
                        if (upperMap != null)
                        {
                            stairs = zTracker.stairsDown[upperMap]; // fetching stairs from upper map, in this case from map upper than other map
                        }
                        else
                        {
                            ZLogger.Error("Upper map is null in " + zTracker.GetMapInfo(otherMap));
                        }
                    }

                    if (stairs != null && stairs.Count > 0)
                    {
                        if (!skipOldMap || skipOldMap && otherMap != oldMap)
                        {
                            IntVec3 newPosition = IntVec3.Invalid;// stairs.MinBy(x => IntVec3Utility.DistanceTo(thing.Position, x.Position)).Position;
                            if (thing is Pawn pawn)
                            {
                                foreach (var stair in stairs.OrderBy(x => IntVec3Utility.DistanceTo(thing.Position, x.Position)))
                                {
                                    //ZLogger.Message($"CHECK: {pawn} is from {zTracker.GetMapInfo(pawn.Map)}, can reach {stair} - {pawn.CanReach(stair, Verse.AI.PathEndMode.OnCell, Danger.Deadly)}," +
                                    //    $" stair is from {zTracker.GetMapInfo(stair.Map)}");
                                    if (pawn.CanReach(stair, Verse.AI.PathEndMode.OnCell, Danger.Deadly))
                                    {
                                        newPosition = stair.Position;
                                        break;
                                    }
                                }
                            }

                            if (newPosition.IsValid)
                            {
                                TeleportThing(thing, otherMap, newPosition);
                                //ZLogger.Message($"1 CHECK: {thing} is going to {zTracker.GetMapInfo(otherMap)}");
                                currentLookedIntoMap = otherMap;
                                yield return(otherMap);
                            }
                            else
                            {
                                var firstStairs = stairs.FirstOrDefault();
                                var map         = firstStairs?.Map;
                                if (map != null)
                                {
                                    //ZLogger.Message($"3 CHECK: stairs map: {zTracker.GetMapInfo(map)} - other map: {zTracker.GetMapInfo(otherMap)} - pawn map: {zTracker.GetMapInfo(thing.Map)}");
                                    if (map != oldMap)
                                    {
                                        var stairsMapIndex = zTracker.GetZIndexFor(map);
                                        if (stairsMapIndex > oldMapZIndex)
                                        {
                                            cantGoUP = true;
                                        }
                                        else if (oldMapZIndex > stairsMapIndex)
                                        {
                                            cantGoDown = true;
                                        }
                                    }
                                    else if (firstStairs is Building_StairsUp)
                                    {
                                        cantGoUP = true;
                                    }
                                    else if (firstStairs is Building_StairsDown)
                                    {
                                        cantGoDown = true;
                                    }
                                }
                            }
                        }
                    }
                    else if (otherMap == oldMap && !skipOldMap)
                    {
                        TeleportThing(thing, oldMap, oldPosition);
                        //ZLogger.Message($"2 CHECK: {thing} is going to {zTracker.GetMapInfo(otherMap)}");
                        currentLookedIntoMap = otherMap;
                        yield return(otherMap);
                    }
                    else
                    {
                        if (otherMapZIndex > oldMapZIndex)
                        {
                            //ZLogger.Message(thing + " cant go up in " + zTracker.GetMapInfo(otherMap));
                            cantGoUP = true;
                        }
                        else if (otherMapZIndex < oldMapZIndex)
                        {
                            //ZLogger.Message(thing + " cant go down in " + zTracker.GetMapInfo(otherMap));
                            cantGoDown = true;
                        }
                    }
                }
                else
                {
                    TeleportThing(thing, otherMap, oldPosition);
                    currentLookedIntoMap = otherMap;
                    yield return(otherMap);
                }
            }
        }
Exemplo n.º 7
0
        public static IEnumerable <Map> GetAllMapsInClosestOrderForTwoThings(Thing thing, Map oldMap, IntVec3 oldPosition, Thing thing2, Map oldMap2, IntVec3 oldPosition2)
        {
            bool cantGoDown = false;
            bool cantGoUP   = false;

            foreach (var otherMap in ZTracker.GetAllMapsInClosestOrder(oldMap))
            {
                var stairs = new List <Building_Stairs>();
                if (ZTracker.GetZIndexFor(otherMap) > ZTracker.GetZIndexFor(oldMap) && !cantGoUP)
                {
                    Map lowerMap = ZTracker.GetLowerLevel(otherMap.Tile, otherMap);
                    if (lowerMap != null)
                    {
                        stairs = ZTracker.stairsUp[lowerMap];
                    }
                    else
                    {
                        ZLogger.Message("Lower map is null in " + ZTracker.GetMapInfo(otherMap));
                    }
                }
                else if (ZTracker.GetZIndexFor(otherMap) < ZTracker.GetZIndexFor(oldMap) && !cantGoDown)
                {
                    Map upperMap = ZTracker.GetUpperLevel(otherMap.Tile, otherMap);
                    if (upperMap != null)
                    {
                        stairs = ZTracker.stairsDown[upperMap];
                    }
                    else
                    {
                        ZLogger.Message("Upper map is null in " + ZTracker.GetMapInfo(otherMap));
                    }
                }
                if (stairs != null && stairs.Count > 0)
                {
                    var selectedStairs = stairs.MinBy(x => IntVec3Utility.DistanceTo(thing.Position, x.Position));
                    var position       = selectedStairs.Position;
                    TeleportThing(thing, otherMap, position);
                    TeleportThing(thing2, otherMap, position);
                    currentLookedIntoMap = otherMap;
                    yield return(otherMap);
                }
                else if (otherMap == oldMap)
                {
                    TeleportThing(thing, oldMap, oldPosition);
                    TeleportThing(thing2, oldMap2, oldPosition2);
                    currentLookedIntoMap = otherMap;
                    yield return(otherMap);
                }
                else
                {
                    if (ZTracker.GetZIndexFor(otherMap) > ZTracker.GetZIndexFor(oldMap))
                    {
                        ZLogger.Message(thing + " cant go up in " + ZTracker.GetMapInfo(otherMap));
                        cantGoUP = true;
                    }
                    else if (ZTracker.GetZIndexFor(otherMap) < ZTracker.GetZIndexFor(oldMap))
                    {
                        ZLogger.Message(thing + " cant go down in " + ZTracker.GetMapInfo(otherMap));
                        cantGoDown = true;
                    }
                }
            }
        }
Exemplo n.º 8
0
        public static IEnumerable <Toil> GoToMap(Pawn pawn, Map dest, JobDriver instance)
        {
            Toil end = new Toil
            {
                initAction = delegate()
                {
                    ZLogger.Message("if (pawn.Map == dest): " + pawn.Map + " - " + dest);
                }
            };

            yield return(new Toil
            {
                initAction = delegate()
                {
                    if (pawn.Map == dest)
                    {
                        instance.JumpToToil(end);
                    }
                }
            });

            Toil setStairs = new Toil
            {
                initAction = delegate()
                {
                    var ZTracker = ZUtils.ZTracker;
                    ZLogger.Message("Pawn.map: " + pawn.Map);
                    ZLogger.Message("Dest Map: " + dest);
                    ZTracker.ReCheckStairs();
                    ZLogger.Message("1 Total count of stairs up: "
                                    + pawn.Map.listerThings.AllThings.Where(x => x is Building_StairsUp).Count());
                    ZLogger.Message("1 Total count of stairs down: "
                                    + pawn.Map.listerThings.AllThings.Where(x => x is Building_StairsDown).Count());

                    ZLogger.Message("2 Total count of stairs up: " + ZTracker.stairsUp[pawn.Map].Count);
                    ZLogger.Message("2 Total count of stairs down: " + ZTracker.stairsDown[pawn.Map].Count);
                    if (ZTracker.GetZIndexFor(pawn.Map) > ZTracker.GetZIndexFor(dest))
                    {
                        var stairs = ZTracker.stairsDown[pawn.Map];
                        if (stairs?.Count() > 0)
                        {
                            pawn.CurJob.targetC = new LocalTargetInfo(stairs.MinBy(x => IntVec3Utility.DistanceTo(pawn.Position, x.Position)));
                        }
                        else
                        {
                            ZLogger.Pause(pawn + " cant find stairs down");
                        }
                    }
                    else if (ZTracker.GetZIndexFor(pawn.Map) < ZTracker.GetZIndexFor(dest))
                    {
                        var stairs = ZTracker.stairsUp[pawn.Map];
                        if (stairs?.Count() > 0)
                        {
                            pawn.CurJob.targetC = new LocalTargetInfo(stairs.MinBy(y => IntVec3Utility.DistanceTo(pawn.Position, y.Position)));
                        }
                        else
                        {
                            ZLogger.Pause(pawn + " cant find stairs up");
                        }
                    }
                    else
                    {
                        pawn.CurJob.targetC = null;
                    }
                }
            };
            var  goToStairs = Toils_Goto.GotoThing(TargetIndex.C, PathEndMode.OnCell);
            Toil useStairs  = Toils_General.Wait(60, 0);

            ToilEffects.WithProgressBarToilDelay(useStairs, TargetIndex.C, false, -0.5f);
            //ToilFailConditions.FailOnDespawnedNullOrForbidden<Toil>(useStairs, TargetIndex.C);
            //ToilFailConditions.FailOnCannotTouch<Toil>(useStairs, TargetIndex.C, PathEndMode.OnCell);

            Toil teleport = new Toil
            {
                initAction = delegate()
                {
                    var ZTracker = ZUtils.ZTracker;
                    if (pawn.CurJob.targetC.Thing is Building_StairsUp stairsUp)
                    {
                        Map map = ZTracker.GetUpperLevel(pawn.Map.Tile, pawn.Map);
                        if (map == null)
                        {
                            map = ZTracker.CreateUpperLevel(pawn.Map, stairsUp.Position);
                            if (stairsUp.pathToPreset != null && stairsUp.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path         = stairsUp.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, true, false, true);
                        }
                        else
                        {
                            if (stairsUp.pathToPreset != null && stairsUp.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path         = stairsUp.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, false, false, stairsUp.shouldSpawnStairsUpper);
                            stairsUp.shouldSpawnStairsUpper = false;
                        }
                    }
                    else if (pawn.CurJob.targetC.Thing is Building_StairsDown stairsDown)
                    {
                        Map map = ZTracker.GetLowerLevel(pawn.Map.Tile, pawn.Map);
                        if (map == null)
                        {
                            map = ZTracker.CreateLowerLevel(pawn.Map, stairsDown.Position);
                            if (stairsDown.pathToPreset != null && stairsDown.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path         = stairsDown.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, true, true);
                        }
                        else
                        {
                            if (stairsDown.pathToPreset != null && stairsDown.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path         = stairsDown.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, false, stairsDown.shouldSpawnStairsBelow);
                            stairsDown.shouldSpawnStairsBelow = false;
                        }
                    }

                    if (pawn.Map != dest)
                    {
                        instance.JumpToToil(setStairs);
                    }
                }
            };

            yield return(setStairs);

            yield return(goToStairs);

            yield return(useStairs);

            yield return(teleport);

            yield return(end);
        }
    }
Exemplo n.º 9
0
            public static FloatMenuOption AddRescueOption(Pawn pawn, Pawn victim)
            {
                var floatOption = FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("Rescue".Translate
                                                                                                   (victim.LabelCap, victim), delegate()
                {
                    var ZTracker     = ZUtils.ZTracker;
                    var oldMap       = pawn.Map;
                    var oldPosition1 = pawn.Position;
                    var oldPosition2 = victim.Position;
                    bool select      = false;
                    if (Find.Selector.SelectedObjects.Contains(pawn))
                    {
                        select = true;
                    }

                    Building building_Bed = null;
                    foreach (var otherMap in ZTracker.GetAllMapsInClosestOrder(oldMap))
                    {
                        ZLogger.Message("Searching rest job for " + pawn + " in " + ZTracker.GetMapInfo(otherMap)
                                        + " for " + ZTracker.GetMapInfo(oldMap));

                        var stairs = new List <Thing>();

                        if (ZTracker.GetZIndexFor(otherMap) > ZTracker.GetZIndexFor(oldMap))
                        {
                            Map lowerMap = ZTracker.GetLowerLevel(otherMap.Tile, otherMap);
                            if (lowerMap != null)
                            {
                                stairs = ZTracker.stairsUp[lowerMap];
                            }
                            else
                            {
                                ZLogger.Message("Lower map is null in " + ZTracker.GetMapInfo(otherMap));
                            }
                        }
                        else if (ZTracker.GetZIndexFor(otherMap) < ZTracker.GetZIndexFor(oldMap))
                        {
                            Map upperMap = ZTracker.GetUpperLevel(otherMap.Tile, otherMap);
                            if (upperMap != null)
                            {
                                stairs = ZTracker.stairsDown[upperMap];
                            }
                            else
                            {
                                ZLogger.Message("Upper map is null in " + ZTracker.GetMapInfo(otherMap));
                            }
                        }

                        if (stairs != null && stairs.Count() > 0)
                        {
                            var selectedStairs = stairs.MinBy(x => IntVec3Utility.DistanceTo(pawn.Position, x.Position));
                            var position       = selectedStairs.Position;

                            Traverse.Create(pawn).Field("mapIndexOrState")
                            .SetValue((sbyte)Find.Maps.IndexOf(otherMap));
                            Traverse.Create(pawn).Field("positionInt")
                            .SetValue(position);

                            Traverse.Create(victim).Field("mapIndexOrState")
                            .SetValue((sbyte)Find.Maps.IndexOf(otherMap));
                            Traverse.Create(victim).Field("positionInt")
                            .SetValue(position);
                        }
                        else if (pawn.Map != oldMap && otherMap == oldMap)
                        {
                            Traverse.Create(pawn).Field("mapIndexOrState")
                            .SetValue((sbyte)Find.Maps.IndexOf(oldMap));
                            Traverse.Create(pawn).Field("positionInt")
                            .SetValue(oldPosition1);

                            Traverse.Create(victim).Field("mapIndexOrState")
                            .SetValue((sbyte)Find.Maps.IndexOf(oldMap));
                            Traverse.Create(victim).Field("positionInt")
                            .SetValue(oldPosition2);
                        }

                        building_Bed = RestUtility.FindBedFor(victim, pawn, sleeperWillBePrisoner: false, checkSocialProperness: false);
                        if (building_Bed == null)
                        {
                            building_Bed = RestUtility.FindBedFor(victim, pawn, sleeperWillBePrisoner: false, checkSocialProperness: false, ignoreOtherReservations: true);
                        }
                        if (building_Bed != null)
                        {
                            break;
                        }
                    }
                    if (select)
                    {
                        Find.Selector.Select(pawn);
                    }
                    Traverse.Create(pawn).Field("mapIndexOrState")
                    .SetValue((sbyte)Find.Maps.IndexOf(oldMap));
                    Traverse.Create(pawn).Field("positionInt")
                    .SetValue(oldPosition1);

                    Traverse.Create(victim).Field("mapIndexOrState")
                    .SetValue((sbyte)Find.Maps.IndexOf(oldMap));
                    Traverse.Create(victim).Field("positionInt")
                    .SetValue(oldPosition2);

                    if (building_Bed == null)
                    {
                        string t3 = (!victim.RaceProps.Animal) ? ((string)"NoNonPrisonerBed".Translate()) : ((string)"NoAnimalBed".Translate());
                        Messages.Message("CannotRescue".Translate() + ": " + t3, victim, MessageTypeDefOf.RejectInput, historical: false);
                    }
                    else
                    {
                        Job job   = JobMaker.MakeJob(JobDefOf.Rescue, victim, building_Bed);
                        job.count = 1;
                        ZTracker.BuildJobListFor(pawn, pawn.Map, job);
                        Log.Message(pawn + " taking first job 2");
                        pawn.jobs.EndCurrentJob(JobCondition.InterruptForced, false);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.Rescuing, KnowledgeAmount.Total);
                    }
                }, MenuOptionPriority.RescueOrCapture, null, victim, 0f, null, null), pawn, victim, "ReservedBy");

                return(floatOption);
            }
Exemplo n.º 10
0
            public static FloatMenuOption AddCaptureOption(Pawn pawn, Pawn victim)
            {
                var floatOption = FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("Capture".Translate
                                                                                                   (victim.LabelCap, victim), delegate()
                {
                    var ZTracker     = ZUtils.ZTracker;
                    var oldMap       = pawn.Map;
                    var oldPosition1 = pawn.Position;
                    var oldPosition2 = victim.Position;
                    bool select      = false;
                    if (Find.Selector.SelectedObjects.Contains(pawn))
                    {
                        select = true;
                    }

                    Building building_Bed = null;
                    foreach (var otherMap in ZTracker.GetAllMapsInClosestOrder(oldMap))
                    {
                        ZLogger.Message("Searching rest job for " + pawn + " in " + ZTracker.GetMapInfo(otherMap)
                                        + " for " + ZTracker.GetMapInfo(oldMap));

                        var stairs = new List <Thing>();

                        if (ZTracker.GetZIndexFor(otherMap) > ZTracker.GetZIndexFor(oldMap))
                        {
                            Map lowerMap = ZTracker.GetLowerLevel(otherMap.Tile, otherMap);
                            if (lowerMap != null)
                            {
                                stairs = ZTracker.stairsUp[lowerMap];
                            }
                            else
                            {
                                ZLogger.Message("Lower map is null in " + ZTracker.GetMapInfo(otherMap));
                            }
                        }
                        else if (ZTracker.GetZIndexFor(otherMap) < ZTracker.GetZIndexFor(oldMap))
                        {
                            Map upperMap = ZTracker.GetUpperLevel(otherMap.Tile, otherMap);
                            if (upperMap != null)
                            {
                                stairs = ZTracker.stairsDown[upperMap];
                            }
                            else
                            {
                                ZLogger.Message("Upper map is null in " + ZTracker.GetMapInfo(otherMap));
                            }
                        }

                        if (stairs != null && stairs.Count() > 0)
                        {
                            var selectedStairs = stairs.MinBy(x => IntVec3Utility.DistanceTo(pawn.Position, x.Position));
                            var position       = selectedStairs.Position;

                            Traverse.Create(pawn).Field("mapIndexOrState")
                            .SetValue((sbyte)Find.Maps.IndexOf(otherMap));
                            Traverse.Create(pawn).Field("positionInt")
                            .SetValue(position);

                            Traverse.Create(victim).Field("mapIndexOrState")
                            .SetValue((sbyte)Find.Maps.IndexOf(otherMap));
                            Traverse.Create(victim).Field("positionInt")
                            .SetValue(position);
                        }
                        else if (pawn.Map != oldMap && otherMap == oldMap)
                        {
                            Traverse.Create(pawn).Field("mapIndexOrState")
                            .SetValue((sbyte)Find.Maps.IndexOf(oldMap));
                            Traverse.Create(pawn).Field("positionInt")
                            .SetValue(oldPosition1);

                            Traverse.Create(victim).Field("mapIndexOrState")
                            .SetValue((sbyte)Find.Maps.IndexOf(oldMap));
                            Traverse.Create(victim).Field("positionInt")
                            .SetValue(oldPosition2);
                        }


                        building_Bed = RestUtility.FindBedFor(victim, pawn, true, false, false);
                        if (building_Bed == null)
                        {
                            building_Bed = RestUtility.FindBedFor(victim, pawn, true, false, true);
                        }
                        if (building_Bed != null)
                        {
                            break;
                        }
                    }

                    Traverse.Create(pawn).Field("mapIndexOrState")
                    .SetValue((sbyte)Find.Maps.IndexOf(oldMap));
                    Traverse.Create(pawn).Field("positionInt")
                    .SetValue(oldPosition1);

                    Traverse.Create(victim).Field("mapIndexOrState")
                    .SetValue((sbyte)Find.Maps.IndexOf(oldMap));
                    Traverse.Create(victim).Field("positionInt")
                    .SetValue(oldPosition2);

                    if (select)
                    {
                        Find.Selector.Select(pawn);
                    }

                    if (building_Bed == null)
                    {
                        Messages.Message("CannotCapture".Translate() + ": " + "NoPrisonerBed".Translate(), victim, MessageTypeDefOf.RejectInput, false);
                        return;
                    }
                    Job job   = JobMaker.MakeJob(JobDefOf.Capture, victim, building_Bed);
                    job.count = 1;
                    ZTracker.BuildJobListFor(pawn, pawn.Map, job);
                    ZLogger.Message(pawn + " taking first job 3");
                    pawn.jobs.EndCurrentJob(JobCondition.InterruptForced, false);
                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.Capturing, KnowledgeAmount.Total);
                    if (victim.Faction != null && victim.Faction != Faction.OfPlayer && !victim.Faction.def.hidden && !victim.Faction.HostileTo(Faction.OfPlayer) && !victim.IsPrisonerOfColony)
                    {
                        Messages.Message("MessageCapturingWillAngerFaction".Translate(victim.Named("PAWN"))
                                         .AdjustedFor(victim, "PAWN", true), victim, MessageTypeDefOf.CautionInput, false);
                    }
                }, MenuOptionPriority.RescueOrCapture, null, victim, 0f, null, null), pawn, victim, "ReservedBy");

                return(floatOption);
            }
Exemplo n.º 11
0
 // Token: 0x06000020 RID: 32 RVA: 0x000035CE File Offset: 0x000017CE
 internal static float GetFlashDistFactor(Pawn pawn, Pawn seer)
 {
     return(Mathf.Lerp(0.5f, 1f, Math.Min(CamoUtility.maxCamoDist, IntVec3Utility.DistanceTo(pawn.Position, seer.Position)) / CamoUtility.maxCamoDist));
 }
Exemplo n.º 12
0
        // Token: 0x0600001A RID: 26 RVA: 0x00002E4C File Offset: 0x0000104C
        public static bool CamoEffectWorked(Pawn target, Thing seer, Apparel ACApparel, float CamoEff, bool isActive, bool isStealth, int StealthCamoChance, out int chance, out float scaler)
        {
            float bestChance = Controller.Settings.bestChance;
            int   num        = 0;
            float num2       = IntVec3Utility.DistanceTo(target.Position, seer.Position);
            float num3       = 0.1f;
            float num4       = 0.2f;

            if (!isActive)
            {
                if (num2 >= CamoUtility.minCamoDist)
                {
                    if (num2 > CamoUtility.maxCamoDist)
                    {
                        scaler = 1f;
                    }
                    else
                    {
                        scaler = Mathf.Lerp(num3, 1f, Math.Max(0f, (num2 - CamoUtility.minCamoDist) / (CamoUtility.maxCamoDist - CamoUtility.minCamoDist)));
                    }
                }
                else
                {
                    scaler = 0f;
                }
            }
            else if (num2 >= CamoUtility.ACminCamoDist)
            {
                if (num2 > CamoUtility.ACmaxCamoDist)
                {
                    scaler = 1f;
                }
                else
                {
                    scaler = Mathf.Lerp(num4, 1f, Math.Max(0f, (num2 - CamoUtility.ACminCamoDist) / (CamoUtility.ACmaxCamoDist - CamoUtility.ACminCamoDist)));
                }
            }
            else
            {
                scaler = 0f;
            }
            float num5 = Math.Max(0f, Math.Min(1f, CamoEff));

            if (num5 > 0f)
            {
                scaler *= num5;
            }
            if (isActive)
            {
                scaler *= 0.95f + 0.05f * (Controller.Settings.RelPct / 100f);
            }
            else
            {
                scaler *= 0.85f + 0.1f * (Controller.Settings.RelPct / 100f);
            }
            if (scaler < 0f)
            {
                scaler = 0f;
            }
            if (scaler > 1f)
            {
                scaler = 1f;
            }
            int num6 = 0;

            if (StealthyBox.IsWearingStealthBox(target, out _))
            {
                num6 += 25;
            }
            int num7 = 0;

            if (isActive && ACApparel != null)
            {
                num7 = CamoUtility.GetQualOffset(ACApparel);
            }
            if (isActive)
            {
                if (isStealth)
                {
                    chance = StealthCamoChance;
                    num    = (int)Mathf.Lerp(Math.Min(bestChance, bestChance - (float)num7), Math.Max(1f, 1f - (float)num7), scaler);
                }
                else
                {
                    chance = (int)Mathf.Lerp(Math.Min(bestChance, bestChance - (float)num7), Math.Max(1f, 1f - (float)num7), scaler);
                }
            }
            else
            {
                chance = (int)Mathf.Lerp(bestChance, 1f, scaler);
            }
            int num8 = chance;

            if (!(seer is Pawn))
            {
                return(false);
            }
            if ((seer as Pawn).health.capacities.CapableOf(PawnCapacityDefOf.Sight))
            {
                float level = (seer as Pawn).health.capacities.GetLevel(PawnCapacityDefOf.Sight);
                if (Controller.Settings.DoCheckFlash)
                {
                    float gunFlashEff = CamoUtility.GetGunFlashEff(target, seer as Pawn);
                    if (gunFlashEff > 1f)
                    {
                        int num9 = chance;
                        if (isStealth)
                        {
                            num9 = num;
                        }
                        chance = Math.Min((int)bestChance, (int)((float)num9 * gunFlashEff));
                    }
                }
                int num10 = chance;
                if (chance > 0)
                {
                    float miscFactor = CamoUtility.GetMiscFactor(target, seer as Pawn, false);
                    chance = Math.Min((int)bestChance, (int)((float)chance * level * miscFactor));
                }
                int num11 = chance;
                if (CamoUtility.IsDebugMode())
                {
                    Log.Message("Base: " + num8.ToString() + ", Flash: " + num10.ToString() + ", Sight: " + num11.ToString(), false);
                }
                return(chance < 100 && (chance < 1 || CamoUtility.Rnd100() + num6 > chance));
            }
            return(true);
        }
        private Thing FindFood(Pawn pawn, IntVec3 gatheringSpot)
        {
            Predicate <Thing> validator = delegate(Thing x)
            {
                //Log.Message("Item candidate: " + x, true);
                if (IntVec3Utility.DistanceTo(x.Position, pawn.Position) > 50f)
                {
                    //Log.Message(" - FindFood - return false; - 1", true);
                    return(false);
                }
                if (!x.IngestibleNow)
                {
                    //Log.Message(" - FindFood - return false; - 2", true);
                    return(false);
                }
                if (!x.def.IsNutritionGivingIngestible)
                {
                    //Log.Message(" - FindFood - return false; - 4", true);
                    return(false);
                }
                if (x.def.IsDrug)
                {
                    if (!pawn.drugs.CurrentPolicy[x.def].allowedForJoy ||
                        pawn.Ideo != null && pawn.Ideo.PreceptsListForReading.Any(precept => precept.def.defName == "DrugUse_Prohibited" || precept.def.defName == "DrugUse_MedicalOnly"))
                    {
                        return(false);
                    }
                }

                if ((int)x.def.ingestible.preferability <= 4 && !x.def.IsDrug)
                {
                    //Log.Message(x.def + " - " + x.def.ingestible.preferability, true);
                    //Log.Message(" - FindFood - return false; - 10", true);
                    return(false);
                }
                if (!x.def.IsDrug && !pawn.WillEat(x))
                {
                    //Log.Message(" - FindFood - return false; - 12", true);
                    return(false);
                }
                if (x.IsForbidden(pawn))
                {
                    //Log.Message(" - FindFood - return false; - 14", true);
                    return(false);
                }
                if (!x.IsSociallyProper(pawn))
                {
                    //Log.Message(" - FindFood - return false; - 16", true);
                    return(false);
                }
                //Log.Message(pawn + " canReserve " + x + ": " + canReserve, true);
                return(!x.IsForbidden(pawn) && pawn.CanReserveAndReach(x, PathEndMode.OnCell, Danger.Deadly));
            };

            List <Thing> list          = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.FoodSourceNotPlantOrTree);
            Thing        foodCandidate = null;

            if (pawn.needs.food.CurLevel < 0.4)
            {
                foodCandidate = SpawnedFoodSearchInnerScan(pawn, pawn.Position, list, PathEndMode.OnCell, TraverseParms.For(TraverseMode.ByPawn, Danger.Deadly), 50, validator);
            }
            else
            {
                foodCandidate = list.Where(x => validator(x)).OrderByDescending(x => x.def.ingestible?.joy).ToList().FirstOrDefault();
                if (foodCandidate is null || !(foodCandidate.def.ingestible?.joy > 0))
                {
                    foodCandidate = SpawnedFoodSearchInnerScan(pawn, pawn.Position, list, PathEndMode.OnCell, TraverseParms.For(TraverseMode.ByPawn, Danger.Deadly), 50, validator);
                }
            }
            //Log.Message(pawn + " - " + foodCandidate, true);
            return(foodCandidate);
        }
Exemplo n.º 14
0
        public static IEnumerable <Toil> Toils_GoToThingMap(Pawn pawn, Thing selectedStairs, Thing thing, JobDriver instance)
        {
            Toil setStairs = new Toil
            {
                initAction = delegate()
                {
                    var ZTracker = Current.Game.GetComponent <ZLevelsManager>();
                    ZLogger.Message("Pawn: " + pawn);
                    ZLogger.Message("Pawn.map: " + pawn.Map);
                    ZLogger.Message("thing: " + thing);
                    ZLogger.Message("thing.Map: " + thing.Map);
                    ZLogger.Message("pawn.CurJob: " + pawn.jobs.curJob);
                    if (ZTracker.GetZIndexFor(pawn.Map) > ZTracker.GetZIndexFor(thing.Map))
                    {
                        var stairs = ZTracker.stairsDown[pawn.Map];
                        if (stairs?.Count() > 0)
                        {
                            selectedStairs = stairs.MinBy(x => IntVec3Utility.DistanceTo(thing.Position, x.Position));
                        }
                    }
                    else if (ZTracker.GetZIndexFor(pawn.Map) < ZTracker.GetZIndexFor(thing.Map))
                    {
                        var stairs = ZTracker.stairsUp[pawn.Map];
                        if (stairs?.Count() > 0)
                        {
                            selectedStairs = stairs.MinBy(x => IntVec3Utility.DistanceTo(thing.Position, x.Position));
                        }
                    }
                    pawn.jobs.curJob.targetC = new LocalTargetInfo(selectedStairs);
                }
            };

            yield return(setStairs);

            yield return(Toils_Goto.GotoThing(TargetIndex.C, PathEndMode.OnCell));

            Toil useStairs = Toils_General.Wait(60, 0);

            ToilEffects.WithProgressBarToilDelay(useStairs, TargetIndex.C, false, -0.5f);
            ToilFailConditions.FailOnDespawnedNullOrForbidden <Toil>(useStairs, TargetIndex.C);
            //ToilFailConditions.FailOnCannotTouch<Toil>(useStairs, TargetIndex.C, PathEndMode.OnCell);
            yield return(useStairs);

            yield return(new Toil
            {
                initAction = delegate()
                {
                    var ZTracker = Current.Game.GetComponent <ZLevelsManager>();
                    if (selectedStairs is Building_StairsUp stairsUp)
                    {
                        Map map = ZTracker.GetUpperLevel(pawn.Map.Tile, pawn.Map);
                        if (map == null)
                        {
                            map = ZTracker.CreateUpperLevel(pawn.Map, stairsUp.Position);
                            if (stairsUp.pathToPreset != null && stairsUp.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path = stairsUp.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, true, false, true);
                        }
                        else
                        {
                            if (stairsUp.pathToPreset != null && stairsUp.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path = stairsUp.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, false, false, stairsUp.shouldSpawnStairsUpper);
                            stairsUp.shouldSpawnStairsUpper = false;
                        }
                    }

                    else if (selectedStairs is Building_StairsDown stairsDown)
                    {
                        Map map = ZTracker.GetLowerLevel(pawn.Map.Tile, pawn.Map);
                        if (map == null)
                        {
                            map = ZTracker.CreateLowerLevel(pawn.Map, stairsDown.Position);
                            if (stairsDown.pathToPreset != null && stairsDown.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path = stairsDown.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, true, true);
                        }
                        else
                        {
                            if (stairsDown.pathToPreset != null && stairsDown.pathToPreset.Length > 0)
                            {
                                var comp = map.GetComponent <MapComponentZLevel>();
                                comp.DoGeneration = true;
                                comp.path = stairsDown.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, false, stairsDown.shouldSpawnStairsBelow);
                            stairsDown.shouldSpawnStairsBelow = false;
                        }
                    }

                    if (pawn.Map != thing.Map)
                    {
                        instance.JumpToToil(setStairs);
                    }
                }
            });
Exemplo n.º 15
0
        private static bool Prefix(ref JobGiver_AIFightEnemy __instance, ref Job __result, ref Pawn pawn)
        {
            bool flag = !pawn.RaceProps.Animal;
            bool result;

            if (flag)
            {
                result = true;
            }
            else
            {
                bool        flag2    = false;
                List <Verb> allVerbs = pawn.verbTracker.AllVerbs;
                List <Verb> list     = new List <Verb>();
                for (int i = 0; i < allVerbs.Count; i++)
                {
                    bool flag3 = allVerbs[i].verbProps.range > 1.1f;
                    if (flag3)
                    {
                        list.Add(allVerbs[i]);
                        flag2 = true;
                    }
                }
                bool flag4 = !flag2;
                if (flag4)
                {
                    result = true;
                }
                else
                {
                    Verb verb  = GenCollection.RandomElementByWeight <Verb>(list, (Verb rangeItem) => rangeItem.verbProps.commonality);
                    bool flag5 = verb == null;
                    if (flag5)
                    {
                        result = true;
                    }
                    else
                    {
                        Thing thing = (Thing)AttackTargetFinder.BestAttackTarget(pawn, TargetScanFlags.NeedThreat, (Thing x) => x is Pawn || x is Building, 0f, verb.verbProps.range, default(IntVec3), float.MaxValue, false, true);
                        bool  flag6 = thing == null;
                        if (flag6)
                        {
                            result = true;
                        }
                        else
                        {
                            bool flag7 = IntVec3Utility.DistanceTo(thing.Position, pawn.Position) < verb.verbProps.minRange;
                            if (flag7)
                            {
                                bool flag8 = GenAdj.AdjacentTo8Way(thing.Position, pawn.Position);
                                if (flag8)
                                {
                                    __result = new Job(JobDefOf.AttackMelee, thing)
                                    {
                                        maxNumMeleeAttacks     = 1,
                                        expiryInterval         = Rand.Range(420, 900),
                                        attackDoorIfTargetLost = false
                                    };
                                    return(false);
                                }
                                bool flag9 = pawn.Faction != null && !pawn.Faction.def.isPlayer;
                                if (!flag9)
                                {
                                    bool flag10 = ReachabilityUtility.CanReach(pawn, thing, PathEndMode.Touch, Danger.Deadly, false, 0) && pawn.playerSettings.Master.playerSettings.animalsReleased;
                                    if (flag10)
                                    {
                                        __result = new Job(JobDefOf.AttackMelee, thing)
                                        {
                                            maxNumMeleeAttacks     = 1,
                                            expiryInterval         = Rand.Range(420, 900),
                                            attackDoorIfTargetLost = false
                                        };
                                        return(false);
                                    }
                                    return(true);
                                }
                            }
                            bool flag11 = (double)CoverUtility.CalculateOverallBlockChance(pawn.Position, thing.Position, pawn.Map) > 0.00999999977648258;
                            bool flag12 = GenGrid.Standable(pawn.Position, pawn.Map);
                            bool flag13 = verb.CanHitTarget(thing);
                            bool flag14 = (pawn.Position - thing.Position).LengthHorizontalSquared < 25;
                            bool flag15 = (flag11 && flag12 && flag13) || (flag14 && flag13);
                            if (flag15)
                            {
                                JobDef named = DefDatabase <JobDef> .GetNamed("PI_AnimalRangeAttack", true);

                                LocalTargetInfo localTargetInfo = thing;
                                IntRange        expiryInterval_ShooterSucceeded = JobGiver_AIFightEnemy.ExpiryInterval_ShooterSucceeded;
                                __result = new Job(named, localTargetInfo, expiryInterval_ShooterSucceeded.RandomInRange, true)
                                {
                                    verbToUse = verb
                                };
                                result = false;
                            }
                            else
                            {
                                CastPositionRequest castPositionRequest = default(CastPositionRequest);
                                castPositionRequest.caster              = pawn;
                                castPositionRequest.target              = thing;
                                castPositionRequest.verb                = verb;
                                castPositionRequest.maxRangeFromTarget  = verb.verbProps.range;
                                castPositionRequest.wantCoverFromTarget = (pawn.training.HasLearned(TrainableDefOf.Release) && (double)verb.verbProps.range > 7.0);
                                castPositionRequest.locus               = pawn.playerSettings.Master.Position;
                                castPositionRequest.maxRangeFromLocus   = Traverse.Create(__instance).Method("GetFlagRadius", new object[]
                                {
                                    pawn
                                }).GetValue <float>();
                                castPositionRequest.maxRegions = 50;
                                IntVec3 intVec = new IntVec3();
                                bool    flag16 = CastPositionFinder.TryFindCastPosition(castPositionRequest, out intVec);
                                bool    flag17 = !flag16;
                                if (flag17)
                                {
                                    result = true;
                                }
                                else
                                {
                                    bool flag18 = intVec == pawn.Position;
                                    if (flag18)
                                    {
                                        JobDef named2 = DefDatabase <JobDef> .GetNamed("PI_AnimalRangeAttack", true);

                                        LocalTargetInfo localTargetInfo2 = thing;
                                        IntRange        expiryInterval_ShooterSucceeded = JobGiver_AIFightEnemy.ExpiryInterval_ShooterSucceeded;
                                        __result = new Job(named2, localTargetInfo2, expiryInterval_ShooterSucceeded.RandomInRange, true)
                                        {
                                            verbToUse = verb
                                        };
                                        result = false;
                                    }
                                    else
                                    {
                                        Job      job = new Job(JobDefOf.Goto, intVec);
                                        IntRange expiryInterval_ShooterSucceeded = JobGiver_AIFightEnemy.ExpiryInterval_ShooterSucceeded;
                                        job.expiryInterval        = expiryInterval_ShooterSucceeded.RandomInRange;
                                        job.checkOverrideOnExpire = true;
                                        __result = job;
                                        result   = false;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
Exemplo n.º 16
0
        // Token: 0x0600002A RID: 42 RVA: 0x00002E28 File Offset: 0x00001028
        internal bool FlightCellCheck(Pawn pilot, IntVec3 tCell, int fuel, float fRate, float minJump, float maxJump, out string cantReason)
        {
            cantReason = "";
            if (!GenGrid.InBounds(tCell, pilot.Map))
            {
                cantReason = Translator.Translate("JetPack.JumpReasonInvalid");
                return(false);
            }
            if (this.JPOnCooldown)
            {
                cantReason = Translator.Translate("JetPack.JumpReasonOnCooldown");
                return(false);
            }
            if (!ReservationUtility.CanReserve(pilot, tCell, 1, -1, null, false))
            {
                cantReason = Translator.Translate("JetPack.JumpReasonReserved");
                return(false);
            }
            if (GridsUtility.Roofed(tCell, pilot.Map))
            {
                if (!Settings.RoofPunch)
                {
                    cantReason = Translator.Translate("JetPack.JumpReasonRoofed");
                    return(false);
                }
                ThingDef chkSKF = DefDatabase <ThingDef> .GetNamed(this.JPSkyFallType, false);

                if (chkSKF == null || !chkSKF.skyfaller.hitRoof)
                {
                    cantReason = TranslatorFormattedStringExtensions.Translate("JetPack.JumpReasonSFNotRPunch", (chkSKF != null) ? GenText.CapitalizeFirst(chkSKF.label) : null);
                    return(false);
                }
            }
            if (!GenGrid.Walkable(tCell, pilot.Map))
            {
                cantReason = Translator.Translate("JetPack.JumpReasonNotWalk");
                return(false);
            }
            if (DangerUtility.GetDangerFor(tCell, pilot, pilot.Map) == Danger.Deadly)
            {
                cantReason = Translator.Translate("JetPack.JumpReasonDeadly");
                return(false);
            }
            float distance = IntVec3Utility.DistanceTo(pilot.Position, tCell);

            if (distance < minJump)
            {
                cantReason = TranslatorFormattedStringExtensions.Translate("JetPack.JumpReasonMinRange", ((int)minJump).ToString());
                return(false);
            }
            if (distance > maxJump)
            {
                cantReason = TranslatorFormattedStringExtensions.Translate("JetPack.JumpReasonMaxRange", ((int)maxJump).ToString());
                return(false);
            }
            if (fRate <= 0f)
            {
                cantReason = TranslatorFormattedStringExtensions.Translate("JetPack.JumpFuelRateInvalid", fRate.ToString());
                return(false);
            }
            float distCanJump;

            if (Settings.UseCarry)
            {
                distCanJump = (float)fuel / fRate * JPWeightUtility.JPCarryFactor(pilot, this.def, this.JPFuelItem);
            }
            else
            {
                distCanJump = (float)fuel / fRate;
            }
            if (distCanJump > maxJump)
            {
                distCanJump = maxJump;
            }
            if (distCanJump < distance)
            {
                cantReason = Translator.Translate("JetPack.JumpNotEnoughfuel");
                return(false);
            }
            return(true);
        }