Ejemplo n.º 1
0
        private void TakeWearoutDamageForDay(Thing ap)
        {
            int num = GenMath.RoundRandom(ap.def.apparel.wearPerDay);

            if (num > 0)
            {
                ap.TakeDamage(new DamageInfo(DamageDefOf.Deterioration, (float)num, 0f, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown, null));
            }
            if (ap.Destroyed && PawnUtility.ShouldSendNotificationAbout(this.pawn) && !this.pawn.Dead)
            {
                string text = "MessageWornApparelDeterioratedAway".Translate(GenLabel.ThingLabel(ap.def, ap.Stuff, 1), this.pawn);
                text = text.CapitalizeFirst();
                Messages.Message(text, this.pawn, MessageTypeDefOf.NegativeEvent, true);
            }
        }
        public new bool TryExecute(IncidentParms parms)
        {
            Map        map = (Map)parms.target;
            HorrorHive t   = null;
            int        num;

            for (int i = Mathf.Max(GenMath.RoundRandom(parms.points / HivePoints), 1); i > 0; i -= num)
            {
                num = Mathf.Min(3, i);
                t   = this.SpawnHiveCluster(num, map);
            }
            base.SendStandardLetter(parms, t);
            Find.TickManager.slower.SignalForceNormalSpeedShort();
            return(true);
        }
        private void RefundResources(float yield)
        {
            List <ThingDefCountClass> ingredientCount = UpgradableComp.upgradeCostListFinalized;

            foreach (ThingDefCountClass thing in ingredientCount)
            {
                int   yieldCount = GenMath.RoundRandom(thing.count * yield);
                Thing yieldItem  = ThingMaker.MakeThing(thing.thingDef);
                yieldItem.stackCount = yieldCount;
                if (yieldCount > 0)
                {
                    GenPlace.TryPlaceThing(yieldItem, TargetThingA.Position, TargetThingA.Map, ThingPlaceMode.Near);
                }
            }
        }
Ejemplo n.º 4
0
        public virtual int YieldNow()
        {
            if (!this.CanYieldNow())
            {
                return(0);
            }
            float num  = this.def.plant.harvestYield;
            float num2 = Mathf.InverseLerp(this.def.plant.harvestMinGrowth, 1f, this.growthInt);

            num2 = 0.5f + num2 * 0.5f;
            num *= num2;
            num *= Mathf.Lerp(0.5f, 1f, (float)this.HitPoints / (float)base.MaxHitPoints);
            num *= Find.Storyteller.difficulty.cropYieldFactor;
            return(GenMath.RoundRandom(num));
        }
Ejemplo n.º 5
0
 private void RefundResources(float yield)
 {
     UpgradableComp.innerContainer.TryDropAll(TargetThingA.Position, TargetThingA.Map, ThingPlaceMode.Near, (t, c) =>
     {
         c = GenMath.RoundRandom(c * yield);
         if (c > 0)
         {
             t.stackCount = c;
         }
         else
         {
             t.Destroy();
         }
     });
 }
Ejemplo n.º 6
0
        private void TakeWearoutDamageForDay(Thing ap)
        {
            int num = GenMath.RoundRandom(ap.def.apparel.wearPerDay);

            if (num > 0)
            {
                ap.TakeDamage(new DamageInfo(DamageDefOf.Deterioration, (float)num));
            }
            if (ap.Destroyed && PawnUtility.ShouldSendNotificationAbout(pawn) && !pawn.Dead)
            {
                string str = "MessageWornApparelDeterioratedAway".Translate(GenLabel.ThingLabel(ap.def, ap.Stuff), pawn);
                str = str.CapitalizeFirst();
                Messages.Message(str, pawn, MessageTypeDefOf.NegativeEvent);
            }
        }
Ejemplo n.º 7
0
        public virtual int YieldNow()
        {
            if (!CanYieldNow())
            {
                return(0);
            }
            float harvestYield = def.plant.harvestYield;
            float num          = Mathf.InverseLerp(def.plant.harvestMinGrowth, 1f, growthInt);

            num           = 0.5f + num * 0.5f;
            harvestYield *= num;
            harvestYield *= Mathf.Lerp(0.5f, 1f, (float)HitPoints / (float)base.MaxHitPoints);
            harvestYield *= Find.Storyteller.difficulty.cropYieldFactor;
            return(GenMath.RoundRandom(harvestYield));
        }
