コード例 #1
0
    //Searches for the best available slot in the slot array.  (One that already has the specified item)
    public MerchantSlotScript FindBestAvailableSlot(ResourceReferenceWithStackAndPrice pendingObjectToCheck)
    {
        if (slotArray != null)
        {
            for (int y = slotArray.GetLength(0) - 1; y >= 0; y--)
            {
                //Check for a stackable slot.
                for (int x = 0; x < slotArray.GetLength(1); x++)
                {
                    //Define the object in the slot.
                    ResourceReferenceWithStackAndPrice objectAssigned = slotArray[y, x].GetCurrentlyAssigned();
                    //Check to make sure objectAssigned is not null.
                    if (objectAssigned != null)
                    {
                        //Check to make sure the item is the same.
                        if (objectAssigned.mainContentReference.uiSlotContent.itemType == pendingObjectToCheck.mainContentReference.uiSlotContent.itemType)
                        {
                            if (objectAssigned.mainContentReference.uiSlotContent.localGroupID == pendingObjectToCheck.mainContentReference.uiSlotContent.localGroupID)
                            {
                                //Since the slot fits all requirements, return the slot.
                                return(slotArray [y, x]);
                            }
                        }
                    }
                }
            }
        }
        else
        {
            Debug.Log("Slot array is null and initialized status is " + initialized);
        }

        return(null);
    }
コード例 #2
0
    public virtual ResourceReferenceWithStackAndPrice DeAssignItem()
    {
        ResourceReferenceWithStackAndPrice toReturn = currentlyAssigned;

        currentlyAssigned = null;
        childIcon.sprite  = null;
        childIcon.enabled = false;
        UpdateStackIndicator();
        UpdatePriceIndicator();
        return(toReturn);
    }
コード例 #3
0
    //Assigns a new item to the best possible slot.
    public bool AssignNewItemToBestSlot(ResourceReferenceWithStackAndPrice item)
    {
        //Has to be here for the return statement
        bool successfullyAssigned = false;

        //Make sure that the prerequisites are met.
        if (initialized && item != null)
        {
            MerchantSlotScript bestAvailableSlot = FindBestAvailableSlot(item);

            if (bestAvailableSlot != null)
            {
                //Set successfully assigned.
                successfullyAssigned = true;
                //Add the new stack to the current item stack.
                bestAvailableSlot.ModifyCurrentItemStack(item.mainContentReference.stack);
                Debug.Log("Assigned " + item.mainContentReference.uiSlotContent.itemScreenName + " to slot with items of same type.");
            }
            else
            {
                Debug.Log("Could not stack item: Attempting to add to an empty slot");
                bestAvailableSlot = FindBestAvailableNullSlot();
                if (bestAvailableSlot != null)
                {
                    successfullyAssigned = true;
                    bestAvailableSlot.AssignNewItem(item);
                }
                else
                {
                    Debug.LogError("No slots are empty!");
                }
            }
        }
        else
        {
            if (initialized == false && item == null)
            {
                Debug.LogError("Not initialized and item is null");
            }
            else if (initialized == false)
            {
                Debug.LogError("Not initialized");
            }
            else
            {
                Debug.LogError("Item is null");
            }
        }

        return(successfullyAssigned);
    }
コード例 #4
0
    /******************************* ASSIGNING *******************************/

    public virtual void AssignNewItem(ResourceReferenceWithStackAndPrice itemToAssign)
    {
        if (itemToAssign.mainContentReference.stack > 0)
        {
            Sprite itemWithoutPivotPoint = ScriptingUtilities.GetSpriteWithoutPivotPoint(itemToAssign.mainContentReference.uiSlotContent.itemIcon);
            childIcon.enabled = true;
            currentlyAssigned = itemToAssign;
            childIcon.sprite  = itemWithoutPivotPoint;
            UpdateStackIndicator();
            UpdatePriceIndicator();
        }
        else
        {
            Debug.LogError("Could not assign item with 0 or less stack!");
        }
    }
コード例 #5
0
    protected override void InitializeNPC()
    {
        //Find and hide the inventory.
        merchantInventory = CurrentLevelVariableManagement.GetLevelUIReference().transform.Find("Merchant Inventory").GetComponent <MerchantInventoryFunctions> ();

        //Define the UISlotContent items that will be added to the inventory.
        merchantItems     = new ResourceReferenceWithStackAndPrice[2];
        merchantItems [0] = new ResourceReferenceWithStackAndPrice(new ResourceReferenceWithStack(ResourceDatabase.GetItemByParameter("Wooden Hatchet"), 1), 10);
        merchantItems [1] = new ResourceReferenceWithStackAndPrice(new ResourceReferenceWithStack(ResourceDatabase.GetItemByParameter("Diamond Sword"), 2), 20);

        string[] dialogue = new string[] {
            "Purchase any item you like!",
            "Everything is cheap at Sluk's Hardware Store!"
        };
        GetComponent <NPCPanelController> ().SetCharacterDialogue(dialogue);
    }
コード例 #6
0
    //Used to determine whether the player has a required item.
    public MerchantSlotScript CheckForCertainInventoryItem(ResourceReferenceWithStackAndPrice pendingObjectToCheck)
    {
        if (slotArray != null)
        {
            for (int y = slotArray.GetLength(0) - 1; y >= 0; y--)
            {
                //Check for a stackable slot.
                for (int x = 0; x < slotArray.GetLength(1); x++)
                {
                    //Define the item that is in the specified slot.
                    ResourceReferenceWithStackAndPrice objectAssigned = slotArray[y, x].GetCurrentlyAssigned();
                    //Check whether the assigned object is null.
                    if (objectAssigned != null)
                    {
                        //Check to make sure the item types are the same.
                        if (objectAssigned.mainContentReference.uiSlotContent.itemType == pendingObjectToCheck.mainContentReference.uiSlotContent.itemType)
                        {
                            //Check to see that the IDs are the same.
                            if (objectAssigned.mainContentReference.uiSlotContent.localGroupID == pendingObjectToCheck.mainContentReference.uiSlotContent.localGroupID)
                            {
                                //Check to see that the stacks are greater or equal to one another.
                                if (objectAssigned.mainContentReference.stack >= pendingObjectToCheck.mainContentReference.stack)
                                {
                                    //Since the slot fits all requirements, return the slot.
                                    return(slotArray [y, x]);
                                }
                            }
                        }
                    }
                }
            }
        }
        else
        {
            Debug.Log("Slot array is null");
        }

        return(null);
    }