예제 #1
0
 private void PodOpen()
 {
     for (int i = this.contents.innerContainer.Count - 1; i >= 0; i--)
     {
         Thing thing = this.contents.innerContainer[i];
         Thing thing2;
         GenPlace.TryPlaceThing(thing, base.Position, base.Map, ThingPlaceMode.Near, out thing2, delegate(Thing placedThing, int count)
         {
             if (Find.TickManager.TicksGame < 1200 && TutorSystem.TutorialMode && placedThing.def.category == ThingCategory.Item)
             {
                 Find.TutorialState.AddStartingItem(placedThing);
             }
         }, null);
         Pawn pawn = thing2 as Pawn;
         if (pawn != null)
         {
             if (pawn.RaceProps.Humanlike)
             {
                 TaleRecorder.RecordTale(TaleDefOf.LandedInPod, new object[]
                 {
                     pawn
                 });
             }
             if (pawn.IsColonist && pawn.Spawned && !base.Map.IsPlayerHome)
             {
                 pawn.drafter.Drafted = true;
             }
         }
     }
     this.contents.innerContainer.ClearAndDestroyContents(DestroyMode.Vanish);
     if (this.contents.leaveSlag)
     {
         for (int j = 0; j < 1; j++)
         {
             Thing thing3 = ThingMaker.MakeThing(ThingDefOf.ChunkSlagSteel, null);
             GenPlace.TryPlaceThing(thing3, base.Position, base.Map, ThingPlaceMode.Near, null, null);
         }
     }
     SoundDefOf.DropPod_Open.PlayOneShot(new TargetInfo(base.Position, base.Map, false));
     this.Destroy(DestroyMode.Vanish);
 }
예제 #2
0
        protected virtual void Impact(Thing hitThing)
        {
            GenPlace.TryPlaceThing(this.flyingThing, base.Position, base.Map, ThingPlaceMode.Direct);
            if (this.flyingThing is Pawn)
            {
                Pawn p = this.flyingThing as Pawn;
                if (p.IsColonist && this.drafted && p.drafter != null)
                {
                    p.drafter.Drafted = true;
                }
            }

            if (this.destroyPctAtEnd != 0)
            {
                int rangeMax = 10;
                for (int i = 0; i < rangeMax; i++)
                {
                    float   direction = Rand.Range(0, 360);
                    Vector3 rndPos    = this.flyingThing.DrawPos;
                    rndPos.x += Rand.Range(-.3f, .3f);
                    rndPos.z += Rand.Range(-.3f, .3f);
                    ThingDef mote = TorannMagicDefOf.Mote_Shadow;
                    TM_MoteMaker.ThrowGenericMote(mote, rndPos, this.Map, Rand.Range(.5f, 1f), 0.4f, Rand.Range(.1f, .4f), Rand.Range(1.2f, 2f), Rand.Range(-200, 200), Rand.Range(1.2f, 2f), direction, direction);
                    SoundInfo info = SoundInfo.InMap(new TargetInfo(base.Position, this.Map, false), MaintenanceType.None);
                    info.pitchFactor  = .8f;
                    info.volumeFactor = 1.2f;
                    TorannMagicDefOf.TM_Vibration.PlayOneShot(info);
                }
            }

            if (this.destroyPctAtEnd >= 1f)
            {
                this.flyingThing.Destroy(DestroyMode.Vanish);
            }
            else if (this.destroyPctAtEnd != 0)
            {
                this.flyingThing.SplitOff(Mathf.RoundToInt(this.flyingThing.stackCount * this.destroyPctAtEnd)).Destroy(DestroyMode.Vanish);
            }

            this.Destroy(DestroyMode.Vanish);
        }
        public bool TryDoSpawn()
        {
            if (!this.parent.Spawned)
            {
                return(false);
            }

            IntVec3 center;

            ThingDef thingToSpawn = ThingDef.Named(currentThingList.items.RandomElement());

            if (thingToSpawn == null)
            {
                return(false);
            }
            if (CompConfigurableSpawner.TryFindSpawnCell(this.parent, thingToSpawn, this.PropsSpawner.spawnCount, out center))
            {
                Thing thing = ThingMaker.MakeThing(thingToSpawn, null);
                thing.stackCount = this.PropsSpawner.spawnCount;
                if (thing == null)
                {
                    Log.Error("Could not spawn anything for " + this.parent, false);
                }
                if (this.PropsSpawner.inheritFaction && thing.Faction != this.parent.Faction)
                {
                    thing.SetFaction(this.parent.Faction, null);
                }
                Thing t;
                GenPlace.TryPlaceThing(thing, this.parent.InteractionCell, this.parent.Map, ThingPlaceMode.Direct, out t, null, null, default(Rot4));
                if (this.PropsSpawner.spawnForbidden)
                {
                    t.SetForbidden(true, true);
                }
                if (this.PropsSpawner.showMessageIfOwned && this.parent.Faction == Faction.OfPlayer)
                {
                    Messages.Message("MessageCompSpawnerSpawnedItem".Translate(thingToSpawn.LabelCap), thing, MessageTypeDefOf.PositiveEvent, true);
                }
                return(true);
            }
            return(false);
        }
