private bool TryFindMortarSpawnCell(CellRect rect, Rot4 rot, ThingDef mortarDef, out IntVec3 cell)
        {
            Map map = BaseGen.globalSettings.map;
            Predicate <CellRect> edgeTouchCheck;

            if (rot == Rot4.North)
            {
                edgeTouchCheck = ((CellRect x) => x.Cells.Any((IntVec3 y) => y.z == rect.maxZ));
            }
            else if (rot == Rot4.South)
            {
                edgeTouchCheck = ((CellRect x) => x.Cells.Any((IntVec3 y) => y.z == rect.minZ));
            }
            else if (rot == Rot4.West)
            {
                edgeTouchCheck = ((CellRect x) => x.Cells.Any((IntVec3 y) => y.x == rect.minX));
            }
            else
            {
                edgeTouchCheck = ((CellRect x) => x.Cells.Any((IntVec3 y) => y.x == rect.maxX));
            }
            return(CellFinder.TryFindRandomCellInsideWith(rect, delegate(IntVec3 x)
            {
                CellRect obj = GenAdj.OccupiedRect(x, rot, mortarDef.size);
                return ThingUtility.InteractionCellWhenAt(mortarDef, x, rot, map).Standable(map) && obj.FullyContainedWithin(rect) && edgeTouchCheck(obj);
            }, out cell));
        }
Example #2
0
        private static int RandomRequestCount(ThingDef thingDef, Map map)
        {
            float num = (float)BaseValueWantedRange.RandomInRange;

            num *= ValueWantedFactorFromWealthCurve.Evaluate(map.wealthWatcher.WealthTotal);
            return(ThingUtility.RoundedResourceStackCount(Mathf.Max(1, Mathf.RoundToInt(num / thingDef.BaseMarketValue))));
        }
        public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null)
        {
            var def = checkingDef as ThingDef;

            if (def == null)
            {
                return(false);
            }

            bool cond_building = false;
            var  terrainLoc    = map.terrainGrid.TerrainAt(loc);

            if (terrainLoc.IsIce())
            {
                cond_building = true;
            }

            bool cond_interaction = true;

            if (def.hasInteractionCell)
            {
                var terrainInteraction = map.terrainGrid.TerrainAt(ThingUtility.InteractionCellWhenAt(def, loc, rot, map));
                if (terrainInteraction.passability != Traversability.Standable)
                {
                    cond_interaction = false;
                }
            }

            return(cond_building && cond_interaction);
        }
Example #4
0
        public override void Resolve(ResolveParams rp)
        {
            Map     map = BaseGen.globalSettings.map;
            Faction faction;

            if ((faction = rp.faction) == null)
            {
                faction = (Find.FactionManager.RandomEnemyFaction(false, false, true, TechLevel.Industrial) ?? Find.FactionManager.RandomEnemyFaction(false, false, true, TechLevel.Undefined));
            }
            Faction  faction2 = faction;
            Rot4?    thingRot = rp.thingRot;
            Rot4     rot      = (thingRot == null) ? Rot4.Random : thingRot.Value;
            ThingDef thingDef;

            if ((thingDef = rp.mortarDef) == null)
            {
                thingDef = (from x in DefDatabase <ThingDef> .AllDefsListForReading
                            where x.category == ThingCategory.Building && x.building.IsMortar
                            select x).RandomElement <ThingDef>();
            }
            ThingDef thingDef2 = thingDef;
            IntVec3  intVec;

            if (this.TryFindMortarSpawnCell(rp.rect, rot, thingDef2, out intVec))
            {
                if (thingDef2.HasComp(typeof(CompMannable)))
                {
                    IntVec3               c = ThingUtility.InteractionCellWhenAt(thingDef2, intVec, rot, map);
                    Lord                  singlePawnLord = LordMaker.MakeNewLord(faction2, new LordJob_ManTurrets(), map, null);
                    PawnKindDef           kind           = faction2.RandomPawnKind();
                    Faction               faction3       = faction2;
                    int                   tile           = map.Tile;
                    PawnGenerationRequest value          = new PawnGenerationRequest(kind, faction3, PawnGenerationContext.NonPlayer, tile, false, false, false, false, true, true, 1f, false, true, true, true, false, false, false, null, null, null, null, null, null, null, null);
                    ResolveParams         resolveParams  = rp;
                    resolveParams.faction = faction2;
                    resolveParams.singlePawnGenerationRequest = new PawnGenerationRequest?(value);
                    resolveParams.rect           = CellRect.SingleCell(c);
                    resolveParams.singlePawnLord = singlePawnLord;
                    BaseGen.symbolStack.Push("pawn", resolveParams);
                }
                ThingDef  turret    = thingDef2;
                bool      allowEMP  = false;
                TechLevel techLevel = faction2.def.techLevel;
                ThingDef  thingDef3 = TurretGunUtility.TryFindRandomShellDef(turret, allowEMP, true, techLevel, false, 250f);
                if (thingDef3 != null)
                {
                    ResolveParams resolveParams2 = rp;
                    resolveParams2.faction               = faction2;
                    resolveParams2.singleThingDef        = thingDef3;
                    resolveParams2.singleThingStackCount = new int?(Rand.RangeInclusive(5, Mathf.Min(8, thingDef3.stackLimit)));
                    BaseGen.symbolStack.Push("thing", resolveParams2);
                }
                ResolveParams resolveParams3 = rp;
                resolveParams3.faction        = faction2;
                resolveParams3.singleThingDef = thingDef2;
                resolveParams3.rect           = CellRect.SingleCell(intVec);
                resolveParams3.thingRot       = new Rot4?(rot);
                BaseGen.symbolStack.Push("thing", resolveParams3);
            }
        }
Example #5
0
 public static bool IsDerpWeapon(ThingDef thing, ThingDef stuff)
 {
     if (stuff == null)
     {
         return(false);
     }
     if (thing.IsMeleeWeapon)
     {
         if (thing.tools.NullOrEmpty())
         {
             return(false);
         }
         DamageDef damageDef = ThingUtility.PrimaryMeleeWeaponDamageType(thing);
         if (damageDef == null)
         {
             return(false);
         }
         DamageArmorCategoryDef armorCategory = damageDef.armorCategory;
         if (armorCategory != null && armorCategory.multStat != null && stuff.GetStatValueAbstract(armorCategory.multStat) < 0.7f)
         {
             return(true);
         }
     }
     return(false);
 }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map          map    = (Map)parms.target;
            List <Thing> things = ThingSetMakerDefOf.RefugeePod.root.Generate();
            IntVec3      intVec = DropCellFinder.RandomDropSpot(map);
            Pawn         pawn   = ThingUtility.FindPawn(things);

            pawn.guest.getRescuedThoughtOnUndownedBecauseOfPlayer = true;
            TaggedString title = "LetterLabelRefugeePodCrash".Translate();
            TaggedString text  = "RefugeePodCrash".Translate(pawn.Named("PAWN")).AdjustedFor(pawn);

            text += "\n\n";
            if (pawn.Faction == null)
            {
                text += "RefugeePodCrash_Factionless".Translate(pawn.Named("PAWN")).AdjustedFor(pawn);
            }
            else if (pawn.Faction.HostileTo(Faction.OfPlayer))
            {
                text += "RefugeePodCrash_Hostile".Translate(pawn.Named("PAWN")).AdjustedFor(pawn);
            }
            else
            {
                text += "RefugeePodCrash_NonHostile".Translate(pawn.Named("PAWN")).AdjustedFor(pawn);
            }
            PawnRelationUtility.TryAppendRelationsWithColonistsInfo(ref text, ref title, pawn);
            SendStandardLetter(title, text, LetterDefOf.NeutralEvent, parms, new TargetInfo(intVec, map));
            ActiveDropPodInfo activeDropPodInfo = new ActiveDropPodInfo();

            activeDropPodInfo.innerContainer.TryAddRangeOrTransfer(things);
            activeDropPodInfo.openDelay = 180;
            activeDropPodInfo.leaveSlag = true;
            DropPodUtility.MakeDropPodAt(intVec, map, activeDropPodInfo);
            return(true);
        }
