模块:Xb2QueryHelper
来自乐园数据管理室
此模块的文档可以在模块:Xb2QueryHelper/doc创建
local p = {}
p.language = "cn"
local cache = {}
function p.query(sql)
if cache[sql] then
return cache[sql]
end
local result = mw.xbdb.query(sql, p.language)
cache[sql] = result
return result
end
function p.queryOne(sql)
local result = p.query(sql)
if #result == 1 then
result = result[1]
elseif #result == 0 then
error("SQL返回结果为空\n" .. sql)
else
error("结果行数大于1,请检查WHERE条件\n" .. sql)
end
return result
end
function p.getEnhance(id)
if type(id) ~= "number" then
error("id must be number")
end
local result =
p.queryOne(
[[
SELECT
"BTL_Enhance"."Param1",
"BTL_Enhance"."Param2",
"BTL_EnhanceEff"."Param",
"btl_enhance_cap"."name" AS "Caption",
"btl_buff_ms"."name" AS "BuffName"
FROM
"BTL_Enhance"
INNER JOIN "BTL_EnhanceEff" ON "BTL_Enhance"."EnhanceEffect" = "BTL_EnhanceEff".row_id
LEFT JOIN "btl_enhance_cap" ON "BTL_Enhance"."Caption" = "btl_enhance_cap".row_id
LEFT JOIN "btl_buff_ms" ON "BTL_EnhanceEff"."Name" = "btl_buff_ms".row_id
WHERE
"BTL_Enhance".row_id = ]] ..
id
)
local CaptionText =
p.replaceCaptionParam(
result.Caption or "",
{
Param = result.Param,
Param1 = result.Param1,
Param2 = result.Param2
}
)
result.RenderedCaption = CaptionText
return result
end
function p.replaceCaptionParam(caption, params)
local str = caption
local paramStrArray = {}
local paramStr = ""
local inStr = false
for i = 1, mw.ustring.len(str) do
local c = mw.ustring.sub(str, i, i)
if c == "]" then
inStr = false
if not mw.ustring.find(paramStr, "ML:Enhance") then
error("找不到 ML:Enhance:" .. paramStr)
end
if mw.ustring.find(paramStr, "Param1") then
paramStrArray.Param1 = paramStr
elseif mw.ustring.find(paramStr, "Param2") then
paramStrArray.Param2 = paramStr
else
paramStrArray.Param = paramStr
end
end
if inStr then
paramStr = paramStr .. c
end
if c == "[" then
inStr = true
paramStr = ""
end
end
for k, v in pairs(paramStrArray) do
str = mw.ustring.gsub(str, "%[" .. v .. "%]", params[k])
end
return str
end
function p.getBuff(id)
return p.queryOne(
[[
SELECT
"btl_buff_ms"."name" AS "Name",
"btl_buff_cap"."name" AS "Caption",
"BaseNum",
"BaseTime",
"BaseRecast",
"BaseProb",
"Interval"
FROM
"BTL_Buff"
LEFT JOIN "btl_buff_cap" ON "BTL_Buff"."Caption" = "btl_buff_cap".row_id
LEFT JOIN "btl_buff_ms" ON "BTL_Buff"."Name" = "btl_buff_ms".row_id
WHERE
"BTL_Buff".row_id = ]] ..
id
)
end
function p.getArtsDr(id)
return p.queryOne(
[[
SELECT
btl_arts_dr_ms."name" AS "NameText",
btl_arts_dr_cap."name" AS "CaptionText",
"BTL_Arts_Dr".*
FROM
"BTL_Arts_Dr"
LEFT JOIN btl_arts_dr_ms ON "BTL_Arts_Dr"."Name" = btl_arts_dr_ms.row_id
LEFT JOIN btl_arts_dr_cap ON "BTL_Arts_Dr"."Caption" = btl_arts_dr_cap.row_id
WHERE
"BTL_Arts_Dr".row_id = ]] ..
id
)
end
function p.getArtsDrListByDriver(id)
return p.query(
[[
SELECT
btl_arts_dr_ms."name" AS "NameText",
btl_arts_dr_cap."name" AS "CaptionText",
condcapms."name" AS "CondCapText",
talentcapms."name" AS "TalentCapText",
"BTL_Arts_Dr".*
FROM
"BTL_Arts_Dr"
LEFT JOIN btl_arts_dr_ms ON "BTL_Arts_Dr"."Name" = btl_arts_dr_ms.row_id
LEFT JOIN btl_arts_dr_cap ON "BTL_Arts_Dr"."Caption" = btl_arts_dr_cap.row_id
LEFT JOIN btl_arts_dr_cap AS condcapms ON "BTL_Arts_Dr"."CondCap" = condcapms.row_id
LEFT JOIN btl_arts_dr_cap AS talentcapms ON "BTL_Arts_Dr"."TalentCap" = talentcapms.row_id
WHERE
"BTL_Arts_Dr"."Driver" = ]] ..
id
)
end
function p.getDr(id)
local result =
p.queryOne(
[[
SELECT
chr_dr_ms."name" AS "NameText",
category1."name" AS "FavoriteCategory1Text",
itm1ms."name" AS "FavoriteItem1Text",
category2."name" AS "FavoriteCategory2Text",
itm2ms."name" AS "FavoriteItem2Text",
"CHR_Dr".*
FROM
"CHR_Dr"
LEFT JOIN chr_dr_ms ON "CHR_Dr"."Name" = chr_dr_ms.row_id
LEFT JOIN menu_favorite_category AS category1 ON "CHR_Dr"."FavoriteCategory1" - 11 = category1.row_id
LEFT JOIN menu_favorite_category AS category2 ON "CHR_Dr"."FavoriteCategory2" - 11 = category2.row_id
LEFT JOIN "ITM_FavoriteList" AS item1 ON "CHR_Dr"."FavoriteItem1" = item1.row_id
LEFT JOIN itm_favorite AS itm1ms ON item1."Name" = itm1ms.row_id
LEFT JOIN "ITM_FavoriteList" AS item2 ON "CHR_Dr"."FavoriteItem2" = item2.row_id
LEFT JOIN itm_favorite AS itm2ms ON item2."Name" = itm2ms.row_id
WHERE
"CHR_Dr".row_id = ]] ..
id
)
local WpnType = result.WpnType
WpnType = mw.ustring.sub(WpnType, 2)
WpnType = mw.ustring.sub(WpnType, 1, -2)
local WpnTypeArray = {}
for str in mw.ustring.gmatch(WpnType, "([^,]+)") do
table.insert(WpnTypeArray, str)
end
local condition = {}
for i, v in ipairs(WpnTypeArray) do
if tonumber(v) > 0 then
table.insert(condition, i)
end
end
condition = table.concat(condition, ", ")
result.WpnType =
p.query(
[[
SELECT
"ITM_PcWpnType".row_id,
itm_pcwpntype_ms."name" AS "Name",
menu_role_name_ms."name" AS "Role",
"ITM_PcWpnType"."JustRange",
"ITM_PcWpnType"."JustRange2"
FROM
"ITM_PcWpnType"
LEFT JOIN itm_pcwpntype_ms ON itm_pcwpntype_ms.row_id = "ITM_PcWpnType"."Name"
LEFT JOIN menu_role_name_ms ON menu_role_name_ms.row_id = "ITM_PcWpnType"."Role"
WHERE
"ITM_PcWpnType".row_id IN (]] ..
condition .. [[)
]]
)
return result
end
function p.getSkillDrList(id)
local driverIds = {
[1] = true,
[2] = true,
[3] = true,
[4] = true,
[5] = true,
[6] = true,
[17] = true,
[18] = true,
[19] = true
}
if not driverIds[tonumber(id)] then
return nil
end
if tonumber(id) < 10 then
id = "0" .. tostring(tonumber(id))
end
local result =
p.query(
[[
SELECT
btl_skill_dr_name."name" AS "NameText",
"BTL_Skill_Dr_Table]] ..
id ..
[[".*,
"BTL_Skill_Dr"."Enhance"
FROM
"BTL_Skill_Dr_Table]] ..
id ..
[["
LEFT JOIN "BTL_Skill_Dr" ON "BTL_Skill_Dr_Table]] ..
id ..
[["."SkillID" = "BTL_Skill_Dr".row_id
LEFT JOIN btl_skill_dr_name ON btl_skill_dr_name.row_id = "BTL_Skill_Dr"."Name"
ORDER BY
"Round",
"RowNum",
"ColumnNum"
]]
)
for _, row in ipairs(result) do
row.Enhance = p.getEnhance(tonumber(row.Enhance))
end
return result
end
function p.t()
local ret = p.getBuff(3).Name
mw.logObject(ret)
return ret
end
return p