name: Madolche
card_text: 2 Level 4 "Madolche" monsters
  Once per turn: You can detach 1 material from this card, then target up to 2 "Madolche" card(s) in your GY; shuffle those cards into the Deck, also, after that, shuffle cards your opponent controls into the Deck, up to the number of "Madolche" cards returned.
external_ids: local SETCARD_ID_0 = 0x71 --Madolche
  
lua: local SETCARD_ID_0 = 0x71 --Madolche
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, aux.FilterBoolFunction(Card.IsSetCard, SETCARD_ID_0), 4, 2)
  	c:EnableReviveLimit()
  	--todeck
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TODECK)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetCountLimit(1)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToDeck()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil) and Duel.IsExistingMatchingCard(Card.IsAbleToDeck, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 2, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, g:GetCount(), 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	local ct = g:FilterCount(Card.IsLocation, nil, LOCATION_DECK + LOCATION_HAND + LOCATION_EXTRA)
  	local dg = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, 0, LOCATION_ONFIELD, nil)
  	if ct > 0 and dg:GetCount() > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  		local rg = dg:Select(tp, 1, ct, nil)
  		Duel.HintSelection(rg)
  		Duel.SendtoDeck(rg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  end
  
  
source_text: Madolche
  2 Level 4 "Madolche" monsters
  Once per turn: You can detach 1 material from this card, then target up to 2 "Madolche" card(s) in your GY; shuffle those cards into the Deck, also, after that, shuffle cards your opponent controls into the Deck, up to the number of "Madolche" cards returned.
target_text: -- Madolche
  local SETCARD_ID_0 = 0x71 --Madolche
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, aux.FilterBoolFunction(Card.IsSetCard, SETCARD_ID_0), 4, 2)
  	c:EnableReviveLimit()
  	--todeck
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TODECK)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetCountLimit(1)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToDeck()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil) and Duel.IsExistingMatchingCard(Card.IsAbleToDeck, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 2, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, g:GetCount(), 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	local ct = g:FilterCount(Card.IsLocation, nil, LOCATION_DECK + LOCATION_HAND + LOCATION_EXTRA)
  	local dg = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, 0, LOCATION_ONFIELD, nil)
  	if ct > 0 and dg:GetCount() > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  		local rg = dg:Select(tp, 1, ct, nil)
  		Duel.HintSelection(rg)
  		Duel.SendtoDeck(rg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  end
  
  