| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455 |
- ---- 次元魔珠 中心服
- local Util = require("common.Util")
- local ObjHuman = require("core.ObjHuman")
- local MoZhuDB = require("mozhu.MoZhuDB")
- local MoZhuExcel = require("excel.mozhu")
- local InnerMsg = require("core.InnerMsg")
- local MoZhuLogic = require("mozhu.MoZhuLogic")
- local CombatDefine = require("combat.CombatDefine")
- local Msg = require("core.Msg")
- local MiddleManager = require("middle.MiddleManager")
- function sendReward(mozhuData)
- local unionList = {}
- for rank, unionUuid in ipairs(mozhuData.unionRank) do
- unionList[unionUuid] = rank
- end
- MoZhuLogic.actOverRank({
- type = 2,
- list = unionList
- })
- local roleList = {}
- for rank, uuid in ipairs(mozhuData.roleRank) do
- roleList[uuid] = rank
- end
- MoZhuLogic.actOverRank({
- type = 1,
- list = roleList
- })
- end
- function onHour(hour)
- if _G.is_middle ~= true then
- -- 目前没有跨服,暂时注释
- --return
- end
- local nowWeek = Util.getWeekDay()
- -- mozhu 暂未开放
- if not MoZhuLogic.MOZHU_OPEN_DAY[nowWeek] then
- --是否需要重置mozhu数据
- return
- end
- local mozhuData = MoZhuDB.getMoZhu()
- if not next(mozhuData) or not Util.isSameDay(mozhuData.time) then
- MoZhuDB.initMoZhu()
- mozhuData = MoZhuDB.getMoZhu()
- end
- -- 是否发奖励
- local start,finish = MoZhuLogic.getActTime()
- local nowTime = os.time()
- if nowTime >= finish and nowTime < (start + 86400) and (not mozhuData.isReward or not Util.isSameDay(mozhuData.isReward))then
- mozhuData.isReward = nowTime
- -- 延后处理 随机十秒
- local r = math.random(10)
- require("core.Timer").addLater(r,function()
- sendReward(mozhuData)
- MoZhuDB.saveMoZhu()
- end)
- -- 发放上一日 排名奖励
- --actOverUnion()
- --actOverRole()
- MoZhuDB.saveMoZhu()
- end
- end
- function getCiTiao()
- local mozhuDB = MoZhuDB.getMoZhu()
- return mozhuDB.citiao
- end
- function fontRoleRank(mozhuDB, msgInner, topRank)
- local maxRank = topRank and topRank or #mozhuDB.roleRank
- maxRank = maxRank <= #mozhuDB.roleRank and maxRank or #mozhuDB.roleRank
- maxRank = maxRank <= 100 and maxRank or 100
- for i = 1, maxRank do
- local uuid = mozhuDB.roleRank[i]
- local role = mozhuDB.role[uuid]
- if uuid and role then
- -- local net = msgInner.roleRank[i]
- msgInner.roleRank[i] = {}
- msgInner.roleRank[i].uuid = uuid
- msgInner.roleRank[i].roleBase = role.roleBase
- msgInner.roleRank[i].hurt = role.hurt
- end
- end
- end
- function fontUnionRank(mozhuDB, msgInner, topRank)
- local maxRank = topRank and topRank or #mozhuDB.unionRank
- maxRank = maxRank <= #mozhuDB.unionRank and maxRank or #mozhuDB.unionRank
- maxRank = maxRank <= 50 and maxRank or 50
- for i = 1, maxRank do
- local unionUuid = mozhuDB.unionRank[i]
- local union = mozhuDB.union[unionUuid]
- if unionUuid and union then
- -- local net = msgInner.unionRank[i]
- msgInner.unionRank[i] = {}
- msgInner.unionRank[i].unionUuid = unionUuid
- msgInner.unionRank[i].unionBase = union.unionBase
- msgInner.unionRank[i].hurt = union.hurt
- end
- end
- end
- function fontMyRank(mozhuDB, uuid, msgInner)
- local rank = MoZhuDB.getRoleRank(uuid)
- local role = mozhuDB.role[uuid]
- if rank > 0 and role then
- msgInner.info.myRank.uuid = uuid
- msgInner.info.myRank.rank = rank
- msgInner.info.myRank.roleBase = role.roleBase
- msgInner.info.myRank.hurt = role.hurt
- end
- end
- function fontMyUnion(mozhuDB, unionUuid, msgInner)
- local union = mozhuDB.union[unionUuid]
- local rank = MoZhuDB.getUnionRank(unionUuid)
- if rank > 0 and union then
- msgInner.info.myUnion.unionUuid = unionUuid
- msgInner.info.myUnion.rank = rank
- msgInner.info.myUnion.unionBase = union.unionBase
- msgInner.info.myUnion.hurt = union.hurt
- end
- end
- function LW_MOZHU_QUERY(fd, msg)
- MoZhuDB.checkUnion()
- local mozhuDB = MoZhuDB.getMoZhu()
- if not mozhuDB or not mozhuDB.time then
- -- MoZhuDB.initMoZhu()
- -- mozhuDB = MoZhuDB.getMoZhu()
- end
-
- -- Util.printTable(mozhuDB)
- local msgInner = {} --InnerMsg.wl.WL_MOZHU_QUERY
- msgInner.uuid = msg.uuid
- msgInner.myRank = 0
- msgInner.roleRank = {}
- msgInner.unionRank = {}
- msgInner.info = {}
- msgInner.info.citiao = {}
- msgInner.info.myRank = {}
- msgInner.info.myUnion = {}
- msgInner.info.citiao = mozhuDB.citiao
- msgInner.info.citiaoTime = mozhuDB.citiaoTime
- fontUnionRank(mozhuDB, msgInner, 10)
- fontRoleRank(mozhuDB, msgInner, 10)
- fontMyRank(mozhuDB, msg.uuid, msgInner)
- fontMyUnion(mozhuDB, msg.unionUuid, msgInner)
- --InnerMsg.sendMsg(fd, msgInner)
- WL_MOZHU_QUERY(fd,msgInner)
- end
- function WL_MOZHU_QUERY(fd, msg)
- local human = ObjHuman.onlineUuid[msg.uuid]
- if human == nil then
- return
- end
- MoZhuLogic.WLQuery(human,msg)
- end
- function LW_MOZHU_FIGHT_END(fd, msg)
- -- 检测活动是否已经结束
- local combatInfo = msg.combatInfo
- local atkHurt = 0
- for pos = 1, CombatDefine.COMBAT_HERO_CNT do
- local obj = combatInfo.objList and combatInfo.objList[pos]
- if obj then
- atkHurt = atkHurt + obj.result[1]
- end
- end
- -- 魔兽 造成伤害
- for _,pos in ipairs(CombatDefine.SIDE2HELPPOS[CombatDefine.ATTACK_SIDE]) do
- local pet = combatInfo.helpList and combatInfo.helpList[pos]
- if pet and pet.isPet then
- atkHurt = atkHurt + pet.result[1]
- end
- end
- if atkHurt <= 0 then
- atkHurt = 0
- end
- local startTime, endTime = MoZhuLogic.getActTime()
- local now = os.time()
- local msgInner = {} --InnerMsg.wl.WL_MOZHU_FIGHT_END
- if now < startTime or now > endTime then
- local rank, maxHurt = MoZhuDB.getRoleRank(msg.uuid)
- local unRank = MoZhuDB.getUnionRank(msg.unionUuid)
- msgInner.backType = 0
- msgInner.uuid = msg.uuid
- msgInner.oldRank= rank
- msgInner.rank = rank
- msgInner.unionRank = unRank
- msgInner.unionRanked = unRank
- msgInner.thisHurt = atkHurt
- msgInner.maxHurt = maxHurt
- msgInner.combatInfo = msg.combatInfo
- -- Msg.trace(msgInner)
- --InnerMsg.sendMsg(fd, msgInner)
- WL_MOZHU_FIGHT_END(fd,msgInner)
- return
- end
- local oldRank = MoZhuDB.getRoleRank(msg.uuid)
- local oldUnRank = MoZhuDB.getUnionRank(msg.unionUuid)
- MoZhuDB.updateHurt(msg.uuid, msg.roleBase, msg.maxHurt)
- MoZhuDB.updateUnion(msg.unionUuid, msg.unionBase)
-
- local newRank, maxHurt = MoZhuDB.getRoleRank(msg.uuid)
- local newUnRank = MoZhuDB.getUnionRank(msg.unionUuid)
- -- Util.printTable(MoZhuDB.getMoZhu())
- msgInner.backType = 1
- msgInner.uuid = msg.uuid
- msgInner.oldRank= oldRank
- msgInner.rank = newRank
- msgInner.unionRank = newUnRank
- msgInner.unionRanked = oldUnRank
- msgInner.thisHurt = atkHurt
- msgInner.maxHurt = maxHurt
- msgInner.combatInfo = msg.combatInfo
- -- Msg.trace(msgInner)
- --InnerMsg.sendMsg(fd, msgInner)
- WL_MOZHU_FIGHT_END(fd,msgInner)
- MoZhuDB.saveMoZhu()
- end
- function WL_MOZHU_FIGHT_END(fd, msg)
- local human = ObjHuman.onlineUuid[msg.uuid]
- if human == nil then
- return
- end
- MoZhuLogic.onfightEndWL(human,msg)
- end
- function LW_MOZHU_RANK_QUERY(fd, msg)
- local mozhuDB = MoZhuDB.getMoZhu()
- local msgInner = {}--InnerMsg.wl.WL_MOZHU_RANK_QUERY
- msgInner.uuid = msg.uuid
- msgInner.type = msg.type
- msgInner.roleRank = {}
- msgInner.unionRank = {}
- if msg.type == 1 then
- fontRoleRank(mozhuDB, msgInner)
- else
- fontUnionRank(mozhuDB, msgInner)
- end
- --InnerMsg.sendMsg(fd, msgInner)
- WL_MOZHU_RANK_QUERY(fd,msgInner)
- end
- function WL_MOZHU_RANK_QUERY(fd, msg)
- local human = ObjHuman.onlineUuid[msg.uuid]
- if human == nil then
- return
- end
- MoZhuLogic.rankQueryWL(human, msg)
- end
- function LW_MOZHU_UNION_GET(fd, msg)
- local mozhuDB = MoZhuDB.getMoZhu()
- local union = mozhuDB.union[msg.unionUuid]
- local rank = MoZhuDB.getUnionRank(msg.unionUuid)
- local ret = 0
- if rank > 0 and union then
- local config = MoZhuExcel.hurt[msg.id]
- if config.unionHurt <= union.hurt then
- ret = 1
- end
- end
- local msgInner = {} --InnerMsg.wl.WL_MOZHU_UNION_GET
- msgInner.uuid = msg.uuid
- msgInner.ret = ret
- msgInner.id = msg.id
- --InnerMsg.sendMsg(fd, msgInner)
- WL_MOZHU_UNION_GET(fd,msgInner)
- end
- function WL_MOZHU_UNION_GET(fd, msg)
- local human = ObjHuman.onlineUuid[msg.uuid]
- if human == nil then
- return
- end
- MoZhuLogic.unionGetWL(human, msg)
- end
- function LW_ROLE_UNION_OP(fd, msg)
- if msg.op == 1 then
- roleLeaveUnion(msg.uuid, msg.unionUuid)
- elseif msg.op == 2 then
- joinUnion(msg.uuid, msg.unionUuid)
- elseif msg.op == 3 then
- dismissUnion(msg.uuid, msg.unionUuid)
- end
- end
- function roleLeaveUnion(uuid, unionUuid)
- local mozhuDB = MoZhuDB.getMoZhu()
- local rank = MoZhuDB.getRoleRank(uuid)
- local role = mozhuDB.role[uuid]
- local union = mozhuDB.union[unionUuid]
- if rank > 0 and role then
- MoZhuDB.chageRoleUnionUuid(uuid, "")
- if union then
- MoZhuDB.refreshUnion(unionUuid)
- end
- MoZhuDB.saveMoZhu()
- end
- end
- function joinUnion(uuid, unionUuid)
- local mozhuDB = MoZhuDB.getMoZhu()
- local rank = MoZhuDB.getRoleRank(uuid)
- local role = mozhuDB.role[uuid]
- local union = mozhuDB.union[unionUuid]
- if rank > 0 and role then
- MoZhuDB.chageRoleUnionUuid(uuid, unionUuid)
- if union then
- MoZhuDB.refreshUnion(unionUuid)
- end
- MoZhuDB.saveMoZhu()
- end
- end
- function dismissUnion(uuid, unionUuid)
- local mozhuDB = MoZhuDB.getMoZhu()
- local rank = MoZhuDB.getRoleRank(uuid)
- local role = mozhuDB.role[uuid]
- if rank > 0 and role then
- MoZhuDB.chageRoleUnionUuid(uuid, unionUuid)
- end
-
- local union = mozhuDB.union[unionUuid]
- if union then
- MoZhuDB.dismissUnion(unionUuid)
- end
- end
- -------------------------------- Act End --------------------------
- function actOverUnion()
- local mozhuDB = MoZhuDB.getMoZhu()
- local svrList = {}
- for rank, unionUuid in ipairs(mozhuDB.unionRank) do
- local union = mozhuDB.union[unionUuid]
- if unionUuid and union and union.unionBase and union.unionBase.svrIndex and union.hurt > 0 then
- local svrIndex = union.unionBase.svrIndex
- svrList[svrIndex] = svrList[svrIndex] or {}
- svrList[svrIndex][unionUuid] = rank
- end
- end
- for svrIndex, list in pairs(svrList) do
- local msgInner = InnerMsg.wl.WL_MOZHU_RANK_OVER
- msgInner.type = 2
- msgInner.list = msgInner.list or {}
- Util.cleanTable(msgInner.list)
- msgInner.list = list
- local fd = MiddleManager.getFDBySvrIndex(svrIndex)
- InnerMsg.sendMsg(fd, msgInner)
- end
- end
- function actOverRole()
- local mozhuDB = MoZhuDB.getMoZhu()
- local svrList = {}
-
- for rank, uuid in ipairs(mozhuDB.roleRank) do
- local role = mozhuDB.role[uuid]
- if uuid and role and role.roleBase and role.roleBase.svrIndex and role.hurt > 0 then
- local svrIndex = role.roleBase.svrIndex
- svrList[svrIndex] = svrList[svrIndex] or {}
- svrList[svrIndex][uuid] = rank
- end
- end
- for svrIndex, list in pairs(svrList) do
- local msgInner = InnerMsg.wl.WL_MOZHU_RANK_OVER
- msgInner.type = 1
- msgInner.list = msgInner.list or {}
- Util.cleanTable(msgInner.list)
- msgInner.list = list
- local fd = MiddleManager.getFDBySvrIndex(svrIndex)
- InnerMsg.sendMsg(fd, msgInner)
- end
- end
- function initAfterHotClean()
- if _G.is_middle == true then
-
- MoZhuDB.refreshAllUnion()
- end
- --[[
- local uuidList = {}
- uuidList[1] = "61512a8f639f62538000641a"
- uuidList[2] = "616a5468d98e7c2e9b000ad8"
- uuidList[3] = "616a2005cdd131276d0003cc"
- uuidList[4] = "6160766fcdd1317fc1000065"
- if _G.is_middle ~= true then
- for _, uuid in ipairs(uuidList) do
- local human = ObjHuman.onlineUuid[uuid]
- if human then
- human.db.mozhu = {}
- human.db.mozhu.time = os.time()
- human.db.mozhu.hurtMax = 0
- human.db.mozhu.hurt = 0
- human.db.mozhu.tzCnt = 0
- human.db.mozhu.restCnt = 0
- else
- local RoleDBLogic = require("role.RoleDBLogic")
- local db = RoleDBLogic.getDb(uuid)
- if db then
- human = {}
- human.db = db
- human.db.mozhu = {}
- human.db.mozhu.time = os.time()
- human.db.mozhu.hurtMax = 0
- human.db.mozhu.hurt = 0
- human.db.mozhu.tzCnt = 0
- human.db.mozhu.restCnt = 0
- ObjHuman.save(human)
- end
- end
- end
- else
- for _, uuid in ipairs(uuidList) do
- MoZhuDB.delRole(uuid)
- end
- end
-
- ]]
-
- end
|