// Token: 0x06000012 RID: 18 RVA: 0x0000314C File Offset: 0x0000134C FindRandomPreSpacerPawnForSpawn
        private static void GenerateSlave(Building_XenomorphCryptosleepCasket pod)
        {
            PawnGenerationRequest pawnGenerationRequest;

            pawnGenerationRequest = new PawnGenerationRequest(Building_XenomorphCryptosleepCasket.FindRandomPreSpacerPawnForSpawn(), Faction.OfAncients, (PawnGenerationContext)2, (pod.Map != null ? pod.Map.Tile : pod.MapHeld.Tile), false, false, false, false, true, false, 1f, false, true, true, false, true, false, false);
            Pawn pawn = PawnGenerator.GeneratePawn(pawnGenerationRequest);

            HealthUtility.DamageUntilDowned(pawn, true);
            if (Rand.Chance(0.75f))
            {
                BodyPartRecord part = pawn.RaceProps.body.AllParts.Find(x => x.def == BodyPartDefOf.Head);
                pawn.health.AddHediff(XenomorphDefOf.RRY_FaceHuggerInfection, part);
            }
            Building_XenomorphCryptosleepCasket.GiveRandomLootInventoryForTombPawn(pawn);
            bool flag = Rand.Value < 0.5f;

            if (flag)
            {
                HealthUtility.DamageUntilDead(pawn);
            }
            bool flag2 = !pod.TryAcceptThing(pawn, false);

            if (flag2)
            {
                Find.WorldPawns.PassToWorld(pawn, (PawnDiscardDecideMode)2);
            }
        }
Exemple #2
0
        public override void Tick()
        {
            base.Tick();
            if (Find.TickManager.TicksGame % 250 == 0)
            {
                this.TickRare();
            }
            this.mindState.mentalStateHandler.neverFleeIndividual = true;

            if (this.health.hediffSet.HasTendableInjury())
            {
                this.TickHeal(true);
            }
            if (!base.Dead || !base.Downed)
            {
                int num = this.ticksSinceStatusUpdate;
                this.ticksSinceStatusUpdate = num + 1;
                if (this.ticksSinceStatusUpdate >= this.updateStatusEveryXTicks)
                {
                    IntVec3  intVec = CellFinder.RandomClosewalkCellNear(base.Position, base.Map, 1);
                    ThingDef named  = DefDatabase <ThingDef> .GetNamed("Filth_Blood", true);

                    FilthMaker.TryMakeFilth(intVec, base.Map, named, 1);
                    this.ticksSinceStatusUpdate = 0;
                }
            }
            if (base.Downed)
            {
                IntVec3  intVec2 = CellFinder.RandomClosewalkCellNear(base.Position, base.Map, 2);
                ThingDef named2  = DefDatabase <ThingDef> .GetNamed("Filth_Blood", true);

                FilthMaker.TryMakeFilth(intVec2, base.Map, named2, 3);
                HealthUtility.DamageUntilDead(this);
            }
        }
Exemple #3
0
        private Pawn GenerateSlave()
        {
            Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(PawnKindDefOf.Slave, Faction.OfAncients, PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn: false, newborn: false, allowDead: false, allowDowned: false, canGeneratePawnRelations: true, mustBeCapableOfViolence: false, 1f, forceAddFreeWarmLayerIfNeeded: false, allowGay: true, allowFood: true, allowAddictions: true, inhabitant: false, certainlyBeenInCryptosleep: true));

            HealthUtility.DamageUntilDowned(pawn);
            GiveRandomLootInventoryForTombPawn(pawn);
            if (Rand.Value < 0.5f)
            {
                HealthUtility.DamageUntilDead(pawn);
            }
            return(pawn);
        }
        private Pawn GenerateSlave()
        {
            PawnGenerationRequest request = new PawnGenerationRequest(PawnKindDefOf.Slave, Faction.OfAncients, PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, false, 1f, false, true, true, false, true, false, false, null, null, null, null, null, null, null, null);
            Pawn pawn = PawnGenerator.GeneratePawn(request);

            HealthUtility.DamageUntilDowned(pawn);
            this.GiveRandomLootInventoryForTombPawn(pawn);
            if (Rand.Value < 0.5f)
            {
                HealthUtility.DamageUntilDead(pawn);
            }
            return(pawn);
        }
 public static void KillAndRotPawn(Pawn pawn, float rotProgressInTicks)
 {
     HealthUtility.DamageUntilDead(pawn);
     foreach (Thing thing in pawn.Position.GetThingList(pawn.MapHeld))
     {
         if (thing.def.defName.Contains("Corpse"))
         {
             CompRottable rotComp = thing.TryGetComp <CompRottable>();
             if (rotComp != null)
             {
                 rotComp.RotProgress = rotProgressInTicks;
             }
         }
     }
 }
Exemple #6
0
        private static void GenerateSlave(Building_CryptosleepCasket pod)
        {
            Faction faction = Find.FactionManager.FirstFactionOfDef(FactionDefOf.Spacer);
            Pawn    pawn    = PawnGenerator.GeneratePawn(PawnKindDefOf.Slave, faction);

            if (!pod.TryAcceptThing(pawn, false))
            {
                Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
                return;
            }
            HealthUtility.DamageUntilDowned(pawn);
            GiveRandomLootInventoryForTombPawn(pawn);
            if (Rand.Value < 0.5f)
            {
                HealthUtility.DamageUntilDead(pawn);
            }
        }
Exemple #7
0
        private static void GenerateSlave(Building_CryptosleepCasket pod)
        {
            PawnGenerationRequest request = new PawnGenerationRequest(PawnKindDefOf.Slave, Faction.OfAncients, PawnGenerationContext.NonPlayer, -1, false, false, false, false, true, false, 1f, false, true, true, false, false, true, false, false, 0f, 0f, null, 1, null, null, null, null, null);
            Pawn pawn = PawnGenerator.GeneratePawn(request);

            HealthUtility.DamageUntilDowned(pawn, true);
            GiveRandomLootInventoryForTombPawn(pawn);
            if (Rand.Value < 0.4f)
            {
                HealthUtility.DamageUntilDead(pawn);
            }

            if (!pod.TryAcceptThing(pawn, false))
            {
                Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
            }
        }
        public override void Resolve(ResolveParams rp)
        {
            //spawn dead dudes
            ResolveParams resolveParamsCorpses = rp;
            int           corpseCount          = rp.rect.Width * rp.rect.Height / 180; //Adjust as needed. Maybe run symbol multiple times in parent function

            for (int i = 0; i < corpseCount; i++)
            {
                PawnGenerationRequest request = new PawnGenerationRequest(DefsOfLGE.CityDwellerLGE, Faction.OfAncients, PawnGenerationContext.NonPlayer, canGeneratePawnRelations: false, forceGenerateNewPawn: true);
                Pawn pawn = PawnGenerator.GeneratePawn(request);
                HealthUtility.DamageUntilDead(pawn);
                pawn.Corpse.GetComp <CompRottable>().RotProgress = 5000000;
                //This corpse is now 10 years old with 36mio ticks
                pawn.Corpse.Age = 36000000;
                resolveParamsCorpses.singleThingToSpawn = pawn.Corpse;
                BaseGen.symbolStack.Push("thing", resolveParamsCorpses);
            }
        }
        public override void Execute(int amount, string boughtBy)
        {
            var amountOfDrops = 20;
            var currentMap    = Find.CurrentMap;

            var pawnGenerationRequest = new PawnGenerationRequest(PawnKindDefOf.Colonist, allowDead: true);

            for (int i = 0; i < amountOfDrops; i++)
            {
                var newPawn = PawnGenerator.GeneratePawn(pawnGenerationRequest);

                IntVec3 dropVector = DropCellFinder.TradeDropSpot(currentMap);
                TradeUtility.SpawnDropPod(dropVector, currentMap, newPawn);

                HealthUtility.DamageUntilDead(newPawn);
                newPawn.equipment.DestroyAllEquipment();
                newPawn.apparel.DestroyAll();
            }

            AlertManager.NormalEventNotification("It's Raining men, hallelujah!");
        }
Exemple #10
0
        private void GeneratePawns(Building_Container container, Faction owner)
        {
            int pawnsCount = Rand.Range(1, 4);

            for (int i = 0; i < pawnsCount; i++)
            {
                Pawn p = PawnGenerator.GeneratePawn(new PawnGenerationRequest(PawnKindDefOf.Colonist, owner));

                if (Rand.Chance(0.2f))
                {
                    HealthUtility.DamageUntilDead(p);
                }
                else
                {
                    HealthUtility.DamageUntilDowned(p, false);
                }

                container.AddItem(p);

                dangerousLevel += p.MarketValue * Rand.Range(1f, 1.7f);
            }
        }
