Beispiel #1
0
    public void  TakeSelectedItems()
    {
        if (SelectedItem >= 0)        //Check if the player has selected an item before pressing this button.
        {
            Transform ItemSelected = ActiveItemGroup.Content[SelectedItem];
            if (InvManager.Items < InvManager.MaxItems || ItemSelected.gameObject.GetComponent <Item>().ItemType == 1) //Check if we still have room for new item:
            {
                Item ItemScript = ItemSelected.gameObject.GetComponent <Item>();                                       //Getting the item script.

                //Removing this item from the item group content.
                List <Transform> TempContent = new List <Transform>(ActiveItemGroup.Content);
                TempContent.Remove(ItemSelected);
                ActiveItemGroup.Content = TempContent.ToArray();

                if (ItemScript.ItemType == 0)
                {
                    InvManager.AddItem(ItemSelected);                     //Add this item to the bag
                }
                if (ItemScript.ItemType == 1)
                {
                    InvManager.AddCurrency(ItemSelected);                     //Add this currency to the inventory
                }

                //Reset the selected item var:
                if (SelectedItem >= 0)
                {
                    Items[SelectedItem].Textfield.color = LastTextColor;
                }
                SelectedItem = -1;
                RefreshItems();
            }
            else
            {
                if (MsgUI != null)
                {
                    MsgUI.SendMsg("Inventory is full!");
                }
                SelectedItem = -1;
                return;
            }
        }

        if (ActiveItemGroup.Content.Length == 0)
        {
            DesactivatePanel();
        }
    }
Beispiel #2
0
    void  OnMouseDown()
    {
        float Distance;

        Distance = Vector3.Distance(MyTransform.position, InvManager.Player.transform.position);         //Get the current distance between the player and the item.
        if (Distance <= MinDistance && InvManager.PickupType == InventoryManager.PickupTypes.Mouse)      //Check if that distance is below or equal to the minimum distance. And the player is using the mouse to pick up items.
        {
            if (ItemType == 0)
            {
                InvManager.AddItem(MyTransform);                 //Add this item to the bag
            }
            if (ItemType == 1)
            {
                InvManager.AddCurrency(MyTransform);                 //Add this currency to the inventory
            }
        }
    }
        public override void OnEnter()
        {
            if (amount.Value > 0f)
            {
                InventoryManager.AddCurrency((uint)currencyID.Value, amount.Value);
            }
            else if (amount.Value < 0f)
            {
                InventoryManager.RemoveCurrency((uint)currencyID.Value, Mathf.Abs(amount.Value));
            }

            Finish();
        }
Beispiel #4
0
        public void DataProvider_Callback(string[] nfo)
        {
            // this is what gets called when DiaQuest.RunRewardGivers()
            // is called and this provider is chosen for handling
            // a reward entry in the quest. Note that RunRewardGivers()
            // will append the reward value to the nfo array so the
            // last entry in this array will be the value as entered
            // in the quest editor. The other nfo entries are as you
            // set them up in the Info (editor) class. DiaQSampleRewardGiverInfo

            // I know that I defined the following about nfo
            // nfo[0] = 0:Currency, 1:InventoryPro Item
            // nfo[1] = ID of item / ID of currency
            // nfo[2] = the value (amount of items, or amount of curency)

            if (nfo[0] == "0")
            {
                var currencyID = int.Parse(nfo[1]);
                if (currencyID < 0)
                {
                    return; // Not a currencyID
                }
                InventoryManager.AddCurrency((uint)currencyID, float.Parse(nfo[3]));

                // Give player
                Debug.Log("(DiaQ) Player received: " + nfo[3] + " " + nfo[2]);
            }
            else if (nfo[0] == "1")
            {
                var itemID = int.Parse(nfo[1]);
                if (itemID < 0)
                {
                    return; // Not an itemID
                }
                var item = GameObject.Instantiate <InventoryItemBase>(ItemManager.database.items[itemID]);
                item.currentStackSize = uint.Parse(nfo[3]);

                InventoryManager.AddItem(item);
            }
        }
Beispiel #5
0
 private static void AddCurrency(string currencyID, float amount)
 {
     InventoryManager.AddCurrency(GetCurrencyFromID(currencyID).ID, amount);
 }
Beispiel #6
0
		protected override void OnExecute(){
			InventoryManager.AddCurrency((uint)currencyID.value, amount.value);
			EndAction(true);
		}
Beispiel #7
0
    //Purchasing items:
    public void  PurchaseItem(Transform ItemSelected)
    {
        Item SelectedItemScript = ItemSelected.GetComponent <Item>();        //Getting the item script.
        bool HasCurrency        = true;
        bool HasAmount          = true;
        bool InvSpace           = true;

        for (int i = 0; i < InvManager.Riches.Length; i++)                                                         //Starting a loop in the currencies types:
        {
            if (InvManager.Items < InvManager.MaxItems)                                                            //If we still have room for new item:
            {
                if (InvManager.Riches[i].Name == SelectedItemScript.Currency)                                      //If the required currency type for this item exists in the inventory.
                {
                    if (InvManager.Riches[i].Amount >= SelectedItemScript.CurrencyAmount)                          //And if the amount is enough
                    {
                        InvManager.RemoveCurrency(SelectedItemScript.Currency, SelectedItemScript.CurrencyAmount); //Reduce the amount of this currency.
                        Transform ItemClone;
                        ItemClone = Instantiate(ItemSelected, ItemSelected.transform.position, ItemSelected.transform.rotation) as Transform;
                        GetComponent <AudioSource>().PlayOneShot(ItemSold);
                        if (SelectedItemScript.ItemType == 0)
                        {
                            InvManager.AddItem(ItemClone);                             //Add this item to the bag
                        }
                        if (SelectedItemScript.ItemType == 1)
                        {
                            InvManager.AddCurrency(ItemClone);                             //Add this currency to the inventory
                        }

                        HasCurrency = true;
                        HasAmount   = true;
                        InvSpace    = true;

                        CustomEvents.OnPlayerBuyItem(ItemClone.GetComponent <Item>());
                        return;
                    }
                    else
                    {
                        HasAmount = false;
                    }
                }
                else
                {
                    HasCurrency = false;
                }
            }
            else
            {
                InvSpace = false;
            }
        }
        if (InvSpace == false)        //If there isn't room for the new item:
        {
            if (MsgUI != null)
            {
                MsgUI.SendMsg("Inventory is full!");
            }
        }
        else if (HasCurrency == false)        //If we don't have the required type of currency.
        {
            if (MsgUI != null)
            {
                MsgUI.SendMsg("You don't have " + SelectedItemScript.Currency + ".");
            }
        }
        else if (HasAmount == false)        //If we don't have the enough amount of currency.
        {
            if (MsgUI != null)
            {
                MsgUI.SendMsg("You don't have enough " + SelectedItemScript.Currency + ".");
            }
            if (InvManager.AudioSC)
            {
                InvManager.AudioSC.PlayOneShot(CantAfford);
            }
        }
    }
 public override BlockReturn Run(BlockReturn param)
 {
     InventoryManager.AddCurrency((uint)currencyID.value, amount.value);
     return(BlockReturn.OK);
 }