Blame view

src/adv/AdvBlock.lua 4 KB
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  --块类型
  local AdvCommon = require "adv.AdvCommon"
  local Passive = require "adv.AdvPassive"
  
  local Block = class("AdvBlock")
  function Block:ctor(room, blockId, event, isOpen, trapId)
  	self.room = room
  	self.blockId = blockId
  	self.col, self.row = AdvCommon.getCrById(self.blockId)
  
  	self.isOpen = isOpen and true or false
  	self.trapId = trapId
  
  	self:updateEvent(event)
  end
  function Block:isBoss()
  	return self:getEventType() == AdvEventType.BOSS
  end
  
  function Block:isMonster()
  	return (self:getEventType() == AdvEventType.BOSS or self:getEventType() == AdvEventType.Monster)
  end
  
9687f887   zhouhaihai   建筑被动
24
25
26
27
  function Block:isBuild()
  	return self:getEventType() == AdvEventType.Build
  end
  
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
28
29
30
31
32
33
34
35
36
37
38
  function Block:getEventType()
  	return self.event and self.event.etype
  end
  
  function Block:updateEvent(event)
  	self.event = event
  end
  
  function Block:clear()
  	if self:getEventType() == AdvEventType.Trap then 
  		self.trapId = self.event.id
44dd6cae   zhouhaihai   建筑消失删除建筑角色
39
40
41
42
43
  	elseif self:getEventType() == AdvEventType.Build then
  		local build = self.room.map.adv.battle:getBuild(self.room.roomId, self.blockId, self.room.map.mapIdx)
  		if build then
  			build.isDead = true
  		end
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
44
45
46
47
  	end
  	self.event = nil
  end
  
4f0a5fae   zhouhaihai   营养剂
48
49
  
  function Block:randomEvent()
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  	local room = self.room
  	local map = room.map
  	local adv = map.adv
  	--如果翻开有数据处理在这里处理
  	local randomFunc = {}
  	--怪
  	randomFunc[AdvEventType.Monster] = function()
  		self.event.mId = adv.lastEnemyId  --给怪一个有序id 回合逻辑时使用
  		adv.lastEnemyId = adv.lastEnemyId + 1
  		local enemy = adv.battle:getEnemy(room.roomId, self.blockId, map.mapIdx)
  		if enemy then
  			enemy:unlock(self.event.mId)
  		else
  			enemy = adv.battle:addEnemy(room, self, map.mapIdx)
  		end
  		enemy:triggerPassive(Passive.BORN_ONCE)
d3da3368   zhouhaihai   冒险地图被动技, buff 神器
66
67
68
69
70
  
  		adv.battle.player:triggerPassive(Passive.OPEN_MONSTER, {trigger = enemy})
  		for _, monster in pairs(adv.battle.player:getTeam(2)) do
  			adv.battle.player:triggerPassive(Passive.OPEN_MONSTER, {trigger = enemy})
  		end
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  	end
  	randomFunc[AdvEventType.BOSS] = randomFunc[AdvEventType.Monster]
  	--掉落
  	randomFunc[AdvEventType.Drop] = function()
  		self.event.item = csvdb["event_dropCsv"][self.event.id]["range"]:randWeight(true)
  	end
  	--交易
  	randomFunc[AdvEventType.Trader] = function()
  		local data = csvdb["event_traderCsv"][self.event.id]
  		self.event.shop = {}
  		self.event.status = "" --购买次数状态  1 就是购买过了  -- 购买id就是shop索引
  		for i = 1, 10 do
  			local numS, rangeS = "num" .. i, "range" .. i
  			if data[numS] and data[rangeS] then
  				for j = 1, data[numS] do
  					table.insert(self.event.shop, data[rangeS]:randWeight(true))
  				end
  			else
  				break
  			end
  		end
  	end
  	--建筑
  	randomFunc[AdvEventType.Build] = function()
9687f887   zhouhaihai   建筑被动
95
96
97
98
99
100
101
  		local build = adv.battle:getBuild(room.roomId, self.blockId, map.mapIdx)
  		if build then
  			build:unlock()
  		else
  			build = adv.battle:addEnemy(room, self, map.mapIdx)
  		end
  		build:triggerPassive(Passive.BORN_ONCE)
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
102
103
104
105
  	end
  
  	randomFunc[AdvEventType.Trap] = function()
  		local data = csvdb["event_trapCsv"][self.event.id]
7828ffd0   zhouhaihai   冒险 连续选择点 和 地图因子
106
107
  		local buffs = data.effect:toArray(true, "=")
  		for _, buffId in ipairs(buffs) do
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
108
109
  			adv.battle.player:addBuff(buffId)
  		end
7828ffd0   zhouhaihai   冒险 连续选择点 和 地图因子
110
111
112
113
114
115
116
117
118
119
120
121
122
123
  		if data.target == 1 then-- 给所有敌人同样增加buff
  			local enemys = adv.battle.player:getTeam(2)
  			for k , enemy in ipairs(enemys) do
  				for _, buffId in ipairs(buffs) do
  					enemy:addBuff(buffId)
  				end
  			end
  		end
  		if data.specialEff ~= "" then
  			local effect = data.specialEff:toArray(true, "=")
  			if effect[1] == 1 then
  				self.room.map.adv:mapItemChange(effect[2])
  			end
  		end
d3da3368   zhouhaihai   冒险地图被动技, buff 神器
124
  		adv.battle.player:triggerPassive(Passive.CLICK_TRAP)
b176d7d3   zhouhaihai   冒险成就
125
  		adv:checkAchievement(adv.AchievType.Trap, 1, self.event.id)
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
126
127
128
129
130
131
132
133
134
135
  		adv:backTrap()
  		self:clear()
  	end
  
  
  	if self.event then -- 随机出具体的事件
  		if randomFunc[self:getEventType()] then
  			randomFunc[self:getEventType()]()
  		end
  	end
4f0a5fae   zhouhaihai   营养剂
136
137
138
139
140
141
142
143
144
145
  end
  
  
  --事件有需要额外处理的部分
  function Block:open()
  	if self.isOpen then return end
  	local room = self.room
  	local map = room.map
  	local adv = map.adv
  	self:randomEvent()
53e8037e   zhouhaihai   任务
146
  	adv.owner:checkTaskEnter("AdvOpenBlock")
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
147
  	self.isOpen = true
d3da3368   zhouhaihai   冒险地图被动技, buff 神器
148
  	return true
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
149
150
151
  end
  
  return Block