diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 708cb74..af5d6b2 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -35,6 +35,8 @@ actionCodes = { Adv_useItemRpc = 154, Adv_usePotionRpc = 155, Adv_exitAdvRpc = 156, + Adv_startBattleRpc = 157, + Adv_endBattleRpc = 158, Hero_loadInfos = 201, Hero_updateProperty = 202, diff --git a/src/actions/AdvAction.lua b/src/actions/AdvAction.lua index 30f9fac..d2be8ba 100644 --- a/src/actions/AdvAction.lua +++ b/src/actions/AdvAction.lua @@ -100,5 +100,59 @@ function _M.exitAdvRpc(agent, data) return true end +--开始战斗 +function _M.startBattleRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + + -- 校验一下信息 + local roomId = msg.roomId + local blockId = msg.blockId + local monsterId = msg.monsterId + local enemyId = msg.enemyId + if not enemyId then return end + + local adv = role:getAdvData() + local enemy = adv.battle:getEnemyById(enemyId) + + if enemy.monsterId ~= monsterId or enemy.roomId ~= roomId or enemy.blockId ~= blockId or enemy.lock or enemy.isDead then return end + + local key = tostring(math.random()) + adv.__battleCache = { + enemyId = enemyId, + key = key + } + SendPacket(actionCodes.Adv_startBattleRpc, MsgPack.pack({key = key})) + return true +end + +-- 结束战斗 +function _M.endBattleRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local roomId = msg.roomId + local blockId = msg.blockId + local monsterId = msg.monsterId + local enemyId = msg.enemyId + local key = msg.key + local player = msg.player + + if not player or not player.hp or not player.sp or not enemyId or not key then return end + local adv = role:getAdvData() + -- 校验 + if not adv.__battleCache then return end + if adv.__battleCache.enemyId ~= enemyId then return end + local enemy = adv.battle:getEnemyById(enemyId) + if enemy.monsterId ~= monsterId or enemy.roomId ~= roomId or enemy.blockId ~= blockId then return end + adv.__battleCache = nil + + + local status = adv:clickBlock(roomId, blockId, {player = player}) + if not status then return end + SendPacket(actionCodes.Adv_endBattleRpc, MsgPack.pack({events = adv:popBackEvents()})) + return true +end + + return _M \ No newline at end of file diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index 3a085fb..1b54acd 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -720,7 +720,7 @@ end --战斗 普通攻击 local function clickMonster(self, room, block, params) - self.battle:battleBegin(room.roomId, block.blockId, params.quick) + self.battle:battleBegin(room.roomId, block.blockId, params) return true end @@ -933,9 +933,6 @@ function Adv:clickBlock(roomId, blockId, params) if block.event.etype == AdvEventType.Out then needChange = false end - if (block.event.etype == AdvEventType.Monster or block.event.etype == AdvEventType.BOSS) and not self.battle:isBattleEnd() then - needChange = false - end end if status and needChange then --出去了就不计算回合了 self:backBlockChange(roomId, blockId) diff --git a/src/adv/AdvBattle.lua b/src/adv/AdvBattle.lua index d628145..1f69726 100644 --- a/src/adv/AdvBattle.lua +++ b/src/adv/AdvBattle.lua @@ -153,6 +153,19 @@ function Battle:afterRound() end +function Battle:battleBegin(roomId, blockId, params) + local enemy = self:getEnemy(roomId, blockId) + if not enemy then return end + local player = params.player + -- 玩家没死就是怪死了 + if player.hp > 0 then + enemy:hurt(enemy.hp, self.player, {hurtType = 5}) + end + self.player:hurt(math.max(0, math.ceil(self.player.hp - player.hp)), enemy, {hurtType = 5}) --战斗血量只会变少 + self.player:changeSp(math.min(0, math.floor(player.sp - self.player.sp)) , 0) --战斗魔力只会变少 +end + + --写入数据 function Battle:getDB() self.adv.advTeam.player = self.player:getDB() diff --git a/src/adv/AdvPlayer.lua b/src/adv/AdvPlayer.lua index f38685b..d7845ad 100644 --- a/src/adv/AdvPlayer.lua +++ b/src/adv/AdvPlayer.lua @@ -205,7 +205,7 @@ function BaseObject:getInjuredValue(value) end --最终伤害 = [ (敌方攻击 - 己方防御) * (1+伤害增加百分比-伤害减少百分比)*(1+受伤增加百分比-受伤减少百分比)+(伤害增加固定值-伤害增加固定值+受伤增加固定值-受伤增加固定值)]*(1+侍宠百分比)-侍宠固定值 --- params -- hurtType 1 普攻伤害 2 buff伤害 3 反弹伤害 4 真实伤害 +-- params -- hurtType 1 普攻伤害 2 buff伤害 3 反弹伤害 4 真实伤害 5 客户端发回来的伤害 --直接作用 --进入这个方法之前计算好释放者加成的伤害 function BaseObject:hurt(value, releaser, params) params = params or {} @@ -226,39 +226,41 @@ function BaseObject:hurt(value, releaser, params) team:triggerPassive(Passive.TEAM_HURT, {trigger = releaser}) end end - if not params.hurtType or params.hurtType ~= 4 then - value = self:getInjuredValue(value) --减伤计算 - end - if value == 0 then return end - - -- 舍身和恃宠 - local team = self:getTeam(1) - local transfer = {} - local absorb = {} - for _, one in ipairs(team) do - local change1, count1 = one:getCommonBuffEffect(Buff.INJURED_CHANGE) - local change2, count2 = one:getCommonBuffEffect(Buff.HURT_ABSORB) - if count1 > 0 then - table.insert(transfer, {one, change1, count1}) + if params.hurtType ~= 5 then + if not params.hurtType or params.hurtType ~= 4 then + value = self:getInjuredValue(value) --减伤计算 end - if count2 > 0 then - table.insert(absorb, {one, change2, count2}) - end - end - if #absorb == 1 then --舍身优先级高 --舍身生效 - if absorb[1][1] ~= self then --舍身的人不是自己才有效 - local absorbV = (value - absorb[1][2][0]) * absorb[1][2][1] + absorb[1][2][0] --固定值先生效 - value = value - absorbV - absorb[1][1]:hurt(absorbV, releaser, params) + if value == 0 then return end + + -- 舍身和恃宠 + local team = self:getTeam(1) + local transfer = {} + local absorb = {} + for _, one in ipairs(team) do + local change1, count1 = one:getCommonBuffEffect(Buff.INJURED_CHANGE) + local change2, count2 = one:getCommonBuffEffect(Buff.HURT_ABSORB) + if count1 > 0 then + table.insert(transfer, {one, change1, count1}) + end + if count2 > 0 then + table.insert(absorb, {one, change2, count2}) + end end - else - if #transfer == 1 and transfer[1][1] == self and #team > 1 then --侍宠 生效 - local transferValue = (value - transfer[1][2][0])* transfer[1][2][1] + transfer[1][2][0] --固定值先生效 - value = value - transferValue - local oneValue = transferValue / (#team - 1) - for _, one in ipairs(team) do - if one ~= self then - one:hurt(oneValue, releaser, params) + if #absorb == 1 then --舍身优先级高 --舍身生效 + if absorb[1][1] ~= self then --舍身的人不是自己才有效 + local absorbV = (value - absorb[1][2][0]) * absorb[1][2][1] + absorb[1][2][0] --固定值先生效 + value = value - absorbV + absorb[1][1]:hurt(absorbV, releaser, params) + end + else + if #transfer == 1 and transfer[1][1] == self and #team > 1 then --侍宠 生效 + local transferValue = (value - transfer[1][2][0])* transfer[1][2][1] + transfer[1][2][0] --固定值先生效 + value = value - transferValue + local oneValue = transferValue / (#team - 1) + for _, one in ipairs(team) do + if one ~= self then + one:hurt(oneValue, releaser, params) + end end end end @@ -267,7 +269,7 @@ function BaseObject:hurt(value, releaser, params) value = math.max(0, math.ceil(value)) if value == 0 then return end -- 反弹伤害 - if params.hurtType ~= 3 and releaser and not releaser.isDead then + if params.hurtType ~= 3 and params.hurtType ~= 5 and releaser and not releaser.isDead then local backEffect = self:getBackHurtBuff(params.hurtType == 1) local backValue = math.max(0, value * backEffect[1] + backEffect[0]) releaser:hurt(backValue, releaser, {hurtType = 3}) -- libgit2 0.21.2