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

-- Physical combat
newTalentType{ allow_random=true, type="technique/2hweapon-offense", name = "双手武器系", description = "双手武器专攻。" }
newTalentType{ allow_random=true, type="technique/2hweapon-cripple", name = "双手战技系", description = "双手武器专攻。" }
newTalentType{ allow_random=true, type="technique/shield-offense", name = "盾战术系", description = "盾系专攻。" }
newTalentType{ allow_random=true, type="technique/shield-defense", name = "盾牌防御系", description = "盾系专攻。" }
newTalentType{ allow_random=true, type="technique/dualweapon-training", name = "双持武器系", description = "双持专攻。" }
newTalentType{ allow_random=true, type="technique/dualweapon-attack", name = "双持战技系", description = "双持专攻。" }
newTalentType{ allow_random=true, type="technique/archery-base", name = "基本弓箭手技能", description = "基础射击能力。" }
newTalentType{ allow_random=true, type="technique/archery-bow", name = "弓系", description = "弓系专攻。" }
newTalentType{ allow_random=true, type="technique/archery-sling", name = "投石索系", description = "投石索专攻。" }
newTalentType{ allow_random=true, type="technique/archery-training", name = "箭术训练系", description = "通用射击专攻。" }
newTalentType{ allow_random=true, type="technique/archery-utility", name = "强化箭系", description = "通用射击专攻。" }
newTalentType{ allow_random=true, type="technique/superiority", name = "战术优化系", min_lev = 10, description = "高级战斗技巧。Advanced combat techniques." }
newTalentType{ allow_random=true, type="technique/battle-tactics", name = "战术策略系", min_lev = 10, description = "高级战斗技巧。Advanced combat tactics." }
newTalentType{ allow_random=true, type="technique/warcries", name = "战吼系", no_silence = true, min_lev = 10, description = "战吼掌握，强化自身弱化敌人。Master the warcries to improve yourself and weaken others." }
newTalentType{ allow_random=true, type="technique/bloodthirst", name = "嗜血系", min_lev = 10, description = "嗜血专攻。" }
newTalentType{ allow_random=true, type="technique/field-control", name = "阵地控制系", generic = true, description = "战斗控制专攻。" }
newTalentType{ allow_random=true, type="technique/combat-techniques-active", name = "战斗技巧系", description = "通用战斗技巧。" }
newTalentType{ allow_random=true, type="technique/combat-techniques-passive", name = "战斗经验系", description = "通用战斗技巧。" }
newTalentType{ allow_random=true, type="technique/combat-training", name = "战斗训练系", generic = true, description = "战斗训练专攻。" }
newTalentType{ allow_random=true, type="technique/magical-combat", name = "魔法战斗系", description = "近身魔法格斗技术。" }
newTalentType{ allow_random=true, type="technique/mobility", name = "移动系", generic = true, description = "提高你的战斗机动性。" }
newTalentType{ allow_random=true, type="technique/thuggery", name = "暗杀系", description = "暗杀专攻。" }

-- Unarmed Combat
newTalentType{ is_unarmed=true, allow_random=true, type="technique/pugilism", name = "拳术系", description = "徒手拳击格斗技术，你不能装备板甲、武器和盾牌" }
newTalentType{ is_unarmed=true, allow_random=true, type="technique/finishing-moves", name = "终结追击系", description = "终结技能专攻。" }
newTalentType{ is_unarmed=true, allow_random=true, type="technique/grappling", name = "关节技系", description = "徒手搏斗技术，你不能装备板甲、武器和盾牌。" }
newTalentType{ is_unarmed=true, allow_random=true, type="technique/unarmed-discipline", name = "徒手格斗系", description = "高级徒手战斗技巧，可以学习脚踢、投技，不能装备板甲、武器和盾牌。" }
newTalentType{ is_unarmed=true, allow_random=true, type="technique/unarmed-training", name = "徒手训练系", description = "高级武术技能，不能装备板甲、武器和盾牌。" }
newTalentType{ allow_random=true, type="technique/conditioning", name = "体质强化系", generic = true, description = "体质强化。" }

newTalentType{ is_unarmed=true, type="technique/unarmed-other", name = "其他徒手格斗技能", generic = true, description = "基本武术战斗技巧。" }



