/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="location">The location to track.</param> public LocationTracker(GameLocation location) { this.Location = location; // init watchers this.BuildingsWatcher = location is BuildableGameLocation buildableLocation?WatcherFactory.ForNetCollection(buildableLocation.buildings) : WatcherFactory.ForImmutableCollection <Building>(); this.DebrisWatcher = WatcherFactory.ForNetCollection(location.debris); this.LargeTerrainFeaturesWatcher = WatcherFactory.ForNetCollection(location.largeTerrainFeatures); this.NpcsWatcher = WatcherFactory.ForNetCollection(location.characters); this.ObjectsWatcher = WatcherFactory.ForNetDictionary(location.netObjects); this.TerrainFeaturesWatcher = WatcherFactory.ForNetDictionary(location.terrainFeatures); this.FurnitureWatcher = WatcherFactory.ForNetCollection(location.furniture); this.Watchers.AddRange(new IWatcher[] { this.BuildingsWatcher, this.DebrisWatcher, this.LargeTerrainFeaturesWatcher, this.NpcsWatcher, this.ObjectsWatcher, this.TerrainFeaturesWatcher, this.FurnitureWatcher }); this.UpdateChestWatcherList(added: location.Objects.Pairs, removed: Array.Empty <KeyValuePair <Vector2, SObject> >()); }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="location">The location to track.</param> public LocationTracker(GameLocation location) { this.Location = location; // init watchers this.BuildingsWatcher = location is BuildableGameLocation buildableLocation ? WatcherFactory.ForNetCollection(buildableLocation.buildings) : (ICollectionWatcher <Building>)WatcherFactory.ForObservableCollection(new ObservableCollection <Building>()); this.DebrisWatcher = WatcherFactory.ForNetCollection(location.debris); this.LargeTerrainFeaturesWatcher = WatcherFactory.ForNetCollection(location.largeTerrainFeatures); this.NpcsWatcher = WatcherFactory.ForNetCollection(location.characters); this.ObjectsWatcher = WatcherFactory.ForNetDictionary(location.netObjects); this.TerrainFeaturesWatcher = WatcherFactory.ForNetDictionary(location.terrainFeatures); this.Watchers.AddRange(new IWatcher[] { this.BuildingsWatcher, this.DebrisWatcher, this.LargeTerrainFeaturesWatcher, this.NpcsWatcher, this.ObjectsWatcher, this.TerrainFeaturesWatcher }); }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="player">The player to track.</param> public PlayerTracker(Farmer player) { // init player data this.Player = player; this.PreviousInventory = this.GetInventory(); // init trackers this.LocationWatcher = WatcherFactory.ForReference(this.GetCurrentLocation); this.LocationObjectsWatcher = WatcherFactory.ForNetDictionary(this.GetCurrentLocation().netObjects); this.MineLevelWatcher = WatcherFactory.ForEquatable(() => this.LastValidLocation is MineShaft mine ? mine.mineLevel : 0); this.SkillWatchers = new Dictionary <EventArgsLevelUp.LevelType, IValueWatcher <int> > { [EventArgsLevelUp.LevelType.Combat] = WatcherFactory.ForEquatable(() => player.combatLevel), [EventArgsLevelUp.LevelType.Farming] = WatcherFactory.ForEquatable(() => player.farmingLevel), [EventArgsLevelUp.LevelType.Fishing] = WatcherFactory.ForEquatable(() => player.fishingLevel), [EventArgsLevelUp.LevelType.Foraging] = WatcherFactory.ForEquatable(() => player.foragingLevel), [EventArgsLevelUp.LevelType.Luck] = WatcherFactory.ForEquatable(() => player.luckLevel), [EventArgsLevelUp.LevelType.Mining] = WatcherFactory.ForEquatable(() => player.miningLevel) }; // track watchers for convenience this.Watchers.AddRange(new IWatcher[] { this.LocationWatcher, this.LocationObjectsWatcher, this.MineLevelWatcher }); this.Watchers.AddRange(this.SkillWatchers.Values); }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="location">The location to track.</param> public LocationTracker(GameLocation location) { this.Location = location; // init watchers this.ObjectsWatcher = WatcherFactory.ForNetDictionary(location.netObjects); this.BuildingsWatcher = location is BuildableGameLocation buildableLocation ? WatcherFactory.ForNetCollection(buildableLocation.buildings) : (ICollectionWatcher <Building>)WatcherFactory.ForObservableCollection(new ObservableCollection <Building>()); this.Watchers.AddRange(new IWatcher[] { this.BuildingsWatcher, this.ObjectsWatcher }); }
/// <summary>Update the current values if needed.</summary> public void Update() { // update valid location this.LastValidLocation = this.GetCurrentLocation(); // update watchers foreach (IWatcher watcher in this.Watchers) { watcher.Update(); } // replace location objects watcher if (this.LocationWatcher.IsChanged) { this.Watchers.Remove(this.LocationObjectsWatcher); this.LocationObjectsWatcher.Dispose(); this.LocationObjectsWatcher = WatcherFactory.ForNetDictionary(this.GetCurrentLocation().netObjects); this.Watchers.Add(this.LocationObjectsWatcher); } // update inventory this.CurrentInventory = this.GetInventory(); }