예제 #4
0
 public static void DropThingGroupsNear(IntVec3 dropCenter, List <List <Thing> > thingsGroups, int openDelay = 110, bool canInstaDropDuringInit = true, bool leaveSlag = false, bool canRoofPunch = true)
 {
     foreach (List <Thing> current in thingsGroups)
     {
         IntVec3 intVec;
         if (!DropCellFinder.TryFindDropSpotNear(dropCenter, out intVec, true, canRoofPunch))
         {
             Log.Warning(string.Concat(new object[]
             {
                 "DropThingsNear failed to find a place to drop ",
                 current.FirstOrDefault <Thing>(),
                 " near ",
                 dropCenter,
                 ". Dropping on random square instead."
             }));
             intVec = CellFinderLoose.RandomCellWith((IntVec3 c) => c.Walkable(), 1000);
         }
         for (int i = 0; i < current.Count; i++)
         {
             current[i].SetForbidden(true, false);
         }
         if (canInstaDropDuringInit && Find.TickManager.TicksGame < 2)
         {
             foreach (Thing current2 in current)
             {
                 GenPlace.TryPlaceThing(current2, intVec, ThingPlaceMode.Near);
             }
         }
         else
         {
             DropPodInfo dropPodInfo = new DropPodInfo();
             foreach (Thing current3 in current)
             {
                 dropPodInfo.containedThings.Add(current3);
             }
             dropPodInfo.openDelay = openDelay;
             dropPodInfo.leaveSlag = leaveSlag;
             MakeDropPodAt(intVec, dropPodInfo);
         }
     }
 }
예제 #5
0
        public void InitiateMassSummon(Map map, LocalTargetInfo target)
        {
            IntVec3 curCell;
            IEnumerable <IntVec3> targets = GenRadial.RadialCellsAround(target.Cell, 7, true);
            int transportedItemCount      = 0;

            for (int i = 0; i < targets.Count(); i++)
            {
                curCell = targets.ToArray <IntVec3>()[i];
                if (curCell.InBounds(map) && curCell.IsValid)
                {
                    List <Thing> thingList = curCell.GetThingList(map);
                    for (int j = 0; j < thingList.Count(); j++)
                    {
                        if (thingList[j] != null && thingList[j].def.mote == null)
                        {
                            Thing targetThing = thingList[j];
                            if (targetThing is Pawn && targetThing != this.CasterPawn)
                            {
                                MoteMaker.ThrowLightningGlow(targetThing.DrawPos, targetThing.Map, 1f);
                                MoteMaker.ThrowHeatGlow(targetThing.Position, targetThing.Map, 1f);
                                targetThing.DeSpawn();
                                GenSpawn.Spawn(targetThing, this.CasterPawn.Position, this.CasterPawn.Map);
                                transportedItemCount++;
                                j--;
                            }
                            else if (targetThing != null && targetThing.def.EverHaulable)
                            {
                                MoteMaker.ThrowLightningGlow(targetThing.DrawPos, targetThing.Map, .6f);
                                MoteMaker.ThrowHeatGlow(targetThing.Position, targetThing.Map, 1f);
                                targetThing.DeSpawn();
                                GenPlace.TryPlaceThing(targetThing, this.CasterPawn.Position, this.CasterPawn.Map, ThingPlaceMode.Near, null);
                                transportedItemCount++;
                                j--;
                            }
                        }
                    }
                    MoteMaker.ThrowSmoke(curCell.ToVector3Shifted(), map, .6f);
                }
            }
        }
예제 #6
0
 public static void DropThingGroupsNear(IntVec3 dropCenter, List <List <Thing> > thingsGroups, int openDelay = 30, bool canInstaDropDuringInit = true, bool leaveSlag = false, bool canRoofPunch = true)
 {
     foreach (List <Thing> current in thingsGroups)
     {
         IntVec3 intVec;
         if (!DropCellFinder.TryFindDropSpotNear(dropCenter, out intVec, true, canRoofPunch))
         {
             Log.Warning(string.Concat(new object[]
             {
                 "DropThingsNear failed to find a place to drop ",
                 current.FirstOrDefault <Thing>(),
                 " near ",
                 dropCenter,
                 ". Dropping on random square instead."
             }));
             intVec = CellFinderLoose.RandomCellWith((IntVec3 c) => GenGrid.Standable(c) && !Find.RoofGrid.Roofed(c) && !Find.FogGrid.IsFogged(c), 1000);
         }
         foreach (Thing current2 in current)
         {
             ThingWithComps thingWithComponents = current2 as ThingWithComps;
             if (thingWithComponents != null && thingWithComponents.GetComp <CompForbiddable>() != null)
             {
                 thingWithComponents.GetComp <CompForbiddable>().Forbidden = true;
             }
         }
         if (canInstaDropDuringInit && Find.TickManager.TicksGame < 2)
         {
             using (List <Thing> .Enumerator enumerator3 = current.GetEnumerator())
             {
                 while (enumerator3.MoveNext())
                 {
                     Thing current3 = enumerator3.Current;
                     GenPlace.TryPlaceThing(current3, intVec, ThingPlaceMode.Near);
                 }
                 continue;
             }
         }
         intVec = CellFinderLoose.RandomCellWith((IntVec3 c) => GenGrid.Standable(c) && !Find.RoofGrid.Roofed(c) && !Find.FogGrid.IsFogged(c), 1000);
         RazorRainUtility.MakeRazorRainAt(intVec);
     }
 }
