-- 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 = "Earthen Missiles",
	display_name = "岩石飞弹",
	type = {"spell/stone",1},
	require = spells_req_high1,
	points = 5,
	random_ego = "attack",
	mana = 10,
	cooldown = 3,
	tactical = { ATTACK = { PHYSICAL = 1, cut = 1} },
	range = 10,
	direct_hit = true,
	reflectable = true,
	proj_speed = 20,
	requires_target = true,
	getDamage = function(self, t) return self:combatTalentSpellDamage(t, 15, 120) end,
	action = function(self, t)
		local tg = {type="bolt", range=self:getTalentRange(t), talent=t, display={particle="stone_shards", trail="earthtrail"}}
		local x, y = self:getTarget(tg)
		if not x or not y then return nil end
		local damage = t.getDamage(self, t)
		self:projectile(tg, x, y, DamageType.SPLIT_BLEED, self:spellCrit(damage), nil)
		game:playSoundNear(self, "talents/earth")
		--missile #2
		local tg2 = {type="bolt", range=self:getTalentRange(t), talent=t, display={particle="stone_shards", trail="earthtrail"}}
		local x, y = self:getTarget(tg2)
		if x and y then
			self:projectile(tg2, x, y, DamageType.SPLIT_BLEED, self:spellCrit(damage), nil)
			game:playSoundNear(self, "talents/earth")
		end
		--missile #3 (Talent Level 5 Bonus Missile)
		if self:getTalentLevel(t) >= 5 then
			local tg3 = {type="bolt", range=self:getTalentRange(t), talent=t, display={particle="stone_shards", trail="earthtrail"}}
			local x, y = self:getTarget(tg3)
			if x and y then
				self:projectile(tg3, x, y, DamageType.SPLIT_BLEED, self:spellCrit(damage), nil)
				game:playSoundNear(self, "talents/earth")
			end
		else end
		return true
	end,
	info = function(self, t)
		local count = 2
		if self:getTalentLevel(t) >= 5 then
			count = count + 1
		end
		local damage = t.getDamage(self, t)
		return ([[释放出 %d 个岩石飞弹射向任意射程内的目标。每个飞弹造成 %0.2f 物理伤害和每回合 %0.2f 流血伤害，持续5回合的流血伤害。
		在等级5时，你可以额外多释放一个飞弹。
		受法术强度影响，伤害有额外加成。]]):format(count,damDesc(self, DamageType.PHYSICAL, damage/2), damDesc(self, DamageType.PHYSICAL, damage/12))
	end,
}

newTalent{
	name = "Body of Stone",
	display_name = "岩石身躯",
	type = {"spell/stone",2},
	require = spells_req_high2,
	points = 5,
	mode = "sustained",
	sustain_mana = 70,
	cooldown = 12,
	no_npc_use = true,
	tactical = { BUFF = 2 },
	getFireRes = function(self, t) return self:combatTalentSpellDamage(t, 5, 80) end,
	getLightningRes = function(self, t) return self:combatTalentSpellDamage(t, 5, 50) end,
	getPhysicalRes = function(self, t) return self:combatTalentSpellDamage(t, 5, 20) end,
	getKnockbackRes = function(self, t) return self:getTalentLevel(t)/10 end,
	getCooldownReduction = function(self, t) return self:getTalentLevel(t)/2 end,
	activate = function(self, t)
		local cdr = t.getCooldownReduction(self, t)
		game:playSoundNear(self, "talents/earth")
		return {
			particle = self:addParticles(Particles.new("stone_skin", 1)),
			move = self:addTemporaryValue("never_move", 1),
			knock = self:addTemporaryValue("knockback_immune", t.getKnockbackRes(self, t)),
			cdred = self:addTemporaryValue("talent_cd_reduction", {
				[self.T_EARTHEN_MISSILES] = cdr,
				[self.T_STRIKE] = cdr,
				[self.T_EARTHQUAKE] = cdr,
			}),
			res = self:addTemporaryValue("resists", {
				[DamageType.FIRE] = t.getFireRes(self, t),
				[DamageType.LIGHTNING] = t.getLightningRes(self, t),
				[DamageType.PHYSICAL] = t.getPhysicalRes(self, t),
			}),
		}
	end,
	deactivate = function(self, t, p)
		self:removeParticles(p.particle)
		self:removeTemporaryValue("never_move", p.move)
		self:removeTemporaryValue("knockback_immune", p.knock)
		self:removeTemporaryValue("talent_cd_reduction", p.cdred)
		self:removeTemporaryValue("resists", p.res)
		return true
	end,
	info = function(self, t)
		local fireres = t.getFireRes(self, t)
		local lightningres = t.getLightningRes(self, t)
		local physicalres = t.getPhysicalRes(self, t)
		local cooldownred = t.getCooldownReduction(self, t)
		local knockbackres = t.getKnockbackRes(self, t)
		return ([[你将自己扎根于土壤并使你的肉体融入石头。
		当此技能被激活时你不能移动并且任何移动会中止此技能效果。
		当此技能激活时，受你的石化形态和土壤相关影响，会产生以下效果：
		*减少岩石飞弹、地震和石拳打击冷却时间 %d 回合。
		*获得 %d%% 火焰抵抗， %d%% 闪电抵抗， %d%% 物理伤害抵抗和 %d%% 击退抵抗。
		受魔法影响，抵抗百分比按比例额外加成。]])
		:format(cooldownred, fireres, lightningres, physicalres, knockbackres*100)
	end,
}