Ejemplo n.º 8
0
 public override void PreApplyDamage(ref DamageInfo dinfo, out bool absorbed)
 {
     base.PreApplyDamage(ref dinfo, out absorbed);
     if (!absorbed)
     {
         if (this.def.building.mineableThing != null && this.def.building.mineableYieldWasteable)
         {
             if (dinfo.Def == DamageDefOf.Mining && dinfo.Instigator != null && dinfo.Instigator is Pawn)
             {
                 this.Notify_TookMiningDamage(GenMath.RoundRandom(dinfo.Amount), (Pawn)dinfo.Instigator);
             }
         }
         absorbed = false;
     }
 }
Ejemplo n.º 9
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map  map = (Map)parms.target;
            Hive t   = null;
            int  num2;

            for (int num = Mathf.Max(GenMath.RoundRandom((float)(parms.points / 400.0)), 1); num > 0; num -= num2)
            {
                num2 = Mathf.Min(3, num);
                t    = this.SpawnHiveCluster(num2, map);
            }
            base.SendStandardLetter(t);
            Find.TickManager.slower.SignalForceNormalSpeedShort();
            return(true);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map   map = (Map)parms.target;
            Thing t   = null;
            int   num;

            for (int i = Mathf.Max(GenMath.RoundRandom(parms.points / 250f), 1); i > 0; i -= num)
            {
                num = Mathf.Min(3, i);
                t   = this.SpawnTunnel(num, map);
            }
            base.SendStandardLetter(t, null, new string[0]);
            Find.TickManager.slower.SignalForceNormalSpeedShort();
            return(true);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map         map          = (Map)parms.target;
            PawnKindDef largeMonster = WyvernUtility.GetRandomLargeMonsterForEvent(map);

            if (largeMonster == null)
            {
                return(false);
            }
            IntVec3 intVec;

            if (!RCellFinder.TryFindRandomPawnEntryCell(out intVec, map, CellFinder.EdgeRoadChance_Animal, false, null))
            {
                return(false);
            }
            IntVec3     loc               = CellFinder.RandomClosewalkCellNear(intVec, map, 10, null);
            Pawn        newThing          = PawnGenerator.GeneratePawn(largeMonster, null);
            PawnKindDef smallMonsterGroup = WyvernUtility.GetSmallMonsterGroupForLargeMonster(largeMonster); // is leader of pack if not null

            if (smallMonsterGroup != null)
            {
                newThing.gender = Gender.Male;                            // pack leader are always male
            }
            Pawn newLargeMonster = (Pawn)GenSpawn.Spawn(newThing, loc, map, WipeMode.Vanish);

            newLargeMonster.needs.food.CurLevelPercentage = 1f;

            if (smallMonsterGroup == null)
            {
                Find.LetterStack.ReceiveLetter("LetterLabelLargeMonsterAppear".Translate(), "LetterTextLargeMonsterAppear".Translate(newLargeMonster.Label.CapitalizeFirst()), LetterDefOf.ThreatSmall, new TargetInfo(intVec, map, false), null, null);
                return(true);
            }

            int   freeColonistsCount = map.mapPawns.FreeColonistsCount;
            float randomInRange      = IncidentWorker_LargeMonsterAppear.CountPerColonistRange.RandomInRange;
            float f   = (float)freeColonistsCount * randomInRange;
            int   num = Mathf.Clamp(GenMath.RoundRandom(f), 1, 10);

            for (int i = 0; i < num; i++)
            {
                Pawn newThing2       = PawnGenerator.GeneratePawn(smallMonsterGroup, null);
                Pawn newSmallMonster = (Pawn)GenSpawn.Spawn(newThing2, loc, map, WipeMode.Vanish);
                newSmallMonster.needs.food.CurLevelPercentage = 1f;
            }
            Find.LetterStack.ReceiveLetter("LetterLabelLargeMonsterAppear".Translate(), "LetterTextLargeMonsterAppearWithGroup".Translate(newLargeMonster.Label.CapitalizeFirst(), smallMonsterGroup.label.CapitalizeFirst()), LetterDefOf.ThreatSmall, new TargetInfo(intVec, map, false), null, null);

            return(true);
        }
        /// <summary>Tries the execute the incident.</summary>
        /// <param name="parms">The parms.</param>
        /// <returns></returns>
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            var map = (Map)parms.target;

            if (!TryFindEntryCell(map, out IntVec3 intVec))
            {
                return(false);
            }

            var pawnkinds = new List <string>
            {
                "Chaofox",
                "Chaodino",
                "Chaocow"
            };

            PawnKindDef animal = PawnKindDef.Named(pawnkinds.RandomElement());
            float       num    = StorytellerUtility.DefaultThreatPointsNow(map);
            int         num2   = GenMath.RoundRandom(num / animal.combatPower);
            int         max    = Rand.RangeInclusive(2, 4);

            num2 = Mathf.Clamp(num2, 1, max);
            int     num3    = Rand.RangeInclusive(90000, 150000);
            IntVec3 invalid = IntVec3.Invalid;

            if (!RCellFinder.TryFindRandomCellOutsideColonyNearTheCenterOfTheMap(intVec, map, 10f, out invalid))
            {
                invalid = IntVec3.Invalid;
            }

            Pawn pawn = null;

            for (var i = 0; i < num2; i++)
            {
                IntVec3 loc = CellFinder.RandomClosewalkCellNear(intVec, map, 10);
                pawn = PawnGenerator.GeneratePawn(animal);
                GenSpawn.Spawn(pawn, loc, map, Rot4.Random);
                pawn.mindState.exitMapAfterTick = Find.TickManager.TicksGame + num3;
                if (invalid.IsValid)
                {
                    pawn.mindState.forcedGotoPosition = CellFinder.RandomClosewalkCellNear(invalid, map, 10);
                }
            }

            Find.LetterStack.ReceiveLetter("LetterLabelChaomorphPasses".Translate(animal.label).CapitalizeFirst(),
                                           "LetterChaomorphPasses".Translate(animal.label), LetterDefOf.PositiveEvent, pawn);
            return(true);
        }