예제 #7
0
        /// <summary>
        /// Some PRF Buildings are Magic, and can move stuff anywhere into a slotGroup
        ///   (or, you know, they pile stuff up until it falls, or use a machine
        ///    arm to move things, etc)
        /// </summary>
        /// <returns><c>true</c>, if thing was placed somewhere; <c>false</c> otherwise.</returns>
        /// <param name="placer">IPRF Buidling placing.</param>
        /// <param name="t">thing to place.</param>
        /// <param name="slotGroup">SlotGroup.</param>
        /// <param name="cell">optional first cell</param>
        public static bool PlaceThingAnywhereInSlotGroup(this IPRF_Building placer, Thing t,
                                                         SlotGroup slotGroup, IntVec3?cell = null)
        {
            // Should we even be putting anything here?
            if (placer.ObeysStorageFilters && !slotGroup.parent.Accepts(t))
            {
                return(false);
            }
            Map map = placer.Map;

            // Go through slotGroup, starting with cell if given
            // TODO: go thru slotgroup in order of increasing distance from cell?
            foreach (var c in (cell != null ? ((new[] { (IntVec3)cell }).Concat(slotGroup.CellsList.Where(x => x != cell)))
                                          : slotGroup.CellsList))
            {
                if (CallNoStorageBlockersIn(c, map, t))
                {
                    Debug.Message(Debug.Flag.PlaceThing, "Found NoStorageBlockersIn(" + cell + ", map, " + t + ") - Placing");
                    if (t.Spawned)
                    {
                        t.DeSpawn();
                    }
                    if (!GenPlace.TryPlaceThing(t, c, map, ThingPlaceMode.Direct))
                    {
                        // This happens if some was absorbed, but not the whole stack
                        //  We should continue on, to see if we can place everything
                        Debug.Message(Debug.Flag.PlaceThing, "  some was absorbed, still have " + t.stackCount);
                        continue;
                    }
                    placer.EffectOnPlaceThing(t);
                    if (placer.ForbidOnPlacing(t))
                    {
                        t.SetForbidden(true, false);
                    }
                    return(true);
                }
            }
            Debug.Message(Debug.Flag.PlaceThing, "There were StorageBlockersIn every cell of "
                          + slotGroup.parent + " - cannot place" + t);
            return(false);
        }
