示例#1
0
        private IEnumerator C_Update(CraftData craftData, ItemContainer inventory)
        {
            //float waitTimeInSeconds = 1f;
            //var waitTime = new WaitForSeconds(waitTimeInSeconds);

            while (m_AmountToCraftRemained > 0)
            {
                float remainedTime = craftData.Result.Recipe.Duration;

                while (remainedTime > 0)
                {
                    yield return(null);

                    remainedTime             = Mathf.Clamp(remainedTime - Time.deltaTime, 0, Mathf.Infinity);
                    m_RemainedTime.text      = string.Format("{0}s (x{1})", Mathf.Ceil(remainedTime), m_AmountToCraftRemained);
                    m_ProgressBar.fillAmount = 1f - remainedTime / craftData.Result.Recipe.Duration;
                }

                // The item was successfully crafted.
                inventory.TryAddItem(m_Result, 1);
                m_AmountToCraftRemained--;

                m_ProgressBar.fillAmount = 0f;
                m_RemainedTime.text      = string.Format("{0}s (x{1})", 0, m_AmountToCraftRemained);
            }

            Complete.Send();
            Destroy(gameObject);
        }
示例#2
0
        public void CancelCrafting()
        {
            if (m_AmountToCraftRemained > 0)
            {
                foreach (var item in m_CraftData.Result.Recipe.RequiredItems)
                {
                    ItemData itemData;
                    InventoryController.Instance.Database.FindItemByName(item.Name, out itemData);
                    m_Inventory.TryAddItem(itemData, item.Amount * m_AmountToCraftRemained);
                }
            }

            Cancel.Send(this);
            Destroy(gameObject);
        }
示例#3
0
        private void On_DismantleClicked()
        {
            var item = InspectedSlot.CurrentItem;

            InspectedSlot.ItemHolder.SetItem(null);

            var requiredItems = item.ItemData.Recipe.RequiredItems;

            for (int i = 0; i < requiredItems.Length; i++)
            {
                var amountToGive = Mathf.RoundToInt(requiredItems[i].Amount * item.GetPropertyValue("Durability").Float.Ratio * 0.6f) + 1;
                m_InventoryContainer.TryAddItem(requiredItems[i].Name, amountToGive);
            }

            MessageDisplayer.Instance.PushMessage(string.Format("<color=yellow>{0}</color> has been dismantled", item.Name));
            m_DismantleAudio.Play2D();
        }