Example #7
0
 public void SwitchOffLight()
 {
     if (!ThingUtility.DestroyedOrNull(light))
     {
         light.Destroy(0);
         light = null;
     }
     lightIsOn = false;
 }
        private static int RandomRequestCount(ThingDef thingDef, Map map)
        {
            Rand.PushState(Find.TickManager.TicksGame ^ thingDef.GetHashCode() ^ 0x343820DB);
            float num = BaseValueWantedRange.RandomInRange;

            Rand.PopState();
            num *= ValueWantedFactorFromWealthCurve.Evaluate(map.wealthWatcher.WealthTotal);
            return(ThingUtility.RoundedResourceStackCount(Mathf.Max(1, Mathf.RoundToInt(num / thingDef.BaseMarketValue))));
        }
Example #9
0
        public override void CompTickRare()
        {
            bool spawned = parent.Spawned;
            var  map     = parent.Map;

            base.CompTickRare();
            if (spawned)
            {
                ThingUtility.CheckAutoRebuildOnDestroyed(parent, DestroyMode.KillFinalize, map, parent.def);
            }
        }
Example #10
0
        public override void Destroy(DestroyMode mode = DestroyMode.Vanish)
        {
            bool spawned = base.Spawned;
            Map  map     = base.Map;

            base.Destroy(mode);
            if (spawned)
            {
                ThingUtility.CheckAutoRebuildOnDestroyed(this, mode, map, def.entityDefToBuild);
            }
        }
Example #11
0
        public void SwitchOnLight()
        {
            IntVec3 val = IntVec3Utility.ToIntVec3(this.get_Wearer().get_DrawPos());

            if (!ThingUtility.DestroyedOrNull(light) && val != light.get_Position())
            {
                SwitchOffLight();
            }
            if (ThingUtility.DestroyedOrNull(light) && GridsUtility.GetFirstThing(val, this.get_Wearer().get_Map(), Util_VehicleLights.MiningLightDef) == null)
            {
                light = GenSpawn.Spawn(Util_VehicleLights.VehicleLightDef, val, this.get_Wearer().get_Map(), 0);
            }
            lightIsOn = true;
        }
        public override void Resolve(ResolveParams rp)
        {
            Map      map      = BaseGen.globalSettings.map;
            Faction  faction  = rp.faction ?? Find.FactionManager.RandomEnemyFaction(allowHidden: false, allowDefeated: false, allowNonHumanlike: true, TechLevel.Industrial) ?? Find.FactionManager.RandomEnemyFaction();
            Rot4?    thingRot = rp.thingRot;
            Rot4     rot      = (!thingRot.HasValue) ? Rot4.Random : thingRot.Value;
            ThingDef thingDef = rp.mortarDef ?? (from x in DefDatabase <ThingDef> .AllDefsListForReading
                                                 where x.category == ThingCategory.Building && x.building.IsMortar
                                                 select x).RandomElement();

            if (TryFindMortarSpawnCell(rp.rect, rot, thingDef, out IntVec3 cell))
            {
                if (thingDef.HasComp(typeof(CompMannable)))
                {
                    IntVec3               c = ThingUtility.InteractionCellWhenAt(thingDef, cell, rot, map);
                    Lord                  singlePawnLord = LordMaker.MakeNewLord(faction, new LordJob_ManTurrets(), map);
                    PawnKindDef           kind           = faction.RandomPawnKind();
                    Faction               faction2       = faction;
                    int                   tile           = map.Tile;
                    PawnGenerationRequest value          = new PawnGenerationRequest(kind, faction2, PawnGenerationContext.NonPlayer, tile, forceGenerateNewPawn: false, newborn: false, allowDead: false, allowDowned: false, canGeneratePawnRelations: true, mustBeCapableOfViolence: true, 1f, forceAddFreeWarmLayerIfNeeded: false, allowGay: true, allowFood: true, inhabitant: true);
                    ResolveParams         resolveParams  = rp;
                    resolveParams.faction = faction;
                    resolveParams.singlePawnGenerationRequest = value;
                    resolveParams.rect           = CellRect.SingleCell(c);
                    resolveParams.singlePawnLord = singlePawnLord;
                    BaseGen.symbolStack.Push("pawn", resolveParams);
                }
                ThingDef  turret    = thingDef;
                bool      allowEMP  = false;
                TechLevel techLevel = faction.def.techLevel;
                ThingDef  thingDef2 = TurretGunUtility.TryFindRandomShellDef(turret, allowEMP, mustHarmHealth: true, techLevel, allowAntigrainWarhead: false, 250f);
                if (thingDef2 != null)
                {
                    ResolveParams resolveParams2 = rp;
                    resolveParams2.faction               = faction;
                    resolveParams2.singleThingDef        = thingDef2;
                    resolveParams2.singleThingStackCount = Rand.RangeInclusive(5, Mathf.Min(8, thingDef2.stackLimit));
                    BaseGen.symbolStack.Push("thing", resolveParams2);
                }
                ResolveParams resolveParams3 = rp;
                resolveParams3.faction        = faction;
                resolveParams3.singleThingDef = thingDef;
                resolveParams3.rect           = CellRect.SingleCell(cell);
                resolveParams3.thingRot       = rot;
                BaseGen.symbolStack.Push("thing", resolveParams3);
            }
        }
Example #13
0
        public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null, Thing thing = null)
        {
            TerrainDef terrainDef = map.terrainGrid.TerrainAt(loc);

            if (!terrainDef.defName.Contains("Water") && !terrainDef.defName.Equals("Marsh"))
            {
                return(new AcceptanceReport("RBB.FishingSpot1".Translate()));
            }
            ThingDef thingDef = checkingDef as ThingDef;
            IntVec3  intVec3  = ThingUtility.InteractionCellWhenAt(thingDef, loc, rot, map);

            if (!intVec3.InBounds(map))
            {
                return(new AcceptanceReport("InteractionSpotOutOfBounds".Translate()));
            }

            List <Thing> things = map.thingGrid.ThingsListAtFast(intVec3);

            for (int j = 0; j < things.Count; j++)
            {
                if (things[j] != thingToIgnore)
                {
                    if (things[j].def.passability == Traversability.Impassable)
                    {
                        return(new AcceptanceReport(TranslatorFormattedStringExtensions.Translate("InteractionSpotBlocked", things[j].LabelNoCount).CapitalizeFirst()));
                    }
                    Blueprint blueprint = things[j] as Blueprint;
                    if (blueprint != null && blueprint.def.entityDefToBuild.passability == Traversability.Impassable)
                    {
                        return(new AcceptanceReport(TranslatorFormattedStringExtensions.Translate("InteractionSpotWillBeBlocked", blueprint.LabelNoCount).CapitalizeFirst()));
                    }
                }
            }
            TerrainDef landCheck = map.terrainGrid.TerrainAt(intVec3);

            if (!landCheck.defName.Contains("Water") && landCheck != TerrainDef.Named("Marsh"))
            {
                return(true);
            }
            if (landCheck.defName.Contains("Bridge"))
            {
                return(true);
            }
            return(new AcceptanceReport("RBB.FishingSpot2".Translate()));
        }
