36c30c5c
zhouahaihai
冒险
|
1
|
local Player, Enemy = table.unpack(require "adv.advPlayer")
|
46fac6f1
zhouahaihai
酱料
|
2
|
local Buff = require "adv.AdvBuff"
|
32bca13b
zhouahaihai
bug
|
3
|
local Passive = require "adv.AdvPassive"
|
36c30c5c
zhouahaihai
冒险
|
4
|
local Battle = class("Battle")
|
46fac6f1
zhouahaihai
酱料
|
5
6
7
|
function Battle:ctor(adv)
self.adv = adv
self.player = nil --玩家
|
02c4de8d
zhouahaihai
增加 固有技
|
8
|
self.isNewPlayer = false
|
46fac6f1
zhouahaihai
酱料
|
9
10
11
12
|
self.enemys = {} --怪
self:initPlayer()
self:initEnemys()
self:initAfter()
|
02c4de8d
zhouahaihai
增加 固有技
|
13
14
15
|
if self.isNewPlayer then
self.player:triggerPassive(Passive.BORN_ONCE)
end
|
46fac6f1
zhouahaihai
酱料
|
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
end
function Battle:initAfter()
self.player:initAfter(self.adv.advTeam.player)
for _, enemy in pairs(self.enemys) do
enemy:initAfter(self.adv.rooms[enemy.roomId].blocks[enemy.blockId].event.enemy)
end
end
function Battle:initPlayer()
if not next(self.adv.advTeam.heros) then return end
if not self.adv.advTeam.player then
local hp = 0
local player = {}
player.passives = {}
for slot, heroId in pairs(self.adv.advTeam.heros) do
if self.adv.owner.heros[heroId] then
hp = hp + self.adv.owner.heros[heroId]:getProperty("battleV")
local advSkillId = csvdb["unitCsv"][self.adv.owner.heros[heroId]:getSkinId()]["adv"]
if advSkillId > 1000 then
table.insert(player.passives, {id = advSkillId, level = self.adv.owner.heros[heroId]:getSkillLevel(4)})
end
end
end
player.hp = hp
|
384bb077
zhouahaihai
挂机
|
41
|
player.atk = tonumber(string.format("%0.0f", player.hp * 0.1)) --todo 系数是临时的
|
e996b82a
zhouahaihai
冒险增加防御属性
|
42
|
player.def = 0
|
46fac6f1
zhouahaihai
酱料
|
43
44
45
|
player.miss = 0
player.hit = 100
self.adv.advTeam.player = player
|
02c4de8d
zhouahaihai
增加 固有技
|
46
|
self.isNewPlayer = true
|
46fac6f1
zhouahaihai
酱料
|
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
end
self.player = Player.new(self, self.adv.advTeam.player)
end
function Battle:initEnemys()
for _, room in pairs(self.adv.rooms) do
for _, block in pairs(room.blocks) do
self:addEnemy(room, block)
end
end
end
function Battle:addEnemy(room, block)
if block.event and (block.event.etype == AdvEventType.BOSS or block.event.etype == AdvEventType.Monster) then
if not block.event.enemy then
local enemyCsv = csvdb["event_monsterCsv"][block.event.id]
local enemy = {}
enemy.hp = enemyCsv.hp + enemyCsv.levelhp * self.adv.advInfo.level
enemy.atk = enemyCsv.atk + enemyCsv.levelatk * self.adv.advInfo.level
enemy.hit = enemyCsv.hit + enemyCsv.levelhit * self.adv.advInfo.level
enemy.miss = enemyCsv.miss + enemyCsv.levelmiss * self.adv.advInfo.level
|
e996b82a
zhouahaihai
冒险增加防御属性
|
68
|
enemy.def = enemyCsv.def + enemyCsv.leveldef * self.adv.advInfo.level
|
46fac6f1
zhouahaihai
酱料
|
69
70
71
72
73
|
enemy.passives = {}
for _, id in ipairs(enemyCsv.passive:toArray(true, "=")) do
table.insert(enemy.passives, {id = id})
end
block.event.enemy = enemy
|
46fac6f1
zhouahaihai
酱料
|
74
|
end
|
02c4de8d
zhouahaihai
增加 固有技
|
75
76
77
|
local player = Enemy.new(self, block.event.mId or 999, block.event.id, room.roomId, block.blockId, not block.isOpen, block.event.enemy)
table.insert(self.enemys, player)
return player
|
46fac6f1
zhouahaihai
酱料
|
78
79
80
81
82
|
end
end
function Battle:getEnemy(roomId, blockId)
for _, enemy in ipairs(self.enemys) do
|
36c30c5c
zhouahaihai
冒险
|
83
|
if enemy.roomId == roomId and enemy.blockId == blockId then
|
46fac6f1
zhouahaihai
酱料
|
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
return enemy
end
end
end
function Battle:getEnemyById(id)
for _, enemy in ipairs(self.enemys) do
if enemy.id == id then
return enemy
end
end
end
--普通攻击
function Battle:playerAtk(roomId, blockId)
local enemy = self:getEnemy(roomId, blockId)
if enemy then
|
821f2b60
suhongyang
冒险战斗完善,增加battlebe...
|
100
101
|
self.player:battleBegin()
enemy:battleBegin()
|
bedca62d
zhouahaihai
冒险
|
102
|
while not enemy.isDead and not self.player.isDead do
|
65de8cf1
suhongyang
被动逻辑进一步修缮
|
103
|
-- 玩家先出手
|
bedca62d
zhouahaihai
冒险
|
104
|
self.adv:backAtk(nil, enemy.id)
|
7c55db1f
suhongyang
Buff逻辑完善,buff生效次数...
|
105
|
self:doBattleTurn(self.player, enemy)
|
bedca62d
zhouahaihai
冒险
|
106
107
108
|
--是否无法反击
if not enemy.isDead and not enemy:hadBuff(Buff.CANT_BACK_ATK) then
self.adv:backAtk(enemy.id, nil)
|
7c55db1f
suhongyang
Buff逻辑完善,buff生效次数...
|
109
|
self:doBattleTurn(enemy, self.player)
|
bedca62d
zhouahaihai
冒险
|
110
|
end
|
46fac6f1
zhouahaihai
酱料
|
111
|
end
|
0d405dc3
suhongyang
Buff生命周期调整,被动加buf...
|
112
113
114
115
116
|
if not self.player.isDead then
self.player:battleEnd()
elseif not enemy.isDead then
enemy:battleEnd()
end
|
46fac6f1
zhouahaihai
酱料
|
117
118
|
end
end
|
7c55db1f
suhongyang
Buff逻辑完善,buff生效次数...
|
119
120
121
122
123
124
125
|
--战斗内回合逻辑
function Battle:doBattleTurn(atkPlayer, hurtPlayer)
atkPlayer:beforeTurn()
hurtPlayer:hurt(atkPlayer:getHurtValue(), atkPlayer, {hurtType = 1})
atkPlayer:afterTurn()
atkPlayer:clearTurn()
end
|
46fac6f1
zhouahaihai
酱料
|
126
127
|
--触发全员被动技能
function Battle:triggerPassive(condType, params)
|
02c4de8d
zhouahaihai
增加 固有技
|
128
129
130
131
|
self.player:triggerPassive(condType, params)
for _, enemy in ipairs(self.enemys) do
enemy:triggerPassive(condType, params)
end
|
46fac6f1
zhouahaihai
酱料
|
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
end
--回合
function Battle:afterRound()
self.player:afterRound()
table.sort(self.enemys, function(e1, e2)
return e1.id < e2.id
end)
for _, enemy in ipairs(self.enemys) do
enemy:afterRound()
end
self.player:clearRound()
for _, enemy in ipairs(self.enemys) do
enemy:clearRound()
end
for i = #self.enemys, 1, -1 do
if self.enemys[i].isDead then
self.adv:enemyDead(self.enemys[i].roomId, self.enemys[i].blockId)
self.enemys[i]:clear()
table.remove(self.enemys, i)
end
end
|
ec87b4a5
zhouahaihai
冒险 完善
|
154
155
156
157
158
159
160
161
|
if self.adv.advInfo.power > 0 then
self.adv:changePower(-1)
else
self.player:hurt(self.player.hpMax / 10, nil, {hurtType = 4})
end
|
46fac6f1
zhouahaihai
酱料
|
162
|
if self.player.isDead then
|
4b7c7c96
zhouahaihai
增加 清空 挂机 冒险gm 角色经验
|
163
|
self.adv:over(false)
|
46fac6f1
zhouahaihai
酱料
|
164
165
166
167
168
169
170
171
172
173
174
175
|
end
end
--写入数据
function Battle:getDB()
self.adv.advTeam.player = self.player:getDB()
for _, enemy in ipairs(self.enemys) do
local block = self.adv.rooms[enemy.roomId].blocks[enemy.blockId]
block.event.enemy = enemy:getDB()
end
end
|
36c30c5c
zhouahaihai
冒险
|
176
|
return Battle
|