コード例 #1
0
        public static void Postfix(Verb __instance, IntVec3 root, LocalTargetInfo targ, ref ShootLine resultingLine, ref bool __result)
        {
            if (teleportBack)
            {
                if (oldMap1 != null)
                {
                    ZUtils.TeleportThing(targ.Thing, oldMap1, targ.Thing.Position);
                    oldMap1 = null;
                }
                else if (oldMap2 != null)
                {
                    ZUtils.TeleportThing(__instance.caster, oldMap2, __instance.caster.Position);
                    oldMap2 = null;
                }

                if (__result)
                {
                    if (ind1 > ind2 && !IsVoidsEverywhereInShootingLine(resultingLine, __instance.caster.Map, __instance.caster, targ.Thing))
                    {
                        __result = false;
                    }
                    else if (ind1 < ind2 && !IsVoidsEverywhereInShootingLineInBackWard(resultingLine, targ.Thing.Map, __instance.caster, targ.Thing))
                    {
                        __result = false;
                    }
                }

                ind1         = 0;
                ind2         = 0;
                teleportBack = false;
            }
        }
コード例 #2
0
        public static void Prefix(Verb_LaunchProjectile __instance, List <IntVec3> ___tempLeanShootSources, List <IntVec3> ___tempDestList, LocalTargetInfo ___currentTarget, ref bool __result)
        {
            //ZLogger.Message("__instance.caster: " + __instance.caster, true);
            //ZLogger.Message("__instance.caster.Map: " + __instance.caster.Map, true);
            //ZLogger.Message("__instance.caster.Map.Tile: " + __instance.caster.Map.Tile, true);
            //
            //ZLogger.Message("___currentTarget.Thing: " + ___currentTarget.Thing, true);
            //ZLogger.Message("___currentTarget.Thing?.Map: " + ___currentTarget.Thing?.Map, true);
            //ZLogger.Message("___currentTarget.Thing?.Map.Tile: " + ___currentTarget.Thing?.Map.Tile, true);

            if (__instance.caster.Map != ___currentTarget.Thing?.Map && __instance.caster.Map.Tile == ___currentTarget.Thing?.Map?.Tile)
            {
                var ind1 = ZUtils.ZTracker.GetZIndexFor(__instance.caster.Map);
                var ind2 = ZUtils.ZTracker.GetZIndexFor(___currentTarget.Thing.Map);
                if (ind1 > ind2)
                {
                    teleportBack = true;
                    targetOldMap = ___currentTarget.Thing.Map;
                    ZUtils.TeleportThing(___currentTarget.Thing, __instance.caster.Map, ___currentTarget.Thing.Position);
                    RoofAndFloorPatches.Patch_SpawnSetup.doTeleport = false;
                }
                else if (ind1 < ind2)
                {
                    teleportBack = true;
                    casterOldMap = __instance.caster.Map;
                    ZUtils.TeleportThing(__instance.caster, ___currentTarget.Thing.Map, __instance.caster.Position);
                    RoofAndFloorPatches.Patch_SpawnSetup.doTeleport = false;
                }
            }
        }
コード例 #3
0
 private static Exception Finalizer(Exception __exception, Pawn pawn)
 {
     if (__exception != null)
     {
         Log.Error("Z-Levels caught an exception: " + __exception + ", trying to fix it");
         ZUtils.TryFixPawnError(pawn);
         IntVec3 nextCell = pawn.pather.nextCell;
         foreach (IntVec3 item in CellRect.FromLimits(nextCell, pawn.Position).ExpandedBy(1))
         {
             if (item.InBounds(pawn.Map))
             {
                 List <Thing> thingList = item.GetThingList(pawn.Map);
                 for (int i = 0; i < thingList.Count; i++)
                 {
                     Pawn pawn2 = thingList[i] as Pawn;
                     if (pawn2 != null && pawn2 != pawn && pawn2.GetPosture() == PawnPosture.Standing)
                     {
                         ZUtils.TryFixPawnError(pawn);
                     }
                 }
             }
         }
         return(__exception);
     }
     return(null);
 }
コード例 #4
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      = Find.Selector.SelectedObjects.Contains(pawn);

                    Building building_Bed = null;
                    foreach (var otherMap in ZUtils.GetAllMapsInClosestOrderForTwoThings(pawn, oldMap, oldPosition1,
                                                                                         victim, oldMap, 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;
                        }
                    }

                    ZUtils.TeleportThing(pawn, oldMap, oldPosition1);
                    ZUtils.TeleportThing(victim, oldMap, 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);
            }
コード例 #5
0
 private static void Prefix(ref int __result, ReservationManager __instance, Pawn claimant, LocalTargetInfo target, ref bool __state, int maxPawns = 1, ReservationLayerDef layer = null, bool ignoreOtherReservations = false)
 {
     if (target.HasThing && target.Thing.Map != claimant.Map)
     {
         oldMap = claimant.Map;
         ZUtils.TeleportThing(claimant, target.Thing.Map, claimant.Position);
         __state = true;
     }
 }
