--妖刀·星切
function c66914011.initial_effect(c)
	c:EnableCounterPermit(0x1371)
	c:EnableCounterPermit(0x1372)
	c:EnableCounterPermit(0x1373)
	c:SetUniqueOnField(1,0,66914011)
	--Activate
	local e1=Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_EQUIP)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetProperty(EFFECT_FLAG_CARD_TARGET+EFFECT_FLAG_CONTINUOUS_TARGET)
	e1:SetTarget(c66914011.target)
	e1:SetOperation(c66914011.operation)
	c:RegisterEffect(e1)   
	--Equip limit
	local e2=Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_SINGLE)
	e2:SetCode(EFFECT_EQUIP_LIMIT)
	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
	e2:SetValue(c66914011.eqlimit)
	c:RegisterEffect(e2) 
	--special summon
	local e21=Effect.CreateEffect(c)
	e21:SetDescription(aux.Stringid(66914011,1))
	e21:SetCategory(CATEGORY_DESTROY+CATEGORY_COUNTER)
	e21:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_O)
	e21:SetRange(LOCATION_SZONE)
	e21:SetCode(EVENT_CHAINING)
	e21:SetCountLimit(1)
	e21:SetProperty(EFFECT_FLAG_DELAY)
	e21:SetCondition(c66914011.spcon1)
	e21:SetTarget(c66914011.destg)
	e21:SetOperation(c66914011.desop)
	c:RegisterEffect(e21)
	--atk/def
	local e24=Effect.CreateEffect(c)
	e24:SetType(EFFECT_TYPE_EQUIP)
	e24:SetCode(EFFECT_UPDATE_ATTACK)
	e24:SetCondition(c66914011.indcon)
	e24:SetValue(c66914011.atkval)
	c:RegisterEffect(e24)
	--redirect
	local e23=Effect.CreateEffect(c)
	e23:SetType(EFFECT_TYPE_EQUIP)
	e23:SetCode(EFFECT_BATTLE_DESTROY_REDIRECT)
	e23:SetValue(LOCATION_REMOVED)
	e23:SetCondition(c66914011.indcon2)
	c:RegisterEffect(e23)
	--immune
	local e5=Effect.CreateEffect(c)
	e5:SetType(EFFECT_TYPE_EQUIP)
	e5:SetCode(EFFECT_IMMUNE_EFFECT)
	e5:SetCondition(c66914011.indcon)
	e5:SetValue(c66914011.efilter)
	c:RegisterEffect(e5)
	local e13=Effect.CreateEffect(c)
	e13:SetType(EFFECT_TYPE_SINGLE)
	e13:SetCode(EFFECT_IMMUNE_EFFECT)
	e13:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
	e13:SetRange(LOCATION_SZONE)
	e13:SetCondition(c66914011.indcon)
	e13:SetValue(c66914011.efilter)
	c:RegisterEffect(e13)
	--to hand
	local e25=Effect.CreateEffect(c)
	e25:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
	e25:SetCode(EVENT_CHAIN_DISABLED)
	e25:SetRange(LOCATION_SZONE)
	e25:SetCondition(c66914011.thcon)
	e25:SetOperation(c66914011.thop)
	c:RegisterEffect(e25)
end
function c66914011.efilter(e,re)
	return e:GetHandlerPlayer()~=re:GetOwnerPlayer()
end
function c66914011.atkval(e,c)
	local count=0
	if e:GetHandler():GetCounter(0x1371)>0 then
		count=count+1
	end
	if e:GetHandler():GetCounter(0x1372)>0 then
		count=count+1
	end
	if e:GetHandler():GetCounter(0x1373)>0 then 
		count=count+1
	end  
	return count*500
end
function c66914011.indcon(e)
	local count=0
	if e:GetHandler():GetCounter(0x1371)>0 then
		count=count+1
	end
	if e:GetHandler():GetCounter(0x1372)>0 then
		count=count+1
	end
	if e:GetHandler():GetCounter(0x1373)>0 then 
		count=count+1
	end  
	return count>=2
