예제 #1
0
    public void OpenInspector(SojournItem item)
    {
        /* Is this our journal? */
        if (!hasAuthority || !isClient)
        {
            if (debug)
            {
                Debug.LogError("JournalManager: We don't manager this journal!");
            }
            return;
        }

        /* Are we opening or closing the journal? */
        if (IsBusy() || IsClosed())
        {
            if (debug)
            {
                Debug.LogError("JournalManager: The journal is busy!");
            }
            return;
        }

        if (!pages.OpenItemInspector(item))
        {
            Debug.LogError("JournalManager: We cannot inspect this item: " + item.name);
        }
    }
예제 #2
0
    protected override void OnAfterPickedUp(GameObject obj, HandManager hand)
    {
        if (!isClient)
        {
            return;
        }

        /* We need to have a journal */
        if (currentJournal == null)
        {
            return;
        }

        /* Is this the player relic? */
        if (obj.GetComponent <PlayerRelic>() != null)
        {
            return;
        }

        /* Convert the obj to a sojourn item */
        SojournItem item = obj.GetComponent <SojournItem>();

        /* Is this our journal? */
        if (currentJournal.gameObject == obj)
        {
            if (debug)
            {
                Debug.Log("PlayerJournalManager: Picked up the Player Journal!");
            }

            /* Update journal stats just in case */
            currentJournal.UpdateStats(playerController.GetEntityName(), skillsManager.GetSkills(), combatManager);

            /* Open the journal */
            currentJournal.OpenJournal();

            /* Disable highlighting */
            currentJournal.DisableHighlight();
        }
        else if (currentJournal.GetAttachedHand() != null)
        {
            if (debug)
            {
                Debug.Log("PlayerJournalManager: We are inspecting an item!");
            }

            /* Our journal is probably in our other hand, so lets inspect this item if possible */
            inspecting       = true;
            beforeInspecting = currentJournal.GetCurrentPagePairing();

            /* Open the inspector to this item */
            currentJournal.OpenInspector(item);
        }
    }
예제 #3
0
    public void InspectItem(Item item)
    {
        /* Make sure the item socket is open */
        Clear();
        Debug.Assert(itemSocket.GetAttachedObject() == null);

        /* Set some of the properties */
        itemNameText.text        = item.item_name;
        itemWeightValueText.text = "Weight: " + item.item_value + " Value: " + item.item_value;
        itemPropertiesText.text  = "";

        /* Display the item */
        itemSocket.CreateLocalItemInSocket(item);

        /* Transform the item */
        SojournItem sojournItem = itemSocket.GetAttachedItem();

        sojournItem.PlacedInInventory();
    }
예제 #4
0
    /**
     * Opens the item inspector to inspect the given item.
     */
    public bool OpenItemInspector(SojournItem item)
    {
        if (debug)
        {
            Debug.Log("PageManager: We are opening the item inspector to inspect: " + item.itemName);
        }

        /* Setup the left page */
        ItemInspectorLeftPage leftPage = (ItemInspectorLeftPage)itemInspector.pageLeft;

        leftPage.InspectItem(item.GetItem());

        /* Setup the right page */
        ItemInspectorRightPage rightPage = (ItemInspectorRightPage)itemInspector.pageRight;

        rightPage.SetDescription("");

        /* Open to the item inspector */
        return(UpdateTarget(itemInspector));
    }
예제 #5
0
    protected override bool OnInteractionBoxPressed(InteractionBox box, HandManager hand)
    {
        /* Get the item slot from the interaction box */
        UIItemSlot itemSlot = box.GetGameObject().GetComponent <UIItemSlot>();

        if (itemSlot == null)
        {
            return(false);
        }

        /* The store manager has to be setup */
        if (storeManager == null)
        {
            return(false);
        }

        /* See if either of our slot managers own this slot */
        bool catalogueOwnsSlot = barteringCatalogue.OwnsSlot(itemSlot);

        /* Get the item from the slot */
        SojournItem transfoerSojournItem = itemSlot.GetItem();

        if (transfoerSojournItem == null)
        {
            return(true);
        }
        Item transfer = transfoerSojournItem.GetItem();

        if (transfer == null)
        {
            return(true);
        }

        if (catalogueOwnsSlot)
        {
            CmdTransferFromStoreToInventory(storeManager.GetComponent <NetworkIdentity>().netId, transfer.item_name);
        }

        return(true);
    }
