Пример #1
0
        public bool AllowsItem(SavableItem item)
        {
            bool isOfRequiredCategory  = false;
            bool hasRequiredProperties = true;

            if (m_RequiredProperties.Count > 0)
            {
                for (int i = 0; i < m_RequiredProperties.Count; i++)
                {
                    if (!item.HasProperty(m_RequiredProperties[i]))
                    {
                        hasRequiredProperties = false;
                        break;
                    }
                }
            }

            if (m_RequiredCategories.Count > 0)
            {
                for (int i = 0; i < m_RequiredCategories.Count; i++)
                {
                    if (m_RequiredCategories[i] == item.ItemData.Category)
                    {
                        isOfRequiredCategory = true;
                        break;
                    }
                }
            }
            else
            {
                isOfRequiredCategory = true;
            }

            return(isOfRequiredCategory && hasRequiredProperties);
        }
Пример #2
0
        /// <summary>
        /// Will return a clone of this slot, without the background (useful when you want to simulate item dragging).
        /// </summary>
        public RectTransform GetDragTemplate(SavableItem forItem, float alpha)
        {
            var template = Instantiate <Slot>(this);

            // HACK: We shouldn't know about the frame object, only the hotbar script should know.
            var frame = template.transform.FindDeepChild("Frame");

            if (frame != null)
            {
                Destroy(frame.gameObject);
            }

            template.enabled       = false;
            template.image.enabled = false;

            template.m_ItemIcon.enabled = true;

            template.m_StackDisplayer.enabled = forItem.CurrentInStack > 1;
            template.m_StackDisplayer.text    = string.Format("x{0}", forItem.CurrentInStack);

            template.m_DurabilityBar.SetActive(forItem.HasProperty("Durability"));

            var group = template.gameObject.AddComponent <CanvasGroup>();

            group.alpha = alpha;

            return(template.GetComponent <RectTransform>());
        }
Пример #3
0
    /// <summary>
    /// 添加物品,一般是ItemHolder还没有物体的时候,即CurrentItem为空
    /// </summary>
    /// <param name="itemData"></param>
    /// <param name="amount"></param>
    /// <param name="added"></param>
    /// <returns></returns>
    public bool TryAddItem(ItemData itemData, int amount, out int added)
    {
        added = 0;
        //如果已经有物体,还不是相同物体,直接跳过
        if (HasItem && itemData.Id != CurrentItem.Id)
        {
            return(false);
        }
        //没有物体
        if (!HasItem)
        {
            CurrentItem = new SavableItem(itemData, 1);
            CurrentItem.CurrentInStack = 0;
            CurrentItem.StackChanged.AddListener(On_StackChanged);
        }
        int oldValue       = CurrentItem.CurrentInStack;
        int surplus        = amount + oldValue - itemData.StackSize;
        int currentInStack = oldValue;

        if (surplus <= 0)
        {
            currentInStack += amount;
        }
        else
        {
            currentInStack = itemData.StackSize;
        }

        CurrentItem.CurrentInStack = currentInStack;
        added = currentInStack - oldValue;

        Updated.Send(this);
        //如果添加了返回true
        return(added > 0);
    }
Пример #4
0
    /// <summary>
    /// 交换物品
    /// </summary>
    /// <param name="item"></param>
    public void ExchangeItem(ItemHolder itemholder)
    {
        SavableItem temp;

        temp                   = CurrentItem;
        CurrentItem            = itemholder.CurrentItem;
        itemholder.CurrentItem = temp;

        Updated.Send(this);
        itemholder.Updated.Send(itemholder);
    }
Пример #5
0
    public bool HasItem(SavableItem item)
    {
        for (int i = 0; i < Slots.Count; i++)
        {
            if (item == Slots[i].CurrentItem)
            {
                return(true);
            }
        }

        return(false);
    }
Пример #6
0
        /// <summary>
        /// Removes a specific item, if it's found in this collection.
        /// </summary>
        public bool TryRemoveItem(SavableItem item)
        {
            Slot targetSlot = Slots.Find((Slot slot) => { return(slot.CurrentItem == item); });

            if (targetSlot)
            {
                targetSlot.ItemHolder.SetItem(null);
                return(true);
            }

            return(false);
        }
Пример #7
0
        public bool HasItem(SavableItem item)
        {
            for (int i = 0; i < m_ItemHolders.Count; i++)
            {
                if (item == m_ItemHolders[i])
                {
                    return(true);
                }
            }

            return(false);
        }
 private void Update()
 {
     if (picked)
     {
         PickedItemTrans.position = Input.mousePosition;
     }
     else
     {
         PickedItemTrans.gameObject.SetActive(false);
         if (pickedItem != null)
         {
             pickedItem = null;
         }
     }
 }
Пример #9
0
    public bool AddItemInShop(ItemData data)
    {
        if (HasItem && data.Id != CurrentItem.Id)
        {
            return(false);
        }

        if (!HasItem)
        {
            CurrentItem = new SavableItem(data, 1);
            Updated.Send(this);
            return(true);
        }
        return(false);
    }
Пример #10
0
        /// <summary>
        /// Tries to add a specific item in this collection.
        /// </summary>
        /// <param name="item">The runtime representation of the item.</param>
        public bool TryAddItem(SavableItem item)
        {
            if (item == null)
            {
                return(false);
            }

            int added = 0;

            CollectionUtils.AddItem(item.ItemData, item.CurrentInStack, Slots, out added, item.CurrentPropertyValues);

            //if(added != item.CurrentInStack)
            //	InventoryController.Instance.Try_DropItem(new SavableItem(item.ItemData, item.CurrentInStack - added, item.CurrentPropertyValues));

            return(added > 0);
        }
