local s,id,o=GetID()
function s.initial_effect(c)
    aux.AddCodeList(c,33900648)
    local e1=Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetHintTiming(0,TIMINGS_CHECK_MONSTER)
	e1:SetCountLimit(1,id)
    e1:SetCondition(s.cond)
	e1:SetOperation(s.operation)
	c:RegisterEffect(e1)
	--disable
	local e2=Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_QUICK_O)
	e2:SetCategory(CATEGORY_DISABLE+CATEGORY_DESTROY)
	e2:SetCode(EVENT_CHAINING)
	e2:SetRange(LOCATION_GRAVE)
	e2:SetCountLimit(1,id+id)
	e2:SetCondition(s.discon)
	e2:SetCost(aux.bfgcost)
	e2:SetTarget(s.distg)
	e2:SetOperation(s.disop)
	c:RegisterEffect(e2)
end
function s.acfilter(c)
    return aux.IsCodeListed(c,33900648) and c:IsFaceup()
end
function s.ffilter(c)
    return c:IsCode(33900648) and c:IsFaceup()
end
function s.cond(e,tp,eg,ep,ev,re,r,rp)
    return Duel.IsExistingMatchingCard(s.acfilter,tp,LOCATION_MZONE,0,1,nil) and Duel.IsExistingMatchingCard(s.ffilter,tp,LOCATION_FZONE,0,1,nil)
end
function s.operation(e,tp,eg,ep,ev,re,r,rp)
	local c=e:GetHandler()
	local e1=Effect.CreateEffect(c)
    e1:SetType(EFFECT_TYPE_FIELD)
	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET+EFFECT_FLAG_CLIENT_HINT)
	e1:SetTargetRange(1,1)
    e1:SetCode(EFFECT_CANNOT_ACTIVATE)
    e1:SetValue(s.actlimit)
    e1:SetReset(1,RESET_PHASE+PHASE_END)
	Duel.RegisterEffect(e1,tp)
    local e2=e1:Clone()
    e2:SetCode(EFFECT_CANNOT_REMOVE)
    e2:SetTarget(s.rmlimit)
    Duel.RegisterEffect(e2,tp)
    local e3=e1:Clone()
    e3:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
    e3:SetTarget(s.splimit)
    Duel.RegisterEffect(e3,tp)
end
function s.actlimit(e,re,tp)
	return re:GetActivateLocation()==LOCATION_GRAVE
end
function s.rmlimit(e,c)
	return c:IsLocation(LOCATION_GRAVE)
end
function s.splimit(e,c)
	return c:IsLocation(LOCATION_GRAVE) and c:IsType(TYPE_MONSTER)
end
function s.tgfilter(c,tp)
	return (c:IsFaceup() and c:IsLocation(LOCATION_ONFIELD) and c:IsControler(tp) and aux.IsCodeListed(c,33900648)) or (c:IsFaceup() and c:IsLocation(LOCATION_FZONE) and c:IsCode(33900648))
end
function s.discon(e,tp,eg,ep,ev,re,r,rp)
	if not re:IsHasProperty(EFFECT_FLAG_CARD_TARGET) then return false end
	local tg=Duel.GetChainInfo(ev,CHAININFO_TARGET_CARDS)
	return tg and tg:IsExists(s.tgfilter,1,nil,tp) and Duel.IsChainDisablable(ev)
end
function s.distg(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return true end
	Duel.SetOperationInfo(0,CATEGORY_DISABLE,eg,1,0,0)
	if re:GetHandler():IsDestructable() and re:GetHandler():IsRelateToEffect(re) then
		Duel.SetOperationInfo(0,CATEGORY_DESTROY,eg,1,0,0)
	end
end
function s.disop(e,tp,eg,ep,ev,re,r,rp)
	if Duel.NegateEffect(ev) and re:GetHandler():IsRelateToEffect(re) then
		Duel.Destroy(eg,REASON_EFFECT)
	end
end
