Пример #1
0
            private static bool Prefix(TradeShip __instance, Thing toGive, int countToGive, Pawn playerNegotiator, List <Pawn> ___soldPrisoners)
            {
                if (__instance.Map != null)
                {
                    MapParent_PocketDimension mapParent = __instance.Map.info.parent as MapParent_PocketDimension;
                    if (mapParent != null)
                    {
                        Map containingMap = PocketDimensionUtility.GetHighestContainingMap(__instance.Map);

                        // If there was no containing map found (should mean box is in a caravan; could mean the box was nested inside itself, it which case, oh well, give them their goods anyway :P)
                        if (containingMap == __instance.Map)
                        {
                            Building_PocketDimensionExit exit = PocketDimensionUtility.GetExit(mapParent.dimensionSeed);
                            if (exit != null && exit.SpawnedOrAnyParentSpawned)
                            {
                                Thing thing = toGive.SplitOff(countToGive);
                                thing.PreTraded(TradeAction.PlayerBuys, playerNegotiator, __instance);
                                Pawn pawn = thing as Pawn;
                                if (pawn != null)
                                {
                                    ___soldPrisoners.Remove(pawn);
                                }

                                IntVec3 positionHeld = exit.PositionHeld;
                                Map     mapHeld      = exit.MapHeld;
                                GenPlace.TryPlaceThing(thing, positionHeld, mapHeld, ThingPlaceMode.Near);
                                return(false);
                            }
                        }
                    }
                }

                return(true);
            }
        private void EqualizeTemperatures()
        {
            Building_PocketDimensionExit exit = PocketDimensionUtility.GetExit(this.dimensionSeed);

            if (exit == null)
            {
                return;
            }
            // If the exits vent is not open it means we are loading an old save from before the vents were on both side and synced, so just close the vent to fix
            else if (!exit.VentOpen)
            {
                SetVentOpen(false);
                return;
            }


            RoomGroup thisRoomGroup  = this.GetRoomGroup();
            RoomGroup otherRoomGroup = exit.GetRoomGroup();

            if (thisRoomGroup == null || otherRoomGroup == null || thisRoomGroup == otherRoomGroup)
            {
                return;
            }

            float totalTemperature   = thisRoomGroup.Temperature + otherRoomGroup.Temperature;
            float averageTemperature = totalTemperature / 2.0f;

            float thisRoomChangeAmount    = this.GetTemperatureChangeAmount(thisRoomGroup, averageTemperature);
            float otherRoomChangeAmount   = this.GetTemperatureChangeAmount(otherRoomGroup, averageTemperature);
            float temperatureChangeAmount = Mathf.Min(thisRoomChangeAmount, otherRoomChangeAmount);

            EqualizeTemperatureForRoom(thisRoomGroup, averageTemperature, temperatureChangeAmount);
            EqualizeTemperatureForRoom(otherRoomGroup, averageTemperature, temperatureChangeAmount);
        }
Пример #3
0
        public static Building_PocketDimensionExit GetExit(string dimensionSeed)
        {
            Building_PocketDimensionExit exit = null;

            if (dimensionSeed != null)
            {
                Exits.TryGetValue(dimensionSeed, out exit);
            }
            return(exit);
        }
Пример #4
0
        public static Building_PocketDimensionEntranceBase GetOtherSide(Building_PocketDimensionEntranceBase thisSide)
        {
            Building_PocketDimensionBox  box  = GetBox(thisSide.dimensionSeed);
            Building_PocketDimensionExit exit = GetExit(thisSide.dimensionSeed);

            if (box != null && box != thisSide)
            {
                return(box);
            }
            else if (exit != null && exit != thisSide)
            {
                return(exit);
            }

            return(null);
        }
Пример #5
0
        protected override void SetName(string name)
        {
            Building_PocketDimensionBox  box  = PocketDimensionUtility.GetBox(buildingSeed);
            Building_PocketDimensionExit exit = PocketDimensionUtility.GetExit(buildingSeed);

            if (box != null)
            {
                box.uniqueName = curName;
            }
            if (exit != null)
            {
                exit.uniqueName = "CM_PocketDimension_ExitName".Translate(curName);
            }

            Messages.Message("CM_RenamePocketDimensionMessage".Translate(curName), MessageTypeDefOf.TaskCompletion);
        }