Пример #11
0
    /// <summary>
    /// 设置物品,一般是ItemHolder已经有物体的时候
    /// </summary>
    /// <param name="item"></param>
    public void SetItem(SavableItem item)
    {
        if (CurrentItem)
        {
            //CurrentItem.PropertyChanged.RemoveListener(On_PropertyChanged);
            CurrentItem.StackChanged.RemoveListener(On_StackChanged);
        }

        CurrentItem = item;

        if (CurrentItem)
        {
            //CurrentItem.PropertyChanged.AddListener(On_PropertyChanged);
            CurrentItem.StackChanged.AddListener(On_StackChanged);
        }

        Updated.Send(this);
    }
Пример #12
0
        private void ShowInfo(SavableItem item)
        {
            // Name.
            m_ItemName.text = (item.ItemData.DisplayName == string.Empty) ? item.ItemData.Name : item.ItemData.DisplayName;

            // Main description.
            if (item.ItemData.Descriptions.Length > 0)
            {
                m_MainDescription.text = item.GetDescription(0);
            }
            else
            {
                m_MainDescription.text = "";
            }

            // Secondary description.
            if (item.ItemData.Descriptions.Length > 1)
            {
                m_SecondaryDescription.text = item.GetDescription(1);
            }
            else
            {
                m_SecondaryDescription.text = "";
            }

            // Icon.
            m_Icon.sprite = item.ItemData.Icon;

            // Durability bar.
            if (item.HasProperty("Durability"))
            {
                if (!m_DurabilityBar.Active)
                {
                    m_DurabilityBar.SetActive(true);
                }

                m_DurabilityBar.SetFillAmount(item.GetPropertyValue("Durability").Float.Ratio);
            }
            else if (m_DurabilityBar.Active)
            {
                m_DurabilityBar.SetActive(false);
            }

            // Magazine.
            ItemProperty.Value property;
            if (item.FindPropertyValue("Magazine", out property))
            {
                var magazine = property.IntRange;
                m_Magazine.text = "Magazine: " + magazine.ToString();
            }
            else
            {
                m_Magazine.text = "";
            }

            // Consume action.
            m_ConsumeButton.gameObject.SetActive(item.HasProperty("Can Consume"));

            // Dismantle action.
            m_DismantleButton.gameObject.SetActive(item.HasProperty("Can Dismantle"));
        }
    //鼠标点击事件
    void OnDownSlot(PointerEventData eventData, Slot slot)
    {
        if (slot.CurrentItem == null)
        {
            return;
        }
        //左键点击事件
        if (eventData.button == PointerEventData.InputButton.Left)
        {
            PickedItemTrans.gameObject.SetActive(true);
            PickedItemImage.sprite = slot.GetImage();
            pickedItem             = slot.ItemHolder.CurrentItem;
            picked = true;

            currentSlot = slot;//储存格子的引用
            slot.HideImage();
        }
        //右键点击事件
        else if (eventData.button == PointerEventData.InputButton.Right)
        {
            //如果点击的是背包里的格子
            if (slot.SlotType == SlotType.背包)
            {
                //等级判断
                if (PlayerStateInfo.Instance.Level.Get() < slot.CurrentItem.ItemData.NeedLevel)
                {
                    Debug.Log("等级不够");
                    return;
                }
                if (slot.CurrentItem.MainType == ItemMainType.消耗品)//消耗品
                {
                    //使用消耗品,并显示特效
                    //应用属性
                    foreach (var property in slot.CurrentItem.BasePropertys)
                    {
                        if (property.BaseProperty == BasePropertyType.生命值)
                        {
                            if (PlayerStateInfo.Instance.HP.Get() == PlayerStateInfo.Instance.MaxHp.Get())
                            {
                                return;
                            }
                            PlayerStateInfo.Instance.HP.Set(PlayerStateInfo.Instance.HP.Get() + property.Value);
                            //显示加血特效
                            PlayerContorller.Instance.ShowHpEffect();
                        }
                        else if (property.BaseProperty == BasePropertyType.魔法值)
                        {
                            if (PlayerStateInfo.Instance.MP.Get() == PlayerStateInfo.Instance.MaxMp.Get())
                            {
                                return;
                            }
                            PlayerStateInfo.Instance.MP.Set(PlayerStateInfo.Instance.MP.Get() + property.Value);
                            //显示加蓝特效
                            PlayerContorller.Instance.ShowMpEffect();
                        }
                    }
                    slot.ItemHolder.RemoveFromStack(1);
                }
                else if (slot.CurrentItem.MainType != ItemMainType.材料)//装备
                {
                    //装备使用逻辑在EquipmentContainer中已有
                    InventoryController.Instance.EquipmentContainer.TryAddEquipment(slot.ItemHolder);
                }
            }//如果点击的是装备栏里的格子
            else if (slot.SlotType != SlotType.商店 && slot.SlotType != SlotType.技能)
            {
                //卸掉装备
                int added;
                InventoryController.Instance.InventoryContainer.TryAddItem(slot.CurrentItem.ItemData, 1, out added);
                slot.ItemHolder.RemoveFromStack(1);
            }
        }
    }