-- 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 = "Stoneshield",
	display_name = "石盾术",
	type = {"wild-gift/earthen-power", 1},
	mode = "passive",
	require = gifts_req1,
	points = 5,
	getValues = function(self, t)
		return
			(5 + self:getTalentLevel(t) * 2) / 100,
			5 + self:getTalentLevel(t),
			(5 + self:getTalentLevel(t) * 1.7) / 100,
			4 + self:getTalentLevel(t)
	end,
	info = function(self, t)
		local m, mm, e, em = t.getValues(self, t)
		return ([[每次你收到攻击时你回复 %d%% mana (最多 %0.2f)和 %d%% 失衡值(最多 %0.2f)。
		你的近战攻击同时也会造成一次盾击。]]):format(100 * m, mm, 100 * e, em)
	end,
}

newTalent{
	name = "Stone Fortress",
	display_name = "坚石堡垒",
	type = {"wild-gift/earthen-power", 2},
	require = gifts_req2,
	points = 5,
	mode = "passive",
	info = function(self, t)
		return ([[当你使用 矮人回复 种族能力时，你的皮肤变得更加坚硬，除吸收物理伤害以外还能吸收部分非物理伤害。
		非物理伤害减少相当于你护甲值的 %d%% 。]]):
		format(50 + self:getTalentLevel(t) * 10)
	end,
}

newTalent{
	name = "Shards",
	display_name = "石凝碎块",
	type = {"wild-gift/earthen-power", 3},
	require = gifts_req3,
	points = 5,
	equilibrium = 4,
	cooldown = 30,
	tactical = { ATTACK = 2 },
	range = 10,
	direct_hit = true,
	proj_speed = 8,
	action = function(self, t)
		local tg = {type="bolt", range=self:getTalentRange(t), display={particle="bolt_arcane"}}
		local x, y = self:getTarget(tg)
		if not x or not y then return nil end
		self:projectile(tg, x, y, DamageType.SLIME, self:combatTalentStatDamage(t, "dex", 30, 290), {type="slime"})
		game:playSoundNear(self, "talents/stone")
		return true
	end,
	info = function(self, t)
		return ([[向你的目标喷射石凝碎块造成 %0.2f 自然伤害并减速 30%% 持续3回合。
		受敏捷影响伤害有额外加成。]]):format(damDesc(self, DamageType.NATURE, self:combatTalentStatDamage(t, "dex", 30, 290)))
	end,
}

newTalent{
	name = "Eldritch Stone",
	display_name = "怪力之石",
	type = {"wild-gift/earthen-power", 4},
	require = gifts_req4,
	points = 5,
	equilibrium = 5,
	cooldown = 20,
	tactical = { CLOSEIN = 2 },
	requires_target = true,
	range = function(self, t)
		return 5 + self:getTalentLevel(t)
	end,
	radius = function(self, t)
		return util.bound(4 - self:getTalentLevel(t) / 2, 1, 4)
	end,
	getDuration = function(self, t)
		return util.bound(7 - self:getTalentLevel(t) / 2, 2, 7)
	end,
	is_teleport = true,
	action = function(self, t)
		local range = self:getTalentRange(t)
		local radius = self:getTalentRadius(t)
		local tg = {type="ball", nolock=true, pass_terrain=true, nowarning=true, range=range, radius=radius, requires_knowledge=false}
		local x, y = self:getTarget(tg)
		if not x then return nil end
		-- Target code does not restrict the self coordinates to the range, it lets the project function do it
		-- but we cant ...
		local _ _, x, y = self:canProject(tg, x, y)
		game.level.map:particleEmitter(self.x, self.y, 1, "slime")
		self:teleportRandom(x, y, self:getTalentRadius(t))
		game.level.map:particleEmitter(self.x, self.y, 1, "slime")

		local duration = t.getDuration(self, t)

		for tid, lev in pairs(self.talents) do
			local t = self:getTalentFromId(tid)
			if t.mode == "activated" and not t.innate then
				self.talents_cd[t.id] = duration
			end
		end
		game:playSoundNear(self, "talents/stone")
		return true
	end,
	info = function(self, t)
		local range = self:getTalentRange(t)
		local radius = self:getTalentRadius(t)
		local duration = t.getDuration(self, t)
		return ([[你遁入大地，然后在 %d 到 %d 格范围内重新出现。
		整个过程会增加对你身体的负担，使你的所有技能处于CD状态持续 %d 回合。]]):format(range, radius, duration)
	end,
}
