123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- --[[
- 客户端数据保存
- ]]
- local skynet = require "skynet"
- local schema = require "model.schema"
- local logger = require "logger"
- local cjson = require "cjson"
- local asset = require "model.asset"
- local stringify = require "stringify"
- local reward = require "model.reward"
- local currency
- local adventure
- local relic
- local trace = logger.trace
- local CMD = {}
- local REQUEST = {}
- local gm = {}
- local cjson_decode = cjson.decode -- 解码
- local cjson_encode = cjson.encode -- 编码
- local _M = schema.new('gm', {
- })
- ---------------------------------------------------------------------
- function gm.list_request_interests() return REQUEST end
- function gm.list_command_interests() return CMD end
- --
- function gm.parse(character)
- _M.load(character)
- end
- function gm.launch(character)
- currency = currency or require "model.currency"
- adventure = adventure or require "model.adventure"
- end
- function gm.monitor(character)
- -- TODO: 侦听事件
- --character.monitor("", function(_, resettime)
- --end)
- end
- -------------------------------- CMD ---------------------------------
- -- TODO: 道具处理
- function CMD.gm_item(character, args)
- end
- -- TODO: 调用制定功能模块
- --[[
- args[1] = model路径(player 中填写的路径)
- args[2] = 功能名
- args[...] = 参数
- ]]
- function CMD.gm_model(character, args)
- logger.trace("args = %s", stringify(args))
- local m = require(args[1])
- if m and m[args[2]] then
- local ret = {m[args[2]](character, table.unpack(args,3))}
- return {0, cjson_encode(ret)}
- else
- return {1,"错误的路径名/功能名"}
- end
- end
- function CMD.gm_award(character, args)
- if type(args) ~= "table" then
- return 2, "失败"
- end
- local detail = {}
- for i = 1, #args, 2 do
- local id = args[i]
- local num = args[i+1]
- if id and num then
- table.insert(detail, {id = id, num = num})
- end
- end
- -- 发奖励
- local desc = {
- module="gm_test",
- brief="gm_award",
- context= "gm奖励:",
- mailgen={subject=2, body=""},
- notify={
- flags="gm_award"
- },
- detail=detail
- }
- reward(character, desc)
- return 0, "成功"
- end
- function CMD.gm_set_money(character, args)
- if type(args) ~= "table" then
- return "失败"
- end
- for i = 1, #args, 2 do
- local id = args[i]
- local num = args[i+1]
- if id and num then
- currency.set_money(character, id, num)
- end
- end
- return "成功"
- end
- function CMD.set_simple_adventure(character, args)
- if type(args) ~= "table" then
- return "失败"
- end
- local id = args[1]
- if not id or id <= 0 then
- return "失败"
- end
- adventure.gm_set_simple_adventure(character, id)
- return "成功"
- end
- function CMD.set_elite_adventure(character, args)
- if type(args) ~= "table" then
- return "失败"
- end
- local id = args[1]
- if not id or id <= 0 then
- return "失败"
- end
- local ok = adventure.gm_set_elite_adventure(character, id)
- if ok then
- return "成功"
- else
- return "失败"
- end
- end
- function CMD.gm_add_cost(character, args)
- if type(args) ~= "table" then
- return "失败"
- end
- local num = args[1]
- if not num or num <= 0 then
- return "参数异常"
- end
- relic.gm_add_cost(character, num)
- end
- return gm
|