local isMobile = SL:GetMetaValue("CURRENT_OPERMODE") or 1
-- 显示物品需求
if GUI:Win_IsNotNull(ui.itemroom) and next_cfg then
GUI:removeAllChildren(ui.itemroom)
-- 焚天系统物品需求显示
local item_name = next_cfg.name1 or "化魔石"
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-03-20 19:47:23 |
👁️ 阅读: 9
```lua
local isMobile = SL:GetMetaValue("CURRENT_OPERMODE") or 1
-- 显示物品需求
if GUI:Win_IsNotNull(ui.itemroom) and next_cfg then
GUI:removeAllChildren(ui.itemroom)
-- 焚天系统物品需求显示
local item_name = next_cfg.name1 or "化魔石"
local itemCount = tonumber(SL:GetMetaValue("ITEM_COUNT", item_name)) or 0
local needItemCount = tonumber(next_cfg.value1) or 0
local goldCount = tonumber(SL:GetMetaValue("MONEY", 2)) or 0
local needGold = tonumber(next_cfg.value2) or 0
-- 获取物品ID
local item_id = 0
if item_name == "化魔石" then
item_id = 11549 -- 神源之石的物品ID
else
item_id = lib:getitemidx(item_name) or 11549
end
-- 获取货币ID
local money_id = 2 -- 金币的货币ID
-- 安全比较函数
local function safe_lt(a, b)
local num_a = tonumber(a) or 0
local num_b = tonumber(b) or 0
return num_a < num_b
end
-- 根据是否足够设置颜色
local itemColor = 255
if safe_lt(itemCount, needItemCount) then
itemColor = 58
end
local goldColor = 255
if safe_lt(goldCount, needGold) then
goldColor = 58
end
-- 根据平台设置坐标
local goldX, goldY = 280, 90
local itemX, itemY = 193, 90
local itemX2, itemY2 = 333, 240
if isMobile == 2 then
-- 手机端坐标调整
goldX, goldY = 84, 90
itemX, itemY = 20, 90
itemX2, itemY2 = -455, 280
end
-- 显示物品需求
GUI:ItemShow_Create(ui.itemroom, "ItemShow_1", itemX, itemY, {
index = item_id,
count = needItemCount,
look = true,
bgVisible = false,
color = itemColor
})
-- 显示金币需求
GUI:ItemShow_Create(ui.itemroom, "ItemShow_2", goldX, goldY, {
index = money_id,
count = needGold,
look = true,
bgVisible = false,
color = goldColor
})
-- 获取等级和魔力值
local u44_level = tonumber(SL:GetMetaValue("U44_LEVEL")) or 0
local magic_value = tonumber(SL:GetMetaValue("MAGIC_VALUE")) or 0
-- 检查是否显示ItemShow_3
if u44_level >= 10 and magic_value >= 1000 then
-- 隐藏Effect_1
if GUI:Win_IsNotNull(ui.Effect_1) then
GUI:setVisible(ui.Effect_1, false)
end
-- 显示ItemShow_3
local current_gemid = 50834 -- 默认ID
GUI:ItemShow_Create(ui.itemroom, "ItemShow_3", itemX2, itemY2, {
index = current_gemid,
count = 1,
look = true,
bgVisible = false,
})
end
end
-- 按钮点击事件
if GUI:Win_IsNotNull(ui.Button_2) then
GUI:addOnClickEvent(ui.Button_2, function()
SL:print("点击了第2个按钮")
GUI:delayTouchEnabled(ui.Button_2, 0.2)
-- 获取当前等级和魔力值
local u44_level = tonumber(SL:GetMetaValue("U44_LEVEL")) or 0
local magic_value = tonumber(SL:GetMetaValue("MAGIC_VALUE")) or 0
-- 定义ID映射表
local gemid_map = {
[10] = 50834, -- 默认
[20] = 50835,
[30] = 50836,
[40] = 50837,
[50] = 50838,
[60] = 50839,
[70] = 50840,
[80] = 50841,
[90] = 50842,
[100] = 50843
}
-- 定义魔力值要求
local magic_requirements = {
[10] = 1000,
[20] = 3000,
[30] = 4000,
[40] = 8000,
[50] = 8000,
[60] = 16000,
[70] = 32000,
[80] = 128000,
[90] = 256000,
[100] = 512000
}
-- 确定当前应该显示的ID
local target_gemid = 50834 -- 默认
-- 从高到低检查条件
if u44_level >= 100 and magic_value >= magic_requirements[100] then
target_gemid = gemid_map[100]
elseif u44_level >= 90 and magic_value >= magic_requirements[90] then
target_gemid = gemid_map[90]
elseif u44_level >= 80 and magic_value >= magic_requirements[80] then
target_gemid = gemid_map[80]
elseif u44_level >= 70 and magic_value >= magic_requirements[70] then
target_gemid = gemid_map[70]
elseif u44_level >= 60 and magic_value >= magic_requirements[60] then
target_gemid = gemid_map[60]
elseif u44_level >= 50 and magic_value >= magic_requirements[50] then
target_gemid = gemid_map[50]
elseif u44_level >= 40 and magic_value >= magic_requirements[40] then
target_gemid = gemid_map[40]
elseif u44_level >= 30 and magic_value >= magic_requirements[30] then
target_gemid = gemid_map[30]
elseif u44_level >= 20 and magic_value >= magic_requirements[20] then
target_gemid = gemid_map[20]
elseif u44_level >= 10 and magic_value >= magic_requirements[10] then
target_gemid = gemid_map[10]
end
-- 更新ItemShow_3
if GUI:Win_IsNotNull(ui.itemroom) then
-- 先移除现有的ItemShow_3
local old_item = GUI:getChildByName(ui.itemroom, "ItemShow_3")
if GUI:Win_IsNotNull(old_item) then
GUI:removeFromParent(old_item)
end
-- 根据平台设置坐标
local itemX2, itemY2 = 333, 240
if isMobile == 2 then
itemX2, itemY2 = -455, 280
end
-- 创建新的ItemShow_3
GUI:ItemShow_Create(ui.itemroom, "ItemShow_3", itemX2, itemY2, {
index = target_gemid,
count = 1,
look = true,
bgVisible = false,
})
end
-- 发送网络消息
local msg = {}
msg.Script = moshen.param1
local jsonstr = SL:JsonEncode(msg)
SL:SendLuaNetMsg(58003, moshen.param2, 1, 0, jsonstr)
end)
end
```
**代码说明:**
1. **等级和魔力值检查**:使用 `SL:GetMetaValue` 获取 `U44_LEVEL` 和 `MAGIC_VALUE` 来判断是否满足条件
2. **ItemShow_3显示逻辑**:
- 当等级≥10且魔力值≥1000时,隐藏 `Effect_1` 并显示默认ID为50834的 `ItemShow_3`
- 使用 `GUI:setVisible(ui.Effect_1, false)` 隐藏特效
3. **按钮点击事件**:
- 根据等级和魔力值条件,从高到低检查并确定应该显示的物品ID
- 每次点击时先移除旧的 `ItemShow_3`,再创建新的
- 使用 `GUI:removeFromParent()` 移除旧组件
4. **坐标处理**:
- 根据 `CURRENT_OPERMODE` 判断平台类型
- PC端和手机端使用不同的坐标
5. **网络通信**:
- 点击按钮后发送网络消息到服务器
- 使用 `SL:SendLuaNetMsg` 发送消息
**注意**:确保服务器端有对应的 `U44_LEVEL` 和 `MAGIC_VALUE` 数据,否则获取到的值会是0。
```lua
local isMobile = SL:GetMetaValue("CURRENT_OPERMODE") or 1
-- 显示物品需求
if GUI:Win_IsNotNull(ui.itemroom) and next_cfg then
GUI:removeAllChildren(ui.itemroom)
-- 焚天系统物品需求显示
local item_name = next_cfg.name1 or "化魔石"
local itemCount = tonumber(SL:GetMetaValue("ITEM_COUNT", item_name)) or 0
local needItemCount = tonumber(next_cfg.value1) or 0
local goldCount = tonumber(SL:GetMetaValue("MONEY", 2)) or 0
local needGold = tonumber(next_cfg.value2) or 0
-- 获取物品ID
local item_id = 0
if item_name == "化魔石" then
item_id = 11549 -- 神源之石的物品ID
else
item_id = lib:getitemidx(item_name) or 11549
end
-- 获取货币ID
local money_id = 2 -- 金币的货币ID
-- 安全比较函数
local function safe_lt(a, b)
local num_a = tonumber(a) or 0
local num_b = tonumber(b) or 0
return num_a < num_b
end
-- 根据是否足够设置颜色
local itemColor = 255
if safe_lt(itemCount, needItemCount) then
itemColor = 58
end
local goldColor = 255
if safe_lt(goldCount, needGold) then
goldColor = 58
end
-- 根据平台设置坐标
local goldX, goldY = 280, 90
local itemX, itemY = 193, 90
local itemX2, itemY2 = 333, 240
if isMobile == 2 then
-- 手机端坐标调整
goldX, goldY = 84, 90
itemX, itemY = 20, 90
itemX2, itemY2 = -455, 280
end
-- 显示物品需求
GUI:ItemShow_Create(ui.itemroom, "ItemShow_1", itemX, itemY, {
index = item_id,
count = needItemCount,
look = true,
bgVisible = false,
color = itemColor
})
-- 显示金币需求
GUI:ItemShow_Create(ui.itemroom, "ItemShow_2", goldX, goldY, {
index = money_id,
count = needGold,
look = true,
bgVisible = false,
color = goldColor
})
-- 获取等级和魔力值
local u44_level = tonumber(SL:GetMetaValue("U44_LEVEL")) or 0
local magic_value = tonumber(SL:GetMetaValue("MAGIC_VALUE")) or 0
-- 检查是否显示ItemShow_3
if u44_level >= 10 and magic_value >= 1000 then
-- 隐藏Effect_1
if GUI:Win_IsNotNull(ui.Effect_1) then
GUI:setVisible(ui.Effect_1, false)
end
-- 显示ItemShow_3
local current_gemid = 50834 -- 默认ID
GUI:ItemShow_Create(ui.itemroom, "ItemShow_3", itemX2, itemY2, {
index = current_gemid,
count = 1,
look = true,
bgVisible = false,
})
end
end
-- 按钮点击事件
if GUI:Win_IsNotNull(ui.Button_2) then
GUI:addOnClickEvent(ui.Button_2, function()
SL:print("点击了第2个按钮")
GUI:delayTouchEnabled(ui.Button_2, 0.2)
-- 获取当前等级和魔力值
local u44_level = tonumber(SL:GetMetaValue("U44_LEVEL")) or 0
local magic_value = tonumber(SL:GetMetaValue("MAGIC_VALUE")) or 0
-- 定义ID映射表
local gemid_map = {
[10] = 50834, -- 默认
[20] = 50835,
[30] = 50836,
[40] = 50837,
[50] = 50838,
[60] = 50839,
[70] = 50840,
[80] = 50841,
[90] = 50842,
[100] = 50843
}
-- 定义魔力值要求
local magic_requirements = {
[10] = 1000,
[20] = 3000,
[30] = 4000,
[40] = 8000,
[50] = 8000,
[60] = 16000,
[70] = 32000,
[80] = 128000,
[90] = 256000,
[100] = 512000
}
-- 确定当前应该显示的ID
local target_gemid = 50834 -- 默认
-- 从高到低检查条件
if u44_level >= 100 and magic_value >= magic_requirements[100] then
target_gemid = gemid_map[100]
elseif u44_level >= 90 and magic_value >= magic_requirements[90] then
target_gemid = gemid_map[90]
elseif u44_level >= 80 and magic_value >= magic_requirements[80] then
target_gemid = gemid_map[80]
elseif u44_level >= 70 and magic_value >= magic_requirements[70] then
target_gemid = gemid_map[70]
elseif u44_level >= 60 and magic_value >= magic_requirements[60] then
target_gemid = gemid_map[60]
elseif u44_level >= 50 and magic_value >= magic_requirements[50] then
target_gemid = gemid_map[50]
elseif u44_level >= 40 and magic_value >= magic_requirements[40] then
target_gemid = gemid_map[40]
elseif u44_level >= 30 and magic_value >= magic_requirements[30] then
target_gemid = gemid_map[30]
elseif u44_level >= 20 and magic_value >= magic_requirements[20] then
target_gemid = gemid_map[20]
elseif u44_level >= 10 and magic_value >= magic_requirements[10] then
target_gemid = gemid_map[10]
end
-- 更新ItemShow_3
if GUI:Win_IsNotNull(ui.itemroom) then
-- 先移除现有的ItemShow_3
local old_item = GUI:getChildByName(ui.itemroom, "ItemShow_3")
if GUI:Win_IsNotNull(old_item) then
GUI:removeFromParent(old_item)
end
-- 根据平台设置坐标
local itemX2, itemY2 = 333, 240
if isMobile == 2 then
itemX2, itemY2 = -455, 280
end
-- 创建新的ItemShow_3
GUI:ItemShow_Create(ui.itemroom, "ItemShow_3", itemX2, itemY2, {
index = target_gemid,
count = 1,
look = true,
bgVisible = false,
})
end
-- 发送网络消息
local msg = {}
msg.Script = moshen.param1
local jsonstr = SL:JsonEncode(msg)
SL:SendLuaNetMsg(58003, moshen.param2, 1, 0, jsonstr)
end)
end
```
**代码说明:**
1. **等级和魔力值检查**:使用 `SL:GetMetaValue` 获取 `U44_LEVEL` 和 `MAGIC_VALUE` 来判断是否满足条件
2. **ItemShow_3显示逻辑**:
- 当等级≥10且魔力值≥1000时,隐藏 `Effect_1` 并显示默认ID为50834的 `ItemShow_3`
- 使用 `GUI:setVisible(ui.Effect_1, false)` 隐藏特效
3. **按钮点击事件**:
- 根据等级和魔力值条件,从高到低检查并确定应该显示的物品ID
- 每次点击时先移除旧的 `ItemShow_3`,再创建新的
- 使用 `GUI:removeFromParent()` 移除旧组件
4. **坐标处理**:
- 根据 `CURRENT_OPERMODE` 判断平台类型
- PC端和手机端使用不同的坐标
5. **网络通信**:
- 点击按钮后发送网络消息到服务器
- 使用 `SL:SendLuaNetMsg` 发送消息
**注意**:确保服务器端有对应的 `U44_LEVEL` 和 `MAGIC_VALUE` 数据,否则获取到的值会是0。
← 返回问答库