示例#1
0
        protected override void LeaveMap()
        {
            if (this.alreadyLeft)
            {
                base.LeaveMap();
            }
            else if (this.groupID < 0)
            {
                Log.Error("Drop pod left the map, but its group ID is " + (object)this.groupID);
                this.Destroy(DestroyMode.Vanish);
            }
            else if (this.destinationTile < 0)
            {
                Log.Error("Drop pod left the map, but its destination tile is " + (object)this.destinationTile);
                this.Destroy(DestroyMode.Vanish);
            }
            else
            {
                Lord lord = TransporterUtility.FindLord(this.groupID, this.Map);
                if (lord != null)
                {
                    this.Map.lordManager.RemoveLord(lord);
                }
                TravelingSRTS travelingTransportPods = (TravelingSRTS)WorldObjectMaker.MakeWorldObject(DefDatabase <WorldObjectDef> .GetNamed("TravelingSRTS", true));
                travelingTransportPods.Tile = this.Map.Tile;
                travelingTransportPods.SetFaction(Faction.OfPlayer);
                travelingTransportPods.destinationTile = this.destinationTile;
                travelingTransportPods.arrivalAction   = this.arrivalAction;

                Find.WorldObjects.Add((WorldObject)travelingTransportPods);
                SRTSLeaving.tmpActiveDropPods.Clear();
                SRTSLeaving.tmpActiveDropPods.AddRange((IEnumerable <Thing>) this.Map.listerThings.ThingsInGroup(ThingRequestGroup.ActiveDropPod));
                travelingTransportPods.flyingThing = tmpActiveDropPods.Find(x => (x as SRTSLeaving)?.groupID == this.groupID);
                for (int index = 0; index < SRTSLeaving.tmpActiveDropPods.Count; ++index)
                {
                    SRTSLeaving tmpActiveDropPod = SRTSLeaving.tmpActiveDropPods[index] as SRTSLeaving;
                    if (tmpActiveDropPod != null && tmpActiveDropPod.groupID == this.groupID)
                    {
                        tmpActiveDropPod.alreadyLeft = true;
                        travelingTransportPods.AddPod(tmpActiveDropPod.Contents, true);
                        tmpActiveDropPod.Contents = (ActiveDropPodInfo)null;
                        tmpActiveDropPod.Destroy(DestroyMode.Vanish);
                    }
                }
            }
        }
        public void TryLaunch(int destinationTile, TransportPodsArrivalAction arrivalAction, Caravan cafr = null)
        {
            if (cafr == null && !this.parent.Spawned)
            {
                Log.Error("Tried to launch " + (object)this.parent + ", but it's unspawned.", false);
            }
            else
            {
                if (this.parent.Spawned && !this.LoadingInProgressOrReadyToLaunch || (!this.AllInGroupConnectedToFuelingPort || !this.AllFuelingPortSourcesInGroupHaveAnyFuel))
                {
                    return;
                }
                if (cafr == null)
                {
                    Map map = this.parent.Map;
                    int num = Find.WorldGrid.TraversalDistanceBetween(map.Tile, destinationTile, true, int.MaxValue);
                    if (num > this.MaxLaunchDistance)
                    {
                        return;
                    }
                    this.Transporter.TryRemoveLord(map);
                    int             groupId           = this.Transporter.groupID;
                    float           amount            = Mathf.Max(CompLaunchableSRTS.FuelNeededToLaunchAtDist((float)num), 1f);
                    CompTransporter comp1             = this.FuelingPortSource.TryGetComp <CompTransporter>();
                    Building        fuelingPortSource = this.FuelingPortSource;
                    if (fuelingPortSource != null)
                    {
                        fuelingPortSource.TryGetComp <CompRefuelable>().ConsumeFuel(amount);
                    }
                    ThingOwner directlyHeldThings = comp1.GetDirectlyHeldThings();

                    // Neceros Edit
                    Thing thing = ThingMaker.MakeThing(ThingDef.Named(parent.def.defName), (ThingDef)null);
                    thing.SetFactionDirect(Faction.OfPlayer);
                    thing.Rotation = this.FuelingPortSource.Rotation;
                    CompRefuelable comp2 = thing.TryGetComp <CompRefuelable>();
                    comp2.GetType().GetField("fuel", BindingFlags.Instance | BindingFlags.NonPublic).SetValue((object)comp2, (object)fuelingPortSource.TryGetComp <CompRefuelable>().Fuel);
                    comp2.TargetFuelLevel = fuelingPortSource.TryGetComp <CompRefuelable>().TargetFuelLevel;
                    thing.stackCount      = 1;
                    directlyHeldThings.TryAddOrTransfer(thing, true);

                    // Neceros Edit
                    ActiveDropPod activeDropPod = (ActiveDropPod)ThingMaker.MakeThing(ThingDef.Named(parent.def.defName + "_Active"), null);
                    activeDropPod.Contents = new ActiveDropPodInfo();
                    activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer((IEnumerable <Thing>)directlyHeldThings, true, true);

                    // Neceros Edit
                    SRTSLeaving srtsLeaving = (SRTSLeaving)SkyfallerMaker.MakeSkyfaller(ThingDef.Named(parent.def.defName + "_Leaving"), (Thing)activeDropPod);
                    srtsLeaving.rotation        = this.FuelingPortSource.Rotation;
                    srtsLeaving.groupID         = groupId;
                    srtsLeaving.destinationTile = destinationTile;
                    srtsLeaving.arrivalAction   = arrivalAction;
                    comp1.CleanUpLoadingVars(map);
                    IntVec3 position = fuelingPortSource.Position;
                    SRTSStatic.SRTSDestroy((Thing)fuelingPortSource, DestroyMode.Vanish);
                    GenSpawn.Spawn((Thing)srtsLeaving, position, map, WipeMode.Vanish);
                    CameraJumper.TryHideWorld();
                }
                else
                {
                    int num = Find.WorldGrid.TraversalDistanceBetween(this.carr.Tile, destinationTile, true, int.MaxValue);
                    if (num > this.MaxLaunchDistance)
                    {
                        return;
                    }
                    float amount = Mathf.Max(CompLaunchableSRTS.FuelNeededToLaunchAtDist((float)num), 1f);
                    if (this.FuelingPortSource != null)
                    {
                        this.FuelingPortSource.TryGetComp <CompRefuelable>().ConsumeFuel(amount);
                    }
                    ThingOwner <Pawn> directlyHeldThings = (ThingOwner <Pawn>)cafr.GetDirectlyHeldThings();
                    Thing             thing = null;
                    foreach (Pawn pawn in directlyHeldThings.InnerListForReading)
                    {
                        Pawn_InventoryTracker inventory = pawn.inventory;
                        for (int index = 0; index < inventory.innerContainer.Count; ++index)
                        {
                            // Neceros Edit
                            if (inventory.innerContainer[index].TryGetComp <CompLaunchableSRTS>() != null)
                            {
                                thing = inventory.innerContainer[index];
                                inventory.innerContainer[index].holdingOwner.Remove(inventory.innerContainer[index]);
                                break;
                            }
                        }
                    }
                    /*Add caravan items to SRTS - SmashPhil */
                    foreach (Pawn p in directlyHeldThings.InnerListForReading)
                    {
                        p.inventory.innerContainer.InnerListForReading.ForEach(x => AddThingsToSRTS(x));
                        p.inventory.innerContainer.Clear();
                    }

                    ThingOwner <Thing> thingOwner = new ThingOwner <Thing>();
                    foreach (Pawn pawn in directlyHeldThings.AsEnumerable <Pawn>().ToList <Pawn>())
                    {
                        thingOwner.TryAddOrTransfer((Thing)pawn, true);
                    }
                    if (thing != null && thing.holdingOwner == null)
                    {
                        thingOwner.TryAddOrTransfer(thing, false);
                    }

                    // Neceros Edit
                    ActiveDropPod activeDropPod = (ActiveDropPod)ThingMaker.MakeThing(ThingDef.Named(parent.def.defName + "_Active"), (ThingDef)null);
                    activeDropPod.Contents = new ActiveDropPodInfo();
                    activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer((IEnumerable <Thing>)thingOwner, true, true);
                    activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer((IEnumerable <Thing>)thingsInsideShip, true, true);
                    thingsInsideShip.Clear();

                    cafr.RemoveAllPawns();
                    if (cafr.Spawned)
                    {
                        Find.WorldObjects.Remove((WorldObject)cafr);
                    }
                    TravelingTransportPods travelingTransportPods = (TravelingTransportPods)WorldObjectMaker.MakeWorldObject(DefDatabase <WorldObjectDef> .GetNamed("TravelingSRTS", true));
                    travelingTransportPods.Tile = cafr.Tile;
                    travelingTransportPods.SetFaction(Faction.OfPlayer);
                    travelingTransportPods.destinationTile = destinationTile;
                    travelingTransportPods.arrivalAction   = arrivalAction;
                    Find.WorldObjects.Add((WorldObject)travelingTransportPods);
                    travelingTransportPods.AddPod(activeDropPod.Contents, true);
                    activeDropPod.Contents = (ActiveDropPodInfo)null;
                    activeDropPod.Destroy(DestroyMode.Vanish);
                    Find.WorldTargeter.StopTargeting();
                }
            }
        }