예제 #8
0
        public bool TryDoSpawn()
        {
            if (this.PropsSpawner.spawnMaxAdjacent >= 0)
            {
                int num = 0;
                for (int i = 0; i < 9; i++)
                {
                    List <Thing> thingList = (base.parent.Position + GenAdj.AdjacentCellsAndInside[i]).GetThingList(base.parent.Map);
                    for (int j = 0; j < thingList.Count; j++)
                    {
                        if (thingList[j].def == this.PropsSpawner.thingToSpawn)
                        {
                            num += thingList[j].stackCount;
                            if (num >= this.PropsSpawner.spawnMaxAdjacent)
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            IntVec3 center = default(IntVec3);

            if (this.TryFindSpawnCell(out center))
            {
                Thing thing = ThingMaker.MakeThing(this.PropsSpawner.thingToSpawn, null);
                thing.stackCount = this.PropsSpawner.spawnCount;
                Thing t = default(Thing);
                GenPlace.TryPlaceThing(thing, center, base.parent.Map, ThingPlaceMode.Direct, out t, (Action <Thing, int>)null);
                if (this.PropsSpawner.spawnForbidden)
                {
                    t.SetForbidden(true, true);
                }
                if (this.PropsSpawner.showMessageIfOwned && base.parent.Faction == Faction.OfPlayer)
                {
                    Messages.Message("MessageCompSpawnerSpawnedItem".Translate(this.PropsSpawner.thingToSpawn.label).CapitalizeFirst(), thing, MessageTypeDefOf.PositiveEvent);
                }
                return(true);
            }
            return(false);
        }
        public override void Tick()
        {
            base.Tick();

            this.age++;
            if (this.age >= TimerTicks)          // time out!!
            {
                Map   map       = base.Map;
                Thing thingslag = ThingMaker.MakeThing(RimWorld.ThingDefOf.ChunkSlagSteel, null);
                GenPlace.TryPlaceThing(thingslag, base.Position, map, ThingPlaceMode.Near, null, null);

                // great masive destruction here

                PLAHFmanabooom manabooom = (PLAHFmanabooom)GenSpawn.Spawn((PLAHFmanabooom)ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("PLAHFmanabooom", true)), this.Position, map, WipeMode.Vanish);
                manabooom.duration   = 2222;
                manabooom.instigator = this.Faction.leader;

                manabooom.weaponDef = null;
                manabooom.StartStrike();


                /*
                 * Bombardment bombardment = (Bombardment)GenSpawn.Spawn(RimWorld.ThingDefOf.Bombardment, bombstart, this.Map, WipeMode.Vanish);
                 * bombardment.duration = 540;
                 * bombardment.instigator = this.Faction.leader;
                 * bombardment.weaponDef = null;
                 * bombardment.StartStrike();
                 */


                this.Destroy(DestroyMode.Vanish);
            }
            else if (warnhalf)
            {
                if (this.age >= (TimerTicks / 2))
                {
                    Find.LetterStack.ReceiveLetter("LetterLabelPLAHFTMBAttackhalf".Translate(), "LetterPLAHFTMBAttackhalf".Translate(), LetterDefOf.ThreatBig, this, null, null);
                    warnhalf = !warnhalf;
                }
            }
        }
예제 #10
0
 public static void DropThingGroupsNear(IntVec3 dropCenter, Map map, List <List <Thing> > thingsGroups, int openDelay = 110, bool instaDrop = false, bool leaveSlag = false, bool canRoofPunch = true)
 {
     foreach (List <Thing> current in thingsGroups)
     {
         IntVec3 intVec;
         if (!DropCellFinder.TryFindDropSpotNear(dropCenter, map, out intVec, true, canRoofPunch))
         {
             Log.Warning(string.Concat(new object[]
             {
                 "DropThingsNear failed to find a place to drop ",
                 current.FirstOrDefault <Thing>(),
                 " near ",
                 dropCenter,
                 ". Dropping on random square instead."
             }), false);
             intVec = CellFinderLoose.RandomCellWith((IntVec3 c) => c.Walkable(map), map, 1000);
         }
         for (int i = 0; i < current.Count; i++)
         {
             current[i].SetForbidden(true, false);
         }
         if (instaDrop)
         {
             foreach (Thing current2 in current)
             {
                 GenPlace.TryPlaceThing(current2, intVec, map, ThingPlaceMode.Near, null, null);
             }
         }
         else
         {
             ActiveDropPodInfo activeDropPodInfo = new ActiveDropPodInfo();
             foreach (Thing current3 in current)
             {
                 activeDropPodInfo.innerContainer.TryAdd(current3, true);
             }
             activeDropPodInfo.openDelay = openDelay;
             activeDropPodInfo.leaveSlag = leaveSlag;
             DropPodUtility.MakeDropPodAt(intVec, map, activeDropPodInfo);
         }
     }
 }
예제 #11
0
        // Token: 0x0600002D RID: 45 RVA: 0x000035EC File Offset: 0x000017EC
        public void PlaceProduct()
        {
            var position = Position;
            var map      = Map;
            var thing    = ThingMaker.MakeThing(ThingDef.Named(compostBinComp.Props.productOne));

            thing.stackCount = compostBinComp.Props.numProductOne;
            GenPlace.TryPlaceThing(thing, position, map, ThingPlaceMode.Near);
            var thing2 = ThingMaker.MakeThing(ThingDef.Named(compostBinComp.Props.productTwo));

            thing2.stackCount = compostBinComp.Props.numProductTwo;
            GenPlace.TryPlaceThing(thing2, position, map, ThingPlaceMode.Near);
            if (def.defName != AYCharcoalKiln)
            {
                var random = new Random();
                var Chance = random.Next(3);
                var num    = random.Next(3);
                if (Chance < 2)
                {
                    GenPlace.TryPlaceThing(ThingMaker.MakeThing(ThingDef.Named("WoodLog")), position, map,
                                           ThingPlaceMode.Near);
                }

                if (num < 1)
                {
                    GenPlace.TryPlaceThing(ThingMaker.MakeThing(ThingDef.Named("WoodLog")), position, map,
                                           ThingPlaceMode.Near);
                }
            }

            ThingDef prevStuff = null;

            if (Stuff != null)
            {
                prevStuff = Stuff;
            }

            Destroy();
            GenConstruct.PlaceBlueprintForBuild(ThingDef.Named(def.defName), position, map, Rot4.North,
                                                Faction.OfPlayer, prevStuff);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            var map = parms.target as Map;

            if (!CultUtility.TryFindDropCell(map.Center, map, 999999, out var intVec))
            {
                return(false);
            }

            //this.EndOnDespawnedOrNull(this.pawn, JobCondition.Incompletable);
            for (var i = 0; i < Rand.Range(1, 3); i++)
            {
                var thing = (Building_TreasureChest)ThingMaker.MakeThing(CultsDefOf.Cults_TreasureChest);
                GenPlace.TryPlaceThing(thing, intVec.RandomAdjacentCell8Way(), map, ThingPlaceMode.Near);
            }

            map.GetComponent <MapComponent_SacrificeTracker>().lastLocation = intVec;
            Messages.Message("Treasures from the deep mysteriously appear.", new TargetInfo(intVec, map),
                             MessageTypeDefOf.PositiveEvent);
            return(true);
        }
예제 #13
0
 private void TrySpawnYield(Map map, float yieldChance, bool moteOnWaste, Pawn pawn)
 {
     if (def.building.mineableThing != null && !(Rand.Value > def.building.mineableDropChance))
     {
         int num = Mathf.Max(1, def.building.EffectiveMineableYield);
         if (def.building.mineableYieldWasteable)
         {
             num = Mathf.Max(1, GenMath.RoundRandom((float)num * yieldPct));
         }
         Thing thing2 = ThingMaker.MakeThing(def.building.mineableThing);
         thing2.stackCount = num;
         GenPlace.TryPlaceThing(thing2, base.Position, map, ThingPlaceMode.Near, ForbidIfNecessary);
     }
     void ForbidIfNecessary(Thing thing, int count)
     {
         if ((pawn == null || !pawn.IsColonist) && thing.def.EverHaulable && !thing.def.designateHaulable)
         {
             thing.SetForbidden(value: true, warnOnFail: false);
         }
     }
 }
예제 #14
0
        public void EjectLoadedShells()
        {
            var loaded = CurrentShellDef;

            if (loaded == null)
            {
                return;
            }

            if (LoadedShellCount <= 0)
            {
                return;
            }

            var thing = ThingMaker.MakeThing(loaded);

            thing.stackCount = LoadedShellCount;
            GenPlace.TryPlaceThing(thing, Position - new IntVec3(0, 0, 3), Map, ThingPlaceMode.Near);

            ClearLoadedShells();
        }
예제 #15
0
        public void Hatch()
        {
            if (HatchingTicker < (this.Props.hatcherDaystoHatch * 60000))
            {
                HatchingTicker += 1;
            }
            else
            {
                if ((this.parent.pawn.Map != null) && ((this.parent.pawn.Faction == Faction.OfPlayer) || ((this.parent.pawn.IsPrisoner) && (this.parent.pawn.Map.IsPlayerHome))))
                {
                    Thing thing = ThingMaker.MakeThing(ThingDef.Named("Milk"), null);
                    thing.stackCount = Props.hatcherYield;
                    GenPlace.TryPlaceThing(thing, this.parent.pawn.Position, this.parent.pawn.Map, ThingPlaceMode.Near, null, null);
                    //GenSpawn.Spawn(ThingDef.Named("Milk"), this.parent.pawn.Position, this.parent.pawn.Map);
                }
                HatchingTicker = 0;
            }


            //this.parent.Destroy(DestroyMode.Vanish);
        }
예제 #16
0
 private void PopulateCells()
 {
     foreach (IntVec3 cell in parent.OccupiedRect().Cells)
     {
         if (cell.GetItemList(parent.Map, true).Count == 0)
         {
             Thing thing = ProduceThing();
             if (thing != null)
             {
                 if (cell.AllowedToAccept(parent.Map, thing) && GenPlace.TryPlaceThing(thing, cell, parent.Map, ThingPlaceMode.Direct))
                 {
                     cell.DropSound(parent.Map, thing.def);
                 }
                 else
                 {
                     UnProduceThing(thing);
                 }
             }
         }
     }
 }
예제 #17
0
    public IEnumerable <Thing> ButcherProducts(Pawn butcher, float efficiency)
    {
        butcher.skills.Learn(SkillDefOf.Cooking, LearnRates.XpPerPawnSizeButchered * sourcePawn.def.race.bodySize);

        {
            Filth blood = (Filth)ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("FilthBlood"));
            blood.sources.Add(sourcePawn.Label);
            GenPlace.TryPlaceThing(blood, butcher.Position, ThingPlaceMode.Near);
        }

        if (sourcePawn.RaceDef.humanoid)
        {
            butcher.psychology.thoughts.GainThought(ThoughtDef.Named("ButcheredHumanoidCorpse"));
        }

        {
            Thing meat = ThingMaker.MakeThing(sourcePawn.def.race.meatDef);
            meat.stackCount = Mathf.RoundToInt(BaseButcherProductAmount * sourcePawn.def.race.bodySize * efficiency);
            yield return(meat);
        }
    }
        public static void DeployGas(Map map, IntVec3 pos, ThingDef gasDef, int amount)
        {
            if (gasDef == null)
            {
                RemoteTechController.Instance.Logger.Error("Tried to deploy null GasDef: " + Environment.StackTrace);
                return;
            }
            var cloud = TryFindGasCloudAt(map, pos, gasDef);

            if (cloud == null)
            {
                cloud = ThingMaker.MakeThing(gasDef) as GasCloud;
                if (cloud == null)
                {
                    RemoteTechController.Instance.Logger.Error($"Deployed thing was not a GasCloud: {gasDef}");
                    return;
                }
                GenPlace.TryPlaceThing(cloud, pos, map, ThingPlaceMode.Direct);
            }
            cloud.ReceiveConcentration(amount);
        }
예제 #19
0
 static void Postfix(CompRottable __instance, ref State __state)
 {
     if (__instance.parent.Destroyed)
     {
         if (__instance.parent.def.thingCategories == null)
         {
             return;
         }
         if (__instance.parent.def.defName.Contains("__Corpse"))
         {
             return;
         }
         if (__state.map == null)
         {
             return;
         }
         var twRawCompost = ThingMaker.MakeThing(ThingDefOf.twRawCompost, null);
         twRawCompost.stackCount = __state.stackCount;
         GenPlace.TryPlaceThing(twRawCompost, __instance.parent.Position, __state.map, ThingPlaceMode.Near, null);
     }
 }
예제 #20
0
        public override void incPctYeild(float amount, Pawn miner)
        {
            propExtracted += (float)Mathf.Min(amount, HitPoints) / (float)MaxHitPoints * miner.GetStatValue(StatDefOf.MiningYield, true) + (miner.GetStatValue(StatDefOf.MiningYield, true) - attributes.extractionDifficulty) * 0.2f + Rand.Range(-0.2f, 0.2f);
            if (propExtracted >= 1f)
            {
                propExtracted = 0f;
                ThingDef myThingDef = DefDatabase <ThingDef> .GetNamed(attributes.defName + "Trophy", true);

                if (myThingDef != null)
                {
                    BigMineralTrophy thing     = (BigMineralTrophy)ThingMaker.MakeThing(myThingDef, null);
                    Thing            miniThing = thing.MakeMinified();
                    GenPlace.TryPlaceThing(miniThing, Position, Map, ThingPlaceMode.Near, null);
                    Messages.Message("Rare mineral trophy extracted!".CapitalizeFirst(), MessageTypeDefOf.NeutralEvent, true);
                }
            }
            else
            {
                base.incPctYeild(amount, miner);
            }
        }
예제 #21
0
        private void EjectPilot()
        {
            Thing     thingForGraphic = this.GetThingForGraphic();
            HarpyComp comp            = thingForGraphic.TryGetComp <HarpyComp>();
            bool      flag            = thingForGraphic != null;

            if (flag)
            {
                GenPlace.TryPlaceThing(thingForGraphic, base.Position, base.Map, ThingPlaceMode.Near, delegate(Thing t, int count)
                {
                    PawnUtility.RecoverFromUnwalkablePositionOrKill(t.Position, t.Map);
                    bool flag2 = t.def.Fillage == FillCategory.Full && this.def.skyfaller.CausesExplosion && this.def.skyfaller.explosionDamage.isExplosive && t.Position.InHorDistOf(this.Position, this.def.skyfaller.explosionRadius);
                    if (flag2)
                    {
                        this.Map.terrainGrid.Notify_TerrainDestroyed(t.Position);
                    }
                    this.CheckDrafting(t);
                    comp.TriggerCooldown();
                }, null, default(Rot4));
            }
        }
예제 #22
0
 public virtual void TryOutputItem()
 {
     if (!OutputSlotOccupied && thingPlacementQueue.Count > 0)
     {
         GenPlace.TryPlaceThing(thingPlacementQueue.First(), OutputSlot, Map, ThingPlaceMode.Direct);
         thingPlacementQueue.RemoveAt(0);
     }
     else if (thingPlacementQueue.Count > 0)
     {
         foreach (var t in thingPlacementQueue)
         {
             var thing = OutputSlot.GetThingList(Map).Find(th => th.CanStackWith(t));
             thing?.TryAbsorbStack(t, true);
             if (t.Destroyed || t.stackCount == 0)
             {
                 thingPlacementQueue.Remove(t);
                 break;
             }
         }
     }
 }
예제 #23
0
 public static void SpawnArtilleryStrike(Map map, IntVec3 targetPosition, ArtilleryStrikeDef StrikeDef, Thing instigator = null, ThingDef weaponDef = null, bool warnFail = false)
 {
     for (int i = 0; i < StrikeDef.ordnance.Count; i++)
     {
         ThingDef ordnance  = StrikeDef.ordnance[i];
         IntVec3  strikeLoc = targetPosition;
         if (Rand.Chance(0.9f) || !DropCellFinder.IsGoodDropSpot(targetPosition, map, true, true))
         {
             if (!OrdnanceStrikeCellFinder.TryFindStrikeLocNear(targetPosition, map, out strikeLoc, true, true, true))
             {
                 if (warnFail)
                 {
                     Log.Warning("Artillery Strike: " + StrikeDef.LabelCap + " Target: " + targetPosition + " Failed to find location");
                 }
                 break;
             }
         }
         ArtilleryIncoming ordnanceIncoming = ArtilleryStrikeMaker.MakeSkyfaller(OrdnanceUtility.ArtilleryStrike, ordnance);
         GenPlace.TryPlaceThing(ordnanceIncoming, strikeLoc, map, ThingPlaceMode.Near, null, null, default(Rot4));
     }
 }
예제 #24
0
        public override void PawnDied(Corpse corpse)
        {
            for (int i = 0; i < 3; i++)
            {
                MoteMaker.ThrowSmoke(corpse.DrawPos, corpse.Map, Rand.Range(.5f, 1.1f));
            }
            TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_Ghost, corpse.DrawPos, corpse.Map, 1f, .25f, 0f, .25f, 0, Rand.Range(2f, 3f), 0, 0);
            //MoteMaker.ThrowHeatGlow(corpse.Position, corpse.Map, 1f);
            List <Thing> rewards   = new List <Thing>();
            Thing        arcalleum = ThingMaker.MakeThing(TorannMagicDefOf.TM_Arcalleum, null);

            if (corpse.Faction != Faction.OfPlayer)
            {
                if (corpse.InnerPawn.def == TorannMagicDefOf.TM_SkeletonR)
                {
                    arcalleum.stackCount = Rand.Range(4, 8);
                    rewards.Add(arcalleum);
                }
                else if (corpse.InnerPawn.def == TorannMagicDefOf.TM_GiantSkeletonR)
                {
                    arcalleum.stackCount = Rand.Range(25, 60);
                    rewards.Add(arcalleum);
                }
                else if (corpse.InnerPawn.def == TorannMagicDefOf.TM_SkeletonLichR)
                {
                    arcalleum.stackCount = Rand.Range(40, 80);
                    rewards.Add(arcalleum);

                    Thing tome = ThingMaker.MakeThing(TM_Data.MageBookList().RandomElement(), null);
                    tome.stackCount = 1;
                    rewards.Add(tome);
                    rewards.AddRange(ItemCollectionGenerator_Internal_Arcane.Generate(2000));
                }
                for (int i = 0; i < rewards.Count; i++)
                {
                    GenPlace.TryPlaceThing(rewards[i], corpse.Position, corpse.Map, ThingPlaceMode.Near);
                }
            }
            corpse.Destroy();
        }
        public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
        {
            base.Apply(target, dest);
            Map          map  = parent.pawn.Map;
            List <Thing> list = new List <Thing>();

            list.AddRange(AffectedCells(target, map).SelectMany((IntVec3 c) => from t in c.GetThingList(map)
                                                                where t.def.category == ThingCategory.Item
                                                                select t));
            foreach (Thing item in list)
            {
                item.DeSpawn();
            }
            foreach (IntVec3 item2 in AffectedCells(target, map))
            {
                GenSpawn.Spawn(ThingDefOf.RaisedRocks, item2, map);
                MoteMaker.ThrowDustPuffThick(item2.ToVector3Shifted(), map, Rand.Range(1.5f, 3f), DustColor);
            }
            foreach (Thing item3 in list)
            {
                IntVec3 intVec = IntVec3.Invalid;
                for (int i = 0; i < 9; i++)
                {
                    IntVec3 intVec2 = item3.Position + GenRadial.RadialPattern[i];
                    if (intVec2.InBounds(map) && intVec2.Walkable(map) && map.thingGrid.ThingsListAtFast(intVec2).Count <= 0)
                    {
                        intVec = intVec2;
                        break;
                    }
                }
                if (intVec != IntVec3.Invalid)
                {
                    GenSpawn.Spawn(item3, intVec, map);
                }
                else
                {
                    GenPlace.TryPlaceThing(item3, item3.Position, map, ThingPlaceMode.Near);
                }
            }
        }
 public void TrySpawnItemsAtOutput(List <IntVec3> clist)
 {
     foreach (IntVec3 cell in clist)
     {
         if (ThingCount <= 0)
         {
             continue;
         }
         Thing thing = cell.GetThingList(Map).Find(t => t.def == storedDef);
         bool  any   = cell.GetThingList(Map).Any(t => t.def.category == ThingCategory.Item);
         if (thing != null)
         {
             int potential = thing.def.stackLimit - thing.stackCount;
             if (potential > ThingCount)
             {
                 thing.stackCount += ThingCount;
                 ThingCount        = 0;
                 continue;
             }
             ThingCount       -= potential;
             thing.stackCount += potential;
             continue;
         }
         if (!any && storedDef != null)
         {
             Thing t = ThingMaker.MakeThing(storedDef);
             if (t.def.stackLimit > ThingCount)
             {
                 t.stackCount = ThingCount;
                 ThingCount   = 0;
             }
             else
             {
                 ThingCount  -= t.def.stackLimit;
                 t.stackCount = t.def.stackLimit;
             }
             GenPlace.TryPlaceThing(t, cell, Map, ThingPlaceMode.Direct);
         }
     }
 }
        public static bool DropSingleThing(Thing toDrop, IntVec3 from, Map map, out Thing result)
        {
            result = null;
            if (toDrop.stackCount == 0)
            {
                Log.Warning("To Drop Thing " + toDrop.Label + " had stack count of 0");
                return(false);
            }

            try
            {
                if (!toDrop.Spawned)
                {
                    GenThing.TryDropAndSetForbidden(toDrop, from, map, ThingPlaceMode.Near, out result, false);
                    if (!result.Spawned)
                    {
                        if (GenPlace.TryPlaceThing(toDrop, from, map, ThingPlaceMode.Near))
                        {
                            result = toDrop;
                        }
                        else
                        {
                            result = null;
                            Log.Error("Failed to spawn " + toDrop.Label + " x" + toDrop.stackCount);
                            return(false);
                        }
                    }
                }

                toDrop.Position = from;
            }
            catch (Exception e)
            {
                Log.Error(
                    typeof(BuildingUtil).Name + ".DropApparel\n" +
                    e.GetType().Name + " " + e.Message + "\n" +
                    e.StackTrace);
            }
            return(result != null && result.Spawned);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.OnCell));

            Toil extractStack = Toils_General.Wait(120, 0);

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

            yield return(new Toil
            {
                initAction = delegate()
                {
                    Corpse corpse = (Corpse)TargetThingA;
                    Hediff_CorticalStack hediff = corpse.InnerPawn.health.hediffSet.hediffs.FirstOrDefault((Hediff x) =>
                                                                                                           x.def.defName == "AC_CorticalStack") as Hediff_CorticalStack;
                    if (hediff != null)
                    {
                        if (hediff.def.spawnThingOnRemoved != null)
                        {
                            var corticalStack = ThingMaker.MakeThing(hediff.def.spawnThingOnRemoved) as CorticalStack;
                            if (hediff.hasPawn)
                            {
                                corticalStack.SavePawnFromHediff(hediff);
                            }
                            else
                            {
                                corticalStack.SavePawnToCorticalStack(corpse.InnerPawn);
                            }
                            GenPlace.TryPlaceThing(corticalStack, TargetThingA.Position, GetActor().Map, ThingPlaceMode.Near);
                            ACUtils.ACTracker.RegisterStack(corticalStack);
                            ACUtils.ACTracker.RegisterSleeve(corpse.InnerPawn);
                        }
                        corpse.InnerPawn.health.RemoveHediff(hediff);
                    }
                }
            });
        }
