Commit 6947e3822b951e2814d8eedff33bc68f93e61234
1 parent
188558e8
好感度, 皮肤
Showing
6 changed files
with
145 additions
and
15 deletions
Show diff stats
src/ProtocolCode.lua
... | ... | @@ -19,6 +19,7 @@ actionCodes = { |
19 | 19 | Role_updateProperty = 105, |
20 | 20 | Role_updateProperties = 106, |
21 | 21 | Role_updateItems = 107, |
22 | + Role_changeUpdate = 108, | |
22 | 23 | |
23 | 24 | Hero_loadInfos = 201, |
24 | 25 | Hero_updateProperty = 202, |
... | ... | @@ -31,6 +32,9 @@ actionCodes = { |
31 | 32 | Hero_commentHeroRpc = 209, |
32 | 33 | Hero_getCommentsRpc = 210, |
33 | 34 | Hero_likeCommentRpc = 211, |
35 | + Hero_loveItemRpc = 212, | |
36 | + Hero_loveTaskRpc = 213, | |
37 | + Hero_changeSkinRpc = 214, | |
34 | 38 | } |
35 | 39 | |
36 | 40 | rpcResponseBegin = 10000 | ... | ... |
src/actions/HeroAction.lua
... | ... | @@ -333,4 +333,75 @@ function _M.likeCommentRpc(agent, data) |
333 | 333 | return true |
334 | 334 | end |
335 | 335 | |
336 | +function _M.loveItemRpc(agent, data) | |
337 | + local role = agent.role | |
338 | + local msg = MsgPack.unpack(data) | |
339 | + local hero = role.heros[msg.id] | |
340 | + if not hero then return end | |
341 | + local result = {} | |
342 | + local curL = hero:getProperty("loveL") | |
343 | + local curExp = hero:getProperty("loveExp") | |
344 | + local curPlus = csvdb["unit_love_plusCsv"][hero:getProperty("type")] | |
345 | + if not curPlus or curL >= curPlus.limit then return end | |
346 | + | |
347 | + local curEffect = csvdb["unit_love_effectCsv"][curL] | |
348 | + if not curEffect or curExp >= curEffect.loveValue then return end | |
349 | + local delta = 100 -- todo | |
350 | + local newExp = curExp + delta | |
351 | + hero:updateProperty({field = "loveExp", value = newExp}) | |
352 | + if newExp >= curEffect.loveValue then | |
353 | + -- todo 发任务 | |
354 | + end | |
355 | + SendPacket(actionCodes.Hero_loveItemRpc, MsgPack.pack({delta = delta})) | |
356 | + return true | |
357 | +end | |
358 | + | |
359 | +function _M.loveTaskRpc(agent, data) | |
360 | + local role = agent.role | |
361 | + local msg = MsgPack.unpack(data) | |
362 | + local hero = role.heros[msg.id] | |
363 | + if not hero then return end | |
364 | + | |
365 | + local curL = hero:getProperty("loveL") | |
366 | + local curExp = hero:getProperty("loveExp") | |
367 | + local curType = hero:getProperty("type") | |
368 | + local curPlus = csvdb["unit_love_plusCsv"][curType] | |
369 | + if not curPlus or curL >= curPlus.limit then return end | |
370 | + | |
371 | + local curEffect = csvdb["unit_love_effectCsv"][curL] | |
372 | + if not curEffect or curExp < curEffect.loveValue then return end | |
373 | + | |
374 | + local lastEffect = csvdb["unit_love_effectCsv"][curL + 1] | |
375 | + local newExp = curExp - curEffect.loveValue | |
376 | + if lastEffect and curL + 1 < curPlus.limit then | |
377 | + if newExp >= lastEffect.loveValue then | |
378 | + -- todo 发任务 | |
379 | + end | |
380 | + else | |
381 | + newExp = 0 | |
382 | + end | |
383 | + hero:updateProperty({field = "loveExp", value = newExp}) | |
384 | + hero:updateProperty({field = "loveL", value = curL + 1}) | |
385 | + | |
386 | + if role:getProperty("loveStatus"):getv(curType, 0) < curL + 1 then | |
387 | + role:changeUpdates({{type = "loveStatus", field = curType, value = curL + 1}}) -- 总的 | |
388 | + end | |
389 | + | |
390 | + SendPacket(actionCodes.Hero_loveTaskRpc, "") | |
391 | + return true | |
392 | +end | |
393 | + | |
394 | +function _M.changeSkinRpc(agent, data) | |
395 | + local role = agent.role | |
396 | + local msg = MsgPack.unpack(data) | |
397 | + local hero = role.heros[msg.id] | |
398 | + if not hero then return end | |
399 | + local skin = msg.skin | |
400 | + local skinData = csvdb["unit_skinCsv"][hero:getSkinId(skin)] | |
401 | + if not skinData or (skinData.itemId ~= 0 and not role:checkItemEnough({[skinData.itemId] = 1})) then return end | |
402 | + hero:updateProperty({field = "skin", value = skin}) | |
403 | + SendPacket(actionCodes.Hero_changeSkinRpc, "") | |
404 | + return true | |
405 | +end | |
406 | + | |
336 | 407 | return _M |
337 | 408 | \ No newline at end of file | ... | ... |
src/actions/RoleAction.lua
... | ... | @@ -54,7 +54,6 @@ local _M = {} |
54 | 54 | function _M.loginRpc( agent, data ) |
55 | 55 | local msg = MsgPack.unpack(data) |
56 | 56 | local response = {} |
57 | - | |
58 | 57 | -- if msg.version ~= globalCsv.version then |
59 | 58 | -- response.result = "UPDATE_TIP" |
60 | 59 | -- SendPacket(actionCodes.Role_loginRpc, MsgPack.pack(response)) |
... | ... | @@ -139,7 +138,7 @@ function _M.loginRpc( agent, data ) |
139 | 138 | table.insert(heroIds, heroId) |
140 | 139 | end |
141 | 140 | local heroWave = math.ceil(#heroIds / WAVE_HERO_NUMS) |
142 | - if #heroIds <= 0 then | |
141 | + if #heroIds <= 50 then | |
143 | 142 | heroWave = 0 |
144 | 143 | table_insert(modules, "heros") |
145 | 144 | end | ... | ... |
src/models/Hero.lua
... | ... | @@ -13,8 +13,9 @@ Hero.schema = { |
13 | 13 | skillL = {"string", ""}, -- 技能等级 1=1 2=1 3=1 |
14 | 14 | talent = {"string", ""}, -- 0=阶段 1=1 2=1 3=1 4=1 四个天赋当前阶段的等级 阶段默认为1 等级默认为0 |
15 | 15 | battleV = {"number", 0}, -- 保存战斗力 |
16 | - | |
17 | - | |
16 | + loveExp = {"number", 0}, --好感度经验 | |
17 | + loveL = {"number", 0}, --好感度等级 | |
18 | + skin = {"number", 0}, --皮肤 0 、 1、 2、 3 | |
18 | 19 | } |
19 | 20 | |
20 | 21 | Hero.fields = { |
... | ... | @@ -25,7 +26,10 @@ Hero.fields = { |
25 | 26 | wakeL = true, |
26 | 27 | skillL = true, |
27 | 28 | talent = true, |
28 | - battleV = true, | |
29 | + battleV = true, | |
30 | + loveExp = true, | |
31 | + loveL = true, | |
32 | + skin = true, | |
29 | 33 | } |
30 | 34 | |
31 | 35 | function Hero:ctor( properties ) |
... | ... | @@ -68,7 +72,7 @@ function Hero:updateProperty(params) |
68 | 72 | local datas = {} |
69 | 73 | table.insert(datas, {key = params.field, newValue = self:getProperty(params.field)}) |
70 | 74 | |
71 | - local check = {level = true, breakL = true, wakeL = true, talent = true} | |
75 | + local check = {level = true, breakL = true, wakeL = true, talent = true, loveL = true, skin = true} | |
72 | 76 | if check[params.field] then |
73 | 77 | local orginValue = self:getProperty("battleV") |
74 | 78 | local curValue = self:saveBattleValue() |
... | ... | @@ -89,7 +93,10 @@ function Hero:data() |
89 | 93 | wakeL = self:getProperty("wakeL"), |
90 | 94 | skillL = self:getProperty("skillL"), |
91 | 95 | talent = self:getProperty("talent"), |
92 | - battleV = self:getProperty("battleV"), | |
96 | + battleV = self:getProperty("battleV"), | |
97 | + loveExp = self:getProperty("loveExp"), | |
98 | + loveL = self:getProperty("loveL"), | |
99 | + skin = self:getProperty("skin"), | |
93 | 100 | } |
94 | 101 | end |
95 | 102 | ... | ... |
src/models/HeroPlugin.lua
... | ... | @@ -66,9 +66,26 @@ function HeroPlugin.bind(Hero) |
66 | 66 | end |
67 | 67 | end |
68 | 68 | |
69 | + --好感度 | |
70 | + local loveUp = {} | |
71 | + for i = 0, self:getProperty("loveL") do | |
72 | + local reward = csvdb["unit_love_effectCsv"][i]["reward"] | |
73 | + for attrId, value in pairs(reward:toNumMap()) do | |
74 | + loveUp[AttsEnumEx[attrId]] = (loveUp[AttsEnumEx[attrId]] or 0) + value | |
75 | + end | |
76 | + end | |
77 | + | |
78 | + --皮肤 | |
79 | + local skinUp = {} | |
80 | + local reward = (csvdb["unit_skinCsv"][self:getSkinId()] or {})["reward"] or "" | |
81 | + for attrId, value in pairs(reward:toNumMap()) do | |
82 | + skinUp[AttsEnumEx[attrId]] = (skinUp[AttsEnumEx[attrId]] or 0) + value | |
83 | + end | |
84 | + | |
85 | + --觉醒 | |
69 | 86 | local wData = csvdb["unit_wakeCsv"][wakeL] |
70 | 87 | for attr, value in pairs(attrs) do |
71 | - attrs[attr] = attrs[attr] * (100 + (wData[attr .. "Level"] or 0) + (talentAttrS[attr] or 0)) / 100 | |
88 | + attrs[attr] = attrs[attr] * (100 + (wData[attr .. "Level"] or 0) + (talentAttrS[attr] or 0) + (loveUp[attr] or 0) + (skinUp[attr] or 0)) / 100 | |
72 | 89 | end |
73 | 90 | |
74 | 91 | return attrs |
... | ... | @@ -98,12 +115,22 @@ function HeroPlugin.bind(Hero) |
98 | 115 | return self:getProperty("skillL"):getv(idx, 1) |
99 | 116 | end |
100 | 117 | |
101 | - function Hero:getSkillData(idx) | |
102 | - if idx == 1 then | |
103 | - return csvdb["skill_blockCsv"][csvdb["unitCsv"][self:getProperty("type")].block] | |
118 | + function Hero:getSkillData(idx, skin) | |
119 | + local unitData = csvdb["unitCsv"][self:getSkinId(skin)] | |
120 | + if idx == 1 then | |
121 | + return csvdb["skill_blockCsv"][unitData.block] | |
122 | + end | |
123 | + return {} | |
124 | + end | |
125 | + | |
126 | + function Hero:getSkinId(skin) | |
127 | + skin = skin or self:getProperty("skin") | |
128 | + if skin == 0 then | |
129 | + return self:getProperty("type") | |
130 | + else | |
131 | + return 30000 + self:getProperty("type") * 10 + skin | |
132 | + end | |
104 | 133 | end |
105 | - return {} | |
106 | -end | |
107 | 134 | |
108 | 135 | end |
109 | 136 | ... | ... |
src/models/Role.lua
... | ... | @@ -33,7 +33,8 @@ Role.schema = { |
33 | 33 | level = {"number", 0}, |
34 | 34 | diamond = {"number", 0}, |
35 | 35 | reDiamond = {"number", 0}, |
36 | - items = {"string", ""} | |
36 | + items = {"string", ""}, | |
37 | + loveStatus = {"string", ""}, --统计角色的最高 好感度等级 类型相关 -- type=loveL type=loveL | |
37 | 38 | } |
38 | 39 | |
39 | 40 | Role.fields = { |
... | ... | @@ -51,6 +52,7 @@ Role.fields = { |
51 | 52 | diamond = true, |
52 | 53 | reDiamond = true, |
53 | 54 | items = true, |
55 | + loveStatus = true, | |
54 | 56 | } |
55 | 57 | |
56 | 58 | |
... | ... | @@ -99,7 +101,27 @@ function Role:notifyUpdateProperties(params) |
99 | 101 | SendPacket(actionCodes.Role_updateProperties, MsgPack.pack(params)) |
100 | 102 | end |
101 | 103 | |
104 | +-- 某些字段更新改变量 改变量的定义由字段自身决定 {{type = ""}, } | |
105 | +function Role:changeUpdates(params, notNotify) | |
106 | + local changeUpdateFunc = { | |
107 | + ["loveStatus"] = function(info) | |
108 | + self:setProperty("loveStatus", self:getProperty("loveStatus"):setv(info["field"], info["value"])) | |
109 | + return {type = "loveStatus", field = info["field"], value = info["value"]} | |
110 | + end, | |
111 | + } | |
102 | 112 | |
113 | + local updates = {} | |
114 | + for _, one in ipairs(params) do | |
115 | + if changeUpdateFunc[one["type"]] then | |
116 | + table.insert(updates, changeUpdateFunc[one["type"]](one)) | |
117 | + else | |
118 | + print("need handler for changeUpdate type : " .. params["type"]) | |
119 | + end | |
120 | + end | |
121 | + if not notNotify and next(updates) then | |
122 | + SendPacket(actionCodes.Role_changeUpdate, MsgPack.pack(updates)) | |
123 | + end | |
124 | +end | |
103 | 125 | |
104 | 126 | function Role:data() |
105 | 127 | return { |
... | ... | @@ -109,7 +131,7 @@ function Role:data() |
109 | 131 | diamond = self:getProperty("diamond"), |
110 | 132 | reDiamond = self:getProperty("reDiamond"), |
111 | 133 | items = self:getProperty("items"):toNumMap(), |
112 | - | |
134 | + loveStatus = self:getProperty("loveStatus"):toNumMap(), | |
113 | 135 | } |
114 | 136 | end |
115 | 137 | ... | ... |