From 0a07bdd981c3ccb5305c53746d63f284ca5ac78b Mon Sep 17 00:00:00 2001 From: zhouahaihai Date: Tue, 27 Nov 2018 10:40:29 +0800 Subject: [PATCH] 角色升级 。gm --- src/ProtocolCode.lua | 225 ++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/RedisKeys.lua | 88 +++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------- src/actions/GmAction.lua | 7 +++++++ src/actions/HeroAction.lua | 31 +++++++++++++++++++++++++++++++ src/actions/RoleAction.lua | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------ src/agent.lua | 4 ++-- src/models/Hero.lua | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/models/Role.lua | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----- src/models/RoleChangeStruct.lua | 4 ++-- src/models/RolePlugin.lua | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 10 files changed, 336 insertions(+), 298 deletions(-) create mode 100644 src/actions/HeroAction.lua create mode 100644 src/models/Hero.lua diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index d151d11..367a9ce 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -15,235 +15,14 @@ actionCodes = { Role_queryLoginRpc = 101, Role_createRpc = 102, Role_loginRpc = 103, + Role_syncTimeRpc = 104, Role_updateProperty = 105, Role_updateProperties = 106, - Role_changeFormationRpc = 107, - Role_setCrownRpc = 108, - Role_formationPosRpc = 109, - Role_entrustRpc = 110, - Role_finishEntrustRpc = 111, - Role_updateStoryBook = 112, - Role_finishTalkRpc = 113, - Role_updateHeroBook = 114, - Role_guideRpc = 115, - Role_changeAutoSateRpc = 116, - Role_signRpc = 117, - Role_dailyTaskRpc = 118, - Role_mainTaskRpc = 119, - Role_missionRpc = 120, - Role_formationQuickRpc = 121, - Role_changeNameRpc = 122, - Role_changeHomeBgRpc = 123, - Role_changeHeadIconRpc = 124, - Role_changeHeadFrameRpc = 125, - Role_cookNotesRpc = 126, - Role_cookAddFavoritesRpc = 127, - Role_cookDelFavoritesRpc = 128, - Role_drawCodeRpc = 129, - Role_chat = 130, - Role_signGiftRpc = 131, - Role_changeToRealUserRpc = 132, - Role_cafeSignRpc = 133, - Role_syncTimeRpc = 134, - Role_getLevelRankRpc = 135, - Role_deletAccountRpc = 136, - Role_getItemRankRpc = 137, Hero_loadInfos = 201, Hero_updateProperty = 202, - Hero_decomposeRpc = 203, - Hero_qualityRpc = 204, - Hero_strengthRpc = 205, - Hero_lockRpc = 206, - Hero_researchRpc = 207, - Hero_finishResearchRpc = 208, - Hero_treatRpc = 209, - Hero_finishTreatRpc = 210, - Hero_loveItemRpc = 211, - Hero_finishLoveTaskRpc = 212, - Hero_changeDressRpc = 213, - Hero_quickTreatRpc = 214, - Hero_skillUpRpc = 215, - Hero_changeNameRpc = 216, - Hero_likeHeroRpc = 217, - Hero_commentHeroRpc = 218, - Hero_getCommentsRpc = 219, - Hero_likeCommentRpc = 220, + Hero_levelUpRpc = 203, - - - Item_updateProperty = 301, - - Store_produceRpc = 401, - Store_finishBuildRpc = 402, - Store_diamondBuyRpc = 403, - Store_itemBuyRpc = 404, - Store_rechargeRpc = 405, - Store_ayncPurchaseRpc = 406, - Store_purchaseOrderResult = 407, - Store_iapPurchaseRpc = 408, - Store_iapCancelPurchase = 409, - Store_restorePurchaseRpc = 410, - Store_googlePurchaseRpc = 411, - Store_googleCancelPurchase = 412, - Store_samsungPurchaseRpc = 413, - Store_samsungCancelPurchase = 414, - - Trade_getInfoRpc = 450, - Trade_sellRpc = 451, - Trade_buyRpc = 452, - Trade_giveUpRpc = 453, - Trade_cleanBuyRpc = 454, - - Carbon_arrangeCarbonRpc = 500, - Carbon_moveRpc = 501, - Carbon_actionEndRpc = 502, - Carbon_beginGameRpc = 503, - Carbon_endGameRpc = 504, - Carbon_cancelMoveRpc = 505, - Carbon_updateProperty = 506, - Carbon_endCarbonRpc = 507, - Carbon_exitTeamRpc = 508, - Carbon_supplyRpc = 509, - Map_updateProperty = 510, - Carbon_changePosRpc = 511, - Carbon_generateBoss = 512, - Carbon_givpUpBoss = 513, - Carbon_drawBossAward = 514, - Carbon_SelectRpc = 515, - - Friend_updateProperty = 550, - Friend_listRpc = 551, - Friend_searchRpc = 552, - Friend_randomRpc = 553, - Friend_deleteRpc = 554, - Friend_applyRpc = 555, - Friend_applyListRpc = 556, - Friend_handleApplyRpc = 557, - Friend_report = 558, - - Farm_updateProperty = 600, - Farm_drawMaterial = 601, - Farm_levelUpBuilding = 602, - Farm_changeShowMedal = 603, - Farm_plantRpc = 604, - Farm_useItemRpc = 605, - Farm_getPlantRpc = 606, - Farm_farmInfoRpc = 607, - Farm_changeFarmerRpc = 608, - - Tower_updateProperty = 630, - Tower_battleBeginRpc = 631, - Tower_battleEndRpc = 632, - Tower_resetRpc = 633, - Tower_cureRpc = 634, - Tower_changeFormatRpc = 635, - Tower_getRankRpc = 636, - Tower_formatQuickRpc = 637, - Tower_formationPosRpc = 638, - Tower_breakRpc = 639, - - Email_listRpc = 650, - Email_drawAttachRpc = 651, - Email_checkRpc = 652, - Email_delRpc = 653, - Email_drawAllAttachRpc = 654, - - Pvp_updateProperty = 670, - Pvp_battleBeginRpc = 671, - Pvp_battleEndRpc = 672, - Pvp_resetRpc = 673, - Pvp_enterPvpRpc = 674, - Pvp_getRankRpc = 675, - Pvp_changeFormatRpc = 676, - Pvp_formatQuickRpc = 677, - Pvp_formationPosRpc = 678, - Pvp_skillOrderRpc = 679, - Pvp_shopBuyRpc = 680, - - Equip_updateProperty = 750, - Equip_wearEquipRpc = 751, - Equip_repairEquipRpc = 752, - Equip_forgeEquipAttrsRpc = 753, - Equip_replaceEquipAttrRpc = 754, - Equip_buildEquipRpc = 755, - Equip_finishBuildEquipRpc = 756, - Equip_decomposEquipRpc = 757, - Equip_resetEquipRpc = 758, - Equip_upEquipRpc = 759, - - Activity_getRewardRpc = 801, - Activity_lotteryGiftRpc = 802, - Activity_shopBuyRpc = 803, - Activity_puzzleRewardRpc = 804, - Activity_inheritRewardRpc = 805, - Activity_midAutRewardRpc = 806, - Activity_clearRed = 807, - Activity_halloweenMoveRpc = 808, - Activity_halloweenResetRpc = 809, - Activity_halloweenRewardRpc = 810, - Activity_traditionalRewardRpc = 811, - Activity_africanRpc = 812, - Activity_oldBackRpc = 813, - Activity_orderRewardRpc = 814, - Activity_cookHeroRpc = 815, - - Moon_arrangeCarbonRpc = 850, - Moon_moveRpc = 851, - Moon_actionEndRpc = 852, - Moon_beginGameRpc = 853, - Moon_endGameRpc = 854, - Moon_cancelMoveRpc = 855, - Moon_updateProperty = 856, - Moon_endCarbonRpc = 857, - Moon_exitTeamRpc = 858, - Moon_supplyRpc = 859, - Moon_changePosRpc = 860, - Moon_generateBoss = 861, - Moon_givpUpBoss = 862, - Moon_drawBossAward = 863, - Moon_SelectRpc = 864, - - Paradise_arrangeCarbonRpc = 875, - Paradise_moveRpc = 876, - Paradise_actionEndRpc = 877, - Paradise_beginGameRpc = 878, - Paradise_endGameRpc = 879, - Paradise_cancelMoveRpc = 880, - Paradise_updateProperty = 881, - Paradise_endCarbonRpc = 882, - Paradise_exitTeamRpc = 883, - Paradise_supplyRpc = 884, - Paradise_changePosRpc = 885, - Paradise_SelectRpc = 886, - Paradise_buyCountRpc = 887, - - Diner_loadRpc = 900, - Diner_updateProperty = 901, - Diner_updateProperties = 902, - Diner_accessoryUpdateProperty = 903, - Diner_itemUpdateProperty = 904, - Diner_wearAccessoryRpc = 905, - Diner_upLevelAccessoryRpc = 906, - Diner_supplyMaterialRpc = 907, - Diner_changeCarRpc = 908, - Diner_recycleAccessoryRpc = 909, - Diner_heroToBoxRpc = 910, - Diner_saveBoxFitmentRpc = 911, - Diner_recycleFitmentsRpc = 912, - Diner_sellRpc = 913, - Diner_finishSellRpc = 914, - Diner_shopBuyRpc = 915, - Diner_drawRewardRpc = 916, - Diner_talentUpdateProperty = 917, - - Diner_likeOtherBoxRpc = 918, - Diner_comfortRankRpc = 919, - Diner_nearLikeMeRpc = 920, - Diner_friendListRpc = 921, - Diner_getBoxDataRpc = 922, - Diner_changeTalkRpc = 923, - Diner_changeTalkBgRpc = 924, } rpcResponseBegin = 10000 diff --git a/src/RedisKeys.lua b/src/RedisKeys.lua index a3eeefa..fbd49bb 100644 --- a/src/RedisKeys.lua +++ b/src/RedisKeys.lua @@ -1,41 +1,47 @@ --- role -R_FARM_KEY = "role:%d:farm" -R_TOWER_KEY = "role:%d:tower" -R_COOKLOG_KEY = "role:%d:cooklog" -R_TRADELOG_KEY = "role:%d:tradelog" -R_PVP_KEY = "role:%d:pvp" -R_DINER_KEY = "role:%d:diner" --- rank -RANK_PVP = "rank:pvp" -RANK_TRADE = "rank:trade" -RANK_TOWER = "rank:tower" -RANK_BOX = "rank:box" -- 盒子舒适度排行榜 -MAP_LIKE = "map:box:like" --点赞个数 -RANK_LEVEL = "rank:level" --等级排名 -RANK_ITEM = "rank:item" --活动物品排行 --- 日志 -NOTE_COOK_KEY = "note:cook:%d" - -TRADE_KEY = "trade:%d" -TRADE_ID_KEY = "tradeIDs" - -TASK_ACTIVE = "task:%d:active" -- 记录激活的任务 -TASK_FINISH = "task:%d:finish" -- 记录完成的任务 - -BOSS_SET = "boss:%d:%d" -BOSS_INFO = "boss:battle" - -FRIEND_KEY = "role:%d:friend" --哈希表 -FRIEND_APPLY_KEY = "role:%d:apply" -- set -FRIEND_DINER_LIKE_KEY = "role:%d:diner:like" -- list - -UNION_SET = "global:union" -UNION_KEY = "union:%d" -UNION_ROLE = "union:%d:%d" -UNION_ROLE_SET = "union:%d:roleList" -UNION_APPLY_SET = "union:%d:applyList" - -PVP_KING = "pvp:king" --王者传奇组 -PVP_HONOR = "pvp:honor" --荣耀咸鱼组 -PVP_NOOB = "pvp:noob" --菜鸟组 -PVP_INFO = "pvp:info" --玩家信息组 \ No newline at end of file + + +R_INCR = "role:%d:autoincr" +R_HEROS = "role:%d:heroIds" +R_HERO = "hero:%d:%d" + +-- -- role +-- R_FARM_KEY = "role:%d:farm" +-- R_TOWER_KEY = "role:%d:tower" +-- R_COOKLOG_KEY = "role:%d:cooklog" +-- R_TRADELOG_KEY = "role:%d:tradelog" +-- R_PVP_KEY = "role:%d:pvp" +-- R_DINER_KEY = "role:%d:diner" +-- -- rank +-- RANK_PVP = "rank:pvp" +-- RANK_TRADE = "rank:trade" +-- RANK_TOWER = "rank:tower" +-- RANK_BOX = "rank:box" -- 盒子舒适度排行榜 +-- MAP_LIKE = "map:box:like" --点赞个数 +-- RANK_LEVEL = "rank:level" --等级排名 +-- RANK_ITEM = "rank:item" --活动物品排行 +-- -- 日志 +-- NOTE_COOK_KEY = "note:cook:%d" + +-- TRADE_KEY = "trade:%d" +-- TRADE_ID_KEY = "tradeIDs" + +-- TASK_ACTIVE = "task:%d:active" -- 记录激活的任务 +-- TASK_FINISH = "task:%d:finish" -- 记录完成的任务 + +-- BOSS_SET = "boss:%d:%d" +-- BOSS_INFO = "boss:battle" + +-- FRIEND_KEY = "role:%d:friend" --哈希表 +-- FRIEND_APPLY_KEY = "role:%d:apply" -- set +-- FRIEND_DINER_LIKE_KEY = "role:%d:diner:like" -- list + +-- UNION_SET = "global:union" +-- UNION_KEY = "union:%d" +-- UNION_ROLE = "union:%d:%d" +-- UNION_ROLE_SET = "union:%d:roleList" +-- UNION_APPLY_SET = "union:%d:applyList" + +-- PVP_KING = "pvp:king" --王者传奇组 +-- PVP_HONOR = "pvp:honor" --荣耀咸鱼组 +-- PVP_NOOB = "pvp:noob" --菜鸟组 +-- PVP_INFO = "pvp:info" --玩家信息组 \ No newline at end of file diff --git a/src/actions/GmAction.lua b/src/actions/GmAction.lua index 168d11c..8189056 100644 --- a/src/actions/GmAction.lua +++ b/src/actions/GmAction.lua @@ -15,4 +15,11 @@ function _M.clientRequest(agent, data) return true end + +function _M.hero(role, pms) + local heroType = tonum(pms.pm1) + role:addHero({type = heroType}) + return "成功" +end + return _M \ No newline at end of file diff --git a/src/actions/HeroAction.lua b/src/actions/HeroAction.lua new file mode 100644 index 0000000..b4408a9 --- /dev/null +++ b/src/actions/HeroAction.lua @@ -0,0 +1,31 @@ +local ipairs = ipairs +local table = table +local math = math +local next = next +local string = string +local redisproxy = redisproxy +local MsgPack = MsgPack +local getRandomName = getRandomName +local mcast_util = mcast_util +local string_format = string.format +local tonumber = tonumber +local require = require +local table_insert = table.insert +local tconcat = table.concat + +local _M = {} +function _M.levelUpRpc( agent, data ) + local role = agent.role + local msg = MsgPack.unpack(data) + local hero = role.heros[msg.id] + if not hero then return end + + if hero:getProperty("level") >= hero:getMaxLevel() then return end + hero:updateProperty({field = "level", delta = 1}) + + SendPacket(actionCodes.Hero_levelUpRpc, '') + return true +end + + +return _M \ No newline at end of file diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index 72e4f6f..1bcfe7d 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -74,7 +74,7 @@ function _M.loginRpc( agent, data ) --维护不能登录 local maintain = tonumber(redisproxy:hget("autoincrement_set", "maintain")) if maintain and maintain > 0 then - if tonumber(redisproxy:hget(string_format("role:%d", roleId), "ignoreMaintain")) ~= 1 then + if tonumber(redisproxy:hget(string_format("role:%d", roleId), "ignoreMt")) ~= 1 then response.result = "MAINTAIN_TIP" SendPacket(actionCodes.Role_loginRpc, MsgPack.pack(response)) return true @@ -99,42 +99,73 @@ function _M.loginRpc( agent, data ) role:reloadWhenLogin() end - -- if not msg.isGMlogin then - -- local banTime = role:getProperty("banTime") - -- if banTime > now then - -- response.result = "BAN_TIP" - -- response.banTime = banTime - -- response.banType = role:getProperty("banType") - -- response.roleId = roleId - -- SendPacket(actionCodes.Role_loginRpc, MsgPack.pack(response)) - -- return true - -- end - -- if banTime ~= 0 then - -- -- 清除封号状态 - -- role:setBan(0) - -- end - -- end + if not msg.isGMlogin then + local banTime = role:getProperty("banTime") + if banTime > now then + response.result = "BAN_TIP" + response.banTime = banTime + response.banType = role:getProperty("banType") + response.roleId = roleId + SendPacket(actionCodes.Role_loginRpc, MsgPack.pack(response)) + return true + end + if banTime ~= 0 then + -- 清除封号状态 + role:setBan(0) + end + end SERV_OPEN = redisproxy:hget("autoincrement_set", "server_start") - local lastLoginTime = role:getProperty("lastLoginTime") + local ltime = role:getProperty("ltime") role:changeStructVersion() -- 数据结构 版本更新 -- 跨天登陆事件 - -- role:onCrossDay(now) - - role:setProperty("lastLoginTime", now) - -- if msg.device and type(msg.device) == "string" then - -- role:setProperty("device", msg.device) - -- end + role:onCrossDay(now) + role:setProperty("ltime", now) + response.role = role:data() response.result = "SUCCESS" response.serverTime = now - response.wave = 1 + local modules = {} + + local heroIds = {} + for heroId, _ in pairs(role.heros) do + table.insert(heroIds, heroId) + end + local heroWave = math.ceil(#heroIds / WAVE_HERO_NUMS) + if #heroIds <= 0 then + heroWave = 0 + table_insert(modules, "heros") + end + + for _, name in ipairs(modules) do + response[name] = {} + for id, unit in pairs(role[name]) do + response[name][id] = unit:data() + end + end + + response.wave = 1 + heroWave SendPacket(actionCodes.Role_loginRpc, MsgPack.pack(response)) + local heroIndex = 1 + for index = 2, 1 + heroWave do + local heroResponse = {heros = {}} + for i = heroIndex, heroIndex + WAVE_HERO_NUMS do + local heroId = heroIds[i] + if not heroId then + break + end + local hero = role.heros[heroId] + table_insert(heroResponse.heros, hero:data()) + heroIndex = heroIndex + 1 + end + heroResponse.heroWave = index + SendPacket(actionCodes.Role_loginRpc, MsgPack.pack(heroResponse)) + end -- role:log("login", { ip = agent.ip, diamond = role:getProperty("diamond"), reDiamond = role:getProperty("reDiamond")}) diff --git a/src/agent.lua b/src/agent.lua index 160f96b..b690959 100644 --- a/src/agent.lua +++ b/src/agent.lua @@ -221,13 +221,13 @@ function CMD.close() local role = agentInfo.role if not role then return end - role:log("logout", {online = skynet.timex()-role:getProperty("lastLoginTime")}) + role:log("logout", {online = skynet.timex()-role:getProperty("ltime")}) role:onOfflineEvent() end function CMD.exit() if agentInfo.role then - -- role:log("logout", {online = skynet.timex()-role:getProperty("lastLoginTime")}) + -- role:log("logout", {online = skynet.timex()-role:getProperty("ltime")}) datacenter.set("agent", agentInfo.role:getProperty("id"), nil) end skynet.exit() diff --git a/src/models/Hero.lua b/src/models/Hero.lua new file mode 100644 index 0000000..654ac87 --- /dev/null +++ b/src/models/Hero.lua @@ -0,0 +1,71 @@ +local Hero = class("Hero", require("shared.ModelBase")) + +Hero.schema = { + key = { "string" }, + id = {"number"}, + type = {"number", 0}, + level = {"number", 1}, -- 等级 +} + +Hero.fields = { + id = true, + type = true, + level = true, +} + +function Hero:ctor( properties ) + Hero.super.ctor(self, properties) +end + +function Hero:notifyUpdateProperty(field, newValue, oldValue) + local updateData = { + id = self:getProperty("id"), + datas = { + { + key = field, + newValue = newValue, + oldValue = oldValue or "", + }, + } + } + + SendPacket(actionCodes.Hero_updateProperty, MsgPack.pack(updateData)) +end + +function Hero:notifyUpdateProperties(params) + local updateData = { + id = self:getProperty("id"), + datas = params + } + + SendPacket(actionCodes.Hero_updateProperty, MsgPack.pack(updateData)) +end + +function Hero:updateProperty(params) + if not params.field or (not params.delta and not params.value) then + return + end + if params.delta then + self:incrProperty(params.field, params.delta) + elseif params.value then + self:setProperty(params.field, params.value) + end + local datas = {} + table.insert(datas, {key = params.field, newValue = self:getProperty(params.field)}) + + self:notifyUpdateProperties(datas) +end + +function Hero:getMaxLevel() + return #csvdb["unit_expCsv"] +end + +function Hero:data() + return { + id = self:getProperty("id"), + type = self:getProperty("type"), + level = self:getProperty("level"), + } +end + +return Hero \ No newline at end of file diff --git a/src/models/Role.lua b/src/models/Role.lua index 74a0998..1434f12 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -12,6 +12,7 @@ RoleChangeStruct.bind(Role) function Role:ctor( properties ) Role.super.ctor(self, properties) self.ignoreHeartbeat = false + self.heros = {} end Role.schema = { @@ -23,9 +24,10 @@ Role.schema = { device = {"string", ""}, banTime = {"number", 0}, banType = {"number", 0}, - lastLoginTime = {"number", 0}, - createTime = {"number", skynet.timex()}, - structVersion = {"number", globalCsv.StructVersion or 0}, -- 重整数据 + ltime = {"number", 0}, -- 最后登录时间 + ctime = {"number", skynet.timex()}, -- 创建时间 + ignoreMt = {"number", 0}, -- 忽略维护拦截 + sversion = {"number", globalCsv.StructVersion or 0}, -- 重整数据版本 -- roleInfo level = {"number", 0}, @@ -42,8 +44,9 @@ Role.fields = { name = true, banTime = true, banType = true, - lastLoginTime = true, - createTime = true, + ltime = true, + ctime = true, + sversion = true, level = true, diamond = true, reDiamond = true, @@ -51,6 +54,52 @@ Role.fields = { } +function Role:notifyUpdateProperty(field, newValue, oldValue, extraValue) + local updateData = { + { + key = field, + newValue = newValue, + oldValue = oldValue or "", + extraValue = extraValue, + } + } + + SendPacket(actionCodes.Role_updateProperty, MsgPack.pack(updateData)) +end + +function Role:updateProperty(params) + params = params or {} + if not self.fields[params.field] then return end + local oldValue = self:getProperty(params.field) + local ret = {key = params.field, oldValue = oldValue} + if params.value then + ret.newValue = params.value + self:setProperty(params.field, params.value) + elseif params.delta then + self:incrProperty(params.field, params.delta) + ret.newValue = self:getProperty(params.field) + else + return + end + if not params.notNotify then + SendPacket(actionCodes.Role_updateProperty, MsgPack.pack({ret})) + end +end + +function Role:updateProperties(params, notNotify) + for field, value in pairs(params) do + self:setProperty(field, value) + end + if not notNotify then + SendPacket(actionCodes.Role_updateProperties, MsgPack.pack(params)) + end +end + +function Role:notifyUpdateProperties(params) + SendPacket(actionCodes.Role_updateProperties, MsgPack.pack(params)) +end + + function Role:data() return { diff --git a/src/models/RoleChangeStruct.lua b/src/models/RoleChangeStruct.lua index 8dd0c97..c5d861b 100644 --- a/src/models/RoleChangeStruct.lua +++ b/src/models/RoleChangeStruct.lua @@ -51,7 +51,7 @@ local RoleChangeStruct = {} function RoleChangeStruct.bind(Role) function Role:changeStructVersion() - local curVersion = self:getProperty("structVersion") + local curVersion = self:getProperty("sversion") if not globalCsv.StructVersion or curVersion >= globalCsv.StructVersion then return end local jumpVersion = {} @@ -99,7 +99,7 @@ function RoleChangeStruct.bind(Role) end end end - self:setProperty("structVersion", globalCsv.StructVersion) + self:setProperty("sversion", globalCsv.StructVersion) end end diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index 6601749..8f57287 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -9,14 +9,78 @@ function RolePlugin.bind(Role) end function Role:loadAll() - + self:loadHeros() end function Role:reloadWhenLogin() + end + + function Role:onCrossDay(now) + + end + + function Role:addHero(params) + local roleId = self:getProperty("id") + local heroId = tonum(redisproxy:hincrby(string.format(R_INCR, roleId), "hero", 1)) + + local heroType = params.type + local unitData = csvdb["unitCsv"][heroType] + redisproxy:sadd(string.format(R_HEROS, roleId), heroId) + + local heroInfo = { + key = string.format(R_HERO, roleId, heroId), + id = heroId, + type= heroType, + } + + local newHero = require("models.Hero").new(heroInfo) + newHero:create() + newHero.owner = self + self.heros[heroId] = newHero + + if not params.notNotify then + local heroResponse = {} + table.insert(heroResponse, newHero:data()) + local bin = MsgPack.pack(heroResponse) + SendPacket(actionCodes.Hero_loadInfos, bin) + end end + function Role:delHero(params) + local roleId = self:getProperty('id') + local hero = self.heros[heroId] + if not hero then return end + + self.heros[heroId] = nil + redisproxy:pipelining(function (red) + red:del(string.format(R_HERO, roleId, heroId)) + red:srem(string.format(R_HEROS, roleId), heroId) + end) + SendPacket(actionCodes.Hero_loadInfos, MsgPack.pack({{id = heroId, bDel = true}})) + end + function Role:loadHeros() + local roleId = self:getProperty("id") + local heroIds = redisproxy:smembers(string.format(R_HEROS, roleId)) + local redret = redisproxy:pipelining(function (red) + for _, heroId in ipairs(heroIds) do + red:hgetall(string.format(R_HERO, roleId, heroId)) + end + end) + for index, heroId in ipairs(heroIds) do + local hero = require("models.Hero").new({key = string.format(R_HERO, roleId, heroId)}) + if hero:load(table.array2Table(redret[index])) then + hero.owner = self + self.heros[tonumber(heroId)] = hero + end + end + end + + -- 发奖功能入口 + function Role:award() + + end end return RolePlugin \ No newline at end of file -- libgit2 0.21.2