-- 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 = "Deflect Projectiles",
	display_name = "抛射偏移",
	type = {"psionic/grip", 1},
	require = psi_wil_20_1,
	points = 5,
	mode = "sustained",
	sustain_psi = 35,
	getEvasion = function(self, t) return 10 + self:getTalentLevel(t) * 7, self:getTalentLevel(t) >= 4 and 2 or 1 end,
	activate = function(self, t)
		local chance, spread = t.getEvasion(self, t)
		return {
			chance = self:addTemporaryValue("projectile_evasion", chance),
			spread = self:addTemporaryValue("projectile_evasion_spread", spread),
		}
	end,
	deactivate = function(self, t, p)
		self:removeTemporaryValue("projectile_evasion", p.chance)
		self:removeTemporaryValue("projectile_evasion_spread", p.spread)
		return true
	end,
	info = function(self, t)
		local chance, spread = t.getEvasion(self, t)
		return ([[你学会使用一部分精神力，击落、抓取或者用其他方式偏转想你飞来的抛射物。
		所有攻击你的抛射物有 %d%% 概率偏移到旁边 %d 格。]]):
		format(chance, spread)
	end,

}

newTalent{
	name = "Bind",
	display_name = "灵能捆绑",
	type = {"psionic/grip", 2},
	require = psi_wil_20_2,
	points = 5,
	random_ego = "attack",
	cooldown = function(self, t)
		local c = 25
		local gem_level = getGemLevel(self)
		return math.max(c - gem_level, 0)
	end,
	psi = 10,
	tactical = { DISABLE = 2 },
	range = function(self, t)
		local r = 5
		local gem_level = getGemLevel(self)
		local mult = (1 + 0.02*gem_level*(self:getTalentLevel(self.T_REACH)))
		r = math.floor(r*mult)
		return math.min(r, 10)
	end,
	getDuration = function (self, t)
		local gem_level = getGemLevel(self)
		return self:combatStatTalentIntervalDamage(t, "combatMindpower", 3, 10, 0.2) + gem_level
	end,
	requires_target = true,
	target = function(self, t) return {type="ball", range=self:getTalentRange(t), radius=0, selffire=false, talent=t} end,
	action = function(self, t)
		local gem_level = getGemLevel(self)
		local dur = t.getDuration(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)
		game:playSoundNear(self, "talents/spell_generic")
		local target = game.level.map(x, y, Map.ACTOR)
		if target then
			target:setEffect(self.EFF_PSIONIC_BIND, dur, {power=1, apply_power=self:combatMindpower()})
		else
			return
		end
		return true
	end,
	info = function(self, t)
		local dur = t.getDuration(self, t)
		return ([[用巨大的束缚能量捆住目标 %d 回合。
		当意念装备1颗宝石时，将会增加技能效果。]]):
		format(dur)
	end,
}

newTalent{
	name = "Implode",
	display_name = "碎骨压制",
	type = {"psionic/grip", 3},
	require = psi_wil_20_3,
	points = 5,
	random_ego = "attack",
	cooldown = function(self, t)
		local c = 45
		local gem_level = getGemLevel(self)
		return math.max(c - 2 * gem_level, 0)
	end,
	psi = 40,
	tactical = { ATTACK = { PHYSICAL = 2 } },
	range = function(self, t)
		local r = 3
		local gem_level = getGemLevel(self)
		local mult = (1 + 0.02*gem_level*(self:getTalentLevel(self.T_REACH)))
		r = math.floor(r*mult)
		return math.min(r, 10)
	end,
	getDuration = function (self, t)
		local gem_level = getGemLevel(self)
		return self:combatStatTalentIntervalDamage(t, "combatMindpower", 2, 6, 0.2)
	end,
	getDamage = function (self, t)
		local gem_level = getGemLevel(self)
		return self:combatStatTalentIntervalDamage(t, "combatMindpower", 100, 150, 0.25)*(1 + 0.1*gem_level)
	end,
	requires_target = true,
	target = function(self, t) return {type="ball", range=self:getTalentRange(t), radius=0, selffire=false, talent=t} end,
	action = function(self, t)
		local dur = t.getDuration(self, t)
		local dam = t.getDamage(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		if not x or not y then return nil end
		self:project(tg, x, y, DamageType.IMPLOSION, {dur=dur, dam=dam})
--		target:crossTierEffect(target.EFF_OFFBALANCE, self:combatMindpower())

		return true
	end,
	info = function(self, t)
		local dur = t.getDuration(self, t)
		local dam = t.getDamage(self, t)
		return ([[使用一股能导致骨裂的压力残忍地压制目标，减少目标50%%速度 %d 回合，每回合造成 %d 伤害。
		当意念装备1颗宝石时，将会增加技能效果。]]):
		format(dur, dam)
	end,
}


newTalent{
	name = "Greater Telekinetic Grasp",
	display_name = "灵能支配",
	type = {"psionic/grip", 4},
	require = psi_wil_20_4,
	points = 5,
	mode = "passive",
	stat_sub = function(self, t)
		return .6 + .04 * self:getTalentLevel(t)
	end,
	on_learn = function(self, t)
		self.disarm_immune = (self.disarm_immune or 0) + .2
	end,

	on_unlearn = function(self, t)
		self.disarm_immune = (self.disarm_immune or 0) - .2
	end,
	info = function(self, t)
		local boost = 100 * t.stat_sub(self, t)
		return ([[用细致的操控来增加你的肉体支配和能量支配。
		此技能有以下效果：
		增加 %d%%缴械免疫。
		当使用充能武器造成伤害时，用 %d%% 意志和灵巧（通常60%%）来代替力量和敏捷决定伤害。
		在等级5时，意念装备宝石品质提升一级。]]):
		format(self:getTalentLevelRaw(t)*20, boost)
	end,
}
