name: Epurrely
card_text: 2 Level 2 monsters
  Once per turn: You can target up to 2 Spells/Traps in the GYs; attach them to this card as material. This is a Quick Effect if this card has "Purrely Delicious Memory" as material. Up to thrice per turn, when you activate a "Purrely" Quick-Play Spell Card (Quick Effect): You can attach that card on the field to this card as material, then you can banish 1 monster on the field until the End Phase.
external_ids: local CARD_ID_0 = 55584558 --Purrely Delicious Memory
  local SETCARD_ID_0 = 0x18c --Purrely
  
lua: local CARD_ID_0 = 55584558 --Purrely Delicious Memory
  local SETCARD_ID_0 = 0x18c --Purrely
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--xyz summon
  	aux.AddXyzProcedure(c, nil, 2, 2)
  	c:EnableReviveLimit()
  	--be material from grave
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetCountLimit(1, EFFECT_COUNT_CODE_SINGLE)
  	e1:SetCondition(s.gmatcon)
  	e1:SetTarget(s.gmattg)
  	e1:SetOperation(s.gmatop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetCondition(s.gmatcon2)
  	c:RegisterEffect(e2)
  	--be material from szone
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_REMOVE)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_CHAINING)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(3)
  	e3:SetCondition(s.matcon)
  	e3:SetTarget(s.mattg)
  	e3:SetOperation(s.matop)
  	c:RegisterEffect(e3)
  end
  function s.gmatcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetOverlayGroup():IsExists(Card.IsCode, 1, nil, CARD_ID_0)
  end
  function s.gmatcon2(e, tp, eg, ep, ev, re, r, rp)
  	return not e:GetHandler():GetOverlayGroup():IsExists(Card.IsCode, 1, nil, CARD_ID_0)
  end
  function s.gmattgfilter(c, sc)
  	return c:IsCanOverlay() and c:IsType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.gmattg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.gmattgfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, nil, c)
  	end
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_XMATERIAL)
  	local g = Duel.SelectTarget(tp, s.gmattgfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, 2, nil, c)
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, g, #g, 0, 0)
  end
  function s.gmafilter(c, e)
  	return not c:IsImmuneToEffect(e) and c:IsCanOverlay()
  end
  function s.gmatop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetTargetsRelateToChain():Filter(s.gmafilter, nil, e)
  	if c:IsRelateToChain() and #g > 0 then
  		Duel.Overlay(c, g)
  	end
  end
  function s.matcon(e, tp, eg, ep, ev, re, r, rp)
  	return re:IsHasType(EFFECT_TYPE_ACTIVATE) and rp == tp and re:IsActiveType(TYPE_QUICKPLAY) and re:GetHandler():IsSetCard(SETCARD_ID_0)
  end
  function s.mattg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return re:GetHandler():IsCanOverlay()
  	end
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  	re:GetHandler():CreateEffectRelation(e)
  end
  function s.matop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = re:GetHandler()
  	if c:IsRelateToChain() and tc:IsRelateToChain() and tc:IsCanOverlay() and not tc:IsImmuneToEffect(e) then
  		tc:CancelToGrave()
  		Duel.Overlay(c, tc)
  		if Duel.IsExistingMatchingCard(Card.IsAbleToRemove, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil, tp) and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  			local tg = Duel.SelectMatchingCard(tp, Card.IsAbleToRemove, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil, tp)
  			local rc = tg:GetFirst()
  			if Duel.Remove(rc, 0, REASON_EFFECT + REASON_TEMPORARY) ~= 0 then
  				rc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  				local e1 = Effect.CreateEffect(c)
  				e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  				e1:SetCode(EVENT_PHASE + PHASE_END)
  				e1:SetReset(RESET_PHASE + PHASE_END)
  				e1:SetLabelObject(rc)
  				e1:SetCountLimit(1)
  				e1:SetCondition(s.retcon)
  				e1:SetOperation(s.retop)
  				Duel.RegisterEffect(e1, tp)
  			end
  		end
  	end
  end
  function s.retcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetLabelObject():GetFlagEffect(id) ~= 0
  end
  function s.retop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.ReturnToField(e:GetLabelObject())
  end
  
  
