19d8c401
zhouhaihai
大小写
|
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
|
self.enemys = {} --怪
|
e459a5fc
suhongyang
战斗回合检查同步以及回合数据缓存
|
10
|
self.tempData = {} -- 临时回合数据
|
46fac6f1
zhouahaihai
酱料
|
11
12
13
|
self:initPlayer()
self:initEnemys()
self:initAfter()
|
02c4de8d
zhouahaihai
增加 固有技
|
14
15
16
|
if self.isNewPlayer then
self.player:triggerPassive(Passive.BORN_ONCE)
end
|
46fac6f1
zhouahaihai
酱料
|
17
18
19
20
21
22
23
|
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
|
46fac6f1
zhouahaihai
酱料
|
24
|
end
|
b53593b5
zhouhaihai
羁绊加成
|
25
26
27
28
29
30
31
32
33
|
--[[
队伍总属性 = 基础属性 + 等级 × 成长率
基础属性: 固定属性,与章节、队伍够成、养成无关,由策划给出
等级: 根据进入时的关卡,获得一个【初始等级】;消灭怪物获得经验后,累计N点会提升等级
羁绊加成: 加成条件与“战斗”相同,加成目标改为【冒险队】
成长率: 由【队伍总生存力】决定
成长率 =(总生存力 / 80)^0.52 + INT(总角色等级 / 50)* 1
--]]
|
46fac6f1
zhouahaihai
酱料
|
34
35
36
37
|
function Battle:initPlayer()
if not next(self.adv.advTeam.heros) then return end
if not self.adv.advTeam.player then
|
46fac6f1
zhouahaihai
酱料
|
38
39
|
local player = {}
player.passives = {}
|
b53593b5
zhouhaihai
羁绊加成
|
40
|
local heroLevel = 0
|
46fac6f1
zhouahaihai
酱料
|
41
|
for slot, heroId in pairs(self.adv.advTeam.heros) do
|
b53593b5
zhouhaihai
羁绊加成
|
42
43
44
|
local hero = self.adv.owner.heros[heroId]
if hero then
heroLevel = heroLevel + hero:getProperty("level")
|
46fac6f1
zhouahaihai
酱料
|
45
46
|
local advSkillId = csvdb["unitCsv"][self.adv.owner.heros[heroId]:getSkinId()]["adv"]
if advSkillId > 1000 then
|
b53593b5
zhouhaihai
羁绊加成
|
47
|
table.insert(player.passives, {id = advSkillId, level = hero:getSkillLevel(4)})
|
46fac6f1
zhouahaihai
酱料
|
48
49
50
|
end
end
end
|
b53593b5
zhouhaihai
羁绊加成
|
51
|
player.growth = (self.adv.owner:getRealBattleValue(self.adv.advTeam.heros) / 80) ^ 0.52 + math.floor(heroLevel / 50) / 50
|
386ca58e
zhouhaihai
优化log
|
52
|
player.level = 1
|
b53593b5
zhouhaihai
羁绊加成
|
53
|
player.exp = 0
|
3b0526d2
zhouhaihai
冒险demo
|
54
|
player.sp = 100
|
a41b9076
zhouhaihai
增加羁绊方法
|
55
|
local activeRelation = self.adv.owner:getHeroActiveRelation()
|
b53593b5
zhouhaihai
羁绊加成
|
56
57
58
|
local baseAttr = csvdb["adv_unitCsv"][math.floor(self.adv.advInfo.chapter / 100)]
for _, attr in pairs(AttsEnumEx) do
if baseAttr[attr] then
|
9812cb83
zhouhaihai
冒险队属性
|
59
|
player[attr] = baseAttr[attr] + baseAttr[attr] * player.growth * (player.level - 1)
|
b53593b5
zhouhaihai
羁绊加成
|
60
61
|
end
end
|
1b35c0a2
zhouhaihai
冒险
|
62
|
player.hpMax = player.hp or 0
|
46fac6f1
zhouahaihai
酱料
|
63
|
self.adv.advTeam.player = player
|
02c4de8d
zhouahaihai
增加 固有技
|
64
|
self.isNewPlayer = true
|
46fac6f1
zhouahaihai
酱料
|
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
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
冒险增加防御属性
|
86
|
enemy.def = enemyCsv.def + enemyCsv.leveldef * self.adv.advInfo.level
|
46fac6f1
zhouahaihai
酱料
|
87
|
enemy.passives = {}
|
de3b786f
zhouhaihai
字段换名字
|
88
|
for _, id in ipairs(enemyCsv.mapPassive:toArray(true, "=")) do
|
46fac6f1
zhouahaihai
酱料
|
89
90
91
|
table.insert(enemy.passives, {id = id})
end
block.event.enemy = enemy
|
46fac6f1
zhouahaihai
酱料
|
92
|
end
|
02c4de8d
zhouahaihai
增加 固有技
|
93
94
95
|
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
酱料
|
96
97
98
99
100
|
end
end
function Battle:getEnemy(roomId, blockId)
for _, enemy in ipairs(self.enemys) do
|
36c30c5c
zhouahaihai
冒险
|
101
|
if enemy.roomId == roomId and enemy.blockId == blockId then
|
46fac6f1
zhouahaihai
酱料
|
102
103
104
105
106
107
108
109
110
111
112
113
|
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
|
39a6e08b
suhongyang
冒险战斗内逻辑调整
|
114
115
116
117
118
119
|
function Battle:getRBByEnemyId(enemyId)
local enemy = self:getEnemyById(enemyId)
return enemy.roomId, enemy.blockId
end
|
39a6e08b
suhongyang
冒险战斗内逻辑调整
|
120
|
|
46fac6f1
zhouahaihai
酱料
|
121
122
|
--触发全员被动技能
function Battle:triggerPassive(condType, params)
|
02c4de8d
zhouahaihai
增加 固有技
|
123
124
125
126
|
self.player:triggerPassive(condType, params)
for _, enemy in ipairs(self.enemys) do
enemy:triggerPassive(condType, params)
end
|
46fac6f1
zhouahaihai
酱料
|
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
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
冒险 完善
|
149
|
|
46fac6f1
zhouahaihai
酱料
|
150
|
if self.player.isDead then
|
4b7c7c96
zhouahaihai
增加 清空 挂机 冒险gm 角色经验
|
151
|
self.adv:over(false)
|
46fac6f1
zhouahaihai
酱料
|
152
153
154
|
end
end
|
e459a5fc
suhongyang
战斗回合检查同步以及回合数据缓存
|
155
|
|
12f7b52c
zhouhaihai
冒险战斗
|
156
157
158
159
160
161
162
163
164
165
166
167
168
|
function Battle:battleBegin(roomId, blockId, params)
local enemy = self:getEnemy(roomId, blockId)
if not enemy then return end
local player = params.player
-- 玩家没死就是怪死了
if player.hp > 0 then
enemy:hurt(enemy.hp, self.player, {hurtType = 5})
end
self.player:hurt(math.max(0, math.ceil(self.player.hp - player.hp)), enemy, {hurtType = 5}) --战斗血量只会变少
self.player:changeSp(math.min(0, math.floor(player.sp - self.player.sp)) , 0) --战斗魔力只会变少
end
|
46fac6f1
zhouahaihai
酱料
|
169
170
|
--写入数据
function Battle:getDB()
|
46fac6f1
zhouahaihai
酱料
|
171
172
173
174
175
|
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
|
46fac6f1
zhouahaihai
酱料
|
176
177
|
end
|
36c30c5c
zhouahaihai
冒险
|
178
|
return Battle
|