| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531 |
- OpenServerNewAct = {}
- local this = {}
- ---全服首杀数据
- local GLOBAL_OPENSERVERNEW_INFO = "R$global_openservernew_info"
- ---开服活动常量
- local Const = {
- AwardType = {
- ---无
- NONE = 0,
- ---集字
- COLLECT_WORD = 1,
- ---冲级
- LEVEL_UP = 2,
- ---一代翅膀
- WING_ONE = 3,
- ---二代翅膀
- WING_TWO = 4,
- ---三代翅膀
- WING_THREE = 5,
- ---大天使武器
- ANGLE_WEAPON = 6,
- },
- }
- function OpenServerNewAct.IsDataKey(varName)
- if string.equalsIgnoreCase(varName,GLOBAL_OPENSERVERNEW_INFO) then
- return true
- else
- return false
- end
- end
- ---合服事件触发
- function OpenServerNewAct.Combine(varName)
- --清空全服数据
- this.SaveGlobalFirstKill(nil)
- this.SaveGlobalRankInfo(nil)
- end
- --活动是否结束
- function this.IsEnd(type)
- local openDay = tonumber(getserveropendays())
- if type == Const.AwardType.COLLECT_WORD then
- return openDay > 30
- end
- return false
- end
- ---活动页面是否关闭
- function this.IsClose(type)
- local openDay = tonumber(getserveropendays())
- if type == Const.AwardType.COLLECT_WORD then
- return openDay > 30
- end
- return false
- end
- ---[[
- --- 开服数据结构
- --- {type : Const.AwardType,
- --- record : table {
- --- rank : 1,
- --- rid : 1,
- --- }
- --- }
- ---]]
- ---获取开服活动数据
- function this.GetGlobalOpenServerData(type)
- local globalOpenServerInfo = getsysvar(GLOBAL_OPENSERVERNEW_INFO)
- if globalOpenServerInfo == nil then
- globalOpenServerInfo = {}
- end
- -- 如果type为NONE则返回所有数据
- if type == Const.AwardType.NONE then
- return globalOpenServerInfo
- end
- -- 如果type不为NONE则返回对应数据
- if globalOpenServerInfo[type] == nil then
- globalOpenServerInfo[type] = {}
- end
- return globalOpenServerInfo[type]
- end
- ---保存开服活动数据
- function this.SaveGlobalOpenServerData(type, globalOpenServerInfo)
- local golbalOpenServerAllInfo = this.GetGlobalOpenServerData(Const.AwardType.NONE)
- golbalOpenServerAllInfo[type] = globalOpenServerInfo
- setsysvar(GLOBAL_OPENSERVERNEW_INFO, golbalOpenServerAllInfo)
- end
- ---构建活动数据回包
- function OpenServerNewAct.SendActivityInfo(actor, msgData)
- this.SendActivityInfo(actor)
- end
- ---构建活动数据回包
- function this.SendActivityInfo(actor)
- -- setsysvar(GLOBAL_OPENSERVERNEW_INFO, {})
- local globalOpenServerInfo = this.GetGlobalOpenServerData(Const.AwardType.NONE)
-
- sendluamsg(actor, LuaMessageIdToClient.RES_ACTIVITY_OPENSERVER_INFO, globalOpenServerInfo)
- end
- ---构建子活动记录
- function OpenServerNewAct.SendActivitySubRecord(actor, msgData)
- this.SendActivitySubRecord(actor, msgData)
- end
- ---构建子活动记录
- function this.SendActivitySubRecord(actor, msgData)
- local activityType = tonumber(msgData["activityType"])
- local globalOpenServerInfo = this.GetGlobalOpenServerData(activityType)
- if globalOpenServerInfo.record == nil then
- globalOpenServerInfo.record = {}
- end
- local listRecord = {}
- if activityType == Const.AwardType.COLLECT_WORD then
- for i = 1, 10 do
- local recordData = globalOpenServerInfo.record[i] or {}
- for _, data in ipairs(recordData) do
- local rid = tonumber(data.rid)
- local actor = getactor(rid)
- local rank = tonumber(data.rank)
- local name = getbaseinfo(actor, "rolename")
- local careerbase = getbaseinfo(actor, "getbasecareer")
- local careerrank = getbaseinfo(actor, "getcareerrank")
- local rewardType = i
- table.insert(listRecord, {rid = rid, rank = rank, name = name, careerbase = careerbase, careerrank = careerrank, rewardType = rewardType})
- end
- end
- else
- for _, data in ipairs(globalOpenServerInfo.record) do
- local rid = tonumber(data.rid)
- local actor = getactor(rid)
- local rank = tonumber(data.rank)
- local name = getbaseinfo(actor, "rolename")
- local careerbase = getbaseinfo(actor, "getbasecareer")
- local careerrank = getbaseinfo(actor, "getcareerrank")
- table.insert(listRecord, {rid = rid, rank = rank, name = name, careerbase = careerbase, careerrank = careerrank})
- end
- end
-
- sendluamsg(actor, LuaMessageIdToClient.RES_ACTIVITY_OPENSERVER_RECORD, listRecord)
- end
- -- 获取对应活动可领取奖励总数
- function this.GetActivityRewardTotalNum(activityType, listConfig)
- local totalNum = 0
- for _, v in pairs(listConfig) do
- local numParam = v.numparam
- if activityType == Const.AwardType.COLLECT_WORD or
- activityType == Const.AwardType.ANGLE_WEAPON then
- totalNum = totalNum + tonumber(numParam)
- else
- local numArr = string.split(numParam, "#")
- local numLower = tonumber(numArr[1])
- local numUpper = tonumber(numArr[2])
- totalNum = totalNum + numUpper - numLower + 1
- end
- end
- return totalNum
- end
- ---领取奖励
- function OpenServerNewAct.ReceiveReward(actor, msgData)
- this.ReceiveAward(actor, msgData)
- end
- ---领取奖励
- function this.ReceiveAward(actor, msgData)
- -- jprint("玩家请求领取开服冲榜奖励",actor,msgData)
- local activityType = tonumber(msgData["activityType"])
- local activitySubType = tonumber(msgData["activitySubType"])
- local activityData = this.GetGlobalOpenServerData(activityType)
- if this.IsEnd(activityType) then
- tipinfo(actor, "活动已结束")
- return
- end
- ---@type cfg_OpenServer_column[]
- local listConfig = {}
- local configTable = ConfigDataManager.getList("cfg_OpenServer")
- for i = 1, #configTable do
- ---@type cfg_OpenServer_column
- local config = configTable[i]
- if tonumber(config.maingroup) == activityType then
- if activityType ~= Const.AwardType.COLLECT_WORD or tonumber(config.subtype) == activitySubType then
- table.insert(listConfig, config)
- end
- end
- end
- local totalCount = this.GetActivityRewardTotalNum(activityType, listConfig)
- if totalCount <= 0 then
- tipinfo(actor,"配置可领取数量不足")
- return
- elseif activityType == Const.AwardType.COLLECT_WORD then
- local configCollectWord = listConfig[1]
- if configCollectWord == nil then
- print("OpenServerNewActivity.ReceiveAward configCollectWord is nil, listConfig:", listConfig)
- return
- end
- if activityData.record == nil then
- activityData.record = {}
- end
-
- if activityData.record[activitySubType] == nil then
- activityData.record[activitySubType] = {}
- end
- -- 可领取数量不足
- local hasRewardNum = #activityData.record[activitySubType]
- if tonumber(configCollectWord.numparam) <= hasRewardNum then
- tipinfo(actor,"可领取数量不足")
- -- 发送活动数据刷新显示
- this.SendActivityInfo(actor)
- return
- end
- -- 解析配置表,获取所需的物品
- local itemsNeedArr = string.split(configCollectWord.needitem, "|")
- local itemsNeed = {}
- for _, itemData in pairs(itemsNeedArr) do
- local itemAttr = string.split(itemData, "#")
- local itemNeed = {itemId = tonumber(itemAttr[1]), num = tonumber(itemAttr[2])}
- table.insert(itemsNeed, itemNeed)
- end
- -- print("OpenServerNewActivity.ReceiveAward itemsNeed:", itemsNeed)
- -- 判断所需道具是否足够
- local listItem = getbagdata(actor)
- for _, item in pairs(listItem.items) do
- for i, itemNeed in ipairs(itemsNeed) do
- if tonumber(item.cfgid) == itemNeed.itemId and itemNeed.num > 0 then
- if tonumber(item.count) >= itemNeed.num then
- itemsNeed[i].num = 0
- else
- itemsNeed[i].num = itemsNeed[i].num - tonumber(item.count)
- end
- end
- end
- end
- local hasItem = false
- for k, itemNeed in pairs(itemsNeed) do
- if itemNeed.num > 0 then
- hasItem = true
- break
- end
- end
- if hasItem then
- -- 所需道具不足
- tipinfo(actor,"所需道具不足")
- return
- end
- -- 发送对应活动奖励
- if this.SendReward(actor, activityType, activitySubType, activityData, listConfig) then
- local recordNum = 0
- for i,v in pairs(activityData.record) do
- recordNum = recordNum + table.count(v)
- end
- local recordData = {rank = recordNum + 1, rid = getbaseinfo(actor, "rid")}
- table.insert(activityData.record[activitySubType], recordData)
- this.SaveGlobalOpenServerData(activityType, activityData)
- this.SendActivityInfo(actor)
- end
- else
- if activityData.record == nil then
- activityData.record = {}
- end
- -- 可领取数量不足
- if #activityData.record >= totalCount then
- tipinfo(actor,"可领取数量不足")
- -- 发送活动数据刷新显示
- this.SendActivityInfo(actor)
- return
- end
- -- 判断是否已领取过
- local rid = getbaseinfo(actor, "rid")
- for k, recordData in pairs(activityData.record) do
- if tonumber(rid) == tonumber(recordData.rid) then
- tipinfo(actor,"您已领取过该活动奖励")
- -- 发送活动数据刷新显示
- this.SendActivityInfo(actor)
- return
- end
- end
- local wingItemId = 0
- -- 判断是否符合条件
- if activityType == Const.AwardType.LEVEL_UP then
- local levelNeed = tonumber(listConfig[1].needitem)
- if levelNeed > getbaseinfo(actor, "level") then
- -- 目标等级不足
- tipinfo(actor,"等级不足"..levelNeed.."级")
- return
- end
- elseif activityType == Const.AwardType.WING_ONE or
- activityType == Const.AwardType.WING_TWO or
- activityType == Const.AwardType.WING_THREE then
- -- 解析配置表,获取所需的翅膀id
- local wingIdsNeedArr = string.split(listConfig[1].needitem, "|")
- local wingIdsNeed = {}
- for _, wingItem in pairs(wingIdsNeedArr) do
- local wingItemAttr = string.split(wingItem, "#")
- table.insert(wingIdsNeed, tonumber(wingItemAttr[1]))
- end
- -- 获取当前角色的翅膀id
- local hasWing = false
- local hasSameWing = false
- local listEquip = getallequipinfo(actor)
- for _, equipItem in pairs(listEquip) do
- local cfgId = tonumber(equipItem.cfgid)
- local configEquip = ConfigDataManager.getById("cfg_item", cfgId)
- local originid = API.GetItemData(actor, equipItem.id, "originid")
- if configEquip ~= nil and tonumber(configEquip.type) == 2 and tonumber(configEquip.subtype) == 13 then
- for _, wingId in pairs(wingIdsNeed) do
- if tonumber(wingId) == tonumber(configEquip.id) then
- local tmpHasSameWing = false
- for _,recordData in ipairs(activityData.record) do
- print("check wing id, recordData: ", recordData, originid, equipItem.id)
- if originid ~= nil and tonumber(recordData.itemId) == tonumber(originid) then
- tmpHasSameWing = true
- elseif tonumber(recordData.itemId) == tonumber(equipItem.id) then
- tmpHasSameWing = true
- end
- end
- if tmpHasSameWing then
- hasSameWing = true
- else
- if originid ~= nil and tonumber(originid) > 0 then
- wingItemId = originid
- else
- wingItemId = equipItem.id
- end
- hasWing = true
- break
- end
- end
- end
- if hasWing then
- break
- end
- end
- end
- if not hasWing then
- -- 目标没有所需翅膀
- if hasSameWing then
- tipinfo(actor,"您拥有的翅膀已领取过奖励")
- else
- tipinfo(actor,"没有所需翅膀")
- end
- return
- end
- elseif activityType == Const.AwardType.ANGLE_WEAPON then
- -- 解析配置表,获取所需的大天使武器id
- local weaponIdsNeedArr = string.split(listConfig[1].needitem, "|")
- local weaponIdsNeed = {}
- for _, weaponItem in ipairs(weaponIdsNeedArr) do
- local weaponItemAttr = string.split(weaponItem, "#")
- table.insert(weaponIdsNeed, tonumber(weaponItemAttr[1]))
- end
- -- 获取当前角色的大天使武器id
- local hasWeapon = false
- local listEquip = getallequipinfo(actor)
- for _, equipItem in pairs(listEquip) do
- local cfgId = tonumber(equipItem.cfgid)
- local configEquip = ConfigDataManager.getById("cfg_item", cfgId)
- if configEquip ~= nil and tonumber(configEquip.type) == 2 then
- for _, weaponId in pairs(weaponIdsNeed) do
- if tonumber(weaponId) == tonumber(equipItem.cfgid) then
- hasWeapon = true
- break
- end
- end
- if hasWeapon then
- break
- end
- end
- end
- if not hasWeapon then
- -- 目标没有所需大天使武器
- tipinfo(actor,"没有所需大天使武器")
- return
- end
- end
- print("OpenServerNewAct.ReceiveReward SendReward Start")
- -- 发送对应活动奖励
- if this.SendReward(actor, activityType, activitySubType, activityData, listConfig) then
- local recordData = {rank = #activityData.record + 1, rid = getbaseinfo(actor, "rid")}
- if wingItemId > 0 then
- recordData.itemId = wingItemId
- end
-
- table.insert(activityData.record, recordData)
- this.SaveGlobalOpenServerData(activityType, activityData)
- this.SendActivityInfo(actor)
- end
- end
- end
- -- 获取对应活动配置
- function this.GetRewardConfig(activityType, activitySubType, activityData, listConfig)
- if activityType == Const.AwardType.COLLECT_WORD then
- return listConfig[1]
- elseif activityType == Const.AwardType.LEVEL_UP or
- activityType == Const.AwardType.WING_ONE or
- activityType == Const.AwardType.WING_TWO or
- activityType == Const.AwardType.WING_THREE then
- local rewardNum = #activityData.record + 1
- for _, config in ipairs(listConfig) do
- local numParam = config.numparam
- local numArr = string.split(numParam, "#")
- local numUpper = tonumber(numArr[2])
- local numLower = tonumber(numArr[1])
- rewardNum = rewardNum - numUpper + numLower - 1
- if rewardNum <= 0 then
- return config
- end
- end
- return nil
- elseif activityType == Const.AwardType.ANGLE_WEAPON then
- return listConfig[1]
- end
- return nil
- end
- -- 发送奖励
- function this.SendReward(actor, activityType, activitySubType, activityData, listConfig)
- local configReward = this.GetRewardConfig(activityType, activitySubType, activityData, listConfig)
- if configReward == nil then
- print("[OpenServerNewActivity.SendReward] configReward is nil")
- return false
- end
- local title = "开服活动"
- if activityType == Const.AwardType.COLLECT_WORD then
- local emailId = MailConfig.ACTIVITY_OPENSERVER_COLLECTWORD_1
- if activitySubType == 1 then
- emailId = MailConfig.ACTIVITY_OPENSERVER_COLLECTWORD_1
- elseif activitySubType == 2 then
- emailId = MailConfig.ACTIVITY_OPENSERVER_COLLECTWORD_2
- elseif activitySubType == 3 then
- emailId = MailConfig.ACTIVITY_OPENSERVER_COLLECTWORD_3
- else
- print("[OpenServerNewActivity.SendReward] activitySubType error")
- return false
- end
- -- 解析配置表,移除道具
- local itemsNeedArr = string.split(configReward.needitem, "|")
- local itemsNeed = {}
- for _, itemData in pairs(itemsNeedArr) do
- local itemAttr = string.split(itemData, "#")
- local itemNeed = {itemId = tonumber(itemAttr[1]), num = tonumber(itemAttr[2])}
- table.insert(itemsNeed, itemNeed)
-
- removeitemfrombag(actor, tonumber(itemAttr[1]), tonumber(itemAttr[2]), 0, 9999, "开服集字活动")
- end
- sendconfigmailbyrid(actor, getbaseinfo(actor, "rid"), emailId, {}, "")
- else
- local rewardArr = string.split(configReward.reward, "|")
- local rewardMap = {}
- for i = 1, #rewardArr do
- local rewardArr2 = string.split(rewardArr[i], "#")
- rewardMap[tonumber(rewardArr2[1])] = tonumber(rewardArr2[2])
- end
- local emailId = MailConfig.ACTIVITY_OPENSERVER_LEVEL_UP
- if activityType == Const.AwardType.LEVEL_UP then
- emailId = MailConfig.ACTIVITY_OPENSERVER_LEVEL_UP
- elseif activityType == Const.AwardType.WING_ONE then
- emailId = MailConfig.ACTIVITY_OPENSERVER_WING_ONE
- elseif activityType == Const.AwardType.WING_TWO then
- emailId = MailConfig.ACTIVITY_OPENSERVER_WING_TWO
- elseif activityType == Const.AwardType.WING_THREE then
- emailId = MailConfig.ACTIVITY_OPENSERVER_WING_THREE
- elseif activityType == Const.AwardType.ANGLE_WEAPON then
- emailId = MailConfig.ACTIVITY_OPENSERVER_ANGLE_WEAPON
- else
- print("[OpenServerNewActivity.SendReward] activityType error")
- return false
- end
- local rewardNum = #activityData.record + 1
- sendconfigmailbyrid(actor, getbaseinfo(actor, "rid"), emailId, rewardMap, configReward.showtogname.."#"..rewardNum)
- end
- print("OpenServerNewActivity.SendReward send reward success")
-
- sendluamsg(actor, LuaMessageIdToClient.RES_ACTIVITY_OPENSERVER_REWARD_RESULT, {activityType = activityType, activitySubType = activitySubType})
- return true
- end
|