예제 #6
0
    protected override bool OnBeforeDropped(GameObject obj, HandManager hand)
    {
        /* Get the item component from the object */
        SojournItem item = obj.GetComponent <SojournItem>();

        if (item == null)
        {
            return(false);
        }

        /* Is this our player journal? */
        if (item.GetComponent <JournalManager>() == null || !item.hasAuthority)
        {
            return(false);
        }

        if (debug)
        {
            Debug.Log("PlayerToolbeltManager Client: We returned the player journal!");
        }

        /* The player journal has to return to it's slot */
        PlayerToolbeltSlot slot = toolbelt.ReturnItem(item);

        if (slot == null)
        {
            if (debug)
            {
                Debug.Log("PlayerToolbeltManager Client: Failed to return restricted item!");
            }
            return(false);
        }

        /* Deliver the toolbet event */
        eventManager.OnToolbeltEvent(VRInteraction.InteractionEvent.OnItemPlacedInToolbelt, obj, slot, hand);

        /* We handled this event */
        return(true);
    }
예제 #7
0
 public bool IsItemInToolbelt(SojournItem item)
 {
     return(toolbelt.GetItems().Contains(item));
 }
예제 #8
0
 public bool ReturnItem(SojournItem item)
 {
     return(toolbelt.ReturnItem(item));
 }
예제 #9
0
    protected override bool OnItemDroppedOnInteractionBox(InteractionBox box, GameObject obj, HandManager hand)
    {
        /* See if this object is a sojourn item */
        SojournItem item = obj.GetComponent <SojournItem>();

        /* Is this an item? */
        if (item == null)
        {
            return(false);
        }

        /* Is this the relic or the journal? */
        bool relic   = obj.GetComponent <PlayerRelic>() != null;
        bool journal = obj.GetComponent <JournalManager>() != null;

        /* Are we dropping something into a slot? */
        PlayerToolbeltSlot slot = box.GetGameObject().GetComponent <PlayerToolbeltSlot>();

        if (slot == null)
        {
            /* This event isn't consumable by us */
            return(false);
        }

        /* Do we own this toolbelt slot? */
        if (!slot.GetSocketManager().hasAuthority)
        {
            /* We don't own this toolbelt slot */
            if (debug)
            {
                Debug.Log("PlayerToolbeltManager: We don't own this toolbelt slot!");
            }
            return(false);
        }

        /* Is this slot occupied? */
        if (slot.IsOccupied())
        {
            if (debug)
            {
                Debug.Log("PlayerToolbeltManager: Toolbelt slot is occupied.");
            }
            return(false);
        }

        if (debug)
        {
            Debug.Log("PlayerToolbeltManager Client: Player dropped something onto a slot!");
        }

        /* If this is the relic or the journal, return this to the slot where it's supposed to be */
        if (relic || journal)
        {
            /* Return this item to where it's supposed to go */
            if (!toolbelt.ReturnItem(item))
            {
                Debug.LogError("PlayerToolbeltManager: Failed to return item to it's correct slot.");
            }
        }

        /* Are we overlapping with a slot? */
        if (!slot.socketRestricted && !slot.IsOccupied())
        {
            if (debug)
            {
                Debug.Log("PlayerToolbeltManager Client: We're dropping something onto a slot!");
            }

            /* Attach this to something else */
            if (!item.ClientReattach(slot))
            {
                Debug.LogError("PlayerToolbeltManager Client: Failed to attach item to socket!");
                return(false);
            }

            /* Deliver the toolbet event */
            eventManager.OnToolbeltEvent(VRInteraction.InteractionEvent.OnItemPlacedInToolbelt, obj, slot, hand);

            /* This event was handled */
            return(true);
        }

        /* Is the player returning a restricted item? */
        if (slot.socketRestricted && slot.AcceptsAttachable(item))
        {
            /* Return the item to the toolbelt. */
            if (!slot.ReturnItem(item))
            {
                if (debug)
                {
                    Debug.Log("PlayerToolbeltManager Client: Failed to return restricted item!");
                }
                return(false);
            }

            if (debug)
            {
                Debug.Log("PlayerToolbeltManager Client: We returned a restricted item!");
            }

            /* Deliver the toolbet event */
            eventManager.OnToolbeltEvent(VRInteraction.InteractionEvent.OnItemPlacedInToolbelt, obj, slot, hand);

            /* The item was returned */
            return(true);
        }

        if (debug)
        {
            Debug.Log("PlayerToolbeltManager Client: We aren't overlapping with an open toolbelt slot.");
        }

        /* We couldn't consume this event */
        return(false);
    }
예제 #10
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");
        }
    }
