{{#invoke:AskSubtotal|get
|askcondition=[[职业::术师]][[:+]]
|特性|攻击造成法术伤害$,^攻击造成群体法术伤害,超远距离,浮游单元,跳跃,通常时不攻击|
replacenumber=no
|sortclass=no
|row=6
|comparemode=loose
|replaceitem=<.->|
matchpattern=yes
|matchpattern_tag=|
displaytarget=干员
|displayclass=类特性
|hideempty=no
|}}
p={}
function spilt_ask(str,sep2)
--name=""
--prop={}
hasprop=string.find(str, "(.*)")
if(hasprop)then
name=string.gsub(str,"(.*)","")
prop_str=string.sub(str, string.find(str, "(.*)"))
prop_str=string.sub(prop_str, 4,-4)
prop=mw.text.split(prop_str, sep2, true)
else
name=str
prop=nil
end
--print("aa"..name.."bb")
--print("aa"..prop_str.."bb")
return name,prop
end
function ask_fileNumber(frame,askitem,askcondition)
local sep1='@sep1@'
local sep2='@sep2@'
local sep3='@sep2@'
local str=frame:callParserFunction{
name = '#ask:'..askcondition, args={
'?'..askitem,
format='plainlist',
propsep=sep2,
valuesep=sep3,
sep=sep1,
headers='hide',
link='none',
limit='1000',
order='asc'
}}
local str_table = mw.text.split(str, sep1, true)
local name_table={}
local prop_table={}
for i = 1, #str_table do
name_table[i],temp=spilt_ask(str_table[i],sep2)
if(temp)then
prop_table[i]=temp[1]
else
prop_table[i]=""
end
end
return name_table ,prop_table
end
function stringcanceltrans(str)
local tranlist={'%','(',')','.','+','-','*','?','[','^','$'}
for i = 1, #tranlist do
str=string.gsub(str,"%"..tranlist[i],"%%%"..tranlist[i])
end
return str
end
function findclass(class_table,tag,comparemode,matchpattern,matchpattern_tag)
local rtn={}
for i = 1, #class_table do
local compareresult
if(comparemode =="strict")then
compareresult=(class_table[i]==tag)
else
local tempstra=class_table[i]
local tempstrb=tag
local temptaga
local temptagb
if(matchpattern~="no" and string.find(tempstra,matchpattern_tag))then
temptaga=string.gsub(tempstra,matchpattern_tag,"")
else
temptaga=stringcanceltrans(tempstra)
end
if(matchpattern~="no" and string.find(tempstrb,matchpattern_tag))then
temptagb=string.gsub(tempstrb,matchpattern_tag,"")
else
temptagb=stringcanceltrans(tempstrb)
end
compareresult=(string.find(tempstrb,temptaga) or string.find(tempstra,temptagb))
end
if(compareresult)then
--rtn=i
--break
table.insert(rtn,i)
end
end
return rtn
end
local function intableSort2( a, b )
if(#a[2] < #b[2])then
return true
end
if(#a[2] > #b[2])then
return false
end
if(a[1] < b[1])then
return true
end
return false
end
local function intableSort( a, b )
local str_a=a[2]
local str_b=b[2]
local tag_a=string.gsub(str_a,"%d","")
local tag_b=string.gsub(str_b,"%d","")
if(tag_a == tag_b)then
local num_a_str=string.gsub(str_a,"%D","")
local num_b_str=string.gsub(str_b,"%D","")
local num_a=tonumber(num_a_str)
local num_b=tonumber(num_b_str)
if(num_a and num_b)then
if(num_a < num_b)then
return true
else
if(num_a > num_b)then
return false
end
end
end
end
if(str_a < str_b)then
return true
end
if(str_a > str_b)then
return false
end
if(a[1] < b[1])then
return true
end
return false
end
function sorttablebynum(name_table,fileNumber_table)
local temptable={}
for i = 1, #name_table do
temptable[i]={}
temptable[i][1]=name_table[i]
temptable[i][2]=fileNumber_table[i]
--table.insert(temptable[i],name_table[i])
--table.insert(temptable[i],fileNumber_table[i])
end
table.sort(temptable,intableSort)
for i = 1, #name_table do
name_table[i]=temptable[i][1]
fileNumber_table[i]=temptable[i][2]
end
return name_table,fileNumber_table
end
function makeclasstable(i_class,spilt_class_table,name_table,fileNumber_table,askitem)
local tablehead=
[[{|border="1" style="border-collapse:collapse;border: darkgray;margin: auto;"
|-style="background-color:#eaebee;"
!style="width:80px;"|]]..displaytarget..[[!!style="width:60px;"|]]..askitem.."\n"
local tableend="|}\n"
local rtn=""
for j = 1, #spilt_class_table[i_class] do
local i_num=spilt_class_table[i_class][j]
rtn=rtn.."|-\n|[["..name_table[i_num].."]]||"..fileNumber_table[i_num].."\n"
end
rtn=tablehead..rtn..tableend
if(#spilt_class_table[i_class]==0)then
rtn=""
end
return rtn
end
function makeplainoutput(class_table,spilt_class_table,name_table,fileNumber_table)
local rtn=""
for i = 1, #class_table do
rtn=rtn..class_table[i]..": \n\n"
for j = 1, #spilt_class_table[i] do
i_num=spilt_class_table[i][j]
rtn=rtn.."("..name_table[i_num]..","..fileNumber_table[i_num]..")"
end
rtn=rtn.."\n\n----"
end
return rtn
end
function p.get(frame)
local args = (frame == mw.getCurrentFrame() and frame.args) or frame
--local argv = #args
local argv = 0
while(args[argv+1])do
argv=argv+1
end
local askitem="情报编号"
local class_table_str=""
local askcondition =""
local replacenumber ="yes"
local comparemode ="strict"
local N_row=8
local sortclass="no"
local matchpattern="no"
local replaceitem_str=""
local matchpattern_tag="模式匹配"
local hideempty="no"
displaytarget="对象"
displayclass="类"
local class_table={}
local replaceitem_table={}
if(args[1])then
askitem=args[1]
end
if(args[2])then
class_table_str=args[2]
class_table=mw.text.split(class_table_str, ",", true)
end
if(args["askcondition"])then
askcondition=args["askcondition"]
else
askcondition='[['..askitem..'::+]][[:+]]'
end
if(args["replacenumber"])then
replacenumber=args["replacenumber"]
end
if(args["comparemode"])then
comparemode=args["comparemode"]
end
if(args["row"])then
N_row=tonumber(args["row"])
end
if(args["sortclass"])then
sortclass=args["sortclass"]
end
if(args["matchpattern"])then
matchpattern=args["matchpattern"]
end
if(args["matchpattern_tag"])then
matchpattern_tag=args["matchpattern_tag"]
end
if(args["replaceitem"])then
replaceitem_str=args["replaceitem"]
replaceitem_table=mw.text.split(replaceitem_str, ",", true)
end
if(args["hideempty"])then
hideempty=args["hideempty"]
end
if(args["displaytarget"])then
displaytarget=args["displaytarget"]
end
if(args["displayclass"])then
displayclass=args["displayclass"]
end
---------------------------------------------------------------------------------------------
name_table ,fileNumber_table=ask_fileNumber(frame,askitem,askcondition)
name_table ,fileNumber_table=sorttablebynum(name_table,fileNumber_table)
local tag_table={}
for i = 1, #fileNumber_table do
if(replacenumber=="yes")then
tag_table[i]=string.gsub(fileNumber_table[i],"%d","")
else
tag_table[i]=fileNumber_table[i]
end
for j = 1, #replaceitem_table do
tag_table[i]=string.gsub(tag_table[i],replaceitem_table[j],"")
end
end
local spilt_class_table={}
for i = 1, #class_table do
spilt_class_table[i]={}
end
for i = 1, #name_table do
local i_class_table=findclass(class_table,tag_table[i],comparemode,matchpattern,matchpattern_tag)
if(#i_class_table==0)then
table.insert(class_table,tag_table[i])
table.insert(spilt_class_table,{})
i_class=#class_table
table.insert(spilt_class_table[i_class], i)
else
for j = 1, #i_class_table do
i_class=i_class_table[j]
table.insert(spilt_class_table[i_class], i)
end
end
end
if(hideempty~="no")then
local temp=#spilt_class_table
for i = temp, 1 ,-1 do
if #spilt_class_table[i]==0 then
table.remove (spilt_class_table , i)
table.remove (class_table , i)
end
end
end
local classsorttable={}
if(sortclass~="no")then
for i = 1, #spilt_class_table do
classsorttable[i]={}
classsorttable[i][1]=i
classsorttable[i][2]=spilt_class_table[i]
end
table.sort(classsorttable,intableSort2)
end
local class_row_table={{}}
local i_row=1
local n_row=1
local n_valid_class=0
for i = 1, #class_table do
if(n_row==N_row+1)then
n_row=1
i_row=i_row+1
table.insert(class_row_table, {})
end
local i_choose=i
if(sortclass~="no")then
i_choose=classsorttable[i][1]
end
class_row_table[i_row][n_row]=i_choose
n_row=n_row+1
if(#spilt_class_table[i]>0)then
n_valid_class=n_valid_class+1
end
end
local tablehead=[[{|class="wikitable" style="white-space:normal; text-align:center;"]].."\n"
tablehead=tablehead..'|-\n!colspan="'..N_row..'"|'..askitem..'('..#name_table..displaytarget..'-'..n_valid_class..displayclass..')\n'
local tableend="|}\n"
local rtn2=""
local setwidthstr=""
if(#class_table>=N_row)then
setwidthstr='style="width:'..string.format("%.2f",(100/N_row))..'%;"|'
end
for i = 1, #class_row_table do
local str_title=""
local str_contant=[[|-style="vertical-align:top;"]].."\n"
for j = 1, #class_row_table[i] do
local i_class=class_row_table[i][j]
if(j==1)then
str_title=str_title.."|-\n!"..setwidthstr..class_table[i_class]
else
str_title=str_title.."!!"..setwidthstr..class_table[i_class]
end
if(#spilt_class_table[i_class]>0)then
str_title=str_title.."("..#spilt_class_table[i_class]..")"
end
str_contant=str_contant.."||\n"..makeclasstable(i_class,spilt_class_table,name_table,fileNumber_table,askitem)
end
str_title=str_title.."\n"
rtn2=rtn2..str_title..str_contant
end
rtn2=tablehead..rtn2..tableend
--local rtn=makeplainoutput(class_table,spilt_class_table,name_table,fileNumber_table)
--return rtn.."\n\n\n\n"..rtn2
return rtn2
end
return p