Ejemplo n.º 1
0
    // Takes the inputted ID numbers and calls GetItemWithID on each, returns a list of ItemScripts
    List <ItemScript> ConvertToItemScripts(int[] idNumbers)
    {
        // Initialise a blank list
        List <ItemScript> scripts = new List <ItemScript>(idNumbers.Length);

        // Avoid the creation of temporary variables
        GameObject currentItem;
        ItemScript currentScript;

        // Iterate through the array obtaining valid ItemScripts
        for (int i = 0; i < idNumbers.Length; ++i)
        {
            // Assign and check if currentItem is a valid pointer
            if (currentItem = m_itemIDs.GetItemWithID(idNumbers[i]))
            {
                // Assign and check if currentScript is a valid pointer
                if (currentScript = currentItem.GetComponent <ItemScript>())
                {
                    scripts.Add(currentScript);
                }

                else
                {
                    Debug.LogError("Couldn't find an ItemScript component on: " + currentItem.name);
                }
            }
        }

        return(scripts);
    }
Ejemplo n.º 2
0
    void AlertServerInventoryRemoval(int itemID)
    {
        // Determine the GameObject and index
        GameObject toRemove = m_itemIDs.GetItemWithID(itemID);
        int        index    = m_cShipInventory.IndexOf(toRemove);

        // Remove the item
        m_cShipInventory.RemoveAt(index);
        m_requestedItem.RemoveAt(index);

        //Propagate inventory after change
        networkView.RPC("AlertCShipInventoryHasChanged", RPCMode.Others);
        for (int i = 0; i < m_cShipInventory.Count; i++)
        {
            networkView.RPC("PropagateCShipInventory", RPCMode.Others, i, m_cShipInventory[i].GetComponent <ItemScript>().m_equipmentID);
        }
    }
Ejemplo n.º 3
0
    void PropagateItemAtIndex(int index, int itemID)
    {
        // Allow null values if m_nullRemovedItems
        GameObject itemObject = m_itemIDs.GetItemWithID(itemID);
        ItemScript item       = itemObject ? itemObject.GetComponent <ItemScript>() : null;

        // Only allow nulls if that has been specified as an attribute
        if (m_nullRemovedItems || (!m_nullRemovedItems && item))
        {
            // The index should always be valid but just in case.
            if (IsValidIndex(index))
            {
                // Decrement the addRequests counter if being placed in a null
                if (!m_inventory[index])
                {
                    --addRequests;
                }

                m_inventory[index]       = item;
                m_isItemRequested[index] = false;
                m_requestTickets[index].Reset();
            }

            // The server may decide simply adding would be more suitable
            else
            {
                m_inventory.Add(item);
                m_isItemRequested.Add(false);
                m_requestTickets.Add(new ItemTicket());
                --addRequests;
            }


            // Propagate it to the clients to keep the clients inventories in sync
            if (Network.isServer)
            {
                --addRequests;


                networkView.RPC("PropagateItemAtIndex", RPCMode.Others, index, itemID);
            }
        }

        else
        {
            Debug.Log("Attempt to add null to " + name + ".NetworkInventory.m_inventory when nulls are not allowed.");
        }
    }