-- 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 = "Blurred Mortality",
	display_name = "模糊死亡",
	type = {"spell/necrosis",1},
	require = spells_req1,
	mode = "sustained",
	points = 5,
	sustain_mana = 30,
	cooldown = 30,
	tactical = { BUFF = 2 },
	activate = function(self, t)
		local ret = {
			die_at = self:addTemporaryValue("die_at", -50 * self:getTalentLevelRaw(t)),
		}
		return ret
	end,
	deactivate = function(self, t, p)
		self:removeTemporaryValue("die_at", p.die_at)
		return true
	end,
	info = function(self, t)
		return ([[对你而言，生死之别变的模糊，你只有在生命值下降到 -%d 时才会死亡。
		不管怎样，当你生命值降到0时，你无法看到你还剩多少生命值。]]):
		format(50 * self:getTalentLevelRaw(t))
	end,
}

newTalent{
	name = "Impending Doom",
	display_name = "灾厄降临",
	type = {"spell/necrosis",2},
	require = spells_req2,
	points = 5,
	mana = 70,
	cooldown = 30,
	tactical = { ATTACK = { ARCANE = 3 }, DISABLE = 2 },
	range = 7,
	requires_target = true,
	getMax = function(self, t) return 200 + self:combatTalentSpellDamage(t, 28, 850) end,
	getDamage = function(self, t) return 50 + self:combatTalentSpellDamage(t, 10, 100) end,
	action = function(self, t)
		local tg = {type="hit", 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 dam = target.life * t.getDamage(self, t) / 100
			dam = math.min(dam, t.getMax(self, t))
			target:setEffect(target.EFF_IMPENDING_DOOM, 10, {dam=dam/10, src=self})
		end, 1, {type="freeze"})
		return true
	end,
	info = function(self, t)
		return ([[你使目标厄运临头。目标不能回复或治疗且会对目标造成它 %d%% 剩余生命值的奥术伤害（或 %0.2f ，取最小伤害值），持续10回合。
		受法术强度影响，伤害有额外加成。]]):
		format(t.getDamage(self, t), t.getMax(self, t))
	end,
}

newTalent{
	name = "Undeath Link",
	display_name = "亡灵分流",
	type = {"spell/necrosis",3},
	require = spells_req3,
	points = 5,
	random_ego = "attack",
	mana = 35,
	cooldown = 20,
	tactical = { HEAL = 2 },
	is_heal = true,
	getHeal = function(self, t) return 20 + self:combatTalentSpellDamage(t, 10, 70) end,
	on_pre_use = function(self, t)
		if game.party and game.party:hasMember(self) then
			for act, def in pairs(game.party.members) do
				if act.summoner and act.summoner == self and act.necrotic_minion then
					return true
				end
			end
		else
			for uid, act in pairs(game.level.entities) do
				if act.summoner and act.summoner == self and act.necrotic_minion then
					return true
				end
			end
		end
		return false
	end,
	action = function(self, t)
		local heal = t.getHeal(self, t)
		if game.party and game.party:hasMember(self) then
			for act, def in pairs(game.party.members) do
				if act.summoner and act.summoner == self and act.necrotic_minion then
					act:takeHit(act.max_life * heal / 100, self)
				end
			end
		else
			for uid, act in pairs(game.level.entities) do
				if act.summoner and act.summoner == self and act.necrotic_minion then
					act:takeHit(act.max_life * heal / 100, self)
				end
			end
		end
		self:heal(self.max_life * heal / 100)
		game:playSoundNear(self, "talents/ice")
		return true
	end,
	info = function(self, t)
		local heal = t.getHeal(self, t)
		return ([[吸收你所有亡灵随从 %d%% 的生命值（可能会杀死它们）并使用这股能量治愈你 %d%% 总生命值。
		受法术强度影响，治疗量有额外加成。]]):
		format(heal, heal)
	end,
}