Ejemplo n.º 13
0
        // Token: 0x06000052 RID: 82 RVA: 0x000045CC File Offset: 0x000027CC
        public void JPImpact()
        {
            if (def.skyfaller.CausesExplosion)
            {
                GenExplosion.DoExplosion(Position, Map, def.skyfaller.explosionRadius, def.skyfaller.explosionDamage,
                                         null,
                                         GenMath.RoundRandom(def.skyfaller.explosionDamage.defaultDamage *
                                                             def.skyfaller.explosionDamageFactor));
            }

            for (var num = innerContainer.Count - 1; num >= 0; num--)
            {
                GenPlace.TryPlaceThing(innerContainer[num], Position, Map, ThingPlaceMode.Near,
                                       delegate(Thing thing, int _)
                {
                    PawnUtility.RecoverFromUnwalkablePositionOrKill(thing.Position, thing.Map);
                    if (thing.def.Fillage == FillCategory.Full && def.skyfaller.CausesExplosion &&
                        thing.Position.InHorDistOf(Position, def.skyfaller.explosionRadius))
                    {
                        Map.terrainGrid.Notify_TerrainDestroyed(thing.Position);
                    }
                });
            }

            innerContainer.ClearAndDestroyContents();
            var cellRect = this.OccupiedRect();

            for (var i = 0; i < cellRect.Area * def.skyfaller.motesPerCell; i++)
            {
                FleckMaker.ThrowDustPuff(cellRect.RandomVector3, Map, 2f);
            }

            if (def.skyfaller.MakesShrapnel)
            {
                SkyfallerShrapnelUtility.MakeShrapnel(Position, Map, shrapnelDirection,
                                                      def.skyfaller.shrapnelDistanceFactor, def.skyfaller.metalShrapnelCountRange.RandomInRange,
                                                      def.skyfaller.rubbleShrapnelCountRange.RandomInRange, true);
            }

            if (def.skyfaller.cameraShake > 0f && Map == Find.CurrentMap)
            {
                Find.CameraDriver.shaker.DoShake(def.skyfaller.cameraShake);
            }

            def.skyfaller.impactSound?.PlayOneShot(SoundInfo.InMap(new TargetInfo(Position, Map)));

            Destroy();
        }
Ejemplo n.º 14
0
        public override bool TryExecuteWorker(IncidentParms parms)
        {
            if (def.mechClusterBuilding == null)
            {
                return(false);
            }
            if (!def.mechClusterBuilding.HasModExtension <HiveDefExtension>())
            {
                return(false);
            }
            HiveDefExtension ext = def.mechClusterBuilding.GetModExtension <HiveDefExtension>();
            Map map = (Map)parms.target;

            if (parms.faction == null)
            {
                try
                {
                    IEnumerable <Faction> factions = Find.FactionManager.AllFactions.Where(x => x.def.defName.Contains(ext.Faction.defName));
                    if (!factions.EnumerableNullOrEmpty())
                    {
                        parms.faction = factions.RandomElement();
                    }
                    else
                    {
                        parms.faction = FactionGenerator.NewGeneratedFaction(new FactionGeneratorParms(ext.Faction));
                    }
                    //	Log.Message(parms.faction.def.defName);
                }
                catch (System.Exception)
                {
                    Faction faction = Find.FactionManager.FirstFactionOfDef(ext.Faction);
                    if (faction == null)
                    {
                        faction = FactionGenerator.NewGeneratedFaction(new FactionGeneratorParms(ext.Faction));
                    }
                    parms.faction = faction;
                }
            }
            CompProperties_SpawnerPawn spawnerPawn = def.mechClusterBuilding.GetCompProperties <CompProperties_SpawnerPawn>();
            float points = spawnerPawn?.initialPawnsPoints ?? 250f;
            int   count  = Mathf.Max(GenMath.RoundRandom(parms.points / points), 1);

            Thing t = InfestationUtility.SpawnTunnels(def.mechClusterBuilding, count, map, true, true, faction: parms.faction);

            SendStandardLetter(parms, t);
            Find.TickManager.slower.SignalForceNormalSpeedShort();
            return(true);
        }
