| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564 |
- 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
|