Ejemplo n.º 1
0
    internal void TargetReceiveUpdate(NetworkConnection conn, StoreInventory inventory)
    {
        if (debug)
        {
            Debug.Log("StoreManager Client: We received a single update for store " + storeNumber);
        }
        this.currentStoreInventory.Apply(inventory);

        /* Get the main player */
        PlayerEntityController player = SojournGameManager.GetMainPlayer();

        Debug.Assert(player != null);

        /* Get the bartering menu manager */
        PlayerBarteringManager menu = player.GetComponent <PlayerBarteringManager>();

        /* Let the manager know that the inventory changed. */
        menu.StoreInventoryChanged(this);
    }
Ejemplo n.º 2
0
    internal void RpcUpdateClientStoreInventory(StoreInventory currentInventory)
    {
        if (debug)
        {
            Debug.Log("StoreManager Client: We got an update for store " + storeNumber);
        }

        this.currentStoreInventory.Apply(currentInventory);

        /* Get the main player */
        PlayerEntityController player = SojournGameManager.GetMainPlayer();

        Debug.Assert(player != null);

        /* Get the bartering menu manager */
        PlayerBarteringManager menu = player.GetComponent <PlayerBarteringManager>();

        /* Let the manager know that the inventory changed. */
        menu.StoreInventoryChanged(this);
    }
Ejemplo n.º 3
0
    internal void CmdTransferFromStoreToInventory(NetworkInstanceId store_id, string item_name)
    {
        /* Get the item that the player is trying to purchase */
        Item item = SojournDBM.odbm.GetItemByName(item_name);

        if (Item.IsNull(item))
        {
            Debug.LogError("BarteringMenuManager Server: Client sent us a bad item uuid.");
            return;
        }

        if (debug)
        {
            Debug.Log("BarteringMenuManager Server: Got a request to move an item from the inventory to the store.");
        }

        /* Get the player's attribute manager */
        PlayerEntityController attrib = GetComponent <PlayerEntityController>();

        /* Get this player's inventory */
        PlayerInventory inventory = attrib.GetComponent <PlayerInventoryManager>().GetInventory();

        /* Get the object for the store */
        GameObject storeObject = NetworkServer.FindLocalObject(store_id);

        if (storeObject == null)
        {
            Debug.LogError("BarteringMenuManager Server: The client send us a bad object id!");
            return;
        }

        /* Get the store manager for this store */
        StoreManager storeManager = storeObject.GetComponent <StoreManager>();

        if (storeManager == null)
        {
            Debug.LogError("BarteringMenuManager Server: The client sent us an ID for something that isn't a store!");
            return;
        }

        /* Does the store carry the given item? */
        if (storeManager.GetCurrentInventory().GetQuantity(item) <= 0)
        {
            Debug.LogError("BarteringMenuManager Server: The store doesn't carry this item.");
            return;
        }

        /* Take coins from store and give them to the player */
        long value = item.item_value;

        if (inventory.gold < value)
        {
            if (debug)
            {
                Debug.LogWarning("BarteringMenuManager Server: The player doesn't have enough coins to buy this item!");
            }
            return;
        }

        inventory.gold -= value;
        storeManager.AddCoins(value);

        /* Remove the item from the store */
        if (!storeManager.RemoveItem(item))
        {
            Debug.LogError("BarteringMenuManager Server: Failed to remove the item from the store!");
            return;
        }

        /* Give the item to the player */
        if (!inventory.Add(item))
        {
            Debug.LogError("BarteringMenuManager Server: Failed to add item to the player's inventory!!");

            /* If this happens we should really restore the store's item. */
            if (storeManager.AddItem(item))
            {
                Debug.LogWarning("BarteringMenuManager Server: We were able to restore the store's item.");
            }
            else
            {
                Debug.LogError("BarteringMenuManager Server: We failed to restore the store's item!!");
            }

            return;
        }

        /* The player's inventory has been updated */
        // attrib.UpdateClientInventory();

        if (debug)
        {
            Debug.Log("BarteringMenuManager Server: Item transferred to the inventory.");
        }
    }
Ejemplo n.º 4
0
    internal void CmdTransferFromInventoryToStore(NetworkInstanceId store_id, int row, int col)
    {
        if (debug)
        {
            Debug.Log("BarteringMenuManager Server: Got a request to move an item from the inventory to the store.");
        }

        /* Get the player's attribute manager */
        PlayerEntityController attrib = GetComponent <PlayerEntityController>();

        /* Get this player's inventory */
        PlayerInventory inventory = attrib.GetComponent <PlayerInventoryManager>().GetInventory();

        /* Get the item from the player's inventory */
        Item item = inventory.Get(row, col);

        if (Item.IsNull(item))
        {
            Debug.LogError("BarteringMenuManager Server: Can't take null item from inventory!");
            return;
        }

        GameObject storeObject = NetworkServer.FindLocalObject(store_id);

        if (storeObject == null)
        {
            Debug.LogError("BarteringMenuManager Server: The client send us a bad object id!");
            return;
        }

        /* Get the store manager for this store */
        StoreManager storeManager = storeObject.GetComponent <StoreManager>();

        if (storeManager == null)
        {
            Debug.LogError("BarteringMenuManager Server: The client sent us an ID for something that isn't a store!");
            return;
        }

        /* Take coins from player and give them to the store */
        long value = item.item_value;

        if (storeManager.GetCoins() < value)
        {
            if (debug)
            {
                Debug.LogWarning("BarteringMenuManager Server: The store doesn't have enough coins to buy this item!");
            }

            /* Reduce the value to the amount of coins remaining in the shop */
            value = storeManager.GetCoins();
        }

        inventory.gold += value;
        storeManager.RemoveCoins(value);

        /* Remove the item from the player's inventory */
        if (inventory.Remove(row, col) == null)
        {
            Debug.LogError("BarteringMenuManager Server: Failed to remove item from player inventory!");
            return;
        }

        /* Give the item to the store */
        if (!storeManager.AddItem(item))
        {
            Debug.LogError("BarteringMenuManager Server: Failed to add item to the shop!!");

            /* If this happens we should really restore the player's item. */
            if (inventory.Add(item))
            {
                Debug.LogWarning("BarteringMenuManager Server: We were able to restore the player's item.");
            }
            else
            {
                Debug.LogError("BarteringMenuManager Server: We failed to restore the player's item!!");
            }

            return;
        }

        /* The player's inventory has been updated */
        // attrib.UpdateClientInventory();

        if (debug)
        {
            Debug.Log("BarteringMenuManager Server: Item transferred to the player inventory.");
        }
    }
Ejemplo n.º 5
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.");
        }
    }