コード例 #6
0
 private static bool SpawnAnimalPrefix(WildAnimalSpawner __instance, ref IntVec3 loc,
                                       ref bool __result, Map ___map)
 {
     if (ZLevelsMod.settings.allowZLevelsInfestation)
     {
         try
         {
             bool result   = false;
             var  comp     = ZUtils.GetMapComponentZLevel(___map);
             var  ZTracker = ZUtils.ZTracker;
             if (___map.Parent is MapParent_ZLevel && comp != null &&
                 ZTracker.GetUpperLevel(___map.Tile, ___map) != null &&
                 !ZUtils.GetMapComponentZLevel(ZTracker.GetUpperLevel(___map.Tile, ___map))
                 .hasCavesBelow.GetValueOrDefault(false))
             {
                 result = false;
             }
             else
             {
                 PawnKindDef pawnKindDef = (from a in ___map.Biome.AllWildAnimals
                                            where ___map.mapTemperature.SeasonAcceptableFor(a.race)
                                            select a)
                                           .RandomElementByWeight((PawnKindDef def) =>
                                                                  ___map.Biome.CommonalityOfAnimal(def) / def.wildGroupSize.Average);
                 if (pawnKindDef == null)
                 {
                     Log.Error("No spawnable animals right now.");
                     result = false;
                 }
                 else
                 {
                     ZLogger.Message("Spawning animal: " + pawnKindDef + " in biome: " + ___map.Biome);
                     int randomInRange = pawnKindDef.wildGroupSize.RandomInRange;
                     int radius        = Mathf.CeilToInt(Mathf.Sqrt((float)pawnKindDef.wildGroupSize.max));
                     if (___map.Parent is MapParent_ZLevel && !loc.Walkable(___map))
                     {
                         loc = CellFinderLoose.RandomCellWith((IntVec3 sq) => sq.Walkable(___map), ___map);
                     }
                     for (int i = 0; i < randomInRange; i++)
                     {
                         IntVec3 loc2 = CellFinder.RandomClosewalkCellNear(loc, ___map, radius, null);
                         GenSpawn.Spawn(PawnGenerator.GeneratePawn(pawnKindDef, null), loc2, ___map, WipeMode.Vanish);
                     }
                     result = true;
                 }
             }
             __result = result;
         }
         catch (Exception ex)
         {
             Log.Error("[Z-Levels] SpawnAnimalPrefix patch produced an error. That should not happen and will break things. Send a Hugslib log to the Z-Levels developers. Error message: " + ex);
         }
         return(false);
     }
     return(true);
 }
コード例 #7
0
 private static bool PreFix(ref bool __result, IncidentParms parms)
 {
     if (ZLevelsMod.settings.allowZLevelsInfestation)
     {
         try
         {
             Map map  = (Map)parms.target;
             var comp = ZUtils.GetMapComponentZLevel(map);
             if (comp.hasCavesBelow.HasValue && comp.hasCavesBelow.Value)
             {
                 var foods = map.listerThings.AllThings.Where(x => !(x is Plant) && !(x is Pawn) &&
                                                              x.GetStatValue(StatDefOf.Nutrition, true) > 0.1f);
                 if (foods != null && foods.Any())
                 {
                     List <PawnKindDef> infestators = new List <PawnKindDef>
                     {
                         ZLevelsDefOf.ZL_UndegroundBiome.AllWildAnimals.RandomElement()
                     };
                     var infestationPlace = foods.RandomElement().Position;
                     var infestationData  = new InfestationData(infestators, parms.points, infestationPlace);
                     if (comp.ActiveInfestations == null)
                     {
                         comp.ActiveInfestations = new List <InfestationData>();
                     }
                     comp.ActiveInfestations.Add(infestationData);
                     if (comp.TotalInfestations == null)
                     {
                         comp.TotalInfestations = new List <InfestationData>();
                     }
                     comp.TotalInfestations.Add(infestationData);
                     var naturalHole = (Building_StairsDown)ThingMaker.MakeThing(ZLevelsDefOf.ZL_NaturalHole);
                     naturalHole.infestationData = infestationData;
                     GenSpawn.Spawn(naturalHole, infestationPlace, map, WipeMode.Vanish);
                     Find.LetterStack.ReceiveLetter("ZLevelInfestation"
                                                    .Translate(infestators.RandomElement().race.label), "ZLevelInfestationDesc".Translate(),
                                                    LetterDefOf.ThreatBig, naturalHole);
                 }
             }
             else
             {
                 ZLogger.Message("The map has no caves below to generate infestation");
             }
             __result = false;
         }
         catch (Exception ex)
         {
             Log.Error("[Z-Levels] Patch_Infestation_TryExecuteWorker patch produced an error. That should not happen and will break things. Send a Hugslib log to the Z-Levels developers. Error message: " + ex);
         }
         return(false);
     }
     return(true);
 }
コード例 #8
0
        private static void Postfix(Reachability __instance, ref bool __result, IntVec3 start, LocalTargetInfo dest, PathEndMode peMode, TraverseParms traverseParams, bool __state)
        {
            if (__state && traverseParams.pawn != null)
            {
                //Log.Message("Postfix: dest: " + dest + " - dest.thingInt.Map: " + dest.thingInt?.Map + " - pawn.Map: " + traverseParams.pawn.Map + " - __instance: " + __instance.map);
                ZUtils.TeleportThing(traverseParams.pawn, oldMap, oldPosition);
            }

            //if (dest.HasThing)
            //{
            //    Log.Message($"{pawn} can reach {dest}: {__result}, {pawn.Map} - {dest.Thing.Map}");
            //}
        }
