Example #1
0
    private void UpdateItem(ItemData item)
    {
        ItemStaticData staticData = GameData.instance.item_static_data[item.static_id];

        item_name.text     = staticData.name;
        item_type.text     = GameConst.itemTypeName[staticData.type];
        item_sub_type.text = GameConst.itemSubTypeName[staticData.sub_ype];
        item_need_lv.text  = LevelConfigData.GetBigName(staticData.level);

        string[] array = staticData.des.Split('\n');
        for (int i = 1; i < transform.childCount; i++)
        {
            if (i > array.Length)
            {
                transform.GetChild(i).gameObject.SetActive(false);
            }
            else
            {
                GameObject obj = transform.GetChild(i).gameObject;
                obj.SetActive(true);
                obj.GetComponent <Text>().text = array[i - 1];
            }
        }
        //item_attr.text = GetItemAttrDes(staticData);
        item_bg.sprite    = UIAssets.instance.bgColor[staticData.color];
        item_color.sprite = UIAssets.instance.itemColor[staticData.color];
        item_icon.sprite  = UIAssets.instance.itemIcon[staticData.icon];
        item_use.SetActive(RoleData.mainRole.ItemIsEquip(item.id));
    }
Example #2
0
    public void EquipItem(int item_id, int idx)
    {
        ItemData       item        = GameData.instance.all_item[item_id];
        ItemStaticData static_data = GameData.instance.item_static_data[item.static_id];

        if (!LevelConfigData.CheckLevel(GetAttr(RoleAttribute.level), static_data.level))
        {
            MessageTips.Message(43, LevelConfigData.GetBigName(static_data.level));
            return;
        }

        if (static_data.sub_ype == ItemSubType.recoverRemedy || static_data.sub_ype == ItemSubType.buffRemedy)
        {
            remedy_items[idx] = item_id;
            EventManager.SendEvent(EventTyp.ItemChange, null);
        }
        else
        {
            EquipItem(item_id);
        }
    }
Example #3
0
    /// <summary>
    /// 装备物品
    /// 戒指或坐骑:如果是已穿戴就卸下,否则就穿戴
    /// 药物:是已装备的药物则卸下,否则装备到最后一个空格子,没有的话提示装备已满
    /// </summary>
    public void EquipItem(int item_id)
    {
        ItemData       item        = GameData.instance.all_item[item_id];
        ItemStaticData static_data = GameData.instance.item_static_data[item.static_id];

        if (!LevelConfigData.CheckLevel(GetAttr(RoleAttribute.level), static_data.level))
        {
            MessageTips.Message(43, LevelConfigData.GetBigName(static_data.level));
            return;
        }
        // 移除穿在身上的
        if (static_data.sub_ype == ItemSubType.Ring)
        {
            if (equip_items[0] != -1)
            {
                int empty_count = GetAttr(RoleAttribute.max_item) - bag_items.Count;
                if (equip_items[0] == item_id)
                {
                    // 脱下
                    empty_count -= GetItemAttrbuite(item_id, RoleAttribute.max_item);
                }
                else
                {
                    // 更换
                    if (equip_items[0] != -1)
                    {
                        empty_count -= GetItemAttrbuite(equip_items[0], RoleAttribute.max_item);
                    }
                    empty_count += GetItemAttrbuite(item_id, RoleAttribute.max_item);
                }
                if (empty_count < 0)
                {
                    // 无法更换或脱下戒指
                    MessageTips.Message(44);
                    return;
                }
            }

            if (equip_items[0] == item_id)   // 戒指
            {
                equip_items[0] = -1;
            }
            else
            {
                equip_items[0] = item_id;
            }
            UpdateAttr();
            EventManager.SendEvent(EventTyp.ItemChange, null);
        }
        else if (static_data.sub_ype == ItemSubType.Ride)
        {
            if (equip_items[1] == item_id)   // 坐骑
            {
                equip_items[1] = -1;
            }
            else
            {
                equip_items[1] = item_id;
            }
            UpdateAttr();
            EventManager.SendEvent(EventTyp.ItemChange, null);
        }
        else if (static_data.sub_ype == ItemSubType.recoverRemedy || static_data.sub_ype == ItemSubType.buffRemedy)
        {
            for (int i = 0; i < remedy_items.Length; i++)   // 判断卸下丹药
            {
                if (remedy_items[i] == item_id)
                {
                    remedy_items[i] = -1;
                    EventManager.SendEvent(EventTyp.ItemChange, null);
                    return;
                }
            }
            for (int i = 0; i < remedy_items.Length; i++)   // 判断穿戴丹药
            {
                if (remedy_items[i] == -1)
                {
                    remedy_items[i] = item_id;
                    EventManager.SendEvent(EventTyp.ItemChange, null);
                    return;
                }
            }
            MessageTips.Message(27);
        }
    }
