-- 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
local Chat = require "engine.Chat"

newTalent{
	name = "Life Tap", 
	display_name = "生命分流",
	short_name = "GOLEMANCY_LIFE_TAP",
	type = {"spell/advanced-golemancy", 1},
	require = spells_req_high1,
	points = 5,
	mana = 25,
	cooldown = 12,
	tactical = { HEAL = 2 },
	is_heal = true,
	getPower = function(self, t) return 70 + self:combatTalentSpellDamage(t, 15, 450) end,
	action = function(self, t)
		local mover, golem = getGolem(self)
		if not golem then
			game.logPlayer(self, "Your golem is currently inactive.")
			return
		end

		local power = math.min(t.getPower(self, t), golem.life)
		golem.life = golem.life - power -- Direct hit, bypass all checks
		golem.changed = true
		self:heal(power)
		game:playSoundNear(self, "talents/arcane")
		return true
	end,
	info = function(self, t)
		local power=t.getPower(self, t)
		return ([[你汲取傀儡的生命能量来恢复自己。恢复 %d 点生命。]]):
		format(power)
	end,
}

newTalent{
	name = "Gem Golem",
	display_name = "宝石傀儡",
	type = {"spell/advanced-golemancy",2},
	require = spells_req_high2,
	mode = "passive",
	points = 5,
	info = function(self, t)
		return ([[在傀儡身上镶嵌2颗宝石，它可以得到宝石加成并改变近战攻击类型。
		可用宝石等级： %d
		当你重置傀儡时，宝石改变已定（满血时使用重置傀儡）。]]):format(self:getTalentLevelRaw(t))
	end,
}

newTalent{
	name = "Supercharge Golem",
	display_name = "超能傀儡",
	type = {"spell/advanced-golemancy", 3},
	require = spells_req_high3,
	points = 5,
	mana = 20,
	cooldown = function(self, t) return math.floor(25 - self:getTalentLevel(t)) end,
	tactical = { DEFEND = 1, ATTACK=1 },
	getPower = function(self, t) return (60 + self:combatTalentSpellDamage(t, 15, 450)) / 7, 7, 20 + self:getTalentLevel(t) * 7 end,
	action = function(self, t)
		local regen, dur, hp = t.getPower(self, t)

		-- ressurect the golem
		if not game.level:hasEntity(self.alchemy_golem) or self.alchemy_golem.dead then
			self.alchemy_golem.dead = nil
			self.alchemy_golem.life = self.alchemy_golem.max_life / 100 * hp

			-- Find space
			local x, y = util.findFreeGrid(self.x, self.y, 5, true, {[Map.ACTOR]=true})
			if not x then
				game.logPlayer(self, "Not enough space to supercharge!")
				return
			end
			game.zone:addEntity(game.level, self.alchemy_golem, "actor", x, y)
			self.alchemy_golem:setTarget(nil)
			self.alchemy_golem.ai_state.tactic_leash_anchor = self
			self.alchemy_golem:removeAllEffects()
		end

		local mover, golem = getGolem(self)
		if not golem then
			game.logPlayer(self, "Your golem is currently inactive.")
			return
		end

		golem:setEffect(golem.EFF_SUPERCHARGE_GOLEM, dur, {regen=regen})

		game:playSoundNear(self, "talents/arcane")
		return true
	end,
	info = function(self, t)
		local regen, turns, life = t.getPower(self, t)
		return ([[你激活傀儡的特殊模式，提高它每回合 %0.2f 生命回复速度，持续 %d 回合。
		如果你的傀儡死亡，它会立刻复活，复活时保留 %d%% 生命值。
		此技能激活时你的傀儡处于激怒状态，可增加25%%伤害。]]):
		format(regen, turns, life)
	end,
}



newTalent{
	name = "Runic Golem",
	display_name = "符文傀儡",
	type = {"spell/advanced-golemancy",4},
	require = spells_req_high4,
	mode = "passive",
	points = 5,
	no_npc_use = true,
	on_learn = function(self, t)
		self.alchemy_golem.life_regen = self.alchemy_golem.life_regen + 1
		self.alchemy_golem.mana_regen = self.alchemy_golem.mana_regen + 1
		self.alchemy_golem.stamina_regen = self.alchemy_golem.stamina_regen + 1
		local lev = self:getTalentLevelRaw(t)
		if lev == 1 or lev == 3 or lev == 5 then
			self.alchemy_golem.max_inscriptions = self.alchemy_golem.max_inscriptions + 1
			self.alchemy_golem.inscriptions_slots_added = self.alchemy_golem.inscriptions_slots_added + 1
		end
	end,
	on_unlearn = function(self, t)
		self.alchemy_golem.life_regen = self.alchemy_golem.life_regen - 1
		self.alchemy_golem.mana_regen = self.alchemy_golem.mana_regen - 1
		self.alchemy_golem.stamina_regen = self.alchemy_golem.stamina_regen - 1
		local lev = self:getTalentLevelRaw(t)
		if lev == 0 or lev == 2 or lev == 4 then
			self.alchemy_golem.max_inscriptions = self.alchemy_golem.max_inscriptions - 1
			self.alchemy_golem.inscriptions_slots_added = self.alchemy_golem.inscriptions_slots_added - 1
		end
	end,
	info = function(self, t)
		return ([[增加傀儡 %0.2f 生命、法力和耐力回复。
		在等级1、3、5时，傀儡会增加1个新的符文孔。
		即使没有此天赋，傀儡默认也有3个符文孔。]]):
		format(self:getTalentLevelRaw(t))
	end,
}
