require("ai.JINB.JINB")
--
function c87592201.initial_effect(c)
	--Activate
	local e1=Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	c:RegisterEffect(e1)

	local e2=Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(87592201,0))
	e2:SetType(EFFECT_TYPE_QUICK_F)
	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP+EFFECT_FLAG_DAMAGE_CAL)
	e2:SetCode(EVENT_CHAINING)
	e2:SetRange(LOCATION_FZONE)
	e2:SetCountLimit(1)
	e2:SetCondition(c87592201.con)
	e2:SetOperation(c87592201.op)
	c:RegisterEffect(e2)

end

function c87592201.con(e,tp,eg,ep,ev,re,r,rp)
	if not re:IsHasProperty(EFFECT_FLAG_CARD_TARGET) then return false end
	local g=Duel.GetChainInfo(ev,CHAININFO_TARGET_CARDS):Filter(c87592201.filter,nil)
	return g:GetCount()==1
	and not Duel.IsExistingMatchingCard(Card.IsSetCard,g:GetFirst():GetControler(),LOCATION_HAND,0,1,nil,0x871)
end
function c87592201.filter(c)
	return c:IsType(TYPE_FUSION) and c:IsFaceup() and c:IsLocation(LOCATION_MZONE)
end
function c87592201.op(e,tp,eg,ep,ev,re,r,rp)
	local p=Duel.GetChainInfo(ev,CHAININFO_TARGET_CARDS):Filter(c87592201.filter,nil):GetFirst():GetControler()
	c=Duel.CreateToken(p,ac1[math.random(#ac1)])
	Duel.SendtoHand(c,p,REASON_RULE)
	--action
	local e1=Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_SINGLE)
	e1:SetCode(EFFECT_CANNOT_SSET)
	c:RegisterEffect(e1)
	local e2=Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_SINGLE)
	e2:SetCode(EFFECT_QP_ACT_IN_NTPHAND)
	c:RegisterEffect(e2)
end
