コード例 #1
0
 public static bool Prefix(Caravan caravan, Settlement settlement)
 {
     if (settlement.Faction != null && settlement.Faction.def.HasModExtension <CustomGenOption>() ||
         (Find.World.worldObjects.AllWorldObjects.Find(o => o.Tile == settlement.Tile && o.def.HasModExtension <CustomGenOption>()) is WorldObject worldObject))
     {
         if (!settlement.HasMap)
         {
             CGO.useCustomWindowContent = true;
             CGO.dateTime = DateTime.Now;
             LongEventHandler.QueueLongEvent(delegate()
             {
                 CGO.allTip = DefDatabase <TipSetDef> .AllDefsListForReading.SelectMany((TipSetDef set) => set.tips).InRandomOrder().ToList();
                 if (CGO.allTip.Count > 0)
                 {
                     CGO.tipAvailable = true;
                 }
                 CustomAttackNowNoLetter(caravan, settlement);
                 LongEventHandler.ExecuteWhenFinished(() =>
                 {
                     KLog.Message($"Generation done in {(DateTime.Now - CGO.dateTime).Duration().TotalSeconds}");
                     // Send letter
                     if (settlement.Faction != null)
                     {
                         SendAttackLetter(caravan, settlement);
                     }
                     // Clear
                     CGO.ClearUI();
                     CGO.ClearAll();
                     LongEventHandler_Patches.LongEventsOnGUI_Prefix.structure = null;
                 });
             }, "GeneratingMapForNewEncounter", true, delegate(Exception e)
             {
                 Log.Error($"{e}");
                 CGO.ClearUI();
                 CGO.ClearAll();
             }, true);
         }
         else
         {
             AccessTools.Method(typeof(SettlementUtility), "AttackNow").Invoke(null, new object[] { caravan, settlement });
         }
         return(false);
     }
     return(true);
 }
コード例 #2
0
        public override List <Pawn> SpawnThreats(IncidentParms parms)
        {
            RectUtils.HeightWidthFromLayout(CGO.fallingStructureChoosen, out int h, out int w);
            CellRect cellRect = CellRect.CenteredOn(parms.spawnCenter, w, h);

            List <string> allSymbList = new List <string>();
            Map           map         = (Map)parms.target;

            foreach (string str in CGO.fallingStructureChoosen.layouts[0])
            {
                List <string> symbSplitFromLine = str.Split(',').ToList();
                symbSplitFromLine.ForEach((s) => allSymbList.Add(s));
            }

            List <TTIR> fallers = new List <TTIR>();
            Dictionary <ActiveDropPodInfo, IntVec3> pods = new Dictionary <ActiveDropPodInfo, IntVec3>();

            int l = 0;

            foreach (IntVec3 cell in cellRect.Cells)
            {
                if (l < allSymbList.Count && allSymbList[l] != ".")
                {
                    SymbolDef temp = DefDatabase <SymbolDef> .GetNamed(allSymbList[l], false);

                    Thing thing;

                    if (temp.thingDef != null && !CGO.fallingStructure.thingsToSpawnInDropPod.Contains(temp.thingDef))
                    {
                        TTIR ttir = new TTIR();

                        thing = ThingMaker.MakeThing(temp.thingDef, temp.stuffDef);
                        thing.SetFactionDirect(parms.faction);
                        if (!CGO.fallingStructure.spawnDormantWhenPossible && thing.TryGetComp <CompCanBeDormant>() is CompCanBeDormant ccbd && ccbd != null)
                        {
                            ccbd.wakeUpOnTick = Find.TickManager.TicksGame + 150;
                        }

                        if (thing.def.rotatable && thing.def.category == ThingCategory.Building)
                        {
                            ttir.rot = new Rot4(temp.rotation.AsInt);
                        }

                        ThingDef faller = new ThingDef
                        {
                            thingClass   = CGO.fallingStructure.skyfaller,
                            category     = ThingCategory.Ethereal,
                            useHitPoints = false,

                            drawOffscreen = true,
                            tickerType    = TickerType.Normal,
                            altitudeLayer = AltitudeLayer.Skyfaller,
                            drawerType    = DrawerType.RealtimeOnly,

                            defName = temp.thingDef.defName,
                            label   = temp.thingDef.label + " (incoming)",
                            size    = new IntVec2(thing.def.size.x, thing.def.size.z)
                        };

                        faller.skyfaller = new SkyfallerProperties()
                        {
                            shadowSize         = new UnityEngine.Vector2(thing.def.size.x + 1, thing.def.size.z + 1),
                            ticksToImpactRange = new IntRange(150, 150),
                            movementType       = SkyfallerMovementType.Decelerate
                        };

                        ttir.faller  = faller;
                        ttir.toSpawn = thing;
                        ttir.cell    = cell;

                        fallers.Add(ttir);
                    }
                    else if (temp.thingDef != null)
                    {
                        thing = ThingMaker.MakeThing(temp.thingDef, temp.stuffDef);
                        thing.SetFactionDirect(parms.faction);

                        ActiveDropPodInfo activeDropPodInfo = new ActiveDropPodInfo();
                        activeDropPodInfo.innerContainer.TryAdd(thing);
                        activeDropPodInfo.openDelay = 40;
                        activeDropPodInfo.leaveSlag = false;
                        pods.Add(activeDropPodInfo, cell);
                    }
                }
                l++;
            }
            // ARRIVAL
            fallers.ForEach(ttir => this.SpawnSkyfaller(ttir.faller, ttir.toSpawn, ttir.cell, map, ttir.rot));
            for (int i = 0; i < pods.Count; i++)
            {
                DropPodUtility.MakeDropPodAt(pods.ElementAt(i).Value, map, pods.ElementAt(i).Key);
            }

            IncidentParms parms1 = parms;

            RCellFinder.TryFindRandomCellNearWith(parms.spawnCenter, i => i.Walkable(map), map, out parms1.spawnCenter, 33, 40);

            base.SpawnThreats(parms1);
            CGO.ClearFalling();
            return(null);
        }