-- 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 = "Shadow Combat",
	display_name = "影之格斗",
	type = {"cunning/shadow-magic", 1},
	mode = "sustained",
	points = 5,
	require = cuns_req1,
	sustain_stamina = 20,
	cooldown = 5,
	tactical = { BUFF = 2 },
	getDamage = function(self, t) return 2 + self:combatTalentSpellDamage(t, 2, 50) end,
	getManaCost = function(self, t) return 2 end,
	activate = function(self, t)
		return {}
	end,
	deactivate = function(self, t, p)
		return true
	end,
	info = function(self, t)
		local damage = t.getDamage(self, t)
		local manacost = t.getManaCost(self, t)
		return ([[在你的武器上注入一股黑暗的能量，每次攻击会造出 %.2f 暗影伤害并消耗 %.2f 点法力。]]):
		format(damDesc(self, DamageType.DARKNESS, damage), manacost)
	end,
}

newTalent{
	name = "Shadow Cunning",
	display_name = "影之狡诈",
	type = {"cunning/shadow-magic", 2},
	mode = "passive",
	points = 5,
	require = cuns_req2,
	getSpellpower = function(self, t) return 15 + self:getTalentLevel(t) * 3 end,
	info = function(self, t)
		local spellpower = t.getSpellpower(self, t)
		return ([[增加相当于你 %d%% 灵巧的法术强度。]]):
		format(spellpower)
	end,
}

newTalent{
	name = "Shadow Feed",
	display_name = "暗影充能",
	type = {"cunning/shadow-magic", 3},
	mode = "sustained",
	points = 5,
	cooldown = 5,
	sustain_stamina = 40,
	require = cuns_req3,
	range = 10,
	tactical = { BUFF = 2 },
	getManaRegen = function(self, t) return self:getTalentLevel(t) / 14 end,
	activate = function(self, t)
		return {
			regen = self:addTemporaryValue("mana_regen", t.getManaRegen(self, t)),
		}
	end,
	deactivate = function(self, t, p)
		self:removeTemporaryValue("mana_regen", p.regen)
		return true
	end,
	info = function(self, t)
		local manaregen = t.getManaRegen(self, t)
		return ([[当此技能激活时，每回合回复 %0.2f 法力值。]]):
		format(manaregen)
	end,
}

newTalent{
	name = "Shadowstep",
	display_name = "暗影突袭",
	type = {"cunning/shadow-magic", 4},
	points = 5,
	random_ego = "attack",
	cooldown = 5,
	stamina = 30,
	require = cuns_req4,
	tactical = { CLOSEIN = 2, DISABLE = { stun = 1 } },
	range = function(self, t) return math.floor(5 + self:getTalentLevel(t)) end,
	direct_hit = true,
	requires_target = true,
	getDuration = function(self, t) return 2 + self:getTalentLevel(t) end,
	getDamage = function(self, t) return self:combatTalentWeaponDamage(t, 1.2, 2.2) end,
	action = function(self, t)
		if self:attr("never_move") then game.logPlayer(self, "You can not do that currently.") return end

		local tg = {type="hit", range=self:getTalentRange(t)}
		local x, y, target = self:getTarget(tg)
		if not x or not y or not target then return nil end
		if core.fov.distance(self.x, self.y, x, y) > self:getTalentRange(t) then return nil end
		if not game.level.map.seens(x, y) then return nil end

		local tx, ty = util.findFreeGrid(x, y, 20, true, {[engine.Map.ACTOR]=true})
		self:move(tx, ty, true)

		-- Attack ?
		if core.fov.distance(self.x, self.y, x, y) == 1 then
			self:attackTarget(target, DamageType.DARKNESS, t.getDamage(self, t), true)
			if target:canBe("stun") then
				target:setEffect(target.EFF_DAZED, t.getDuration(self, t), {})
			else
				game.logSeen(target, "%s is not dazed!", target.name:capitalize())
			end
		end
		return true
	end,
	info = function(self, t)
		local duration = t.getDuration(self, t)
		return ([[通过阴影突袭你的目标，眩晕它 %d 回合并用你所有武器对目标造成 %d%% 暗影武器伤害。
		被眩晕的目标不能动作，但任何对目标的伤害会解除眩晕。
		当你使用暗影突袭时，目标必须在视野范围内。]]):
		format(duration, t.getDamage(self, t) * 100)
	end,
}