Ejemplo n.º 15
0
        public static bool OnIntervalPassed(HediffGiver_Heat __instance, Pawn pawn, Hediff cause)
        {
            float  ambientTemperature        = pawn.AmbientTemperature;
            float  comfortableTemperatureMax = pawn.GetStatValue(StatDefOf.ComfyTemperatureMax, true);
            float  maxTemp          = comfortableTemperatureMax + 10f;
            Hediff firstHediffOfDef = pawn.health.hediffSet.GetFirstHediffOfDef(__instance.hediff, false);

            if (ambientTemperature > maxTemp)
            {
                float x         = ambientTemperature - maxTemp;
                float sevOffset = Mathf.Max(HediffGiver_Heat.TemperatureOverageAdjustmentCurve.Evaluate(x) * 6.45E-05f, 0.000375f);
                HealthUtility.AdjustSeverity(pawn, __instance.hediff, sevOffset);
            }
            else if (firstHediffOfDef != null && ambientTemperature < comfortableTemperatureMax)
            {
                float num = Mathf.Clamp(firstHediffOfDef.Severity * 0.027f, 0.0015f, 0.015f);
                firstHediffOfDef.Severity -= num;
            }
            if (pawn.Dead || !pawn.IsNestedHashIntervalTick(60, 420))
            {
                return(false);
            }

            float num4 = comfortableTemperatureMax + 150f;

            if (ambientTemperature <= num4)
            {
                return(false);
            }

            float      x1    = ambientTemperature - num4;
            int        num2  = Mathf.Max(GenMath.RoundRandom(HediffGiver_Heat.TemperatureOverageAdjustmentCurve.Evaluate(x1) * 0.06f), 3);
            DamageInfo dinfo = new DamageInfo(DamageDefOf.Burn, num2, 0f, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown, null);

            dinfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside);
            pawn.TakeDamage(dinfo);
            if (pawn.Faction == Faction.OfPlayer)
            {
                Find.TickManager.slower.SignalForceNormalSpeed();
                if (MessagesRepeatAvoider.MessageShowAllowed("PawnBeingBurned", 60f))
                {
                    Messages.Message("MessagePawnBeingBurned".Translate(pawn.LabelShort, pawn), pawn, MessageTypeDefOf.ThreatSmall, true);
                }
            }
            pawn.GetLord()?.ReceiveMemo(HediffGiver_Heat.MemoPawnBurnedByAir);

            return(false);
        }
        private void SetVars(Slate slate)
        {
            float x   = slate.Get("points", 0f);
            float num = pointsCurve.GetValue(slate).Evaluate(x);

            if (roundRandom.GetValue(slate))
            {
                num = GenMath.RoundRandom(num);
            }
            if (challengeRating.TryGetValue(slate, out int value))
            {
                switch (value)
                {
                case 1:
                    num = Mathf.Min(num, maxCountOneStar.GetValue(slate));
                    break;

                case 2:
                    num = Mathf.Min(num, maxCountTwoStar.GetValue(slate));
                    break;

                default:
                    num = Mathf.Min(num, maxCountThreeStar.GetValue(slate));
                    break;
                }
            }
            SimpleCurve value2 = chancesCurve.GetValue(slate);
            int         num2   = value2.Points.Count - 1;

            while (num2 >= 0)
            {
                if (value2.Points[num2].x > num)
                {
                    value2.Points[num2] = new CurvePoint(0f, 0f);
                    num2--;
                    continue;
                }
                value2.Points.Insert(num2 + 1, new CurvePoint(num + 1f, 0f));
                break;
            }
            float num3 = Rand.ByCurve(value2);

            if (roundRandom.GetValue(slate))
            {
                num3 = GenMath.RoundRandom(num3);
            }
            slate.Set(storeAs.GetValue(slate), Mathf.Clamp(num3, 1f, num));
        }
