Commit 1f3087de2202bfcfe80881518f3348e7dabb4c31
Merge branch 'master' into feng/equip
Showing
8 changed files
with
142 additions
and
27 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
| @@ -32,6 +32,7 @@ actionCodes = { | @@ -32,6 +32,7 @@ actionCodes = { | ||
| 32 | Adv_useItemRpc = 154, | 32 | Adv_useItemRpc = 154, |
| 33 | Adv_useSkillRpc = 155, | 33 | Adv_useSkillRpc = 155, |
| 34 | Adv_exitAdvRpc = 156, | 34 | Adv_exitAdvRpc = 156, |
| 35 | + Adv_nextTurnRpc = 157, | ||
| 35 | 36 | ||
| 36 | Hero_loadInfos = 201, | 37 | Hero_loadInfos = 201, |
| 37 | Hero_updateProperty = 202, | 38 | Hero_updateProperty = 202, |
src/actions/AdvAction.lua
| @@ -97,6 +97,18 @@ function _M.exitAdvRpc(agent, data) | @@ -97,6 +97,18 @@ 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(msg.turn) | ||
| 106 | + if not status then -- 数据不同步则发送缓存数据 | ||
| 107 | + SendPacket(actionCodes.Adv_nextTurnRpc, MsgPack.pack({events = adv.tempBackEvents})) | ||
| 108 | + return true | ||
| 109 | + end | ||
| 110 | + SendPacket(actionCodes.Adv_nextTurnRpc, MsgPack.pack({events = adv:popBackEvents()})) | ||
| 111 | + return true | ||
| 112 | +end | ||
| 101 | 113 | ||
| 102 | return _M | 114 | return _M |
| 103 | \ No newline at end of file | 115 | \ No newline at end of file |
src/adv/Adv.lua
| @@ -442,6 +442,7 @@ function Adv:ctor(owner) | @@ -442,6 +442,7 @@ function Adv:ctor(owner) | ||
| 442 | self.advTeam = self.owner:getProperty("advTeam") --这个变量置空使用 table.clear | 442 | self.advTeam = self.owner:getProperty("advTeam") --这个变量置空使用 table.clear |
| 443 | self:clear() | 443 | self:clear() |
| 444 | self.backEvents = {} --发给客户端的事件组 | 444 | self.backEvents = {} --发给客户端的事件组 |
| 445 | + self.tempBackEvents = {} --发给客户端的事件组(缓存) | ||
| 445 | end | 446 | end |
| 446 | 447 | ||
| 447 | -- 清空自己组织的数据 | 448 | -- 清空自己组织的数据 |
| @@ -699,7 +700,7 @@ end | @@ -699,7 +700,7 @@ end | ||
| 699 | 700 | ||
| 700 | --战斗 普通攻击 | 701 | --战斗 普通攻击 |
| 701 | local function clickMonster(self, room, block, params) | 702 | local function clickMonster(self, room, block, params) |
| 702 | - self.battle:playerAtk(room.roomId, block.blockId) | 703 | + self.battle:battleBegin(room.roomId, block.blockId) |
| 703 | return true | 704 | return true |
| 704 | end | 705 | end |
| 705 | 706 | ||
| @@ -881,7 +882,16 @@ function Adv:clickBlock(roomId, blockId, params) | @@ -881,7 +882,16 @@ function Adv:clickBlock(roomId, blockId, params) | ||
| 881 | end | 882 | end |
| 882 | end | 883 | end |
| 883 | end | 884 | end |
| 884 | - if status and (not clickEvent or (not block.event or block.event.etype ~= AdvEventType.Out)) then --出去了就不计算回合了 | 885 | + local needChange = true |
| 886 | + if clickEvent and block.event then | ||
| 887 | + if block.event.etype == AdvEventType.Out then | ||
| 888 | + needChange = false | ||
| 889 | + end | ||
| 890 | + if (block.event.etype == AdvEventType.Monster or block.event.etype == AdvEventType.BOSS) and not self.battle:isBattleEnd() then | ||
| 891 | + needChange = false | ||
| 892 | + end | ||
| 893 | + end | ||
| 894 | + if status and needChange then --出去了就不计算回合了 | ||
| 885 | self:backBlockChange(roomId, blockId) | 895 | self:backBlockChange(roomId, blockId) |
| 886 | self:afterRound() | 896 | self:afterRound() |
| 887 | end | 897 | end |
| @@ -889,6 +899,22 @@ function Adv:clickBlock(roomId, blockId, params) | @@ -889,6 +899,22 @@ function Adv:clickBlock(roomId, blockId, params) | ||
| 889 | return status | 899 | return status |
| 890 | end | 900 | end |
| 891 | 901 | ||
| 902 | +--继续战斗 | ||
| 903 | +function Adv:nextBattleTurn(turn) | ||
| 904 | + local enemy = self.battle.enemy | ||
| 905 | + if not enemy or self.battle:checkTurn(turn) then | ||
| 906 | + return | ||
| 907 | + end | ||
| 908 | + local roomId, blockId = self.battle:getRBByEnemyId(enemy.id) | ||
| 909 | + self.battle:doBattleTurn() | ||
| 910 | + if self.battle:isBattleEnd() then | ||
| 911 | + self:backBlockChange(roomId, blockId) | ||
| 912 | + self:afterRound() | ||
| 913 | + end | ||
| 914 | + self:saveDB() | ||
| 915 | + return true | ||
| 916 | +end | ||
| 917 | + | ||
| 892 | --使用道具产生效果 | 918 | --使用道具产生效果 |
| 893 | function Adv:useItem(itemId, count, target) | 919 | function Adv:useItem(itemId, count, target) |
| 894 | count = count or 1 | 920 | count = count or 1 |
| @@ -1049,6 +1075,10 @@ function Adv:backDead(enemyId) | @@ -1049,6 +1075,10 @@ function Adv:backDead(enemyId) | ||
| 1049 | self:pushBackEvent(AdvBackEventType.Dead, {enemyId = enemyId}) | 1075 | self:pushBackEvent(AdvBackEventType.Dead, {enemyId = enemyId}) |
| 1050 | end | 1076 | end |
| 1051 | 1077 | ||
| 1078 | +function Adv:backTurnEnd() | ||
| 1079 | + self:pushBackEvent(AdvBackEventType.TurnEnd, {}) | ||
| 1080 | +end | ||
| 1081 | + | ||
| 1052 | 1082 | ||
| 1053 | function Adv:scoreChange(scoreType, pms) | 1083 | function Adv:scoreChange(scoreType, pms) |
| 1054 | local cutTypes = {} | 1084 | local cutTypes = {} |
| @@ -1091,6 +1121,8 @@ end | @@ -1091,6 +1121,8 @@ end | ||
| 1091 | 1121 | ||
| 1092 | function Adv:popBackEvents() | 1122 | function Adv:popBackEvents() |
| 1093 | local events = self.backEvents | 1123 | local events = self.backEvents |
| 1124 | + -- TODO 缓存数据需要分类,防止发错,暂时只有战斗,可以不分 | ||
| 1125 | + self.tempBackEvents = events | ||
| 1094 | self.backEvents = {} | 1126 | self.backEvents = {} |
| 1095 | return events | 1127 | return events |
| 1096 | end | 1128 | end |
| @@ -1100,6 +1132,7 @@ function Adv:afterRound() | @@ -1100,6 +1132,7 @@ function Adv:afterRound() | ||
| 1100 | if self.battle then | 1132 | if self.battle then |
| 1101 | self.battle:afterRound() | 1133 | self.battle:afterRound() |
| 1102 | end | 1134 | end |
| 1135 | + -- TODO 房间回合事件 | ||
| 1103 | end | 1136 | end |
| 1104 | 1137 | ||
| 1105 | function Adv:saveDB() | 1138 | function Adv:saveDB() |
src/adv/AdvBattle.lua
| @@ -6,7 +6,9 @@ function Battle:ctor(adv) | @@ -6,7 +6,9 @@ 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.enemy = nil | ||
| 9 | self.enemys = {} --怪 | 10 | self.enemys = {} --怪 |
| 11 | + self.tempData = {} -- 临时回合数据 | ||
| 10 | self:initPlayer() | 12 | self:initPlayer() |
| 11 | self:initEnemys() | 13 | self:initEnemys() |
| 12 | self:initAfter() | 14 | self:initAfter() |
| @@ -20,6 +22,10 @@ function Battle:initAfter() | @@ -20,6 +22,10 @@ function Battle:initAfter() | ||
| 20 | for _, enemy in pairs(self.enemys) do | 22 | for _, enemy in pairs(self.enemys) do |
| 21 | enemy:initAfter(self.adv.rooms[enemy.roomId].blocks[enemy.blockId].event.enemy) | 23 | enemy:initAfter(self.adv.rooms[enemy.roomId].blocks[enemy.blockId].event.enemy) |
| 22 | end | 24 | end |
| 25 | + if self.adv.advTeam.enemyId then | ||
| 26 | + local enemy = self:getEnemyById(self.adv.advTeam.enemyId) | ||
| 27 | + self.enemy = enemy | ||
| 28 | + end | ||
| 23 | end | 29 | end |
| 24 | 30 | ||
| 25 | function Battle:initPlayer() | 31 | function Battle:initPlayer() |
| @@ -93,36 +99,71 @@ function Battle:getEnemyById(id) | @@ -93,36 +99,71 @@ function Battle:getEnemyById(id) | ||
| 93 | end | 99 | end |
| 94 | end | 100 | end |
| 95 | end | 101 | end |
| 96 | ---普通攻击 | ||
| 97 | -function Battle:playerAtk(roomId, blockId) | 102 | + |
| 103 | +function Battle:getRBByEnemyId(enemyId) | ||
| 104 | + local enemy = self:getEnemyById(enemyId) | ||
| 105 | + return enemy.roomId, enemy.blockId | ||
| 106 | +end | ||
| 107 | + | ||
| 108 | +function Battle:isBattleEnd() | ||
| 109 | + if not self.enemy then | ||
| 110 | + return true | ||
| 111 | + end | ||
| 112 | +end | ||
| 113 | + | ||
| 114 | +--战斗开始 | ||
| 115 | +function Battle:battleBegin(roomId, blockId) | ||
| 116 | + self.tempData = {} -- 清理上次战斗数据 | ||
| 117 | + if self.enemy then | ||
| 118 | + self.player:reset(self.adv.advTeam.player) | ||
| 119 | + self.enemy:reset(self.adv.rooms[self.enemy.roomId].blocks[self.enemy.blockId].event.enemy) | ||
| 120 | + end | ||
| 98 | local enemy = self:getEnemy(roomId, blockId) | 121 | local enemy = self:getEnemy(roomId, blockId) |
| 99 | if enemy then | 122 | if enemy then |
| 123 | + self.enemy = enemy | ||
| 100 | self.player:battleBegin() | 124 | self.player:battleBegin() |
| 101 | - 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 | 125 | + self.enemy:battleBegin() |
| 126 | + self:doBattleTurn() | ||
| 127 | + end | ||
| 128 | +end | ||
| 129 | + | ||
| 130 | +-- 检查回合数同步 | ||
| 131 | +function Battle:checkTurn(turn) | ||
| 132 | + if self.tempData[turn] then | ||
| 133 | + return true | ||
| 117 | end | 134 | end |
| 118 | end | 135 | end |
| 119 | ---战斗内回合逻辑 | ||
| 120 | -function Battle:doBattleTurn(atkPlayer, hurtPlayer) | 136 | + |
| 137 | +-- 战斗内一回合 | ||
| 138 | +function Battle:doBattleTurn() | ||
| 139 | + local enemy = self.enemy | ||
| 140 | + -- 玩家先出手 | ||
| 141 | + self.adv:backAtk(nil, enemy.id) | ||
| 142 | + self:doPlayerTurn(self.player, enemy) | ||
| 143 | + --是否无法攻击 | ||
| 144 | + if not enemy.isDead and not enemy:hadBuff(Buff.CANT_BACK_ATK) then | ||
| 145 | + self.adv:backAtk(enemy.id, nil) | ||
| 146 | + self:doPlayerTurn(enemy, self.player) | ||
| 147 | + end | ||
| 148 | + -- 判定死亡 | ||
| 149 | + if enemy.isDead or self.player.isDead then | ||
| 150 | + local deadPlayer = enemy.isDead and enemy or self.player | ||
| 151 | + deadPlayer:battleEnd() | ||
| 152 | + self.enemy = nil | ||
| 153 | + else | ||
| 154 | + self.adv:backTurnEnd() | ||
| 155 | + end | ||
| 156 | + self:getTempDB() | ||
| 157 | +end | ||
| 158 | + | ||
| 159 | +--战斗内角色回合逻辑 | ||
| 160 | +function Battle:doPlayerTurn(atkPlayer, hurtPlayer) | ||
| 121 | atkPlayer:beforeTurn() | 161 | atkPlayer:beforeTurn() |
| 122 | hurtPlayer:hurt(atkPlayer:getHurtValue(), atkPlayer, {hurtType = 1}) | 162 | hurtPlayer:hurt(atkPlayer:getHurtValue(), atkPlayer, {hurtType = 1}) |
| 123 | atkPlayer:afterTurn() | 163 | atkPlayer:afterTurn() |
| 124 | atkPlayer:clearTurn() | 164 | atkPlayer:clearTurn() |
| 125 | end | 165 | end |
| 166 | + | ||
| 126 | --触发全员被动技能 | 167 | --触发全员被动技能 |
| 127 | function Battle:triggerPassive(condType, params) | 168 | function Battle:triggerPassive(condType, params) |
| 128 | self.player:triggerPassive(condType, params) | 169 | self.player:triggerPassive(condType, params) |
| @@ -157,15 +198,29 @@ function Battle:afterRound() | @@ -157,15 +198,29 @@ function Battle:afterRound() | ||
| 157 | else | 198 | else |
| 158 | self.player:hurt(self.player.hpMax / 10, nil, {hurtType = 4}) | 199 | self.player:hurt(self.player.hpMax / 10, nil, {hurtType = 4}) |
| 159 | end | 200 | end |
| 160 | - | ||
| 161 | - | ||
| 162 | if self.player.isDead then | 201 | if self.player.isDead then |
| 163 | self.adv:over(false) | 202 | self.adv:over(false) |
| 164 | end | 203 | end |
| 165 | end | 204 | end |
| 166 | 205 | ||
| 206 | +-- 写入临时数据 | ||
| 207 | +function Battle:getTempDB() | ||
| 208 | + local turnDB = {} | ||
| 209 | + if self.enemy then | ||
| 210 | + turnDB.enemy = self.enemy:getDB() | ||
| 211 | + end | ||
| 212 | + turnDB.player = self.player:getDB() | ||
| 213 | + table.insert(self.tempData, turnDB) | ||
| 214 | +end | ||
| 215 | + | ||
| 167 | --写入数据 | 216 | --写入数据 |
| 168 | function Battle:getDB() | 217 | function Battle:getDB() |
| 218 | + if not self.enemy then | ||
| 219 | + self.adv.advTeam.enemyId = nil | ||
| 220 | + else | ||
| 221 | + self.adv.advTeam.enemyId = self.enemy.id | ||
| 222 | + return | ||
| 223 | + end | ||
| 169 | self.adv.advTeam.player = self.player:getDB() | 224 | self.adv.advTeam.player = self.player:getDB() |
| 170 | for _, enemy in ipairs(self.enemys) do | 225 | for _, enemy in ipairs(self.enemys) do |
| 171 | local block = self.adv.rooms[enemy.roomId].blocks[enemy.blockId] | 226 | local block = self.adv.rooms[enemy.roomId].blocks[enemy.blockId] |
src/adv/AdvBuff.lua
| @@ -106,7 +106,7 @@ local BuffFactory = { | @@ -106,7 +106,7 @@ local BuffFactory = { | ||
| 106 | end | 106 | end |
| 107 | end, | 107 | end, |
| 108 | [Buff.ATTR_CHANGE] = function(_Buff) | 108 | [Buff.ATTR_CHANGE] = function(_Buff) |
| 109 | - local attrName = AttsEnumEx[self.buffData.effectValue3] | 109 | + local attrName = AttsEnumEx[_Buff.buffData.effectValue3] |
| 110 | commonAttr(_Buff, attrName) | 110 | commonAttr(_Buff, attrName) |
| 111 | end, | 111 | end, |
| 112 | [Buff.BACK_HURT] = function(_Buff) | 112 | [Buff.BACK_HURT] = function(_Buff) |
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 |
| @@ -41,6 +45,13 @@ function BaseObject:initAfter(data) | @@ -41,6 +45,13 @@ function BaseObject:initAfter(data) | ||
| 41 | end | 45 | end |
| 42 | end | 46 | end |
| 43 | 47 | ||
| 48 | +function BaseObject:reset(data) | ||
| 49 | + self.passives = {} | ||
| 50 | + self.buffs = {} | ||
| 51 | + self:initData(data) | ||
| 52 | + self:initAfter(data) | ||
| 53 | +end | ||
| 54 | + | ||
| 44 | function BaseObject:beforeTurn() | 55 | function BaseObject:beforeTurn() |
| 45 | for _, buff in ipairs(self.buffs) do | 56 | for _, buff in ipairs(self.buffs) do |
| 46 | buff:beforeTurn() | 57 | buff:beforeTurn() |
| @@ -377,6 +388,8 @@ function BaseObject:getDB() | @@ -377,6 +388,8 @@ function BaseObject:getDB() | ||
| 377 | local db = {} | 388 | local db = {} |
| 378 | db.hpMax = self.hpMax | 389 | db.hpMax = self.hpMax |
| 379 | db.hp = self.hp | 390 | db.hp = self.hp |
| 391 | + db.mpMax = self.mpMax | ||
| 392 | + db.mp = self.mp | ||
| 380 | local baseAttr = {"atk", "miss", "hit", "def"} | 393 | local baseAttr = {"atk", "miss", "hit", "def"} |
| 381 | for _, field in pairs(baseAttr) do | 394 | for _, field in pairs(baseAttr) do |
| 382 | db[field] = self[field] | 395 | db[field] = self[field] |