Exemple #11
0
        public static void MakeColony(params ColonyMakerFlag[] flags)
        {
            bool godMode = DebugSettings.godMode;

            DebugSettings.godMode            = true;
            Thing.allowDestroyNonDestroyable = true;
            if (Autotests_ColonyMaker.usedCells == null)
            {
                Autotests_ColonyMaker.usedCells = new BoolGrid(Autotests_ColonyMaker.Map);
            }
            else
            {
                Autotests_ColonyMaker.usedCells.ClearAndResizeTo(Autotests_ColonyMaker.Map);
            }
            Autotests_ColonyMaker.overRect = new CellRect(Autotests_ColonyMaker.Map.Center.x - 50, Autotests_ColonyMaker.Map.Center.z - 50, 100, 100);
            Autotests_ColonyMaker.DeleteAllSpawnedPawns();
            GenDebug.ClearArea(Autotests_ColonyMaker.overRect, Find.VisibleMap);
            if (flags.Contains(ColonyMakerFlag.Animals))
            {
                foreach (PawnKindDef current in from k in DefDatabase <PawnKindDef> .AllDefs
                         where k.RaceProps.Animal
                         select k)
                {
                    CellRect cellRect;
                    if (!Autotests_ColonyMaker.TryGetFreeRect(6, 3, out cellRect))
                    {
                        return;
                    }
                    cellRect = cellRect.ContractedBy(1);
                    foreach (IntVec3 current2 in cellRect)
                    {
                        Autotests_ColonyMaker.Map.terrainGrid.SetTerrain(current2, TerrainDefOf.Concrete);
                    }
                    GenSpawn.Spawn(PawnGenerator.GeneratePawn(current, null), cellRect.Cells.ElementAt(0), Autotests_ColonyMaker.Map);
                    IntVec3 intVec = cellRect.Cells.ElementAt(1);
                    Pawn    p      = (Pawn)GenSpawn.Spawn(PawnGenerator.GeneratePawn(current, null), intVec, Autotests_ColonyMaker.Map);
                    HealthUtility.DamageUntilDead(p);
                    Corpse       thing        = (Corpse)intVec.GetThingList(Find.VisibleMap).First((Thing t) => t is Corpse);
                    CompRottable compRottable = thing.TryGetComp <CompRottable>();
                    if (compRottable != null)
                    {
                        compRottable.RotProgress += 1200000f;
                    }
                    if (current.RaceProps.leatherDef != null)
                    {
                        GenSpawn.Spawn(current.RaceProps.leatherDef, cellRect.Cells.ElementAt(2), Autotests_ColonyMaker.Map);
                    }
                    if (current.RaceProps.meatDef != null)
                    {
                        GenSpawn.Spawn(current.RaceProps.meatDef, cellRect.Cells.ElementAt(3), Autotests_ColonyMaker.Map);
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.ConduitGrid))
            {
                Designator_Build designator_Build = new Designator_Build(ThingDefOf.PowerConduit);
                for (int i = Autotests_ColonyMaker.overRect.minX; i < Autotests_ColonyMaker.overRect.maxX; i++)
                {
                    for (int j = Autotests_ColonyMaker.overRect.minZ; j < Autotests_ColonyMaker.overRect.maxZ; j += 7)
                    {
                        designator_Build.DesignateSingleCell(new IntVec3(i, 0, j));
                    }
                }
                for (int k2 = Autotests_ColonyMaker.overRect.minZ; k2 < Autotests_ColonyMaker.overRect.maxZ; k2++)
                {
                    for (int l = Autotests_ColonyMaker.overRect.minX; l < Autotests_ColonyMaker.overRect.maxX; l += 7)
                    {
                        designator_Build.DesignateSingleCell(new IntVec3(l, 0, k2));
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.PowerPlants))
            {
                List <ThingDef> list = new List <ThingDef>
                {
                    ThingDefOf.SolarGenerator,
                    ThingDefOf.WindTurbine
                };
                for (int m = 0; m < 8; m++)
                {
                    if (Autotests_ColonyMaker.TryMakeBuilding(list[m % list.Count]) == null)
                    {
                        Log.Message("Could not make solar generator.");
                        break;
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.Batteries))
            {
                for (int n = 0; n < 6; n++)
                {
                    Thing thing2 = Autotests_ColonyMaker.TryMakeBuilding(ThingDefOf.Battery);
                    if (thing2 == null)
                    {
                        Log.Message("Could not make battery.");
                        break;
                    }
                    ((Building_Battery)thing2).GetComp <CompPowerBattery>().AddEnergy(999999f);
                }
            }
            if (flags.Contains(ColonyMakerFlag.WorkTables))
            {
                IEnumerable <ThingDef> enumerable = from def in DefDatabase <ThingDef> .AllDefs
                                                    where typeof(Building_WorkTable).IsAssignableFrom(def.thingClass)
                                                    select def;
                foreach (ThingDef current3 in enumerable)
                {
                    Thing thing3 = Autotests_ColonyMaker.TryMakeBuilding(current3);
                    if (thing3 == null)
                    {
                        Log.Message("Could not make worktable: " + current3.defName);
                        break;
                    }
                    Building_WorkTable building_WorkTable = thing3 as Building_WorkTable;
                    if (building_WorkTable != null)
                    {
                        foreach (RecipeDef current4 in building_WorkTable.def.AllRecipes)
                        {
                            building_WorkTable.billStack.AddBill(current4.MakeNewBill());
                        }
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.AllBuildings))
            {
                IEnumerable <ThingDef> enumerable2 = from def in DefDatabase <ThingDef> .AllDefs
                                                     where def.category == ThingCategory.Building && def.designationCategory != null
                                                     select def;
                foreach (ThingDef current5 in enumerable2)
                {
                    if (current5 != ThingDefOf.PowerConduit)
                    {
                        if (Autotests_ColonyMaker.TryMakeBuilding(current5) == null)
                        {
                            Log.Message("Could not make building: " + current5.defName);
                            break;
                        }
                    }
                }
            }
            CellRect rect;

            if (!Autotests_ColonyMaker.TryGetFreeRect(33, 33, out rect))
            {
                Log.Error("Could not get wallable rect");
            }
            rect = rect.ContractedBy(1);
            if (flags.Contains(ColonyMakerFlag.AllItems))
            {
                List <ThingDef> itemDefs = (from def in DefDatabase <ThingDef> .AllDefs
                                            where DebugThingPlaceHelper.IsDebugSpawnable(def) && def.category == ThingCategory.Item
                                            select def).ToList <ThingDef>();
                Autotests_ColonyMaker.FillWithItems(rect, itemDefs);
            }
            else if (flags.Contains(ColonyMakerFlag.ItemsRawFood))
            {
                List <ThingDef> list2 = new List <ThingDef>();
                list2.Add(ThingDefOf.RawPotatoes);
                Autotests_ColonyMaker.FillWithItems(rect, list2);
            }
            if (flags.Contains(ColonyMakerFlag.Filth))
            {
                foreach (IntVec3 current6 in rect)
                {
                    GenSpawn.Spawn(ThingDefOf.FilthDirt, current6, Autotests_ColonyMaker.Map);
                }
            }
            if (flags.Contains(ColonyMakerFlag.ItemsWall))
            {
                CellRect         cellRect2         = rect.ExpandedBy(1);
                Designator_Build designator_Build2 = new Designator_Build(ThingDefOf.Wall);
                designator_Build2.SetStuffDef(ThingDefOf.WoodLog);
                foreach (IntVec3 current7 in cellRect2.EdgeCells)
                {
                    designator_Build2.DesignateSingleCell(current7);
                }
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsMany))
            {
                Autotests_ColonyMaker.MakeColonists(15, Autotests_ColonyMaker.overRect.CenterCell);
            }
            else if (flags.Contains(ColonyMakerFlag.ColonistOne))
            {
                Autotests_ColonyMaker.MakeColonists(1, Autotests_ColonyMaker.overRect.CenterCell);
            }
            if (flags.Contains(ColonyMakerFlag.Fire))
            {
                CellRect cellRect3;
                if (!Autotests_ColonyMaker.TryGetFreeRect(30, 30, out cellRect3))
                {
                    Log.Error("Could not get free rect for fire.");
                }
                ThingDef plantTreeOak = ThingDefOf.PlantTreeOak;
                foreach (IntVec3 current8 in cellRect3)
                {
                    GenSpawn.Spawn(plantTreeOak, current8, Autotests_ColonyMaker.Map);
                }
                foreach (IntVec3 current9 in cellRect3)
                {
                    if (current9.x % 7 == 0 && current9.z % 7 == 0)
                    {
                        GenExplosion.DoExplosion(current9, Find.VisibleMap, 3.9f, DamageDefOf.Flame, null, -1, null, null, null, null, 0f, 1, false, null, 0f, 1, 0f, false);
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsHungry))
            {
                Autotests_ColonyMaker.DoToColonists(0.4f, delegate(Pawn col)
                {
                    col.needs.food.CurLevel = Mathf.Max(0f, Rand.Range(-0.05f, 0.05f));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsTired))
            {
                Autotests_ColonyMaker.DoToColonists(0.4f, delegate(Pawn col)
                {
                    col.needs.rest.CurLevel = Mathf.Max(0f, Rand.Range(-0.05f, 0.05f));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsInjured))
            {
                Autotests_ColonyMaker.DoToColonists(0.4f, delegate(Pawn col)
                {
                    DamageDef def = (from d in DefDatabase <DamageDef> .AllDefs
                                     where d.externalViolence
                                     select d).RandomElement <DamageDef>();
                    col.TakeDamage(new DamageInfo(def, 10, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsDiseased))
            {
                foreach (HediffDef current10 in from d in DefDatabase <HediffDef> .AllDefs
                         where d.hediffClass != typeof(Hediff_AddedPart) && (d.HasComp(typeof(HediffComp_Immunizable)) || d.HasComp(typeof(HediffComp_GrowthMode)))
                         select d)
                {
                    Pawn     pawn = PawnGenerator.GeneratePawn(Faction.OfPlayer.def.basicMemberKind, Faction.OfPlayer);
                    CellRect cellRect4;
                    Autotests_ColonyMaker.TryGetFreeRect(1, 1, out cellRect4);
                    GenSpawn.Spawn(pawn, cellRect4.CenterCell, Autotests_ColonyMaker.Map);
                    pawn.health.AddHediff(current10, null, null);
                }
            }
            if (flags.Contains(ColonyMakerFlag.Beds))
            {
                IEnumerable <ThingDef> source = from def in DefDatabase <ThingDef> .AllDefs
                                                where def.thingClass == typeof(Building_Bed)
                                                select def;
                int freeColonistsCount = Autotests_ColonyMaker.Map.mapPawns.FreeColonistsCount;
                for (int num = 0; num < freeColonistsCount; num++)
                {
                    if (Autotests_ColonyMaker.TryMakeBuilding(source.RandomElement <ThingDef>()) == null)
                    {
                        Log.Message("Could not make beds.");
                        break;
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.Stockpiles))
            {
                Designator_ZoneAddStockpile_Resources designator_ZoneAddStockpile_Resources = new Designator_ZoneAddStockpile_Resources();
                foreach (StoragePriority priority in Enum.GetValues(typeof(StoragePriority)))
                {
                    CellRect cellRect5;
                    Autotests_ColonyMaker.TryGetFreeRect(7, 7, out cellRect5);
                    cellRect5 = cellRect5.ContractedBy(1);
                    designator_ZoneAddStockpile_Resources.DesignateMultiCell(cellRect5.Cells);
                    Zone_Stockpile zone_Stockpile = (Zone_Stockpile)Autotests_ColonyMaker.Map.zoneManager.ZoneAt(cellRect5.CenterCell);
                    zone_Stockpile.settings.Priority = priority;
                }
            }
            if (flags.Contains(ColonyMakerFlag.GrowingZones))
            {
                Zone_Growing dummyZone = new Zone_Growing(Autotests_ColonyMaker.Map.zoneManager);
                foreach (ThingDef current11 in from d in DefDatabase <ThingDef> .AllDefs
                         where d.plant != null && GenPlant.CanSowOnGrower(d, dummyZone)
                         select d)
                {
                    CellRect cellRect6;
                    if (!Autotests_ColonyMaker.TryGetFreeRect(6, 6, out cellRect6))
                    {
                        Log.Error("Could not get growing zone rect.");
                    }
                    cellRect6 = cellRect6.ContractedBy(1);
                    foreach (IntVec3 current12 in cellRect6)
                    {
                        Autotests_ColonyMaker.Map.terrainGrid.SetTerrain(current12, TerrainDefOf.Soil);
                    }
                    Designator_ZoneAdd_Growing designator_ZoneAdd_Growing = new Designator_ZoneAdd_Growing();
                    designator_ZoneAdd_Growing.DesignateMultiCell(cellRect6.Cells);
                    Zone_Growing zone_Growing = (Zone_Growing)Autotests_ColonyMaker.Map.zoneManager.ZoneAt(cellRect6.CenterCell);
                    zone_Growing.SetPlantDefToGrow(current11);
                }
                dummyZone.Delete();
            }
            Autotests_ColonyMaker.ClearAllHomeArea();
            Autotests_ColonyMaker.FillWithHomeArea(Autotests_ColonyMaker.overRect);
            DebugSettings.godMode            = godMode;
            Thing.allowDestroyNonDestroyable = false;
        }
Exemple #12
0
        public static void MakeColony(params ColonyMakerFlag[] flags)
        {
            bool godMode = DebugSettings.godMode;

            DebugSettings.godMode            = true;
            Thing.allowDestroyNonDestroyable = true;
            if (usedCells == null)
            {
                usedCells = new BoolGrid(Map);
            }
            else
            {
                usedCells.ClearAndResizeTo(Map);
            }
            IntVec3 center  = Map.Center;
            int     minX    = center.x - 50;
            IntVec3 center2 = Map.Center;

            overRect = new CellRect(minX, center2.z - 50, 100, 100);
            DeleteAllSpawnedPawns();
            GenDebug.ClearArea(overRect, Find.CurrentMap);
            if (flags.Contains(ColonyMakerFlag.Animals))
            {
                foreach (PawnKindDef item in from k in DefDatabase <PawnKindDef> .AllDefs
                         where k.RaceProps.Animal
                         select k)
                {
                    if (!TryGetFreeRect(6, 3, out CellRect result))
                    {
                        return;
                    }
                    result = result.ContractedBy(1);
                    foreach (IntVec3 item2 in result)
                    {
                        Map.terrainGrid.SetTerrain(item2, TerrainDefOf.Concrete);
                    }
                    GenSpawn.Spawn(PawnGenerator.GeneratePawn(item), result.Cells.ElementAt(0), Map);
                    IntVec3 intVec = result.Cells.ElementAt(1);
                    Pawn    p      = (Pawn)GenSpawn.Spawn(PawnGenerator.GeneratePawn(item), intVec, Map);
                    HealthUtility.DamageUntilDead(p);
                    Corpse       thing        = (Corpse)intVec.GetThingList(Find.CurrentMap).First((Thing t) => t is Corpse);
                    CompRottable compRottable = thing.TryGetComp <CompRottable>();
                    if (compRottable != null)
                    {
                        compRottable.RotProgress += 1200000f;
                    }
                    if (item.RaceProps.leatherDef != null)
                    {
                        GenSpawn.Spawn(item.RaceProps.leatherDef, result.Cells.ElementAt(2), Map);
                    }
                    if (item.RaceProps.meatDef != null)
                    {
                        GenSpawn.Spawn(item.RaceProps.meatDef, result.Cells.ElementAt(3), Map);
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.ConduitGrid))
            {
                Designator_Build designator_Build = new Designator_Build(ThingDefOf.PowerConduit);
                for (int i = overRect.minX; i < overRect.maxX; i++)
                {
                    for (int j = overRect.minZ; j < overRect.maxZ; j += 7)
                    {
                        designator_Build.DesignateSingleCell(new IntVec3(i, 0, j));
                    }
                }
                for (int l = overRect.minZ; l < overRect.maxZ; l++)
                {
                    for (int m = overRect.minX; m < overRect.maxX; m += 7)
                    {
                        designator_Build.DesignateSingleCell(new IntVec3(m, 0, l));
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.PowerPlants))
            {
                List <ThingDef> list = new List <ThingDef>();
                list.Add(ThingDefOf.SolarGenerator);
                list.Add(ThingDefOf.WindTurbine);
                List <ThingDef> list2 = list;
                for (int n = 0; n < 8; n++)
                {
                    if (TryMakeBuilding(list2[n % list2.Count]) == null)
                    {
                        Log.Message("Could not make solar generator.");
                        break;
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.Batteries))
            {
                for (int num = 0; num < 6; num++)
                {
                    Thing thing2 = TryMakeBuilding(ThingDefOf.Battery);
                    if (thing2 == null)
                    {
                        Log.Message("Could not make battery.");
                        break;
                    }
                    ((Building_Battery)thing2).GetComp <CompPowerBattery>().AddEnergy(999999f);
                }
            }
            if (flags.Contains(ColonyMakerFlag.WorkTables))
            {
                IEnumerable <ThingDef> enumerable = from def in DefDatabase <ThingDef> .AllDefs
                                                    where typeof(Building_WorkTable).IsAssignableFrom(def.thingClass)
                                                    select def;
                foreach (ThingDef item3 in enumerable)
                {
                    Thing thing3 = TryMakeBuilding(item3);
                    if (thing3 == null)
                    {
                        Log.Message("Could not make worktable: " + item3.defName);
                        break;
                    }
                    Building_WorkTable building_WorkTable = thing3 as Building_WorkTable;
                    if (building_WorkTable != null)
                    {
                        foreach (RecipeDef allRecipe in building_WorkTable.def.AllRecipes)
                        {
                            building_WorkTable.billStack.AddBill(allRecipe.MakeNewBill());
                        }
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.AllBuildings))
            {
                IEnumerable <ThingDef> enumerable2 = from def in DefDatabase <ThingDef> .AllDefs
                                                     where def.category == ThingCategory.Building && def.BuildableByPlayer
                                                     select def;
                foreach (ThingDef item4 in enumerable2)
                {
                    if (item4 != ThingDefOf.PowerConduit)
                    {
                        Thing thing4 = TryMakeBuilding(item4);
                        if (thing4 == null)
                        {
                            Log.Message("Could not make building: " + item4.defName);
                            break;
                        }
                    }
                }
            }
            if (!TryGetFreeRect(33, 33, out CellRect result2))
            {
                Log.Error("Could not get wallable rect");
            }
            result2 = result2.ContractedBy(1);
            if (flags.Contains(ColonyMakerFlag.AllItems))
            {
                List <ThingDef> itemDefs = (from def in DefDatabase <ThingDef> .AllDefs
                                            where DebugThingPlaceHelper.IsDebugSpawnable(def) && def.category == ThingCategory.Item
                                            select def).ToList();
                FillWithItems(result2, itemDefs);
            }
            else if (flags.Contains(ColonyMakerFlag.ItemsRawFood))
            {
                List <ThingDef> list3 = new List <ThingDef>();
                list3.Add(ThingDefOf.RawPotatoes);
                FillWithItems(result2, list3);
            }
            if (flags.Contains(ColonyMakerFlag.Filth))
            {
                foreach (IntVec3 item5 in result2)
                {
                    GenSpawn.Spawn(ThingDefOf.Filth_Dirt, item5, Map);
                }
            }
            if (flags.Contains(ColonyMakerFlag.ItemsWall))
            {
                CellRect         cellRect          = result2.ExpandedBy(1);
                Designator_Build designator_Build2 = new Designator_Build(ThingDefOf.Wall);
                designator_Build2.SetStuffDef(ThingDefOf.WoodLog);
                foreach (IntVec3 edgeCell in cellRect.EdgeCells)
                {
                    designator_Build2.DesignateSingleCell(edgeCell);
                }
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsMany))
            {
                MakeColonists(15, overRect.CenterCell);
            }
            else if (flags.Contains(ColonyMakerFlag.ColonistOne))
            {
                MakeColonists(1, overRect.CenterCell);
            }
            if (flags.Contains(ColonyMakerFlag.Fire))
            {
                if (!TryGetFreeRect(30, 30, out CellRect result3))
                {
                    Log.Error("Could not get free rect for fire.");
                }
                ThingDef plant_TreeOak = ThingDefOf.Plant_TreeOak;
                foreach (IntVec3 item6 in result3)
                {
                    GenSpawn.Spawn(plant_TreeOak, item6, Map);
                }
                foreach (IntVec3 item7 in result3)
                {
                    IntVec3 current9 = item7;
                    if (current9.x % 7 == 0 && current9.z % 7 == 0)
                    {
                        GenExplosion.DoExplosion(current9, Find.CurrentMap, 3.9f, DamageDefOf.Flame, null);
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsHungry))
            {
                DoToColonists(0.4f, delegate(Pawn col)
                {
                    col.needs.food.CurLevel = Mathf.Max(0f, Rand.Range(-0.05f, 0.05f));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsTired))
            {
                DoToColonists(0.4f, delegate(Pawn col)
                {
                    col.needs.rest.CurLevel = Mathf.Max(0f, Rand.Range(-0.05f, 0.05f));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsInjured))
            {
                DoToColonists(0.4f, delegate(Pawn col)
                {
                    DamageDef def2 = (from d in DefDatabase <DamageDef> .AllDefs
                                      where d.ExternalViolenceFor(null)
                                      select d).RandomElement();
                    col.TakeDamage(new DamageInfo(def2, 10f));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsDiseased))
            {
                foreach (HediffDef item8 in from d in DefDatabase <HediffDef> .AllDefs
                         where d.hediffClass != typeof(Hediff_AddedPart) && (d.HasComp(typeof(HediffComp_Immunizable)) || d.HasComp(typeof(HediffComp_GrowthMode)))
                         select d)
                {
                    Pawn pawn = PawnGenerator.GeneratePawn(Faction.OfPlayer.def.basicMemberKind, Faction.OfPlayer);
                    TryGetFreeRect(1, 1, out CellRect result4);
                    GenSpawn.Spawn(pawn, result4.CenterCell, Map);
                    pawn.health.AddHediff(item8);
                }
            }
            if (flags.Contains(ColonyMakerFlag.Beds))
            {
                IEnumerable <ThingDef> source = from def in DefDatabase <ThingDef> .AllDefs
                                                where def.thingClass == typeof(Building_Bed)
                                                select def;
                int freeColonistsCount = Map.mapPawns.FreeColonistsCount;
                for (int num2 = 0; num2 < freeColonistsCount; num2++)
                {
                    if (TryMakeBuilding(source.RandomElement()) == null)
                    {
                        Log.Message("Could not make beds.");
                        break;
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.Stockpiles))
            {
                Designator_ZoneAddStockpile_Resources designator_ZoneAddStockpile_Resources = new Designator_ZoneAddStockpile_Resources();
                IEnumerator enumerator11 = Enum.GetValues(typeof(StoragePriority)).GetEnumerator();
                try
                {
                    while (enumerator11.MoveNext())
                    {
                        StoragePriority priority = (StoragePriority)enumerator11.Current;
                        TryGetFreeRect(7, 7, out CellRect result5);
                        result5 = result5.ContractedBy(1);
                        designator_ZoneAddStockpile_Resources.DesignateMultiCell(result5.Cells);
                        Zone_Stockpile zone_Stockpile = (Zone_Stockpile)Map.zoneManager.ZoneAt(result5.CenterCell);
                        zone_Stockpile.settings.Priority = priority;
                    }
                }
                finally
                {
                    IDisposable disposable;
                    if ((disposable = (enumerator11 as IDisposable)) != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.GrowingZones))
            {
                Zone_Growing dummyZone = new Zone_Growing(Map.zoneManager);
                Map.zoneManager.RegisterZone(dummyZone);
                foreach (ThingDef item9 in from d in DefDatabase <ThingDef> .AllDefs
                         where d.plant != null && PlantUtility.CanSowOnGrower(d, dummyZone)
                         select d)
                {
                    if (!TryGetFreeRect(6, 6, out CellRect result6))
                    {
                        Log.Error("Could not get growing zone rect.");
                    }
                    result6 = result6.ContractedBy(1);
                    foreach (IntVec3 item10 in result6)
                    {
                        Map.terrainGrid.SetTerrain(item10, TerrainDefOf.Soil);
                    }
                    Designator_ZoneAdd_Growing designator_ZoneAdd_Growing = new Designator_ZoneAdd_Growing();
                    designator_ZoneAdd_Growing.DesignateMultiCell(result6.Cells);
                    (Map.zoneManager.ZoneAt(result6.CenterCell) as Zone_Growing)?.SetPlantDefToGrow(item9);
                }
                dummyZone.Delete();
            }
            ClearAllHomeArea();
            FillWithHomeArea(overRect);
            DebugSettings.godMode            = godMode;
            Thing.allowDestroyNonDestroyable = false;
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map          map      = (Map)parms.target;
            ThingDef     thingDef = MOIncidentWorker_ShipBreak.RandomPodContentsDef();
            List <Thing> list     = new List <Thing>();
            List <Thing> list2    = new List <Thing>();
            float        num      = (float)Rand.Range(150, 900);

            do
            {
                Thing thing = ThingMaker.MakeThing(thingDef, null);
                int   num2  = Rand.Range(20, 40);
                bool  flag  = num2 > thing.def.stackLimit;
                if (flag)
                {
                    num2 = thing.def.stackLimit;
                }
                bool flag2 = (float)num2 * thing.def.BaseMarketValue > num;
                if (flag2)
                {
                    num2 = Mathf.FloorToInt(num / thing.def.BaseMarketValue);
                }
                bool flag3 = num2 == 0;
                if (flag3)
                {
                    num2 = 1;
                }
                thing.stackCount = num2;
                list.Add(thing);
                list2.Add(thing);
                num -= (float)num2 * thingDef.BaseMarketValue;
            }while (list.Count < 25 && num > thingDef.BaseMarketValue);
            while (list2.Count < 25 && num > thingDef.BaseMarketValue)
            {
            }
            IntVec3 intVec  = DropCellFinder.RandomDropSpot(map);
            IntVec3 intVec2 = DropCellFinder.RandomDropSpot(map);
            IntVec3 intVec3 = DropCellFinder.RandomDropSpot(map);
            Faction faction = Find.FactionManager.RandomNonHostileFaction(true, true, true, TechLevel.Spacer);
            PawnGenerationRequest pawnGenerationRequest =
                new PawnGenerationRequest(PawnKindDefOf.SpaceRefugee, faction, PawnGenerationContext.NonPlayer, -1, true, false, false, false, true, false, 1f, true, true, true, false, false, false, false, false, 0f,
                                          null, 1f, null, null, null, null, null, null);
            PawnGenerationRequest pawnGenerationRequest2 = new PawnGenerationRequest(PawnKindDefOf.SpaceRefugee, faction, PawnGenerationContext.NonPlayer, -1, true, false, false, false, true, false, 1f, true, true, true, false, false, false, false, false, 0f,
                                                                                     null, 1f, null, null, null, null, null, null);
            PawnGenerationRequest pawnGenerationRequest3 = new PawnGenerationRequest(PawnKindDefOf.SpaceRefugee, faction, PawnGenerationContext.NonPlayer, -1, true, false, false, false, true, false, 1f, true, true, true, false, false, false, false, false, 0f,
                                                                                     null, 1f, null, null, null, null, null, null);
            Pawn pawn  = PawnGenerator.GeneratePawn(pawnGenerationRequest);
            Pawn pawn2 = PawnGenerator.GeneratePawn(pawnGenerationRequest2);
            Pawn pawn3 = PawnGenerator.GeneratePawn(pawnGenerationRequest3);

            HealthUtility.DamageUntilDowned(pawn);
            HealthUtility.DamageUntilDead(pawn2);
            HealthUtility.DamageUntilDowned(pawn3);
            DropPodUtility.MakeDropPodAt(intVec, map, new ActiveDropPodInfo
            {
                SingleContainedThing = pawn,
                openDelay            = 180,
                leaveSlag            = true
            });
            DropPodUtility.MakeDropPodAt(intVec, map, new ActiveDropPodInfo
            {
                SingleContainedThing = pawn2,
                openDelay            = 180,
                leaveSlag            = true
            });
            DropPodUtility.DropThingsNear(intVec, map, list, 110, false, true, true);
            Find.LetterStack.ReceiveLetter("MO_CargoRain".Translate(), "MO_CargoRainDesc".Translate(), LetterDefOf.PositiveEvent, new TargetInfo(intVec, map, false), null);             //"A chunk of your crashed ship fell into the atmosphere, watch out for falling cargo and rescue pods.\n\nIt looks like this chunk came from one of the richer parts of the ship."
            return(true);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            const float baseFishingDuration    = 1600f;
            const float catchSuccessRateOnPier = 0.90f;
            const float skillGainPerTick       = 0.15f;

            int fishingDuration = (int)baseFishingDuration;
            Building_FishingPier fishingPier = this.TargetThingA as Building_FishingPier;
            int thrownCornCount   = 0;
            int nextCornThrowTick = 0;

            this.FailOnBurningImmobile(fishingPierIndex);

            // Drawing.
            this.rotateToFace = TargetIndex.B;
            this.pawn.CurJob.SetTarget(TargetIndex.C, fishingPier.riverCell);
            TargetIndex riverCellIndex = TargetIndex.C;

            // Compute fishing duration.
            float fishingSkillLevel = 0f;

            fishingSkillLevel = this.pawn.skills.AverageOfRelevantSkillsFor(WorkTypeDefOf.Hunting);
            float fishingSkillDurationFactor = fishingSkillLevel / 20f;

            fishingDuration = (int)(baseFishingDuration * (1.5f - fishingSkillDurationFactor));

            yield return(Toils_Goto.GotoThing(fishingPierIndex, fishingPier.riverCell).FailOn(FishingForbiddenOrPierDestroyedOrNoFish));

            Toil attractfishesToil = new Toil()
            {
                tickAction = () =>
                {
                    if (fishingPier.allowUsingGrain == false)
                    {
                        this.ReadyForNextToil();
                        return;
                    }
                    if (Find.TickManager.TicksGame >= nextCornThrowTick)
                    {
                        nextCornThrowTick = Find.TickManager.TicksGame + 3 * GenTicks.TicksPerRealSecond;
                        // Look for corn in inventory.
                        Thing corn = null;
                        foreach (Thing thing in this.pawn.inventory.innerContainer)
                        {
                            if (thing.def == Util_FishIndustry.RawCornDef)
                            {
                                corn = thing;
                                break;
                            }
                        }
                        if ((corn == null) ||
                            (thrownCornCount >= grainCountToAttractFishes))
                        {
                            fishingDuration -= Mathf.CeilToInt((float)fishingDuration * 0.75f * ((float)thrownCornCount / (float)grainCountToAttractFishes));
                            this.ReadyForNextToil();
                            return;
                        }
                        // Throw corn grains.
                        thrownCornCount++;
                        this.pawn.inventory.innerContainer.Take(corn, 1);
                        for (int cornGrainIndex = 0; cornGrainIndex < 5; cornGrainIndex++)
                        {
                            if (!this.pawn.Position.ShouldSpawnMotesAt(this.pawn.Map) || this.pawn.Map.moteCounter.Saturated)
                            {
                                break;
                            }
                            float   speed          = Rand.Range(1.5f, 3f);
                            Vector3 targetPosition = this.pawn.Position.ToVector3Shifted() + new Vector3(0f, 0f, 2f).RotatedBy(fishingPier.Rotation.AsAngle) + Vector3Utility.RandomHorizontalOffset(1.5f);
                            targetPosition.y = this.pawn.DrawPos.y;
                            MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(ThingDefOf.Mote_Stone, null);
                            moteThrown.Scale         = 0.2f;
                            moteThrown.rotationRate  = (float)Rand.Range(-300, 300);
                            moteThrown.exactPosition = this.pawn.DrawPos;
                            moteThrown.SetVelocity((targetPosition - moteThrown.exactPosition).AngleFlat(), speed);
                            moteThrown.airTimeLeft = (float)Mathf.RoundToInt((moteThrown.exactPosition - targetPosition).MagnitudeHorizontal() / speed);
                            GenSpawn.Spawn(moteThrown, this.pawn.Position, this.pawn.Map);
                            MoteMaker.MakeWaterSplash(targetPosition, this.pawn.Map, 1.8f, 0.5f);
                        }
                    }
                },
                defaultDuration     = fishingDuration,
                defaultCompleteMode = ToilCompleteMode.Delay
            };

            yield return(attractfishesToil.FailOn(FishingForbiddenOrPierDestroyedOrNoFish));

            Toil fishToil = new Toil()
            {
                initAction = () =>
                {
                    ThingDef moteDef = null;
                    if (fishingPier.Rotation == Rot4.North)
                    {
                        moteDef = Util_FishIndustry.MoteFishingRodNorthDef;
                    }
                    else if (fishingPier.Rotation == Rot4.East)
                    {
                        moteDef = Util_FishIndustry.MoteFishingRodEastDef;
                    }
                    else if (fishingPier.Rotation == Rot4.South)
                    {
                        moteDef = Util_FishIndustry.MoteFishingRodSouthDef;
                    }
                    else
                    {
                        moteDef = Util_FishIndustry.MoteFishingRodWestDef;
                    }
                    this.fishingRodMote = (Mote)ThingMaker.MakeThing(moteDef, null);
                    this.fishingRodMote.exactPosition = fishingPier.fishingSpotCell.ToVector3Shifted();
                    this.fishingRodMote.Scale         = 1f;
                    GenSpawn.Spawn(this.fishingRodMote, fishingPier.fishingSpotCell, this.Map);
                },
                tickAction = () =>
                {
                    this.pawn.skills.Learn(SkillDefOf.Shooting, skillGainPerTick);

                    if (this.fishingRodMote != null)
                    {
                        this.fishingRodMote.Maintain();
                    }
                },
                defaultDuration     = fishingDuration,
                defaultCompleteMode = ToilCompleteMode.Delay
            };

            yield return(fishToil.WithProgressBarToilDelay(riverCellIndex).FailOn(FishingForbiddenOrPierDestroyedOrNoFish));

            Toil catchFishToil = new Toil()
            {
                initAction = () =>
                {
                    Thing fishingCatch = null;

                    bool catchIsSuccessful = (Rand.Value <= catchSuccessRateOnPier);
                    if (catchIsSuccessful == false)
                    {
                        MoteMaker.ThrowMetaIcon(this.pawn.Position, this.Map, ThingDefOf.Mote_IncapIcon);
                        this.pawn.jobs.EndCurrentJob(JobCondition.Incompletable);
                        return;
                    }

                    float catchSelectorValue = Rand.Value;

                    if (catchSelectorValue < 0.02)
                    {
                        float bonusCatchValue = Rand.Value;
                        if (bonusCatchValue < 0.01f)
                        {
                            // Really small chance to find a sunken treasure!!!
                            fishingCatch            = GenSpawn.Spawn(ThingDefOf.Gold, this.pawn.Position, this.Map);
                            fishingCatch.stackCount = Rand.RangeInclusive(58, 289);
                            Thing treasureSilver = GenSpawn.Spawn(ThingDefOf.Silver, fishingPier.middleCell, this.Map);
                            treasureSilver.stackCount = Rand.RangeInclusive(237, 2154);
                            Find.LetterStack.ReceiveLetter("FishIndustry.LetterLabelSunkenTreasure".Translate(), "FishIndustry.SunkenTreasure".Translate(this.pawn.Name.ToStringShort.CapitalizeFirst()),
                                                           LetterDefOf.PositiveEvent, this.pawn);
                        }
                        else if (bonusCatchValue < 0.02f)
                        {
                            // Really small chance to find a complete power armor set + sniper or charge rifle.
                            Thing powerArmor = GenSpawn.Spawn(ThingDef.Named("Apparel_PowerArmor"), this.pawn.Position, this.Map);
                            fishingCatch = powerArmor; // Used to carry the power armor.
                            Thing powerArmorHelmet = GenSpawn.Spawn(ThingDef.Named("Apparel_PowerArmorHelmet"), this.pawn.Position, this.Map);
                            Thing rifle            = null;
                            if (Rand.Value < 0.5f)
                            {
                                rifle = GenSpawn.Spawn(ThingDef.Named("Gun_ChargeRifle"), this.pawn.Position, this.Map);
                            }
                            else
                            {
                                rifle = GenSpawn.Spawn(ThingDef.Named("Gun_SniperRifle"), this.pawn.Position, this.Map);
                            }
                            CompQuality qualityComp = powerArmor.TryGetComp <CompQuality>();
                            if (qualityComp != null)
                            {
                                qualityComp.SetQuality(QualityCategory.Masterwork, ArtGenerationContext.Outsider);
                            }
                            qualityComp = powerArmorHelmet.TryGetComp <CompQuality>();
                            if (qualityComp != null)
                            {
                                qualityComp.SetQuality(QualityCategory.Masterwork, ArtGenerationContext.Outsider);
                            }
                            qualityComp = rifle.TryGetComp <CompQuality>();
                            if (qualityComp != null)
                            {
                                qualityComp.SetQuality(QualityCategory.Masterwork, ArtGenerationContext.Outsider);
                            }

                            Faction faction    = Find.FactionManager.FirstFactionOfDef(FactionDefOf.AncientsHostile);
                            Pawn    deadMarine = PawnGenerator.GeneratePawn(PawnKindDefOf.AncientSoldier, faction);
                            HealthUtility.DamageUntilDead(deadMarine);
                            Corpse       corpse  = deadMarine.ParentHolder as Corpse;
                            CompRottable rotComp = corpse.TryGetComp <CompRottable>();
                            if (rotComp != null)
                            {
                                rotComp.RotProgress = 20f * GenDate.TicksPerDay; // 20 days so the corpse is dessicated.
                            }
                            GenSpawn.Spawn(corpse, fishingPier.bankCell, this.Map);
                            string eventText = "FishIndustry.LetterDescDeadMarine".Translate(this.pawn.Name.ToStringShort.CapitalizeFirst());
                            Find.LetterStack.ReceiveLetter("FishIndustry.LetterLabelDeadMarine".Translate(), eventText, LetterDefOf.PositiveEvent, this.pawn);
                        }
                        else
                        {
                            // Find a small amount of gold.
                            fishingCatch            = GenSpawn.Spawn(ThingDefOf.Gold, this.pawn.Position, this.Map);
                            fishingCatch.stackCount = Rand.RangeInclusive(1, 7);
                        }
                    }
                    else if (catchSelectorValue < 0.04)
                    {
                        // Find oysters.
                        fishingCatch            = GenSpawn.Spawn(Util_FishIndustry.OysterDef, this.pawn.Position, this.Map);
                        fishingCatch.stackCount = Rand.RangeInclusive(2, 9);
                    }
                    else
                    {
                        // Catch a fish.
                        IntVec3 fishSpot        = fishingPier.aquaticCells.RandomElement();
                        bool    fishSpotIsOcean = (this.Map.terrainGrid.TerrainAt(fishSpot) == TerrainDefOf.WaterOceanShallow) ||
                                                  (this.Map.terrainGrid.TerrainAt(fishSpot) == TerrainDefOf.WaterOceanDeep);
                        bool fishSpotIsMarshy = (this.Map.terrainGrid.TerrainAt(fishSpot) == TerrainDef.Named("Marsh"));

                        PawnKindDef caugthFishDef = null;
                        if (fishSpotIsOcean)
                        {
                            caugthFishDef = (from fishSpecies in Util_FishIndustry.GetFishSpeciesList(this.Map.Biome)
                                             where fishSpecies.livesInOcean
                                             select fishSpecies).RandomElementByWeight((PawnKindDef_FishSpecies def) => def.commonality);
                        }
                        else if (fishSpotIsMarshy)
                        {
                            caugthFishDef = (from fishSpecies in Util_FishIndustry.GetFishSpeciesList(this.Map.Biome)
                                             where fishSpecies.livesInMarsh
                                             select fishSpecies).RandomElementByWeight((PawnKindDef_FishSpecies def) => def.commonality);
                        }
                        else
                        {
                            caugthFishDef = (from fishSpecies in Util_FishIndustry.GetFishSpeciesList(this.Map.Biome)
                                             where fishSpecies.livesInRiver
                                             select fishSpecies).RandomElementByWeight((PawnKindDef_FishSpecies def) => def.commonality);
                        }
                        Pawn caughtFish = PawnGenerator.GeneratePawn(caugthFishDef);
                        ExecutionUtility.DoExecutionByCut(this.pawn, caughtFish);
                        Corpse corpse = caughtFish.ParentHolder as Corpse;
                        GenSpawn.Spawn(corpse, this.pawn.Position, this.Map);
                        fishingCatch = corpse;
                        fishingCatch.SetForbidden(false);
                        if (caughtFish.BodySize >= 0.1f)
                        {
                            fishingPier.fishStock--;
                        }
                    }
                    IntVec3 storageCell;
                    if (StoreUtility.TryFindBestBetterStoreCellFor(fishingCatch, this.pawn, this.Map, StoragePriority.Unstored, this.pawn.Faction, out storageCell, true))
                    {
                        this.pawn.Reserve(fishingCatch, this.job);
                        this.pawn.Reserve(storageCell, this.job);
                        this.pawn.CurJob.SetTarget(TargetIndex.B, storageCell);
                        this.pawn.CurJob.SetTarget(TargetIndex.A, fishingCatch);
                        this.pawn.CurJob.count    = 9999;
                        this.pawn.CurJob.haulMode = HaulMode.ToCellStorage;
                    }
                    else
                    {
                        this.pawn.jobs.EndCurrentJob(JobCondition.Succeeded);
                    }
                }
            };

            yield return(catchFishToil);

            yield return(Toils_Haul.StartCarryThing(TargetIndex.A));

            Toil carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.B);

            yield return(carryToCell);

            yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.B, carryToCell, true));
        }
            public static bool Replacement(IncidentParms parms, ref bool __result)
            {
                Map     map = (Map)parms.target;
                IntVec3 spawnSpot;

                if (!CellFinder.TryFindRandomEdgeCellWith(c => map.reachability.CanReachColony(c), map, CellFinder.EdgeRoadChance_Neutral, out spawnSpot))
                {
                    __result = false;
                    return(false);
                }

                #region CHANGED

                Pawn refugee = Rand.Value < 0.7f ? GenericUtility.GetAnyRelatedWorldPawn(_selector, 100) : null;
                if (refugee == null)
                {
                    // Just ANYONE
                    Find.WorldPawns.AllPawnsAlive.Where(_selector).TryRandomElement(out refugee);
                }
                if (refugee == null)
                {
                    __result = false;
                    return(false);
                }

                #endregion

                refugee.relations.everSeenByPlayer = true;
                Faction enemyFac;
                if (!(from f in Find.FactionManager.AllFactions
                      where !f.def.hidden && f.HostileTo(Faction.OfPlayer)
                      select f).TryRandomElement(out enemyFac))
                {
                    __result = false;
                    return(false);
                }
                string text = "RefugeeChasedInitial".Translate(new object[]
                {
                    refugee.Name.ToStringFull,
                    refugee.story.Title.ToLower(),
                    enemyFac.def.pawnsPlural,
                    enemyFac.Name,
                    refugee.ageTracker.AgeBiologicalYears
                });
                text = text.AdjustedFor(refugee);
                PawnRelationUtility.TryAppendRelationsWithColonistsInfo(ref text, refugee);
                DiaNode   diaNode   = new DiaNode(text);
                DiaOption diaOption = new DiaOption("RefugeeChasedInitial_Accept".Translate());
                diaOption.action = delegate
                {
                    GenSpawn.Spawn(refugee, spawnSpot, map);
                    refugee.SetFaction(Faction.OfPlayer, null);
                    CameraJumper.TryJump(refugee);
                    IncidentParms incidentParms = StorytellerUtility.DefaultParmsNow(Find.Storyteller.def, IncidentCategory.ThreatBig, map);
                    incidentParms.forced          = true;
                    incidentParms.faction         = enemyFac;
                    incidentParms.raidStrategy    = RaidStrategyDefOf.ImmediateAttack;
                    incidentParms.raidArrivalMode = PawnsArriveMode.EdgeWalkIn;
                    incidentParms.spawnCenter     = spawnSpot;
                    incidentParms.points         *= RaidPointsFactor;
                    QueuedIncident qi = new QueuedIncident(new FiringIncident(IncidentDefOf.RaidEnemy, null, incidentParms), Find.TickManager.TicksGame + RaidDelay.RandomInRange);
                    Find.Storyteller.incidentQueue.Add(qi);
                };
                diaOption.resolveTree = true;
                diaNode.options.Add(diaOption);
                string text2 = "RefugeeChasedRejected".Translate(new object[]
                {
                    refugee.NameStringShort
                });
                DiaNode   diaNode2   = new DiaNode(text2);
                DiaOption diaOption2 = new DiaOption("OK".Translate());
                diaOption2.resolveTree = true;
                diaNode2.options.Add(diaOption2);
                DiaOption diaOption3 = new DiaOption("RefugeeChasedInitial_Reject".Translate());
                diaOption3.action = delegate
                {
                    #region CHANGED

                    HealthUtility.DamageUntilDead(refugee);
                    //Log.Message(refugee.Name + " dead? " + refugee.Dead);
                    //Find.WorldPawns.PassToWorld(refugee,PawnDiscardDecideMode.Discard);

                    #endregion
                };
                diaOption3.link = diaNode2;
                diaNode.options.Add(diaOption3);
                string title = "RefugeeChasedTitle".Translate(new object[]
                {
                    map.info.parent.Label
                });
                Find.WindowStack.Add(new Dialog_NodeTree(diaNode, true, true, title));
                __result = true;
                return(false);
            }
Exemple #16
0
        private void AddPsionicShock(Pawn pawn)
        {
            System.Random rand = new System.Random();

            int  psychicSensitivity    = 0;
            bool?shouldGiveHeartAttack = null;
            bool?shouldSedate          = null;

            if (pawn.story?.traits != null && pawn.story.traits.HasTrait(TraitDef.Named("PsychicSensitivity")))
            {
                Trait psychicSensitivityTrait = pawn.story.traits.GetTrait(TraitDef.Named("PsychicSensitivity"));
                psychicSensitivity = psychicSensitivityTrait.Degree;
            }

            // If they're Psychically Deaf, do nothing:
            if (psychicSensitivity == -2)
            {
                return;
            }
            // If they're Psychically Dull, don't give them a heart attack.
            else if (psychicSensitivity == -1)
            {
                shouldGiveHeartAttack = false;
            }
            // If they're Psychically Sensitive, make sure they're passed out for a few hours.
            else if (psychicSensitivity == 1)
            {
                shouldSedate = true;
            }
            // If they're Psychically Hypersensitive, unfortunately, it will mean instant death :-(
            else if (psychicSensitivity >= 2)
            {
                if (pawn.IsColonist)
                {
                    Messages.Message(pawn.Name.ToStringShort + " was psychically supersensitive and died because of the psionic blast.", MessageTypeDefOf.ThreatSmall);
                }

                HealthUtility.DamageUntilDead(pawn);
            }

            Hediff shock = HediffMaker.MakeHediff(HediffDefOf.PsychicShock, pawn, null);

            pawn.health.AddHediff(shock, null, null);

            if (shouldGiveHeartAttack == null)
            {
                shouldGiveHeartAttack = rand.Next(1, 11) >= 3;
            }

            if (shouldGiveHeartAttack == true)
            {
                this.CauseHeartAttack(pawn);
            }

            if (shouldSedate == null)
            {
                int likelihood = rand.Next(1, 11);
                if (pawn.Name?.ToStringShort != null)
                {
                    Log.Message(pawn.Name.ToStringShort + " should sedate? " + likelihood);
                }
                else
                {
                    Log.Message(pawn.def.label + " should sedate? " + likelihood);
                }

                shouldSedate = likelihood >= 6;
            }

            if (shouldSedate == true)
            {
                this.CauseSedation(pawn);
            }

            DamageInfo psionicIntensity = new DamageInfo(DamageDefOf.Stun, 50);

            pawn.TakeDamage(psionicIntensity);
        }
Exemple #17
0
        public static void ApplyState(Thing thing, AttackThingState state, bool pawnHealthStateDead = false)
        {
            //полезное из игры: RecoverFromUnwalkablePositionOrKill
            if (state.StackCount > 0 && thing.stackCount != state.StackCount)
            {
                Loger.Log("Client ApplyState Set StackCount " + thing.stackCount.ToString() + " -> " + state.StackCount.ToString());
                thing.stackCount = state.StackCount;
            }

            if (thing.Position.x != state.Position.x || thing.Position.z != state.Position.z)
            {
                thing.Position = state.Position.Get();
                if (thing is Pawn)
                {
                    var pawn = (Pawn)thing;
                    try
                    {
                        pawn.Notify_Teleported(true, true);
                    }
                    catch (Exception ext)
                    {
                        Loger.Log("Client ApplyState Exception " + ext.ToString());
                    }
                    pawn.Drawer.DrawTrackerTick();
                }
            }

            if (thing is Fire)
            {
                (thing as Fire).fireSize = (float)state.HitPoints / 10000f;
            }
            else
            {
                if (thing.def.useHitPoints)
                {
                    Loger.Log("Client ApplyState Set HitPoints " + thing.HitPoints.ToString() + " -> " + state.HitPoints.ToString());
                    thing.HitPoints = state.HitPoints;
                }
            }

            if (thing is Pawn)
            {
                var pawn = thing as Pawn;
                if ((int)pawn.health.State != (int)state.DownState)
                {
                    if (pawn.health.State == PawnHealthState.Dead)
                    {
                        Loger.Log("Client ApplyState Set pawn state is Dead! Error to change on " + state.DownState.ToString());
                    }
                    else if (state.DownState == AttackThingState.PawnHealthState.Dead)
                    {
                        if (pawnHealthStateDead)
                        {
                            Loger.Log("Client ApplyState Set pawn state (1): " + pawn.health.State.ToString() + " -> " + state.DownState.ToString());
                            HealthUtility.DamageUntilDead(pawn);
                            //PawnKill(pawn);
                        }
                    }
                    else if (state.DownState == AttackThingState.PawnHealthState.Down)
                    {
                        Loger.Log("Client ApplyState Set pawn state (2): " + pawn.health.State.ToString() + " -> " + state.DownState.ToString());
                        //todo! Применяем наркоз?
                        HealthUtility.DamageUntilDowned(pawn, false);
                    }
                    else
                    {
                        Loger.Log("Client ApplyState Set pawn state (3): " + pawn.health.State.ToString() + " -> " + state.DownState.ToString());
                        //полное лечение
                        pawn.health.Notify_Resurrected();
                    }
                }
            }
        }
Exemple #18
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            const float baseFishingDuration = 2000f;

            int   fishingDuration            = (int)baseFishingDuration;
            float catchSomethingThreshold    = 0f;
            Building_FishingPier fishingPier = this.TargetThingA as Building_FishingPier;
            Passion     passion          = Passion.None;
            const float skillGainPerTick = 0.15f;

            this.AddEndCondition(() =>
            {
                var targ = this.pawn.jobs.curJob.GetTarget(fishingPierIndex).Thing;
                if (targ is Building && !targ.Spawned)
                {
                    return(JobCondition.Incompletable);
                }
                return(JobCondition.Ongoing);
            });

            this.FailOnBurningImmobile(fishingPierIndex); // Bill giver or product burning in carry phase.

            this.rotateToFace = TargetIndex.B;

            yield return(Toils_Reserve.Reserve(fishingPierIndex));

            float fishingSkillLevel = 0f;

            fishingSkillLevel = this.pawn.skills.AverageOfRelevantSkillsFor(WorkTypeDefOf.Hunting);
            float fishingSkillDurationFactor = fishingSkillLevel / 20f;

            fishingDuration = (int)(baseFishingDuration * (1.5f - fishingSkillDurationFactor));

            yield return(Toils_Goto.GotoThing(fishingPierIndex, fishingPier.riverCell).FailOnDespawnedOrNull(fishingPierIndex));

            Toil fishToil = new Toil()
            {
                initAction = () =>
                {
                    ThingDef moteDef = null;
                    if (fishingPier.Rotation == Rot4.North)
                    {
                        moteDef = Util_FishIndustry.MoteFishingRodNorthDef;
                    }
                    else if (fishingPier.Rotation == Rot4.East)
                    {
                        moteDef = Util_FishIndustry.MoteFishingRodEastDef;
                    }
                    else if (fishingPier.Rotation == Rot4.South)
                    {
                        moteDef = Util_FishIndustry.MoteFishingRodSouthDef;
                    }
                    else
                    {
                        moteDef = Util_FishIndustry.MoteFishingRodWestDef;
                    }
                    this.fishingRodMote = (Mote)ThingMaker.MakeThing(moteDef, null);
                    this.fishingRodMote.exactPosition = fishingPier.fishingSpotCell.ToVector3Shifted();
                    this.fishingRodMote.Scale         = 1f;
                    GenSpawn.Spawn(this.fishingRodMote, fishingPier.fishingSpotCell, this.Map);
                },
                tickAction = () =>
                {
                    if (passion == Passion.Minor)
                    {
                        this.pawn.needs.joy.GainJoy(NeedTunings.JoyPerXpForPassionMinor, JoyKindDefOf.Work);
                    }
                    else if (passion == Passion.Major)
                    {
                        this.pawn.needs.joy.GainJoy(NeedTunings.JoyPerXpForPassionMajor, JoyKindDefOf.Work);
                    }
                    this.pawn.skills.Learn(SkillDefOf.Shooting, skillGainPerTick);

                    if (this.ticksLeftThisToil == 1)
                    {
                        if (this.fishingRodMote != null)
                        {
                            this.fishingRodMote.Destroy();
                        }
                    }
                },
                defaultDuration     = fishingDuration,
                defaultCompleteMode = ToilCompleteMode.Delay
            };

            yield return(fishToil.WithProgressBarToilDelay(fishingPierIndex));

            Toil computeChanceToCatchToil = new Toil()
            {
                initAction = () =>
                {
                    catchSomethingThreshold = fishingSkillLevel / 20f;
                    // Reframe min and max chance (min 5%, max 75 % chance of success).
                    Mathf.Clamp(catchSomethingThreshold, 0.05f, 0.75f);
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            };

            yield return(computeChanceToCatchToil);

            Toil catchFishToil = new Toil()
            {
                initAction = () =>
                {
                    Job   curJob       = this.pawn.jobs.curJob;
                    Thing fishingCatch = null;

                    // 90% chance to successfully catch something.
                    bool catchIsSuccessful = (Rand.Value >= 0.1f);
                    if (catchIsSuccessful == false)
                    {
                        MoteMaker.ThrowMetaIcon(this.pawn.Position, this.Map, ThingDefOf.Mote_IncapIcon);
                        this.pawn.jobs.EndCurrentJob(JobCondition.Incompletable);
                        return;
                    }

                    float catchSelectorValue = Rand.Value;
                    if (catchSelectorValue > 0.04f)
                    {
                        // Catch a fish.
                        bool fishSpotIsOcean = (this.Map.terrainGrid.TerrainAt(fishingPier.fishingSpotCell) == TerrainDefOf.WaterOceanShallow) ||
                                               (this.Map.terrainGrid.TerrainAt(fishingPier.fishingSpotCell) == TerrainDefOf.WaterOceanDeep);
                        bool fishSpotIsMarshy = (this.Map.terrainGrid.TerrainAt(fishingPier.fishingSpotCell) == TerrainDef.Named("Marsh"));

                        PawnKindDef caugthFishDef = null;
                        if (fishSpotIsOcean)
                        {
                            caugthFishDef = (from fishSpecies in Util_FishIndustry.GetFishSpeciesList(this.Map.Biome)
                                             where fishSpecies.livesInOcean
                                             select fishSpecies).RandomElementByWeight((PawnKindDef_FishSpecies def) => def.commonality);
                        }
                        else if (fishSpotIsMarshy)
                        {
                            caugthFishDef = (from fishSpecies in Util_FishIndustry.GetFishSpeciesList(this.Map.Biome)
                                             where fishSpecies.livesInMarsh
                                             select fishSpecies).RandomElementByWeight((PawnKindDef_FishSpecies def) => def.commonality);
                        }
                        else
                        {
                            caugthFishDef = (from fishSpecies in Util_FishIndustry.GetFishSpeciesList(this.Map.Biome)
                                             where fishSpecies.livesInRiver
                                             select fishSpecies).RandomElementByWeight((PawnKindDef_FishSpecies def) => def.commonality);
                        }
                        Pawn caughtFish = PawnGenerator.GeneratePawn(caugthFishDef);
                        GenSpawn.Spawn(caughtFish, this.pawn.Position, this.Map);
                        HealthUtility.DamageUntilDead(caughtFish);
                        foreach (Thing thing in this.pawn.Position.GetThingList(this.Map))
                        {
                            Corpse fishCorpse = thing as Corpse;
                            if (fishCorpse != null)
                            {
                                fishingCatch = fishCorpse;
                                fishingCatch.SetForbidden(false);
                            }
                        }
                        if (caughtFish.BodySize >= 0.1f)
                        {
                            fishingPier.fishStock--;
                            fishingPier.ComputeMaxFishStockAndRespawnPeriod();
                        }
                    }
                    else if (catchSelectorValue > 0.02)
                    {
                        fishingCatch            = GenSpawn.Spawn(Util_FishIndustry.OysterDef, this.pawn.Position, this.Map);
                        fishingCatch.stackCount = Rand.RangeInclusive(5, 27);
                    }
                    else
                    {
                        float bonusCatchValue = Rand.Value;
                        if (bonusCatchValue < 0.01f)
                        {
                            // Really small chance to find a sunken treasure!!!
                            fishingCatch            = GenSpawn.Spawn(ThingDefOf.Gold, this.pawn.Position, this.Map);
                            fishingCatch.stackCount = Rand.RangeInclusive(58, 289);
                            Thing treasureSilver = GenSpawn.Spawn(ThingDefOf.Silver, fishingPier.middleCell, this.Map);
                            treasureSilver.stackCount = Rand.RangeInclusive(237, 2154);
                            Find.LetterStack.ReceiveLetter("FishIndustry.LetterLabelSunkenTreasure".Translate(), "FishIndustry.SunkenTreasure".Translate(this.pawn.Name.ToStringShort.CapitalizeFirst()),
                                                           LetterDefOf.Good, this.pawn);
                        }
                        else if (bonusCatchValue < 0.02f)
                        {
                            // Really small chance to find a complete power armor set + sniper or charge rifle.
                            Thing powerArmor = GenSpawn.Spawn(ThingDef.Named("Apparel_PowerArmor"), this.pawn.Position, this.Map);
                            fishingCatch = powerArmor; // Used to carry the power armor.
                            Thing powerArmorHelmet = GenSpawn.Spawn(ThingDef.Named("Apparel_PowerArmorHelmet"), this.pawn.Position, this.Map);
                            Thing rifle            = null;
                            if (Rand.Value < 0.5f)
                            {
                                rifle = GenSpawn.Spawn(ThingDef.Named("Gun_ChargeRifle"), this.pawn.Position, this.Map);
                            }
                            else
                            {
                                rifle = GenSpawn.Spawn(ThingDef.Named("Gun_SniperRifle"), this.pawn.Position, this.Map);
                            }
                            CompQuality qualityComp = powerArmor.TryGetComp <CompQuality>();
                            if (qualityComp != null)
                            {
                                qualityComp.SetQuality(QualityCategory.Masterwork, ArtGenerationContext.Outsider);
                            }
                            qualityComp = powerArmorHelmet.TryGetComp <CompQuality>();
                            if (qualityComp != null)
                            {
                                qualityComp.SetQuality(QualityCategory.Masterwork, ArtGenerationContext.Outsider);
                            }
                            qualityComp = rifle.TryGetComp <CompQuality>();
                            if (qualityComp != null)
                            {
                                qualityComp.SetQuality(QualityCategory.Masterwork, ArtGenerationContext.Outsider);
                            }

                            Faction faction    = Find.FactionManager.FirstFactionOfDef(FactionDefOf.SpacerHostile);
                            Pawn    deadMarine = PawnGenerator.GeneratePawn(PawnKindDefOf.SpaceSoldier, faction);
                            GenSpawn.Spawn(deadMarine, fishingPier.bankCell, this.Map);
                            HealthUtility.DamageUntilDead(deadMarine);
                            List <Thing> thingsList = deadMarine.Position.GetThingList(this.Map);
                            foreach (Thing thing in thingsList)
                            {
                                if (thing.def.defName.Contains("Corpse"))
                                {
                                    CompRottable rotComp = thing.TryGetComp <CompRottable>();
                                    if (rotComp != null)
                                    {
                                        rotComp.RotProgress = 20f * GenDate.TicksPerDay; // 20 days so the corpse is dessicated.
                                    }
                                }
                            }
                            string eventText = this.pawn.Name.ToStringShort.CapitalizeFirst() + " has cought a dead body while fishing!\n\n'This is really disgusting but look at his gear! This guy was probably a MiningCo. security member. I wonder what happend to him...'\n";
                            Find.LetterStack.ReceiveLetter("Dead marine", eventText, LetterDefOf.Good, this.pawn);
                        }
                        else
                        {
                            // Find a small amount of gold.
                            fishingCatch            = GenSpawn.Spawn(ThingDefOf.Gold, this.pawn.Position, this.Map);
                            fishingCatch.stackCount = Rand.RangeInclusive(1, 7);
                        }
                        // TODO: add chance to get hurt by a tailteeth (missing finger or even hand!).
                    }
                    IntVec3 storageCell;
                    if (StoreUtility.TryFindBestBetterStoreCellFor(fishingCatch, this.pawn, this.Map, StoragePriority.Unstored, this.pawn.Faction, out storageCell, true))
                    {
                        this.pawn.Reserve(fishingCatch, 1);
                        this.pawn.Reserve(storageCell, 1);
                        this.pawn.CurJob.SetTarget(TargetIndex.B, storageCell);
                        this.pawn.CurJob.SetTarget(TargetIndex.A, fishingCatch);
                        this.pawn.CurJob.count    = 1;
                        this.pawn.CurJob.haulMode = HaulMode.ToCellStorage;
                    }
                    else
                    {
                        this.pawn.jobs.EndCurrentJob(JobCondition.Succeeded);
                    }
                }
            };

            yield return(catchFishToil);

            yield return(Toils_Haul.StartCarryThing(TargetIndex.A));

            Toil carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.B);

            yield return(carryToCell);

            yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.B, carryToCell, true));

            yield return(Toils_Reserve.Release(fishingPierIndex));
        }