예제 #11
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.");
        }
    }
예제 #12
0
    protected override bool OnControllerInteraction(VRInteraction.InteractionEvent action, GameObject interactable, HandManager hand)
    {
        /* Make sure our toolbelt is actually setup */
        if (toolbelt == null)
        {
            return(false);
        }

        /* Is the interactable a toolbelt slot? */
        PlayerToolbeltSlot slot = interactable.GetComponent <PlayerToolbeltSlot>();

        if (slot == null || !slot.GetSocketManager().hasAuthority)
        {
            return(false);
        }

        /* This has to be a pickup action */
        if (!SojournItem.IsPickupEvent(action))
        {
            return(false);
        }

        if (debug)
        {
            Debug.Log("PlayerToolbeltManager Client: The player is attempting to pickup something from our toolbelt slot.");
        }

        /* The slot must be occupied */
        if (!slot.IsOccupied())
        {
            if (debug)
            {
                Debug.LogError("PlayerToolbeltManager Client: This toolbelt slot isn't occupied!");
            }
            return(false);
        }

        /* Get the object that's in the slot we're interacting with */
        GameObject toolbeltItemObj = slot.GetAttachedObject();

        if (toolbeltItemObj == null)
        {
            throw new System.Exception("Why is there no attached item if this slot is occupied?");
        }

        /* Convert the object to an item */
        SojournItem toolbeltItem = toolbeltItemObj.GetComponent <SojournItem>();

        if (toolbeltItem == null)
        {
            throw new System.Exception("Why is this object attached to the toolbelt but it's not an item!!");
        }

        /* If the hand isn't empty, swap the items */
        if (hand.IsHoldingSomething())
        {
            if (debug)
            {
                Debug.LogWarning("PlayerToolbeltManager Client: The player is already holding something so we'll swap items");
            }

            /* We have to do the swap on the server */
            //CmdSwapItems(hand.netId, slot.GetSocketManager().netId, slot.socketNumber);

            /* We swapped items */
            return(true);
        }

        if (debug)
        {
            Debug.Log("PlayerToolbeltManager Client: We weren't holding something, so we're just picking up the object");
        }

        /* Pickup the item from the toolbelt */
        CmdPickupItem(hand.netId, slot.GetSocketManager().netId, slot.GetSocketNumber());

        /* We picked up the object */
        return(true);
    }
예제 #13
0
    /**
     * Update the representation of the inventory.
     */
    public void InventoryUpdated()
    {
        if (gridRows != PlayerInventory.INVENTORY_ROWS)
        {
            throw new System.Exception("Slot rows is not equal to inventory rows!");
        }
        if (gridCols != PlayerInventory.INVENTORY_COLS)
        {
            throw new System.Exception("Slot cols is not equal to inventory cols!");
        }
        if (inventory == null)
        {
            return;
        }
        if (!hasGrid)
        {
            throw new System.Exception("Why is this socket manager not in grid mode?");
        }

        if (debug)
        {
            Debug.Log("InventorySocketManager: Received inventory update.");
        }

        /* Populate the grid */
        for (int row = 0; row < PlayerInventory.INVENTORY_ROWS; row++)
        {
            for (int col = 0; col < PlayerInventory.INVENTORY_COLS; col++)
            {
                /* Get the item at the inventory row,col */
                Item item = inventory.Get(row, col);

                /* Get the slot this item should be placed in */
                SojournItemSocket socket = GetGridItemSocket(row, col);
                Debug.Assert(socket != null);

                /* If there is no longer an item here, destroy the item. */
                if (Item.IsNull(item))
                {
                    /* Do we need to destroy this item? */
                    if (socket.IsOccupied())
                    {
                        if (debug)
                        {
                            Debug.Log("InventorySocketManager: (" + row + ", " + col + ") Item will be destroyed.");
                        }

                        /* Destroy the item if we need to */
                        if (!socket.ServerDestroyAttachedItem())
                        {
                            Debug.LogWarning("InventorySocketManager: (" + row + ", " + col + ") Failed to destroy item in socket!");
                        }
                    }

                    /* Don't do anything else with this socket */
                    continue;
                }

                if (debug)
                {
                    Debug.Log("InventorySocketManager: Item in inventory: (" + row + ", " + col + "): " + item.item_name + " : " + item.item_id);
                }

                /* Get the item that's in the socket */
                SojournItem sojournItem = socket.GetAttachedItem();

                /* Is this socket already occupied? */
                if (sojournItem != null)
                {
                    if (debug)
                    {
                        Debug.Log("InventorySocketManager: Item in socket: (" + row + ", " + col + "): " + sojournItem.GetItem().item_name
                                  + " : " + sojournItem.GetItem().item_id);
                    }

                    /* Are we already displaying this item? */
                    if (sojournItem.GetItem().item_id == item.item_id)
                    {
                        if (debug)
                        {
                            Debug.Log("InventorySocketManager: (" + row + ", " + col + ") Requires no change.");
                        }
                        continue;
                    }

                    if (debug)
                    {
                        Debug.Log("InventorySocketManager: (" + row + ", " + col + ") Destroying attached item.");
                    }

                    /* We need to display a different item */
                    if (!socket.ServerDestroyAttachedItem())
                    {
                        Debug.LogWarning("InventorySocketManager: (" + row + ", " + col + ") Failed to destroy item in socket!");
                    }
                }

                /* Spawn the new item in the socket */
                if (!socket.CreateLocalItemInSocket(item))
                {
                    Debug.LogError("InventorySocketManager: Failed to spawn local only object in inventory: " + item.item_name);
                    return;
                }

                /* Transform the new item */
                sojournItem = socket.GetAttachedItem();
                if (!sojournItem.PlacedInInventory())
                {
                    Debug.LogError("InventorySocketManager: (" + row + ", " + col + ") Failed to scale for inventory!");
                    return;
                }

                if (debug)
                {
                    Debug.Log("InventorySocketManager: Displaying new item at "
                              + row + "," + col + " item: " + sojournItem.name);
                }
            }
        }
    }
