/// <summary>
        /// Gets the non lightning rod <see cref="TerrainFeature"/> that will be hit today under the given RNG info.
        /// </summary>
        /// <param name="when">The time the strike will hit</param>
        /// <param name="feature">The <see cref="TerrainFeature"/> hit, or null if none was hit</param>
        /// <returns>Whether a <see cref="TerrainFeature"/> was hit</returns>
        internal static bool GetSDVLightningStrikePositionAt(LightningStrikeRNGInfo info, out KeyValuePair <Vector2, TerrainFeature>?feature)
        {
            feature = null;
            if (!info.isLightning || Game1.timeOfDay > 2400 || Game1.getFarm().terrainFeatures.Count == 0)
            {
                return(false);
            }

            Random random = info.GetRandom();

            if (random.NextDouble() < 0.125 + info.dailyLuck + info.luckLevel / 100.0)
            {
                if (Game1.currentLocation.IsOutdoors && !(Game1.currentLocation is Desert) && !Game1.newDay)
                {
                    random.NextDouble();
                }

                GameLocation   locationFromName = Game1.getLocationFromName("Farm");
                List <Vector2> source           = new List <Vector2>();
                foreach (KeyValuePair <Vector2, SObject> keyValuePair in locationFromName.objects)
                {
                    if (keyValuePair.Value.bigCraftable && keyValuePair.Value.ParentSheetIndex == 9)
                    {
                        source.Add(keyValuePair.Key);
                    }
                }
                if (source.Count > 0)
                {
                    for (int index1 = 0; index1 < 2; ++index1)
                    {
                        Vector2 index2 = source.ElementAt(random.Next(source.Count));
                        if (locationFromName.objects[index2].heldObject == null)
                        {
                            return(false);
                        }
                    }
                }
                if (random.NextDouble() >= 0.25 - info.dailyLuck - info.luckLevel / 100.0)
                {
                    return(false);
                }

                feature = locationFromName.terrainFeatures.ElementAt(random.Next(locationFromName.terrainFeatures.Count));

                return(true);
            }
            return(false);
        }
Exemple #2
0
        /// <summary>
        ///     Run an exact copy of SDV's lightning code, using custom RNG paremeters.
        /// </summary>
        /// <param name="info">RNG parameters to use</param>
        internal static void CauseVanillaStrike(LightningStrikeRNGInfo info)
        {
            Random random = info.GetRandom();

            if (random.NextDouble() < 0.125 + info.dailyLuck + info.luckLevel / 100.0)
            {
                if (Game1.currentLocation.IsOutdoors && !(Game1.currentLocation is Desert) && !Game1.newDay)
                {
                    Game1.flashAlpha = (float)(0.5 + random.NextDouble());
                    Game1.playSound("thunder");
                }

                GameLocation   locationFromName = Game1.getLocationFromName("Farm");
                List <Vector2> source           = new List <Vector2>();
                foreach (KeyValuePair <Vector2, SObject> keyValuePair in (Dictionary <Vector2, SObject>)locationFromName
                         .Objects.Pairs)
                {
                    if (keyValuePair.Value.bigCraftable.Value && keyValuePair.Value.ParentSheetIndex == 9)
                    {
                        source.Add(keyValuePair.Key);
                    }
                }
                if (source.Count > 0)
                {
                    for (int index1 = 0; index1 < 2; ++index1)
                    {
                        Vector2 index2 = source.ElementAt(random.Next(source.Count));
                        if (locationFromName.objects[index2].heldObject.Value == null)
                        {
                            locationFromName.objects[index2].heldObject.Value  = new SObject(787, 1, false, -1, 0);
                            locationFromName.objects[index2].MinutesUntilReady = 3000 - Game1.timeOfDay;
                            locationFromName.objects[index2].shakeTimer        = 1000;
                            if (!(Game1.currentLocation is Farm))
                            {
                                return;
                            }
                            Utility.drawLightningBolt(index2 * Game1.tileSize + new Vector2(Game1.tileSize / 2, 0.0f),
                                                      locationFromName);
                            return;
                        }
                    }
                }

                if (random.NextDouble() >= 0.25 - info.dailyLuck - info.luckLevel / 100.0)
                {
                    return;
                }
                try
                {
                    KeyValuePair <Vector2, TerrainFeature> keyValuePair =
                        locationFromName.terrainFeatures.Pairs.ElementAt <KeyValuePair <Vector2, TerrainFeature> >(
                            random.Next(locationFromName.terrainFeatures.Count()));
                    if (!(keyValuePair.Value is FruitTree) &&
                        keyValuePair.Value.performToolAction(null, 50, keyValuePair.Key, locationFromName))
                    {
                        locationFromName.terrainFeatures.Remove(keyValuePair.Key);
                        if (!Game1.currentLocation.Name.Equals("Farm"))
                        {
                            return;
                        }
                        locationFromName.temporarySprites.Add(
                            new TemporaryAnimatedSprite(362, 75f, 6, 1, keyValuePair.Key, false, false));
                        Utility.drawLightningBolt(
                            keyValuePair.Key * Game1.tileSize + new Vector2(Game1.tileSize / 2, -Game1.tileSize * 2),
                            locationFromName);
                    }
                    else
                    {
                        if (!(keyValuePair.Value is FruitTree fruitTree))
                        {
                            return;
                        }
                        fruitTree.struckByLightningCountdown.Value = 4;
                        fruitTree.shake(keyValuePair.Key, true);
                        Utility.drawLightningBolt(
                            keyValuePair.Key * Game1.tileSize + new Vector2(Game1.tileSize / 2, -Game1.tileSize * 2),
                            locationFromName);
                    }
                }
                catch
                {
                }
            }
            else
            {
                if (random.NextDouble() >= 0.1 || !Game1.currentLocation.IsOutdoors ||
                    Game1.currentLocation is Desert || Game1.newDay)
                {
                    return;
                }
                Game1.flashAlpha = (float)(0.5 + random.NextDouble());
                if (random.NextDouble() < 0.5)
                {
                    DelayedAction.screenFlashAfterDelay((float)(0.3 + random.NextDouble()), random.Next(500, 1000),
                                                        "");
                }
                DelayedAction.playSoundAfterDelay("thunder_small", random.Next(500, 1500));
            }
        }