diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 395d733..b21ed92 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -19,6 +19,7 @@ actionCodes = { Role_updateProperty = 105, Role_updateProperties = 106, Role_updateItems = 107, + Role_changeUpdate = 108, Hero_loadInfos = 201, Hero_updateProperty = 202, @@ -31,6 +32,9 @@ actionCodes = { Hero_commentHeroRpc = 209, Hero_getCommentsRpc = 210, Hero_likeCommentRpc = 211, + Hero_loveItemRpc = 212, + Hero_loveTaskRpc = 213, + Hero_changeSkinRpc = 214, } rpcResponseBegin = 10000 diff --git a/src/actions/HeroAction.lua b/src/actions/HeroAction.lua index 368f6c9..41066db 100644 --- a/src/actions/HeroAction.lua +++ b/src/actions/HeroAction.lua @@ -333,4 +333,75 @@ function _M.likeCommentRpc(agent, data) return true end +function _M.loveItemRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local hero = role.heros[msg.id] + if not hero then return end + local result = {} + local curL = hero:getProperty("loveL") + local curExp = hero:getProperty("loveExp") + local curPlus = csvdb["unit_love_plusCsv"][hero:getProperty("type")] + if not curPlus or curL >= curPlus.limit then return end + + local curEffect = csvdb["unit_love_effectCsv"][curL] + if not curEffect or curExp >= curEffect.loveValue then return end + local delta = 100 -- todo + local newExp = curExp + delta + hero:updateProperty({field = "loveExp", value = newExp}) + if newExp >= curEffect.loveValue then + -- todo 发任务 + end + SendPacket(actionCodes.Hero_loveItemRpc, MsgPack.pack({delta = delta})) + return true +end + +function _M.loveTaskRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local hero = role.heros[msg.id] + if not hero then return end + + local curL = hero:getProperty("loveL") + local curExp = hero:getProperty("loveExp") + local curType = hero:getProperty("type") + local curPlus = csvdb["unit_love_plusCsv"][curType] + if not curPlus or curL >= curPlus.limit then return end + + local curEffect = csvdb["unit_love_effectCsv"][curL] + if not curEffect or curExp < curEffect.loveValue then return end + + local lastEffect = csvdb["unit_love_effectCsv"][curL + 1] + local newExp = curExp - curEffect.loveValue + if lastEffect and curL + 1 < curPlus.limit then + if newExp >= lastEffect.loveValue then + -- todo 发任务 + end + else + newExp = 0 + end + hero:updateProperty({field = "loveExp", value = newExp}) + hero:updateProperty({field = "loveL", value = curL + 1}) + + if role:getProperty("loveStatus"):getv(curType, 0) < curL + 1 then + role:changeUpdates({{type = "loveStatus", field = curType, value = curL + 1}}) -- 总的 + end + + SendPacket(actionCodes.Hero_loveTaskRpc, "") + return true +end + +function _M.changeSkinRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local hero = role.heros[msg.id] + if not hero then return end + local skin = msg.skin + local skinData = csvdb["unit_skinCsv"][hero:getSkinId(skin)] + if not skinData or (skinData.itemId ~= 0 and not role:checkItemEnough({[skinData.itemId] = 1})) then return end + hero:updateProperty({field = "skin", value = skin}) + SendPacket(actionCodes.Hero_changeSkinRpc, "") + return true +end + return _M \ No newline at end of file diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index 6577307..4a1edd0 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -54,7 +54,6 @@ local _M = {} function _M.loginRpc( agent, data ) local msg = MsgPack.unpack(data) local response = {} - -- if msg.version ~= globalCsv.version then -- response.result = "UPDATE_TIP" -- SendPacket(actionCodes.Role_loginRpc, MsgPack.pack(response)) @@ -139,7 +138,7 @@ function _M.loginRpc( agent, data ) table.insert(heroIds, heroId) end local heroWave = math.ceil(#heroIds / WAVE_HERO_NUMS) - if #heroIds <= 0 then + if #heroIds <= 50 then heroWave = 0 table_insert(modules, "heros") end diff --git a/src/models/Hero.lua b/src/models/Hero.lua index 08216f8..d8edd73 100644 --- a/src/models/Hero.lua +++ b/src/models/Hero.lua @@ -13,8 +13,9 @@ Hero.schema = { skillL = {"string", ""}, -- 技能等级 1=1 2=1 3=1 talent = {"string", ""}, -- 0=阶段 1=1 2=1 3=1 4=1 四个天赋当前阶段的等级 阶段默认为1 等级默认为0 battleV = {"number", 0}, -- 保存战斗力 - - + loveExp = {"number", 0}, --好感度经验 + loveL = {"number", 0}, --好感度等级 + skin = {"number", 0}, --皮肤 0 、 1、 2、 3 } Hero.fields = { @@ -25,7 +26,10 @@ Hero.fields = { wakeL = true, skillL = true, talent = true, - battleV = true, + battleV = true, + loveExp = true, + loveL = true, + skin = true, } function Hero:ctor( properties ) @@ -68,7 +72,7 @@ function Hero:updateProperty(params) local datas = {} table.insert(datas, {key = params.field, newValue = self:getProperty(params.field)}) - local check = {level = true, breakL = true, wakeL = true, talent = true} + local check = {level = true, breakL = true, wakeL = true, talent = true, loveL = true, skin = true} if check[params.field] then local orginValue = self:getProperty("battleV") local curValue = self:saveBattleValue() @@ -89,7 +93,10 @@ function Hero:data() wakeL = self:getProperty("wakeL"), skillL = self:getProperty("skillL"), talent = self:getProperty("talent"), - battleV = self:getProperty("battleV"), + battleV = self:getProperty("battleV"), + loveExp = self:getProperty("loveExp"), + loveL = self:getProperty("loveL"), + skin = self:getProperty("skin"), } end diff --git a/src/models/HeroPlugin.lua b/src/models/HeroPlugin.lua index a65b724..171ac38 100644 --- a/src/models/HeroPlugin.lua +++ b/src/models/HeroPlugin.lua @@ -66,9 +66,26 @@ function HeroPlugin.bind(Hero) end end + --好感度 + local loveUp = {} + for i = 0, self:getProperty("loveL") do + local reward = csvdb["unit_love_effectCsv"][i]["reward"] + for attrId, value in pairs(reward:toNumMap()) do + loveUp[AttsEnumEx[attrId]] = (loveUp[AttsEnumEx[attrId]] or 0) + value + end + end + + --皮肤 + local skinUp = {} + local reward = (csvdb["unit_skinCsv"][self:getSkinId()] or {})["reward"] or "" + for attrId, value in pairs(reward:toNumMap()) do + skinUp[AttsEnumEx[attrId]] = (skinUp[AttsEnumEx[attrId]] or 0) + value + end + + --觉醒 local wData = csvdb["unit_wakeCsv"][wakeL] for attr, value in pairs(attrs) do - attrs[attr] = attrs[attr] * (100 + (wData[attr .. "Level"] or 0) + (talentAttrS[attr] or 0)) / 100 + attrs[attr] = attrs[attr] * (100 + (wData[attr .. "Level"] or 0) + (talentAttrS[attr] or 0) + (loveUp[attr] or 0) + (skinUp[attr] or 0)) / 100 end return attrs @@ -98,12 +115,22 @@ function HeroPlugin.bind(Hero) return self:getProperty("skillL"):getv(idx, 1) end - function Hero:getSkillData(idx) - if idx == 1 then - return csvdb["skill_blockCsv"][csvdb["unitCsv"][self:getProperty("type")].block] + function Hero:getSkillData(idx, skin) + local unitData = csvdb["unitCsv"][self:getSkinId(skin)] + if idx == 1 then + return csvdb["skill_blockCsv"][unitData.block] + end + return {} + end + + function Hero:getSkinId(skin) + skin = skin or self:getProperty("skin") + if skin == 0 then + return self:getProperty("type") + else + return 30000 + self:getProperty("type") * 10 + skin + end end - return {} -end end diff --git a/src/models/Role.lua b/src/models/Role.lua index 1434f12..0301289 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -33,7 +33,8 @@ Role.schema = { level = {"number", 0}, diamond = {"number", 0}, reDiamond = {"number", 0}, - items = {"string", ""} + items = {"string", ""}, + loveStatus = {"string", ""}, --统计角色的最高 好感度等级 类型相关 -- type=loveL type=loveL } Role.fields = { @@ -51,6 +52,7 @@ Role.fields = { diamond = true, reDiamond = true, items = true, + loveStatus = true, } @@ -99,7 +101,27 @@ function Role:notifyUpdateProperties(params) SendPacket(actionCodes.Role_updateProperties, MsgPack.pack(params)) end +-- 某些字段更新改变量 改变量的定义由字段自身决定 {{type = ""}, } +function Role:changeUpdates(params, notNotify) + local changeUpdateFunc = { + ["loveStatus"] = function(info) + self:setProperty("loveStatus", self:getProperty("loveStatus"):setv(info["field"], info["value"])) + return {type = "loveStatus", field = info["field"], value = info["value"]} + end, + } + local updates = {} + for _, one in ipairs(params) do + if changeUpdateFunc[one["type"]] then + table.insert(updates, changeUpdateFunc[one["type"]](one)) + else + print("need handler for changeUpdate type : " .. params["type"]) + end + end + if not notNotify and next(updates) then + SendPacket(actionCodes.Role_changeUpdate, MsgPack.pack(updates)) + end +end function Role:data() return { @@ -109,7 +131,7 @@ function Role:data() diamond = self:getProperty("diamond"), reDiamond = self:getProperty("reDiamond"), items = self:getProperty("items"):toNumMap(), - + loveStatus = self:getProperty("loveStatus"):toNumMap(), } end -- libgit2 0.21.2