示例#3
0
        private void TryLaunchBombRun(int destTile, Pair <IntVec3, IntVec3> targetPoints, IEnumerable <IntVec3> bombCells, MapParent mapParent)
        {
            if (!this.parent.Spawned)
            {
                Log.Error("Tried to launch " + this.parent + ", but it's unspawned.");
                return;
            }

            if (!CompLauncher.LoadingInProgressOrReadyToLaunch || !CompLauncher.AllInGroupConnectedToFuelingPort || !CompLauncher.AllFuelingPortSourcesInGroupHaveAnyFuel)
            {
                return;
            }

            Map map = this.parent.Map;
            int num = Find.WorldGrid.TraversalDistanceBetween(map.Tile, destTile);

            if (num > CompLauncher.MaxLaunchDistance)
            {
                return;
            }
            CompLauncher.Transporter.TryRemoveLord(map);
            int             groupID        = CompLauncher.Transporter.groupID;
            float           amount         = Mathf.Max(CompLaunchableSRTS.FuelNeededToLaunchAtDist((float)num, this.parent.GetComp <CompLaunchableSRTS>().BaseFuelPerTile), 1f);
            CompTransporter comp1          = CompLauncher.FuelingPortSource.TryGetComp <CompTransporter>();
            Building        fuelPortSource = CompLauncher.FuelingPortSource;

            if (fuelPortSource != null)
            {
                fuelPortSource.TryGetComp <CompRefuelable>().ConsumeFuel(amount);
            }
            ThingOwner directlyHeldThings = comp1.GetDirectlyHeldThings();

            Thing thing = ThingMaker.MakeThing(ThingDef.Named(parent.def.defName), null);

            thing.SetFactionDirect(Faction.OfPlayer);
            thing.Rotation = CompLauncher.FuelingPortSource.Rotation;
            CompRefuelable comp2 = thing.TryGetComp <CompRefuelable>();

            comp2.GetType().GetField("fuel", BindingFlags.Instance | BindingFlags.NonPublic).SetValue((object)comp2, (object)fuelPortSource.TryGetComp <CompRefuelable>().Fuel);
            comp2.TargetFuelLevel = fuelPortSource.TryGetComp <CompRefuelable>().TargetFuelLevel;
            thing.stackCount      = 1;
            directlyHeldThings.TryAddOrTransfer(thing, true);

            ActiveDropPod activeDropPod = (ActiveDropPod)ThingMaker.MakeThing(ThingDef.Named(parent.def.defName + "_Active"), null);

            activeDropPod.Contents = new ActiveDropPodInfo();
            activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer((IEnumerable <Thing>)directlyHeldThings, true, true);

            SRTSLeaving srtsLeaving = (SRTSLeaving)SkyfallerMaker.MakeSkyfaller(ThingDef.Named(parent.def.defName + "_Leaving"), (Thing)activeDropPod);

            srtsLeaving.rotation        = CompLauncher.FuelingPortSource.Rotation;
            srtsLeaving.groupID         = groupID;
            srtsLeaving.destinationTile = destTile;
            srtsLeaving.arrivalAction   = new SRTSArrivalActionBombRun(mapParent, targetPoints, bombCells, this.bombType, map, CompLauncher.FuelingPortSource.Position);

            comp1.CleanUpLoadingVars(map);
            IntVec3 position = fuelPortSource.Position;

            SRTSStatic.SRTSDestroy((Thing)fuelPortSource, DestroyMode.Vanish);
            GenSpawn.Spawn((Thing)srtsLeaving, position, map, WipeMode.Vanish);
            CameraJumper.TryHideWorld();
        }