modifier_ability_power_remilia = class({})

local public = modifier_ability_power_remilia

local m_modifier_funcs=
{
	MODIFIER_PROPERTY_OVERRIDE_ABILITY_SPECIAL,
	MODIFIER_PROPERTY_OVERRIDE_ABILITY_SPECIAL_VALUE,
	MODIFIER_PROPERTY_COOLDOWN_REDUCTION_CONSTANT,
}

local power_bonus = {
	["thtd_remilia_01"] = {  
		[1] = {
			["power_bonus"] = 1,
			["duration_time"] = 1,
		},
		[2] = {
			["power_bonus"] = 1,
			["duration_time"] = 1,
		},
		[3] = {
			["power_bonus"] = 1,
			["duration_time"] = 1,
		},	
		[4] = {
			["power_bonus"] = 6,
			["duration_time"] = 6,
		},		
		[5] = {
			["power_bonus"] = 6,
			["duration_time"] = 6,
		},		
	},
	["thtd_remilia_03"] = {  
		[1] = {
			["cd"] = 1,
		},
		[2] = {
			["cd"] = 3,
		},
		[3] = {
			["cd"] = 5,
		},	
		[4] = {
			["cd"] = 5,			
		},	
		[5] = {
			["cd"] = 5,			
		},		
	},
	["thtd_remilia_04"] = {  
		[1] = {
			["power_damage"] = 10,
		},
		[2] = {
			["power_damage"] = 20,
		},
		[3] = {
			["power_damage"] = 30,
		},	
	},	
}
local power999_bonus = 400

function public:IsHidden()
	return true
end

function public:IsPermanent()
	return true
end

function public:RemoveOnDeath()
	return false
end

function public:IsDebuff()
	return false
end

function public:IsPurgable()
	return false
end

function public:OnDestroy(kv)
	if not IsServer() then return end

	local caster = self:GetParent()
	caster:AddDamageOutgoingAll("thtd_remilia_power_999")	
end

function public:OnStackCountChanged( iStackCount )
	-- 双端触发，iStackCount为改变前的层数	
	if not IsServer() then return end

	local caster = self:GetParent()
	if self:GetStackCount() == 5 then 	
		caster:AddDamageOutgoingAll(power999_bonus, "thtd_remilia_power_999")		
	end
end

function public:DeclareFunctions()
	return m_modifier_funcs
end

function public:GetModifierOverrideAbilitySpecial( params )
	if self:GetParent() == nil or params.ability == nil then
		return 0
	end
		
	local abilityName = params.ability:GetAbilityName() 
	local level = self:GetStackCount()
	local valueName = params.ability_special_value
	
	if power_bonus[abilityName] == nil then
		return 0
	end

	if power_bonus[abilityName][level] == nil then
		level = 3
	end
	if power_bonus[abilityName][level] == nil then
		return 0
	end

	if power_bonus[abilityName][level][valueName] == nil then
		return 0
	end

	return 1
end

function public:GetModifierOverrideAbilitySpecialValue( params )
	local abilityName = params.ability:GetAbilityName() 
	local level = self:GetStackCount()
	local valueName = params.ability_special_value
	local specialLevel = params.ability_special_level

	if power_bonus[abilityName][level] == nil then
		level = 3
	end

	if abilityName == "thtd_remilia_01" then 
		return params.ability:GetLevelSpecialValueNoOverride(valueName, specialLevel) * power_bonus[abilityName][level][valueName]
	elseif abilityName == "thtd_remilia_04" then 
		return params.ability:GetLevelSpecialValueNoOverride(valueName, specialLevel) + power_bonus[abilityName][level][valueName]		
	end
end

function public:GetModifierCooldownReduction_Constant( params )
	if self:GetParent() == nil or params.ability == nil then
		return 0
	end

	if params.ability:GetAbilityName() == "thtd_remilia_03" then 		
		return power_bonus["thtd_remilia_03"][self:GetStackCount()]["cd"] or 0
	else
		return 0
	end
end