Ejemplo n.º 17
0
 public override void PostDestroy(DestroyMode mode, Map previousMap)
 {
     base.PostDestroy(mode, previousMap);
     if (previousMap != null && Props.fuelFilter.AllowedDefCount == 1 && Props.initialFuelPercent == 0f)
     {
         ThingDef thingDef = Props.fuelFilter.AllowedThingDefs.First();
         int      num      = GenMath.RoundRandom(1f * fuel);
         while (num > 0)
         {
             Thing thing = ThingMaker.MakeThing(thingDef);
             thing.stackCount = Mathf.Min(num, thingDef.stackLimit);
             num -= thing.stackCount;
             GenPlace.TryPlaceThing(thing, parent.Position, previousMap, ThingPlaceMode.Near);
         }
     }
 }
Ejemplo n.º 18
0
        public static IEnumerable <Thing> Postfix(IEnumerable <Thing> products, Pawn __instance, float efficiency)
        {
            foreach (Thing product in products)
            {
                yield return(product);
            }

            int boneCount = GenMath.RoundRandom(__instance.GetStatValue(MyDefOf.BoneAmount) * efficiency);

            if (boneCount > 0)
            {
                Thing bones = ThingMaker.MakeThing(BoneUtility.GetBoneProductFor(__instance));
                bones.stackCount = boneCount;
                yield return(bones);
            }
        }
Ejemplo n.º 19
0
        public override bool ManualDeterminParams()
        {
            Map map = (Map)parms.target;

            if (!RCellFinder.TryFindRandomPawnEntryCell(out EntryVec, map, CellFinder.EdgeRoadChance_Animal, false, null))
            {
                return(false);
            }
            if (!this.TryFindRandomPawnKind(map, out AnimalType))
            {
                return(false);
            }
            AnimalNum   = Mathf.Clamp(GenMath.RoundRandom(2.5f / AnimalType.RaceProps.baseBodySize), 2, 10);
            lookTargets = new TargetInfo(EntryVec, map, false);
            return(true);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            var        map = (Map)parms.target;
            HorrorHive t   = null;
            int        num;

            for (var i = Mathf.Max(GenMath.RoundRandom(parms.points / HivePoints), 1); i > 0; i -= num)
            {
                num = Mathf.Min(3, i);
                t   = SpawnHiveCluster(map);
            }

            SendStandardLetter(parms, t);
            Find.TickManager.slower.SignalForceNormalSpeedShort();
            return(true);
        }
Ejemplo n.º 21
0
        public override void CompTickRare()
        {
            float ambientTemperature = this.parent.AmbientTemperature;

            if (ambientTemperature < 0f)
            {
                return;
            }
            float f   = 0.15f * (ambientTemperature / 10f);
            int   num = GenMath.RoundRandom(f);

            if (num > 0)
            {
                this.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, num, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown));
            }
        }
Ejemplo n.º 22
0
 public override DamageWorker.DamageResult Apply(DamageInfo dinfo, Thing victim)
 {
     DamageWorker.DamageResult damageResult = new DamageWorker.DamageResult();
     if (victim.def.category == ThingCategory.Pawn && victim.def.useHitPoints && dinfo.Def.harmsHealth)
     {
         float amount = dinfo.Amount;
         damageResult.totalDamageDealt = (float)Mathf.Min(victim.HitPoints, GenMath.RoundRandom(amount));
         victim.HitPoints -= Mathf.RoundToInt(damageResult.totalDamageDealt);
         if (victim.HitPoints <= 0)
         {
             victim.HitPoints = 0;
             victim.Kill(new DamageInfo?(dinfo), null);
         }
     }
     return(damageResult);
 }
Ejemplo n.º 23
0
        public static void ApplyProperDamage(ref float damAmount, float armorRating, Thing armorThing, DamageDef damageDef)
        {
            if (tempDamageAmount != null && damAmount > 0)
            {
                float damageDiff = Mathf.Clamp(damAmount - tempDamageAmount.Value, 0, damAmount);

                //Log.Message("Apply amount original: " + damAmount);
                //Log.Message("Apply amount modified: " + tempDamageAmount.Value);
                damAmount        = GenMath.RoundRandom(tempDamageAmount.Value);
                tempDamageAmount = null;
                if (damageDiff > 0)
                {
                    tempDamageAbsorbed = GenMath.RoundRandom(damageDiff);
                }
            }
        }
