private void TimeEvents_DayOfMonthChanged(object sender, EventArgsIntChanged e)
 {
     if (_config.EnableMod)
     {
         Monitor.Log("It's a new day. Resetting the Item Collector mod");
         _machinesProcessor.ValidateGameLocations();
         _buildingProcessor.DailyReset();
         _machinesProcessor.DailyReset();
     }
 }
예제 #2
0
        public override void Entry(params object[] objects)
        {
            base.Entry(objects);
            GameEvents.GameLoaded += (s, e) => { _gameLoaded = true; };

            TimeEvents.DayOfMonthChanged += (s, e) =>
            {
                if (_config.EnableMod)
                {
                    Log.Debug("It's a new day. Resetting the Item Collector mod");
                    _machinesProcessor.ValidateGameLocations();
                    _animalHouseProcessor.DailyReset();
                    _machinesProcessor.DailyReset();
                }
            };
            TimeEvents.TimeOfDayChanged += (s, e) =>
            {
                if (_gameLoaded && _config.EnableMod)
                {
                    try
                    {
                        _animalHouseProcessor.ProcessAnimalBuildings();
                        _machinesProcessor.ProcessMachines();
                    }
                    catch (Exception ex)
                    {
                        Log.Error($"an error occured with the automation mod: {ex}");
                        _machinesProcessor.DailyReset();
                    }
                }
            };
            PlayerEvents.InventoryChanged += (s, c) =>
            {
                if (_gameLoaded && ItemFinder.HaveConnectorsInInventoryChanged(c))
                {
                    try
                    {
                        _animalHouseProcessor.DailyReset();
                        _machinesProcessor.InvalidateCacheForLocation(Game1.player.currentLocation);
                    }
                    catch (Exception ex)
                    {
                        Log.Error($"an error occured with the automation mod: {ex}");
                        _machinesProcessor.DailyReset();
                    }
                }
            };
#if DEBUG
            // allow keypresses to initiate events for easier debugging.
            ControlEvents.KeyPressed += (s, c) =>
            {
                if (_gameLoaded && c.KeyPressed == Keys.K)
                {
                    _animalHouseProcessor.ProcessAnimalBuildings();
                    _machinesProcessor.ProcessMachines();
                }
                if (_gameLoaded && c.KeyPressed == Keys.P)
                {
                    _animalHouseProcessor.DailyReset();
                    _machinesProcessor.DailyReset();
                }
            };
#endif
        }