コード例 #1
0
    private SojournSocket GetSojournSocket(NetworkInstanceId socketManagerId, int socketNumber)
    {
        /* Get the socket manager object that the client sent us */
        GameObject socketManagerObj = NetworkServer.FindLocalObject(socketManagerId);

        if (socketManagerObj == null)
        {
            Debug.LogError("PlayerToolbeltManager Server: Client has sent us a bad socket manager object!");
            return(null);
        }

        /* Get the socket manager component from the object */
        PlayerToolbelt playerToolbelt = socketManagerObj.GetComponent <PlayerToolbelt>();

        if (playerToolbelt == null)
        {
            Debug.LogError("PlayerToolbeltManager Server: Client sent us an object that isn't an item socket manager!");
            return(null);
        }

        /* Make sure the client owns this socket manager */
        if (playerToolbelt.GetPlayerId() != netId)
        {
            Debug.LogError("PlayerToolbeltManager Server: Client doesn't own this socket manager!");
            return(null);
        }

        /* Get the item socket from the socket manager */
        SojournSocket itemSlot = playerToolbelt.GetSocket(socketNumber);

        if (itemSlot == null)
        {
            Debug.LogError("PlayerToolbeltManager Server: This socket number is invalid: " + socketNumber);
            return(null);
        }

        /* Return the toolbelt item */
        return(itemSlot);
    }
コード例 #2
0
    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");
        }
    }
コード例 #3
0
    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.");
        }
    }