コード例 #9
0
        private static bool Prefix(ref bool __result, ReservationManager __instance, Pawn claimant, LocalTargetInfo target, out bool __state, int maxPawns = 1, int stackCount = -1, ReservationLayerDef layer = null, bool ignoreOtherReservations = false)
        {
            __state = false;
            if (claimant.RaceProps.Humanlike)
            {
                if (target.HasThing)
                {
                    if (target.thingInt.Map != null && target.thingInt.Map != claimant.Map)
                    {
                        var cellToTeleport = ZUtils.GetCellToTeleportFrom(claimant.Map, claimant.Position, target.thingInt.Map);
                        var cell           = cellToTeleport.IsValid ? cellToTeleport : claimant.Position;

                        __state     = true;
                        oldMap      = claimant.Map;
                        oldPosition = claimant.Position;
                        ZUtils.TeleportThing(claimant, target.thingInt.Map, cell);
                        ZLogger.Message($"Teleporting claimaint {claimant} to {target.thingInt.Map}");
                        __result = claimant.CanReserve(target, maxPawns, stackCount, layer, ignoreOtherReservations);
                        return(false);
                    }
                }
                else
                {
                    if (ZUtils.ZTracker.jobTracker.TryGetValue(claimant, out var jobTracker) && jobTracker.lookedAtLocalCellMap != null &&
                        jobTracker.lookedAtLocalCellMap.TryGetValue(target.cellInt, out var mapDest))
                    {
                        if (mapDest != null && mapDest != claimant.Map)
                        {
                            var cellToTeleport = ZUtils.GetCellToTeleportFrom(claimant.Map, claimant.Position, mapDest);
                            var cell           = cellToTeleport.IsValid ? cellToTeleport : claimant.Position;

                            __state     = true;
                            oldMap      = claimant.Map;
                            oldPosition = claimant.Position;
                            ZUtils.TeleportThing(claimant, mapDest, cell);
                            ZLogger.Message($"3 Teleporting claimaint {claimant} to {mapDest}");
                            __result = claimant.CanReserve(target, maxPawns, stackCount, layer, ignoreOtherReservations);
                            return(false);
                        }
                    }
                    //else
                    //{
                    //    if (ZUtils.ZTracker.jobTracker.TryGetValue(claimant, out var job))
                    //    {
                    //    }
                    //    ZLogger.Pause($"2 Unsupported target (most likely cell), claimant: {claimant}, target {target}");
                    //}
                }
            }
            return(true);
        }
コード例 #10
0
ファイル: CombatPatches.cs プロジェクト: Proxyer/Z-Levels
        public static bool Prefix(ref IAttackTarget __result, List <IAttackTarget> ___tmpTargets, List <Pair <IAttackTarget, float> > ___availableShootingTargets,
                                  List <float> ___tmpTargetScores, List <bool> ___tmpCanShootAtTarget, List <IntVec3> ___tempDestList, List <IntVec3> ___tempSourceList,
                                  IAttackTargetSearcher searcher, TargetScanFlags flags, Predicate <Thing> validator = null, float minDist = 0f,
                                  float maxDist = 9999f, IntVec3 locus = default(IntVec3), float maxTravelRadiusFromLocus = 3.40282347E+38f, bool canBash = false,
                                  bool canTakeTargetsCloserThanEffectiveMinRange = true)
        {
            bool result = true;

            if (!recursiveTrap && multiMapSearch)
            {
                recursiveTrap = true;
                Map     oldMap             = searcher.Thing.Map;
                IntVec3 oldPosition        = searcher.Thing.Position;
                bool    dontCheckForStairs = searcher.Thing is Building;
                foreach (var map in ZUtils.GetAllMapsInClosestOrder(searcher.Thing, oldMap, oldPosition, dontCheckForStairs: dontCheckForStairs))
                {
                    if (ZUtils.ZTracker.GetZIndexFor(map) < ZUtils.ZTracker.GetZIndexFor(oldMap))
                    {
                        CanBeSeenOverFast_Patch.checkLevels = true;
                        CanBeSeenOverFast_Patch.upperMap    = oldMap;
                        CanBeSeenOverFast_Patch.lowerMap    = map;
                        CanBeSeenOverFast_Patch.caster      = searcher.Thing;
                    }
                    var target = AttackTargetFinder.BestAttackTarget(searcher, flags, validator, minDist,
                                                                     maxDist, locus, maxTravelRadiusFromLocus, canBash, canTakeTargetsCloserThanEffectiveMinRange);
                    //ZLogger.Message(searcher.Thing + " - 1: " + ZUtils.ZTracker.GetMapInfo(searcher.Thing.Map) + " - result: " + target);
                    if (target != null)
                    {
                        __result = target;
                        result   = false;
                        break;
                    }
                }
                //ZLogger.Message("1 Trying to get " + searcher.Thing + " back to " + oldMap + " - " + oldPosition, true);
                ZUtils.TeleportThing(searcher.Thing, oldMap, oldPosition);
                recursiveTrap = false;
                CanBeSeenOverFast_Patch.checkLevels = false;
                CanBeSeenOverFast_Patch.upperMap    = null;
                CanBeSeenOverFast_Patch.lowerMap    = null;
                CanBeSeenOverFast_Patch.caster      = null;
            }
            //else if (!multiMapSearch)
            //{
            //    ZLogger.Message("BestAttackTarget: multiMapSearch: " + multiMapSearch, true);
            //}
            return(result);
        }
