Commit 36c30c5c9892f0aa4b299c080f1913a650d2213e

Authored by zhouahaihai
1 parent 46fac6f1

冒险

src/GlobalVar.lua
... ... @@ -55,6 +55,7 @@ ItemId = {
55 55 Diamond = 3, -- 钻石
56 56 BreakCost = 4, -- 突破材料
57 57 HeroFC = {700, 701, 702, 703}, -- 通用角色碎片
  58 + AdvKey = 80, -- 冒险钥匙
58 59 }
59 60  
60 61 --客户端不需要知道这个
... ... @@ -78,14 +79,13 @@ AdvEventType = {
78 79 }
79 80  
80 81 AdvBackEventType = {
81   - Reward = 1 --奖励
82   - HpChange = 2 --血量改变
83   - AtkChange = 3 --攻击改变
84   - Buff = 4 --buff 改变
85   - Skill = 5 --释放技能
86   - Atk = 6 --攻击动作
87   - Next = 7 --进入下一层
88   - End = 8 -- 结束
89   - BlockChange = 9 -- 块改变
90   -
  82 + Reward = 1, --奖励
  83 + HpChange = 2, --血量改变
  84 + AtkChange = 3, --攻击改变
  85 + Buff = 4, --buff 改变
  86 + Skill = 5, --释放技能
  87 + Atk = 6, --攻击动作
  88 + Next = 7, --进入下一层
  89 + End = 8, -- 结束
  90 + BlockChange = 9, -- 块改变
91 91 }
92 92 \ No newline at end of file
... ...
src/adv/Adv.lua
... ... @@ -243,7 +243,7 @@ local function randomAdvMap(role, chapterId, level, notNotify)
243 243 print("这个地图没有钥匙!!! mapId : " .. mapId)
244 244 else
245 245 local event = monsterEvents[math.randomInt(1, #monsterEvents)]
246   - event.item = {1, 1} --掉落钥匙 --todo
  246 + event.item = {ItemId.AdvKey, 1} --掉落钥匙 --todo
247 247 end
248 248 end
249 249 end
... ... @@ -269,11 +269,11 @@ function Block:open(adv, room)
269 269 randomFunc[AdvEventType.Monster] = function()
270 270 self.event.mId = adv.advInfo.enemyId --给怪一个有序id 回合逻辑时使用
271 271 adv.advInfo.enemyId = adv.advInfo.enemyId + 1
272   - local enemy = self.battle:getEnemy(room.roomId, self.blockId)
  272 + local enemy = adv.battle:getEnemy(room.roomId, self.blockId)
273 273 if enemy then
274 274 enemy:unlock(self.event.mId)
275 275 else
276   - self.battle:addEnemy(room, self)
  276 + adv.battle:addEnemy(room, self)
277 277 end
278 278 end
279 279 randomFunc[AdvEventType.BOSS] = randomFunc[AdvEventType.Monster]
... ... @@ -298,7 +298,7 @@ function Block:open(adv, room)
298 298 end
299 299 end
300 300 --建筑
301   - [AdvEventType.Build] = function()
  301 + randomFunc[AdvEventType.Build] = function()
302 302 local data = csvdb["event_buildingCsv"][self.event.id]
303 303 self.event.effect = data["range"]:randWeight(true) --随出建筑效果
304 304 if self.event.effect[1] == 1 then --获得某道具
... ... @@ -308,7 +308,7 @@ function Block:open(adv, room)
308 308 end
309 309 end
310 310 --抉择点
311   - [AdvEventType.Choose] = function()
  311 + randomFunc[AdvEventType.Choose] = function()
312 312 local data = csvdb["event_chooseCsv"][self.event.id]
313 313 self.event.effect = {}
314 314 for i = 1, 2 do
... ... @@ -325,7 +325,7 @@ function Block:open(adv, room)
325 325 randomFunc[self.event.etype]()
326 326 end
327 327 end
328   - self.isOpne = true
  328 + self.isOpen = true
329 329 end
330 330  
331 331 local Room = class("Room")
... ... @@ -374,14 +374,18 @@ end
374 374 function Room:openBlock(block, adv)
375 375 if self.blocks[block.blockId] ~= block then return end
376 376 if block.isOpen == true then return end
377   - block:open(adv, self)
378   - local allOpen = true
379   - if not self.isBossRoom then
  377 + if self.isBossRoom then
380 378 for _, _block in pairs(self.blocks) do
381   - if not _block.isOpen then
382   - allOpen = false
383   - break
384   - end
  379 + _block:open(adv, self)
  380 + end
  381 + else
  382 + block:open(adv, self)
  383 + end
  384 + local allOpen = true
  385 + for _, _block in pairs(self.blocks) do
  386 + if not _block.isOpen then
  387 + allOpen = false
  388 + break
385 389 end
386 390 end
387 391  
... ... @@ -413,7 +417,7 @@ function Adv:ctor(owner)
413 417 self.advInfo = self.owner:getProperty("advInfo") --这个变量置空使用 table.clear
414 418 self.advTeam = self.owner:getProperty("advTeam") --这个变量置空使用 table.clear
415 419 self:clear()
416   - self.events = {} --发给客户端的事件组
  420 + self.backEvents = {} --发给客户端的事件组
417 421 end
418 422  
419 423 -- 清空自己组织的数据
... ... @@ -485,9 +489,10 @@ end
485 489  
486 490 -- 随机地图
487 491 function Adv:initByChapter(chapterId, level, notNotify)
  492 + level = level or 1
488 493 randomAdvMap(self.owner, chapterId, level, notNotify)
489 494 self:initByInfo() --初始化
490   - role:updateProperties({advInfo = self.advInfo, advTeam = self.advTeam}, notNotify)
  495 + self.owner:updateProperties({advInfo = self.advInfo, advTeam = self.advTeam}, notNotify)
491 496 end
492 497  
493 498 --获取,某个位置上的 room 和 block
... ... @@ -629,7 +634,7 @@ end
629 634  
630 635 --事件点击处理
631 636 local function clickOut(self, room, block, params)
632   - if self:cost({[1] = 1}, {}) then --todo 钥匙id
  637 + if self:cost({[ItemId.AdvKey] = 1}, {}) then
633 638 if self.advInfo.level >= csvdb["adv_chapterCsv"][self.advInfo.chapter].limitlevel then --关卡结束
634 639 self:over(true)
635 640 else
... ... @@ -781,39 +786,40 @@ function Adv:clickBlock(roomId, blockId, params)
781 786 local block = room.blocks[blockId]
782 787 if not block then return end
783 788  
784   - local canOpen = false --如果未开放是否可以开放
785   - local hadMonster = false -- 周围是否有解锁的怪未击败
786   - for _, one in ipairs(self:getAroundBlocks(room, block)) do
787   - local _room, _block = one[1], one[2]
788   - if _block.isOpen then canOpen = true end
789   - if _block.isOpen and _block.event and (_block.event.etype == AdvEventType.BOSS or _block.event.etype == AdvEventType.Monster) then
790   - hadMonster = true
791   - end
792   - end
793 789 local status = false
  790 + local clickEvent = false
794 791 if not block.isOpen then
  792 + local canOpen = false --如果未开放是否可以开放
  793 + local hadMonster = false -- 周围是否有解锁的怪未击败
  794 + for _, one in ipairs(self:getAroundBlocks(room, block)) do
  795 + local _room, _block = one[1], one[2]
  796 + if _block.isOpen then canOpen = true end
  797 + if _block.isOpen and _block.event and (_block.event.etype == AdvEventType.BOSS or _block.event.etype == AdvEventType.Monster) then
  798 + hadMonster = true
  799 + end
  800 + end
795 801 if canOpen and not hadMonster then --开放
796 802 room:openBlock(block, self)
797 803 status = true
798 804 end
799 805 else
  806 + clickEvent = true
800 807 --点了空地
801 808 if not block.event then
802 809 return
803 810 end
804 811 --可点击的事件
805   - if not hadMonster and not room.isBossRoom then
  812 + if not room.isBossRoom or block.event.etype == AdvEventType.BOSS then
806 813 if eventCallFunc[block.event.etype] then
807 814 status = eventCallFunc[block.event.etype](self, room, block, params)
808 815 end
809 816 end
810 817 end
811   - if status and block.event.etype ~= AdvEventType.Out then --出去了就不计算回合了
  818 + if status and (not clickEvent or (not block.event or block.event.etype ~= AdvEventType.Out)) then --出去了就不计算回合了
812 819 self:backBlockChange(roomId, blockId)
813 820 self:afterRound()
814 821 end
815   - self.battle:getDB()
816   - role:updateProperties({advInfo = self.advInfo, advTeam = self.advTeam})
  822 + self:saveDB()
817 823 return status
818 824 end
819 825  
... ... @@ -840,8 +846,7 @@ function Adv:useItem(itemId, count, target)
840 846 end
841 847  
842 848 self:afterRound()
843   - self.battle:getDB()
844   - role:updateProperties({advInfo = self.advInfo, advTeam = self.advTeam})
  849 + self:saveDB()
845 850 return true
846 851 end
847 852  
... ... @@ -870,20 +875,23 @@ function Adv:useSkill(skillId, target)
870 875 end
871 876  
872 877 self:afterRound()
873   - self.battle:getDB()
874   - role:updateProperties({advInfo = self.advInfo, advTeam = self.advTeam})
  878 + self:saveDB()
875 879 return true
876 880 end
877 881  
878 882 --敌人死亡
879 883 function Adv:enemyDead(roomId, blockId)
880   - local block = self.rooms[roomId].blocks[blockId]
  884 + local room = self.rooms[roomId]
  885 + local block = room.blocks[blockId]
881 886 --死了以后掉东西
882 887 if block.event and (block.event.etype == AdvEventType.BOSS or block.event.etype == AdvEventType.Monster) then --处理死亡
  888 + if block.event.etype == AdvEventType.BOSS then
  889 + room.isBossRoom = false
  890 + end
883 891 local item = block.event.item
884 892 if not item then
885 893 if block.event.etype == AdvEventType.BOSS then
886   - item = {1, 1} --todo 钥匙
  894 + item = {ItemId.AdvKey, 1}
887 895 else
888 896 local monsterData = csvdb["event_monsterCsv"][block.event.id]
889 897 local dropData = csvdb["event_dropCsv"][monsterData.dropid]
... ... @@ -930,7 +938,7 @@ function Adv:backBuff(enemyId, buffId, isDel)
930 938 end
931 939 -- if is player enemyId is nil
932 940 function Adv:backSkill(enemyId, skillId, receiver)
933   - self:pushBackEvent(AdvBackEventType.Skill, {enemyId = enemyId, buffId = skillId, receiver = receiver})
  941 + self:pushBackEvent(AdvBackEventType.Skill, {enemyId = enemyId, skillId = skillId, receiver = receiver})
934 942 end
935 943  
936 944 function Adv:backNext()
... ... @@ -962,4 +970,11 @@ function Adv:afterRound()
962 970 end
963 971 end
964 972  
  973 +function Adv:saveDB()
  974 + if self.battle then
  975 + self.battle:getDB()
  976 + end
  977 + self.owner:updateProperties({advInfo = self.advInfo, advTeam = self.advTeam})
  978 +end
  979 +
965 980 return Adv
966 981 \ No newline at end of file
... ...
src/adv/AdvBattle.lua
1   -local Player, Enemy = require "adv.advPlayer"
  1 +local Player, Enemy = table.unpack(require "adv.advPlayer")
2 2 local Buff = require "adv.AdvBuff"
3   -local AdvBattle = class("Battle")
  3 +local Battle = class("Battle")
4 4 function Battle:ctor(adv)
5 5 self.adv = adv
6 6 self.player = nil --玩家
... ... @@ -63,14 +63,14 @@ function Battle:addEnemy(room, block)
63 63 table.insert(enemy.passives, {id = id})
64 64 end
65 65 block.event.enemy = enemy
66   - table.insert(self.enemys, Enemy.new(self, block.event.mId or 999, block.event.id, room.roomId, block.blockId, not block.isOpen, block.event.enemy))
67 66 end
  67 + table.insert(self.enemys, Enemy.new(self, block.event.mId or 999, block.event.id, room.roomId, block.blockId, not block.isOpen, block.event.enemy))
68 68 end
69 69 end
70 70  
71 71 function Battle:getEnemy(roomId, blockId)
72 72 for _, enemy in ipairs(self.enemys) do
73   - if enemy.roomId == roomId and enemy.blockId = blockId then
  73 + if enemy.roomId == roomId and enemy.blockId == blockId then
74 74 return enemy
75 75 end
76 76 end
... ... @@ -87,16 +87,18 @@ end
87 87 function Battle:playerAtk(roomId, blockId)
88 88 local enemy = self:getEnemy(roomId, blockId)
89 89 if enemy then
  90 + self.adv:backAtk(nil, enemy.id)
90 91 enemy:hurt(self.player:getHurtValue(), self.player, {hurtType = 1})
91 92 --是否无法反击
92 93 if not enemy:hadBuff(Buff.CANT_BACK_ATK) then
  94 + self.adv:backAtk(enemy.id, nil)
93 95 self.player:hurt(enemy:getHurtValue(), enemy, {hurtType = 1})
94 96 end
95 97 end
96 98 end
97 99 --触发全员被动技能
98 100 function Battle:triggerPassive(condType, params)
99   -
  101 +
100 102 end
101 103  
102 104 --回合
... ... @@ -133,4 +135,4 @@ function Battle:getDB()
133 135 end
134 136 end
135 137  
136   -return AdvBattle
137 138 \ No newline at end of file
  139 +return Battle
138 140 \ No newline at end of file
... ...
src/adv/AdvPassive.lua
... ... @@ -25,7 +25,7 @@ Passive.ROOM_SHOW = 19 --自身所在房间被展示时,触发1次
25 25  
26 26 -- 不同的开启条件
27 27 local PassiveFactory = {
28   - []
  28 +
29 29 }
30 30  
31 31 function Passive:ctor(owner, data)
... ... @@ -80,7 +80,9 @@ end
80 80 function Passive:trigger(condType, params) --触发检查
81 81 if self:getCondType() ~= condType then return end
82 82 if self:isActive() then return end
83   -
  83 + if self._trigger then
  84 + if not self._trigger(params) then return end --检查
  85 + end
84 86 self.round = self.passiveData.delay --首次
85 87 self.count = self.passiveData.count --次数
86 88 -- 没有延迟就直接触发
... ... @@ -98,5 +100,6 @@ function Passive:getDB()
98 100 db.level = self.level
99 101 db.round = self.round
100 102 db.count = self.count
  103 + return db
101 104 end
102 105 return Passive
103 106 \ No newline at end of file
... ...
src/adv/AdvPlayer.lua
... ... @@ -30,7 +30,7 @@ end
30 30 -- 角色初始化完以后才是 技能和被动技能 方便初始化 buff 的 释放对象
31 31 function BaseObject:initAfter(data)
32 32 for _, passive in ipairs(data.passives or {}) do
33   - table.insert(self.passives, Passive.load(self, passive))
  33 + table.insert(self.passives, Passive.new(self, passive))
34 34 end
35 35 for _, buff in ipairs(data.buffs or {}) do
36 36 table.insert(self.buffs, Buff.load(self, buff))
... ... @@ -55,6 +55,7 @@ function BaseObject:clearRound()
55 55 end
56 56 for i = #self.buffs, 1, -1 do
57 57 if self.buffs[i].isDel then
  58 + self.battle.adv:backBuff(self.id, self.buffs[i].id, true)
58 59 self.buffs[i]:endBuff()
59 60 table.remove(self.buffs, i)
60 61 end
... ... @@ -78,6 +79,8 @@ function BaseObject:addBuff(buffId, releaser)
78 79 end
79 80 end
80 81 table.insert(self.buffs, Buff.create(self, releaser, {id = buffId}))
  82 +
  83 + self.battle.adv:backBuff(self.id, buffId)
81 84 end
82 85  
83 86 function BaseObject:hadBuff(bType)
... ... @@ -130,10 +133,17 @@ function BaseObject:getInjuredChange()
130 133 end
131 134 --重新计算属性
132 135 function BaseObject:reSetAttr(field)
  136 + local old = self[field]
133 137 self[field] = self["_" .. field] --重置一下
134 138 local fieldToBuff = {atk = Buff.IMMNUE_ATK, hit = Buff.HIT_CHANGE, miss = Buff.MISS_CHANGE}
135 139 local effect = self:getCommonBuffEffect(fieldToBuff[field])
136 140 self[field] = (self[field] + effect[0]) * (1 + effect[1])
  141 + local delta = self[field] - old
  142 + if delta ~= 0 then
  143 + if field == "atk" then
  144 + self.battle.adv:backAtkChange(self.id, delta)
  145 + end
  146 + end
137 147 end
138 148  
139 149 --计算打出伤害加成后的值
... ... @@ -208,6 +218,7 @@ function BaseObject:hurt(value, releaser, params)
208 218 end
209 219  
210 220 --受伤了~
  221 + self.battle.adv:backHpChange(self.id, -value)
211 222 self.hp = math.max(0, self.hp - value)
212 223 if self.hp == 0 then
213 224 self.isDead = true
... ... @@ -218,9 +229,11 @@ function BaseObject:recover(value, releaser, params)
218 229 params = params or {}
219 230 value = math.max(0, value)
220 231 self.hp = math.min(self.hpMax, self.hp + value)
  232 + self.battle.adv:backHpChange(self.id, value)
221 233 end
222 234  
223 235 function BaseObject:releaseSkill(skillId, skillLevel, target)
  236 + if self:hadBuff(Buff.CANT_SKILL) then return end -- 针对 怪物
224 237 skillLevel = skillLevel or 1
225 238 local skillData = csvdb["adv_skillCsv"][skillId][skillLevel or 1]
226 239 local targetChoose = skillData.target:toArray(true, "=")
... ... @@ -289,6 +302,10 @@ function BaseObject:releaseSkill(skillId, skillLevel, target)
289 302 targets = tempT --all
290 303 end
291 304 end
  305 + --返回客户端
  306 + for _, target in ipairs(targets) do
  307 + self.battle.adv:backSkill(self.id, skillId, target.id)
  308 + end
292 309 -- 增加buff
293 310 for _, buffId in ipairs(skillData.selfbuff:toArray(true, "=")) do
294 311 self:addBuff(buffId, self)
... ... @@ -361,14 +378,14 @@ function BaseObject:getDB()
361 378 end
362 379  
363 380 function BaseObject:triggerPassive(condType, params)
364   -
  381 +
365 382 end
366 383  
367 384 local Enemy = class("Enemy", BaseObject)
368   -function Enemy:ctor(battle, monsterId, id, roomId, blockId, lock, enemy)
  385 +function Enemy:ctor(battle, mId, monsterId, roomId, blockId, lock, enemy)
369 386 Enemy.super.ctor(self, battle)
370   - self.id = id
371   - self.monsterId = monsterId
  387 + self.id = mId
  388 + self.monsterId = monsterId --数据id
372 389 self.roomId = roomId
373 390 self.blockId = blockId
374 391 self.lock = lock
... ... @@ -385,4 +402,4 @@ function Player:ctor(battle, data)
385 402 self:initData(data)
386 403 end
387 404  
388   -return Player, Enemy
389 405 \ No newline at end of file
  406 +return table.pack(Player, Enemy)
390 407 \ No newline at end of file
... ...
src/models/Role.lua
... ... @@ -147,6 +147,7 @@ function Role:data()
147 147 advPass = self:getProperty("advPass"),
148 148 advInfo = self:getProperty("advInfo"),
149 149 advItems = self:getProperty("advItems"):toNumMap(),
  150 + advTeam = self:getProperty("advTeam"),
150 151 }
151 152 end
152 153  
... ...
src/models/RolePlugin.lua
... ... @@ -205,6 +205,7 @@ function RolePlugin.bind(Role)
205 205 function Role:getAdvData()
206 206 if not self.advData then
207 207 self.advData = require("adv.Adv").new(self)
  208 + self.advData:initByInfo()
208 209 end
209 210 return self.advData
210 211 end
... ...