--[[
GM 系统:
系统使用说明, \asset\design\GM.md 文本说明
]]
local skynet = require "skynet"
local codecache = require "skynet.codecache"
require "skynet.manager"
local logger = require "logger"
local stringify = require "stringify"
local cjson = require "cjson"
local common_fun = require "model.common_fun"
local module_fun = require "model.module_fun"
local asset = require "model.asset"
local util = require "util"
local usercenter
local function create_html_page(text)
return string.format(
"
%s ",
string.gsub(text, "[\n]", "
"))
end
local function response(header, content)
header = header or {}
if header['pokemon-version'] then
return { content }
else
return create_html_page(content)
end
end
local whitelist = {
}
local CMD = {}
function CMD.gm_check_award(args)
if type(args) ~= "table" then
return "失败"
end
local errno, list = common_fun.get_award(args[1])
if errno ~= 0 then
return errno
end
return stringify(list)
end
function CMD.gm_check_award_all(args)
if type(args) ~= "table" then
return false, "失败"
end
for k in pairs(asset.AwardConfig_proto) do
for i = 1, 10000 do
local errno, list = common_fun.get_award(k)
if errno ~= 0 then
return "配置异常:"..k
end
if not next(list or {}) then
return "奖励为空:"..k
end
errno = module_fun.reward_check(list)
if errno ~= 0 then
return string.format("配置异常:%d, errno:%d", k, errno)
end
end
end
return false, "成功"
end
function CMD.gm_draw(args)
local function draw(data, conf_list, num, special_list)
local award_list = {}
local id_list = {}
local times = num
data.all = data.all or 0
data.daily = data.daily or 0
data.list = data.list or {}
while(times > 0) do
local awardid = 0
local awardtimes = 0
data.all = data.all + 1
data.daily = data.daily + 1
-- 先随特殊库, 看下特殊库的必出是否达成
for _, conf in ipairs(special_list or {}) do
if conf.must > 0 then
local id = conf.ID
local list = data.list
if not data.list[id] then
list[id] = {
score = 0,
times = 0
}
end
local cur_score = data.all - list[id].score
if cur_score >= conf.must then
list[id].score = data.all
list[id].times = list[id].times + 1
awardid = conf.points
awardtimes = list[id].times
break
end
end
end
if awardid == 0 then
for _, conf in ipairs(conf_list) do
local id = conf.ID
local list = data.list
if not list[id] then
list[id] = {
score = 0,
times = 0
}
end
local cur_score = data.all - list[id].score
if awardid == 0 and conf.must > 0 and cur_score >= conf.must then
list[id].score = data.all
list[id].times = list[id].times + 1
awardid = conf.points
awardtimes = list[id].times
break
end
if awardid == 0 and cur_score >= conf.enter then
local score = (cur_score - conf.enter)
local all = conf.luckya*score^conf.luckyn+conf.luckyb*score+conf.chance
local randnum = util.rand(1, MAXRAND)
if all >= randnum then
list[id].score = data.all
list[id].times = list[id].times + 1
awardid = conf.points
awardtimes = list[id].times
break
end
end
end
end
if awardid == 0 then
local conf = conf_list[#conf_list]
local id = conf.ID
local list = data.list
list[id].score = 0
list[id].times = list[id].times + 1
awardid = conf_list[#conf_list].points
awardtimes = list[id].times
end
id_list[awardid] = (id_list[awardid] or 0) + 1
local ok, temp = common_fun.get_award(awardid, "CallawardConfig_proto", awardtimes)
if ok then
award_list = common_fun.merge2list(award_list, temp)
else
break
end
times = times - 1
end
if times ~= 0 then
return {}
end
return award_list, id_list
end
local num = tonumber(args[2] or 1000)
local draw_type = tonumber(args[1] or 1)
if num < 1 then
return "次数异常"
end
local conf_list = {}
local special_list = {}
local draw_name = ""
if draw_type == 1 then
draw_name = "高级英雄召唤"
local data_conf = asset.DataConfig_proto[20]
local special_conf = asset.HeroescallConfig_proto[data_conf.data2]
if special_conf then
table.insert(special_list, special_conf)
end
for _, v in pairs(asset.HeroescallConfig_proto) do
if v.type == 1 then
table.insert(conf_list, v)
end
end
elseif draw_type == 2 then
draw_name = "普通英雄召唤"
local data_conf = asset.DataConfig_proto[20]
local special_conf = asset.HeroescallConfig_proto[data_conf.data1]
if special_conf then
table.insert(special_list, special_conf)
end
for _, v in pairs(asset.HeroescallConfig_proto) do
if v.type == 2 then
table.insert(conf_list, v)
end
end
elseif draw_type == 3 then
draw_name = "装备锻造"
local data_conf = asset.DataConfig_proto[20]
local special_conf = asset.HeroescallConfig_proto[data_conf.data3]
if special_conf then
table.insert(special_list, special_conf)
end
special_conf = asset.HeroescallConfig_proto[data_conf.data4]
if special_conf then
table.insert(special_list, special_conf)
end
for _, v in pairs(asset.HeroescallConfig_proto) do
if v.type == 3 then
table.insert(conf_list, v)
end
end
else
return "类型异常"
end
table.sort(conf_list, function(a, b)
if a.priority > b.priority then
return true
end
return false
end)
local _, show = draw({}, conf_list, num, special_list)
local str = string.format("====%s====, %d次:\n\n\t", draw_name, num)
return str..stringify(show or {})
end
function CMD.show_avglist(args)
local itemavg = skynet.localname(".itemavg")
return skynet.call(itemavg, "lua", "show", args and args[1])
end
function CMD.show_statistics(args)
local statistics = skynet.localname(".statistics")
return skynet.call(statistics, "lua", "get_statistics_data", args and args[1])
end
--[[
example:
参数说明:
http://192.168.108.19:9002/gm_test?user=yytx&pwd=lee@YY-Games.520&context={"uid":"00-xx","func":"gm_item","args":[1,2,3,4]}
]]
local function gm_test(args, ipaddr, header)
logger.warn("处理来自主机 %s 的 gm_test 请求,:%s", ipaddr,args.context)
usercenter = usercenter or skynet.localname(".usercenter")
local context = cjson.decode(args.context)
if not context.uid then
local f = CMD[context.func]
local info = "成功"
if not f then
info = "没有该函数"
else
info = f(context.args)
end
if(context.func =="gm_draw") then
return create_html_page(info)
end
return {stats = 400, msg = info}
else
local errno, msg = skynet.call(usercenter, "lua", "gm_command",
context.uid, context.func, context.args
)
return {stats = errno, msg = msg}
end
end
return gm_test