コード例 #11
0
            private static void Postfix(Pawn ___pawn, ref IEnumerable <Thing> __result, Pawn playerNegotiator)
            {
                var     result      = __result.ToList();
                Map     oldMap      = ___pawn.Map;
                IntVec3 oldPosition = playerNegotiator.Position;
                bool    select      = false;

                if (Find.Selector.SelectedObjects.Contains(___pawn))
                {
                    select = true;
                }
                foreach (var map in ZUtils.GetAllMapsInClosestOrder(___pawn, oldMap, oldPosition))
                {
                    if (map != oldMap)
                    {
                        IEnumerable <Thing> enumerable = ___pawn.Map.listerThings.AllThings.Where((Thing x)
                                                                                                  => x.def.category == ThingCategory.Item && TradeUtility.PlayerSellableNow(x, ___pawn) &&
                                                                                                  !x.Position.Fogged(x.Map) && (___pawn.Map.areaManager.Home[x.Position] ||
                                                                                                                                x.IsInAnyStorage()) && ReachableForTrade(x, ___pawn));
                        foreach (Thing item in enumerable)
                        {
                            result.Add(item);
                        }
                        if (___pawn.GetLord() != null)
                        {
                            foreach (Pawn item2 in from x in TradeUtility.AllSellableColonyPawns(___pawn.Map)
                                     where !x.Downed && ReachableForTrade(x, ___pawn)
                                     select x)
                            {
                                result.Add(item2);
                            }
                        }
                    }
                }
                if (___pawn.Map != oldMap)
                {
                    Traverse.Create(___pawn).Field("mapIndexOrState")
                    .SetValue((sbyte)Find.Maps.IndexOf(oldMap));
                    Traverse.Create(___pawn).Field("positionInt")
                    .SetValue(oldPosition);
                }
                if (select)
                {
                    Find.Selector.Select(___pawn);
                }
                __result = result;
            }
コード例 #12
0
 public static void Postfix(Verb_LaunchProjectile __instance, List <IntVec3> ___tempLeanShootSources, List <IntVec3> ___tempDestList, LocalTargetInfo ___currentTarget, ref bool __result)
 {
     if (teleportBack)
     {
         if (targetOldMap != null)
         {
             ZUtils.TeleportThing(___currentTarget.Thing, targetOldMap, ___currentTarget.Thing.Position);
             targetOldMap = null;
             RoofAndFloorPatches.Patch_SpawnSetup.doTeleport = true;
         }
         else if (casterOldMap != null)
         {
             ZUtils.TeleportThing(__instance.caster, casterOldMap, __instance.caster.Position);
             casterOldMap = null;
             RoofAndFloorPatches.Patch_SpawnSetup.doTeleport = true;
         }
     }
 }
コード例 #13
0
 public static void Prefix(Verb __instance, IntVec3 root, LocalTargetInfo targ, ref ShootLine resultingLine, ref bool __result)
 {
     if (__instance.caster?.Map != targ.Thing?.Map && __instance.caster?.Map?.Tile == targ.Thing?.Map?.Tile)
     {
         ind1 = ZUtils.ZTracker.GetZIndexFor(__instance.caster.Map);
         ind2 = ZUtils.ZTracker.GetZIndexFor(targ.Thing.Map);
         if (ind1 > ind2)
         {
             teleportBack = true;
             oldMap1      = targ.Thing.Map;
             ZUtils.TeleportThing(targ.Thing, __instance.caster.Map, targ.Thing.Position);
         }
         else if (ind1 < ind2)
         {
             teleportBack = true;
             oldMap2      = __instance.caster.Map;
             ZUtils.TeleportThing(__instance.caster, targ.Thing.Map, __instance.caster.Position);
         }
     }
 }
コード例 #14
0
 private static Exception Finalizer(Exception __exception, IntVec3 at, Map map)
 {
     if (__exception != null)
     {
         foreach (IntVec3 item in CellRect.SingleCell(at).ExpandedBy(1))
         {
             if (item.InBounds(map))
             {
                 List <Thing> thingList = item.GetThingList(map);
                 for (int i = 0; i < thingList.Count; i++)
                 {
                     Pawn pawn = thingList[i] as Pawn;
                     if (pawn != null && pawn.GetPosture() == PawnPosture.Standing)
                     {
                         ZUtils.TryFixPawnError(pawn);
                     }
                 }
             }
         }
         Log.Error("Z-Levels caught an exception: " + __exception + ", trying to fix it");
         return(__exception);
     }
     return(null);
 }
