-- 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

-- race & classes
newTalentType{ type="base/class", name = "职业", hide = true, description = "职业的基础技能。" }
newTalentType{ type="base/race", name = "种族", hide = true, description = "不同种族拥有的专长技能。" }
newTalentType{ type="inscriptions/infusions", name = "注入", hide = true, description = "Infusions不是职业技能，你必须找到它们或者从别人那里习得。" }
newTalentType{ is_spell=true, no_silence=true, type="inscriptions/runes", name = "符文", hide = true, description = "Runes不是职业技能，你必须找到它们或者从别人那里习得。" }
newTalentType{ is_spell=true, no_silence=true, type="inscriptions/taints", name = "taints", hide = true, description = "Taints不是职业技能，你必须找到它们或者从别人那里习得。" }

-- Load other misc things
load("/data/talents/misc/inscriptions.lua")
load("/data/talents/misc/npcs.lua")
load("/data/talents/misc/horrors.lua")
load("/data/talents/misc/races.lua")
load("/data/talents/misc/tutorial.lua")

-- Default melee attack
newTalent{
	name = "Attack",
	display_name = "攻击",
	type = {"base/class", 1},
	no_energy = "fake",
	hide = true,
	innate = true,
	points = 1,
	range = 1,
	message = false,
	no_break_stealth = true, -- stealth is broken in attackTarget
	requires_target = true,
	target = {type="hit", range=1},
	tactical = { ATTACK = { PHYSICAL = 1 } },
	no_unlearn_last = true,
	ignored_by_hotkeyautotalents = true,
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		local x, y = self:getTarget(tg)
		if not x then return end
		local _ _, x, y = self:canProject(tg, x, y)
		if not x then return end
		local target = game.level.map(x, y, engine.Map.ACTOR)
		if not target then return end

		local double_strike = false
		if self:knowTalent(self.T_DOUBLE_STRIKE) and self:isTalentActive(self.T_STRIKING_STANCE) then
			local t = self:getTalentFromId(self.T_DOUBLE_STRIKE)
			if not self:isTalentCoolingDown(t) then
				double_strike = true
			end
		end
		-- if double strike isn't on cooldown, throw a double strike; quality of life hack
		if double_strike then
			self:forceUseTalent(self.T_DOUBLE_STRIKE, {force_target=target}) -- uses energy because attack is 'fake'
		else
			self:attackTarget(target)
		end
		return true
	end,
	info = function(self, t)
		return ([[Hack and slash, baby!]])
	end,
}

--mindslayer resource
newTalent{
	name = "Psi Pool",
	display_name = "灵能槽",
	type = {"base/class", 1},
	info = "灵能能量，使你能使用精神技能。",
	mode = "passive",
	hide = true,
	no_unlearn_last = true,
}

newTalent{
	name = "Mana Pool",
	display_name = "法力槽",
	type = {"base/class", 1},
	info = "Allows you to have a mana pool. Mana is used to cast all spells.",
	mode = "passive",
	hide = true,
	no_unlearn_last = true,
}
newTalent{
	name = "Vim Pool",
	display_name = "活力槽",
	type = {"base/class", 1},
	info = "Allows you to have a vim pool. Vim is used by corruptions.",
	mode = "passive",
	hide = true,
	no_unlearn_last = true,
}
newTalent{
	name = "Stamina Pool",
	display_name = "体力槽",
	type = {"base/class", 1},
	info = "Allows you to have a stamina pool. Stamina is used to activate special combat attacks.",
	mode = "passive",
	hide = true,
	no_unlearn_last = true,
}
newTalent{
	name = "Equilibrium Pool",
	display_name = "失衡值槽",
	type = {"base/class", 1},
	info = "Allows you to have an equilibrium pool. Equilibrium is used to measure your balance with nature and the use of wild gifts.",
	mode = "passive",
	hide = true,
	no_unlearn_last = true,
}
newTalent{
	name = "Positive Pool",
	display_name = "正能量槽",
	type = {"base/class", 1},
	info = "Allows you to have a positive energy pool.",
	mode = "passive",
	hide = true,
	no_unlearn_last = true,
}
newTalent{
	name = "Negative Pool",
	display_name = "负能量槽",
	type = {"base/class", 1},
	info = "Allows you to have a negative energy pool.",
	mode = "passive",
	hide = true,
	no_unlearn_last = true,
}
newTalent{
	name = "Hate Pool",
	display_name = "仇恨值槽",
	type = {"base/class", 1},
	info = "Allows you to have a hate pool.",
	mode = "passive",
	hide = true,
	no_unlearn_last = true,
}

