name: Daruma
card_text: (Quick Effect): You can detach 1 material from an Xyz Monster you control, then target 1 face-up monster your opponent controls; change its ATK to 0 until the end of this turn. If an Xyz Monster you control would activate an effect by detaching material(s), except the turn this card was sent to the GY, you can banish this card from your GY instead of 1 of those materials. You can only use each effect of "Daruma Dropper" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--atk 0
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetHintTiming(0, TIMING_ATTACK + TIMING_DAMAGE_STEP)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(aux.dscon)
  	e1:SetCost(s.atkcost)
  	e1:SetTarget(s.atktg)
  	e1:SetOperation(s.atkop)
  	c:RegisterEffect(e1)
  	--remove overlay replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_OVERLAY_REMOVE_REPLACE)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.rcon)
  	e2:SetOperation(s.rop)
  	c:RegisterEffect(e2)
  end
  function s.atkcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckRemoveOverlayCard(tp, 1, 0, 1, REASON_COST)
  	end
  	Duel.RemoveOverlayCard(tp, 1, 0, 1, 1, REASON_COST)
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and aux.nzatk(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(aux.nzatk, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, aux.nzatk, tp, 0, LOCATION_MZONE, 1, 1, nil)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() and tc:GetAttack() > 0 then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  		e1:SetValue(0)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.rcon(e, tp, eg, ep, ev, re, r, rp)
  	return aux.exccon(e)
  		and bit.band(r, REASON_COST) ~= 0
  		and re:IsActivated()
  		and re:IsActiveType(TYPE_XYZ)
  		and re:GetHandler():GetOverlayCount() >= ev - 1
  		and e:GetHandler():IsAbleToRemoveAsCost()
  		and ep == e:GetOwnerPlayer()
  end
  function s.rop(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.Remove(e:GetHandler(), POS_FACEUP, REASON_COST)
  end
  
  
source_text: Daruma
  (Quick Effect): You can detach 1 material from an Xyz Monster you control, then target 1 face-up monster your opponent controls; change its ATK to 0 until the end of this turn. If an Xyz Monster you control would activate an effect by detaching material(s), except the turn this card was sent to the GY, you can banish this card from your GY instead of 1 of those materials. You can only use each effect of "Daruma Dropper" once per turn.
target_text: -- Daruma
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--atk 0
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetHintTiming(0, TIMING_ATTACK + TIMING_DAMAGE_STEP)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(aux.dscon)
  	e1:SetCost(s.atkcost)
  	e1:SetTarget(s.atktg)
  	e1:SetOperation(s.atkop)
  	c:RegisterEffect(e1)
  	--remove overlay replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_OVERLAY_REMOVE_REPLACE)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.rcon)
  	e2:SetOperation(s.rop)
  	c:RegisterEffect(e2)
  end
  function s.atkcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckRemoveOverlayCard(tp, 1, 0, 1, REASON_COST)
  	end
  	Duel.RemoveOverlayCard(tp, 1, 0, 1, 1, REASON_COST)
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and aux.nzatk(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(aux.nzatk, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, aux.nzatk, tp, 0, LOCATION_MZONE, 1, 1, nil)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() and tc:GetAttack() > 0 then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  		e1:SetValue(0)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.rcon(e, tp, eg, ep, ev, re, r, rp)
  	return aux.exccon(e)
  		and bit.band(r, REASON_COST) ~= 0
  		and re:IsActivated()
  		and re:IsActiveType(TYPE_XYZ)
  		and re:GetHandler():GetOverlayCount() >= ev - 1
  		and e:GetHandler():IsAbleToRemoveAsCost()
  		and ep == e:GetOwnerPlayer()
  end
  function s.rop(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.Remove(e:GetHandler(), POS_FACEUP, REASON_COST)
  end
  
  