コード例 #15
0
        private static void Postfix(ref bool __result, Pawn claimant, LocalTargetInfo target, bool __state, int maxPawns = 1, int stackCount = -1, ReservationLayerDef layer = null, bool ignoreOtherReservations = false)
        {
            if (__state)
            {
                ZUtils.TeleportThing(claimant, oldMap, oldPosition);
            }
            if (__result)
            {
                var thing = target.Thing;
                if (thing != null)
                {
                    if (claimant.RaceProps.Humanlike && target.HasThing)
                    {
                        var ZTracker = ZUtils.ZTracker;
                        //foreach (var map in ZTracker.GetAllMaps(claimant.Map.Tile))
                        //{
                        //    foreach (var reservation in map.reservationManager.reservations)
                        //    {
                        //        Log.Message($"map: {map}, Reservation: {reservation.claimant}, target: {reservation.target}, {reservation.claimant.Map} - {reservation.target.Thing?.Map}");
                        //    }
                        //}

                        if (ZTracker.jobTracker != null)
                        {
                            foreach (var data in ZTracker.jobTracker)
                            {
                                if (data.Key != claimant && data.Value.reservedThings != null)
                                {
                                    foreach (var reservation in data.Value.reservedThings)
                                    {
                                        if (reservation.HasThing && reservation.thingInt == target.thingInt)
                                        {
                                            var shouldChangeResult = !((data.Key.jobs?.curDriver is JobDriver_TakeToBed) || (data.Key.jobs?.curDriver is JobDriver_LayDown));
                                            if (shouldChangeResult)
                                            {
                                                Log.Message(data.Key + " - data.Value.mainJob: " + data.Value.mainJob);
                                                Log.Message(data.Key + " - data.Key.CurJob: " + data.Key.CurJob);
                                                Log.Message(data.Key + " - thing.Map.reservationManager.reservations.Any(x => x.Target.thingInt == thing && x.claimant == data.Key): " + thing.Map.reservationManager.reservations.Any(x => x.Target.thingInt == thing && x.claimant == data.Key));
                                                if (data.Key.Map == thing.Map && !thing.Map.reservationManager.reservations.Any(x => x.Target.thingInt == thing && x.claimant == data.Key))
                                                {
                                                    ZLogger.Error($"PREVENTED ZTRACKER reservation disfunction: claimant: {claimant}, pawn: {data.Key}, thing: {thing}");
                                                    continue;
                                                }
                                                __result = false;
                                                ZLogger.Message($"Detected ZTRACKER reservation disfunction: claimant: {claimant}, pawn: {data.Key}, thing: {thing}");
                                                return;
                                            }
                                        }
                                        //Log.Message($"ZTracker reservation: map: Reservation: {data.Key}, target: {reservation}, {data.Key.Map} - {reservation.Thing?.Map}");
                                    }
                                }
                            }
                        }
                        //Log.Message($"---------------------");
                    }
                    //Log.Message($"{claimant} can reserve {target}: {__result}, {claimant.Map} - {target.Thing?.Map}");

                    //if (claimant.Map != thing.Map)
                    //{
                    //    ZLogger.Pause($"CanReserve: {__result}, Detected reservation disfunction: claimant.Map != thing.Map, claimant: {claimant}, thing: {thing}");
                    //    var ZTracker = ZUtils.ZTracker;
                    //    foreach (var map in ZTracker.GetAllMaps(thing.Map.Tile))
                    //    {
                    //        var pawn = map.reservationManager.FirstRespectedReserver(target, claimant);
                    //        if (pawn != null && pawn != claimant)
                    //        {
                    //            ZLogger.Pause($"CanReserve: {__result}, Detected reservation disfunction: claimant: {claimant}, pawn: {pawn}, thing: {thing}");
                    //        }
                    //    }
                    //}
                    //else
                    //{
                    //    var ZTracker = ZUtils.ZTracker;
                    //    foreach (var map in ZTracker.GetAllMaps(thing.Map.Tile))
                    //    {
                    //        var pawn = map.reservationManager.FirstRespectedReserver(target, claimant);
                    //        if (pawn != null && pawn != claimant)
                    //        {
                    //            ZLogger.Pause($"CanReserve: {__result}, Detected other claimant: first claimant: {claimant}, second claimant: {pawn}, thing: {thing}");
                    //        }
                    //    }
                    //}
                }
            }
            else if (ZLogger.DebugEnabled)
            {
                ZLogger.Message($"claimant {claimant} can't reserve target: {target}");
                //var ZTracker = ZUtils.ZTracker;
                //if (target.HasThing)
                //{
                //    foreach (var map in ZTracker.GetAllMaps(claimant.Map.Tile))
                //    {
                //        foreach (var reservation in map.reservationManager.reservations)
                //        {
                //            Log.Message($"Vanilla reservation: map: {map}, Reservation: {reservation.claimant}, target: {reservation.target}, {reservation.claimant.Map} - {reservation.target.Thing?.Map}");
                //        }
                //    }
                //    if (ZTracker.jobTracker != null)
                //    {
                //        foreach (var data in ZTracker.jobTracker)
                //        {
                //            if (data.Value.reservedThings != null)
                //            {
                //                foreach (var reservation in data.Value.reservedThings)
                //                {
                //                    Log.Message($"ZTracker reservation: map: Reservation: {data.Key}, target: {reservation}, {data.Key.Map} - {reservation.Thing?.Map}");
                //                }
                //            }
                //        }
                //    }
                //}
            }
        }
コード例 #16
0
        public override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.OnCell));

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

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

            yield return(new Toil
            {
                initAction = delegate()
                {
                    var ZTracker = ZUtils.ZTracker;
                    Pawn pawn = GetActor();
                    if (TargetA.Thing is Building_StairsUp stairsUp)
                    {
                        Map map = ZTracker.GetUpperLevel(this.pawn.Map.Tile, this.pawn.Map);
                        if (map == null)
                        {
                            map = ZTracker.CreateUpperLevel(this.pawn.Map, stairsUp.Position);
                            if (!string.IsNullOrEmpty(stairsUp.pathToPreset))
                            {
                                var comp = ZUtils.GetMapComponentZLevel(map);
                                comp.DoGeneration = true;
                                comp.path = stairsUp.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, true, false, true);
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(stairsUp.pathToPreset))
                            {
                                var comp = ZUtils.GetMapComponentZLevel(map);
                                comp.DoGeneration = true;
                                comp.path = stairsUp.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, false, false, stairsUp.shouldSpawnStairsUpper);
                            stairsUp.shouldSpawnStairsUpper = false;
                        }
                    }

                    else if (TargetA.Thing is Building_StairsDown stairsDown)
                    {
                        Map map = ZTracker.GetLowerLevel(this.pawn.Map.Tile, this.pawn.Map);
                        if (map == null)
                        {
                            //ZLogger.Message("CREATING LOWER LEVEL AGAIG", true);
                            map = ZTracker.CreateLowerLevel(this.pawn.Map, stairsDown.Position);
                            if (!string.IsNullOrEmpty(stairsDown.pathToPreset))
                            {
                                var comp = ZUtils.GetMapComponentZLevel(map);
                                comp.DoGeneration = true;
                                comp.path = stairsDown.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, true, true);
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(stairsDown.pathToPreset))
                            {
                                var comp = ZUtils.GetMapComponentZLevel(map);
                                comp.DoGeneration = true;
                                comp.path = stairsDown.pathToPreset;
                            }
                            ZTracker.TeleportPawn(pawn, pawn.Position, map, false, stairsDown.shouldSpawnStairsBelow);
                            stairsDown.shouldSpawnStairsBelow = false;
                        }
                    }
                }
            });
