Blame view

src/models/HeroPlugin.lua 7.93 KB
8c74292c   zhouahaihai   增加item 以及 角色突破
1
2
3
4
5
  local HeroPlugin = {}
  
  
  function HeroPlugin.bind(Hero)
  
3133cb76   zhouhaihai   日志
6
7
8
9
10
11
12
13
14
15
16
  	function Hero:log(contents)
  		contents = contents or {}
  		if contents["cint1"] or contents["cint2"] or contents["cint3"] then
  			print("heroLog error log have cint1 or cint2 or cint3 ", debug.traceback())
  		end
  		contents["cint1"] = self:getProperty("id")
  		contents["cint2"] = self:getProperty("type")
  
  		self.owner:log("hero_action", contents)
  	end
  
a43410e1   zhengshouren   整理格式,使用tab替代空格
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  	function Hero:getMaxLevel()
  		return math.min(#csvdb["unit_expCsv"], csvdb["unit_breakCsv"][self:getProperty("breakL")].levelLimit)
  	end
  
  	function Hero:getSPoint()
  		local point = 0
  		for i = 0, self:getProperty("wakeL") do
  			if csvdb["unit_wakeCsv"][i] then
  				point = point + csvdb["unit_wakeCsv"][i].sp
  			end
  		end
  		return point
  	end
  
  	function Hero:getLSPoint()
  		local point = self:getSPoint()
  		for skill, level in pairs(self:getProperty("skillL"):toNumMap()) do
  			point = point - (level - 1)
  		end
  		return point
  	end
ece975b6   zhouhaihai   属性计算
38
  
a43410e1   zhengshouren   整理格式,使用tab替代空格
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  	--角色属性值 = 基础属性值(unit)* [ 1 + 升级属性(unit_exp)+ 突破属性(unit_break)] * [ 1 + 觉醒属性(unit_wake)+ 天赋属性(unit_talent)]
  	function Hero:getBaseAttrs(params)
  		params = params or {}
  		local unitData  = csvdb["unitCsv"][self:getProperty("type")]
  		local level = params.level or self:getProperty("level")
  		local breakL = params.breakL or self:getProperty("breakL")
  		local wakeL = params.wakeL or self:getProperty("wakeL")
  		local talent = params.talent or self:getProperty("talent")
  
  
  		local attrs = {}
  		for _, attName in pairs(AttsEnumEx) do
  			attrs[attName] = unitData[attName] or 0
  		end
  		local lData = csvdb["unit_expCsv"][level]
  		local blData = csvdb["unit_breakCsv"][breakL]
  		-- core
  		for attr, value in pairs(attrs) do
  			attrs[attr] = attrs[attr] * (100 + (lData[attr .. "Level"] or 0) + (blData[attr .. "Level"] or 0)) / 100
  		end
  
  		local talentAttrS = {}
  		-- 天赋阶段属性
1c35c4cf   gaofengduan   fix hero awake
62
  		for i = 1, (talent:getv(0, 1) - 1) do
a43410e1   zhengshouren   整理格式,使用tab替代空格
63
64
65
66
67
  			local curData = csvdb["unit_talentCsv"][i]
  			local effect = curData[#curData].effect:toArray(true, "=")
  			talentAttrS[AttsEnumEx[effect[1]]] = (talentAttrS[AttsEnumEx[effect[1]]] or 0) + effect[2]
  		end
  		-- 四个基础属性
1c35c4cf   gaofengduan   fix hero awake
68
  		local curData = csvdb["unit_talentCsv"][talent:getv(0, 1)]
a43410e1   zhengshouren   整理格式,使用tab替代空格
69
  		if not curData then -- 已经满阶段了
1c35c4cf   gaofengduan   fix hero awake
70
  			curData = csvdb["unit_talentCsv"][#csvdb["unit_talentCsv"]]
a43410e1   zhengshouren   整理格式,使用tab替代空格
71
72
73
74
75
76
77
78
79
80
81
82
  			local strength = curData[#curData].strength
  			for i = 1, 4 do
  				talentAttrS[AttsEnumEx[i]] = (talentAttrS[AttsEnumEx[i]] or 0) + strength
  			end
  		else
  			for i = 1, 4 do --4个天赋
  				talentAttrS[AttsEnumEx[i]] = (talentAttrS[AttsEnumEx[i]] or 0) + curData[talent:getv(i, 0)].strength
  			end
  		end
  
  		--好感度
  		local loveUp = {}
14f1591b   zhouhaihai   删除好感度相关
83
84
85
86
87
88
  		-- for i = 0, self:getProperty("loveL") do
  		-- 	local reward = csvdb["unit_love_effectCsv"][i]["reward"]
  		-- 	for attrId, value in pairs(reward:toNumMap()) do
  		-- 		loveUp[AttsEnumEx[attrId]] = (loveUp[AttsEnumEx[attrId]] or 0) + value
  		-- 	end
  		-- end
a43410e1   zhengshouren   整理格式,使用tab替代空格
89
  
a43410e1   zhengshouren   整理格式,使用tab替代空格
90
91
92
  		--觉醒
  		local wData = csvdb["unit_wakeCsv"][wakeL]
  		for attr, value in pairs(attrs) do
f2fa488d   wangyujie   删除skin相关
93
  			attrs[attr] = attrs[attr] * (100 + (wData[attr .. "Level"] or 0) + (talentAttrS[attr] or 0) + (loveUp[attr] or 0)) / 100
a43410e1   zhengshouren   整理格式,使用tab替代空格
94
95
96
97
98
  		end
  
  		return attrs
  	end
  
ece975b6   zhouhaihai   属性计算
99
  
a43410e1   zhengshouren   整理格式,使用tab替代空格
100
101
  	--当前属性 = [ 角色属性值 + 基础装备(固定)+ 专属装备(固定)] * [ 1 + 基础装备(百分比) + 专属装备(百分比)]
  	function Hero:getTotalAttrs(params)
b53593b5   zhouhaihai   羁绊加成
102
  		params = params or {}
a43410e1   zhengshouren   整理格式,使用tab替代空格
103
  		local attrs = self:getBaseAttrs()
ece975b6   zhouhaihai   属性计算
104
105
106
107
  		-- 装备零件
  		local equipAttrs = self:getRuneEquipAttrs()
  
  		for _, attName in pairs(AttsEnumEx) do
acfc2f02   zhouhaihai   零件套装增加冒险战斗被动
108
  			attrs[attName] = ((attrs[attName] or 0) + equipAttrs.value[attName]) * (1 + equipAttrs.percent[attName] / 100)
ece975b6   zhouhaihai   属性计算
109
110
  		end
  
b53593b5   zhouhaihai   羁绊加成
111
112
113
114
115
116
  		-- 羁绊加成
  	    if params.activeRelation then
  	        for k, v in pairs(AttsEnumEx) do
  	            attrs[v] = (attrs[v] or 0) * (1 + (params.activeRelation[v] or 0) / 100)
  	        end
  	    end
ece975b6   zhouhaihai   属性计算
117
118
119
120
121
  		return attrs
  	end
  
  	-- 当前零件和装备增加属性
  	function Hero:getRuneEquipAttrs()
acfc2f02   zhouhaihai   零件套装增加冒险战斗被动
122
  		local attrs = {value = {}, percent = {}}
ece975b6   zhouhaihai   属性计算
123
124
  		for _, attName in pairs(AttsEnumEx) do
  			attrs.value[attName] = 0
acfc2f02   zhouhaihai   零件套装增加冒险战斗被动
125
  			attrs.percent[attName] = 0
ece975b6   zhouhaihai   属性计算
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
  		end
  		local equipSuits = {}
  		-- 装备效果
  		for typ,level in pairs(self:getProperty("equip"):toNumMap()) do
  			if level > 0 then
  				local data = csvdb["equipCsv"][typ][level]
  				for k,v in pairs(data.attr1:toNumMap()) do
  					attrs.value[AttsEnumEx[k]] = attrs.value[AttsEnumEx[k]] + v
  				end
  				for k,v in pairs(data.attr2:toNumMap()) do
  					attrs.value[AttsEnumEx[k]] = attrs.value[AttsEnumEx[k]] + v
  				end
  				if data.suit ~= "" then
  					if not equipSuits[data.suit] then equipSuits[data.suit] = {} end
  					table.insert(equipSuits[data.suit], data)
  				end
  			end
  		end
  		-- 装备套装效果
  		for suitId,eDatas in pairs(equipSuits) do
  			local suitCsv = csvdb["equip_suitCsv"][tonumber(suitId)]
  			if suitCsv then 
  				local effects = suitCsv.effect:toTableArray(true)
  				local count = #eDatas
  				if count >= 2 then
acfc2f02   zhouhaihai   零件套装增加冒险战斗被动
151
  					attrs.percent[AttsEnumEx[effects[1][1]]] = attrs.percent[AttsEnumEx[effects[1][1]]] + effects[1][2]
ece975b6   zhouhaihai   属性计算
152
153
  				end
  				if count >= 3 then
acfc2f02   zhouhaihai   零件套装增加冒险战斗被动
154
  					attrs.percent[AttsEnumEx[effects[2][1]]] = attrs.percent[AttsEnumEx[effects[2][1]]] + effects[1][2]
ece975b6   zhouhaihai   属性计算
155
156
  				end
  				if count >= 4 then
acfc2f02   zhouhaihai   零件套装增加冒险战斗被动
157
  					attrs.percent[AttsEnumEx[effects[3][1]]] = attrs.percent[AttsEnumEx[effects[3][1]]] + effects[3][2]
ece975b6   zhouhaihai   属性计算
158
159
160
161
162
163
164
165
166
167
  				end
  			end
  		end
  		-- 零件效果
  		local suits = {}
  		for _, uid in pairs(self:getProperty("rune"):toNumMap()) do
  			if uid > 0 then
  				local rune = self.owner.runeBag[uid]
  				local buildData = csvdb["rune_buildCsv"][rune:getProperty("level")]
  				for k,v in pairs(rune:getProperty("attrs"):toNumMap()) do
b58b5b49   zhouhaihai   零件bug
168
  					attrs.value[AttsEnumEx[k]] = attrs.value[AttsEnumEx[k]] + (v / 10 * (1 + buildData.effect/100))  -- 零件的加成属性有特殊需求 填的是 10倍的值
ece975b6   zhouhaihai   属性计算
169
170
171
172
173
174
175
176
177
178
179
180
181
  					
  				end
  				local csvData = csvdb["runeCsv"][rune:getProperty("type")][rune:getProperty("id")]
  				if not suits[csvData.suit] then suits[csvData.suit] = {} end
  				table.insert(suits[csvData.suit],csvData)
  			end
  		end
  		-- 零件套装效果
  		for suitId,runeDatas in pairs(suits) do
  			local suitCsv = csvdb["rune_suitCsv"][tonumber(suitId)]
  			if suitCsv then
  				local effects = suitCsv.effect:toTableArray(true)
  				local count = #runeDatas
acfc2f02   zhouhaihai   零件套装增加冒险战斗被动
182
183
184
185
186
  				if count >= 2 and AttsEnumEx[effects[1][1]]then
  					attrs.percent[AttsEnumEx[effects[1][1]]] = attrs.percent[AttsEnumEx[effects[1][1]]] + effects[1][2]
  				end
  				if count >= 4 and AttsEnumEx[effects[2][1]] then
  					attrs.percent[AttsEnumEx[effects[2][1]]] = attrs.percent[AttsEnumEx[effects[2][1]]] + effects[2][2]
ece975b6   zhouhaihai   属性计算
187
  				end
acfc2f02   zhouhaihai   零件套装增加冒险战斗被动
188
189
  				if count >= 6 and AttsEnumEx[effects[3][1]] then
  					attrs.percent[AttsEnumEx[effects[3][1]]] = attrs.percent[AttsEnumEx[effects[3][1]]] + effects[3][2]
ece975b6   zhouhaihai   属性计算
190
191
192
  				end
  			end
  		end
a43410e1   zhengshouren   整理格式,使用tab替代空格
193
194
  		return attrs
  	end
ece975b6   zhouhaihai   属性计算
195
  
a43410e1   zhengshouren   整理格式,使用tab替代空格
196
  	-- 战斗力(当前属性)= POWER[(生命 + 防御 * 7 + 闪避 * 4)*(攻击 + 命中 * 4)*(1 + 暴击几率/100 * 暴击伤害/100)* 攻击速度 / 60000 ,0.8 ]
b53593b5   zhouhaihai   羁绊加成
197
198
  	function Hero:getBattleValue(activeRelation)
  		local attrs = self:getTotalAttrs({activeRelation = activeRelation})
a43410e1   zhengshouren   整理格式,使用tab替代空格
199
200
201
202
203
204
205
206
207
208
209
210
  		local battleValue = ((attrs["hp"] + attrs["def"] * 7 + attrs["miss"] * 4) * (attrs["atk"] + attrs["hit"] * 4) * (1 + attrs["crit"]/100 * attrs["critHurt"]/100) * attrs["atkSpeed"] / 60000) ^ 0.8
  		return math.floor(battleValue)
  	end
  
  	function Hero:saveBattleValue()
  		local battleValue = self:getBattleValue()
  		if battleValue ~= self:getProperty("battleV") then
  			self:setProperty("battleV", battleValue)
  		end
  		return battleValue
  	end
  
1c35c4cf   gaofengduan   fix hero awake
211
  	-- 技能1234 对应必杀技,冒险技,被动技,战斗技
a43410e1   zhengshouren   整理格式,使用tab替代空格
212
213
214
215
  	function Hero:getSkillLevel(idx)
  		return self:getProperty("skillL"):getv(idx, 1)
  	end
  
f2fa488d   wangyujie   删除skin相关
216
  	function Hero:getSkillData(idx)
1c35c4cf   gaofengduan   fix hero awake
217
  		local unitData = csvdb["unitCsv"][self:getProperty("type")]
a43410e1   zhengshouren   整理格式,使用tab替代空格
218
  		if idx == 1 then
a43410e1   zhengshouren   整理格式,使用tab替代空格
219
  			return csvdb["skill_specialCsv"][unitData.special]
1c35c4cf   gaofengduan   fix hero awake
220
  		elseif idx == 2 then
61421173   zhouhaihai   冒险技能取战斗的
221
  			return csvdb["adv_battle_specialCsv"][unitData.adv]
1c35c4cf   gaofengduan   fix hero awake
222
223
224
225
  		elseif idx == 3 then
  			return csvdb["skill_passiveCsv"][unitData.passive]
  		elseif idx == 4 then
  			return csvdb["skill_blockCsv"][unitData.block]
a43410e1   zhengshouren   整理格式,使用tab替代空格
226
227
228
  		end
  		return {}
  	end
8c74292c   zhouahaihai   增加item 以及 角色突破
229
230
231
232
  end
  
  
  return HeroPlugin