Illustrate = {} SYS_ILLUSTRATEINFO = "T$illustrate_info" SYS_ILLUSTRATEHISTORY = "G$illustrate_history" SYS_ILLUSTRATEHISTORYSELF = "T$illustrate_history_self" SYS_ILLUSTRATEATTRS = "T$illustrate_attrs" local HistoryLen = 50 -- function Illustrate.onLoginEnd(actor) -- end -- 1:获取info信息. 2:获得全服召唤记录 -- 10:召唤 function Illustrate.onHandlereQuest(actor, msgid, sMsg) local type = sMsg.type if type == 1 then Illustrate.getMainInfo(actor, msgid) elseif type == 10 then Illustrate.onSummon(actor, msgid) elseif type == 20 then Illustrate.onRefresh(actor, msgid) elseif type == 30 then Illustrate.onHistorySelf(actor, msgid) elseif type == 31 then Illustrate.onHistory(actor, msgid) elseif type == 40 then Illustrate.onAcviveItem(actor, msgid, sMsg) elseif type == 50 then Illustrate.onAcviveGroup(actor, msgid, sMsg) end end function Illustrate.getInfo(actor) local info = APIGetTable(actor, SYS_ILLUSTRATEINFO) or {} local isInited = true -- 召唤次数 if info.summonNum == nil then info.summonNum = 0 isInited = false end -- 刷新次数 if info.refreshNum == nil then info.refreshNum = 0 isInited = false end -- 召唤的物品 if info.items == nil or table.count(info.items) <= 0 then info.items = Illustrate.getItems() isInited = false end if info.activeitems == nil then info.activeitems = {} end if info.activegroups == nil then -- {[main][sub]=endtime} info.activegroups = {} end if isInited ~= true then Illustrate.setInfo(actor, info) end return info end function Illustrate.setInfo(actor, info) APISetTable(actor, SYS_ILLUSTRATEINFO, info) end function Illustrate.getHistorySelf(actor) local info = APIGetTable(actor, SYS_ILLUSTRATEHISTORYSELF) or {} return info end function Illustrate.setHistorySelf(actor, history) APISetTable(actor, SYS_ILLUSTRATEHISTORYSELF, history) end function Illustrate.getHistory() local info = getsysvar(SYS_ILLUSTRATEHISTORY) or {} return info end function Illustrate.setHistory(history) setsysvar(SYS_ILLUSTRATEHISTORY, history) end function Illustrate.getItems() local items = {} local group1 = {} local group2 = {} local groupTotal1 = 0 local groupTotal2 = 0 local cfgs = ConfigDataManager.getList("cfg_illustrate_summon") for k, v in pairs(cfgs) do if v.group == "1" then groupTotal1 = groupTotal1 + tonumber(v.weightshow) table.insert( group1, { id = v.id, weighted = tonumber(v.weightshow) } ) elseif v.group == "2" then groupTotal2 = groupTotal2 + tonumber(v.weightshow) table.insert( group2, { id = v.id, weighted = tonumber(v.weightshow) } ) end end -- 配置出错 if table.count(group1) < 1 or table.count(group2) < 1 then return {} end local item1 = Illustrate.RandomWeightedOne(group1, groupTotal1) if item1 ~= nil then table.insert(items, item1.id) end for i = 1, 12 do local item2 = Illustrate.RandomWeightedOne(group2, groupTotal2) -- 配置出错 if item2 == nil then return {} end item2.isSelected = true groupTotal2 = groupTotal2 - item2.weighted table.insert(items, item2.id) end return items end function Illustrate.getMainInfo(actor, msgid) local info = Illustrate.getInfo(actor) sendluamsg( actor, msgid, { type = 1, info = info } ) end function Illustrate.onSummon(actor, msgid) local info = Illustrate.getInfo(actor) local weightgetTotal = 0 local items = {} for k, v in pairs(info.items) do local cfg = ConfigDataManager.getById("cfg_illustrate_summon", tonumber(v)) -- 可能策划改配置了 if cfg ~= nil then table.insert( items, { id = v, weighted = tonumber(cfg.weightget) } ) weightgetTotal = weightgetTotal + tonumber(cfg.weightget) end end local reward = Illustrate.RandomWeightedOne(items, weightgetTotal) if reward == nil then tipinfo(actor, "1001#召唤失败!") return end -- 扣除消耗 local summonNum = info.summonNum local cfgCost = nil local cfgs = ConfigDataManager.getList("cfg_illustrate_cost") for i, v in ipairs(cfgs) do local group = tonumber(v.group) local num = tonumber(v.num) - 1 if group == 1 and cfgCost == nil then cfgCost = v elseif group == 1 and summonNum >= num then cfgCost = v end end if cfgCost == nil then tipinfo(actor, "1002#召唤扣除失败!") return end local cost_map = {} if not string.isNullOrEmpty(cfgCost.costs) then string.putIntIntMap(cost_map, cfgCost.costs, "#", "|") end if table.count(cost_map) <= 0 then tipinfo(actor, "1002#召唤扣除失败!") return end if not API.CheckItemMap(actor, cost_map) then tipinfo(actor, "材料不足") return end API.TakeItemMap(actor, cost_map) info.summonNum = info.summonNum + 1 Illustrate.setInfo(actor, info) local cfg = ConfigDataManager.getById("cfg_illustrate_summon", reward.id) local tmpcosts = {} string.putIntIntMap(tmpcosts, cfg.items, "#", "|") if table.count(tmpcosts) > 0 then Bag.addItemMapToBag(actor, tmpcosts, 0, 9999, "图鉴召唤") sendluamsg(actor, LuaMessageIdToClient.COMMON_REWARD_PANEL, tmpcosts) end if cfg.mark == "1" then local playerName = getbaseinfo(actor, "rolename") local historySelf = Illustrate.getHistorySelf(actor) local history = Illustrate.getHistory() for k, v in pairs(tmpcosts) do local data = { cfgId = k, name = playerName } API.InsertAndKeepLen(historySelf, data, HistoryLen) API.InsertAndKeepLen(history, data, HistoryLen) end Illustrate.setHistory(history) Illustrate.setHistorySelf(actor, historySelf) end -- 发放奖励 sendluamsg( actor, msgid, { type = 10, cfgid = reward.id } ) Illustrate.getMainInfo(actor, msgid) Illustrate.onHistorySelf(actor, msgid) Illustrate.onHistory(actor, msgid) end function Illustrate.RandomWeightedOne(datasWeighteds, weightedTotal) local random_weight = math.random(1, weightedTotal) for i, v in ipairs(datasWeighteds) do if v.isSelected == true then else if random_weight <= v.weighted then return v end random_weight = random_weight - v.weighted end end return datasWeighteds[1] end function Illustrate.onRefresh(actor, msgid) -- 判断消耗 local info = Illustrate.getInfo(actor) -- 扣除消耗 local refreshNum = info.refreshNum local cfgCost = nil local cfgs = ConfigDataManager.getList("cfg_illustrate_cost") for i, v in ipairs(cfgs) do local group = tonumber(v.group) local num = tonumber(v.num) - 1 if group == 2 and cfgCost == nil then cfgCost = v elseif group == 2 and refreshNum >= num then cfgCost = v end end if cfgCost == nil then tipinfo(actor, "1002#刷新扣除失败!") return end local cost_map = {} if not string.isNullOrEmpty(cfgCost.costs) then string.putIntIntMap(cost_map, cfgCost.costs, "#", "|") end if table.count(cost_map) <= 0 then tipinfo(actor, "1002#刷新扣除失败!") return end if not API.CheckItemMap(actor, cost_map) then tipinfo(actor, "材料不足") return end API.TakeItemMap(actor, cost_map) info.refreshNum = info.refreshNum + 1 info.items = Illustrate.getItems() Illustrate.setInfo(actor, info) sendluamsg( actor, msgid, { type = 1, info = info } ) end -- 历史记录.保存玩家抽奖信息 -- index -- name -- cfgId function Illustrate.onHistorySelf(actor, msgid) local historys = Illustrate.getHistorySelf(actor) sendluamsg( actor, msgid, { type = 31, historys = historys } ) -- API.InsertAndKeepLen(arr, value, len) end function Illustrate.onHistory(actor, msgid) local historys = Illustrate.getHistory() sendluamsg( actor, msgid, { type = 30, historys = historys } ) end function Illustrate.onAcviveItem(actor, msgid, sMsg) local cfgid = sMsg.cfgid local info = Illustrate.getInfo(actor) if info.activeitems[cfgid] ~= nil and info.activeitems[cfgid].active == 1 then tipinfo(actor, "不可重复激活") return end local cfg = ConfigDataManager.getById("cfg_illustrate", cfgid) if cfg == nil then tipinfo(actor, "配置错误") return end -- 判断消耗 local cost_map = {} if not string.isNullOrEmpty(cfg.items) then string.putIntIntMap(cost_map, cfg.items, "#", "|") end if not API.CheckItemMap(actor, cost_map) then tipinfo(actor, "材料不足") return end API.TakeItemMap(actor, cost_map) if info.activeitems[cfgid] ~= nil then info.activeitems[cfgid].active = 1 else info.activeitems[cfgid] = {active = 1} end -- table.insert(info.activeitems, { -- active = 1, -- }) Illustrate.setInfo(actor, info) sendluamsg( actor, msgid, { type = 1, info = info } ) end function Illustrate.onAcviveGroup(actor, msgid, sMsg) local main = sMsg.main local sub = sMsg.sub local nowsec = getbaseinfo(actor, "nowsec") local info = Illustrate.getInfo(actor) local activegroupsec = info.activegroups[main] ~= nil and info.activegroups[main][sub] ~= nil and info.activegroups[main][sub] or nil if activegroupsec ~= nil and activegroupsec > nowsec then tipinfo(actor, "无法重复激活图鉴") return end local cfgs = ConfigDataManager.getTable("cfg_illustrate", "group", main, "subgroup", sub) if table.count(cfgs) <= 0 then tipinfo(actor, "配置出错") return end local cfgMain = nil local isActiveAll = true for i, v in ipairs(cfgs) do if not string.isNullOrEmpty(v.groupattrs) then cfgMain = v end if info.activeitems[tonumber(v.id)] == nil or info.activeitems[tonumber(v.id)].active ~= 1 then isActiveAll = false end end if cfgMain == nil then tipinfo(actor, "配置出错") return end if isActiveAll ~= true then tipinfo(actor, "图鉴未收集完成") return end -- 判断消耗 local cost_map = {} if not string.isNullOrEmpty(cfgMain.groupitems) then string.putIntIntMap(cost_map, cfgMain.groupitems, "#", "|") end if not API.CheckItemMap(actor, cost_map) then tipinfo(actor, "材料不足") return end API.TakeItemMap(actor, cost_map) if info.activegroups[main] == nil then info.activegroups[main] = {} end info.activegroups[main][sub] = (nowsec + tonumber(cfgMain.grouptime)) Illustrate.setInfo(actor, info) Illustrate.updateattrs(actor) sendluamsg( actor, msgid, { type = 1, info = info } ) -- if info.activeitems == nil then -- info.activeitems = {} -- end -- if info.activegroups == nil then -- -- {[main][sub]=endtime} -- info.activegroups = {} -- end end function Illustrate.updateattrs(actor) local info = APIGetTable(actor, SYS_ILLUSTRATEINFO) if info == nil or info.activegroups == nil then return end local nowsec = getbaseinfo(actor, "nowsec") local attrs = APIGetTable(actor, SYS_ILLUSTRATEATTRS) or {} local isbreak = false local ischange = false for mk, mv in pairs(info.activegroups) do if attrs[mk] == nil then ischange = true break end for sk, sv in pairs(mv) do if attrs[mk][sk] == nil then ischange = true break end if sv < nowsec then ischange = true break end end if isbreak == true then break end end if ischange ~= true then return end APISetTable(actor, SYS_ILLUSTRATEATTRS, attrs) attrs = {} local addAttrs = {} -- 删除过期的属性 for mk, mv in pairs(info.activegroups) do for sk, sv in pairs(mv) do if sv < nowsec then info.activegroups[mk][sk] = nil end end end local cfgs = ConfigDataManager.getTable("cfg_illustrate") for mk, mv in pairs(info.activegroups) do if attrs[mk] == nil then attrs[mk] = {} end for sk, sv in pairs(mv) do local findIndex, cfg = table.findByCondi( cfgs, function(a) return tonumber(a.group) == mk and tonumber(a.subgroup) == sk and not string.isNullOrEmpty(a.groupattrs) end ) if cfg ~= nil then attrs[mk][sk] = 1 local groupattrs = string.split(cfg.groupattrs, "|") for i, v in ipairs(groupattrs) do local av = string.split(v, "#") local attrId = av[1] local attrValue = av[2] if addAttrs[attrId] == nil then addAttrs[attrId] = attrValue else addAttrs[attrId] = tostring(tonumber(addAttrs[attrId]) + tonumber(attrValue)) end end end end end addrolekmlattributes(actor, "illustrategroupattrs", addAttrs) end