Example #1
0
        public void PerformChannelingTreatment()
        {
            this.channelingTicksCounter++;

            if (this.channelingTicksCounter == 1)
            {
                Find.WeatherManager.TransitionTo(Util_MechanoidTerraformer.TerraformingThunderstormDef);
            }
            else if ((this.channelingTicksCounter >= channelingWithoutStrikesTicks) &&
                     (this.channelingTicksCounter < channelingWithoutStrikesTicks + channelingWithStrikesTicks))
            {
                if (Rand.Value < chanceToStrikePerTick)
                {
                    IntVec3 strikePosition = new IntVec3();
                    if (Rand.Value < 0.5f)
                    {
                        // Strike on a nearby pawn.
                        List <Pawn> nearbyPawns = new List <Pawn>();
                        foreach (Pawn pawn in Find.ListerPawns.AllPawns)
                        {
                            if (pawn.Position.InHorDistOf(base.forcedTarget.Cell, this.areaOfEffectRadius))
                            {
                                nearbyPawns.Add(pawn);
                            }
                        }
                        if (nearbyPawns.Count > 0)
                        {
                            strikePosition = nearbyPawns.RandomElement <Pawn>().Position;
                            WeatherEvent_LightningStrike lightningStrike = new WeatherEvent_LightningStrike(strikePosition);
                            Find.WeatherManager.eventHandler.AddEvent(lightningStrike);
                        }
                    }
                    else
                    {
                        Predicate <IntVec3> validator = (IntVec3 cell) =>
                                                        cell.Walkable() &&
                                                        (Find.RoofGrid.Roofed(cell) == false) &&
                                                        cell.InHorDistOf(base.forcedTarget.Cell, this.def.building.turretGunDef.Verbs[0].projectileDef.projectile.explosionRadius);
                        strikePosition = CellFinderLoose.RandomCellWith(validator);
                        WeatherEvent_LightningStrike lightningStrike = new WeatherEvent_LightningStrike(strikePosition);
                        Find.WeatherManager.eventHandler.AddEvent(lightningStrike);
                    }
                }
            }
            else if (this.channelingTicksCounter == channelingWithoutStrikesTicks + channelingWithStrikesTicks)
            {
                Find.WeatherManager.TransitionTo(WeatherDef.Named("Clear"));
            }
            else if (this.channelingTicksCounter == 2 * channelingWithoutStrikesTicks + channelingWithStrikesTicks)
            {
                this.charge = 0;
                this.channelingTicksCounter = 0;
                this.skywrathState          = SkywrathState.Charging;
            }
        }
Example #2
0
 public void TryFireLightningStrikeOnPylon()
 {
     if (Rand.Value < (float)this.pylonsList.Count * strikeChancePerPylon)
     {
         if (this.pylonsList.Count > 0)
         {
             IntVec3 strikePosition = this.pylonsList.RandomElement <Thing>().Position;
             WeatherEvent_LightningStrike lightningStrike = new WeatherEvent_LightningStrike(strikePosition);
             Find.WeatherManager.eventHandler.AddEvent(lightningStrike);
         }
     }
 }
Example #3
0
 private static bool Prefix(WeatherEvent_LightningStrike __instance, Map ___map)
 {
     try
     {
         var ZTracker = ZUtils.ZTracker;
         if (ZTracker.ZLevelsTracker != null && ZTracker.ZLevelsTracker.ContainsKey(___map.Tile) &&
             ZTracker.GetZIndexFor(___map) > 0)
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         Log.Error("[Z-Levels] Patch_WeatherManager patch produced an error. That should not happen and will break things. Send a Hugslib log to the Z-Levels developers. Error message: " + ex, true);
     }
     return(true);
 }
Example #4
0
 private static bool Prefix(WeatherEvent_LightningStrike __instance)
 {
     try
     {
         Map map      = Traverse.Create(__instance).Field("map").GetValue <Map>();
         var ZTracker = Current.Game.GetComponent <ZLevelsManager>();
         if (ZTracker.ZLevelsTracker != null && ZTracker.ZLevelsTracker.ContainsKey(map.Tile) && ZTracker.GetZIndexFor(map) > 0)
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         Log.Error("[Z-Levels] Patch_WeatherManager patch produced an error. That should not happen and will break things. Send a Hugslib log to the Z-Levels developers. Error message: " + ex, true);
     }
     return(true);
 }
        public void PerformChannelingTreatment()
        {
            this.channelingTicksCounter++;

            if (this.channelingTicksCounter == 1)
            {
                Find.WeatherManager.TransitionTo(Util_MechanoidTerraformer.TerraformingThunderstormDef);
            }
            else if ((this.channelingTicksCounter >= channelingWithoutStrikesTicks)
                && (this.channelingTicksCounter < channelingWithoutStrikesTicks + channelingWithStrikesTicks))
            {
                if (Rand.Value < chanceToStrikePerTick)
                {
                    IntVec3 strikePosition = new IntVec3();
                    if (Rand.Value < 0.5f)
                    {
                        // Strike on a nearby pawn.
                        List<Pawn> nearbyPawns = new List<Pawn>();
                        foreach (Pawn pawn in Find.ListerPawns.AllPawns)
                        {
                            if (pawn.Position.InHorDistOf(base.forcedTarget.Cell, this.areaOfEffectRadius))
                            {
                                nearbyPawns.Add(pawn);
                            }
                        }
                        if (nearbyPawns.Count > 0)
                        {
                            strikePosition = nearbyPawns.RandomElement<Pawn>().Position;
                            WeatherEvent_LightningStrike lightningStrike = new WeatherEvent_LightningStrike(strikePosition);
                            Find.WeatherManager.eventHandler.AddEvent(lightningStrike);
                        }
                    }
                    else
                    {
                        Predicate<IntVec3> validator = (IntVec3 cell) =>
                            cell.Walkable()
                            && (Find.RoofGrid.Roofed(cell) == false)
                            && cell.InHorDistOf(base.forcedTarget.Cell, this.def.building.turretGunDef.Verbs[0].projectileDef.projectile.explosionRadius);
                        strikePosition = CellFinderLoose.RandomCellWith(validator);
                        WeatherEvent_LightningStrike lightningStrike = new WeatherEvent_LightningStrike(strikePosition);
                        Find.WeatherManager.eventHandler.AddEvent(lightningStrike);
                    }
                }
            }
            else if (this.channelingTicksCounter == channelingWithoutStrikesTicks + channelingWithStrikesTicks)
            {
                Find.WeatherManager.TransitionTo(WeatherDef.Named("Clear"));
            }
            else if (this.channelingTicksCounter == 2 * channelingWithoutStrikesTicks + channelingWithStrikesTicks)
            {
                this.charge = 0;
                this.channelingTicksCounter = 0;
                this.skywrathState = SkywrathState.Charging;
            }
        }
 public void TryFireLightningStrikeOnPylon()
 {
     if (Rand.Value < (float)this.pylonsList.Count * strikeChancePerPylon)
     {
         if (this.pylonsList.Count > 0)
         {
             IntVec3 strikePosition = this.pylonsList.RandomElement<Thing>().Position;
             WeatherEvent_LightningStrike lightningStrike = new WeatherEvent_LightningStrike(strikePosition);
             Find.WeatherManager.eventHandler.AddEvent(lightningStrike);
         }
     }
 }