end
function c66914011.indcon1(e)
	local count=0
	if e:GetHandler():GetCounter(0x1371)>0 then
		count=count+1
	end
	if e:GetHandler():GetCounter(0x1372)>0 then
		count=count+1
	end
	if e:GetHandler():GetCounter(0x1373)>0 then 
		count=count+1
	end  
	return count>=3 and e:GetHandler():GetEquipTarget()
end
function c66914011.indcon2(e)
	local count=0
	if e:GetHandler():GetCounter(0x1371)>0 then
		count=count+1
	end
	if e:GetHandler():GetCounter(0x1372)>0 then
		count=count+1
	end
	if e:GetHandler():GetCounter(0x1373)>0 then 
		count=count+1
	end  
	return count>=1 and e:GetHandler():GetEquipTarget()
end
function c66914011.eqlimit(e,c)
	return c:GetControler()==e:GetHandler():GetControler()
		and (c:IsCode(66914000) or c:IsCode(66914013))
end
function c66914011.filter(c,tp)
	return c:IsControler(tp) and c:IsFaceup()
		and (c:IsCode(66914000) or c:IsCode(66914013))
end
function c66914011.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc)
	if chkc then return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and c66914011.filter(chkc,tp) end
	if chk==0 then return Duel.IsExistingTarget(c66914011.filter,tp,LOCATION_MZONE,0,1,nil,tp) end
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_EQUIP)
	Duel.SelectTarget(tp,c66914011.filter,tp,LOCATION_MZONE,0,1,1,nil,tp)
	Duel.SetOperationInfo(0,CATEGORY_EQUIP,e:GetHandler(),1,0,0)
end
function c66914011.operation(e,tp,eg,ep,ev,re,r,rp)
	local c=e:GetHandler()
	local tc=Duel.GetFirstTarget()
	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) and tc:IsControler(tp) and tc:IsFaceup() then
		Duel.Equip(tp,c,tc)
	end
end
function c66914011.spcon1(e,tp,eg,ep,ev,re,r,rp)
	local count=0
	for i=1,ev do
		local te,tgp=Duel.GetChainInfo(i,CHAININFO_TRIGGERING_EFFECT,CHAININFO_TRIGGERING_PLAYER)
		if tgp==tp and te:GetHandler():IsSetCard(0x373)  then
			count=count+1
		end
	end
	return count>=2
end
function c66914011.destg(e,tp,eg,ep,ev,re,r,rp,chk)
	local g=Duel.GetMatchingGroup(aux.TRUE,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,nil)
	if chk==0 then return g:GetCount()>0 end
	Duel.SetOperationInfo(0,CATEGORY_DESTROY,g,1,0,0)
end
function c66914011.desop(e,tp,eg,ep,ev,re,r,rp)
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_DESTROY)
	local g=Duel.SelectMatchingCard(tp,aux.TRUE,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,1,1,nil)
	if g:GetCount()>0 then
		Duel.HintSelection(g)
		if Duel.Destroy(g,REASON_EFFECT)~=0 then
			Duel.BreakEffect()
			local tc=g:GetFirst()
			if tc:IsType(TYPE_MONSTER) then
				e:GetHandler():AddCounter(0x1371,1)
			elseif tc:IsType(TYPE_SPELL) then
				e:GetHandler():AddCounter(0x1372,1)
			else
				e:GetHandler():AddCounter(0x1373,1)
			end
		end
	end
end
function c66914011.thcon(e,tp,eg,ep,ev,re,r,rp)
	local de,dp=Duel.GetChainInfo(ev,CHAININFO_DISABLE_REASON,CHAININFO_DISABLE_PLAYER)
	return rp==tp and de and re:IsHasType(EFFECT_TYPE_ACTIVATE)
		and re:GetHandler():IsSetCard(0x373) and re:GetHandler():IsType(TYPE_QUICKPLAY+TYPE_SPELL)
end
function c66914011.thop(e,tp,eg,ep,ev,re,r,rp)
	local rc=re:GetHandler()
	if rc:IsCanTurnSet() and rc:IsRelateToEffect(re) and Duel.SelectYesNo(tp,aux.Stringid(66914011,0)) then
		rc:CancelToGrave()
		Duel.ChangePosition(rc,POS_FACEDOWN)
		Duel.RaiseEvent(rc,EVENT_SSET,e,REASON_EFFECT,tp,tp,0)
	end
end