Commit 0a07bdd981c3ccb5305c53746d63f284ca5ac78b

Authored by zhouahaihai
1 parent 6871f4f6

角色升级 。gm

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