Commit c7ecb87fb0756e9da2b2cf935303e0bc854f0265
1 parent
1313eac0
添加 测试账号 方法
Showing
5 changed files
with
164 additions
and
3 deletions
Show diff stats
src/actions/HttpAction.lua
@@ -184,5 +184,23 @@ function _M.gm_action(query) | @@ -184,5 +184,23 @@ function _M.gm_action(query) | ||
184 | return gmFuncs[query.cmd](role, query) | 184 | return gmFuncs[query.cmd](role, query) |
185 | end | 185 | end |
186 | 186 | ||
187 | +function _M.account_init(query, body) | ||
188 | + if not query.id or not body or body == "" then return "指令不存在" end | ||
189 | + | ||
190 | + local ok, result = pcall(json.decode, body) | ||
191 | + if not ok or type(result) ~= 'table' then | ||
192 | + return "decode body error" | ||
193 | + end | ||
194 | + query.id = tonumber(query.id) | ||
195 | + local agent = datacenter.get("agent", query.id) | ||
196 | + if agent and agent.serv then | ||
197 | + -- local ok, result = pcall(skynet.call, agent.serv, "role", "accountInit", result) | ||
198 | + -- return ok and result or "指令在线失败" | ||
199 | + skynet.call(agent.serv, "role", "accountInit", result) | ||
200 | + return "成功" | ||
201 | + else | ||
202 | + return "角色不在线" | ||
203 | + end | ||
204 | +end | ||
187 | 205 | ||
188 | return _M | 206 | return _M |
189 | \ No newline at end of file | 207 | \ No newline at end of file |
src/models/Hero.lua
@@ -44,6 +44,28 @@ function Hero:notifyUpdateProperties(params) | @@ -44,6 +44,28 @@ function Hero:notifyUpdateProperties(params) | ||
44 | SendPacket(actionCodes.Hero_updateProperty, MsgPack.pack(updateData)) | 44 | SendPacket(actionCodes.Hero_updateProperty, MsgPack.pack(updateData)) |
45 | end | 45 | end |
46 | 46 | ||
47 | +function Hero:updateProperties(params, notNotify) | ||
48 | + self:setProperties(params) | ||
49 | + | ||
50 | + local check = {level = true, breakL = true, wakeL = true, talent = true, loveL = true, equip = true, rune = true} | ||
51 | + local datas = {} | ||
52 | + local updateBV = false | ||
53 | + for k , v in pairs(params) do | ||
54 | + if check[k] then updateBV = true end | ||
55 | + table.insert(datas, {key = k, newValue = self:getProperty(k)}) | ||
56 | + end | ||
57 | + if updateBV then | ||
58 | + local orginValue = self:getProperty("battleV") | ||
59 | + local curValue = self:saveBattleValue() | ||
60 | + if orginValue ~= curValue then | ||
61 | + table.insert(datas, { key = "battleV", newValue = curValue }) | ||
62 | + end | ||
63 | + end | ||
64 | + if not notNotify then | ||
65 | + self:notifyUpdateProperties(datas) | ||
66 | + end | ||
67 | +end | ||
68 | + | ||
47 | function Hero:updateProperty(params) | 69 | function Hero:updateProperty(params) |
48 | if not params.field or (not params.delta and not params.value) then | 70 | if not params.field or (not params.delta and not params.value) then |
49 | return | 71 | return |
src/models/RoleCross.lua
@@ -42,6 +42,120 @@ RoleCross.bind = function (Role) | @@ -42,6 +42,120 @@ RoleCross.bind = function (Role) | ||
42 | return info | 42 | return info |
43 | end | 43 | end |
44 | 44 | ||
45 | + function Role:accountInit(initData) | ||
46 | + -- 道具 | ||
47 | + local reward = {} | ||
48 | + for k , v in pairs(initData.items or {}) do | ||
49 | + reward[tonumber(k)] = v | ||
50 | + end | ||
51 | + self:award(reward) | ||
52 | + | ||
53 | + -- 英雄 | ||
54 | + local breakL = 0 | ||
55 | + for i = 0, #csvdb["unit_breakCsv"] do | ||
56 | + if initData.heros.level >= csvdb["unit_breakCsv"][i].levelLimit then | ||
57 | + breakL = i | ||
58 | + else | ||
59 | + break | ||
60 | + end | ||
61 | + end | ||
62 | + local equip = "" | ||
63 | + for slot, equipId in pairs(initData.heros.equip) do | ||
64 | + equip = equip:setv(slot, equipId) | ||
65 | + end | ||
66 | + | ||
67 | + | ||
68 | + | ||
69 | + for _, heroId in ipairs(initData.heros.ids) do | ||
70 | + local hero = self:isHaveHero(heroId) | ||
71 | + local status | ||
72 | + if not hero then | ||
73 | + status, hero = self:addHero({type = heroId}) | ||
74 | + else | ||
75 | + status = true | ||
76 | + end | ||
77 | + if status then | ||
78 | + local rune = "" | ||
79 | + for slot , runeId in pairs(initData.heros.rune) do | ||
80 | + slot = tonumber(slot) | ||
81 | + local status, rune_ = self:addRune({type = slot, id = runeId}) | ||
82 | + if status == 0 then | ||
83 | + rune = rune:setv(slot, rune_:getProperty("uid")) | ||
84 | + if initData.heros.runeL and initData.heros.runeL > 0 then | ||
85 | + rune_:updateProperty({field = "level",value = initData.heros.runeL}) | ||
86 | + end | ||
87 | + rune_:updateProperty({field = "refer",value = hero:getProperty("id")}) | ||
88 | + end | ||
89 | + end | ||
90 | + local talent = "" | ||
91 | + if initData.heros.talent and initData.heros.talent > 0 then | ||
92 | + talent = talent:setv(0, initData.heros.talent) | ||
93 | + local talentData = csvdb["unit_talentCsv"][initData.heros.talent] | ||
94 | + for i = 1, 4 do | ||
95 | + talent = talent:setv(i, #talentData) | ||
96 | + end | ||
97 | + end | ||
98 | + local aheadLevel = 0 | ||
99 | + for i = 1, initData.heros.talent - 1 do | ||
100 | + aheadLevel = aheadLevel + #csvdb["unit_talentCsv"][i] | ||
101 | + end | ||
102 | + aheadLevel = aheadLevel + talent:getv(1, 0) | ||
103 | + | ||
104 | + hero:updateProperties({ | ||
105 | + level = initData.heros.level, | ||
106 | + breakL = breakL, | ||
107 | + wakeL = initData.heros.wakeL, | ||
108 | + talent = talent, | ||
109 | + equip = equip, | ||
110 | + rune = rune, | ||
111 | + }) | ||
112 | + self:checkTaskEnter("Wake", {heroType = heroId, wakeL = initData.heros.wakeL}) | ||
113 | + self:checkTaskEnter("WakeCG", {heroType = heroId}) | ||
114 | + self:checkTaskEnter("HeroTalent", {heroType = heroId, alv = aheadLevel}) | ||
115 | + | ||
116 | + end | ||
117 | + end | ||
118 | + self:checkTaskEnter("HeroLevelUp", {level = initData.heros.level}) | ||
119 | + | ||
120 | + -- fb | ||
121 | + local carbonId = initData.fb | ||
122 | + local passCarbon = self:getProperty("hangPass") | ||
123 | + local addPre | ||
124 | + addPre = function(carbonId) | ||
125 | + local carbonData = csvdb["idle_battleCsv"][carbonId] | ||
126 | + for _, pre in ipairs(carbonData.prepose:toArray(true, "=")) do | ||
127 | + passCarbon[pre] = 1 | ||
128 | + self:checkTaskEnter("HangPass", {id = pre}) | ||
129 | + addPre(pre) | ||
130 | + end | ||
131 | + end | ||
132 | + passCarbon[carbonId] = 1 | ||
133 | + addPre(carbonId) | ||
134 | + self:updateProperty({field = "hangPass", value = passCarbon}) | ||
135 | + self:checkTaskEnter("HangPass", {id = carbonId}) | ||
136 | + | ||
137 | + -- talent | ||
138 | + if initData.talent and initData.talent > 0 then | ||
139 | + local dishTree = self.dinerData:getProperty("dishTree") | ||
140 | + for _, v in pairs(csvdb["diner_treeCsv"]) do | ||
141 | + for id, _ in pairs(v) do | ||
142 | + dishTree = dishTree:setv(id, initData.talent) | ||
143 | + end | ||
144 | + end | ||
145 | + self.dinerData:updateProperty({field = "dishTree", value = dishTree}) | ||
146 | + end | ||
147 | + -- diner | ||
148 | + if initData.diner and initData.diner > 0 then | ||
149 | + local buildL = self.dinerData:getProperty("buildL") | ||
150 | + for typ, _ in pairs(csvdb["diner_buildingCsv"]) do | ||
151 | + buildL = buildL:setv(typ, initData.diner) | ||
152 | + end | ||
153 | + self.dinerData:updateProperty({field = "buildL", value = buildL}) | ||
154 | + end | ||
155 | + | ||
156 | + return "成功" | ||
157 | + end | ||
158 | + | ||
45 | end | 159 | end |
46 | 160 | ||
47 | 161 |
src/models/RolePlugin.lua
@@ -372,14 +372,14 @@ function RolePlugin.bind(Role) | @@ -372,14 +372,14 @@ function RolePlugin.bind(Role) | ||
372 | local bin = MsgPack.pack(heroResponse) | 372 | local bin = MsgPack.pack(heroResponse) |
373 | SendPacket(actionCodes.Hero_loadInfos, bin) | 373 | SendPacket(actionCodes.Hero_loadInfos, bin) |
374 | end | 374 | end |
375 | - return true | 375 | + return true, newHero |
376 | end | 376 | end |
377 | 377 | ||
378 | function Role:isHaveHero(heroType) | 378 | function Role:isHaveHero(heroType) |
379 | if not csvdb["unitCsv"][heroType] then return false end | 379 | if not csvdb["unitCsv"][heroType] then return false end |
380 | for _, hero in pairs(self.heros) do | 380 | for _, hero in pairs(self.heros) do |
381 | if hero:getProperty("type") == heroType then | 381 | if hero:getProperty("type") == heroType then |
382 | - return true | 382 | + return hero |
383 | end | 383 | end |
384 | end | 384 | end |
385 | end | 385 | end |
@@ -524,7 +524,7 @@ function RolePlugin.bind(Role) | @@ -524,7 +524,7 @@ function RolePlugin.bind(Role) | ||
524 | SendPacket(actionCodes.Role_loadRunes, MsgPack.pack(response)) | 524 | SendPacket(actionCodes.Role_loadRunes, MsgPack.pack(response)) |
525 | end | 525 | end |
526 | self:checkTaskEnter("AddRune", {id = params.id, type = params.type, rarity = data.rarity}, params.notNotify) | 526 | self:checkTaskEnter("AddRune", {id = params.id, type = params.type, rarity = data.rarity}, params.notNotify) |
527 | - return 0 | 527 | + return 0, newRune |
528 | else | 528 | else |
529 | return 1 | 529 | return 1 |
530 | end | 530 | end |
src/services/httpweb.lua
@@ -32,6 +32,13 @@ rpcOtherUnion = function(...) end | @@ -32,6 +32,13 @@ rpcOtherUnion = function(...) end | ||
32 | local table = table | 32 | local table = table |
33 | local string = string | 33 | local string = string |
34 | 34 | ||
35 | +skynet.register_protocol { | ||
36 | + name = "role", | ||
37 | + id = 13, | ||
38 | + pack = skynet.pack, | ||
39 | + unpack = skynet.unpack, | ||
40 | +} | ||
41 | + | ||
35 | local port = ... | 42 | local port = ... |
36 | port = tonumber(port) | 43 | port = tonumber(port) |
37 | 44 |