Пример #6
0
        public void Abandon(bool lost)
        {
            if (!this.shouldBeDeleted)
            {
                TaggedString label = "CM_PocketDimensionDestroyedLetterLabel".Translate();
                TaggedString text  = "CM_PocketDimensionDestroyedLetterText".Translate();

                if (lost)
                {
                    label = "CM_PocketDimensionLostLetterLabel".Translate();
                    text  = "CM_PocketDimensionLostLetterText".Translate();
                }

                Building_PocketDimensionBox box = PocketDimensionUtility.GetBox(this.dimensionSeed);
                if (box != null && !box.BeingDestroyed)
                {
                    Thing thingHolder = box.SpawnedParentOrMe;
                    if (thingHolder != null)
                    {
                        LookTargets lookTarget = new LookTargets(thingHolder.Position, thingHolder.Map);
                        Find.LetterStack.ReceiveLetter(label, text, PocketDimensionDefOf.CM_PocketDimensionBreachedLetter, lookTarget);
                    }
                    else
                    {
                        Find.LetterStack.ReceiveLetter(label, text, PocketDimensionDefOf.CM_PocketDimensionBreachedLetter);
                    }
                }
                else
                {
                    Find.LetterStack.ReceiveLetter(label, text, PocketDimensionDefOf.CM_PocketDimensionBreachedLetter);
                }

                if (box != null)
                {
                    box.GetLost = true;
                }

                Building_PocketDimensionExit exit = PocketDimensionUtility.GetExit(this.dimensionSeed);
                if (exit != null)
                {
                    exit.GetLost = true;
                }
            }

            this.shouldBeDeleted = true;
        }
        //Generates a map with a defined seed
        private void GeneratePocketMap(int mapWidth)
        {
            IntVec3 size = new IntVec3(mapWidth, 1, mapWidth);

            this.dimensionSeed = Find.TickManager.TicksAbs.ToString();

            // The new map must be connected to a parent on the world map
            var mapParent = (MapParent_PocketDimension)WorldObjectMaker.MakeWorldObject(PocketDimensionDefOf.CM_WorldObject_PocketDimension);

            mapParent.Tile = this.Map.Tile;
            mapParent.SetFaction(Faction.OfPlayer);
            Find.WorldObjects.Add(mapParent);

            // Generate the map and set the maps entrance to this box so the map knows what stuff it is made of
            string cachedSeedString = Find.World.info.seedString;

            Find.World.info.seedString = this.dimensionSeed;
            PocketDimensionUtility.Boxes[this.dimensionSeed] = this;
            mapParent.dimensionSeed = this.dimensionSeed;
            Map generatedMap = MapGenerator.GenerateMap(size, mapParent, mapParent.MapGeneratorDef, mapParent.ExtraGenStepDefs, null);

            Find.World.info.seedString = cachedSeedString;

            // Permanent darkness - seems moot since adding roof and walls...
            GameCondition_NoSunlight gameCondition_NoSunlight = (GameCondition_NoSunlight)GameConditionMaker.MakeCondition(PocketDimensionDefOf.CM_PocketDimensionCondition, -1);

            gameCondition_NoSunlight.Permanent = true;
            generatedMap.gameConditionManager.RegisterCondition(gameCondition_NoSunlight);

            // Now make an exit in the map
            ThingDef     thingToMake = compCreator.Props.exitDef;
            List <Thing> thingList   = generatedMap.Center.GetThingList(generatedMap).Where(x => x.def == thingToMake).ToList();

            if (thingList.Count() == 0)
            {
                var newExit = ThingMaker.MakeThing(thingToMake, this.Stuff);
                newExit.SetFaction(this.Faction);
                GenPlace.TryPlaceThing(newExit, generatedMap.Center, generatedMap, ThingPlaceMode.Direct);
                thingList = generatedMap.Center.GetThingList(generatedMap).Where(x => x.def == thingToMake).ToList();
            }

            Logger.MessageFormat(this, this.dimensionSeed);

            Building_PocketDimensionExit exit = thingList.First() as Building_PocketDimensionExit;

            exit.dimensionSeed = this.dimensionSeed;
            if (!string.IsNullOrEmpty(this.uniqueName))
            {
                exit.uniqueName = "CM_PocketDimension_ExitName".Translate(this.uniqueName);
            }
            else
            {
                exit.uniqueName = "CM_PocketDimension_ExitName".Translate(this.LabelCap);
            }

            exit.SetVentOpen(ventOpen);

            PocketDimensionUtility.MapParents[this.dimensionSeed] = mapParent;

            PocketDimensionUtility.Exits[this.dimensionSeed] = exit;

            Messages.Message("CM_PocketDimensionCreated".Translate(), new TargetInfo(this), MessageTypeDefOf.PositiveEvent);

            ThingDef moteDef = DefDatabase <ThingDef> .GetNamedSilentFail("Mote_PsycastPsychicEffect");

            SoundDef soundDef = DefDatabase <SoundDef> .GetNamedSilentFail("Psycast_Skip_Exit");

            if (moteDef != null)
            {
                MoteMaker.MakeAttachedOverlay(this, moteDef, Vector3.zero, mapSize);
            }

            if (soundDef != null)
            {
                soundDef.PlayOneShot(new TargetInfo(this.Position, this.Map));
            }
        }