Ejemplo n.º 24
0
        public override void Generate(Map map)
        {
            if (!Find.Storyteller.difficulty.allowCaveHives)
            {
                return;
            }
            CompProperties_TemperatureDamaged compProperties = ThingDefOf.Hive.GetCompProperties <CompProperties_TemperatureDamaged>();

            if (!compProperties.safeTemperatureRange.Includes(map.mapTemperature.OutdoorTemp))
            {
                return;
            }
            MapGenFloatGrid caves     = MapGenerator.Caves;
            MapGenFloatGrid elevation = MapGenerator.Elevation;
            float           num       = 0.7f;
            int             num2      = 0;

            this.rockCells.Clear();
            foreach (IntVec3 current in map.AllCells)
            {
                if (elevation[current] > num)
                {
                    this.rockCells.Add(current);
                }
                if (caves[current] > 0f)
                {
                    num2++;
                }
            }
            int num3 = GenMath.RoundRandom((float)num2 / 1000f);

            GenMorphology.Erode(this.rockCells, 10, map, null);
            this.possibleSpawnCells.Clear();
            for (int i = 0; i < this.rockCells.Count; i++)
            {
                if (caves[this.rockCells[i]] > 0f)
                {
                    this.possibleSpawnCells.Add(this.rockCells[i]);
                }
            }
            this.spawnedHives.Clear();
            for (int j = 0; j < num3; j++)
            {
                this.TrySpawnHive(map);
            }
            this.spawnedHives.Clear();
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map     map = (Map)parms.target;
            IntVec3 intVec;

            if (!this.TryFindEntryCell(map, out intVec))
            {
                return(false);
            }
            PawnKindDef thrumbo = PawnKindDefOf.Thrumbo;
            float       num     = StorytellerUtility.DefaultThreatPointsNow(map);
            int         num2    = GenMath.RoundRandom(num / thrumbo.combatPower);
            int         max     = Rand.RangeInclusive(2, 4);

            num2 = Mathf.Clamp(num2, 1, max);
            int     num3    = Rand.RangeInclusive(90000, 150000);
            IntVec3 invalid = IntVec3.Invalid;

            if (!RCellFinder.TryFindRandomCellOutsideColonyNearTheCenterOfTheMap(intVec, map, 10f, out invalid))
            {
                invalid = IntVec3.Invalid;
            }
            Pawn pawn = null;

            for (int i = 0; i < num2; i++)
            {
                IntVec3 loc = CellFinder.RandomClosewalkCellNear(intVec, map, 10, null);
                pawn = PawnGenerator.GeneratePawn(thrumbo, null);
                GenSpawn.Spawn(pawn, loc, map, Rot4.Random, WipeMode.Vanish, false);
                pawn.mindState.exitMapAfterTick = Find.TickManager.TicksGame + num3;
                if (invalid.IsValid)
                {
                    pawn.mindState.forcedGotoPosition = CellFinder.RandomClosewalkCellNear(invalid, map, 10, null);
                }
            }

            var text = "LetterThrumboPasses".Translate(thrumbo.label);

            if (Quote != null)
            {
                text += "\n\n";
                text += Quote;
            }

            Find.LetterStack.ReceiveLetter("LetterLabelThrumboPasses".Translate(thrumbo.label).CapitalizeFirst(), text, LetterDefOf.PositiveEvent, pawn, null, null);
            return(true);
        }
 public override void Generate(Map map, GenStepParams parms)
 {
     if (Find.Storyteller.difficulty.allowCaveHives)
     {
         CompProperties_TemperatureDamaged compProperties = ThingDefOf.Hive.GetCompProperties <CompProperties_TemperatureDamaged>();
         if (compProperties.safeTemperatureRange.Includes(map.mapTemperature.OutdoorTemp))
         {
             MapGenFloatGrid caves     = MapGenerator.Caves;
             MapGenFloatGrid elevation = MapGenerator.Elevation;
             float           num       = 0.7f;
             int             num2      = 0;
             this.rockCells.Clear();
             foreach (IntVec3 intVec in map.AllCells)
             {
                 if (elevation[intVec] > num)
                 {
                     this.rockCells.Add(intVec);
                 }
                 if (caves[intVec] > 0f)
                 {
                     num2++;
                 }
             }
             List <IntVec3> list = (from c in map.AllCells
                                    where map.thingGrid.ThingsAt(c).Any((Thing thing) => thing.Faction != null)
                                    select c).ToList <IntVec3>();
             GenMorphology.Dilate(list, 50, map, null);
             HashSet <IntVec3> hashSet = new HashSet <IntVec3>(list);
             int num3 = GenMath.RoundRandom((float)num2 / 1000f);
             GenMorphology.Erode(this.rockCells, 10, map, null);
             this.possibleSpawnCells.Clear();
             for (int i = 0; i < this.rockCells.Count; i++)
             {
                 if (caves[this.rockCells[i]] > 0f && !hashSet.Contains(this.rockCells[i]))
                 {
                     this.possibleSpawnCells.Add(this.rockCells[i]);
                 }
             }
             this.spawnedHives.Clear();
             for (int j = 0; j < num3; j++)
             {
                 this.TrySpawnHive(map);
             }
             this.spawnedHives.Clear();
         }
     }
 }
