gm.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. --[[
  2. 客户端数据保存
  3. ]]
  4. local skynet = require "skynet"
  5. local schema = require "model.schema"
  6. local logger = require "logger"
  7. local cjson = require "cjson"
  8. local asset = require "model.asset"
  9. local stringify = require "stringify"
  10. local reward = require "model.reward"
  11. local currency
  12. local adventure
  13. local relic
  14. local trace = logger.trace
  15. local CMD = {}
  16. local REQUEST = {}
  17. local gm = {}
  18. local cjson_decode = cjson.decode -- 解码
  19. local cjson_encode = cjson.encode -- 编码
  20. local _M = schema.new('gm', {
  21. })
  22. ---------------------------------------------------------------------
  23. function gm.list_request_interests() return REQUEST end
  24. function gm.list_command_interests() return CMD end
  25. --
  26. function gm.parse(character)
  27. _M.load(character)
  28. end
  29. function gm.launch(character)
  30. currency = currency or require "model.currency"
  31. adventure = adventure or require "model.adventure"
  32. end
  33. function gm.monitor(character)
  34. -- TODO: 侦听事件
  35. --character.monitor("", function(_, resettime)
  36. --end)
  37. end
  38. -------------------------------- CMD ---------------------------------
  39. -- TODO: 道具处理
  40. function CMD.gm_item(character, args)
  41. end
  42. -- TODO: 调用制定功能模块
  43. --[[
  44. args[1] = model路径(player 中填写的路径)
  45. args[2] = 功能名
  46. args[...] = 参数
  47. ]]
  48. function CMD.gm_model(character, args)
  49. logger.trace("args = %s", stringify(args))
  50. local m = require(args[1])
  51. if m and m[args[2]] then
  52. local ret = {m[args[2]](character, table.unpack(args,3))}
  53. return {0, cjson_encode(ret)}
  54. else
  55. return {1,"错误的路径名/功能名"}
  56. end
  57. end
  58. function CMD.gm_award(character, args)
  59. if type(args) ~= "table" then
  60. return 2, "失败"
  61. end
  62. local detail = {}
  63. for i = 1, #args, 2 do
  64. local id = args[i]
  65. local num = args[i+1]
  66. if id and num then
  67. table.insert(detail, {id = id, num = num})
  68. end
  69. end
  70. -- 发奖励
  71. local desc = {
  72. module="gm_test",
  73. brief="gm_award",
  74. context= "gm奖励:",
  75. mailgen={subject=2, body=""},
  76. notify={
  77. flags="gm_award"
  78. },
  79. detail=detail
  80. }
  81. reward(character, desc)
  82. return 0, "成功"
  83. end
  84. function CMD.gm_set_money(character, args)
  85. if type(args) ~= "table" then
  86. return "失败"
  87. end
  88. for i = 1, #args, 2 do
  89. local id = args[i]
  90. local num = args[i+1]
  91. if id and num then
  92. currency.set_money(character, id, num)
  93. end
  94. end
  95. return "成功"
  96. end
  97. function CMD.set_simple_adventure(character, args)
  98. if type(args) ~= "table" then
  99. return "失败"
  100. end
  101. local id = args[1]
  102. if not id or id <= 0 then
  103. return "失败"
  104. end
  105. adventure.gm_set_simple_adventure(character, id)
  106. return "成功"
  107. end
  108. function CMD.set_elite_adventure(character, args)
  109. if type(args) ~= "table" then
  110. return "失败"
  111. end
  112. local id = args[1]
  113. if not id or id <= 0 then
  114. return "失败"
  115. end
  116. local ok = adventure.gm_set_elite_adventure(character, id)
  117. if ok then
  118. return "成功"
  119. else
  120. return "失败"
  121. end
  122. end
  123. function CMD.gm_add_cost(character, args)
  124. if type(args) ~= "table" then
  125. return "失败"
  126. end
  127. local num = args[1]
  128. if not num or num <= 0 then
  129. return "参数异常"
  130. end
  131. relic.gm_add_cost(character, num)
  132. end
  133. return gm