newTalent{
	name = "Lichform",
	display_name = "巫妖转生",
	type = {"spell/necrosis",4},
	require = {
		stat = { mag=function(level) return 40 + (level-1) * 2 end },
		level = function(level) return 20 + (level-1)  end,
		special = { desc="'From Death, Life' quest completed", fct=function(self, t) return self:isQuestStatus("lichform", engine.Quest.DONE) end},
	},
	mode = "sustained",
	points = 5,
	sustain_mana = 150,
	cooldown = 30,
	no_unlearn_last = true,
	no_npc_use = true,
	becomeLich = function(self, t)
		self.descriptor.race = "Undead"
		self.descriptor.subrace = "Lich"
		self.moddable_tile = "skeleton"
		self.moddable_tile_nude = true
		self.moddable_tile_base = "base_lich_01.png"
		self.moddable_tile_ornament = nil
		self.blood_color = colors.GREY
		self:attr("poison_immune", 1)
		self:attr("disease_immune", 0.5)
		self:attr("stun_immune", 0.5)
		self:attr("cut_immune", 1)
		self:attr("fear_immune", 1)
		self:attr("no_breath", 1)
		self:attr("undead", 1)
		self.resists[DamageType.COLD] = (self.resists[DamageType.COLD] or 0) + 20
		self.resists[DamageType.DARKNESS] = (self.resists[DamageType.DARKNESS] or 0) + 20
		self.inscription_restrictions = self.inscription_restrictions or {}
		self.inscription_restrictions["inscriptions/runes"] = true
		self.inscription_restrictions["inscriptions/taints"] = true

		local level = self:getTalentLevel(t)
		if level < 2 then
			self:incIncStat("mag", -3) self:incIncStat("wil", -3)
			self.resists.all = (self.resists.all or 0) - 10
		elseif level < 3 then
			-- nothing
		elseif level < 4 then
			self:incIncStat("mag", 3) self:incIncStat("wil", 3)
			self.life_rating = self.life_rating + 1
		elseif level < 5 then
			self:incIncStat("mag", 3) self:incIncStat("wil", 3)
			self:attr("combat_spellresist", 10) self:attr("combat_mentalresist", 10)
			self.life_rating = self.life_rating + 2
		elseif level < 6 then
			self:incIncStat("mag", 5) self:incIncStat("wil", 5)
			self:attr("combat_spellresist", 10) self:attr("combat_mentalresist", 10)
			self.resists_cap.all = (self.resists_cap.all or 0) + 10
			self.life_rating = self.life_rating + 2
		else
			self:incIncStat("mag", 6) self:incIncStat("wil", 6) self:incIncStat("cun", 6)
			self:attr("combat_spellresist", 15) self:attr("combat_mentalresist", 15)
			self.resists_cap.all = (self.resists_cap.all or 0) + 15
			self.life_rating = self.life_rating + 3
		end

		if self:attr("blood_life") then
			self.blood_life = nil
			game.log("#GREY#As you turn into a powerful undead you feel your body violently rejecting the Blood of Life.")
		end

		require("engine.ui.Dialog"):simplePopup("Lichform", "#GREY#You feel your life slip away, only to be replaced by pure arcane forces! Your flesh starts to rot on your bones, and your eyes fall apart as you are reborn into a Lich!")

		game.level.map:particleEmitter(self.x, self.y, 1, "demon_teleport")
	end,
	on_pre_use = function(self, t)
		if self:attr("undead") then return false else return true end
	end,
	activate = function(self, t)
		local ret = {
			mana = self:addTemporaryValue("mana_regen", -4),
		}
		return ret
	end,
	deactivate = function(self, t, p)
		self:removeTemporaryValue("mana_regen", p.mana)
		return true
	end,
	info = function(self, t)
		return ([[你的终极目标。所有亡灵法师的目标，就是变成一个强大且永生的巫妖！
		当此技能激活时，如果你被杀死，你的身体会被转化为巫妖。
		所有的巫妖会增加以下天赋：
		*毒系、切割、恐惧免疫
		*50%%疾病抵抗
		*50%%震慑抵抗
		*20%%冰冷和暗系抵抗
		*不需要呼吸
		*铭文（infusion）不起作用
		同时：
		*等级1：-3所有属性，-10%%所有抵抗。如此微小的代价！
		*等级2：无
		*等级3：+3魔力和意志，+1每等级增加生命值（不追加前面等级的生命值）。
		*等级4：+3魔力和意志，+2每等级增加生命值（不追加前面等级的生命值），+10法术和精神抵抗。
		*等级5：+5魔力和意志，+2每等级增加生命值（不追加前面等级的生命值），+10法术和精神抵抗，所有抵抗上限增加10%。
		*等级6：+6魔力、意志和机智，+3每等级增加生命值（不追加前面等级的生命值），+15法术和精神抵抗，所有抵抗上限增加15%。恐惧我的力量吧！
		不死族无法使用此天赋。
		当此技能激活时，每回合消耗4法力值。5]]):
		format()
	end,
}
