/// <inheritdoc/> public void LocateableAdded(object sender, BucketItemEventArgs <ILocateable> eventArgs) { if (this.isDisposed) { return; } var item = eventArgs.Item; if (item is IHasBucketInformation hasBucketInfo && this.ObservingBuckets.Contains(hasBucketInfo.OldBucket)) { // we already observe the bucket where the object came from return; } if (!item.IsActive()) { return; } if (item is Player player) { this.adaptee.ViewPlugIns.GetPlugIn <INewPlayersInScopePlugIn>()?.NewPlayersInScope(player.GetAsEnumerable()); } else if (item is NonPlayerCharacter npc) { this.adaptee.ViewPlugIns.GetPlugIn <INewNpcsInScopePlugIn>()?.NewNpcsInScope(npc.GetAsEnumerable()); } else if (item is DroppedItem droppedItem) { this.adaptee.ViewPlugIns.GetPlugIn <IShowDroppedItemsPlugIn>()?.ShowDroppedItems(droppedItem.GetAsEnumerable(), sender != this); } else if (item is DroppedMoney droppedMoney) { this.adaptee.ViewPlugIns.GetPlugIn <IShowMoneyDropPlugIn>()?.ShowMoney(droppedMoney.Id, sender != this, droppedMoney.Amount, droppedMoney.Position); } else { // no action required. } if (item is IObservable observable) { this.observingLock.EnterWriteLock(); try { if (!this.observingObjects.Contains(observable)) { this.observingObjects.Add(observable); } } finally { this.observingLock.ExitWriteLock(); } observable.AddObserver(this.adaptee); } }
/// <inheritdoc/> public void LocateableAdded(object sender, BucketItemEventArgs <ILocateable> eventArgs) { if (this.isDisposed) { return; } var item = eventArgs.Item; if (item is IHasBucketInformation hasBucketInfo && this.ObservingBuckets.Contains(hasBucketInfo.CurrentBucket)) { // we already observe the bucket return; } if (item is Player) { this.adaptee.WorldView.NewPlayersInScope(((Player)item).GetAsEnumerable()); } else if (item is NonPlayerCharacter) { this.adaptee.WorldView.NewNpcsInScope(((NonPlayerCharacter)item).GetAsEnumerable()); } else if (item is DroppedItem) { this.adaptee.WorldView.ShowDroppedItems(((DroppedItem)item).GetAsEnumerable(), sender != this); } else { // no action required. } if (item is IObservable observable) { this.observingLock.EnterWriteLock(); try { if (!this.observingObjects.Contains(observable)) { this.observingObjects.Add(observable); } } finally { this.observingLock.ExitWriteLock(); } observable.AddObserver(this.adaptee); } }
/// <inheritdoc/> public void LocateableRemoved(object sender, BucketItemEventArgs <ILocateable> eventArgs) { if (this.isDisposed) { return; } var item = eventArgs.Item; if (Equals(item, this.adaptee)) { return; // we are always observing ourself } var hasBucketInfo = item as IHasBucketInformation; if (hasBucketInfo?.NewBucket != null && this.ObservingBuckets.Contains(hasBucketInfo.NewBucket)) { // CurrentBucket contains the new bucket if the object is moving. So in this case we still observe the new bucket and don't need to remove the object from observation. return; } if (item is IObservable observable) { this.observingLock.EnterWriteLock(); try { this.observingObjects.Remove(observable); } finally { this.observingLock.ExitWriteLock(); } observable.RemoveObserver(this.adaptee); } if (item is DroppedItem || item is DroppedMoney) { this.adaptee.ViewPlugIns.GetPlugIn <IDroppedItemsDisappearedPlugIn>()?.DroppedItemsDisappeared(item.GetAsEnumerable().Select(i => i.Id)); } else { if (item.IsActive()) { this.adaptee.ViewPlugIns.GetPlugIn <IObjectsOutOfScopePlugIn>()?.ObjectsOutOfScope(item.GetAsEnumerable()); } } }