/// <summary> /// NOTE: Please use Inventory instead for moving inventory around. /// /// Server-side only. Adds the specified item to the slot, updating any observers. /// Note that this doesn't do anything other than saying the item is now in the slot. /// </summary> public void _ServerSetItem(Pickupable newItem) { var removedItem = item; item = newItem; OnSlotContentsChangeServer.Invoke(); //server has to call their own client side hooks because by the time the message is received, //the server will not be able to determine what slot the item came from. OnSlotContentsChangeClient.Invoke(); if (removedItem != null) { //we displaced an item var info = ClientInventoryMove.OfType(ClientInventoryMoveType.Removed); foreach (var hook in removedItem.GetComponents <IClientInventoryMove>()) { hook.OnInventoryMoveClient(info); } } if (newItem != null) { //we are adding an item to this slot var info = ClientInventoryMove.OfType(ClientInventoryMoveType.Added); foreach (var hook in newItem.GetComponents <IClientInventoryMove>()) { hook.OnInventoryMoveClient(info); } } UpdateItemSlotMessage.Send(serverObserverPlayers, this); }
private bool ShouldShowButton(ClientInventoryMove info) { // Check if we are in an inventory if (info.ClientInventoryMoveType == ClientInventoryMoveType.Removed) { return(false); } // ... we are not on a player if (pickupable.ItemSlot.Player == null) { return(false); } // ... not the client that owns this object if (pickupable.ItemSlot.LocalUISlot == null) { return(false); } // ... item is not in an allowed slot if (pickupable.ItemSlot.NamedSlot != null) { if (!allowedSlots.HasFlag(ItemSlot.GetFlaggedSlot(pickupable.ItemSlot.NamedSlot.Value))) { return(false); } } return(true); }
public void OnInventoryMoveClient(ClientInventoryMove info) { var playerScript = PlayerManager.LocalPlayerScript; if ((CustomNetworkManager.Instance._isServer && GameData.IsHeadlessServer) || playerScript == null || playerScript.playerNetworkActions == null || playerScript.playerHealth == null) { return; } switch (info.ClientInventoryMoveType) { case ClientInventoryMoveType.Added when playerScript.playerNetworkActions.GetActiveItemInSlot(NamedSlot.mask)?.gameObject == gameObject: UIManager.PlayerHealthUI.heartMonitor.overlayCrits.SetState(OverlayState.crit); break; case ClientInventoryMoveType.Removed when playerScript.playerNetworkActions.GetActiveItemInSlot(NamedSlot.mask)?.gameObject != gameObject: UIManager.PlayerHealthUI.heartMonitor.overlayCrits.SetState(OverlayState.normal); break; } }
public void OnInventoryMoveClient(ClientInventoryMove info) { //if we were currently looking at this storage, close the storage UI if this item was moved at all. if (UIManager.StorageHandler.CurrentOpenStorage == this) { UIManager.StorageHandler.CloseStorageUI(); } }
public override void Process(NetMessage msg) { //server calls their own client side hooks, so server doesn't do anything here. //It's necessary for it to be this way because by the time the server reaches this point, //the change to this slot has already occurred so it can't figure out what the previous //slot was for this item. if (!CustomNetworkManager.IsServer) { LoadMultipleObjects(new uint[] { msg.Storage, msg.Item }); if (NetworkObjects[0] == null) { return; } ItemSlot slot = null; if (msg.SlotIndex == -1) { slot = ItemSlot.GetNamed(NetworkObjects[0].GetComponent <ItemStorage>(), msg.NamedSlot); } else { slot = ItemSlot.GetIndexed(NetworkObjects[0].GetComponent <ItemStorage>(), msg.SlotIndex); } var previouslyInSlot = slot.ItemObject; var pickupable = msg.Item == NetId.Invalid ? null : NetworkObjects[1].GetComponent <Pickupable>(); slot.ClientUpdate(pickupable); if (previouslyInSlot != null) { if (pickupable != null) { //was removed from slot pickupable._SetItemSlot(null); } var moveInfo = ClientInventoryMove.OfType(ClientInventoryMoveType.Removed); var hooks = previouslyInSlot.GetComponents <IClientInventoryMove>(); foreach (var hook in hooks) { hook.OnInventoryMoveClient(moveInfo); } } if (pickupable != null) { //was added to slot pickupable._SetItemSlot(slot); var moveInfo = ClientInventoryMove.OfType(ClientInventoryMoveType.Added); var hooks = pickupable.GetComponents <IClientInventoryMove>(); foreach (var hook in hooks) { hook.OnInventoryMoveClient(moveInfo); } } } }
public void OnInventoryMoveClient(ClientInventoryMove info) { bool shouldShow = ShouldShowButton(info); ClientSetActionButtonVisibility(shouldShow); if (PlayerManager.LocalPlayerScript == null || PlayerManager.LocalPlayerScript.playerHealth == null) { return; } }
public void OnInventoryMoveClient(ClientInventoryMove info) { var pna = PlayerManager.LocalPlayerScript.playerNetworkActions; var showAlert = pna.GetActiveHandItem() == gameObject || pna.GetOffHandItem() == gameObject; foreach (var _IActionGUI in ControllingActions) { UIActionManager.ToggleLocal(_IActionGUI, showAlert); } }
// TODO: this should be merged into a new AlertUI action system once it's implemented // Client only method public void OnInventoryMoveClient(ClientInventoryMove info) { if (CustomNetworkManager.Instance._isServer && GameData.IsHeadlessServer) { return; } if (canClickPickup) { // Show the 'switch pickup mode' action button if this is in either of the players hands var pna = PlayerManager.LocalPlayerScript.playerNetworkActions; var showAlert = pna.GetActiveHandItem() == gameObject || pna.GetOffHandItem() == gameObject; UIManager.AlertUI.ToggleAlertPickupMode(showAlert); } }
public void OnInventoryMoveClient(ClientInventoryMove info) { var pna = PlayerManager.LocalPlayerScript.playerNetworkActions; if (info.ClientInventoryMoveType == ClientInventoryMoveType.Added & pna.GetActiveItemInSlot(NamedSlot.feet)?.gameObject == gameObject) { UIActionManager.Toggle(this, true); UIActionManager.SetSprite(this, (sprites[0])); } else if (info.ClientInventoryMoveType == ClientInventoryMoveType.Removed & pna.GetActiveItemInSlot(NamedSlot.feet)?.gameObject != gameObject) { UIActionManager.Toggle(this, false); } }
public void OnInventoryMoveClient(ClientInventoryMove info) { bool shouldShow = ShouldShowButton(info); ClientSetActionButtonVisibility(shouldShow); if (PlayerManager.LocalPlayerScript == null) { return; } if (shouldShow) { PlayerManager.LocalPlayerScript.playerHealth.OnDeathNotifyEvent += OnDeath; } else { PlayerManager.LocalPlayerScript.playerHealth.OnDeathNotifyEvent -= OnDeath; } }
public void OnInventoryMoveClient(ClientInventoryMove info) { if (CustomNetworkManager.Instance._isServer && GameData.IsHeadlessServer) { return; } var pna = PlayerManager.LocalPlayerScript.playerNetworkActions; switch (info.ClientInventoryMoveType) { case ClientInventoryMoveType.Added when pna.GetActiveItemInSlot(NamedSlot.feet)?.gameObject == gameObject: UIActionManager.ToggleLocal(this, true); UIActionManager.SetSprite(this, (sprites[0])); break; case ClientInventoryMoveType.Removed when pna.GetActiveItemInSlot(NamedSlot.feet)?.gameObject != gameObject: UIActionManager.ToggleLocal(this, false); break; } }
public void OnInventoryMoveClient(ClientInventoryMove info) { if (PlayerManager.LocalPlayerScript == null) { return; } var pna = PlayerManager.LocalPlayerScript.playerNetworkActions; bool showAlert = false; foreach (var itemSlot in pna.itemStorage.GetHandSlots()) { if (itemSlot.ItemObject == gameObject) { showAlert = true; } } foreach (var _IActionGUI in ControllingActions) { UIActionManager.ToggleLocal(_IActionGUI, showAlert); } }
public void OnInventoryMoveClient(ClientInventoryMove info) { var playerScript = PlayerManager.LocalPlayerScript; if ((CustomNetworkManager.Instance._isServer && GameData.IsHeadlessServer) || playerScript == null || playerScript.playerNetworkActions == null || playerScript.playerHealth == null) { return; } if (info.ClientInventoryMoveType == ClientInventoryMoveType.Added && playerScript.DynamicItemStorage.InventoryHasObjectInCategory(gameObject, NamedSlot.mask)) { UIManager.PlayerHealthUI.heartMonitor.overlayCrits.SetState(OverlayState.crit); } else if (info.ClientInventoryMoveType == ClientInventoryMoveType.Removed && playerScript.DynamicItemStorage.InventoryHasObjectInCategory(gameObject, NamedSlot.mask) == false) { UIManager.PlayerHealthUI.heartMonitor.overlayCrits.SetState(OverlayState.normal); } }
// TODO: this should be merged into a new AlertUI action system once it's implemented // Client only method public void OnInventoryMoveClient(ClientInventoryMove info) { if (CustomNetworkManager.Instance._isServer && GameData.IsHeadlessServer) { return; } if (canClickPickup) { // Show the 'switch pickup mode' action button if this is in either of the players hands var pna = PlayerManager.LocalPlayerScript.playerNetworkActions; bool showAlert = false; foreach (var itemSlot in pna.itemStorage.GetNamedItemSlots(NamedSlot.leftHand)) { if (itemSlot.ItemObject == gameObject) { showAlert = true; break; } } if (showAlert == false) { foreach (var itemSlot in pna.itemStorage.GetNamedItemSlots(NamedSlot.rightHand)) { if (itemSlot.ItemObject == gameObject) { showAlert = true; break; } } } UI.Action.UIActionManager.ToggleLocal(this, showAlert); } }
public void OnInventoryMoveClient(ClientInventoryMove info) { if (!hasActionButton) { return; } bool shouldShowButton = pickupable.ItemSlot != null && pickupable.ItemSlot.Player != null && info.ClientInventoryMoveType == ClientInventoryMoveType.Added; if (!shouldShowButton) { UIActionManager.ToggleLocal(this, false); return; } // If the slot the item is a slot of the client's. if (pickupable.ItemSlot.LocalUISlot != null) { UIActionManager.ToggleLocal(this, true); UIActionManager.SetSpriteSO(this, spriteHandler.GetCurrentSpriteSO(), false); } }
// Client only method public void OnInventoryMoveClient(ClientInventoryMove info) { if (CustomNetworkManager.Instance._isServer && GameData.IsHeadlessServer) { return; } var hand = PlayerManager.LocalPlayerScript.playerNetworkActions; //when item is moved and player has it on his feet if (hand.GetActiveItemInSlot(NamedSlot.feet) != null && hand.GetActiveItemInSlot(NamedSlot.feet) == gameObject) { UIActionManager.Toggle(this, true); UIActionManager.SetSprite(this, (sprites[0])); } else { if (isOn) { ClientChangeSpeed(initialSpeed); //old } UIActionManager.Toggle(this, false); } }