コード例 #17
0
        public static void Prefix(ColonistBar __instance, ref List <ColonistBar.Entry> ___cachedEntries,
                                  ref List <Vector2> ___cachedDrawLocs)
        {
            try
            {
                if (___cachedDrawLocs.Count == ___cachedEntries.Count)
                {
                    for (int i = 0; i < ___cachedDrawLocs.Count; i++)
                    {
                        if (___cachedEntries[i].pawn == null && ___cachedEntries[i].map.Parent is MapParent_ZLevel)
                        {
                            //ZLogger.Message("Rect: " + ___cachedDrawLocs[i].x + " - " + ___cachedDrawLocs[i].y + " - "
                            //      + __instance.Size.x + " - " + __instance.Size.y);
                            Rect rect = new Rect(___cachedDrawLocs[i].x + (__instance.Size.x / 1.25f),
                                                 ___cachedDrawLocs[i].y + (__instance.Size.y / 1.25f),
                                                 __instance.Size.x / 3, __instance.Size.y / 3);
                            GUI.DrawTexture(rect, AbandonButtonTex);
                            if (Mouse.IsOver(rect))
                            {
                                if (Input.GetMouseButtonDown(0) && ___cachedEntries[i].map != null)
                                {
                                    Map map = ___cachedEntries[i].map;
                                    Find.WindowStack.Add(new Dialog_MessageBox("ZAbandonConfirmation".Translate(), "Yes".Translate(), delegate()
                                    {
                                        var comp        = ZUtils.GetMapComponentZLevel(map);
                                        var pathToWrite = Path.Combine(Path.Combine(GenFilePaths.ConfigFolderPath,
                                                                                    "SavedMaps"), map.Tile + " - " + comp.Z_LevelIndex + ".xml");
                                        if (map.listerThings.AllThings.Count > 0)
                                        {
                                            BlueprintUtility.SaveEverything(pathToWrite, map, "SavedMap");
                                            ZLogger.Message("Removing map: " + map);
                                        }
                                        var parent   = map.Parent as MapParent_ZLevel;
                                        var ZTracker = ZUtils.ZTracker;
                                        parent.Abandon();
                                        ZTracker.ZLevelsTracker[map.Tile].ZLevels.Remove(comp.Z_LevelIndex);

                                        foreach (var map2 in Find.Maps)
                                        {
                                            var comp2 = ZUtils.GetMapComponentZLevel(map2);
                                            if (ZTracker.ZLevelsTracker[map2.Tile] != null)
                                            {
                                                foreach (var d in ZTracker.ZLevelsTracker[map2.Tile].ZLevels)
                                                {
                                                    ZLogger.Message(map2 + ": " + d.Key + " - " + d.Value);
                                                }
                                            }
                                        }
                                    }, "No".Translate(), null, null, false, null, null));
                                }
                                else if (Input.GetMouseButtonDown(1) && ___cachedEntries[i].map != null)
                                {
                                    Map map = ___cachedEntries[i].map;
                                    Find.WindowStack.Add(new Dialog_MessageBox("ZAbandonPermanentlyConfirmation".Translate(), "Yes".Translate(), delegate()
                                    {
                                        var comp = ZUtils.GetMapComponentZLevel(map);
                                        try
                                        {
                                            var pathToDelete = Path.Combine(Path.Combine(GenFilePaths.ConfigFolderPath,
                                                                                         "SavedMaps"), map.Tile + " - " + comp.Z_LevelIndex + ".xml");
                                            var file = new FileInfo(pathToDelete);
                                            file.Delete();
                                        }
                                        catch
                                        {
                                        }

                                        var parent   = map.Parent as MapParent_ZLevel;
                                        var ZTracker = ZUtils.ZTracker;
                                        parent.Abandon();
                                        ZTracker.ZLevelsTracker[map.Tile].ZLevels.Remove(comp.Z_LevelIndex);

                                        foreach (var map2 in Find.Maps)
                                        {
                                            var comp2 = ZUtils.GetMapComponentZLevel(map2);
                                            if (ZTracker.ZLevelsTracker[map2.Tile] != null)
                                            {
                                                foreach (var d in ZTracker.ZLevelsTracker[map2.Tile].ZLevels)
                                                {
                                                    ZLogger.Message(map2 + ": " + d.Key + " - " + d.Value);
                                                }
                                            }
                                        }
                                    }, "No".Translate(), null, null, false, null, null));
                                }
                            }
                        }
                    }
                }
            }
            catch { };
        }