Example #14
0
        public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null, Thing thingToPlace = null)
        {
            ThingDef thingDef = checkingDef as ThingDef;

            if (thingDef == null || !thingDef.hasInteractionCell)
            {
                return(true);
            }
            IntVec3 intVec = ThingUtility.InteractionCellWhenAt(thingDef, loc, rot, map);

            for (int i = -1; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    IntVec3 c = intVec;
                    c.x += i;
                    c.z += j;
                    if (!c.InBounds(map))
                    {
                        continue;
                    }
                    foreach (Thing item in map.thingGrid.ThingsListAtFast(c))
                    {
                        if (item != thingToIgnore)
                        {
                            ThingDef thingDef2 = item.def;
                            if (item.def.entityDefToBuild != null)
                            {
                                thingDef2 = item.def.entityDefToBuild as ThingDef;
                            }
                            if (thingDef2 != null && thingDef2.hasInteractionCell && ThingUtility.InteractionCellWhenAt(thingDef2, item.Position, item.Rotation, item.Map) == intVec)
                            {
                                return(new AcceptanceReport(((item.def.entityDefToBuild == null) ? "InteractionSpotOverlaps" : "InteractionSpotWillOverlap").Translate(item.LabelNoCount, item)));
                            }
                        }
                    }
                }
            }
            return(true);
        }
Example #15
0
        public override void Resolve(ResolveParams rp)
        {
            Map             map             = BaseGen.globalSettings.map;
            int             num             = (rp.rect.Width + Mathf.Max(-1, 0)) / (StandardAncientShrineSize.x + -1);
            int             num2            = (rp.rect.Height + Mathf.Max(-1, 0)) / (StandardAncientShrineSize.z + -1);
            IntVec3         bottomLeft      = rp.rect.BottomLeft;
            PodContentsType?podContentsType = rp.podContentsType;

            if (!podContentsType.HasValue)
            {
                float value = Rand.Value;
                podContentsType = ((value < 0.5f) ? null : ((value < 0.7f) ? new PodContentsType?(PodContentsType.Slave) : new PodContentsType?(PodContentsType.AncientHostile)));
            }
            int value2 = rp.ancientCryptosleepCasketGroupID ?? Find.UniqueIDsManager.GetNextAncientCryptosleepCasketGroupID();
            int num3   = 0;

            for (int i = 0; i < num2; i++)
            {
                for (int j = 0; j < num; j++)
                {
                    if (!Rand.Chance(0.25f))
                    {
                        if (num3 >= 6)
                        {
                            break;
                        }
                        CellRect rect = new CellRect(bottomLeft.x + j * (StandardAncientShrineSize.x + -1), bottomLeft.z + i * (StandardAncientShrineSize.z + -1), StandardAncientShrineSize.x, StandardAncientShrineSize.z);
                        if (rect.FullyContainedWithin(rp.rect) && ThingUtility.InteractionCellWhenAt(center: new IntVec3(rect.minX + rect.Width / 2 - 1, 0, rect.minZ + rect.Height / 2), def: ThingDefOf.AncientCryptosleepCasket, rot: Rot4.East, map: map).Standable(map))
                        {
                            ResolveParams resolveParams = rp;
                            resolveParams.rect = rect;
                            resolveParams.ancientCryptosleepCasketGroupID = value2;
                            resolveParams.podContentsType = podContentsType;
                            BaseGen.symbolStack.Push("ancientShrine", resolveParams);
                            num3++;
                        }
                    }
                }
            }
        }
Example #16
0
        public override bool TryAbsorbStack(Thing other, bool respectStackLimit)
        {
            float amount = stackCount;
            float count  = ThingUtility.TryAbsorbStackNumToTake(this, other, respectStackLimit);
            bool  res    = base.TryAbsorbStack(other, respectStackLimit);

            if (res && other is GatheredCumMixture)
            {
                GatheredCumMixture othercum = (GatheredCumMixture)other;
                cumColor = Colors.CMYKLerp(cumColor, othercum.cumColor, count / (amount + count));
                if (!othercum.ingredients.NullOrEmpty())
                {
                    for (int i = 0; i < othercum.ingredients.Count; i++)
                    {
                        if (!ingredients.Contains(othercum.ingredients[i]))
                        {
                            ingredients.Add(othercum.ingredients[i]);
                        }
                    }
                }
            }
            return(res);
        }
        public static AcceptanceReport CanPlaceBlueprintAt(BuildableDef entDef, IntVec3 center, Rot4 rot, Map map, bool godMode = false, Thing thingToIgnore = null)
        {
            CellRect cellRect = GenAdj.OccupiedRect(center, rot, entDef.Size);

            CellRect.CellRectIterator iterator = cellRect.GetIterator();
            while (!iterator.Done())
            {
                IntVec3 c = iterator.Current;
                if (!c.InBounds(map))
                {
                    return(new AcceptanceReport("OutOfBounds".Translate()));
                }
                if (c.InNoBuildEdgeArea(map) && !DebugSettings.godMode)
                {
                    return("TooCloseToMapEdge".Translate());
                }
                iterator.MoveNext();
            }
            if (center.Fogged(map))
            {
                return("CannotPlaceInUndiscovered".Translate());
            }
            List <Thing> thingList = center.GetThingList(map);

            for (int i = 0; i < thingList.Count; i++)
            {
                Thing thing = thingList[i];
                if (thing != thingToIgnore)
                {
                    if (thing.Position == center && thing.Rotation == rot)
                    {
                        if (thing.def == entDef)
                        {
                            return(new AcceptanceReport("IdenticalThingExists".Translate()));
                        }
                        if (thing.def.entityDefToBuild == entDef)
                        {
                            if (thing is Blueprint)
                            {
                                return(new AcceptanceReport("IdenticalBlueprintExists".Translate()));
                            }
                            return(new AcceptanceReport("IdenticalThingExists".Translate()));
                        }
                    }
                }
            }
            ThingDef thingDef = entDef as ThingDef;

            if (thingDef != null && thingDef.hasInteractionCell)
            {
                IntVec3 c2 = ThingUtility.InteractionCellWhenAt(thingDef, center, rot, map);
                if (!c2.InBounds(map))
                {
                    return(new AcceptanceReport("InteractionSpotOutOfBounds".Translate()));
                }
                List <Thing> list = map.thingGrid.ThingsListAtFast(c2);
                for (int j = 0; j < list.Count; j++)
                {
                    if (list[j] != thingToIgnore)
                    {
                        if (list[j].def.passability == Traversability.Impassable)
                        {
                            return(new AcceptanceReport("InteractionSpotBlocked".Translate(new object[]
                            {
                                list[j].LabelNoCount
                            }).CapitalizeFirst()));
                        }
                        Blueprint blueprint = list[j] as Blueprint;
                        if (blueprint != null && blueprint.def.entityDefToBuild.passability == Traversability.Impassable)
                        {
                            return(new AcceptanceReport("InteractionSpotWillBeBlocked".Translate(new object[]
                            {
                                blueprint.LabelNoCount
                            }).CapitalizeFirst()));
                        }
                    }
                }
            }
            if (entDef.passability == Traversability.Impassable)
            {
                foreach (IntVec3 c3 in GenAdj.CellsAdjacentCardinal(center, rot, entDef.Size))
                {
                    if (c3.InBounds(map))
                    {
                        thingList = c3.GetThingList(map);
                        for (int k = 0; k < thingList.Count; k++)
                        {
                            Thing thing2 = thingList[k];
                            if (thing2 != thingToIgnore)
                            {
                                Blueprint blueprint2 = thing2 as Blueprint;
                                ThingDef  thingDef3;
                                if (blueprint2 != null)
                                {
                                    ThingDef thingDef2 = blueprint2.def.entityDefToBuild as ThingDef;
                                    if (thingDef2 == null)
                                    {
                                        goto IL_37F;
                                    }
                                    thingDef3 = thingDef2;
                                }
                                else
                                {
                                    thingDef3 = thing2.def;
                                }
                                if (thingDef3.hasInteractionCell && cellRect.Contains(ThingUtility.InteractionCellWhenAt(thingDef3, thing2.Position, thing2.Rotation, thing2.Map)))
                                {
                                    return(new AcceptanceReport("WouldBlockInteractionSpot".Translate(new object[]
                                    {
                                        entDef.label,
                                        thingDef3.label
                                    }).CapitalizeFirst()));
                                }
                            }
                            IL_37F :;
                        }
                    }
                }
            }
            TerrainDef terrainDef = entDef as TerrainDef;

            if (terrainDef != null)
            {
                if (map.terrainGrid.TerrainAt(center) == terrainDef)
                {
                    return(new AcceptanceReport("TerrainIsAlready".Translate(new object[]
                    {
                        terrainDef.label
                    })));
                }
                if (map.designationManager.DesignationAt(center, DesignationDefOf.SmoothFloor) != null)
                {
                    return(new AcceptanceReport("SpaceBeingSmoothed".Translate()));
                }
            }
            if (!GenConstruct.CanBuildOnTerrain(entDef, center, map, rot, thingToIgnore))
            {
                return(new AcceptanceReport("TerrainCannotSupport".Translate()));
            }
            if (!godMode)
            {
                CellRect.CellRectIterator iterator2 = cellRect.GetIterator();
                while (!iterator2.Done())
                {
                    thingList = iterator2.Current.GetThingList(map);
                    for (int l = 0; l < thingList.Count; l++)
                    {
                        Thing thing3 = thingList[l];
                        if (thing3 != thingToIgnore)
                        {
                            if (!GenConstruct.CanPlaceBlueprintOver(entDef, thing3.def))
                            {
                                return(new AcceptanceReport("SpaceAlreadyOccupied".Translate()));
                            }
                        }
                    }
                    iterator2.MoveNext();
                }
            }
            if (entDef.PlaceWorkers != null)
            {
                for (int m = 0; m < entDef.PlaceWorkers.Count; m++)
                {
                    AcceptanceReport result = entDef.PlaceWorkers[m].AllowsPlacing(entDef, center, rot, map, thingToIgnore);
                    if (!result.Accepted)
                    {
                        return(result);
                    }
                }
            }
            return(AcceptanceReport.WasAccepted);
        }
