name: Hazy
card_text: You can Normal Summon "Hazy Flame" monsters for 1 less Tribute. Once per turn: You can target 1 face-up Xyz Monster you control; attach 1 "Hazy Flame" monster from your hand or your side of the field to that Xyz Monster as an Xyz Material.
external_ids: local SETCARD_ID_0 = 0x107d --Hazy
  
lua: local SETCARD_ID_0 = 0x107d --Hazy
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--decrease tribute
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_DECREASE_TRIBUTE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(LOCATION_HAND, 0)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e2:SetValue(0x1)
  	c:RegisterEffect(e2)
  	--material
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetCountLimit(1)
  	e3:SetTarget(s.mattg)
  	e3:SetOperation(s.matop)
  	c:RegisterEffect(e3)
  end
  function s.xyzfilter(c, tp)
  	return c:IsFaceup() and c:IsType(TYPE_XYZ) and Duel.IsExistingMatchingCard(s.matfilter, tp, LOCATION_MZONE + LOCATION_HAND, 0, 1, c)
  end
  function s.matfilter(c, e)
  	return (c:IsLocation(LOCATION_HAND) or c:IsFaceup()) and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsCanOverlay() and not (e and c:IsImmuneToEffect(e))
  end
  function s.mattg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_MZONE) and s.xyzfilter(chkc, tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.xyzfilter, tp, LOCATION_MZONE, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.xyzfilter, tp, LOCATION_MZONE, 0, 1, 1, nil, tp)
  end
  function s.matop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsFaceup() and tc:IsRelateToEffect(e) and not tc:IsImmuneToEffect(e) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_XMATERIAL)
  		local g = Duel.SelectMatchingCard(tp, s.matfilter, tp, LOCATION_MZONE + LOCATION_HAND, 0, 1, 1, tc, e)
  		if g:GetCount() > 0 then
  			local mg = g:GetFirst():GetOverlayGroup()
  			if mg:GetCount() > 0 then
  				Duel.SendtoGrave(mg, REASON_RULE)
  			end
  			Duel.Overlay(tc, g)
  		end
  	end
  end
  
  
source_text: Hazy
  You can Normal Summon "Hazy Flame" monsters for 1 less Tribute. Once per turn: You can target 1 face-up Xyz Monster you control; attach 1 "Hazy Flame" monster from your hand or your side of the field to that Xyz Monster as an Xyz Material.
target_text: -- Hazy
  local SETCARD_ID_0 = 0x107d --Hazy
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--decrease tribute
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_DECREASE_TRIBUTE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(LOCATION_HAND, 0)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e2:SetValue(0x1)
  	c:RegisterEffect(e2)
  	--material
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetCountLimit(1)
  	e3:SetTarget(s.mattg)
  	e3:SetOperation(s.matop)
  	c:RegisterEffect(e3)
  end
  function s.xyzfilter(c, tp)
  	return c:IsFaceup() and c:IsType(TYPE_XYZ) and Duel.IsExistingMatchingCard(s.matfilter, tp, LOCATION_MZONE + LOCATION_HAND, 0, 1, c)
  end
  function s.matfilter(c, e)
  	return (c:IsLocation(LOCATION_HAND) or c:IsFaceup()) and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsCanOverlay() and not (e and c:IsImmuneToEffect(e))
  end
  function s.mattg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_MZONE) and s.xyzfilter(chkc, tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.xyzfilter, tp, LOCATION_MZONE, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.xyzfilter, tp, LOCATION_MZONE, 0, 1, 1, nil, tp)
  end
  function s.matop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsFaceup() and tc:IsRelateToEffect(e) and not tc:IsImmuneToEffect(e) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_XMATERIAL)
  		local g = Duel.SelectMatchingCard(tp, s.matfilter, tp, LOCATION_MZONE + LOCATION_HAND, 0, 1, 1, tc, e)
  		if g:GetCount() > 0 then
  			local mg = g:GetFirst():GetOverlayGroup()
  			if mg:GetCount() > 0 then
  				Duel.SendtoGrave(mg, REASON_RULE)
  			end
  			Duel.Overlay(tc, g)
  		end
  	end
  end
  
  