SkillHelperFunc = {}

--客戶端使用的各事件監聽列舉
local Base_PreConditionType={
	AfterUseSkill = 1,
	WearEquip = 2,
	HpLessThan = 3,
	MyselfState = 4,
	Partner = 5,
	Buff = 6,
	--檢測學習了某個技能，不需要註冊監聽事件
	LearnedSkill = 7,
	BeingState = 8,
	EquipTakeOff = 9,
	EquipBreak = 10,
}

--前置條件Protype列舉
local SKILL_ABACHECK = 1
local SKILL_ARCH = 2 
local SKILL_Lianhuan = 3
local SKILL_HUPAO = 4
local SKILL_Machine = 5
local SKILL_WOLF = 6
local SKILL_POISON = 7
local SKILL_SOLO = 8
local SKILL_ENSEMBLE = 9 

--前置條件Protype 所牽涉到的基礎事件列舉陣列
local Pro_PreCondtionType = {
	--Aba
	[SKILL_ABACHECK] = {baseTypes = {6}},
	[SKILL_ARCH] = {baseTypes = {6}},
	[SKILL_Lianhuan]= {baseTypes = {6}},
	[SKILL_HUPAO] = {baseTypes = {6}},
	[SKILL_Machine] = {baseTypes = {6}},
	[SKILL_WOLF] = {baseTypes = {5,6}},
	[SKILL_POISON] = {baseTypes = {6}},
	[SKILL_SOLO] = {baseTypes = {2,6}},
	[SKILL_ENSEMBLE] = {baseTypes = {2,6}},
}

--客戶端通過Protype獲取需要監聽的事件列舉
function SkillHelperFunc.GetProRelateCheckTypes(proType)
	local config = Pro_PreCondtionType[proType]
	if(config) then
		return config.baseTypes
	end
	return nil
end

--前後端通過protype和傳入srcuser，檢測是否滿足protype釋放條件
function SkillHelperFunc.CheckPrecondtionByProType(proType,srcuser,skillid)
	if(proType~=nil and srcuser~=nil) then
		local func = Pro_PreCondtionType[proType].Func
		if(func) then
			return func(srcuser,skillid)
		else
			error(string.format("我，申林，素質差，沒配%s這個型別的檢查函式",proType))
		end
	end
	return false
end

-- start 具體檢測前置條件的判斷函式體們
function SkillHelperFunc.AbaPreCheck(srcuser)
	--1.判斷 暴氣狀態
	if(not srcuser:HasBuffID(100510)) then
		return false
	end
	--2. 有沒有蓄氣
	local powerLayer = srcuser:GetBuffLayer(100500)
	if(powerLayer==0) then
		return false
	end

	--3 獲取蓄氣數量num

	--4.1 有沒有1個蓄氣
	if(powerLayer>=1) then
		--4.1.1 氣絕buff
		if(srcuser:HasBuffID(100700)) then
			return true
		end
	--4.2 有沒有3個蓄氣
		if(powerLayer>=3)then
		--4.2.1 伏虎buff
			if(srcuser:HasBuffID(100631)) then
				return true
			end
	--4.2 有沒有4個蓄氣
			if(powerLayer>=4)then
		--4.2.1 猛龍buff
		--4.2.2 真劍buff
				if(srcuser:HasBuffID(100620) or srcuser:HasBuffID(100685)) then
					return true
				end
	--4.3 有沒有5個蓄氣
				if(powerLayer>=5)then
					return true
				end
			end
		end
	end
	return false
end
--------------------------------------------------------------弓身彈影
function SkillHelperFunc.ARCH(srcuser)
	if srcuser:HasBuffID(100510) or srcuser:HasBuffID(100500) then   -------------爆氣狀態或有氣彈可施放
		return true
	end
	return false
end
--------------------------------------------------------------連環全身
function SkillHelperFunc.Lianhuan(srcuser)
	if srcuser:HasBuffID(100685) or srcuser:HasBuffID(100600) then   -------------真劍狀態或承接六合拳可施放
		return true
	end
	return false
end
---------------------------------------------------------------虎炮
function SkillHelperFunc.HUPAO(srcuser)
	local powerLayer = srcuser:GetBuffLayer(100500)
	if srcuser:HasBuffID(100510) and powerLayer>=2 then   -------------爆氣狀態或有氣彈可施放
		return true
	end
	return false
end
---------------------------------------------------------------操作魔導機械
function SkillHelperFunc.Machine(srcuser)

	if srcuser:HasBuffID(117850) or srcuser:HasBuffID(117855) then   -------------魔導機械
		return true
	end

	return false
end
---------------------------------------------------------------攜帶 狼
function SkillHelperFunc.WOLF(srcuser)

	if (srcuser:IsPartner(5049) or srcuser:IsPartner(5090) or srcuser:IsPartner(6657)) or srcuser:HasBuffID(117460) then   -------------攜帶 狼
		return true
	end

	return false