Example #18
0
        public static AcceptanceReport CanPlaceBlueprintAt(BuildableDef entDef, IntVec3 center, Rot4 rot, Map map, bool godMode = false, Thing thingToIgnore = null, Thing thing = null, ThingDef stuffDef = null)
        {
            CellRect cellRect = GenAdj.OccupiedRect(center, rot, entDef.Size);

            if (stuffDef == null && thing != null)
            {
                stuffDef = thing.Stuff;
            }
            foreach (IntVec3 item in cellRect)
            {
                if (!item.InBounds(map))
                {
                    return(new AcceptanceReport("OutOfBounds".Translate()));
                }
                if (item.InNoBuildEdgeArea(map) && !godMode)
                {
                    return("TooCloseToMapEdge".Translate());
                }
            }
            if (center.Fogged(map))
            {
                return("CannotPlaceInUndiscovered".Translate());
            }
            List <Thing> thingList = center.GetThingList(map);

            for (int i = 0; i < thingList.Count; i++)
            {
                Thing thing2 = thingList[i];
                if (thing2 == thingToIgnore || !(thing2.Position == center) || !(thing2.Rotation == rot))
                {
                    continue;
                }
                if (thing2.def == entDef)
                {
                    return(new AcceptanceReport("IdenticalThingExists".Translate()));
                }
                if (thing2.def.entityDefToBuild == entDef)
                {
                    if (thing2 is Blueprint)
                    {
                        return(new AcceptanceReport("IdenticalBlueprintExists".Translate()));
                    }
                    return(new AcceptanceReport("IdenticalThingExists".Translate()));
                }
            }
            ThingDef thingDef = entDef as ThingDef;

            if (thingDef != null && thingDef.hasInteractionCell)
            {
                IntVec3 c = ThingUtility.InteractionCellWhenAt(thingDef, center, rot, map);
                if (!c.InBounds(map))
                {
                    return(new AcceptanceReport("InteractionSpotOutOfBounds".Translate()));
                }
                List <Thing> list = map.thingGrid.ThingsListAtFast(c);
                for (int j = 0; j < list.Count; j++)
                {
                    if (list[j] != thingToIgnore)
                    {
                        if (list[j].def.passability == Traversability.Impassable || list[j].def == thingDef)
                        {
                            return(new AcceptanceReport("InteractionSpotBlocked".Translate(list[j].LabelNoCount, list[j]).CapitalizeFirst()));
                        }
                        BuildableDef entityDefToBuild = list[j].def.entityDefToBuild;
                        if (entityDefToBuild != null && (entityDefToBuild.passability == Traversability.Impassable || entityDefToBuild == thingDef))
                        {
                            return(new AcceptanceReport("InteractionSpotWillBeBlocked".Translate(list[j].LabelNoCount, list[j]).CapitalizeFirst()));
                        }
                    }
                }
            }
            foreach (IntVec3 item2 in GenAdj.CellsAdjacentCardinal(center, rot, entDef.Size))
            {
                if (item2.InBounds(map))
                {
                    thingList = item2.GetThingList(map);
                    for (int k = 0; k < thingList.Count; k++)
                    {
                        Thing thing3 = thingList[k];
                        if (thing3 != thingToIgnore)
                        {
                            ThingDef  thingDef2 = null;
                            Blueprint blueprint = thing3 as Blueprint;
                            if (blueprint != null)
                            {
                                ThingDef thingDef3 = blueprint.def.entityDefToBuild as ThingDef;
                                if (thingDef3 == null)
                                {
                                    continue;
                                }
                                thingDef2 = thingDef3;
                            }
                            else
                            {
                                thingDef2 = thing3.def;
                            }
                            if (thingDef2.hasInteractionCell && (entDef.passability == Traversability.Impassable || entDef == thingDef2) && cellRect.Contains(ThingUtility.InteractionCellWhenAt(thingDef2, thing3.Position, thing3.Rotation, thing3.Map)))
                            {
                                return(new AcceptanceReport("WouldBlockInteractionSpot".Translate(entDef.label, thingDef2.label).CapitalizeFirst()));
                            }
                        }
                    }
                }
            }
            TerrainDef terrainDef = entDef as TerrainDef;

            if (terrainDef != null)
            {
                if (map.terrainGrid.TerrainAt(center) == terrainDef)
                {
                    return(new AcceptanceReport("TerrainIsAlready".Translate(terrainDef.label)));
                }
                if (map.designationManager.DesignationAt(center, DesignationDefOf.SmoothFloor) != null)
                {
                    return(new AcceptanceReport("SpaceBeingSmoothed".Translate()));
                }
            }
            if (!CanBuildOnTerrain(entDef, center, map, rot, thingToIgnore, stuffDef))
            {
                if (entDef.GetTerrainAffordanceNeed(stuffDef) != null)
                {
                    if (entDef.useStuffTerrainAffordance && stuffDef != null)
                    {
                        return(new AcceptanceReport("TerrainCannotSupport_TerrainAffordanceFromStuff".Translate(entDef, entDef.GetTerrainAffordanceNeed(stuffDef), stuffDef).CapitalizeFirst()));
                    }
                    return(new AcceptanceReport("TerrainCannotSupport_TerrainAffordance".Translate(entDef, entDef.GetTerrainAffordanceNeed(stuffDef)).CapitalizeFirst()));
                }
                return(new AcceptanceReport("TerrainCannotSupport".Translate(entDef).CapitalizeFirst()));
            }
            if (ModsConfig.RoyaltyActive)
            {
                List <Thing> list2 = map.listerThings.ThingsOfDef(ThingDefOf.MonumentMarker);
                for (int l = 0; l < list2.Count; l++)
                {
                    MonumentMarker monumentMarker = (MonumentMarker)list2[l];
                    if (!monumentMarker.complete && !monumentMarker.AllowsPlacingBlueprint(entDef, center, rot, stuffDef))
                    {
                        return(new AcceptanceReport("BlueprintWouldCollideWithMonument".Translate()));
                    }
                }
            }
            if (!godMode)
            {
                foreach (IntVec3 item3 in cellRect)
                {
                    thingList = item3.GetThingList(map);
                    for (int m = 0; m < thingList.Count; m++)
                    {
                        Thing thing4 = thingList[m];
                        if (thing4 != thingToIgnore && !CanPlaceBlueprintOver(entDef, thing4.def))
                        {
                            return(new AcceptanceReport("SpaceAlreadyOccupied".Translate()));
                        }
                    }
                }
            }
            if (entDef.PlaceWorkers != null)
            {
                for (int n = 0; n < entDef.PlaceWorkers.Count; n++)
                {
                    AcceptanceReport result = entDef.PlaceWorkers[n].AllowsPlacing(entDef, center, rot, map, thingToIgnore, thing);
                    if (!result.Accepted)
                    {
                        return(result);
                    }
                }
            }
            return(AcceptanceReport.WasAccepted);
        }
        // Token: 0x060000E2 RID: 226 RVA: 0x000071D4 File Offset: 0x000053D4
        public static AcceptanceReport CanPlaceBlueprintAt(BuildableDef entDef, IntVec3 center, Rot4 rot, Map map, bool godMode = false, Thing thingToIgnore = null, Thing thing = null, ThingDef stuffDef = null)
        {
            CellRect cellRect = GenAdj.OccupiedRect(center, rot, entDef.Size);
            bool     flag     = stuffDef == null && thing != null;

            if (flag)
            {
                stuffDef = thing.Stuff;
            }
            foreach (IntVec3 c in cellRect)
            {
                bool flag2 = !c.InBounds(map);
                if (flag2)
                {
                    return(new AcceptanceReport("OutOfBounds".Translate()));
                }
                bool flag3 = c.InNoBuildEdgeArea(map) && !godMode;
                if (flag3)
                {
                    return("TooCloseToMapEdge".Translate());
                }
            }
            bool             flag4 = center.Fogged(map);
            AcceptanceReport result;

            if (flag4)
            {
                result = "CannotPlaceInUndiscovered".Translate();
            }
            else
            {
                List <Thing> thingList = center.GetThingList(map);
                for (int i = 0; i < thingList.Count; i++)
                {
                    Thing thing2 = thingList[i];
                    bool  flag5  = thing2 != thingToIgnore && thing2.Position == center && thing2.Rotation == rot;
                    if (flag5)
                    {
                        bool flag6 = thing2.def == entDef;
                        if (flag6)
                        {
                            return(new AcceptanceReport("IdenticalThingExists".Translate()));
                        }
                        bool flag7 = thing2.def.entityDefToBuild == entDef;
                        if (flag7)
                        {
                            bool flag8 = thing2 is Blueprint;
                            if (flag8)
                            {
                                return(new AcceptanceReport("IdenticalBlueprintExists".Translate()));
                            }
                            return(new AcceptanceReport("IdenticalThingExists".Translate()));
                        }
                    }
                }
                ThingDef thingDef = entDef as ThingDef;
                bool     flag9    = thingDef != null && thingDef.hasInteractionCell;
                if (flag9)
                {
                    IntVec3 c2     = ThingUtility.InteractionCellWhenAt(thingDef, center, rot, map);
                    bool    flag10 = !c2.InBounds(map);
                    if (flag10)
                    {
                        return(new AcceptanceReport("InteractionSpotOutOfBounds".Translate()));
                    }
                    List <Thing> list = map.thingGrid.ThingsListAtFast(c2);
                    for (int j = 0; j < list.Count; j++)
                    {
                        bool flag11 = list[j] != thingToIgnore;
                        if (flag11)
                        {
                            bool flag12 = list[j].def.passability == Traversability.Impassable || list[j].def == thingDef;
                            if (flag12)
                            {
                                return(new AcceptanceReport("InteractionSpotBlocked".Translate(list[j].LabelNoCount, list[j]).CapitalizeFirst()));
                            }
                            BuildableDef entityDefToBuild = list[j].def.entityDefToBuild;
                            bool         flag13           = entityDefToBuild != null && (entityDefToBuild.passability == Traversability.Impassable || entityDefToBuild == thingDef);
                            if (flag13)
                            {
                                return(new AcceptanceReport("InteractionSpotWillBeBlocked".Translate(list[j].LabelNoCount, list[j]).CapitalizeFirst()));
                            }
                        }
                    }
                }
                foreach (IntVec3 c3 in GenAdj.CellsAdjacentCardinal(center, rot, entDef.Size))
                {
                    bool flag14 = c3.InBounds(map);
                    if (flag14)
                    {
                        thingList = c3.GetThingList(map);
                        for (int k = 0; k < thingList.Count; k++)
                        {
                            Thing thing3 = thingList[k];
                            bool  flag15 = thing3 != thingToIgnore;
                            if (flag15)
                            {
                                Blueprint blueprint = thing3 as Blueprint;
                                bool      flag16    = blueprint != null;
                                ThingDef  thingDef3;
                                if (flag16)
                                {
                                    ThingDef thingDef2 = blueprint.def.entityDefToBuild as ThingDef;
                                    bool     flag17    = thingDef2 == null;
                                    if (flag17)
                                    {
                                        goto IL_48F;
                                    }
                                    thingDef3 = thingDef2;
                                }
                                else
                                {
                                    thingDef3 = thing3.def;
                                }
                                bool flag18 = thingDef3.hasInteractionCell && (entDef.passability == Traversability.Impassable || entDef == thingDef3) && cellRect.Contains(ThingUtility.InteractionCellWhenAt(thingDef3, thing3.Position, thing3.Rotation, thing3.Map));
                                if (flag18)
                                {
                                    return(new AcceptanceReport("WouldBlockInteractionSpot".Translate(entDef.label, thingDef3.label).CapitalizeFirst()));
                                }
                            }
                            IL_48F :;
                        }
                    }
                }
                TerrainDef terrainDef = entDef as TerrainDef;
                bool       flag19     = terrainDef != null;
                if (flag19)
                {
                    bool flag20 = map.terrainGrid.TerrainAt(center) == terrainDef;
                    if (flag20)
                    {
                        return(new AcceptanceReport("TerrainIsAlready".Translate(terrainDef.label)));
                    }
                    bool flag21 = map.designationManager.DesignationAt(center, DesignationDefOf.SmoothFloor) != null;
                    if (flag21)
                    {
                        return(new AcceptanceReport("SpaceBeingSmoothed".Translate()));
                    }
                }
                bool flag22 = WPGenConstruct.CanBuildOnTerrain(entDef, center, map, rot, thingToIgnore, stuffDef);
                if (flag22)
                {
                    bool flag23 = !godMode;
                    if (flag23)
                    {
                        foreach (IntVec3 c4 in cellRect)
                        {
                            thingList = c4.GetThingList(map);
                            for (int l = 0; l < thingList.Count; l++)
                            {
                                Thing thing4 = thingList[l];
                                bool  flag24 = thing4 != thingToIgnore && !WPGenConstruct.CanPlaceBlueprintOver(entDef, thing4.def);
                                if (flag24)
                                {
                                    return(new AcceptanceReport("SpaceAlreadyOccupied".Translate()));
                                }
                            }
                        }
                    }
                    bool flag25 = entDef.PlaceWorkers != null;
                    if (flag25)
                    {
                        for (int m = 0; m < entDef.PlaceWorkers.Count; m++)
                        {
                            AcceptanceReport result2 = entDef.PlaceWorkers[m].AllowsPlacing(entDef, center, rot, map, thingToIgnore, thing);
                            bool             flag26  = !result2.Accepted;
                            if (flag26)
                            {
                                return(result2);
                            }
                        }
                    }
                    result = AcceptanceReport.WasAccepted;
                }
                else
                {
                    bool flag27 = entDef.GetTerrainAffordanceNeed(stuffDef) == null;
                    if (flag27)
                    {
                        result = new AcceptanceReport("TerrainCannotSupport".Translate(entDef).CapitalizeFirst());
                    }
                    else
                    {
                        bool flag28 = entDef.useStuffTerrainAffordance && stuffDef != null;
                        if (flag28)
                        {
                            result = new AcceptanceReport("TerrainCannotSupport_TerrainAffordanceFromStuff".Translate(entDef, entDef.GetTerrainAffordanceNeed(stuffDef), stuffDef).CapitalizeFirst());
                        }
                        else
                        {
                            result = new AcceptanceReport("TerrainCannotSupport_TerrainAffordance".Translate(entDef, entDef.GetTerrainAffordanceNeed(stuffDef)).CapitalizeFirst());
                        }
                    }
                }
            }
            return(result);
        }
        public static AcceptanceReport CanPlaceBlueprintAt(BuildableDef entDef, IntVec3 center, Rot4 rot, Map map, ThingDef stuff, bool godMode = false, Thing thingToIgnore = null)
        {
            CellRect cellRect = GenAdj.OccupiedRect(center, rot, entDef.Size);

            CellRect.CellRectIterator iterator = cellRect.GetIterator();
            while (!iterator.Done())
            {
                IntVec3 current = iterator.Current;
                if (!current.InBounds(map))
                {
                    return(new AcceptanceReport("OutOfBounds".Translate()));
                }
                if (current.InNoBuildEdgeArea(map) && !DebugSettings.godMode)
                {
                    return("TooCloseToMapEdge".Translate());
                }
                iterator.MoveNext();
            }
            if (center.Fogged(map))
            {
                return("CannotPlaceInUndiscovered".Translate());
            }
            List <Thing> thingList = center.GetThingList(map);

            for (int i = 0; i < thingList.Count; i++)
            {
                Thing thing = thingList[i];
                if (thing != thingToIgnore)
                {
                    if (thing.Position == center && thing.Rotation == rot)
                    {
                        if (thing.def == entDef)
                        {
                            //Start my code, this code allows blueprint to be placed, so canPlaceOverWall can do it's thing.
                            if (((walls.Contains(thing.def.defName) && walls.Contains(entDef.defName)) ||
                                 (doors.Contains(thing.def.defName) && doors.Contains(entDef.defName))) &&
                                thing.Stuff != stuff)
                            {
                                return(AcceptanceReport.WasAccepted);
                            }
                            //End my code

                            return(new AcceptanceReport("IdenticalThingExists".Translate()));
                        }
                        if (thing.def.entityDefToBuild == entDef)
                        {
                            if (thing is Blueprint)
                            {
                                return(new AcceptanceReport("IdenticalBlueprintExists".Translate()));
                            }
                            return(new AcceptanceReport("IdenticalThingExists".Translate()));
                        }
                    }
                }
            }
            ThingDef thingDef = entDef as ThingDef;

            if (thingDef != null && thingDef.hasInteractionCell)
            {
                IntVec3 c = ThingUtility.InteractionCellWhenAt(thingDef, center, rot, map);
                if (!c.InBounds(map))
                {
                    return(new AcceptanceReport("InteractionSpotOutOfBounds".Translate()));
                }
                List <Thing> list = map.thingGrid.ThingsListAtFast(c);
                for (int j = 0; j < list.Count; j++)
                {
                    if (list[j] != thingToIgnore)
                    {
                        if (list[j].def.passability == Traversability.Impassable)
                        {
                            return(new AcceptanceReport("InteractionSpotBlocked".Translate(new object[]
                            {
                                list[j].LabelNoCount
                            }).CapitalizeFirst()));
                        }
                        Blueprint blueprint = list[j] as Blueprint;
                        if (blueprint != null && blueprint.def.entityDefToBuild.passability == Traversability.Impassable)
                        {
                            return(new AcceptanceReport("InteractionSpotWillBeBlocked".Translate(new object[]
                            {
                                blueprint.LabelNoCount
                            }).CapitalizeFirst()));
                        }
                    }
                }
            }
            if (entDef.passability != Traversability.Standable)
            {
                foreach (IntVec3 current2 in GenAdj.CellsAdjacentCardinal(center, rot, entDef.Size))
                {
                    if (current2.InBounds(map))
                    {
                        thingList = current2.GetThingList(map);
                        for (int k = 0; k < thingList.Count; k++)
                        {
                            Thing thing2 = thingList[k];
                            if (thing2 != thingToIgnore)
                            {
                                Blueprint blueprint2 = thing2 as Blueprint;
                                ThingDef  thingDef3;
                                if (blueprint2 != null)
                                {
                                    ThingDef thingDef2 = blueprint2.def.entityDefToBuild as ThingDef;
                                    if (thingDef2 == null)
                                    {
                                        goto IL_37E;
                                    }
                                    thingDef3 = thingDef2;
                                }
                                else
                                {
                                    thingDef3 = thing2.def;
                                }
                                if (thingDef3.hasInteractionCell && cellRect.Contains(ThingUtility.InteractionCellWhenAt(thingDef3, thing2.Position, thing2.Rotation, thing2.Map)))
                                {
                                    return(new AcceptanceReport("WouldBlockInteractionSpot".Translate(new object[]
                                    {
                                        entDef.label,
                                        thingDef3.label
                                    }).CapitalizeFirst()));
                                }
                            }
                            IL_37E :;
                        }
                    }
                }
            }
            TerrainDef terrainDef = entDef as TerrainDef;

            if (terrainDef != null)
            {
                if (map.terrainGrid.TerrainAt(center) == terrainDef)
                {
                    return(new AcceptanceReport("TerrainIsAlready".Translate(new object[]
                    {
                        terrainDef.label
                    })));
                }
                if (map.designationManager.DesignationAt(center, DesignationDefOf.SmoothFloor) != null)
                {
                    return(new AcceptanceReport("BeingSmoothed".Translate()));
                }
            }
            if (!GenConstruct.CanBuildOnTerrain(entDef, center, map, rot, thingToIgnore))
            {
                return(new AcceptanceReport("TerrainCannotSupport".Translate()));
            }
            if (!godMode)
            {
                CellRect.CellRectIterator iterator2 = cellRect.GetIterator();
                while (!iterator2.Done())
                {
                    thingList = iterator2.Current.GetThingList(map);
                    for (int l = 0; l < thingList.Count; l++)
                    {
                        Thing thing3 = thingList[l];
                        if (thing3 != thingToIgnore)
                        {
                            if (!GenConstruct.CanPlaceBlueprintOver(entDef, thing3.def))
                            {
                                //Start my code, entDef is new, thing3 is old
                                //Allows for doors to replace each other only if different stuff or door <--> autodoor
                                if (thing3?.def?.defName != null)
                                {
                                    if ((doors.Contains(entDef.defName) && doors.Contains(thing3.def.defName)) && //New and old are both doors
                                        (thing3.Stuff != stuff || !entDef.defName.Equals(thing3.def.defName)))    //Not the same stuff or not same thing
                                    {
                                        return(AcceptanceReport.WasAccepted);
                                    }
                                    //Allow placing over mineable
                                    if (thing3 is Mineable && (doors.Contains(entDef.defName) || walls.Contains(entDef.defName)))
                                    {
                                        return(AcceptanceReport.WasAccepted);
                                    }
                                    //Allow walls and doors to be placed over walls
                                    if ((walls.Contains(entDef.defName) || doors.Contains(entDef.defName)) && walls.Contains(thing3.def.defName))
                                    {
                                        return(AcceptanceReport.WasAccepted);
                                    }
                                    //Allow replacing invisible power lines from PowerSwitch by Haplo
                                    if (conduits.Contains(entDef.defName) && conduits.Contains(thing3.def.defName))
                                    {
                                        return(AcceptanceReport.WasAccepted);
                                    }
                                }
                                //End my code

                                return(new AcceptanceReport("SpaceAlreadyOccupied".Translate()));
                            }
                        }
                    }
                    iterator2.MoveNext();
                }
            }
            if (entDef.PlaceWorkers != null)
            {
                for (int m = 0; m < entDef.PlaceWorkers.Count; m++)
                {
                    AcceptanceReport result = entDef.PlaceWorkers[m].AllowsPlacing(entDef, center, rot, map, thingToIgnore);
                    if (!result.Accepted)
                    {
                        return(result);
                    }
                }
            }
            return(AcceptanceReport.WasAccepted);
        }
            internal bool <> m__4(IntVec3 x)
            {
                CellRect obj = GenAdj.OccupiedRect(x, this.rot, this.mortarDef.size);

                return(ThingUtility.InteractionCellWhenAt(this.mortarDef, x, this.rot, this.map).Standable(this.map) && obj.FullyContainedWithin(this.rect) && this.edgeTouchCheck(obj));
            }
