-- 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 = "Congeal Time",
	display_name = "时间凝固",
	type = {"spell/temporal",1},
	require = spells_req1,
	points = 5,
	random_ego = "utility",
	mana = 20,
	cooldown = 30,
	tactical = { DISABLE = 2 },
	reflectable = true,
	proj_speed = 2,
	range = 6,
	direct_hit = true,
	requires_target = true,
	getSlow = function(self, t) return math.min(self:getTalentLevel(t) * 0.08, 0.6) end,
	action = function(self, t)
		local tg = {type="beam", range=self:getTalentRange(t), talent=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.SLOW, 1 - 1 / (1 + t.getSlow(self, t)), {type="manathrust"})
		game:playSoundNear(self, "talents/spell_generic")
		return true
	end,
	info = function(self, t)
		local slow = t.getSlow(self, t)
		return ([[制造一个扭曲时间的力场，目标减速 %d%% ，持续7回合。]]):
		format(100 * slow)
	end,
}

newTalent{
	name = "Time Shield",
	display_name = "时光之盾",
	type = {"spell/temporal", 2},
	require = spells_req2,
	points = 5,
	mana = 50,
	cooldown = 18,
	tactical = { DEFEND = 2 },
	range = 10,
	getMaxAbsorb = function(self, t) return 50 + self:combatTalentSpellDamage(t, 50, 450) end,
	getDuration = function(self, t) return util.bound(5 + math.floor(self:getTalentLevel(t)), 5, 15) end,
	action = function(self, t)
		self:setEffect(self.EFF_TIME_SHIELD, t.getDuration(self, t), {power=t.getMaxAbsorb(self, t)})
		game:playSoundNear(self, "talents/spell_generic")
		return true
	end,
	info = function(self, t)
		local maxabsorb = t.getMaxAbsorb(self, t)
		local duration = t.getDuration(self, t)
		return ([[这个复杂的法术在施法者周围制造一个时间屏障，受到的伤害在未来逐渐生效。
		一旦达到最大伤害吸收值（ %d ）或持续时间（ %d 回合）结束，推移的伤害会回到自身，造成持续自我伤害（持续5回合）。
		受法术强度影响，最大吸收值有额外加成。]]):
		format(maxabsorb, duration)
	end,
}

newTalent{
	name = "Time Prison",
	display_name = "时光之牢",
	type = {"spell/temporal", 3},
	require = spells_req3,
	points = 5,
	random_ego = "utility",
	mana = 140,
	cooldown = 40,
	tactical = { DISABLE = 1, ESCAPE = 3, PROTECT = 3 },
	range = 10,
	direct_hit = true,
	reflectable = true,
	requires_target = true,
	getDuration = function(self, t) return 4 + self:combatSpellpower(0.03) * self:getTalentLevel(t) end,
	action = function(self, t)
		local tg = {type="hit", range=self:getTalentRange(t), talent=t}
		local x, y = self:getTarget(tg)
		if not x or not y then return nil end
		self:project(tg, x, y, DamageType.TIME_PRISON, t.getDuration(self, t), {type="manathrust"})
		game:playSoundNear(self, "talents/spell_generic")
		return true
	end,
	info = function(self, t)
		local duration = t.getDuration(self, t)
		return ([[将目标从时光的流动中移出，持续 %d 回合。在此状态下，目标不能动作也不能被伤害。
		对于目标来说，时间是静止的，技能无法冷却，也没有能量回复……
		受法术强度影响，持续时间有额外加成。]]):
		format(duration)
	end,
}

newTalent{
	name = "Essence of Speed",
	display_name = "时间加速",
	type = {"spell/temporal",4},
	require = spells_req4,
	points = 5,
	mode = "sustained",
	sustain_mana = 250,
	cooldown = 30,
	tactical = { BUFF = 2 },
	getHaste = function(self, t) return self:getTalentLevel(t) * 0.09 end,
	activate = function(self, t)
		game:playSoundNear(self, "talents/spell_generic")
		local power = t.getHaste(self, t)
		return {
			speed = self:addTemporaryValue("global_speed_add", power),
		}
	end,
	deactivate = function(self, t, p)
		self:removeTemporaryValue("global_speed_add", p.speed)
		return true
	end,
	info = function(self, t)
		local haste = t.getHaste(self, t)
		return ([[增加施法者 %d%% 总体速度。]]):
		format(100 * haste)
	end,
}
