123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- local schema = require "model.schema"
- local logger = require "logger"
- local stringify = require "stringify"
- local asset = require "model.asset"
- local payment = require "model.payment"
- local module_name = "talent"
- local _M = schema.new(module_name, {
- list = {
- -- [type] = {type = 1, id = id}
- }
- })
- local REQUEST = {}
- local CMD = {}
- local MODULE = {}
- local THIS = {}
- local function func_ret(fname, character, args)
- local f = THIS[fname]
- if not f then
- logger.error("func_ret not fname:%s !!!", fname)
- return {errno = STD_ERR.COMMON_SYS_ERR}
- end
- local errno, ret = f(character, args)
- if errno ~= 0 then
- return {errno = errno}
- end
- ret = ret or {}
- ret.errno = 0
- return ret
- end
- function MODULE.list_request_interests() return REQUEST end
- function MODULE.list_command_interests() return CMD end
- -- TODO: 解析/升级模块数据 在这里把数据初始化好
- function MODULE.parse(character)
- local d = _M.load(character)
- if not d.list then
- d.list = {}
- end
- end
- -- TODO: 侦听事件
- function MODULE.monitor(character)
- end
- -- TODO: 类似泰利的 prepare 接口
- function MODULE.launch(character)
- local d = _M.assert_get(character)
- local u = _M.assert_runtime(character)
- end
- -- TODO: 与客户端同步数据
- function MODULE.ready(character)
- local d = _M.assert_get(character)
- logger.test("%s:ready, %s", module_name, stringify(d or {}))
- end
- -- TODO: 玩家下线时的处理
- function MODULE.saybye(character)
- end
- function MODULE.talent_get_data(character)
- local d = _M.assert_get(character)
- local ret = {}
- for _, v in pairs(d.list or {}) do
- if v.type == 1 then
- ret.id1 = v.id
- elseif v.type == 2 then
- ret.id2 = v.id
- end
- end
- return ret
- end
- function THIS.talent_get_data(character, args)
- local ret = MODULE.talent_get_data(character)
- return 0, ret
- end
- function THIS.talent_activate(character, args)
- local id = args.id
- if not id then
- return STD_ERR.PLYAER_PARM_LIMIT -- 参数异常
- end
- local d = _M.assert_get(character)
- local conf_list = assert(asset.TalentConfig_proto, "TalentConfig_proto")
- local conf = conf_list[id]
- if not conf then
- return STD_ERR.PLYAER_PARM_LIMIT -- 参数异常
- end
- if character.level < conf.lv then
- return STD_ERR.PLYAER_PARM_LIMIT -- 参数异常
- end
- local data = d.list[conf.talentType] or {type = conf.talentType, id = 0}
- if data.id ~= conf.condition then
- return STD_ERR.PLYAER_PARM_LIMIT -- 参数异常
- end
- local pay_list = {}
- for i = 1, #conf.goods, 2 do
- local item_id = conf.goods[i]
- local item_num = conf.goods[i+1]
- if item_id and item_num and item_id > 0 and item_num > 0 then
- table.insert(pay_list, {id = item_id, num = item_num})
- end
- end
- if next(pay_list) then
- local receipt = {
- module="talent",
- brief="天赋激活",
- context="天赋激活:"..id,
- notify={
- flags="talent_activate"
- },
- detail=pay_list
- }
- local errno = payment(character, receipt)
- if errno ~= 0 then
- return errno
- end
- end
- data.id = id
- d.list[conf.talentType] = data
- _M.persist(character)
- character.dispatch("telent_activate")
- local ctx = _M.assert_runtime(character)
- ctx.special_list = nil
- return 0, {id = args.id}
- end
- -- 天赋数据
- function REQUEST.talent_get_data(character, args)
- return func_ret("talent_get_data", character, args)
- end
- function REQUEST.talent_activate(character, args)
- return func_ret("talent_activate", character, args)
- end
- function MODULE.get_special_attr(character)
- local ctx = _M.assert_runtime(character)
- if ctx.special_list then
- return ctx.special_list
- end
- local list = {}
- local d = _M.assert_get(character) or {}
- for _, talent_conf in pairs(asset.TalentConfig_proto)do
- local data = d.list[talent_conf.talentType]
- if data and data.id >= talent_conf.ID then
- local conf = asset.EntryConfig_proto[talent_conf.entryID]
- if conf and conf.type and conf.type >= 100 then
- if conf.rateArr[1] and conf.rateArr[1] > 0 then
- list[conf.type] = (list[conf.type] or 0) + conf.rateArr[1]
- end
- end
- end
- end
- ctx.special_list = list
- return ctx.special_list
- end
- function MODULE.get_talent_data(character)
- local d = _M.assert_get(character)
- return d.list
- end
- return MODULE
|