Commit 12f7b52c5dc6dbe5f797fb2cce19d69bfa7220a4
1 parent
de3b786f
冒险战斗
Showing
5 changed files
with
105 additions
and
37 deletions
Show diff stats
src/ProtocolCode.lua
| @@ -35,6 +35,8 @@ actionCodes = { | @@ -35,6 +35,8 @@ actionCodes = { | ||
| 35 | Adv_useItemRpc = 154, | 35 | Adv_useItemRpc = 154, |
| 36 | Adv_usePotionRpc = 155, | 36 | Adv_usePotionRpc = 155, |
| 37 | Adv_exitAdvRpc = 156, | 37 | Adv_exitAdvRpc = 156, |
| 38 | + Adv_startBattleRpc = 157, | ||
| 39 | + Adv_endBattleRpc = 158, | ||
| 38 | 40 | ||
| 39 | Hero_loadInfos = 201, | 41 | Hero_loadInfos = 201, |
| 40 | Hero_updateProperty = 202, | 42 | Hero_updateProperty = 202, |
src/actions/AdvAction.lua
| @@ -100,5 +100,59 @@ function _M.exitAdvRpc(agent, data) | @@ -100,5 +100,59 @@ function _M.exitAdvRpc(agent, data) | ||
| 100 | return true | 100 | return true |
| 101 | end | 101 | end |
| 102 | 102 | ||
| 103 | +--开始战斗 | ||
| 104 | +function _M.startBattleRpc(agent, data) | ||
| 105 | + local role = agent.role | ||
| 106 | + local msg = MsgPack.unpack(data) | ||
| 107 | + | ||
| 108 | + -- 校验一下信息 | ||
| 109 | + local roomId = msg.roomId | ||
| 110 | + local blockId = msg.blockId | ||
| 111 | + local monsterId = msg.monsterId | ||
| 112 | + local enemyId = msg.enemyId | ||
| 113 | + if not enemyId then return end | ||
| 114 | + | ||
| 115 | + local adv = role:getAdvData() | ||
| 116 | + local enemy = adv.battle:getEnemyById(enemyId) | ||
| 117 | + | ||
| 118 | + if enemy.monsterId ~= monsterId or enemy.roomId ~= roomId or enemy.blockId ~= blockId or enemy.lock or enemy.isDead then return end | ||
| 119 | + | ||
| 120 | + local key = tostring(math.random()) | ||
| 121 | + adv.__battleCache = { | ||
| 122 | + enemyId = enemyId, | ||
| 123 | + key = key | ||
| 124 | + } | ||
| 125 | + SendPacket(actionCodes.Adv_startBattleRpc, MsgPack.pack({key = key})) | ||
| 126 | + return true | ||
| 127 | +end | ||
| 128 | + | ||
| 129 | +-- 结束战斗 | ||
| 130 | +function _M.endBattleRpc(agent, data) | ||
| 131 | + local role = agent.role | ||
| 132 | + local msg = MsgPack.unpack(data) | ||
| 133 | + local roomId = msg.roomId | ||
| 134 | + local blockId = msg.blockId | ||
| 135 | + local monsterId = msg.monsterId | ||
| 136 | + local enemyId = msg.enemyId | ||
| 137 | + local key = msg.key | ||
| 138 | + local player = msg.player | ||
| 139 | + | ||
| 140 | + if not player or not player.hp or not player.sp or not enemyId or not key then return end | ||
| 141 | + local adv = role:getAdvData() | ||
| 142 | + -- 校验 | ||
| 143 | + if not adv.__battleCache then return end | ||
| 144 | + if adv.__battleCache.enemyId ~= enemyId then return end | ||
| 145 | + local enemy = adv.battle:getEnemyById(enemyId) | ||
| 146 | + if enemy.monsterId ~= monsterId or enemy.roomId ~= roomId or enemy.blockId ~= blockId then return end | ||
| 147 | + adv.__battleCache = nil | ||
| 148 | + | ||
| 149 | + | ||
| 150 | + local status = adv:clickBlock(roomId, blockId, {player = player}) | ||
| 151 | + if not status then return end | ||
| 152 | + SendPacket(actionCodes.Adv_endBattleRpc, MsgPack.pack({events = adv:popBackEvents()})) | ||
| 153 | + return true | ||
| 154 | +end | ||
| 155 | + | ||
| 156 | + | ||
| 103 | 157 | ||
| 104 | return _M | 158 | return _M |
| 105 | \ No newline at end of file | 159 | \ No newline at end of file |
src/adv/Adv.lua
| @@ -720,7 +720,7 @@ end | @@ -720,7 +720,7 @@ end | ||
| 720 | 720 | ||
| 721 | --战斗 普通攻击 | 721 | --战斗 普通攻击 |
| 722 | local function clickMonster(self, room, block, params) | 722 | local function clickMonster(self, room, block, params) |
| 723 | - self.battle:battleBegin(room.roomId, block.blockId, params.quick) | 723 | + self.battle:battleBegin(room.roomId, block.blockId, params) |
| 724 | return true | 724 | return true |
| 725 | end | 725 | end |
| 726 | 726 | ||
| @@ -933,9 +933,6 @@ function Adv:clickBlock(roomId, blockId, params) | @@ -933,9 +933,6 @@ function Adv:clickBlock(roomId, blockId, params) | ||
| 933 | if block.event.etype == AdvEventType.Out then | 933 | if block.event.etype == AdvEventType.Out then |
| 934 | needChange = false | 934 | needChange = false |
| 935 | end | 935 | end |
| 936 | - if (block.event.etype == AdvEventType.Monster or block.event.etype == AdvEventType.BOSS) and not self.battle:isBattleEnd() then | ||
| 937 | - needChange = false | ||
| 938 | - end | ||
| 939 | end | 936 | end |
| 940 | if status and needChange then --出去了就不计算回合了 | 937 | if status and needChange then --出去了就不计算回合了 |
| 941 | self:backBlockChange(roomId, blockId) | 938 | self:backBlockChange(roomId, blockId) |
src/adv/AdvBattle.lua
| @@ -153,6 +153,19 @@ function Battle:afterRound() | @@ -153,6 +153,19 @@ function Battle:afterRound() | ||
| 153 | end | 153 | end |
| 154 | 154 | ||
| 155 | 155 | ||
| 156 | +function Battle:battleBegin(roomId, blockId, params) | ||
| 157 | + local enemy = self:getEnemy(roomId, blockId) | ||
| 158 | + if not enemy then return end | ||
| 159 | + local player = params.player | ||
| 160 | + -- 玩家没死就是怪死了 | ||
| 161 | + if player.hp > 0 then | ||
| 162 | + enemy:hurt(enemy.hp, self.player, {hurtType = 5}) | ||
| 163 | + end | ||
| 164 | + self.player:hurt(math.max(0, math.ceil(self.player.hp - player.hp)), enemy, {hurtType = 5}) --战斗血量只会变少 | ||
| 165 | + self.player:changeSp(math.min(0, math.floor(player.sp - self.player.sp)) , 0) --战斗魔力只会变少 | ||
| 166 | +end | ||
| 167 | + | ||
| 168 | + | ||
| 156 | --写入数据 | 169 | --写入数据 |
| 157 | function Battle:getDB() | 170 | function Battle:getDB() |
| 158 | self.adv.advTeam.player = self.player:getDB() | 171 | self.adv.advTeam.player = self.player:getDB() |
src/adv/AdvPlayer.lua
| @@ -205,7 +205,7 @@ function BaseObject:getInjuredValue(value) | @@ -205,7 +205,7 @@ function BaseObject:getInjuredValue(value) | ||
| 205 | end | 205 | end |
| 206 | 206 | ||
| 207 | --最终伤害 = [ (敌方攻击 - 己方防御) * (1+伤害增加百分比-伤害减少百分比)*(1+受伤增加百分比-受伤减少百分比)+(伤害增加固定值-伤害增加固定值+受伤增加固定值-受伤增加固定值)]*(1+侍宠百分比)-侍宠固定值 | 207 | --最终伤害 = [ (敌方攻击 - 己方防御) * (1+伤害增加百分比-伤害减少百分比)*(1+受伤增加百分比-受伤减少百分比)+(伤害增加固定值-伤害增加固定值+受伤增加固定值-受伤增加固定值)]*(1+侍宠百分比)-侍宠固定值 |
| 208 | --- params -- hurtType 1 普攻伤害 2 buff伤害 3 反弹伤害 4 真实伤害 | 208 | +-- params -- hurtType 1 普攻伤害 2 buff伤害 3 反弹伤害 4 真实伤害 5 客户端发回来的伤害 --直接作用 |
| 209 | --进入这个方法之前计算好释放者加成的伤害 | 209 | --进入这个方法之前计算好释放者加成的伤害 |
| 210 | function BaseObject:hurt(value, releaser, params) | 210 | function BaseObject:hurt(value, releaser, params) |
| 211 | params = params or {} | 211 | params = params or {} |
| @@ -226,39 +226,41 @@ function BaseObject:hurt(value, releaser, params) | @@ -226,39 +226,41 @@ function BaseObject:hurt(value, releaser, params) | ||
| 226 | team:triggerPassive(Passive.TEAM_HURT, {trigger = releaser}) | 226 | team:triggerPassive(Passive.TEAM_HURT, {trigger = releaser}) |
| 227 | end | 227 | end |
| 228 | end | 228 | end |
| 229 | - if not params.hurtType or params.hurtType ~= 4 then | ||
| 230 | - value = self:getInjuredValue(value) --减伤计算 | ||
| 231 | - end | ||
| 232 | - if value == 0 then return end | ||
| 233 | - | ||
| 234 | - -- 舍身和恃宠 | ||
| 235 | - local team = self:getTeam(1) | ||
| 236 | - local transfer = {} | ||
| 237 | - local absorb = {} | ||
| 238 | - for _, one in ipairs(team) do | ||
| 239 | - local change1, count1 = one:getCommonBuffEffect(Buff.INJURED_CHANGE) | ||
| 240 | - local change2, count2 = one:getCommonBuffEffect(Buff.HURT_ABSORB) | ||
| 241 | - if count1 > 0 then | ||
| 242 | - table.insert(transfer, {one, change1, count1}) | 229 | + if params.hurtType ~= 5 then |
| 230 | + if not params.hurtType or params.hurtType ~= 4 then | ||
| 231 | + value = self:getInjuredValue(value) --减伤计算 | ||
| 243 | end | 232 | end |
| 244 | - if count2 > 0 then | ||
| 245 | - table.insert(absorb, {one, change2, count2}) | ||
| 246 | - end | ||
| 247 | - end | ||
| 248 | - if #absorb == 1 then --舍身优先级高 --舍身生效 | ||
| 249 | - if absorb[1][1] ~= self then --舍身的人不是自己才有效 | ||
| 250 | - local absorbV = (value - absorb[1][2][0]) * absorb[1][2][1] + absorb[1][2][0] --固定值先生效 | ||
| 251 | - value = value - absorbV | ||
| 252 | - absorb[1][1]:hurt(absorbV, releaser, params) | 233 | + if value == 0 then return end |
| 234 | + | ||
| 235 | + -- 舍身和恃宠 | ||
| 236 | + local team = self:getTeam(1) | ||
| 237 | + local transfer = {} | ||
| 238 | + local absorb = {} | ||
| 239 | + for _, one in ipairs(team) do | ||
| 240 | + local change1, count1 = one:getCommonBuffEffect(Buff.INJURED_CHANGE) | ||
| 241 | + local change2, count2 = one:getCommonBuffEffect(Buff.HURT_ABSORB) | ||
| 242 | + if count1 > 0 then | ||
| 243 | + table.insert(transfer, {one, change1, count1}) | ||
| 244 | + end | ||
| 245 | + if count2 > 0 then | ||
| 246 | + table.insert(absorb, {one, change2, count2}) | ||
| 247 | + end | ||
| 253 | end | 248 | end |
| 254 | - else | ||
| 255 | - if #transfer == 1 and transfer[1][1] == self and #team > 1 then --侍宠 生效 | ||
| 256 | - local transferValue = (value - transfer[1][2][0])* transfer[1][2][1] + transfer[1][2][0] --固定值先生效 | ||
| 257 | - value = value - transferValue | ||
| 258 | - local oneValue = transferValue / (#team - 1) | ||
| 259 | - for _, one in ipairs(team) do | ||
| 260 | - if one ~= self then | ||
| 261 | - one:hurt(oneValue, releaser, params) | 249 | + if #absorb == 1 then --舍身优先级高 --舍身生效 |
| 250 | + if absorb[1][1] ~= self then --舍身的人不是自己才有效 | ||
| 251 | + local absorbV = (value - absorb[1][2][0]) * absorb[1][2][1] + absorb[1][2][0] --固定值先生效 | ||
| 252 | + value = value - absorbV | ||
| 253 | + absorb[1][1]:hurt(absorbV, releaser, params) | ||
| 254 | + end | ||
| 255 | + else | ||
| 256 | + if #transfer == 1 and transfer[1][1] == self and #team > 1 then --侍宠 生效 | ||
| 257 | + local transferValue = (value - transfer[1][2][0])* transfer[1][2][1] + transfer[1][2][0] --固定值先生效 | ||
| 258 | + value = value - transferValue | ||
| 259 | + local oneValue = transferValue / (#team - 1) | ||
| 260 | + for _, one in ipairs(team) do | ||
| 261 | + if one ~= self then | ||
| 262 | + one:hurt(oneValue, releaser, params) | ||
| 263 | + end | ||
| 262 | end | 264 | end |
| 263 | end | 265 | end |
| 264 | end | 266 | end |
| @@ -267,7 +269,7 @@ function BaseObject:hurt(value, releaser, params) | @@ -267,7 +269,7 @@ function BaseObject:hurt(value, releaser, params) | ||
| 267 | value = math.max(0, math.ceil(value)) | 269 | value = math.max(0, math.ceil(value)) |
| 268 | if value == 0 then return end | 270 | if value == 0 then return end |
| 269 | -- 反弹伤害 | 271 | -- 反弹伤害 |
| 270 | - if params.hurtType ~= 3 and releaser and not releaser.isDead then | 272 | + if params.hurtType ~= 3 and params.hurtType ~= 5 and releaser and not releaser.isDead then |
| 271 | local backEffect = self:getBackHurtBuff(params.hurtType == 1) | 273 | local backEffect = self:getBackHurtBuff(params.hurtType == 1) |
| 272 | local backValue = math.max(0, value * backEffect[1] + backEffect[0]) | 274 | local backValue = math.max(0, value * backEffect[1] + backEffect[0]) |
| 273 | releaser:hurt(backValue, releaser, {hurtType = 3}) | 275 | releaser:hurt(backValue, releaser, {hurtType = 3}) |