-- Generic requires for techs based on talent level
-- Uses STR
techs_req1 = function(self, t) local stat = "str"; return {
	stat = { [stat]=function(level) return 12 + (level-1) * 2 end },
	level = function(level) return 0 + (level-1)  end,
} end
techs_req2 = function(self, t) local stat = "str"; return {
	stat = { [stat]=function(level) return 20 + (level-1) * 2 end },
	level = function(level) return 4 + (level-1)  end,
} end
techs_req3 = function(self, t) local stat = "str"; return {
	stat = { [stat]=function(level) return 28 + (level-1) * 2 end },
	level = function(level) return 8 + (level-1)  end,
} end
techs_req4 = function(self, t) local stat = "str"; return {
	stat = { [stat]=function(level) return 36 + (level-1) * 2 end },
	level = function(level) return 12 + (level-1)  end,
} end
techs_req5 = function(self, t) local stat = "str"; return {
	stat = { [stat]=function(level) return 44 + (level-1) * 2 end },
	level = function(level) return 16 + (level-1)  end,
} end
techs_req_high1 = function(self, t) local stat = "str"; return {
	stat = { [stat]=function(level) return 22 + (level-1) * 2 end },
	level = function(level) return 10 + (level-1)  end,
} end
techs_req_high2 = function(self, t) local stat = "str"; return {
	stat = { [stat]=function(level) return 30 + (level-1) * 2 end },
	level = function(level) return 14 + (level-1)  end,
} end
techs_req_high3 = function(self, t) local stat = "str"; return {
	stat = { [stat]=function(level) return 38 + (level-1) * 2 end },
	level = function(level) return 18 + (level-1)  end,
} end
techs_req_high4 = function(self, t) local stat = "str"; return {
	stat = { [stat]=function(level) return 46 + (level-1) * 2 end },
	level = function(level) return 22 + (level-1)  end,
} end
techs_req_high5 = function(self, t) local stat = "str"; return {
	stat = { [stat]=function(level) return 54 + (level-1) * 2 end },
	level = function(level) return 26 + (level-1)  end,
} end

-- Generic requires for techs_dex based on talent level
techs_dex_req1 = {
	stat = { dex=function(level) return 12 + (level-1) * 2 end },
	level = function(level) return 0 + (level-1)  end,
}
techs_dex_req2 = {
	stat = { dex=function(level) return 20 + (level-1) * 2 end },
	level = function(level) return 4 + (level-1)  end,
}
techs_dex_req3 = {
	stat = { dex=function(level) return 28 + (level-1) * 2 end },
	level = function(level) return 8 + (level-1)  end,
}
techs_dex_req4 = {
	stat = { dex=function(level) return 36 + (level-1) * 2 end },
	level = function(level) return 12 + (level-1)  end,
}
techs_dex_req5 = {
	stat = { dex=function(level) return 44 + (level-1) * 2 end },
	level = function(level) return 16 + (level-1)  end,
}

-- Generic rquires based either on str or dex
techs_strdex_req1 = function(self, t) local stat = self:getStr() >= self:getDex() and "str" or "dex"; return {
	stat = { [stat]=function(level) return 12 + (level-1) * 2 end },
	level = function(level) return 0 + (level-1)  end,
} end
techs_strdex_req2 = function(self, t) local stat = self:getStr() >= self:getDex() and "str" or "dex"; return {
	stat = { [stat]=function(level) return 20 + (level-1) * 2 end },
	level = function(level) return 4 + (level-1)  end,
} end
techs_strdex_req3 = function(self, t) local stat = self:getStr() >= self:getDex() and "str" or "dex"; return {
	stat = { [stat]=function(level) return 28 + (level-1) * 2 end },
	level = function(level) return 8 + (level-1)  end,
} end
techs_strdex_req4 = function(self, t) local stat = self:getStr() >= self:getDex() and "str" or "dex"; return {
	stat = { [stat]=function(level) return 36 + (level-1) * 2 end },
	level = function(level) return 12 + (level-1)  end,
} end
techs_strdex_req5 = function(self, t) local stat = self:getStr() >= self:getDex() and "str" or "dex"; return {
	stat = { [stat]=function(level) return 44 + (level-1) * 2 end },
	level = function(level) return 16 + (level-1)  end,
} end

