name: Lunalight
card_text: Fusion Summon 1 "Lunalight" Fusion Monster from your Extra Deck, using monsters from your hand or field as material. If your opponent controls a monster that was Special Summoned from the Extra Deck, you can also use 1 "Lunalight" monster in your Deck or Extra Deck as material. You can only activate 1 "Lunalight Fusion" per turn.
external_ids: local SETCARD_ID_0 = 0xdf --Lunalight
  
lua: local SETCARD_ID_0 = 0xdf --Lunalight
  local s, id = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = FusionSpell.CreateSummonEffect(c, {
  		fusfilter = s.fusfilter,
  		pre_select_mat_location = s.pre_select_mat_location,
  		fusion_spell_matfilter = s.fusion_spell_matfilter,
  		additional_fcheck = s.fcheck,
  	})
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_FUSION_SUMMON + CATEGORY_DECKDES)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	c:RegisterEffect(e1)
  end
  
  function s.fusfilter(c)
  	return c:IsSetCard(SETCARD_ID_0)
  end
  
  function s.pre_select_mat_location(tc, tp)
  	local res = LOCATION_HAND | LOCATION_MZONE
  	if Duel.IsExistingMatchingCard(s.cfilter, tp, 0, LOCATION_MZONE, 1, nil) then
  		res = res | LOCATION_DECK | LOCATION_EXTRA
  	end
  	return res
  end
  
  function s.cfilter(c)
  	return c:IsSummonLocation(LOCATION_EXTRA)
  end
  
  function s.fcheck(tp, mg, fc, all_mg)
  	--- by fusion spell, the material from deck/extra can only be at most 1
  	if mg:FilterCount(function(c)
  		return c:IsLocation(LOCATION_DECK + LOCATION_EXTRA)
  	end, nil) > 1 then
  		return false
  	end
  	return true
  end
  
  function s.fusion_spell_matfilter(c)
  	--- by fusion spell, the material from deck/extra must be Lunalight monster
  	if c:IsLocation(LOCATION_DECK | LOCATION_EXTRA) and not c:IsFusionSetCard(SETCARD_ID_0) then
  		return false
  	end
  	return true
  end
  
  
source_text: Lunalight
  Fusion Summon 1 "Lunalight" Fusion Monster from your Extra Deck, using monsters from your hand or field as material. If your opponent controls a monster that was Special Summoned from the Extra Deck, you can also use 1 "Lunalight" monster in your Deck or Extra Deck as material. You can only activate 1 "Lunalight Fusion" per turn.
target_text: -- Lunalight
  local SETCARD_ID_0 = 0xdf --Lunalight
  local s, id = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = FusionSpell.CreateSummonEffect(c, {
  		fusfilter = s.fusfilter,
  		pre_select_mat_location = s.pre_select_mat_location,
  		fusion_spell_matfilter = s.fusion_spell_matfilter,
  		additional_fcheck = s.fcheck,
  	})
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_FUSION_SUMMON + CATEGORY_DECKDES)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	c:RegisterEffect(e1)
  end
  
  function s.fusfilter(c)
  	return c:IsSetCard(SETCARD_ID_0)
  end
  
  function s.pre_select_mat_location(tc, tp)
  	local res = LOCATION_HAND | LOCATION_MZONE
  	if Duel.IsExistingMatchingCard(s.cfilter, tp, 0, LOCATION_MZONE, 1, nil) then
  		res = res | LOCATION_DECK | LOCATION_EXTRA
  	end
  	return res
  end
  
  function s.cfilter(c)
  	return c:IsSummonLocation(LOCATION_EXTRA)
  end
  
  function s.fcheck(tp, mg, fc, all_mg)
  	--- by fusion spell, the material from deck/extra can only be at most 1
  	if mg:FilterCount(function(c)
  		return c:IsLocation(LOCATION_DECK + LOCATION_EXTRA)
  	end, nil) > 1 then
  		return false
  	end
  	return true
  end
  
  function s.fusion_spell_matfilter(c)
  	--- by fusion spell, the material from deck/extra must be Lunalight monster
  	if c:IsLocation(LOCATION_DECK | LOCATION_EXTRA) and not c:IsFusionSetCard(SETCARD_ID_0) then
  		return false
  	end
  	return true
  end
  
  