Commit 39a6e08b788a76ce59ce7b83ce224e8e498127b5
1 parent
b96f8839
冒险战斗内逻辑调整
Showing
7 changed files
with
100 additions
and
23 deletions
Show diff stats
src/GlobalVar.lua
| @@ -101,6 +101,7 @@ AdvBackEventType = { | @@ -101,6 +101,7 @@ AdvBackEventType = { | ||
| 101 | Dead = 11, --怪死亡 | 101 | Dead = 11, --怪死亡 |
| 102 | DefChange = 12, -- 防御变化 | 102 | DefChange = 12, -- 防御变化 |
| 103 | Passive = 13, -- 獲得被動 | 103 | Passive = 13, -- 獲得被動 |
| 104 | + TurnEnd = 14, -- 回合结束 | ||
| 104 | } | 105 | } |
| 105 | 106 | ||
| 106 | AdvScoreType = { | 107 | AdvScoreType = { |
src/ProtocolCode.lua
| @@ -30,6 +30,7 @@ actionCodes = { | @@ -30,6 +30,7 @@ actionCodes = { | ||
| 30 | Adv_useItemRpc = 154, | 30 | Adv_useItemRpc = 154, |
| 31 | Adv_useSkillRpc = 155, | 31 | Adv_useSkillRpc = 155, |
| 32 | Adv_exitAdvRpc = 156, | 32 | Adv_exitAdvRpc = 156, |
| 33 | + Adv_nextTurnRpc = 157, | ||
| 33 | 34 | ||
| 34 | Hero_loadInfos = 201, | 35 | Hero_loadInfos = 201, |
| 35 | Hero_updateProperty = 202, | 36 | Hero_updateProperty = 202, |
src/actions/AdvAction.lua
| @@ -97,6 +97,15 @@ function _M.exitAdvRpc(agent, data) | @@ -97,6 +97,15 @@ function _M.exitAdvRpc(agent, data) | ||
| 97 | return true | 97 | return true |
| 98 | end | 98 | end |
| 99 | 99 | ||
| 100 | - | 100 | +--继续战斗 |
| 101 | +function _M.nextTurnRpc(agent, data) | ||
| 102 | + local role = agent.role | ||
| 103 | + local msg = MsgPack.unpack(data) | ||
| 104 | + local adv = role:getAdvData() | ||
| 105 | + local status = adv:nextBattleTurn() | ||
| 106 | + if not status then return end | ||
| 107 | + SendPacket(actionCodes.Adv_nextTurnRpc, MsgPack.pack({events = adv:popBackEvents()})) | ||
| 108 | + return true | ||
| 109 | +end | ||
| 101 | 110 | ||
| 102 | return _M | 111 | return _M |
| 103 | \ No newline at end of file | 112 | \ No newline at end of file |
src/adv/Adv.lua
| @@ -699,7 +699,7 @@ end | @@ -699,7 +699,7 @@ end | ||
| 699 | 699 | ||
| 700 | --战斗 普通攻击 | 700 | --战斗 普通攻击 |
| 701 | local function clickMonster(self, room, block, params) | 701 | local function clickMonster(self, room, block, params) |
| 702 | - self.battle:playerAtk(room.roomId, block.blockId) | 702 | + self.battle:battleBegin(room.roomId, block.blockId) |
| 703 | return true | 703 | return true |
| 704 | end | 704 | end |
| 705 | 705 | ||
| @@ -881,7 +881,16 @@ function Adv:clickBlock(roomId, blockId, params) | @@ -881,7 +881,16 @@ function Adv:clickBlock(roomId, blockId, params) | ||
| 881 | end | 881 | end |
| 882 | end | 882 | end |
| 883 | end | 883 | end |
| 884 | - if status and (not clickEvent or (not block.event or block.event.etype ~= AdvEventType.Out)) then --出去了就不计算回合了 | 884 | + local needChange = true |
| 885 | + if clickEvent and block.event then | ||
| 886 | + if block.event.etype == AdvEventType.Out then | ||
| 887 | + needChange = false | ||
| 888 | + end | ||
| 889 | + if (block.event.etype == AdvEventType.Monster or block.event.etype == AdvEventType.BOSS) and not self.battle:isBattleEnd() then | ||
| 890 | + needChange = false | ||
| 891 | + end | ||
| 892 | + end | ||
| 893 | + if status and needChange then --出去了就不计算回合了 | ||
| 885 | self:backBlockChange(roomId, blockId) | 894 | self:backBlockChange(roomId, blockId) |
| 886 | self:afterRound() | 895 | self:afterRound() |
| 887 | end | 896 | end |
| @@ -889,6 +898,22 @@ function Adv:clickBlock(roomId, blockId, params) | @@ -889,6 +898,22 @@ function Adv:clickBlock(roomId, blockId, params) | ||
| 889 | return status | 898 | return status |
| 890 | end | 899 | end |
| 891 | 900 | ||
| 901 | +--继续战斗 | ||
| 902 | +function Adv:nextBattleTurn() | ||
| 903 | + local enemyId = self.battle.battleEnemyId | ||
| 904 | + if not enemyId then | ||
| 905 | + return | ||
| 906 | + end | ||
| 907 | + local roomId, blockId = self.battle:getRBByEnemyId(enemyId) | ||
| 908 | + self.battle:doBattleTurn() | ||
| 909 | + if self.battle:isBattleEnd() then | ||
| 910 | + self:backBlockChange(roomId, blockId) | ||
| 911 | + self:afterRound() | ||
| 912 | + end | ||
| 913 | + self:saveDB() | ||
| 914 | + return true | ||
| 915 | +end | ||
| 916 | + | ||
| 892 | --使用道具产生效果 | 917 | --使用道具产生效果 |
| 893 | function Adv:useItem(itemId, count, target) | 918 | function Adv:useItem(itemId, count, target) |
| 894 | count = count or 1 | 919 | count = count or 1 |
| @@ -1049,6 +1074,10 @@ function Adv:backDead(enemyId) | @@ -1049,6 +1074,10 @@ function Adv:backDead(enemyId) | ||
| 1049 | self:pushBackEvent(AdvBackEventType.Dead, {enemyId = enemyId}) | 1074 | self:pushBackEvent(AdvBackEventType.Dead, {enemyId = enemyId}) |
| 1050 | end | 1075 | end |
| 1051 | 1076 | ||
| 1077 | +function Adv:backTurnEnd() | ||
| 1078 | + self:pushBackEvent(AdvBackEventType.TurnEnd, {}) | ||
| 1079 | +end | ||
| 1080 | + | ||
| 1052 | 1081 | ||
| 1053 | function Adv:scoreChange(scoreType, pms) | 1082 | function Adv:scoreChange(scoreType, pms) |
| 1054 | local cutTypes = {} | 1083 | local cutTypes = {} |
| @@ -1100,6 +1129,7 @@ function Adv:afterRound() | @@ -1100,6 +1129,7 @@ function Adv:afterRound() | ||
| 1100 | if self.battle then | 1129 | if self.battle then |
| 1101 | self.battle:afterRound() | 1130 | self.battle:afterRound() |
| 1102 | end | 1131 | end |
| 1132 | + -- TODO 房间回合事件 | ||
| 1103 | end | 1133 | end |
| 1104 | 1134 | ||
| 1105 | function Adv:saveDB() | 1135 | function Adv:saveDB() |
src/adv/AdvBattle.lua
| @@ -6,6 +6,7 @@ function Battle:ctor(adv) | @@ -6,6 +6,7 @@ function Battle:ctor(adv) | ||
| 6 | self.adv = adv | 6 | self.adv = adv |
| 7 | self.player = nil --玩家 | 7 | self.player = nil --玩家 |
| 8 | self.isNewPlayer = false | 8 | self.isNewPlayer = false |
| 9 | + self.battleEnemyId = nil | ||
| 9 | self.enemys = {} --怪 | 10 | self.enemys = {} --怪 |
| 10 | self:initPlayer() | 11 | self:initPlayer() |
| 11 | self:initEnemys() | 12 | self:initEnemys() |
| @@ -20,6 +21,7 @@ function Battle:initAfter() | @@ -20,6 +21,7 @@ function Battle:initAfter() | ||
| 20 | for _, enemy in pairs(self.enemys) do | 21 | for _, enemy in pairs(self.enemys) do |
| 21 | enemy:initAfter(self.adv.rooms[enemy.roomId].blocks[enemy.blockId].event.enemy) | 22 | enemy:initAfter(self.adv.rooms[enemy.roomId].blocks[enemy.blockId].event.enemy) |
| 22 | end | 23 | end |
| 24 | + self.battleEnemyId = self.adv.advTeam.enemyId | ||
| 23 | end | 25 | end |
| 24 | 26 | ||
| 25 | function Battle:initPlayer() | 27 | function Battle:initPlayer() |
| @@ -93,36 +95,63 @@ function Battle:getEnemyById(id) | @@ -93,36 +95,63 @@ function Battle:getEnemyById(id) | ||
| 93 | end | 95 | end |
| 94 | end | 96 | end |
| 95 | end | 97 | end |
| 96 | ---普通攻击 | ||
| 97 | -function Battle:playerAtk(roomId, blockId) | 98 | + |
| 99 | +function Battle:getRBByEnemyId(enemyId) | ||
| 100 | + local enemy = self:getEnemyById(enemyId) | ||
| 101 | + return enemy.roomId, enemy.blockId | ||
| 102 | +end | ||
| 103 | + | ||
| 104 | +function Battle:isBattleEnd() | ||
| 105 | + if not self.battleEnemyId then | ||
| 106 | + return true | ||
| 107 | + end | ||
| 108 | +end | ||
| 109 | + | ||
| 110 | +--战斗开始 | ||
| 111 | +function Battle:battleBegin(roomId, blockId) | ||
| 112 | + if self.battleEnemyId then | ||
| 113 | + self.battleEnemyId = nil | ||
| 114 | + -- TODO 清理上次战斗遗留数据 | ||
| 115 | + end | ||
| 98 | local enemy = self:getEnemy(roomId, blockId) | 116 | local enemy = self:getEnemy(roomId, blockId) |
| 99 | if enemy then | 117 | if enemy then |
| 118 | + self.battleEnemyId = enemy.id | ||
| 100 | self.player:battleBegin() | 119 | self.player:battleBegin() |
| 101 | enemy:battleBegin() | 120 | enemy:battleBegin() |
| 102 | - while not enemy.isDead and not self.player.isDead do | ||
| 103 | - -- 玩家先出手 | ||
| 104 | - self.adv:backAtk(nil, enemy.id) | ||
| 105 | - self:doBattleTurn(self.player, enemy) | ||
| 106 | - --是否无法反击 | ||
| 107 | - if not enemy.isDead and not enemy:hadBuff(Buff.CANT_BACK_ATK) then | ||
| 108 | - self.adv:backAtk(enemy.id, nil) | ||
| 109 | - self:doBattleTurn(enemy, self.player) | ||
| 110 | - end | ||
| 111 | - end | ||
| 112 | - if not self.player.isDead then | ||
| 113 | - self.player:battleEnd() | ||
| 114 | - elseif not enemy.isDead then | ||
| 115 | - enemy:battleEnd() | ||
| 116 | - end | 121 | + self:doBattleTurn() |
| 122 | + end | ||
| 123 | +end | ||
| 124 | + | ||
| 125 | +-- 战斗内一回合 | ||
| 126 | +function Battle:doBattleTurn() | ||
| 127 | + local enemy = self:getEnemyById(self.battleEnemyId) | ||
| 128 | + if not enemy then return end | ||
| 129 | + -- 玩家先出手 | ||
| 130 | + self.adv:backAtk(nil, enemy.id) | ||
| 131 | + self:doPlayerTurn(self.player, enemy) | ||
| 132 | + --是否无法攻击 | ||
| 133 | + if not enemy.isDead and not enemy:hadBuff(Buff.CANT_BACK_ATK) then | ||
| 134 | + self.adv:backAtk(enemy.id, nil) | ||
| 135 | + self:doPlayerTurn(enemy, self.player) | ||
| 136 | + end | ||
| 137 | + -- 判定死亡 | ||
| 138 | + if enemy.isDead or self.player.isDead then | ||
| 139 | + local deadPlayer = enemy.isDead and enemy or self.player | ||
| 140 | + deadPlayer:battleEnd() | ||
| 141 | + self.battleEnemyId = nil | ||
| 142 | + else | ||
| 143 | + self.adv:backTurnEnd() | ||
| 117 | end | 144 | end |
| 118 | end | 145 | end |
| 119 | ---战斗内回合逻辑 | ||
| 120 | -function Battle:doBattleTurn(atkPlayer, hurtPlayer) | 146 | + |
| 147 | +--战斗内角色回合逻辑 | ||
| 148 | +function Battle:doPlayerTurn(atkPlayer, hurtPlayer) | ||
| 121 | atkPlayer:beforeTurn() | 149 | atkPlayer:beforeTurn() |
| 122 | hurtPlayer:hurt(atkPlayer:getHurtValue(), atkPlayer, {hurtType = 1}) | 150 | hurtPlayer:hurt(atkPlayer:getHurtValue(), atkPlayer, {hurtType = 1}) |
| 123 | atkPlayer:afterTurn() | 151 | atkPlayer:afterTurn() |
| 124 | atkPlayer:clearTurn() | 152 | atkPlayer:clearTurn() |
| 125 | end | 153 | end |
| 154 | + | ||
| 126 | --触发全员被动技能 | 155 | --触发全员被动技能 |
| 127 | function Battle:triggerPassive(condType, params) | 156 | function Battle:triggerPassive(condType, params) |
| 128 | self.player:triggerPassive(condType, params) | 157 | self.player:triggerPassive(condType, params) |
| @@ -171,6 +200,7 @@ function Battle:getDB() | @@ -171,6 +200,7 @@ function Battle:getDB() | ||
| 171 | local block = self.adv.rooms[enemy.roomId].blocks[enemy.blockId] | 200 | local block = self.adv.rooms[enemy.roomId].blocks[enemy.blockId] |
| 172 | block.event.enemy = enemy:getDB() | 201 | block.event.enemy = enemy:getDB() |
| 173 | end | 202 | end |
| 203 | + self.adv.advTeam.enemyId = self.battleEnemyId | ||
| 174 | end | 204 | end |
| 175 | 205 | ||
| 176 | return Battle | 206 | return Battle |
| 177 | \ No newline at end of file | 207 | \ No newline at end of file |
src/adv/AdvPassive.lua
| @@ -202,7 +202,7 @@ function Passive:ctor(owner, data) | @@ -202,7 +202,7 @@ function Passive:ctor(owner, data) | ||
| 202 | self.count = data.count or self.passiveData.count --触发剩余次数 | 202 | self.count = data.count or self.passiveData.count --触发剩余次数 |
| 203 | self.delay = data.delay or self.passiveData.delayRound --触发延迟回合数 | 203 | self.delay = data.delay or self.passiveData.delayRound --触发延迟回合数 |
| 204 | self.turn = 0 --战斗内回合数 | 204 | self.turn = 0 --战斗内回合数 |
| 205 | - self.delayturn = self.passiveData.delayTurn --战斗内延迟回合数 | 205 | + self.delayTurn = self.passiveData.delayTurn --战斗内延迟回合数 |
| 206 | 206 | ||
| 207 | self.effects = self.passiveData.effect:toTableArray(true) | 207 | self.effects = self.passiveData.effect:toTableArray(true) |
| 208 | self.filters = {} | 208 | self.filters = {} |
src/adv/AdvPlayer.lua
| @@ -15,11 +15,15 @@ function BaseObject:ctor(battle) | @@ -15,11 +15,15 @@ function BaseObject:ctor(battle) | ||
| 15 | self.passives = {} --固有技能 | 15 | self.passives = {} --固有技能 |
| 16 | self.buffs = {} --buff | 16 | self.buffs = {} --buff |
| 17 | self.isDead = false | 17 | self.isDead = false |
| 18 | + self.mpMax = 0 | ||
| 19 | + self.mp = 0 | ||
| 18 | end | 20 | end |
| 19 | --初始化角色 | 21 | --初始化角色 |
| 20 | function BaseObject:initData(data) | 22 | function BaseObject:initData(data) |
| 21 | self.hpMax = data.hpMax or data.hp | 23 | self.hpMax = data.hpMax or data.hp |
| 22 | self.hp = data.hp | 24 | self.hp = data.hp |
| 25 | + self.mpMax = data.mpMax or data.mp | ||
| 26 | + self.mp = data.mp | ||
| 23 | --可变化的值 | 27 | --可变化的值 |
| 24 | self.atk = data.atk | 28 | self.atk = data.atk |
| 25 | self.miss = data.miss | 29 | self.miss = data.miss |
| @@ -377,6 +381,8 @@ function BaseObject:getDB() | @@ -377,6 +381,8 @@ function BaseObject:getDB() | ||
| 377 | local db = {} | 381 | local db = {} |
| 378 | db.hpMax = self.hpMax | 382 | db.hpMax = self.hpMax |
| 379 | db.hp = self.hp | 383 | db.hp = self.hp |
| 384 | + db.mpMax = self.mpMax | ||
| 385 | + db.mp = self.mp | ||
| 380 | local baseAttr = {"atk", "miss", "hit", "def"} | 386 | local baseAttr = {"atk", "miss", "hit", "def"} |
| 381 | for _, field in pairs(baseAttr) do | 387 | for _, field in pairs(baseAttr) do |
| 382 | db[field] = self[field] | 388 | db[field] = self[field] |