newTalent{
	name = "Paradox Pool",
	display_name = "紊乱值槽",
	type = {"base/class", 1},
	info = "Allows you to have a paradox pool.",
	mode = "passive",
	hide = true,
	no_unlearn_last = true,
}

-- Mages class talent, teleport to angolwen
newTalent{
	short_name = "TELEPORT_ANGOLWEN",
	name = "Teleport: Angolwen",
	display_name = "传送：Angolwen",
	type = {"base/class", 1},
	cooldown = 400,
	no_npc_use = true,
	no_unlearn_last = true,
	no_silence=true, is_spell=true,
	action = function(self, t)
		if not self:canBe("worldport") or self:attr("never_move") then
			game.logPlayer(self, "The spell fizzles...")
			return
		end

		local seen = false
		-- Check for visible monsters, only see LOS actors, so telepathy wont prevent it
		core.fov.calc_circle(self.x, self.y, game.level.map.w, game.level.map.h, 20, function(_, x, y) return game.level.map:opaque(x, y) end, function(_, x, y)
			local actor = game.level.map(x, y, game.level.map.ACTOR)
			if actor and actor ~= self then seen = true end
		end, nil)
		if seen then
			game.log("There are creatures that could be watching you; you cannot take the risk.")
			return
		end

		self:setEffect(self.EFF_TELEPORT_ANGOLWEN, 40, {})
		return true
	end,
	info = [[允许你传送至秘密的小镇：Angolwen。
	你已经在那里学习了很多魔法知识并且学会传送至这个小镇。
	其他人是不允许学习这种法术的所以你施法时不能被任何生物看到。
	法术将消耗一段时间生效，你施放法术及法术生效以前你必须保持在其他生物视线以外。]]
}

newTalent{
	name = "Relentless Pursuit",
	display_name = "无尽追踪",
	type = {"base/class", 1},
	points = 5,
	no_energy = true,
	cooldown = function(self, t) return 55 - self:getTalentLevel(t) * 5 end,
	tactical = { CURE = function(self, t, target)
		local nb = 0
		for eff_id, p in pairs(self.tmp) do
			local e = self.tempeffect_def[eff_id]
			if e.status == "detrimental" then nb = nb + 1 end
		end
		return nb
	end},
	action = function(self, t)
		local target = self
		local todel = {}

		local save_for_effects = {
			magical = "combatSpellResist",
			mental = "combatMentalResist",
			physical = "combatPhysicalResist",
		}
		for eff_id, p in pairs(target.tmp) do
			local e = target.tempeffect_def[eff_id]
			if e.status == "detrimental" and save_for_effects[e.type] then
				local save = self[save_for_effects[e.type]](self)
				local decrease = math.floor(save/5)
				print("About to reduce duration of... %s. Will use %s. Reducing duration by %d", e.desc, save_for_effects[e.type])
				p.dur = p.dur - decrease
				if p.dur <= 0 then todel[#todel+1] = eff_id end
			end
		end
		while #todel > 0 do
			target:removeEffect(table.remove(todel))
		end
		game:playSoundNear(self, "talents/spell_generic")
		return true
	end,
	info = function(self, t)
		local physical_reduction = math.floor(self:combatPhysicalResist()/5)
		local spell_reduction = math.floor(self:combatSpellResist()/5)
		local mental_reduction = math.floor(self:combatMentalResist()/5)
		return ([[无论是它的主人、陷落的Reknor的兽人还是Reknor传送上令人恐怖的未知生物都无法阻止你寻找虹吸法杖的魔力。
		孩子们会在将来用歌曲来传唱你的无情。
		当激活时，可以缩短所有不利效果的有效时间。
		物理效果持续时间缩短 %d 回合
		魔法效果持续时间缩短 %d 回合
		精神效果持续时间缩短 %d 回合]]):
		format(physical_reduction, spell_reduction, mental_reduction)
	end,
}