Ejemplo n.º 27
0
        // Token: 0x06000006 RID: 6 RVA: 0x000020C4 File Offset: 0x000002C4
        protected override void ApplySpecialEffectsToPart(Pawn pawn, float totalDamage, DamageInfo dinfo, DamageWorker.DamageResult result)
        {
            base.ApplySpecialEffectsToPart(pawn, totalDamage, dinfo, result);
            Map mapHeld = pawn.MapHeld;
            DamageDefExtension damageDefExtension = dinfo.Def.GetModExtension <DamageDefExtension>() ?? DamageDefExtension.defaultValues;
            int     num  = GenMath.RoundRandom(totalDamage * damageDefExtension.knockbackDistancePerDamageDealt * (damageDefExtension.scaleKnockbackWithBodySize ? (1f / pawn.BodySize) : 1f));
            IntVec3 b    = CyberneticWarfareUtility.IntVec3FromDirection8Way(CyberneticWarfareUtility.Direction8WayFromAngle((pawn.PositionHeld - dinfo.Instigator.PositionHeld).AngleFlat));
            bool    flag = num > 0;

            if (flag)
            {
                float num2 = (float)damageDefExtension.stunDuration;
                for (int i = 0; i < num; i++)
                {
                    IntVec3 c     = pawn.PositionHeld + b;
                    bool    flag2 = !c.InBounds(mapHeld);
                    if (flag2)
                    {
                        break;
                    }
                    bool flag3 = c.Impassable(mapHeld);
                    if (flag3)
                    {
                        num2 *= damageDefExtension.hitBuildingStunDurationFactor;
                        break;
                    }
                    IThingHolder parentHolder = pawn.ParentHolder;
                    Corpse       corpse       = parentHolder as Corpse;
                    bool         flag4        = corpse != null;
                    if (flag4)
                    {
                        corpse.Position += b;
                    }
                    pawn.Position += b;
                }
                bool flag5 = !pawn.Dead;
                if (flag5)
                {
                    pawn.Notify_Teleported(true, false);
                }
                bool flag6 = num2 > 0f && pawn.stances != null;
                if (flag6)
                {
                    pawn.stances.stunner.StunFor(GenMath.RoundRandom(num2), dinfo.Instigator);
                }
            }
        }
Ejemplo n.º 28
0
        private Action PrepDrawRoad(Map map, TerrainDef rockDef, IntVec3 start, IntVec3 end, RoadDef roadDef, RoadPathingDef pathingDef, out IntVec3 centerpoint)
        {
            centerpoint = IntVec3.Invalid;
            PawnPath pawnPath = map.pathFinder.FindPath(start, end, TraverseParms.For(TraverseMode.NoPassClosedDoorsOrWater));

            if (pawnPath == PawnPath.NotFound)
            {
                pawnPath = map.pathFinder.FindPath(start, end, TraverseParms.For(TraverseMode.NoPassClosedDoors));
            }
            if (pawnPath == PawnPath.NotFound)
            {
                pawnPath = map.pathFinder.FindPath(start, end, TraverseParms.For(TraverseMode.PassAllDestroyableThingsNotWater));
            }
            if (pawnPath == PawnPath.NotFound)
            {
                pawnPath = map.pathFinder.FindPath(start, end, TraverseParms.For(TraverseMode.PassAllDestroyableThings));
            }
            if (pawnPath == PawnPath.NotFound)
            {
                return(null);
            }
            List <IntVec3> list = RefinePath(pawnPath.NodesReversed, map);

            pawnPath.ReleaseToPool();
            DistanceElement[,] distance = new DistanceElement[map.Size.x, map.Size.z];
            for (int i = 0; i < distance.GetLength(0); i++)
            {
                for (int j = 0; j < distance.GetLength(1); j++)
                {
                    distance[i, j].origin = IntVec3.Invalid;
                }
            }
            int count            = list.Count;
            int centerpointIndex = Mathf.RoundToInt(Rand.Range(0.3f, 0.7f) * (float)count);
            int num = Mathf.Max(1, GenMath.RoundRandom((float)count / (float)roadDef.tilesPerSegment));

            for (int k = 0; k < num; k++)
            {
                int pathStartIndex = Mathf.RoundToInt((float)(count - 1) / (float)num * (float)k);
                int pathEndIndex   = Mathf.RoundToInt((float)(count - 1) / (float)num * (float)(k + 1));
                DrawCurveSegment(distance, list, pathStartIndex, pathEndIndex, pathingDef, map, centerpointIndex, ref centerpoint);
            }
            return(delegate
            {
                ApplyDistanceField(distance, map, rockDef, roadDef, pathingDef);
            });
        }