예제 #29
0
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);
            var ZTracker = Current.Game.GetComponent <ZLevelsManager>();

            if (!ZTracker.stairsUp.ContainsKey(this.Map))
            {
                ZTracker.stairsUp[this.Map] = new List <Thing>();
            }
            if (!ZTracker.stairsUp[this.Map].Contains(this))
            {
                ZTracker.stairsUp[this.Map].Add(this);
            }
            if (!respawningAfterLoad)
            {
                if (this.Position.GetTerrain(this.Map) == ZLevelsDefOf.ZL_OutsideTerrain)
                {
                    this.Map.terrainGrid.SetTerrain(this.Position, ZLevelsDefOf.ZL_OutsideTerrainTwo);
                }
                Map mapUpper = ZTracker.GetUpperLevel(this.Map.Tile, this.Map);
                if (mapUpper != null && mapUpper != this.Map)
                {
                    if (this.Position.GetThingList(mapUpper).Where(x => x.def == ZLevelsDefOf.ZL_StairsDown).Count() == 0)
                    {
                        mapUpper.terrainGrid.SetTerrain(this.Position, ZLevelsDefOf.ZL_OutsideTerrainTwo);
                        var stairsToSpawn = ThingMaker.MakeThing(ZLevelsDefOf.ZL_StairsDown, this.Stuff);
                        GenPlace.TryPlaceThing(stairsToSpawn, this.Position, mapUpper, ThingPlaceMode.Direct);
                        stairsToSpawn.SetFaction(this.Faction);
                    }
                }
                else if (mapUpper == this.Map)
                {
                    Log.Error("There was a mismatch of ZLevels indices. This is a serious error, report it to the mod developers");
                    foreach (var map2 in ZTracker.GetAllMaps(this.Map.Tile))
                    {
                        ZLogger.Message("Index: " + ZTracker.GetMapInfo(map2));
                    }
                }
            }
        }
