Commit 39a6e08b788a76ce59ce7b83ce224e8e498127b5
1 parent
b96f8839
冒险战斗内逻辑调整
Showing
7 changed files
with
100 additions
and
23 deletions
Show diff stats
src/GlobalVar.lua
src/ProtocolCode.lua
src/actions/AdvAction.lua
... | ... | @@ -97,6 +97,15 @@ 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() | |
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 | 111 | return _M |
103 | 112 | \ No newline at end of file | ... | ... |
src/adv/Adv.lua
... | ... | @@ -699,7 +699,7 @@ end |
699 | 699 | |
700 | 700 | --战斗 普通攻击 |
701 | 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 | 703 | return true |
704 | 704 | end |
705 | 705 | |
... | ... | @@ -881,7 +881,16 @@ function Adv:clickBlock(roomId, blockId, params) |
881 | 881 | end |
882 | 882 | end |
883 | 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 | 894 | self:backBlockChange(roomId, blockId) |
886 | 895 | self:afterRound() |
887 | 896 | end |
... | ... | @@ -889,6 +898,22 @@ function Adv:clickBlock(roomId, blockId, params) |
889 | 898 | return status |
890 | 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 | 918 | function Adv:useItem(itemId, count, target) |
894 | 919 | count = count or 1 |
... | ... | @@ -1049,6 +1074,10 @@ function Adv:backDead(enemyId) |
1049 | 1074 | self:pushBackEvent(AdvBackEventType.Dead, {enemyId = enemyId}) |
1050 | 1075 | end |
1051 | 1076 | |
1077 | +function Adv:backTurnEnd() | |
1078 | + self:pushBackEvent(AdvBackEventType.TurnEnd, {}) | |
1079 | +end | |
1080 | + | |
1052 | 1081 | |
1053 | 1082 | function Adv:scoreChange(scoreType, pms) |
1054 | 1083 | local cutTypes = {} |
... | ... | @@ -1100,6 +1129,7 @@ function Adv:afterRound() |
1100 | 1129 | if self.battle then |
1101 | 1130 | self.battle:afterRound() |
1102 | 1131 | end |
1132 | + -- TODO 房间回合事件 | |
1103 | 1133 | end |
1104 | 1134 | |
1105 | 1135 | function Adv:saveDB() | ... | ... |
src/adv/AdvBattle.lua
... | ... | @@ -6,6 +6,7 @@ function Battle:ctor(adv) |
6 | 6 | self.adv = adv |
7 | 7 | self.player = nil --玩家 |
8 | 8 | self.isNewPlayer = false |
9 | + self.battleEnemyId = nil | |
9 | 10 | self.enemys = {} --怪 |
10 | 11 | self:initPlayer() |
11 | 12 | self:initEnemys() |
... | ... | @@ -20,6 +21,7 @@ function Battle:initAfter() |
20 | 21 | for _, enemy in pairs(self.enemys) do |
21 | 22 | enemy:initAfter(self.adv.rooms[enemy.roomId].blocks[enemy.blockId].event.enemy) |
22 | 23 | end |
24 | + self.battleEnemyId = self.adv.advTeam.enemyId | |
23 | 25 | end |
24 | 26 | |
25 | 27 | function Battle:initPlayer() |
... | ... | @@ -93,36 +95,63 @@ function Battle:getEnemyById(id) |
93 | 95 | end |
94 | 96 | end |
95 | 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 | 116 | local enemy = self:getEnemy(roomId, blockId) |
99 | 117 | if enemy then |
118 | + self.battleEnemyId = enemy.id | |
100 | 119 | self.player:battleBegin() |
101 | 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 | 144 | end |
118 | 145 | end |
119 | ---战斗内回合逻辑 | |
120 | -function Battle:doBattleTurn(atkPlayer, hurtPlayer) | |
146 | + | |
147 | +--战斗内角色回合逻辑 | |
148 | +function Battle:doPlayerTurn(atkPlayer, hurtPlayer) | |
121 | 149 | atkPlayer:beforeTurn() |
122 | 150 | hurtPlayer:hurt(atkPlayer:getHurtValue(), atkPlayer, {hurtType = 1}) |
123 | 151 | atkPlayer:afterTurn() |
124 | 152 | atkPlayer:clearTurn() |
125 | 153 | end |
154 | + | |
126 | 155 | --触发全员被动技能 |
127 | 156 | function Battle:triggerPassive(condType, params) |
128 | 157 | self.player:triggerPassive(condType, params) |
... | ... | @@ -171,6 +200,7 @@ function Battle:getDB() |
171 | 200 | local block = self.adv.rooms[enemy.roomId].blocks[enemy.blockId] |
172 | 201 | block.event.enemy = enemy:getDB() |
173 | 202 | end |
203 | + self.adv.advTeam.enemyId = self.battleEnemyId | |
174 | 204 | end |
175 | 205 | |
176 | 206 | return Battle |
177 | 207 | \ No newline at end of file | ... | ... |
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 |
... | ... | @@ -377,6 +381,8 @@ function BaseObject:getDB() |
377 | 381 | local db = {} |
378 | 382 | db.hpMax = self.hpMax |
379 | 383 | db.hp = self.hp |
384 | + db.mpMax = self.mpMax | |
385 | + db.mp = self.mp | |
380 | 386 | local baseAttr = {"atk", "miss", "hit", "def"} |
381 | 387 | for _, field in pairs(baseAttr) do |
382 | 388 | db[field] = self[field] | ... | ... |