newTalent{
	name = "Earthquake",
	display_name = "地震",
	type = {"spell/stone",3},
	require = spells_req_high3,
	points = 5,
	random_ego = "attack",
	mana = 50,
	cooldown = 30,
	tactical = { ATTACKAREA = { PHYSICAL = 2 }, DISABLE = { stun = 3 } },
	range = 10,
	radius = function(self, t)
		return 2 + (self:getTalentLevel(t)/2)
	end,
	direct_hit = true,
	requires_target = true,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t)}
	end,
	getDamage = function(self, t) return self:combatTalentSpellDamage(t, 15, 70) end,
	getDuration = function(self, t) return 3 + self:getTalentLevel(t) end,
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		if not x or not y then return nil end
		local _ _, _, _, x, y = self:canProject(tg, x, y)
		-- Add a lasting map effect
		game.level.map:addEffect(self,
			x, y, t.getDuration(self, t),
			DamageType.PHYSICAL_STUN, t.getDamage(self, t),
			self:getTalentRadius(t),
			5, nil,
			{type="quake"},
			nil, self:spellFriendlyFire()
		)

		game:playSoundNear(self, "talents/earth")
		return true
	end,
	info = function(self, t)
		local damage = t.getDamage(self, t)
		local radius = self:getTalentRadius(t)
		local duration = t.getDuration(self, t)
		return ([[引起一波强烈的地震，每回合造成 %0.2f 物理伤害（ %d 格半径范围），持续 %d 回合。有概率震慑此技能所影响到的怪物。
		受法术强度影响，伤害有额外加成。]]):
		format(damDesc(self, DamageType.PHYSICAL, damage), radius, duration)
	end,
}

newTalent{
	name = "Crystalline Focus",
	display_name = "水晶力场",
	type = {"spell/stone",4},
	require = spells_req_high4,
	points = 5,
	mode = "sustained",
	sustain_mana = 50,
	cooldown = 30,
	tactical = { BUFF = 2 },
	getPhysicalDamageIncrease = 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/earth")
		return {
			dam = self:addTemporaryValue("inc_damage", {[DamageType.PHYSICAL] = t.getPhysicalDamageIncrease(self, t)}),
			resist = self:addTemporaryValue("resists_pen", {[DamageType.PHYSICAL] = t.getResistPenalty(self, t)}),
			particle = self:addParticles(Particles.new("crystalline_focus", 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.getPhysicalDamageIncrease(self, t)
		local ressistpen = t.getResistPenalty(self, t)
		return ([[你专注于维持水晶力场，增加你 %d%% 所有物理伤害并忽略目标 %d%% 的物理伤害抵抗。]])
		:format(damageinc, ressistpen)
	end,
}