source_text: Epurrely
  2 Level 2 monsters
  Once per turn: You can target up to 2 Spells/Traps in the GYs; attach them to this card as material. This is a Quick Effect if this card has "Purrely Delicious Memory" as material. Up to thrice per turn, when you activate a "Purrely" Quick-Play Spell Card (Quick Effect): You can attach that card on the field to this card as material, then you can banish 1 monster on the field until the End Phase.
target_text: -- Epurrely
  local CARD_ID_0 = 55584558 --Purrely Delicious Memory
  local SETCARD_ID_0 = 0x18c --Purrely
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--xyz summon
  	aux.AddXyzProcedure(c, nil, 2, 2)
  	c:EnableReviveLimit()
  	--be material from grave
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetCountLimit(1, EFFECT_COUNT_CODE_SINGLE)
  	e1:SetCondition(s.gmatcon)
  	e1:SetTarget(s.gmattg)
  	e1:SetOperation(s.gmatop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetCondition(s.gmatcon2)
  	c:RegisterEffect(e2)
  	--be material from szone
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_REMOVE)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_CHAINING)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(3)
  	e3:SetCondition(s.matcon)
  	e3:SetTarget(s.mattg)
  	e3:SetOperation(s.matop)
  	c:RegisterEffect(e3)
  end
  function s.gmatcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetOverlayGroup():IsExists(Card.IsCode, 1, nil, CARD_ID_0)
  end
  function s.gmatcon2(e, tp, eg, ep, ev, re, r, rp)
  	return not e:GetHandler():GetOverlayGroup():IsExists(Card.IsCode, 1, nil, CARD_ID_0)
  end
  function s.gmattgfilter(c, sc)
  	return c:IsCanOverlay() and c:IsType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.gmattg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.gmattgfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, nil, c)
  	end
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_XMATERIAL)
  	local g = Duel.SelectTarget(tp, s.gmattgfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, 2, nil, c)
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, g, #g, 0, 0)
  end
  function s.gmafilter(c, e)
  	return not c:IsImmuneToEffect(e) and c:IsCanOverlay()
  end
  function s.gmatop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetTargetsRelateToChain():Filter(s.gmafilter, nil, e)
  	if c:IsRelateToChain() and #g > 0 then
  		Duel.Overlay(c, g)
  	end
  end
  function s.matcon(e, tp, eg, ep, ev, re, r, rp)
  	return re:IsHasType(EFFECT_TYPE_ACTIVATE) and rp == tp and re:IsActiveType(TYPE_QUICKPLAY) and re:GetHandler():IsSetCard(SETCARD_ID_0)
  end
  function s.mattg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return re:GetHandler():IsCanOverlay()
  	end
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  	re:GetHandler():CreateEffectRelation(e)
  end
  function s.matop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = re:GetHandler()
  	if c:IsRelateToChain() and tc:IsRelateToChain() and tc:IsCanOverlay() and not tc:IsImmuneToEffect(e) then
  		tc:CancelToGrave()
  		Duel.Overlay(c, tc)
  		if Duel.IsExistingMatchingCard(Card.IsAbleToRemove, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil, tp) and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  			local tg = Duel.SelectMatchingCard(tp, Card.IsAbleToRemove, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil, tp)
  			local rc = tg:GetFirst()
  			if Duel.Remove(rc, 0, REASON_EFFECT + REASON_TEMPORARY) ~= 0 then
  				rc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  				local e1 = Effect.CreateEffect(c)
  				e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  				e1:SetCode(EVENT_PHASE + PHASE_END)
  				e1:SetReset(RESET_PHASE + PHASE_END)
  				e1:SetLabelObject(rc)
  				e1:SetCountLimit(1)
  				e1:SetCondition(s.retcon)
  				e1:SetOperation(s.retop)
  				Duel.RegisterEffect(e1, tp)
  			end
  		end
  	end
  end
  function s.retcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetLabelObject():GetFlagEffect(id) ~= 0
  end
  function s.retop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.ReturnToField(e:GetLabelObject())
  end
  
  