Blame view

src/models/HeroPlugin.lua 4.81 KB
8c74292c   zhouahaihai   增加item 以及 角色突破
1
2
3
4
5
  local HeroPlugin = {}
  
  
  function HeroPlugin.bind(Hero)
  
a43410e1   zhengshouren   整理格式,使用tab替代空格
6
7
8
9
10
11
12
13
14
15
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
41
42
43
44
45
46
47
48
49
  	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
  	--角色属性值 = 基础属性值(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
50
  		for i = 1, (talent:getv(0, 1) - 1) do
a43410e1   zhengshouren   整理格式,使用tab替代空格
51
52
53
54
55
  			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
56
  		local curData = csvdb["unit_talentCsv"][talent:getv(0, 1)]
a43410e1   zhengshouren   整理格式,使用tab替代空格
57
  		if not curData then -- 已经满阶段了
1c35c4cf   gaofengduan   fix hero awake
58
  			curData = csvdb["unit_talentCsv"][#csvdb["unit_talentCsv"]]
a43410e1   zhengshouren   整理格式,使用tab替代空格
59
60
61
62
63
64
65
66
67
68
69
70
71
  			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 = {}
  		for i = 0, self:getProperty("loveL") do
1c35c4cf   gaofengduan   fix hero awake
72
  			local reward = csvdb["unit_love_effectCsv"][i]["reward"]
a43410e1   zhengshouren   整理格式,使用tab替代空格
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  			for attrId, value in pairs(reward:toNumMap()) do
  				loveUp[AttsEnumEx[attrId]] = (loveUp[AttsEnumEx[attrId]] or 0) + value
  			end
  		end
  
  		--皮肤
  		local skinUp = {}
  		local reward = (csvdb["unit_skinCsv"][self:getSkinId()] or {})["reward"] or ""
  		for attrId, value in pairs(reward:toNumMap()) do
  			skinUp[AttsEnumEx[attrId]] = (skinUp[AttsEnumEx[attrId]] or 0) + value
  		end
  
  		--觉醒
  		local wData = csvdb["unit_wakeCsv"][wakeL]
  		for attr, value in pairs(attrs) do
  			attrs[attr] = attrs[attr] * (100 + (wData[attr .. "Level"] or 0) + (talentAttrS[attr] or 0) + (loveUp[attr] or 0) + (skinUp[attr] or 0)) / 100
  		end
  
  		return attrs
  	end
  
  	--当前属性 = [ 角色属性值 + 基础装备(固定)+ 专属装备(固定)] * [ 1 + 基础装备(百分比) + 专属装备(百分比)]
  	function Hero:getTotalAttrs(params)
  		local attrs = self:getBaseAttrs()
  		return attrs
  	end
  	-- 战斗力(当前属性)= POWER[(生命 + 防御 * 7 + 闪避 * 4)*(攻击 + 命中 * 4)*(1 + 暴击几率/100 * 暴击伤害/100)* 攻击速度 / 60000 ,0.8 ]
  	function Hero:getBattleValue()
  		local attrs = self:getTotalAttrs()
  		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
114
  	-- 技能1234 对应必杀技,冒险技,被动技,战斗技
a43410e1   zhengshouren   整理格式,使用tab替代空格
115
116
117
118
119
  	function Hero:getSkillLevel(idx)
  		return self:getProperty("skillL"):getv(idx, 1)
  	end
  
  	function Hero:getSkillData(idx, skin)
1c35c4cf   gaofengduan   fix hero awake
120
  		local unitData = csvdb["unitCsv"][self:getProperty("type")]
a43410e1   zhengshouren   整理格式,使用tab替代空格
121
  		if idx == 1 then
a43410e1   zhengshouren   整理格式,使用tab替代空格
122
  			return csvdb["skill_specialCsv"][unitData.special]
1c35c4cf   gaofengduan   fix hero awake
123
  		elseif idx == 2 then
a43410e1   zhengshouren   整理格式,使用tab替代空格
124
125
126
127
128
  			if unitData.adv > 1000 then
  				return csvdb["adv_skill_passiveCsv"][unitData.adv]
  			else
  				return csvdb["adv_skillCsv"][unitData.adv]
  			end
1c35c4cf   gaofengduan   fix hero awake
129
130
131
132
  		elseif idx == 3 then
  			return csvdb["skill_passiveCsv"][unitData.passive]
  		elseif idx == 4 then
  			return csvdb["skill_blockCsv"][unitData.block]
a43410e1   zhengshouren   整理格式,使用tab替代空格
133
134
135
136
137
138
139
140
141
142
143
144
  		end
  		return {}
  	end
  
  	function Hero:getSkinId(skin)
  		skin = skin or self:getProperty("skin")
  		if skin == 0 then
  			return self:getProperty("type")
  		else
  			return 30000 + self:getProperty("type") * 10 + skin
  		end
  	end
997cbdfe   zhouahaihai   技能养成
145
  
8c74292c   zhouahaihai   增加item 以及 角色突破
146
147
148
149
  end
  
  
  return HeroPlugin