예제 #14
0
    protected override void ItemUpdate()
    {
        /* Should we update the journal pieces? */
        if (journalUpdating)
        {
            /* Assume we're done opening or closing the journal */
            bool done = true;

            /* Update both pages */
            done &= journalRight.JournalUpdate(state.open);
            done &= journalLeft.JournalUpdate(state.open);

            /* Are we actually done? */
            if (done)
            {
                if (debug)
                {
                    Debug.Log("JournalManager: The Journal has finished opening or closing.");
                }
                journalUpdating = false;
            }
        }

        /* Update our page manager */
        if (pages != null)
        {
            pages.PagesUpdate();
        }

#if UNITY_EDITOR
        if (pages != null)
        {
            initializeJournal = true;
        }
        if (initializeJournal && pages == null)
        {
            //Quest ip1 = new Quest("In progress 1", "This is the first in progress quest.");
            //ip1.quest_id = System.Guid.NewGuid().ToString();
            //ip1.CreateObjectiveGroup().AddKillingObjective("goblin", 10, false, -1.0f, 0);

            //Quest ip2 = new Quest("In progress 2", "This is the second in progress quest.");
            //ip2.quest_id = System.Guid.NewGuid().ToString();
            //ip2.CreateObjectiveGroup().AddGatheringObjective("aloe", 100, false, -1.0f, 0);

            //List<Quest> ipq = new List<Quest>();
            //ipq.Add(ip1);
            //ipq.Add(ip2);

            //Quest c1 = new Quest("Complete quest 1", "This is the first complete quest.");
            //ip2.quest_id = System.Guid.NewGuid().ToString();
            //ip2.complete = true;
            //ip2.CreateObjectiveGroup().AddGatheringObjective("aloe", 100, false, -1.0f, 0);

            //List<Quest> cq = new List<Quest>();
            //cq.Add(c1);

            //pages = new PageManager(this, ipq, cq);

            //PlayerSkills skills = new PlayerSkills();
            //skills.exp_alchemy += 100000;
            //skills.exp_defense += 10000;
            //skills.exp_mining += 1000;
            //skills.exp_health += 100;
            //skills.exp_cooking += 1;

            //pages.UpdateStats("Sojourn Player", skills, null);

            initializeJournal = false;
        }

        if (openJournal)
        {
            OpenJournal();
            openJournal = false;
        }

        if (closeJournal)
        {
            CloseJournal();
            closeJournal = false;
        }

        if (flipLeft)
        {
            pages.FlipLeft();
            flipLeft = false;
        }

        if (flipRight)
        {
            pages.FlipRight();
            flipRight = false;
        }

        if (inspect != null)
        {
            SojournItem item = inspect.GetComponent <SojournItem>();
            if (item != null)
            {
                OpenInspector(item);
            }
            inspect = null;
        }

        if (highlight)
        {
            EnableHighlight();
            highlight = false;
        }

        if (unhighlight)
        {
            DisableHighlight();
            unhighlight = false;
        }
#endif
    }