Exemple #1
0
        /// <summary>
        ///     Safe Lightning initialization. Sets up console commands, lightning detectors and resolvers, and subscribes to
        ///     events.
        /// </summary>
        /// <param name="helper">The mod helper</param>
        public override void Entry(IModHelper helper)
        {
            new CommandParser(this);

            //Add detectors
            this.lightningDetectors = new List <IResultDetector>
            {
                new CropKilledDetector(),
                new FruitTreeCoalDetector(),
                new RemovedFeatureDetector(),
                new TreeFallingDetector(helper.Reflection)
            };

            this.Monitor.Log($"Loaded {this.lightningDetectors.Count} detectors.", LogLevel.Trace);

            //Add resolvers
            IResultResolver crop    = new CropKilledResolver(this.Monitor);
            IResultResolver fruit   = new FruitTreeCoalResolver(this.Monitor);
            IResultResolver removed = new RemovedFeatureResolver(this.Monitor);
            IResultResolver falling = new TreeFallingResolver(helper.Reflection, this.Monitor);

            this.lightningResolvers = new Dictionary <LightningStrikeResult, IResultResolver>
            {
                { crop.Result, crop },
                { fruit.Result, fruit },
                { removed.Result, removed },
                { falling.Result, falling }
            };

            this.Monitor.Log($"Loaded {this.lightningDetectors.Count} resolvers.", LogLevel.Trace);

            SaveEvents.AfterLoad          += this.AfterLoad;
            SaveEvents.AfterReturnToTitle += (sender, args) => this.Unsubscribe();
        }
Exemple #2
0
        /// <summary>
        /// Safe Lightning initialization. Sets up console commands, lightning detectors and resolvers, and subscribes to events.
        /// </summary>
        /// <param name="helper">The mod helper</param>
        public override void Entry(IModHelper helper)
        {
            new CommandParser(this);

            //Add detectors
            lightningDetectors = new List <IResultDetector>
            {
                new CropKilledDetector(),
                new FruitTreeCoalDetector(),
                new RemovedFeatureDetector(),
                new TreeFallingDetector(helper.Reflection)
            };

            Monitor.Log($"Loaded {lightningDetectors.Count} detectors.", LogLevel.Trace);

            //Add resolvers
            IResultResolver crop    = new CropKilledResolver(Monitor);
            IResultResolver fruit   = new FruitTreeCoalResolver(Monitor);
            IResultResolver removed = new RemovedFeatureResolver(Monitor);
            IResultResolver falling = new TreeFallingResolver(helper.Reflection, Monitor);

            lightningResolvers = new Dictionary <LightningStrikeResult, IResultResolver>
            {
                { crop.Result, crop },
                { fruit.Result, fruit },
                { removed.Result, removed },
                { falling.Result, falling }
            };

            Monitor.Log($"Loaded {lightningDetectors.Count} resolvers.", LogLevel.Trace);

            GameEvents.UpdateTick += this.UpdateTick;

            //To handle overnight lightning
            SaveEvents.BeforeSave += this.BeforeSave;
        }