-- 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 = "Arcane Eye",
	display_name = "奥术之眼",
	type = {"spell/divination", 1},
	require = spells_req1,
	points = 5,
	mana = 15,
	cooldown = 10,
	no_energy = true,
	no_npc_use = true,
	requires_target = true,
	getDuration = function(self, t) return math.floor(10 + self:getTalentLevel(t) * 3) end,
	getRadius = function(self, t) return math.floor(4 + self:getTalentLevel(t)) end,
	action = function(self, t)
		local tg = {type="hit", nolock=true, pass_terrain=true, nowarning=true, range=100, requires_knowledge=false}
		x, y = self:getTarget(tg)
		if not x then return nil end
		-- Target code does not restrict the target coordinates to the range, it lets the project function do it
		-- but we cant ...
		local _ _, x, y = self:canProject(tg, x, y)

		self:setEffect(self.EFF_ARCANE_EYE, t.getDuration(self, t), {x=x, y=y, track=(self:getTalentLevel(t) >= 4) and game.level.map(x, y, Map.ACTOR) or nil, radius=t.getRadius(self, t), true_seeing=self:getTalentLevel(t) >= 5})
		game:playSoundNear(self, "talents/spell_generic")
		return true
	end,
	info = function(self, t)
		local radius = t.getRadius(self, t)
		local duration = t.getDuration(self, t)
		return ([[召唤1个奥术之眼放置于指定地点，持续 %d 回合。
		此眼睛不会被其他生物看见或攻击，它提供魔法视觉，可看到它周围 %d 格范围的怪物。
		它不需要灯光去提供能量，但是当隔着墙时它不可见。
		召唤奥术之眼不消耗回合。
		同时只能存在1个奥术之眼。
		在等级4时，可以在怪物身上放置奥术之眼，持续时间直到技能结束或怪物死亡。
		在等级5时，它可以看穿隐匿单位、潜行单位及其他视觉影响效果。]]):
		format(duration, radius)
	end,
}

newTalent{
	name = "Keen Senses",
	display_name = "敏锐直觉",
	type = {"spell/divination", 2},
	require = spells_req2,
	mode = "sustained",
	points = 5,
	sustain_mana = 40,
	tactical = { BUFF = 2 },
	cooldown = 30,
	getSeeInvisible = function(self, t) return self:combatTalentSpellDamage(t, 2, 45) end,
	getSeeStealth = function(self, t) return self:combatTalentSpellDamage(t, 2, 20) end,
	getCriticalChance = function(self, t) return self:combatTalentSpellDamage(t, 2, 12) end,
	activate = function(self, t)
		game:playSoundNear(self, "talents/spell_generic")
		return {
			invis = self:addTemporaryValue("see_invisible", t.getSeeInvisible(self, t)),
			stealth = self:addTemporaryValue("see_stealth", t.getSeeStealth(self, t)),
			crit = self:addTemporaryValue("combat_spellcrit", t.getCriticalChance(self, t)),
		}
	end,
	deactivate = function(self, t, p)
		self:removeTemporaryValue("see_invisible", p.invis)
		self:removeTemporaryValue("see_stealth", p.stealth)
		self:removeTemporaryValue("combat_spellcrit", p.crit)
		return true
	end,
	info = function(self, t)
		local seeinvisible = t.getSeeInvisible(self, t)
		local seestealth = t.getSeeStealth(self, t)
		local criticalchance = t.getCriticalChance(self, t)
		return ([[你集中精神，通过直觉获取未来的信息。
		增加 %d 点隐匿单位探测强度。
		增加 %d 点潜行单位看穿强度。
		增加 %d%% 法术暴击几率。
		受法术强度影响，此效果有额外加成。]]):
		format(seeinvisible, seestealth, criticalchance)
	end,
}

newTalent{
	name = "Vision",
	display_name = "探测",
	type = {"spell/divination", 3},
	require = spells_req3,
	points = 5,
	random_ego = "utility",
	mana = 20,
	cooldown = 20,
	no_npc_use = true,
	getRadius = function(self, t) return 5 + self:combatTalentSpellDamage(t, 2, 12) end,
	action = function(self, t)
		self:magicMap(t.getRadius(self, t))
		game:playSoundNear(self, "talents/spell_generic")
		return true
	end,
	info = function(self, t)
		local radius = t.getRadius(self, t)
		return ([[通过意念探测周围 %d 格范围地图。]]):
		format(radius)
	end,
}

newTalent{
	name = "Premonition",
	display_name = "预感",
	type = {"spell/divination", 4},
	mode = "sustained",
	require = spells_req4,
	points = 5,
	sustain_mana = 120,
	cooldown = 30,
	tactical = { BUFF = 2 },
	getResist = function(self, t) return 10 + self:combatTalentSpellDamage(t, 2, 25) end,
	on_damage = function(self, t, damtype)
		if damtype == DamageType.PHYSICAL then return end

		if not self:hasEffect(self.EFF_PREMONITION_SHIELD) then
			self:setEffect(self.EFF_PREMONITION_SHIELD, 5, {damtype=damtype, resist=t.getResist(self, t)})
			game.logPlayer(self, "#OLIVE_DRAB#Your premonition allows you to raise a shield just in time!")
		end
	end,
	activate = function(self, t)
		game:playSoundNear(self, "talents/spell_generic")
		return {
		}
	end,
	deactivate = function(self, t, p)
		return true
	end,
	info = function(self, t)
		local resist = t.getResist(self, t)
		return ([[你的眼前会闪烁未来的景象，让你能够预知对你的攻击。
		如果攻击是元素类或魔法类的，那么你会创造一个暂时性的护盾来减少 %d%% 所有此类攻击伤害，持续5回合。
		此效果在5回合内只能激活一次，且在你承受伤害前自动激活。
		受法术强度影响，效果有额外加成。]]):format(resist)
	end,
}