Example #4
0
    public void UseItem(int item_id, int count = 1)
    {
        ItemData       item        = GameData.instance.all_item[item_id];
        ItemStaticData static_data = GameData.instance.item_static_data[item.static_id];

        if (!LevelConfigData.CheckLevel(GetAttr(RoleAttribute.level), static_data.level))
        {
            MessageTips.Message(43, LevelConfigData.GetBigName(static_data.level));
            return;
        }


        switch (static_data.type)
        {
        case ItemType.Remedy:     // 丹药类
            switch (static_data.sub_ype)
            {
            case ItemSubType.recoverRemedy:         // 恢复类丹药
                // 扣除道具
                RemoveItem(item_id, count);
                // 恢复
                for (int i = 0; i < static_data.attributes.Length; i++)
                {
                    ChangeAttrebuteValue(static_data.attributes[i], static_data.attr_values[i] * count);
                }
                break;

            case ItemSubType.aptitudesRemedy:         // 资质丹药
                // 扣除道具
                RemoveItem(item_id, count);
                // 增加属性
                for (int i = 0; i < static_data.attributes.Length; i++)
                {
                    int multiple = (GetAttr(static_data.attributes[i]) >= static_data.param[0]) ? 0 : 1;
                    ChangeAttrebuteMaxValue(static_data.attributes[i], static_data.attr_values[i] * count * multiple);
                    if (multiple < 1)
                    {
                        MessageTips.Message(46);
                    }
                }
                break;

            case ItemSubType.buffRemedy:
                break;

            case ItemSubType.otherRemedy:
                break;
            }
            break;

        case ItemType.Gongfa:     // 功法类
            GongfaStaticData  gongfa    = GameData.GetStaticGongfaFromItem(item_id);
            RoleAttribute[][] need_attr = gongfa.attr_condition;
            var need_value      = gongfa.value_condition;
            int condition_count = need_value.Length;
            for (int i = 0; i < condition_count; i++)
            {
                RoleAttribute[] need  = need_attr[i];
                int             value = need_value[i];
                bool            can   = false;
                foreach (RoleAttribute attr in need)
                {
                    if (GetAttr(attr) >= value)
                    {
                        can = true;
                        break;
                    }
                }
                if (!can)
                {
                    // 修炼资质不足
                    MessageTips.Message(45);
                    return;
                }
            }
            RemoveItem(item_id, count, false);
            GongfaData new_gongfa = new GongfaData()
            {
                item_id = item.id, attr_value = gongfa.attr_value, ex_values = gongfa.ex_values, ex_color = gongfa.ex_color
            };
            all_gongfa.Add(new_gongfa);
            int mood = 10;
            ChangeAttrebuteValue(RoleAttribute.mood, -mood);
            GameData.instance.SetGameData(GlobalAttribute.time, GameData.instance.GetGameData(GlobalAttribute.time) + GameConst.oneDayTicks * 15);
            MessageWindow.Message(49, 50, null, 0, mood.ToString(), gongfa.name);
            break;
        }
    }
Example #5
0
    public void SetItem(GongfaData gongfa, RoleData role = null, bool isBag = false, System.Action clickFunc = null)
    {
        roleData       = role;
        this.gongfa    = gongfa;
        this.isBag     = isBag;
        this.clickFunc = clickFunc;
        if (gongfa == null)
        {
            icon.enabled = false;
            color.sprite = UIAssets.instance.gongfaColor[0];;
            if (bg)
            {
                bg.sprite = UIAssets.instance.bgColor[0];
            }
            if (t_name)
            {
                t_name.text = null;
            }
            if (t_type)
            {
                t_type.text = null;
            }
            if (t_level)
            {
                t_level.text = null;
            }
            Tools.SetActive(useing, false);
            return;
        }

        int            item_id     = gongfa.item_id;
        ItemData       item        = GameData.instance.all_item[item_id];
        ItemStaticData static_data = GameData.instance.item_static_data[item.static_id];

        icon.enabled = true;
        icon.sprite  = UIAssets.instance.itemIcon[static_data.icon];
        color.sprite = UIAssets.instance.gongfaColor[static_data.color];
        if (bg)
        {
            bg.sprite = UIAssets.instance.bgColor[static_data.color];
        }
        if (t_name)
        {
            t_name.text = static_data.name;
        }
        if (t_type)
        {
            t_type.text = GameConst.itemSubTypeName[static_data.sub_ype];
        }
        if (t_level)
        {
            t_level.text = LevelConfigData.GetBigName(static_data.level);
        }

        if (roleData == null || !isBag)
        {
            can_drag = false;
            Tools.SetActive(useing, false);
            return;
        }

        bool isWear = roleData.GonfaIsEquip(gongfa); // 是否穿戴着

        Tools.SetActive(useing, isWear);
        can_drag = roleData == RoleData.mainRole && !isWear;
    }