Beispiel #1
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);
        }
    }
Beispiel #2
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);
        }
    }
Beispiel #3
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;
        }
    }