-- Generic requires for techs_con based on talent level
techs_con_req1 = {
	stat = { con=function(level) return 12 + (level-1) * 2 end },
	level = function(level) return 0 + (level-1)  end,
}
techs_con_req2 = {
	stat = { con=function(level) return 20 + (level-1) * 2 end },
	level = function(level) return 4 + (level-1)  end,
}
techs_con_req3 = {
	stat = { con=function(level) return 28 + (level-1) * 2 end },
	level = function(level) return 8 + (level-1)  end,
}
techs_con_req4 = {
	stat = { con=function(level) return 36 + (level-1) * 2 end },
	level = function(level) return 12 + (level-1)  end,
}
techs_con_req5 = {
	stat = { con=function(level) return 44 + (level-1) * 2 end },
	level = function(level) return 16 + (level-1)  end,
}

-- Generic requires for techs_cun based on talent level
techs_cun_req1 = {
	stat = { cun=function(level) return 12 + (level-1) * 2 end },
	level = function(level) return 0 + (level-1)  end,
}
techs_cun_req2 = {
	stat = { cun=function(level) return 20 + (level-1) * 2 end },
	level = function(level) return 4 + (level-1)  end,
}
techs_cun_req3 = {
	stat = { cun=function(level) return 28 + (level-1) * 2 end },
	level = function(level) return 8 + (level-1)  end,
}
techs_cun_req4 = {
	stat = { cun=function(level) return 36 + (level-1) * 2 end },
	level = function(level) return 12 + (level-1)  end,
}
techs_cun_req5 = {
	stat = { cun=function(level) return 44 + (level-1) * 2 end },
	level = function(level) return 16 + (level-1)  end,
}

-- Archery range talents
archery_range = function(self, t)
	local weapon = self:hasArcheryWeapon()
	if not weapon or not weapon.combat then return 1 end
	return weapon.combat.range or 6
end

-- Unarmed stance changes and stance damage bonuses
getStrikingStyle = function(self, dam)
	local dam = 0
	if self:isTalentActive(self.T_STRIKING_STANCE) then
		local t = self:getTalentFromId(self.T_STRIKING_STANCE)
		dam = t.getDamage(self, t)
	end
	return dam / 100
end

-- Used for grapples and other unarmed attacks that don't rely on glove or gauntlet damage
getUnarmedTrainingBonus = function(self)
	local t = self:getTalentFromId(self.T_UNARMED_MASTERY)
	local damage = t.getPercentInc(self, t) or 0
	return damage + 1
end
	
cancelStances = function(self)
	if self.cancelling_stances then return end
	local stances = {self.T_STRIKING_STANCE, self.T_GRAPPLING_STANCE}
	self.cancelling_stances = true
	for i, t in ipairs(stances) do
		if self:isTalentActive(t) then
			self:forceUseTalent(t, {ignore_energy=true, ignore_cd=true})
		end
	end
	self.cancelling_stances = nil
end

load("/data/talents/techniques/2hweapon.lua")
load("/data/talents/techniques/dualweapon.lua")
load("/data/talents/techniques/weaponshield.lua")
load("/data/talents/techniques/superiority.lua")
load("/data/talents/techniques/warcries.lua")
load("/data/talents/techniques/bloodthirst.lua")
load("/data/talents/techniques/battle-tactics.lua")
load("/data/talents/techniques/field-control.lua")
load("/data/talents/techniques/combat-techniques.lua")
load("/data/talents/techniques/combat-training.lua")
load("/data/talents/techniques/bow.lua")
load("/data/talents/techniques/sling.lua")
load("/data/talents/techniques/archery.lua")
load("/data/talents/techniques/magical-combat.lua")
load("/data/talents/techniques/mobility.lua")
load("/data/talents/techniques/thuggery.lua")

load("/data/talents/techniques/pugilism.lua")
load("/data/talents/techniques/unarmed-discipline.lua")
load("/data/talents/techniques/finishing-moves.lua")
load("/data/talents/techniques/grappling.lua")
load("/data/talents/techniques/unarmed-training.lua")
load("/data/talents/techniques/conditioning.lua")
