private HandManager InternalGetHand(NetworkInstanceId handId) { /* Get the hand object */ GameObject handObj = NetworkServer.FindLocalObject(handId); if (handObj == null) { Debug.LogError("PlayerToolbeltManager Server: Client sent us a bad hand id!"); return(null); } /* Get the hand component from the object */ HandManager hand = handObj.GetComponent <HandManager>(); if (hand == null) { Debug.LogError("PlayerToolbeltManager Server: Client sent us something that isn't a hand!"); return(null); } /* The player has to own this hand */ if (hand.GetPlayerController().connectionToClient != connectionToClient) { Debug.LogError("PlayerToolbeltManager Server: Client sent us a hand that they don't own!"); return(null); } /* Return the hand object */ return(hand); }
private void CmdSwapItems(NetworkInstanceId handId, NetworkInstanceId socketManagerId, int socketNumber) { if (debug) { Debug.Log("PlayerToolbeltManager Server: The client has asked us to swap items between their hand and their toolbelt"); } /* Get our hand manager */ HandManager hand = InternalGetHand(handId); if (hand == null) { return; } /* Get the socket that the client provided */ SojournSocket socket = GetSojournSocket(socketManagerId, socketNumber); if (socket == null) { return; } /* Conver the socket into a toolbelt slot */ PlayerToolbeltSlot toolbeltSlot = (PlayerToolbeltSlot)socket; if (toolbeltSlot == null) { Debug.LogError("PlayerToolbeltManager Server: The client sent us a bad toolbelt slot!"); return; } /* Get the attached object from the toolbelt slot */ GameObject attachedObj = toolbeltSlot.GetAttachedObject(); if (attachedObj == null) { Debug.LogError("SojournToolbeltManager Server: There is nothing attached to this toolbelt slot!"); return; } /* Get the toolbelt item from the socket */ SojournItem toolbeltItem = attachedObj.GetComponent <SojournItem>(); if (toolbeltItem == null) { return; } /* Make the toolbelt item pickupable */ toolbeltItem.SetCanBePickedUp(true); if (debug) { Debug.Log("PlayerToolbeltManager Server: We are allowing the swap"); } /* Get the object from the player's hand */ GameObject handItemObj = hand.GetPickedUpObject(); if (handItemObj == null) { throw new System.Exception("There is supposed to be something in our hand!"); } /* Get the sojourn item component from the hand object */ SojournItem handItem = handItemObj.GetComponent <SojournItem>(); if (handItem == null) { throw new System.Exception("Why is this player holding something that isn't a sojourn item!"); } /* Detach the item from the toolbar socket */ if (!toolbeltItem.ServerDetach()) { throw new System.Exception("Failed to detach item from toolbelt!"); } /* Attach The item to the toolbar */ if (!handItem.ServerAttach(toolbeltSlot, playerController)) { throw new System.Exception("Failed to attach hand item to toolbelt!"); } PlayerPickupManager pickup = hand.GetPlayerController().GetComponent <PlayerPickupManager>(); Debug.Assert(pickup != null); /* Tell the player to pickup the item on their toolbelt */ if (!pickup.ClientPickUp(hand, toolbeltItem)) { throw new System.Exception("Failed to pickup item that was attached to our toolbelt!"); } if (debug) { Debug.Log("PlayerToolbeltManager Server: We have swapped the items"); } }
private void CmdPickupItem(NetworkInstanceId handId, NetworkInstanceId socketManagerId, int socketNumber) { if (debug) { Debug.Log("PlayerToolbeltManager Server: The client has asked us to swap items between their hand and their toolbelt"); } /* Get our hand manager */ HandManager hand = InternalGetHand(handId); if (hand == null) { return; } /* Get the socket that the client provided */ SojournSocket socket = GetSojournSocket(socketManagerId, socketNumber); if (socket == null) { return; } /* Convert the socket into a toolbelt slot */ PlayerToolbeltSlot toolbeltSlot = (PlayerToolbeltSlot)socket; if (toolbeltSlot == null) { Debug.LogError("PlayerToolbeltManager Server: The client sent us a bad toolbelt slot!"); return; } /* Get the attached object from the toolbelt slot */ GameObject attachedObj = toolbeltSlot.GetAttachedObject(); if (attachedObj == null) { Debug.LogError("SojournToolbeltManager Server: There is nothing attached to this toolbelt slot!"); return; } /* Get the toolbelt item from the socket */ SojournItem toolbeltItem = attachedObj.GetComponent <SojournItem>(); if (toolbeltItem == null) { return; } /* Make the toolbelt item pickupable */ toolbeltItem.SetCanBePickedUp(true); /* Get the player controller for this player */ PlayerEntityController player = hand.GetPlayerController(); if (player == null) { throw new System.Exception("Why is there no player controller for this hand?"); } /* Get the player pickup manager for this hand */ PlayerPickupManager pickup = player.GetComponent <PlayerPickupManager>(); if (!pickup.ServerPickUp(hand, toolbeltItem)) { throw new System.Exception("Failed to have player pickup item on toolbelt!"); } if (debug) { Debug.Log("PlayerToolbeltManager Server: Player picked up item from their toolbelt."); } }