name: Ghostrick
card_text: 2 Level 4 monsters
  You can also Xyz Summon this card by using a "Ghostrick" Xyz Monster you control as material, except "Ghostrick Angel of Mischief". (Transfer its materials to this card.) When the number of materials on this card becomes 10, you win the Duel. Once per turn: You can detach 1 material from this card; add 1 "Ghostrick" Spell/Trap from your Deck to your hand. Once per turn: You can attach 1 "Ghostrick" card from your hand to this card as material.
external_ids: local SETCARD_ID_0 = 0x8d --Ghostrick
  
lua: local SETCARD_ID_0 = 0x8d --Ghostrick
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, nil, 4, 2, s.ovfilter, aux.Stringid(id, 0))
  	c:EnableReviveLimit()
  	--win
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EVENT_ADJUST)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetOperation(s.winop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	--search
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1)
  	e2:SetCost(s.thcost)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  	--material
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 2))
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetTarget(s.mttg)
  	e3:SetOperation(s.mtop)
  	c:RegisterEffect(e3)
  end
  function s.ovfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_XYZ) and not c:IsCode(id)
  end
  function s.winop(e, tp, eg, ep, ev, re, r, rp)
  	local WIN_REASON_GHOSTRICK_SPOILEDANGEL = 0x1b
  	if e:GetHandler():GetOverlayCount() == 10 then
  		Duel.Win(tp, WIN_REASON_GHOSTRICK_SPOILEDANGEL)
  	end
  end
  function s.thcost(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.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SPELL + TYPE_TRAP) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  function s.mtfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanOverlay()
  end
  function s.mttg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsType(TYPE_XYZ) and Duel.IsExistingMatchingCard(s.mtfilter, tp, LOCATION_HAND, 0, 1, nil)
  	end
  end
  function s.mtop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_XMATERIAL)
  	local g = Duel.SelectMatchingCard(tp, s.mtfilter, tp, LOCATION_HAND, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.Overlay(c, g)
  	end
  end
  
  
source_text: Ghostrick
  2 Level 4 monsters
  You can also Xyz Summon this card by using a "Ghostrick" Xyz Monster you control as material, except "Ghostrick Angel of Mischief". (Transfer its materials to this card.) When the number of materials on this card becomes 10, you win the Duel. Once per turn: You can detach 1 material from this card; add 1 "Ghostrick" Spell/Trap from your Deck to your hand. Once per turn: You can attach 1 "Ghostrick" card from your hand to this card as material.
target_text: -- Ghostrick
  local SETCARD_ID_0 = 0x8d --Ghostrick
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, nil, 4, 2, s.ovfilter, aux.Stringid(id, 0))
  	c:EnableReviveLimit()
  	--win
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EVENT_ADJUST)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetOperation(s.winop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	--search
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1)
  	e2:SetCost(s.thcost)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  	--material
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 2))
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetTarget(s.mttg)
  	e3:SetOperation(s.mtop)
  	c:RegisterEffect(e3)
  end
  function s.ovfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_XYZ) and not c:IsCode(id)
  end
  function s.winop(e, tp, eg, ep, ev, re, r, rp)
  	local WIN_REASON_GHOSTRICK_SPOILEDANGEL = 0x1b
  	if e:GetHandler():GetOverlayCount() == 10 then
  		Duel.Win(tp, WIN_REASON_GHOSTRICK_SPOILEDANGEL)
  	end
  end
  function s.thcost(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.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SPELL + TYPE_TRAP) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  function s.mtfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanOverlay()
  end
  function s.mttg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsType(TYPE_XYZ) and Duel.IsExistingMatchingCard(s.mtfilter, tp, LOCATION_HAND, 0, 1, nil)
  	end
  end
  function s.mtop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_XMATERIAL)
  	local g = Duel.SelectMatchingCard(tp, s.mtfilter, tp, LOCATION_HAND, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.Overlay(c, g)
  	end
  end
  
  