Commit 440aa055543a9be39467532389631332a02386c8
1 parent
8474ca36
聊天
Showing
6 changed files
with
190 additions
and
10 deletions
Show diff stats
src/RedisKeys.lua
... | ... | @@ -4,6 +4,7 @@ R_HEROS = "role:%d:heroIds" |
4 | 4 | R_HERO = "hero:%d:%d" |
5 | 5 | R_DAILY = "role:%d:daily" |
6 | 6 | R_DINER = "role:%d:diner" -- 餐厅 |
7 | +R_PVP = "role:%d:pvp" -- pvp | |
7 | 8 | R_EQUIP_ROOT = "role:%d:equip*" -- 装备根目录 |
8 | 9 | R_RUNEIDS = "role:%d:runeIds" -- 玩家拥有符文自增id |
9 | 10 | R_RUNE = "role:%d:rune:%d" -- 符文详细信息 |
... | ... | @@ -15,6 +16,12 @@ RANK_TOWER_INFO = "rank:tower:info" |
15 | 16 | |
16 | 17 | RANK_DINER = {"rank:diner1", "rank:diner2"} -- 餐厅排行榜 两个每天互换 |
17 | 18 | RANK_DINER_INFO = "rank:diner:info" |
19 | + | |
20 | +RANK_PVP_COMMON = "rank:pvpc" | |
21 | +RANK_PVP_INFO_COMMON = "rank:pvpc:info" | |
22 | + | |
23 | +RANK_PVP_HIGHT = "rank:pvph" | |
24 | +RANK_PVP_INFO_HIGHT = "rank:pvph:info" | |
18 | 25 | -- -- role |
19 | 26 | -- R_FARM_KEY = "role:%d:farm" |
20 | 27 | -- R_TOWER_KEY = "role:%d:tower" |
... | ... | @@ -47,6 +54,7 @@ FRIEND_APPLY_KEY = "role:%d:apply" -- sort set 申请列表 |
47 | 54 | FRIEND_BLACK_KEY = "role:%d:black" -- set 黑名单 |
48 | 55 | FRIEND_POINT = "role:%d:point" -- set 当天送给我心的人 |
49 | 56 | FRIEND_RECOMMEND = "friend:recommend" -- sort set 登录排序 获取推荐好友 |
57 | +CHAT_OFFLINE = "chat:offline:%d" --消息离线缓存 | |
50 | 58 | |
51 | 59 | |
52 | 60 | -- FRIEND_DINER_LIKE_KEY = "role:%d:diner:like" -- list | ... | ... |
... | ... | @@ -0,0 +1,74 @@ |
1 | +local ipairs = ipairs | |
2 | +local table = table | |
3 | +local math = math | |
4 | +local redisproxy = redisproxy | |
5 | +local MsgPack = MsgPack | |
6 | + | |
7 | + | |
8 | +local _M = {} | |
9 | + | |
10 | + | |
11 | +function _M.formatCommonRpc(agent , data) | |
12 | + local role = agent.role | |
13 | + local msg = MsgPack.unpack(data) | |
14 | + local pvpFC = role.pvpData:getProperty("pvpFC") | |
15 | + for slot, heroId in pairs(msg.heros) do | |
16 | + if not role.heros[heroId] then | |
17 | + return | |
18 | + end | |
19 | + end | |
20 | + table.clear(pvpFC) | |
21 | + pvpFC.heros = {} | |
22 | + for slot, heroId in pairs(msg.heros) do | |
23 | + pvpFC.heros[slot] = heroId | |
24 | + end | |
25 | + pvpFC.leader = msg.leader | |
26 | + | |
27 | + role.pvpData:updateProperty({field = "pvpFC", value = pvpFC}) | |
28 | + SendPacket(actionCodes.Pvp_formatCommonRpc, '') | |
29 | + return true | |
30 | +end | |
31 | + | |
32 | +function _M.formatHighRpc(agent , data) | |
33 | + local role = agent.role | |
34 | + local msg = MsgPack.unpack(data) | |
35 | + local pvpFH = role.pvpData:getProperty("pvpFH") | |
36 | + | |
37 | + | |
38 | + role.pvpData:updateProperty({field = "pvpFH", value = pvpFH}) | |
39 | + SendPacket(actionCodes.Pvp_formatHighRpc, '') | |
40 | + return true | |
41 | +end | |
42 | + | |
43 | +function _M.refreshMatchRpc(agent, data) | |
44 | + local role = agent.role | |
45 | + local msg = MsgPack.unpack(data) | |
46 | + local pvpData = role.pvpData | |
47 | + pvpData:refreshMatchC() | |
48 | + | |
49 | + SendPacket(actionCodes.Pvp_refreshMatchRpc, '') | |
50 | + return true | |
51 | +end | |
52 | + | |
53 | +function _M.buyCountRpc(agent, data) | |
54 | + local role = agent.role | |
55 | + local msg = MsgPack.unpack(data) | |
56 | + | |
57 | + | |
58 | + SendPacket(actionCodes.Pvp_buyCountRpc, '') | |
59 | + return true | |
60 | +end | |
61 | + | |
62 | +function _M.startBattleRpc(agent, data) | |
63 | + | |
64 | +end | |
65 | + | |
66 | +function _M.endBattleRpc(agent, data) | |
67 | + | |
68 | +end | |
69 | + | |
70 | +function _M.matchListRpc(agent, data) | |
71 | + | |
72 | +end | |
73 | + | |
74 | +return _M | |
0 | 75 | \ No newline at end of file | ... | ... |
src/actions/RoleAction.lua
... | ... | @@ -124,7 +124,7 @@ function _M.loginRpc( agent, data ) |
124 | 124 | role:setProperty("ltime", now) |
125 | 125 | redisproxy:zadd(FRIEND_RECOMMEND, now, roleId) |
126 | 126 | |
127 | - for _, name in ipairs({"dailyData", "dinerData"}) do | |
127 | + for _, name in ipairs({"dailyData", "dinerData", "pvpData"}) do | |
128 | 128 | response[name] = role[name]:data() |
129 | 129 | end |
130 | 130 | |
... | ... | @@ -226,6 +226,7 @@ function _M.loginRpc( agent, data ) |
226 | 226 | msgs = {} |
227 | 227 | end |
228 | 228 | worldChatResponse.worldChats = msgs |
229 | + worldChatResponse.p2pChats = redisproxy:lrange(CHAT_OFFLINE:format(roleId), 0, -1) | |
229 | 230 | worldChatResponse.chatWave = curWave + 1 |
230 | 231 | curWave = curWave + 1 |
231 | 232 | |
... | ... | @@ -647,15 +648,17 @@ function _M.chatRpc(agent, data) |
647 | 648 | end |
648 | 649 | |
649 | 650 | -- 若在线,实时发送聊天信息 |
650 | - local agent = datacenter.get("agent", toRoleId) | |
651 | - if not agent then | |
652 | - result = 2 | |
653 | - return | |
654 | - end | |
651 | + local agent = datacenter.get("agent", objectId) | |
655 | 652 | local bin = MsgPack.pack(response) |
656 | - SendPacket(actionCode, bin, agent.fd) | |
653 | + if agent then | |
654 | + SendPacket(actionCode, bin, agent.fd) | |
655 | + else | |
656 | + redisproxy:pipelining(function(red) | |
657 | + red:rpush(CHAT_OFFLINE:format(objectId), bin) | |
658 | + red:ltrim(CHAT_OFFLINE:format(objectId), 0, 200) | |
659 | + end) | |
660 | + end | |
657 | 661 | SendPacket(actionCode, bin, fromFd) |
658 | - | |
659 | 662 | end, |
660 | 663 | } |
661 | 664 | if not check[cmd] then return end | ... | ... |
src/models/Daily.lua
... | ... | @@ -25,12 +25,16 @@ function Daily:updateProperty(params) |
25 | 25 | |
26 | 26 | if params.delta then |
27 | 27 | self:incrProperty(params.field, params.delta) |
28 | - self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field)) | |
28 | + if not params.notNotify then | |
29 | + self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field)) | |
30 | + end | |
29 | 31 | return true |
30 | 32 | end |
31 | 33 | if params.value then |
32 | 34 | self:setProperty(params.field, params.value) |
33 | - self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field)) | |
35 | + if not params.notNotify then | |
36 | + self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field)) | |
37 | + end | |
34 | 38 | return true |
35 | 39 | end |
36 | 40 | return false | ... | ... |
... | ... | @@ -0,0 +1,76 @@ |
1 | +-- 日常数据 | |
2 | + | |
3 | +local Pvp = class("Pvp", require("shared.ModelBase")) | |
4 | + | |
5 | +function Pvp:ctor(properties) | |
6 | + Pvp.super.ctor(self, properties) | |
7 | +end | |
8 | + | |
9 | +Pvp.schema = { | |
10 | + pvpFC = {"table", {}}, -- pvp 编队普通 | |
11 | + pvpFH = {"table", {}}, -- pvp 编队高级 | |
12 | + matchC = {"table", {}}, -- pvp 匹配的对手 普通 {{t = 1, id = roleId}, {t = 2, id = id}, {t = 2, id = id}} -- t 1 玩家 2 机器人 | |
13 | + matchH = {"table", {}}, -- pvp 匹配的对手 高级 {{t = 1, id = roleId}, {t = 2, id = id}, {t = 2, id = id}} -- t 1 玩家 2 机器人 | |
14 | +} | |
15 | + | |
16 | +function Pvp:updateProperty(params) | |
17 | + if params.delta then | |
18 | + self:incrProperty(params.field, params.delta) | |
19 | + if not params.notNotify then | |
20 | + self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field)) | |
21 | + end | |
22 | + return true | |
23 | + end | |
24 | + if params.value then | |
25 | + self:setProperty(params.field, params.value) | |
26 | + if not params.notNotify then | |
27 | + self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field)) | |
28 | + end | |
29 | + return true | |
30 | + end | |
31 | + return false | |
32 | +end | |
33 | + | |
34 | + | |
35 | + | |
36 | +function Pvp:refreshDailyData(notify) | |
37 | + | |
38 | +end | |
39 | + | |
40 | +function Pvp:rankResetData(notify) | |
41 | + | |
42 | +end | |
43 | + | |
44 | +function Pvp:refreshMatchC(score) | |
45 | + local roleId = self.owner:getProperty("id") | |
46 | + local score = score or redisproxy:zscore(RANK_PVP_COMMON, roleId) | |
47 | + local redret = redisproxy:pipelining(function(red) | |
48 | + | |
49 | + end) | |
50 | +end | |
51 | + | |
52 | + | |
53 | +function Pvp:changeScoreCommon(score) | |
54 | + local roleId = self.owner:getProperty("id") | |
55 | + local newScore = tonumber(redisproxy:ZINCRBY(RANK_PVP_COMMON, score, roleId)) | |
56 | + if newScore < 0 then -- 最低0分 | |
57 | + newScore = 0 | |
58 | + redisproxy:zadd(RANK_PVP_COMMON, 0, roleId) | |
59 | + end | |
60 | + self:refreshMatch(newScore) | |
61 | + return newScore | |
62 | +end | |
63 | + | |
64 | + | |
65 | +function Pvp:save | |
66 | + | |
67 | + | |
68 | + | |
69 | +function Pvp:data() | |
70 | + return { | |
71 | + pvpFC = self:getProperty("pvpFC"), | |
72 | + pvpFH = self:getProperty("pvpFH"), | |
73 | + } | |
74 | +end | |
75 | + | |
76 | +return Pvp | |
0 | 77 | \ No newline at end of file | ... | ... |
src/models/RolePlugin.lua
... | ... | @@ -14,6 +14,7 @@ function RolePlugin.bind(Role) |
14 | 14 | self:loadRunes() |
15 | 15 | self:loadHeros() |
16 | 16 | self:loadDiner() |
17 | + self:loadPvp() | |
17 | 18 | end |
18 | 19 | |
19 | 20 | function Role:reloadWhenLogin() |
... | ... | @@ -31,6 +32,7 @@ function RolePlugin.bind(Role) |
31 | 32 | |
32 | 33 | self.dailyData:refreshDailyData(notify) |
33 | 34 | self.dinerData:refreshDailyData(notify) |
35 | + self.pvpData:refreshDailyData(notify) | |
34 | 36 | self:setProperty("dTask", {}) |
35 | 37 | response.dTask = {} |
36 | 38 | |
... | ... | @@ -71,6 +73,7 @@ function RolePlugin.bind(Role) |
71 | 73 | local response = {} |
72 | 74 | |
73 | 75 | self.dinerData:rankResetData(notify) |
76 | + self.pvpData:rankResetData(notify) | |
74 | 77 | |
75 | 78 | return response |
76 | 79 | end |
... | ... | @@ -430,6 +433,18 @@ function RolePlugin.bind(Role) |
430 | 433 | end |
431 | 434 | end |
432 | 435 | |
436 | + function Role:loadPvp() | |
437 | + local roleId = self:getProperty("id") | |
438 | + local dataKey = string.format(R_PVP, roleId) | |
439 | + self.pvpData = require("models.Pvp").new({key = dataKey}) | |
440 | + self.pvpData.owner = self | |
441 | + if not redisproxy:exists(dataKey) then | |
442 | + self.pvpData:create() | |
443 | + else | |
444 | + self.pvpData:load() | |
445 | + end | |
446 | + end | |
447 | + | |
433 | 448 | function Role:loadEquips() |
434 | 449 | -- 放role 里面了 |
435 | 450 | end | ... | ... |