-- 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 = "Resolve",
	display_name = "分解",
	type = {"wild-gift/antimagic", 1},
	require = gifts_req1,
	mode = "passive",
	points = 5,
	on_absorb = function(self, t, damtype)
		if not DamageType:get(damtype).antimagic_resolve then return end

		if not self:isTalentActive(self.T_ANTIMAGIC_SHIELD) then
			local equi = 1 + self:combatTalentMindDamage(t, 10, 5)
			local stamina = 1 + self:combatTalentMindDamage(t, 10, 10)
			self:incEquilibrium(-equi)
			self:incStamina(stamina)
		end
		self:setEffect(self.EFF_RESOLVE, 7, {damtype=damtype, res=self:combatTalentMindDamage(t, 10, 40)})
		game.logSeen(self, "%s is invigorated by the attack!", self.name:capitalize())
	end,
	info = function(self, t)
		return ([[你的反魔法力量使你能抵抗魔法伤害。
		每次受到一种魔法伤害时，你能增加 %d%% 对该元素的抵抗持续7回合。
		如果没有激活反魔法护盾，你同时还可以吸收部分能量，降低 %d 失衡值，增加 %d 体力值。
		该效果受意志有额外加成。]]):
		format(
			self:combatTalentMindDamage(t, 10, 40),
			1 + self:combatTalentMindDamage(t, 10, 5),
			1 + self:combatTalentMindDamage(t, 10, 10)
		)
	end,
}

newTalent{
	name = "Aura of Silence",
	display_name = "沉默光环",
	type = {"wild-gift/antimagic", 2},
	require = gifts_req2,
	points = 5,
	equilibrium = 20,
	cooldown = 10,
	tactical = { DISABLE = { silence = 4 } },
	radius = function(self, t) return 4 + self:getTalentLevel(t) * 1.5 end,
	target = function(self, t)
		return {type="ball", range=self:getTalentRange(t), radius=self:getTalentRadius(t), selffire=true, talent=t}
	end,
	action = function(self, t)
		local tg = self:getTalentTarget(t)
		self:project(tg, self.x, self.y, DamageType.SILENCE, 3 + math.floor(self:getTalentLevel(t) / 2))
		return true
	end,
	info = function(self, t)
		local rad = self:getTalentRadius(t)
		return ([[发出一次音波冲击，沉默你自己和周围目标 %d 回合，有效范围 %d 格。
		沉默几率受意志影响有额外加成。]]):
		format(3 + math.floor(self:getTalentLevel(t) / 2), rad)
	end,
}

newTalent{
	name = "Antimagic Shield",
	display_name = "反魔法护盾",
	type = {"wild-gift/antimagic", 3},
	require = gifts_req3,
	mode = "sustained",
	points = 5,
	sustain_equilibrium = 30,
	cooldown = 20,
	range = 10,
	tactical = { DEFEND = 2 },
	on_damage = function(self, t, damtype, dam)
		if not DamageType:get(damtype).antimagic_resolve then return dam end

		if dam <= self.antimagic_shield then
			self:incEquilibrium(dam / 30)
			dam = 0
		else
			self:incEquilibrium(self.antimagic_shield / 30)
			dam = dam - self.antimagic_shield
		end

		if not self:equilibriumChance() then
			self:forceUseTalent(self.T_ANTIMAGIC_SHIELD, {ignore_energy=true})
			game.logSeen(self, "#GREEN#The antimagic shield of %s crumbles.", self.name)
		end
		return dam
	end,
	activate = function(self, t)
		game:playSoundNear(self, "talents/heal")
		return {
			am = self:addTemporaryValue("antimagic_shield", self:combatTalentMindDamage(t, 20, 80)),
		}
	end,
	deactivate = function(self, t, p)
		self:removeTemporaryValue("antimagic_shield", p.am)
		return true
	end,
	info = function(self, t)
		return ([[给你增加一个护盾，每次被攻击吸收最多 %d 魔法或元素伤害。
		每次伤害吸收都会增加1失衡值，每受30点伤害有一定几率护盾被打碎。
		护盾吸收的伤害值受意志影响有额外加成。]]):
		format(self:combatTalentMindDamage(t, 20, 80))
	end,
}

newTalent{
	name = "Mana Clash",
	display_name = "法力对撞",
	type = {"wild-gift/antimagic", 4},
	require = gifts_req4,
	points = 5,
	equilibrium = 10,
	cooldown = 10,
	range = 10,
	tactical = { ATTACK = { ARCANE = 3 } },
	action = function(self, t)
		local tg = {type="bolt", range=self:getTalentRange(t), talent=t}
		local x, y = self:getTarget(tg)
		if not x or not y then return nil end
		self:project(tg, x, y, function(px, py)
			local target = game.level.map(px, py, Map.ACTOR)
			if not target then return end

			local base = self:combatTalentMindDamage(t, 20, 230)
			local mana = base * 2
			local vim = base
			local positive = base / 2
			local negative = base / 2

			mana = math.min(target:getMana(), mana)
			vim = math.min(target:getVim(), vim)
			positive = math.min(target:getPositive(), positive)
			negative = math.min(target:getNegative(), negative)

			target:incMana(-mana)
			target:incVim(-vim)
			target:incPositive(-positive)
			target:incNegative(-negative)

			local dam = math.max(mana, vim * 2, positive * 4, negative * 4) * 1.3
			DamageType:get(DamageType.ARCANE).projector(self, px, py, DamageType.ARCANE, dam)
		end, nil, {type="slime"})
		game:playSoundNear(self, "talents/heal")
		return true
	end,
	info = function(self, t)
		local base = self:combatTalentMindDamage(t, 20, 230)
		local mana = base * 2
		local vim = base
		local positive = base / 2
		local negative = base / 2

		return ([[从你目标身上吸收 %d 法力, %d 活力, %d 正或负能力,并触发一次魔法对撞，引发一次魔法爆炸。
		造成130%%吸收的法力或260%%吸收的活力或520%%吸收的正负能量的伤害，按最高值的计算。
		效果受意志影响有额外加成。]]):
		format(mana, vim, positive, negative)
	end,
}