コード例 #18
0
            public static FloatMenuOption AddArrestOption(Pawn pawn, Pawn victim)
            {
                if (!pawn.CanReach(victim, PathEndMode.OnCell, Danger.Deadly))
                {
                    return(new FloatMenuOption(
                               "CannotArrest".Translate() + ": " + "NoPath".Translate().CapitalizeFirst(), null));
                }
                else
                {
                    Pawn   pTarg2 = victim;
                    Action action = 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_Bed3 = null;
                        foreach (var otherMap in ZUtils.GetAllMapsInClosestOrderForTwoThings(pawn, oldMap,
                                                                                             oldPosition1, victim, oldMap, oldPosition2))
                        {
                            building_Bed3 = RestUtility.FindBedFor(pTarg2, pawn, sleeperWillBePrisoner: true,
                                                                   checkSocialProperness: false);
                            if (building_Bed3 == null)
                            {
                                building_Bed3 = RestUtility.FindBedFor(pTarg2, pawn, sleeperWillBePrisoner: true,
                                                                       checkSocialProperness: false, ignoreOtherReservations: true);
                            }

                            if (building_Bed3 != null)
                            {
                                break;
                            }
                        }

                        ZUtils.TeleportThing(pawn, oldMap, oldPosition1);
                        ZUtils.TeleportThing(victim, oldMap, oldPosition2);

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

                        if (building_Bed3 == null)
                        {
                            Messages.Message("CannotArrest".Translate() + ": " + "NoPrisonerBed".Translate(),
                                             pTarg2, MessageTypeDefOf.RejectInput, historical: false);
                        }
                        else
                        {
                            Job job = JobMaker.MakeJob(JobDefOf.Arrest, pTarg2, building_Bed3);
                            job.count = 1;
                            ZTracker.BuildJobListFor(pawn, pawn.Map, job);
                            ZLogger.Message(pawn + " taking first job 3");
                            pawn.jobs.EndCurrentJob(JobCondition.InterruptForced, false);

                            if (pTarg2.Faction != null &&
                                ((pTarg2.Faction != Faction.OfPlayer && !pTarg2.Faction.def.hidden) ||
                                 pTarg2.IsQuestLodger()))
                            {
                                TutorUtility.DoModalDialogIfNotKnown(ConceptDefOf.ArrestingCreatesEnemies);
                            }
                        }
                    };
                    return(FloatMenuUtility.DecoratePrioritizedTask(
                               new FloatMenuOption(
                                   "TryToArrest".Translate(victim.LabelCap, victim,
                                                           pTarg2.GetAcceptArrestChance(pawn).ToStringPercent()), action,
                                   MenuOptionPriority.High, null, victim), pawn, pTarg2));
                }
            }
