Commit 1f3087de2202bfcfe80881518f3348e7dabb4c31

Authored by gaofengduan
2 parents 91170e1a a88a35fd

Merge branch 'master' into feng/equip

src/GlobalVar.lua
... ... @@ -101,6 +101,7 @@ AdvBackEventType = {
101 101 Dead = 11, --怪死亡
102 102 DefChange = 12, -- 防御变化
103 103 Passive = 13, -- 獲得被動
  104 + TurnEnd = 14, -- 回合结束
104 105 }
105 106  
106 107 AdvScoreType = {
... ...
src/ProtocolCode.lua
... ... @@ -32,6 +32,7 @@ actionCodes = {
32 32 Adv_useItemRpc = 154,
33 33 Adv_useSkillRpc = 155,
34 34 Adv_exitAdvRpc = 156,
  35 + Adv_nextTurnRpc = 157,
35 36  
36 37 Hero_loadInfos = 201,
37 38 Hero_updateProperty = 202,
... ...
src/actions/AdvAction.lua
... ... @@ -97,6 +97,18 @@ function _M.exitAdvRpc(agent, data)
97 97 return true
98 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 114 return _M
103 115 \ No newline at end of file
... ...
src/adv/Adv.lua
... ... @@ -442,6 +442,7 @@ function Adv:ctor(owner)
442 442 self.advTeam = self.owner:getProperty("advTeam") --这个变量置空使用 table.clear
443 443 self:clear()
444 444 self.backEvents = {} --发给客户端的事件组
  445 + self.tempBackEvents = {} --发给客户端的事件组(缓存)
445 446 end
446 447  
447 448 -- 清空自己组织的数据
... ... @@ -699,7 +700,7 @@ end
699 700  
700 701 --战斗 普通攻击
701 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 704 return true
704 705 end
705 706  
... ... @@ -881,7 +882,16 @@ function Adv:clickBlock(roomId, blockId, params)
881 882 end
882 883 end
883 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 895 self:backBlockChange(roomId, blockId)
886 896 self:afterRound()
887 897 end
... ... @@ -889,6 +899,22 @@ function Adv:clickBlock(roomId, blockId, params)
889 899 return status
890 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 919 function Adv:useItem(itemId, count, target)
894 920 count = count or 1
... ... @@ -1049,6 +1075,10 @@ function Adv:backDead(enemyId)
1049 1075 self:pushBackEvent(AdvBackEventType.Dead, {enemyId = enemyId})
1050 1076 end
1051 1077  
  1078 +function Adv:backTurnEnd()
  1079 + self:pushBackEvent(AdvBackEventType.TurnEnd, {})
  1080 +end
  1081 +
1052 1082  
1053 1083 function Adv:scoreChange(scoreType, pms)
1054 1084 local cutTypes = {}
... ... @@ -1091,6 +1121,8 @@ end
1091 1121  
1092 1122 function Adv:popBackEvents()
1093 1123 local events = self.backEvents
  1124 + -- TODO 缓存数据需要分类,防止发错,暂时只有战斗,可以不分
  1125 + self.tempBackEvents = events
1094 1126 self.backEvents = {}
1095 1127 return events
1096 1128 end
... ... @@ -1100,6 +1132,7 @@ function Adv:afterRound()
1100 1132 if self.battle then
1101 1133 self.battle:afterRound()
1102 1134 end
  1135 + -- TODO 房间回合事件
1103 1136 end
1104 1137  
1105 1138 function Adv:saveDB()
... ...
src/adv/AdvBattle.lua
... ... @@ -6,7 +6,9 @@ function Battle:ctor(adv)
6 6 self.adv = adv
7 7 self.player = nil --玩家
8 8 self.isNewPlayer = false
  9 + self.enemy = nil
9 10 self.enemys = {} --怪
  11 + self.tempData = {} -- 临时回合数据
10 12 self:initPlayer()
11 13 self:initEnemys()
12 14 self:initAfter()
... ... @@ -20,6 +22,10 @@ function Battle:initAfter()
20 22 for _, enemy in pairs(self.enemys) do
21 23 enemy:initAfter(self.adv.rooms[enemy.roomId].blocks[enemy.blockId].event.enemy)
22 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 29 end
24 30  
25 31 function Battle:initPlayer()
... ... @@ -93,36 +99,71 @@ function Battle:getEnemyById(id)
93 99 end
94 100 end
95 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 121 local enemy = self:getEnemy(roomId, blockId)
99 122 if enemy then
  123 + self.enemy = enemy
100 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 134 end
118 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 161 atkPlayer:beforeTurn()
122 162 hurtPlayer:hurt(atkPlayer:getHurtValue(), atkPlayer, {hurtType = 1})
123 163 atkPlayer:afterTurn()
124 164 atkPlayer:clearTurn()
125 165 end
  166 +
126 167 --触发全员被动技能
127 168 function Battle:triggerPassive(condType, params)
128 169 self.player:triggerPassive(condType, params)
... ... @@ -157,15 +198,29 @@ function Battle:afterRound()
157 198 else
158 199 self.player:hurt(self.player.hpMax / 10, nil, {hurtType = 4})
159 200 end
160   -
161   -
162 201 if self.player.isDead then
163 202 self.adv:over(false)
164 203 end
165 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 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 224 self.adv.advTeam.player = self.player:getDB()
170 225 for _, enemy in ipairs(self.enemys) do
171 226 local block = self.adv.rooms[enemy.roomId].blocks[enemy.blockId]
... ...
src/adv/AdvBuff.lua
... ... @@ -106,7 +106,7 @@ local BuffFactory = {
106 106 end
107 107 end,
108 108 [Buff.ATTR_CHANGE] = function(_Buff)
109   - local attrName = AttsEnumEx[self.buffData.effectValue3]
  109 + local attrName = AttsEnumEx[_Buff.buffData.effectValue3]
110 110 commonAttr(_Buff, attrName)
111 111 end,
112 112 [Buff.BACK_HURT] = function(_Buff)
... ...
src/adv/AdvPassive.lua
... ... @@ -202,7 +202,7 @@ function Passive:ctor(owner, data)
202 202 self.count = data.count or self.passiveData.count --触发剩余次数
203 203 self.delay = data.delay or self.passiveData.delayRound --触发延迟回合数
204 204 self.turn = 0 --战斗内回合数
205   - self.delayturn = self.passiveData.delayTurn --战斗内延迟回合数
  205 + self.delayTurn = self.passiveData.delayTurn --战斗内延迟回合数
206 206  
207 207 self.effects = self.passiveData.effect:toTableArray(true)
208 208 self.filters = {}
... ...
src/adv/AdvPlayer.lua
... ... @@ -15,11 +15,15 @@ function BaseObject:ctor(battle)
15 15 self.passives = {} --固有技能
16 16 self.buffs = {} --buff
17 17 self.isDead = false
  18 + self.mpMax = 0
  19 + self.mp = 0
18 20 end
19 21 --初始化角色
20 22 function BaseObject:initData(data)
21 23 self.hpMax = data.hpMax or data.hp
22 24 self.hp = data.hp
  25 + self.mpMax = data.mpMax or data.mp
  26 + self.mp = data.mp
23 27 --可变化的值
24 28 self.atk = data.atk
25 29 self.miss = data.miss
... ... @@ -41,6 +45,13 @@ function BaseObject:initAfter(data)
41 45 end
42 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 55 function BaseObject:beforeTurn()
45 56 for _, buff in ipairs(self.buffs) do
46 57 buff:beforeTurn()
... ... @@ -377,6 +388,8 @@ function BaseObject:getDB()
377 388 local db = {}
378 389 db.hpMax = self.hpMax
379 390 db.hp = self.hp
  391 + db.mpMax = self.mpMax
  392 + db.mp = self.mp
380 393 local baseAttr = {"atk", "miss", "hit", "def"}
381 394 for _, field in pairs(baseAttr) do
382 395 db[field] = self[field]
... ...