-- 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 = "Vitality",
	display_name = "活力",
	type = {"technique/conditioning", 1},
	require = techs_con_req1,
	mode = "passive",
	points = 5,
	getWoundReduction = function(self, t) return self:getTalentLevel(t)/10 end,
	getHealMod = function(self, t) return self:combatTalentStatDamage(t, "con", 20, 80) end,
	getLifeRegen = function(self, t) return self:combatTalentStatDamage(t, "con", 2, 20) end,
	getDuration = function(self, t) return 2 + math.ceil(self:getTalentLevel(t)) end,
	do_vitality_recovery = function(self, t)
		self:setEffect(self.EFF_RECOVERY, t.getDuration(self, t), {heal_mod = t.getHealMod(self, t), regen = t.getLifeRegen(self, t)})
	end,
	info = function(self, t)
		local wounds = t.getWoundReduction(self, t) * 100
		local regen = t.getLifeRegen(self, t)
		local healmod = t.getHealMod(self, t)
		local duration = t.getDuration(self, t)
		return ([[你受中毒、疾病和创伤的影响变小，减少 %d%% 此类效果的持续时间。此外你会增加 %0.2f 生命值回复并且在生命低于50%%时自我恢复 %d%% 生命值。
		受体质影响，生命回复值和恢复血量有额外加成。]]):
		format(wounds, regen, healmod, duration)
	end,
}

newTalent{
	name = "Daunting Presence",
	display_name = "望而生畏",
	type = {"technique/conditioning", 2},
	require = techs_con_req2,
	points = 5,
	mode = "sustained",
	sustain_stamina = 20,
	cooldown = 8,
	tactical = { DEFEND = 2, DISABLE = 1, },
	range = 0,
	getRadius = function(self, t) return math.ceil(self:getTalentLevel(t)/2) end,
	getPenalty = function(self, t) return self:combatTalentStatDamage(t, "con", 5, 25) end,
	getMinimumLife = function(self, t)
		return self.max_life * (0.5 - (self:getTalentLevel(t)/20))
	end,
	on_pre_use = function(self, t, silent) if t.getMinimumLife(self, t) > self.life then if not silent then game.logPlayer(self, "You are too injured to use this talent.") end return false end return true end,
	do_daunting_presence = function(self, t)
		local tg = {type="ball", range=0, radius=t.getRadius(self, t), friendlyfire=false, talent=t}
		self:project(tg, self.x, self.y, function(px, py)
			local target = game.level.map(px, py, engine.Map.ACTOR)
			if target then
				if target:canBe("fear") then
					target:setEffect(target.EFF_INTIMIDATED, 4, {apply_power=self:combatAttackStr(), power=t.getPenalty(self, t)})
					game.level.map:particleEmitter(target.x, target.y, 1, "flame")
				else
					game.logSeen(target, "%s is not intimidated!", target.name:capitalize())
				end
			end
		end)
	end,
	activate = function(self, t)
		local ret = {	}
		return ret
	end,
	deactivate = function(self, t, p)
		return true
	end,
	info = function(self, t)
		local radius = t.getRadius(self, t)
		local penalty = t.getPenalty(self, t)
		local min_life = t.getMinimumLife(self, t)
		return ([[敌人因你不屈不挠的意志而感到恐慌。当你承受超过5%%最大生命值的单次伤害时，你周围 %d 格半径的敌人都会感到恐慌，减少 %d 物理强度、法术强度、精神强度4回合。
		如果你的生命值低于 %d 你将不能激活此技能且此技能自动停止。
		受体质影响，威胁效果有加成。]]):
		format(radius, penalty, min_life)
	end,
}

newTalent{
	name = "Unflinching Resolve",
	display_name = "顽强意志",
	type = {"technique/conditioning", 3},
	require = techs_con_req3,
	mode = "passive",
	points = 5,
	getChance = function(self, t) return self:combatTalentStatDamage(t, "con", 50, 100) end,
	do_unflinching_resolve = function(self, t)
		local effs = {}
		-- Go through all spell effects
		for eff_id, p in pairs(self.tmp) do
			local e = self.tempeffect_def[eff_id]
			if e.status == "detrimental" then
				if e.subtype.stun then 
					effs[#effs+1] = {"effect", eff_id}
				elseif e.subtype.blind and self:getTalentLevel(t) >=2 then
					effs[#effs+1] = {"effect", eff_id}
				elseif e.subtype.confusion and self:getTalentLevel(t) >=3 then
					effs[#effs+1] = {"effect", eff_id}
				elseif e.subtype.pin and self:getTalentLevel(t) >=4 then
					effs[#effs+1] = {"effect", eff_id}
				elseif e.subtype.slow and self:getTalentLevel(t) >=5 then
					effs[#effs+1] = {"effect", eff_id}
				end
			end
		end
		
		if #effs > 0 then
			local eff = rng.tableRemove(effs)
			if eff[1] == "effect" and rng.percent(t.getChance(self, t)) then
				self:removeEffect(eff[2])
				game.logSeen(self, "%s has recovered!", self.name:capitalize())
			end
		end
	end,
	info = function(self, t)
		local chance = t.getChance(self, t)
		return ([[你学会从负面状态中快速恢复。每回合你有 %d%% 从震慑效果中恢复。
		在等级2时，有概率从致盲效果中恢复。
		在等级3时，有概率从混乱效果中恢复。
		在等级4时，有概率重定身效果中恢复。
		在等级5时，有概率从减速效果中恢复。 
		每回合你只能从1种状态中恢复。受体质影响，恢复概率有额外加成。]]):
		format(chance)
	end,
}

newTalent{
	name = "Adrenaline Surge", -- no stamina cost; it's main purpose is to give the player an alternative means of using stamina based talents
	display_name = "肾上腺素",
	type = {"technique/conditioning", 4},
	require = techs_con_req4,
	points = 5,
	cooldown = 24,
	tactical = { STAMINA = 1, BUFF = 2 },
	getAttackPower = function(self, t) return self:combatTalentStatDamage(t, "con", 5, 25) end,
	getDuration = function(self, t) return 2 + math.ceil(self:getTalentLevel(t)) end,
	action = function(self, t)
		self:setEffect(self.EFF_ADRENALINE_SURGE, t.getDuration(self, t), {power = t.getAttackPower(self, t)})
		return true
	end,
	info = function(self, t)
		local attack_power = t.getAttackPower(self, t)
		local duration = t.getDuration(self, t)
		return ([[你激活肾上腺素来增加 %d 物理强度持续 %d 回合。此技能激活时，你可以不知疲倦地战斗，若体力为0，可继续使用消耗类技能，代价为消耗生命。
		受体质影响，物理强度有额外加成。]]):
		format(attack_power, duration)
	end,
}