Ejemplo n.º 29
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map     map = (Map)parms.target;
            IntVec3 intVec;
            bool    flag  = !this.TryFindEntryCell(map, out intVec);
            bool    flag2 = flag;
            bool    result;

            if (flag2)
            {
                result = false;
            }
            else
            {
                PawnKindDef fO_Behemoth = ForsakensFF_DefOf.FO_Behemoth;
                float       num         = StorytellerUtility.DefaultThreatPointsNow(map);
                int         num2        = GenMath.RoundRandom(num / fO_Behemoth.combatPower);
                int         num3        = Rand.RangeInclusive(1, 4);
                num2 = Mathf.Clamp(num2, 1, num3);
                int     num4    = Rand.RangeInclusive(90000, 150000);
                IntVec3 invalid = IntVec3.Invalid;
                bool    flag3   = !RCellFinder.TryFindRandomCellOutsideColonyNearTheCenterOfTheMap(intVec, map, 10f, out invalid);
                bool    flag4   = flag3;
                if (flag4)
                {
                    invalid = IntVec3.Invalid;
                }
                Pawn pawn = null;
                for (int i = 0; i < num2; i++)
                {
                    IntVec3 intVec2 = CellFinder.RandomClosewalkCellNear(intVec, map, 10, null);
                    pawn = PawnGenerator.GeneratePawn(fO_Behemoth, null);
                    GenSpawn.Spawn(pawn, intVec2, map, Rot4.Random, 0, false);
                    pawn.mindState.exitMapAfterTick = Find.TickManager.TicksGame + num4;
                    bool isValid = invalid.IsValid;
                    bool flag5   = isValid;
                    if (flag5)
                    {
                        pawn.mindState.forcedGotoPosition = CellFinder.RandomClosewalkCellNear(invalid, map, 10, null);
                    }
                }
                map.weatherManager.TransitionTo(ForsakensFF_DefOf.DryThunderstorm);
                Find.LetterStack.ReceiveLetter("LetterLabelBehemotPasses".Translate(fO_Behemoth.label), "LetterBehemotPasses".Translate(fO_Behemoth.label), LetterDefOf.PositiveEvent, pawn, null, null);
                result = true;
            }
            return(result);
        }
Ejemplo n.º 30
0
        public override void Generate(Map map, GenStepParams parms)
        {
            if (!Find.Storyteller.difficulty.allowCaveHives)
            {
                return;
            }
            MapGenFloatGrid caves     = MapGenerator.Caves;
            MapGenFloatGrid elevation = MapGenerator.Elevation;
            float           num       = 0.7f;
            int             num2      = 0;

            this.rockCells.Clear();
            foreach (IntVec3 current in map.AllCells)
            {
                if (elevation[current] > num)
                {
                    this.rockCells.Add(current);
                }
                if (caves[current] > 0f)
                {
                    num2++;
                }
            }
            List <IntVec3> list = (from c in map.AllCells
                                   where map.thingGrid.ThingsAt(c).Any((Thing thing) => thing.Faction != null)
                                   select c).ToList <IntVec3>();

            GenMorphology.Dilate(list, 50, map, null);
            HashSet <IntVec3> hashSet = new HashSet <IntVec3>(list);
            int num3 = GenMath.RoundRandom((float)num2 / 1000f);

            GenMorphology.Erode(this.rockCells, 10, map, null);
            this.possibleSpawnCells.Clear();
            for (int i = 0; i < this.rockCells.Count; i++)
            {
                if (caves[this.rockCells[i]] > 0f && !hashSet.Contains(this.rockCells[i]))
                {
                    this.possibleSpawnCells.Add(this.rockCells[i]);
                }
            }
            this.spawnedHives.Clear();
            for (int j = 0; j < num3; j++)
            {
                this.TrySpawnHive(map);
            }
            this.spawnedHives.Clear();
        }