コード例 #19
0
        private static void Postfix(ref bool __result, Pawn claimant, LocalTargetInfo target, bool __state, int maxPawns = 1, int stackCount = -1, ReservationLayerDef layer = null, bool ignoreOtherReservations = false)
        {
            if (__state)
            {
                ZUtils.TeleportThing(claimant, oldMap, oldPosition);
            }
            if (__result)
            {
                var ZTracker = ZUtils.ZTracker;
                if (claimant.RaceProps.Humanlike && ZTracker.jobTracker != null)
                {
                    var thing = target.thingInt;
                    if (thing != null)
                    {
                        foreach (var data in ZTracker.jobTracker)
                        {
                            var otherPawn           = data.Key;
                            var otherPawnJobTracker = data.Value;
                            if (otherPawn != claimant && otherPawnJobTracker.reservedThings != null)
                            {
                                foreach (var reservation in otherPawnJobTracker.reservedThings)
                                {
                                    if (reservation.thingInt == target.thingInt)
                                    {
                                        var shouldChangeResult = !(otherPawn.jobs?.curDriver is JobDriver_TakeToBed);// || !(data.Key.jobs?.curDriver is JobDriver_LayDown));
                                        if (shouldChangeResult)
                                        {
                                            try
                                            {
                                                ZLogger.Message("reservation.thingInt: " + reservation.thingInt + " - target.thingInt: " + target.thingInt);
                                                ZLogger.Message(data.Key + " - 1 data.Value.mainJob: " + data.Value.mainJob);
                                                ZLogger.Message(data.Key + " - 1 data.Key.CurJob: " + data.Key.CurJob);
                                                ZLogger.Message(data.Key + " - 1 thing.Map.reservationManager.reservations.Any(x => x.Target.thingInt == thing && x.claimant == data.Key): " + thing.Map.reservationManager.reservations.Any(x => x.Target.thingInt == thing && x.claimant == data.Key));
                                            }
                                            catch
                                            {
                                            }
                                            if (otherPawn.Map == thing.Map && !thing.Map.reservationManager.reservations.Any(x => x.Target.thingInt == thing && x.claimant == otherPawn))
                                            {
                                                ZLogger.Message($"PREVENTED ZTRACKER reservation disfunction: claimant: {claimant}, pawn: {data.Key}, thing: {thing}");
                                                continue;
                                            }
                                            __result = false;
                                            ZLogger.Message($"shouldChangeResult Detected ZTRACKER reservation disfunction: claimant: {claimant}, pawn: {data.Key}, thing: {thing}");
                                            return;
                                        }
                                    }
                                    //Log.Message($"ZTracker reservation: map: Reservation: {data.Key}, target: {reservation}, {data.Key.Map} - {reservation.Thing?.Map}");
                                }
                            }
                        }
                    }
                    else if (ZTracker.jobTracker.TryGetValue(claimant, out var jobTracker) && jobTracker.lookedAtLocalCellMap.TryGetValue(target.cellInt, out var mapDest) && mapDest != null)
                    {
                        var cell = target.cellInt;
                        foreach (var data in ZTracker.jobTracker)
                        {
                            var otherPawn           = data.Key;
                            var otherPawnJobTracker = data.Value;
                            if (otherPawn != claimant && otherPawnJobTracker.reservedCells != null)
                            {
                                foreach (var reservation in otherPawnJobTracker.reservedCells)
                                {
                                    if (reservation.cellInt == cell && otherPawnJobTracker.mapDest == jobTracker.mapDest)
                                    {
                                        try
                                        {
                                            ZLogger.Message("claimant: " + claimant + " - " + otherPawn + " - 2 data.Value.mainJob: " + data.Value.mainJob);
                                            ZLogger.Message("claimant: " + claimant + " - " + otherPawn + " - 2 data.Key.CurJob: " + data.Key.CurJob);
                                            ZLogger.Message("claimant: " + claimant + " - " + otherPawn + " - 2 jobTracker.lookedAtMap.reservationManager.reservations.Any(x => !x.Target.HasThing && x.Target.cellInt == cell && x.claimant == data.Key)): " + jobTracker.mapDest.reservationManager.reservations.Any(x => !x.Target.HasThing && x.Target.cellInt == cell && x.claimant == data.Key));
                                        }
                                        catch { }
                                        if (otherPawn.Map == jobTracker.mapDest && !jobTracker.mapDest.reservationManager.reservations.Any(x => !x.Target.HasThing && x.Target.cellInt == cell && x.claimant == otherPawn))
                                        {
                                            ZLogger.Message($"2 PREVENTED ZTRACKER reservation disfunction: claimant: {claimant}, pawn: {data.Key}, cell: {cell}");
                                            continue;
                                        }
                                        __result = false;
                                        ZLogger.Message($"reservation.cellInt == cell 2 Detected ZTRACKER reservation disfunction: claimant: {claimant}, pawn: {data.Key}, cell: {cell}");
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (ZLogger.DebugEnabled)
            {
                if (!__result)
                {
                    ZLogger.Error($"claimant {claimant} can't reserve target: {target}");
                }
            }
        }
コード例 #20
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 ZUtils.GetAllMapsInClosestOrderForTwoThings(pawn, oldMap, oldPosition1,
                                                                                         victim, oldMap, oldPosition2))
                    {
                        ZLogger.Message("Searching rest job for " + pawn + " in " + ZTracker.GetMapInfo(otherMap)
                                        + " for " + ZTracker.GetMapInfo(oldMap));
                        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);
                    }
                    ZUtils.TeleportThing(pawn, oldMap, oldPosition1);
                    ZUtils.TeleportThing(victim, oldMap, 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);
            }
コード例 #21
0
        private static bool Prefix(ref bool __result, Reachability __instance, IntVec3 start, LocalTargetInfo dest, PathEndMode peMode, TraverseParms traverseParams, out bool __state)
        {
            __state = false;
            var pawn = traverseParams.pawn;

            if (pawn != null && pawn.Map != null)
            {
                if (dest.HasThing && dest.thingInt.Map != null)
                {
                    if (dest.thingInt.Map != pawn.Map)
                    {
                        var cellToTeleport = ZUtils.GetCellToTeleportFrom(pawn.Map, pawn.Position, dest.thingInt.Map);
                        var cell           = cellToTeleport.IsValid ? cellToTeleport : pawn.Position;

                        __state     = true;
                        oldMap      = pawn.Map;
                        oldPosition = pawn.Position;
                        ZUtils.TeleportThing(pawn, dest.thingInt.Map, cell);
                        if (dest.thingInt.Map != __instance.map)
                        {
                            __result = dest.thingInt.Map.reachability.CanReach(start, dest, peMode, traverseParams);
                            ZLogger.Message($"1 CanReach: Used dest thing map reachability: __instance.map: {__instance.map}, pawn: {pawn}, thing: {dest.thingInt}, pawn.Map: {pawn.Map}, thing.Map: {dest.thingInt.Map}, result: {__result}");
                            return(false);
                        }
                    }
                    else if (dest.thingInt.Map != __instance.map)
                    {
                        __result = dest.thingInt.Map.reachability.CanReach(start, dest, peMode, traverseParams);
                        ZLogger.Message($"2 CanReach: Used dest thing map reachability: __instance.map: {__instance.map}, pawn: {pawn}, thing: {dest.thingInt}, pawn.Map: {pawn.Map}, thing.Map: {dest.thingInt.Map}, result: {__result}");
                        return(false);
                    }
                }
                else if (ZUtils.ZTracker.jobTracker.TryGetValue(pawn, out var jobTracker) && jobTracker.lookedAtLocalCellMap != null &&
                         jobTracker.lookedAtLocalCellMap.TryGetValue(dest.cellInt, out var mapDest) && mapDest != null)
                {
                    if (mapDest != pawn.Map)
                    {
                        var cellToTeleport = ZUtils.GetCellToTeleportFrom(pawn.Map, pawn.Position, mapDest);
                        var cell           = cellToTeleport.IsValid ? cellToTeleport : pawn.Position;

                        __state     = true;
                        oldMap      = pawn.Map;
                        oldPosition = pawn.Position;
                        ZUtils.TeleportThing(pawn, mapDest, cell);
                        if (mapDest != __instance.map)
                        {
                            __result = mapDest.reachability.CanReach(start, dest, peMode, traverseParams);
                            ZLogger.Message($"3 CanReach: Used mapDest map reachability: __instance.map: {__instance.map}, pawn: {pawn}, mapDest: {mapDest}, pawn.Map: {pawn.Map}, result: {__result}");
                            return(false);
                        }
                    }
                    else if (mapDest != __instance.map)
                    {
                        __result = mapDest.reachability.CanReach(start, dest, peMode, traverseParams);
                        ZLogger.Message($"4 CanReach: Used mapDest map reachability: __instance.map: {__instance.map}, pawn: {pawn}, mapDest: {mapDest}, pawn.Map: {pawn.Map}, result: {__result}");
                        return(false);
                    }
                }
            }
            return(true);
        }