gm_test.lua 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. --[[
  2. GM 系统:
  3. 系统使用说明, \asset\design\GM.md 文本说明
  4. ]]
  5. local skynet = require "skynet"
  6. local codecache = require "skynet.codecache"
  7. require "skynet.manager"
  8. local logger = require "logger"
  9. local stringify = require "stringify"
  10. local cjson = require "cjson"
  11. local common_fun = require "model.common_fun"
  12. local module_fun = require "model.module_fun"
  13. local asset = require "model.asset"
  14. local util = require "util"
  15. local usercenter
  16. local function create_html_page(text)
  17. return string.format(
  18. "<!DOCTYPE html><html><head><meta charset='UTF-8'></head> <body>%s</body> </html>",
  19. string.gsub(text, "[\n]", "<br/>"))
  20. end
  21. local function response(header, content)
  22. header = header or {}
  23. if header['pokemon-version'] then
  24. return { content }
  25. else
  26. return create_html_page(content)
  27. end
  28. end
  29. local whitelist = {
  30. }
  31. local CMD = {}
  32. function CMD.gm_check_award(args)
  33. if type(args) ~= "table" then
  34. return "失败"
  35. end
  36. local errno, list = common_fun.get_award(args[1])
  37. if errno ~= 0 then
  38. return errno
  39. end
  40. return stringify(list)
  41. end
  42. function CMD.gm_check_award_all(args)
  43. if type(args) ~= "table" then
  44. return false, "失败"
  45. end
  46. for k in pairs(asset.AwardConfig_proto) do
  47. for i = 1, 10000 do
  48. local errno, list = common_fun.get_award(k)
  49. if errno ~= 0 then
  50. return "配置异常:"..k
  51. end
  52. if not next(list or {}) then
  53. return "奖励为空:"..k
  54. end
  55. errno = module_fun.reward_check(list)
  56. if errno ~= 0 then
  57. return string.format("配置异常:%d, errno:%d", k, errno)
  58. end
  59. end
  60. end
  61. return false, "成功"
  62. end
  63. function CMD.gm_draw(args)
  64. local function draw(data, conf_list, num, special_list)
  65. local award_list = {}
  66. local id_list = {}
  67. local times = num
  68. data.all = data.all or 0
  69. data.daily = data.daily or 0
  70. data.list = data.list or {}
  71. while(times > 0) do
  72. local awardid = 0
  73. local awardtimes = 0
  74. data.all = data.all + 1
  75. data.daily = data.daily + 1
  76. -- 先随特殊库, 看下特殊库的必出是否达成
  77. for _, conf in ipairs(special_list or {}) do
  78. if conf.must > 0 then
  79. local id = conf.ID
  80. local list = data.list
  81. if not data.list[id] then
  82. list[id] = {
  83. score = 0,
  84. times = 0
  85. }
  86. end
  87. local cur_score = data.all - list[id].score
  88. if cur_score >= conf.must then
  89. list[id].score = data.all
  90. list[id].times = list[id].times + 1
  91. awardid = conf.points
  92. awardtimes = list[id].times
  93. break
  94. end
  95. end
  96. end
  97. if awardid == 0 then
  98. for _, conf in ipairs(conf_list) do
  99. local id = conf.ID
  100. local list = data.list
  101. if not list[id] then
  102. list[id] = {
  103. score = 0,
  104. times = 0
  105. }
  106. end
  107. local cur_score = data.all - list[id].score
  108. if awardid == 0 and conf.must > 0 and cur_score >= conf.must then
  109. list[id].score = data.all
  110. list[id].times = list[id].times + 1
  111. awardid = conf.points
  112. awardtimes = list[id].times
  113. break
  114. end
  115. if awardid == 0 and cur_score >= conf.enter then
  116. local score = (cur_score - conf.enter)
  117. local all = conf.luckya*score^conf.luckyn+conf.luckyb*score+conf.chance
  118. local randnum = util.rand(1, MAXRAND)
  119. if all >= randnum then
  120. list[id].score = data.all
  121. list[id].times = list[id].times + 1
  122. awardid = conf.points
  123. awardtimes = list[id].times
  124. break
  125. end
  126. end
  127. end
  128. end
  129. if awardid == 0 then
  130. local conf = conf_list[#conf_list]
  131. local id = conf.ID
  132. local list = data.list
  133. list[id].score = 0
  134. list[id].times = list[id].times + 1
  135. awardid = conf_list[#conf_list].points
  136. awardtimes = list[id].times
  137. end
  138. id_list[awardid] = (id_list[awardid] or 0) + 1
  139. local ok, temp = common_fun.get_award(awardid, "CallawardConfig_proto", awardtimes)
  140. if ok then
  141. award_list = common_fun.merge2list(award_list, temp)
  142. else
  143. break
  144. end
  145. times = times - 1
  146. end
  147. if times ~= 0 then
  148. return {}
  149. end
  150. return award_list, id_list
  151. end
  152. local num = tonumber(args[2] or 1000)
  153. local draw_type = tonumber(args[1] or 1)
  154. if num < 1 then
  155. return "次数异常"
  156. end
  157. local conf_list = {}
  158. local special_list = {}
  159. local draw_name = ""
  160. if draw_type == 1 then
  161. draw_name = "高级英雄召唤"
  162. local data_conf = asset.DataConfig_proto[20]
  163. local special_conf = asset.HeroescallConfig_proto[data_conf.data2]
  164. if special_conf then
  165. table.insert(special_list, special_conf)
  166. end
  167. for _, v in pairs(asset.HeroescallConfig_proto) do
  168. if v.type == 1 then
  169. table.insert(conf_list, v)
  170. end
  171. end
  172. elseif draw_type == 2 then
  173. draw_name = "普通英雄召唤"
  174. local data_conf = asset.DataConfig_proto[20]
  175. local special_conf = asset.HeroescallConfig_proto[data_conf.data1]
  176. if special_conf then
  177. table.insert(special_list, special_conf)
  178. end
  179. for _, v in pairs(asset.HeroescallConfig_proto) do
  180. if v.type == 2 then
  181. table.insert(conf_list, v)
  182. end
  183. end
  184. elseif draw_type == 3 then
  185. draw_name = "装备锻造"
  186. local data_conf = asset.DataConfig_proto[20]
  187. local special_conf = asset.HeroescallConfig_proto[data_conf.data3]
  188. if special_conf then
  189. table.insert(special_list, special_conf)
  190. end
  191. special_conf = asset.HeroescallConfig_proto[data_conf.data4]
  192. if special_conf then
  193. table.insert(special_list, special_conf)
  194. end
  195. for _, v in pairs(asset.HeroescallConfig_proto) do
  196. if v.type == 3 then
  197. table.insert(conf_list, v)
  198. end
  199. end
  200. else
  201. return "类型异常"
  202. end
  203. table.sort(conf_list, function(a, b)
  204. if a.priority > b.priority then
  205. return true
  206. end
  207. return false
  208. end)
  209. local _, show = draw({}, conf_list, num, special_list)
  210. local str = string.format("====%s====, %d次:\n\n\t", draw_name, num)
  211. return str..stringify(show or {})
  212. end
  213. function CMD.show_avglist(args)
  214. local itemavg = skynet.localname(".itemavg")
  215. return skynet.call(itemavg, "lua", "show", args and args[1])
  216. end
  217. function CMD.show_statistics(args)
  218. local statistics = skynet.localname(".statistics")
  219. return skynet.call(statistics, "lua", "get_statistics_data", args and args[1])
  220. end
  221. --[[
  222. example:
  223. 参数说明:
  224. 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]}
  225. ]]
  226. local function gm_test(args, ipaddr, header)
  227. logger.warn("处理来自主机 %s 的 gm_test 请求,:%s", ipaddr,args.context)
  228. usercenter = usercenter or skynet.localname(".usercenter")
  229. local context = cjson.decode(args.context)
  230. if not context.uid then
  231. local f = CMD[context.func]
  232. local info = "成功"
  233. if not f then
  234. info = "没有该函数"
  235. else
  236. info = f(context.args)
  237. end
  238. if(context.func =="gm_draw") then
  239. return create_html_page(info)
  240. end
  241. return {stats = 400, msg = info}
  242. else
  243. local errno, msg = skynet.call(usercenter, "lua", "gm_command",
  244. context.uid, context.func, context.args
  245. )
  246. return {stats = errno, msg = msg}
  247. end
  248. end
  249. return gm_test