name: Farewelcome
card_text: When a monster declares an attack, while you control a Fiend monster: Target 1 card on the field; negate the attack, and if you do, destroy that targeted card, then, you can Set 1 non-"Labrynth" Normal Trap from your hand or Deck.
external_ids: local SETCARD_ID_0 = 0x17e --Labrynth
  
lua: local SETCARD_ID_0 = 0x17e --Labrynth
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c)
  	return c:IsRace(RACE_FIEND) and c:IsFaceup()
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and chkc ~= e:GetHandler()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(aux.TRUE, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, e:GetHandler())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, aux.TRUE, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, e:GetHandler())
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.stfilter(c)
  	return c:GetType() == TYPE_TRAP and not c:IsSetCard(SETCARD_ID_0) and c:IsSSetable()
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	local res = 0
  	if Duel.NegateAttack() and tc:IsRelateToEffect(e) then
  		res = Duel.Destroy(tc, REASON_EFFECT)
  		local g = Duel.GetMatchingGroup(s.stfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, nil)
  		if res > 0 and g:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  			local sg = g:Select(tp, 1, 1, nil)
  			Duel.SSet(tp, sg)
  		end
  	end
  	aux.LabrynthDestroyOp(e, tp, res)
  end
  
  
source_text: Farewelcome
  When a monster declares an attack, while you control a Fiend monster: Target 1 card on the field; negate the attack, and if you do, destroy that targeted card, then, you can Set 1 non-"Labrynth" Normal Trap from your hand or Deck.
target_text: -- Farewelcome
  local SETCARD_ID_0 = 0x17e --Labrynth
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c)
  	return c:IsRace(RACE_FIEND) and c:IsFaceup()
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and chkc ~= e:GetHandler()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(aux.TRUE, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, e:GetHandler())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, aux.TRUE, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, e:GetHandler())
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.stfilter(c)
  	return c:GetType() == TYPE_TRAP and not c:IsSetCard(SETCARD_ID_0) and c:IsSSetable()
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	local res = 0
  	if Duel.NegateAttack() and tc:IsRelateToEffect(e) then
  		res = Duel.Destroy(tc, REASON_EFFECT)
  		local g = Duel.GetMatchingGroup(s.stfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, nil)
  		if res > 0 and g:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  			local sg = g:Select(tp, 1, 1, nil)
  			Duel.SSet(tp, sg)
  		end
  	end
  	aux.LabrynthDestroyOp(e, tp, res)
  end
  
  