From c7ecb87fb0756e9da2b2cf935303e0bc854f0265 Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Wed, 4 Mar 2020 14:08:19 +0800 Subject: [PATCH] 添加 测试账号 方法 --- src/actions/HttpAction.lua | 18 ++++++++++++++++++ src/models/Hero.lua | 22 ++++++++++++++++++++++ src/models/RoleCross.lua | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/models/RolePlugin.lua | 6 +++--- src/services/httpweb.lua | 7 +++++++ 5 files changed, 164 insertions(+), 3 deletions(-) diff --git a/src/actions/HttpAction.lua b/src/actions/HttpAction.lua index daed31a..ba92ea4 100644 --- a/src/actions/HttpAction.lua +++ b/src/actions/HttpAction.lua @@ -184,5 +184,23 @@ function _M.gm_action(query) return gmFuncs[query.cmd](role, query) end +function _M.account_init(query, body) + if not query.id or not body or body == "" then return "指令不存在" end + + local ok, result = pcall(json.decode, body) + if not ok or type(result) ~= 'table' then + return "decode body error" + end + query.id = tonumber(query.id) + local agent = datacenter.get("agent", query.id) + if agent and agent.serv then + -- local ok, result = pcall(skynet.call, agent.serv, "role", "accountInit", result) + -- return ok and result or "指令在线失败" + skynet.call(agent.serv, "role", "accountInit", result) + return "成功" + else + return "角色不在线" + end +end return _M \ No newline at end of file diff --git a/src/models/Hero.lua b/src/models/Hero.lua index a1ffa6d..13f497f 100644 --- a/src/models/Hero.lua +++ b/src/models/Hero.lua @@ -44,6 +44,28 @@ function Hero:notifyUpdateProperties(params) SendPacket(actionCodes.Hero_updateProperty, MsgPack.pack(updateData)) end +function Hero:updateProperties(params, notNotify) + self:setProperties(params) + + local check = {level = true, breakL = true, wakeL = true, talent = true, loveL = true, equip = true, rune = true} + local datas = {} + local updateBV = false + for k , v in pairs(params) do + if check[k] then updateBV = true end + table.insert(datas, {key = k, newValue = self:getProperty(k)}) + end + if updateBV then + local orginValue = self:getProperty("battleV") + local curValue = self:saveBattleValue() + if orginValue ~= curValue then + table.insert(datas, { key = "battleV", newValue = curValue }) + end + end + if not notNotify then + self:notifyUpdateProperties(datas) + end +end + function Hero:updateProperty(params) if not params.field or (not params.delta and not params.value) then return diff --git a/src/models/RoleCross.lua b/src/models/RoleCross.lua index d3c1ed9..eb01f5b 100644 --- a/src/models/RoleCross.lua +++ b/src/models/RoleCross.lua @@ -42,6 +42,120 @@ RoleCross.bind = function (Role) return info end + function Role:accountInit(initData) + -- 道具 + local reward = {} + for k , v in pairs(initData.items or {}) do + reward[tonumber(k)] = v + end + self:award(reward) + + -- 英雄 + local breakL = 0 + for i = 0, #csvdb["unit_breakCsv"] do + if initData.heros.level >= csvdb["unit_breakCsv"][i].levelLimit then + breakL = i + else + break + end + end + local equip = "" + for slot, equipId in pairs(initData.heros.equip) do + equip = equip:setv(slot, equipId) + end + + + + for _, heroId in ipairs(initData.heros.ids) do + local hero = self:isHaveHero(heroId) + local status + if not hero then + status, hero = self:addHero({type = heroId}) + else + status = true + end + if status then + local rune = "" + for slot , runeId in pairs(initData.heros.rune) do + slot = tonumber(slot) + local status, rune_ = self:addRune({type = slot, id = runeId}) + if status == 0 then + rune = rune:setv(slot, rune_:getProperty("uid")) + if initData.heros.runeL and initData.heros.runeL > 0 then + rune_:updateProperty({field = "level",value = initData.heros.runeL}) + end + rune_:updateProperty({field = "refer",value = hero:getProperty("id")}) + end + end + local talent = "" + if initData.heros.talent and initData.heros.talent > 0 then + talent = talent:setv(0, initData.heros.talent) + local talentData = csvdb["unit_talentCsv"][initData.heros.talent] + for i = 1, 4 do + talent = talent:setv(i, #talentData) + end + end + local aheadLevel = 0 + for i = 1, initData.heros.talent - 1 do + aheadLevel = aheadLevel + #csvdb["unit_talentCsv"][i] + end + aheadLevel = aheadLevel + talent:getv(1, 0) + + hero:updateProperties({ + level = initData.heros.level, + breakL = breakL, + wakeL = initData.heros.wakeL, + talent = talent, + equip = equip, + rune = rune, + }) + self:checkTaskEnter("Wake", {heroType = heroId, wakeL = initData.heros.wakeL}) + self:checkTaskEnter("WakeCG", {heroType = heroId}) + self:checkTaskEnter("HeroTalent", {heroType = heroId, alv = aheadLevel}) + + end + end + self:checkTaskEnter("HeroLevelUp", {level = initData.heros.level}) + + -- fb + local carbonId = initData.fb + local passCarbon = self:getProperty("hangPass") + local addPre + addPre = function(carbonId) + local carbonData = csvdb["idle_battleCsv"][carbonId] + for _, pre in ipairs(carbonData.prepose:toArray(true, "=")) do + passCarbon[pre] = 1 + self:checkTaskEnter("HangPass", {id = pre}) + addPre(pre) + end + end + passCarbon[carbonId] = 1 + addPre(carbonId) + self:updateProperty({field = "hangPass", value = passCarbon}) + self:checkTaskEnter("HangPass", {id = carbonId}) + + -- talent + if initData.talent and initData.talent > 0 then + local dishTree = self.dinerData:getProperty("dishTree") + for _, v in pairs(csvdb["diner_treeCsv"]) do + for id, _ in pairs(v) do + dishTree = dishTree:setv(id, initData.talent) + end + end + self.dinerData:updateProperty({field = "dishTree", value = dishTree}) + end + -- diner + if initData.diner and initData.diner > 0 then + local buildL = self.dinerData:getProperty("buildL") + for typ, _ in pairs(csvdb["diner_buildingCsv"]) do + buildL = buildL:setv(typ, initData.diner) + end + self.dinerData:updateProperty({field = "buildL", value = buildL}) + end + + return "成功" + end + end diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index e54e490..d65d2ee 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -372,14 +372,14 @@ function RolePlugin.bind(Role) local bin = MsgPack.pack(heroResponse) SendPacket(actionCodes.Hero_loadInfos, bin) end - return true + return true, newHero end function Role:isHaveHero(heroType) if not csvdb["unitCsv"][heroType] then return false end for _, hero in pairs(self.heros) do if hero:getProperty("type") == heroType then - return true + return hero end end end @@ -524,7 +524,7 @@ function RolePlugin.bind(Role) SendPacket(actionCodes.Role_loadRunes, MsgPack.pack(response)) end self:checkTaskEnter("AddRune", {id = params.id, type = params.type, rarity = data.rarity}, params.notNotify) - return 0 + return 0, newRune else return 1 end diff --git a/src/services/httpweb.lua b/src/services/httpweb.lua index bdd37d9..5ec07d4 100644 --- a/src/services/httpweb.lua +++ b/src/services/httpweb.lua @@ -32,6 +32,13 @@ rpcOtherUnion = function(...) end local table = table local string = string +skynet.register_protocol { + name = "role", + id = 13, + pack = skynet.pack, + unpack = skynet.unpack, +} + local port = ... port = tonumber(port) -- libgit2 0.21.2