end
---------------------------------------------------------------劇毒武器狀態下
function SkillHelperFunc.POISON(srcuser)

	if srcuser:HasBuffID(116015) then   -------------劇毒武器狀態下
		return true
	end

	return false
end
---------------------------------------------------------------合奏Buff下無法使用獨奏
function SkillHelperFunc.SOLO(srcuser)

	if srcuser:HasBuffID(119301) or (srcuser:GetEquipedWeaponType()~=260 and srcuser:GetEquipedWeaponType()~=270) then   -------------合奏buff
		return false
	end

	return true
end
---------------------------------------------------------------合奏使用條件
function SkillHelperFunc.ENSEMBLE(srcuser,skillid)

	if (srcuser:GetEquipedWeaponType()~=260 and srcuser:GetEquipedWeaponType()~=270) then   -------------合奏buff
		return false
	end

	return true
end
-- end 具體檢測前置條件的判斷函式體們
-------------------------------------------------弓身彈影

--Protype 對應的檢測函式
Pro_PreCondtionType[SKILL_ABACHECK].Func = SkillHelperFunc.AbaPreCheck
Pro_PreCondtionType[SKILL_ARCH].Func = SkillHelperFunc.ARCH
Pro_PreCondtionType[SKILL_Lianhuan].Func = SkillHelperFunc.Lianhuan
Pro_PreCondtionType[SKILL_HUPAO].Func = SkillHelperFunc.HUPAO
Pro_PreCondtionType[SKILL_Machine].Func = SkillHelperFunc.Machine
Pro_PreCondtionType[SKILL_WOLF].Func = SkillHelperFunc.WOLF
Pro_PreCondtionType[SKILL_POISON].Func = SkillHelperFunc.POISON
Pro_PreCondtionType[SKILL_SOLO].Func = SkillHelperFunc.SOLO
Pro_PreCondtionType[SKILL_ENSEMBLE].Func = SkillHelperFunc.ENSEMBLE
-- *******************************************************************
-- *******************************************************************
-- *******************************************************************
-- 服務度使用, 技能動態消耗

function SkillHelperFunc.DoDynamicCost(costtype, srcUser, skillid)
  local func = SkillHelperFunc.DynamicCostFunc[costtype]
  if func == nil then
    return
  end

  func(srcUser)
end

function SkillHelperFunc.DoDynamicCost_Aba(srcUser, skillid)
		--1.判斷 暴氣狀態
	if(not srcUser:HasBuffID(100510)) then
		return false
	end
	--2. 有沒有蓄氣
	local powerLayer = srcUser:GetBuffLayer(100500)
	if(powerLayer==0) then
		return false
	end

	--3 獲取蓄氣數量num

	--4.1 有沒有1個蓄氣
	if(powerLayer>=1) then
		--4.1.1 氣絕buff
		if(srcUser:HasBuffID(100700)) then
			srcUser:DelSkillBuff(100500,1)
			return true
		end
	--4.2 有沒有3個蓄氣
		if(powerLayer>=3)then
		--4.2.1 伏虎buff
			if(srcUser:HasBuffID(100631)) then
				srcUser:DelSkillBuff(100500,3)
				return true
			end
	--4.2 有沒有4個蓄氣
			if(powerLayer>=4)then
		--4.2.1 猛龍buff
		--4.2.2 真劍buff
				if(srcUser:HasBuffID(100620) or srcUser:HasBuffID(100685)) then
					srcUser:DelSkillBuff(100500,4)
					return true
				end
	--4.3 有沒有5個蓄氣
				if(powerLayer>=5)then
				srcUser:DelSkillBuff(100500,5)
					return true
				end
			end
		end
	end
	return false
end

-- 弓身彈影 消耗
function SkillHelperFunc.DoDynamicCost_Arch(srcUser, skillid)
  if srcUser == nil then
    return
  end

  local inBomb = srcUser:HasBuffID(100510)
  if inBomb ==true then
    return
  end

  srcUser:DelSkillBuff(100500,1)
end

-- 連環全身掌 消耗
function SkillHelperFunc.DoDynamicCost_Lianhuan(srcUser, skillid)
  if srcUser == nil then
    return
  end
  if srcUser:HasBuffID(100685) then
  	return
  elseif srcUser:HasBuffID(100600) then
  	srcUser:DelSkillBuff(100600,1)
  	return
  end
end


-- NOTICE: 必須放在子函式實現後面!!!
SkillHelperFunc.DynamicCostFunc = {
  [1] = SkillHelperFunc.DoDynamicCost_Aba,
  [2] = SkillHelperFunc.DoDynamicCost_Arch, -- 弓身彈影
  [3] = SkillHelperFunc.DoDynamicCost_Lianhuan -- 連環全身掌
}

