/// <summary>Update the tracked values.</summary> /// <param name="watcher">The player watcher to snapshot.</param> public void Update(PlayerTracker watcher) { this.Location.Update(watcher.LocationWatcher); foreach (var pair in this.Skills) pair.Value.Update(watcher.SkillWatchers[pair.Key]); this.Inventory = watcher.TryGetInventoryChanges(out SnapshotItemListDiff itemChanges) ? itemChanges : this.EmptyItemListDiff; }
/// <summary>Get the inventory changes since the last update, if anything changed.</summary> /// <param name="changes">The inventory changes, or <c>null</c> if nothing changed.</param> /// <returns>Returns whether anything changed.</returns> public bool TryGetInventoryChanges(out SnapshotItemListDiff changes) { IDictionary <Item, int> current = this.GetInventory(); ISet <Item> added = new HashSet <Item>(new ObjectReferenceComparer <Item>()); ISet <Item> removed = new HashSet <Item>(new ObjectReferenceComparer <Item>()); foreach (Item item in this.PreviousInventory.Keys.Union(current.Keys)) { if (!this.PreviousInventory.ContainsKey(item)) { added.Add(item); } else if (!current.ContainsKey(item)) { removed.Add(item); } } return(SnapshotItemListDiff.TryGetChanges(added: added, removed: removed, stackSizes: this.PreviousInventory, out changes)); }
/// <summary>Get the inventory changes since the last update, if anything changed.</summary> /// <param name="changes">The inventory changes, or <c>null</c> if nothing changed.</param> /// <returns>Returns whether anything changed.</returns> public bool TryGetInventoryChanges(out SnapshotItemListDiff changes) { return(SnapshotItemListDiff.TryGetChanges(added: this.Added, removed: this.Removed, stackSizes: this.StackSizes, out changes)); }