-- ToME - Tales of Maj'Eyal
-- Copyright (C) 2009, 2010, 2011 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org

newTalent{
	name = "Nova",
	display_name = "闪电新星",
	type = {"spell/storm",1},
	require = spells_req_high1,
	points = 5,
	mana = 12,
	cooldown = 8,
	tactical = { ATTACKAREA = { LIGHTNING = 2 }, DISABLE = { stun = 1 } },
	range = 0,
	radius = function(self, t)
		return math.floor(2 + self:getTalentLevel(t) * 0.7)
	end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t), selffire=false, talent=t}
	end,
	getDamage = function(self, t) return self:combatTalentSpellDamage(t, 28, 170) end,
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local dam = self:spellCrit(t.getDamage(self, t))
		self:project(tg, self.x, self.y, DamageType.LIGHTNING_DAZE, {daze=75, dam=rng.avg(dam / 3, dam, 3)})
		local x, y = self.x, self.y
		-- Lightning ball gets a special treatment to make it look neat
		local sradius = (tg.radius + 0.5) * (engine.Map.tile_w + engine.Map.tile_h) / 2
		local nb_forks = 16
		local angle_diff = 360 / nb_forks
		for i = 0, nb_forks - 1 do
			local a = math.rad(rng.range(0+i*angle_diff,angle_diff+i*angle_diff))
			local tx = x + math.floor(math.cos(a) * tg.radius)
			local ty = y + math.floor(math.sin(a) * tg.radius)
			game.level.map:particleEmitter(x, y, tg.radius, "lightning", {radius=tg.radius, grids=grids, tx=tx-x, ty=ty-y, nb_particles=25, life=8})
		end

		game:playSoundNear(self, "talents/lightning")
		return true
	end,
	info = function(self, t)
		local dam = damDesc(self, DamageType.LIGHTNING, t.getDamage(self, t))
		local radius = self:getTalentRadius(t)
		return ([[一圈闪电从你身上放射出来，在 %d 格范围内对目标造成 %0.2f ～ %0.2f 闪电伤害并有75%%概率眩晕敌人。
		受法术强度影响，伤害有额外加成。]]):format(radius, dam / 3, dam)
	end,
}

newTalent{
	name = "Shock",
	display_name = "闪电之击",
	type = {"spell/storm",2},
	require = spells_req_high2,
	points = 5,
	mana = 8,
	cooldown = 4,
	tactical = { ATTACK = { LIGHTNING = 2 }, DISABLE = { stun = 1 } },
	range = 10,
	requires_target = true,
	reflectable = true,
	getDamage = function(self, t) return self:combatTalentSpellDamage(t, 25, 200) end,
	action = function(self, t)
		local tg = {type="bolt", range=self:getTalentRange(t), talent=t, display={particle="bolt_lightning", trail="lightningtrail"}}
		local x, y = self:getTarget(tg)
		if not x or not y then return nil end
		local dam = t.getDamage(self, t)
		self:projectile(tg, x, y, DamageType.LIGHTNING_DAZE, {daze=100, dam=self:spellCrit(rng.avg(dam / 3, dam, 3))}, {type="lightning_explosion"})
		game:playSoundNear(self, "talents/lightning")
		return true
	end,
	info = function(self, t)
		local damage = t.getDamage(self, t)
		return ([[召唤一个闪电球对目标造成 %0.2f ～ %0.2f 闪电伤害并眩晕目标3回合。
		受法术强度影响，伤害有额外加成。]]):
		format(damDesc(self, DamageType.LIGHTNING, damage/3), damDesc(self, DamageType.LIGHTNING, damage))
	end,
}

newTalent{
	name = "Hurricane",
	display_name = "风暴之怒",
	type = {"spell/storm",3},
	require = spells_req_high3,
	points = 5,
	mode = "sustained",
	sustain_mana = 100,
	cooldown = 30,
	tactical = { DISABLE = 2, BUFF = 2 },
	range = 10,
	direct_hit = true,
	getDamage = function(self, t) return self:combatTalentSpellDamage(t, 25, 150) end,
	getChance = function(self, t) return 30 + self:getTalentLevel(t) * 5 end,
	getRadius = function(self, t)
			local radius = 2
			if self:getTalentLevel(t) >= 3 then radius = 3 end
			return radius
		end,
	do_hurricane = function(self, t, target)
		if not rng.percent(t.getChance(self, t)) then return end

		target:setEffect(target.EFF_HURRICANE, 10, {src=self, dam=t.getDamage(self, t), radius=t.getRadius(self, t) })
		game:playSoundNear(self, "talents/thunderstorm")
	end,
	activate = function(self, t)
		return {}
	end,
	deactivate = function(self, t, p)
		return true
	end,
	info = function(self, t)
		local damage = t.getDamage(self, t)
		local chance = t.getChance(self, t)
		local radius = t.getRadius(self, t)
		return ([[每次你的闪电法术眩晕目标时，它会有 %d%% 的概率发生连锁反应，生成一个围绕目标 %d 格半径范围的飓风，持续10回合。
		每回合该单位附近的所有生物会承受 %0.2f ～ %0.2f 闪电伤害。
		受法术强度影响，伤害有额外加成。]]):format(chance, radius, damage / 3, damage)
	end,
}

newTalent{
	name = "Tempest",
	display_name = "无尽风暴",
	type = {"spell/storm",4},
	require = spells_req_high4,
	points = 5,
	mode = "sustained",
	tactical = { BUFF = 2 },
	sustain_mana = 50,
	cooldown = 30,
	getLightningDamageIncrease = function(self, t) return self:getTalentLevelRaw(t) * 2 end,
	getResistPenalty = function(self, t) return self:getTalentLevelRaw(t) * 10 end,
	activate = function(self, t)
		game:playSoundNear(self, "talents/thunderstorm")
		return {
			dam = self:addTemporaryValue("inc_damage", {[DamageType.LIGHTNING] = t.getLightningDamageIncrease(self, t)}),
			resist = self:addTemporaryValue("resists_pen", {[DamageType.LIGHTNING] = t.getResistPenalty(self, t)}),
			particle = self:addParticles(Particles.new("tempest", 1)),
		}
	end,
	deactivate = function(self, t, p)
		self:removeParticles(p.particle)
		self:removeTemporaryValue("inc_damage", p.dam)
		self:removeTemporaryValue("resists_pen", p.resist)
		return true
	end,
	info = function(self, t)
		local damageinc = t.getLightningDamageIncrease(self, t)
		local ressistpen = t.getResistPenalty(self, t)
		return ([[在你周围生成一股风暴，增加你 %d%% 闪电伤害并无视目标 %d%% 闪电抵抗。]])
		:format(damageinc, ressistpen)
	end,
}
