name: Prank-Kids
card_text: During the Main Phase: You can activate this effect; immediately after this effect resolves, Link Summon 1 "Prank-Kids" Link Monster using "Prank-Kids" monsters you control as material. When an opponent's monster declares an attack: You can banish this card from your GY; shuffle any number of "Prank-Kids" cards from your GY into the Deck, and if you do, that attacking monster loses 100 ATK for each card shuffled, until the end of this turn. You can only use each effect of "Prank-Kids Plan" once per turn.
external_ids: local SETCARD_ID_0 = 0x120 --Prank-Kids
  
lua: local SETCARD_ID_0 = 0x120 --Prank-Kids
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--link
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_MAIN_END)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.lkcon)
  	e2:SetTarget(s.lktg)
  	e2:SetOperation(s.lkop)
  	c:RegisterEffect(e2)
  	--shuffle
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_TODECK + CATEGORY_ATKCHANGE)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.atkcon)
  	e3:SetCost(aux.bfgcost)
  	e3:SetTarget(s.atktg)
  	e3:SetOperation(s.atkop)
  	c:RegisterEffect(e3)
  end
  function s.lkcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2
  end
  function s.matfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.lkfilter(c, mg)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsLinkSummonable(mg)
  end
  function s.lktg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local mg = Duel.GetMatchingGroup(s.matfilter, tp, LOCATION_MZONE, 0, nil)
  		return Duel.IsExistingMatchingCard(s.lkfilter, tp, LOCATION_EXTRA, 0, 1, nil, mg)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.lkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local mg = Duel.GetMatchingGroup(s.matfilter, tp, LOCATION_MZONE, 0, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local tg = Duel.SelectMatchingCard(tp, s.lkfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, mg)
  	local tc = tg:GetFirst()
  	if tc then
  		Duel.LinkSummon(tp, tc, mg)
  	end
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetAttacker():IsControler(1 - tp)
  end
  function s.tdfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToDeck()
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.tdfilter, tp, LOCATION_GRAVE, 0, 1, e:GetHandler())
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetAttacker()
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectMatchingCard(tp, s.tdfilter, tp, LOCATION_GRAVE, 0, 1, 99, nil)
  	local ct = #g
  	if ct > 0 then
  		Duel.HintSelection(g)
  	end
  	if Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) == 0 then
  		return
  	end
  	if tc:IsFaceup() and tc:IsRelateToBattle() and ct > 0 then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetValue(ct * -100)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  
  
source_text: Prank-Kids
  During the Main Phase: You can activate this effect; immediately after this effect resolves, Link Summon 1 "Prank-Kids" Link Monster using "Prank-Kids" monsters you control as material. When an opponent's monster declares an attack: You can banish this card from your GY; shuffle any number of "Prank-Kids" cards from your GY into the Deck, and if you do, that attacking monster loses 100 ATK for each card shuffled, until the end of this turn. You can only use each effect of "Prank-Kids Plan" once per turn.
target_text: -- Prank-Kids
  local SETCARD_ID_0 = 0x120 --Prank-Kids
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--link
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_MAIN_END)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.lkcon)
  	e2:SetTarget(s.lktg)
  	e2:SetOperation(s.lkop)
  	c:RegisterEffect(e2)
  	--shuffle
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_TODECK + CATEGORY_ATKCHANGE)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.atkcon)
  	e3:SetCost(aux.bfgcost)
  	e3:SetTarget(s.atktg)
  	e3:SetOperation(s.atkop)
  	c:RegisterEffect(e3)
  end
  function s.lkcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2
  end
  function s.matfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.lkfilter(c, mg)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsLinkSummonable(mg)
  end
  function s.lktg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local mg = Duel.GetMatchingGroup(s.matfilter, tp, LOCATION_MZONE, 0, nil)
  		return Duel.IsExistingMatchingCard(s.lkfilter, tp, LOCATION_EXTRA, 0, 1, nil, mg)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.lkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local mg = Duel.GetMatchingGroup(s.matfilter, tp, LOCATION_MZONE, 0, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local tg = Duel.SelectMatchingCard(tp, s.lkfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, mg)
  	local tc = tg:GetFirst()
  	if tc then
  		Duel.LinkSummon(tp, tc, mg)
  	end
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetAttacker():IsControler(1 - tp)
  end
  function s.tdfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToDeck()
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.tdfilter, tp, LOCATION_GRAVE, 0, 1, e:GetHandler())
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetAttacker()
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectMatchingCard(tp, s.tdfilter, tp, LOCATION_GRAVE, 0, 1, 99, nil)
  	local ct = #g
  	if ct > 0 then
  		Duel.HintSelection(g)
  	end
  	if Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) == 0 then
  		return
  	end
  	if tc:IsFaceup() and tc:IsRelateToBattle() and ct > 0 then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetValue(ct * -100)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  
  