public void OnInventoryMoveServer(InventoryMove info) { // stop any observers (except for owner) from observing it if it's moved var fromRootPlayer = info.FromRootPlayer; if (fromRootPlayer != null) { itemStorage.ServerRemoveAllObserversExceptOwner(); } // stop owner observing if it's dropped from the owner's storage var toRootPlayer = info.ToRootPlayer; // no need to do anything, hasn't moved into player inventory if (fromRootPlayer == toRootPlayer) { return; } // make sure it's closed and any children as well if (fromRootPlayer != null) { ObserveInteractableStorageMessage.Send(fromRootPlayer.gameObject, this, false); } }
public void ServerPerformInteraction(MouseDrop interaction) { if (allowedToInteract == false) { return; } if (interaction.IsFromInventory && interaction.TargetObject == gameObject) { // try to add item to this storage Inventory.ServerTransfer(interaction.FromSlot, itemStorage.GetBestSlotFor(interaction.UsedObject)); } else { // player can observe this storage itemStorage.ServerAddObserverPlayer(interaction.Performer); ObserveInteractableStorageMessage.Send(interaction.Performer, this, true); // if we are observing a storage not in our inventory (such as another player's top // level inventory or a storage within their inventory, or a box/backpack sitting on the ground), we must stop observing when it // becomes unobservable for whatever reason (such as the owner becoming unobservable) var rootStorage = itemStorage.GetRootStorage(); if (interaction.Performer != rootStorage.gameObject) { // stop observing when it becomes unobservable for whatever reason var relationship = ObserveStorageRelationship.Observe(this, interaction.Performer.GetComponent <RegisterPlayer>(), PlayerScript.interactionDistance, ServerOnObservationEnded); SpatialRelationship.ServerActivate(relationship); } } }
/// <summary> /// Informs the recipient that they can now show/hide the UI popup for observing a particular /// storage or any children. /// </summary> /// <param name="recipient"></param> /// <param name="storage"></param> /// <param name="observed">true indicates they should show the popup, false indicates it should be hidden</param> public static void Send(GameObject recipient, InteractableStorage storage, bool observed) { var msg = new ObserveInteractableStorageMessage() { Storage = storage.gameObject.NetId(), Observed = observed }; msg.SendTo(recipient); }
public void ServerPerformInteraction(MouseDrop interaction) { if (interaction.IsFromInventory && interaction.TargetObject == gameObject) { //try to add item to this storage Inventory.ServerTransfer(interaction.FromSlot, itemStorage.GetBestSlotFor(interaction.UsedObject)); } else { //player can observe this storage itemStorage.ServerAddObserverPlayer(interaction.Performer); ObserveInteractableStorageMessage.Send(interaction.Performer, this, true); if (!interaction.IsFromInventory) { SpatialRelationship.ServerActivate(RangeRelationship.Between(interaction.Performer, interaction.UsedObject, PlayerScript.interactionDistance, ServerOnRelationshipEnded)); } } }
private void ServerOnObservationEnded(ObserveStorageRelationship cancelled) { // they can't observe anymore itemStorage.ServerRemoveObserverPlayer(cancelled.ObserverPlayer.gameObject); ObserveInteractableStorageMessage.Send(cancelled.ObserverPlayer.gameObject, this, false); }