예제 #30
0
        public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
        {
            base.Apply(target, dest);
            Map          map  = this.parent.pawn.Map;
            List <Thing> list = new List <Thing>();

            list.AddRange(this.AffectedCells(target, map).SelectMany((IntVec3 c) => from t in c.GetThingList(map)
                                                                     where t.def.category == ThingCategory.Item
                                                                     select t));
            foreach (Thing thing in list)
            {
                thing.DeSpawn(DestroyMode.Vanish);
            }
            foreach (IntVec3 loc in this.AffectedCells(target, map))
            {
                GenSpawn.Spawn(ThingDefOf.RaisedRocks, loc, map, WipeMode.Vanish);
                MoteMaker.ThrowDustPuffThick(loc.ToVector3Shifted(), map, Rand.Range(1.5f, 3f), CompAbilityEffect_Colosseum.DustColor);
            }
            foreach (Thing thing2 in list)
            {
                IntVec3 intVec = IntVec3.Invalid;
                for (int i = 0; i < 9; i++)
                {
                    IntVec3 intVec2 = thing2.Position + GenRadial.RadialPattern[i];
                    if (intVec2.InBounds(map) && intVec2.Walkable(map) && map.thingGrid.ThingsListAtFast(intVec2).Count <= 0)
                    {
                        intVec = intVec2;
                        break;
                    }
                }
                if (intVec != IntVec3.Invalid)
                {
                    GenSpawn.Spawn(thing2, intVec, map, WipeMode.Vanish);
                }
                else
                {
                    GenPlace.TryPlaceThing(thing2, thing2.Position, map, ThingPlaceMode.Near, null, null, default(Rot4));
                }
            }
        }