Example #22
0
 public static bool CheckForStateChange_Xenomorph_Prefix(Pawn_HealthTracker __instance, DamageInfo?dinfo, Hediff hediff)
 {
     if (dinfo != null)
     {
         Pawn instigator = null;
         if (dinfo.Value.Instigator != null && dinfo.Value.Instigator.GetType() == typeof(Pawn))
         {
             instigator = (Pawn)dinfo.Value.Instigator;
         }
         if (instigator != null)
         {
             if (instigator.isXenomorph())
             {
                 FieldInfo  fieldInfo   = AccessTools.Field(typeof(Pawn_HealthTracker), "pawn");
                 MethodBase methodBase  = AccessTools.Method(typeof(Pawn_HealthTracker), "MakeDowned", null, null);
                 MethodBase methodBase2 = AccessTools.Method(typeof(Pawn_HealthTracker), "MakeUnDowned", null, null);
                 Traverse   traverse    = Traverse.Create(__instance);
                 Pawn       pawn        = (Pawn)fieldInfo.GetValue(__instance);
                 bool       flag        = pawn != null && dinfo != null && dinfo != null && hediff != null && !ThingUtility.DestroyedOrNull(pawn);
                 bool       result;
                 if (flag)
                 {
                     bool flag2 = !__instance.Dead;
                     if (flag2)
                     {
                         bool value = traverse.Method("ShouldBeDead", Array.Empty <object>()).GetValue <bool>();
                         if (value)
                         {
                             bool flag3 = !pawn.Destroyed;
                             if (flag3)
                             {
                                 pawn.Kill(dinfo, hediff);
                             }
                             return(false);
                         }
                         bool flag4 = !__instance.Downed;
                         if (flag4)
                         {
                             bool value2 = traverse.Method("ShouldBeDowned", Array.Empty <object>()).GetValue <bool>();
                             if (value2)
                             {
                                 /*
                                  * bool flag5 = !__instance.forceIncap && dinfo != null && dinfo.Value.Def.ExternalViolenceFor(pawn) && !WildManUtility.IsWildMan(pawn) && (pawn.Faction == null || !pawn.Faction.IsPlayer) && (pawn.HostFaction == null || !pawn.HostFaction.IsPlayer);
                                  * if (flag5)
                                  * {
                                  *      bool animal = pawn.RaceProps.Animal;
                                  *      float num;
                                  *      if (animal && pawn.isPotentialHost())
                                  *      {
                                  *              num = 0f;
                                  *      }
                                  * }
                                  */
                                 __instance.forceIncap = false;
                                 methodBase.Invoke(__instance, new object[]
                                 {
                                     dinfo,
                                     hediff
                                 });
                                 return(false);
                             }
                             bool flag7 = !__instance.capacities.CapableOf(PawnCapacityDefOf.Manipulation);
                             if (flag7)
                             {
                                 bool flag8 = pawn.carryTracker != null && pawn.carryTracker.CarriedThing != null && pawn.jobs != null && pawn.CurJob != null;
                                 if (flag8)
                                 {
                                     pawn.jobs.EndCurrentJob((JobCondition)5, true, true);
                                 }
                                 bool flag9 = pawn.equipment != null && pawn.equipment.Primary != null;
                                 if (flag9)
                                 {
                                     bool destroyGearOnDrop = pawn.kindDef.destroyGearOnDrop;
                                     if (destroyGearOnDrop)
                                     {
                                         pawn.equipment.DestroyEquipment(pawn.equipment.Primary);
                                     }
                                     else
                                     {
                                         bool inContainerEnclosed = pawn.InContainerEnclosed;
                                         if (inContainerEnclosed)
                                         {
                                             pawn.equipment.TryTransferEquipmentToContainer(pawn.equipment.Primary, pawn.holdingOwner);
                                         }
                                         else
                                         {
                                             bool spawnedOrAnyParentSpawned = pawn.SpawnedOrAnyParentSpawned;
                                             if (spawnedOrAnyParentSpawned)
                                             {
                                                 ThingWithComps thingWithComps;
                                                 pawn.equipment.TryDropEquipment(pawn.equipment.Primary, out thingWithComps, pawn.PositionHeld, true);
                                             }
                                             else
                                             {
                                                 pawn.equipment.DestroyEquipment(pawn.equipment.Primary);
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         else
                         {
                             bool flag10 = !traverse.Method("ShouldBeDowned", Array.Empty <object>()).GetValue <bool>();
                             if (flag10)
                             {
                                 methodBase2.Invoke(__instance, null);
                                 return(false);
                             }
                         }
                     }
                     result = false;
                 }
                 else
                 {
                     result = true;
                 }
                 return(result);
             }
         }
     }
     return(true);
 }
Example #23
0
        public static Thing SpawnModded(Thing newThing, IntVec3 loc, Map map, Rot4 rot)
        {
            bool  flag = map == null;
            Thing result;

            if (flag)
            {
                Log.Error("Tried to spawn " + newThing + " in a null map.");
                result = null;
            }
            else
            {
                bool flag2 = !loc.InBounds(map);
                if (flag2)
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "Tried to spawn ",
                        newThing,
                        " out of bounds at ",
                        loc,
                        "."
                    }));
                    result = null;
                }
                else
                {
                    bool spawned = newThing.Spawned;
                    if (spawned)
                    {
                        Log.Error("Tried to spawn " + newThing + " but it's already spawned.");
                        result = newThing;
                    }
                    else
                    {
                        GenSpawn.WipeExistingThings(loc, rot, newThing.def, map, DestroyMode.Vanish);
                        bool randomizeRotationOnSpawn = newThing.def.randomizeRotationOnSpawn;
                        if (randomizeRotationOnSpawn)
                        {
                            newThing.Rotation = Rot4.Random;
                        }
                        else
                        {
                            newThing.Rotation = rot;
                        }
                        newThing.Position = loc;
                        ThingUtility.UpdateRegionListers(IntVec3.Invalid, loc, map, newThing);
                        map.thingGrid.Register(newThing);
                        newThing.SpawnSetup(map);
                        bool spawned2 = newThing.Spawned;
                        if (spawned2)
                        {
                            bool flag3 = newThing.stackCount == 0;
                            if (flag3)
                            {
                                Log.Error("Spawned thing with 0 stackCount: " + newThing);
                                newThing.Destroy(DestroyMode.Vanish);
                                result = null;
                                return(result);
                            }
                        }
                        else
                        {
                            ThingUtility.UpdateRegionListers(loc, IntVec3.Invalid, map, newThing);
                            map.thingGrid.Deregister(newThing, true);
                        }
                        bool flag4 = newThing.def.GetType() != typeof(Thingdef_AlienRace);
                        if (flag4)
                        {
                            result = newThing;
                        }
                        else
                        {
                            AlienPawn alienPawn = newThing as AlienPawn;
                            alienPawn.SpawnSetupAlien();
                            result = alienPawn;
                        }
                    }
                }
            }
            return(result);
        }
        private Thing GenerateReward(float value, TechLevel techLevel, Predicate <ThingDef> validator = null)
        {
            if (Rand.Chance(0.5f) && (validator == null || validator(ThingDefOf.Silver)))
            {
                Thing thing = ThingMaker.MakeThing(ThingDefOf.Silver, null);
                thing.stackCount = ThingUtility.RoundedResourceStackCount(Mathf.Max(GenMath.RoundRandom(value), 1));
                return(thing);
            }
            ThingDef thingDef = default(ThingDef);

            if (Rand.Chance(0.35f) && (from x in ItemCollectionGeneratorUtility.allGeneratableItems
                                       where x.itemGeneratorTags != null && x.itemGeneratorTags.Contains(ItemCollectionGeneratorUtility.SpecialRewardTag) && (validator == null || validator(x)) && Mathf.Abs((float)(1.0 - x.BaseMarketValue / value)) <= 0.34999999403953552
                                       select x).TryRandomElement <ThingDef>(out thingDef))
            {
                Thing       thing2      = ThingMaker.MakeThing(thingDef, GenStuff.RandomStuffFor(thingDef));
                CompQuality compQuality = thing2.TryGetComp <CompQuality>();
                if (compQuality != null)
                {
                    compQuality.SetQuality(QualityUtility.RandomBaseGenItemQuality(), ArtGenerationContext.Outsider);
                }
                return(thing2);
            }
            if (Rand.Chance(0.13f))
            {
                float    minExpensiveMineableResourceMarketValue = ThingDefOf.Uranium.BaseMarketValue;
                ThingDef thingDef2 = default(ThingDef);
                if ((from x in ItemCollectionGenerator_Meteorite.mineables
                     where x.building.isResourceRock && x.building.mineableThing.BaseMarketValue >= minExpensiveMineableResourceMarketValue && (validator == null || validator(x.building.mineableThing))
                     select x).TryRandomElement <ThingDef>(out thingDef2))
                {
                    float    num           = (float)(value * 0.89999997615814209);
                    ThingDef mineableThing = thingDef2.building.mineableThing;
                    Thing    thing3        = ThingMaker.MakeThing(mineableThing, null);
                    thing3.stackCount = Mathf.Max(GenMath.RoundRandom(num / mineableThing.BaseMarketValue), 1);
                    return(thing3);
                }
            }
            Option option2 = (from option in ItemCollectionGeneratorUtility.allGeneratableItems.Select(delegate(ThingDef td)
            {
                if ((int)td.techLevel > (int)techLevel)
                {
                    return(null);
                }
                if (td.itemGeneratorTags != null && td.itemGeneratorTags.Contains(ItemCollectionGeneratorUtility.SpecialRewardTag))
                {
                    return(null);
                }
                if (!td.IsWithinCategory(ThingCategoryDefOf.Apparel) && !td.IsWithinCategory(ThingCategoryDefOf.Weapons) && !td.IsWithinCategory(ThingCategoryDefOf.Art) && (td.building == null || !td.Minifiable) && (td.tradeTags == null || !td.tradeTags.Contains("Exotic")))
                {
                    return(null);
                }
                if (validator != null && !validator(td))
                {
                    return(null);
                }
                ThingDef stuff = null;
                if (td.MadeFromStuff && !GenStuff.TryRandomStuffByCommonalityFor(td, out stuff, techLevel))
                {
                    return(null);
                }
                Option option3 = new Option();
                option3.thingDef = td;
                option3.quality = ((!td.HasComp(typeof(CompQuality))) ? QualityCategory.Normal : QualityUtility.RandomQuality());
                option3.stuff = stuff;
                return(option3);
            })
                              where option != null
                              select option).MinBy(delegate(Option option)
            {
                float value2 = StatDefOf.MarketValue.Worker.GetValue(StatRequest.For(option.thingDef, option.stuff, option.quality), true);
                return(Mathf.Abs(value - value2));
            });
            Thing       thing4       = ThingMaker.MakeThing(option2.thingDef, option2.stuff);
            CompQuality compQuality2 = thing4.TryGetComp <CompQuality>();

            if (compQuality2 != null)
            {
                compQuality2.SetQuality(option2.quality, ArtGenerationContext.Outsider);
            }
            return(thing4);
        }