name: Ultimate
card_text: During the Main Phase: Fusion Summon 1 Fusion Monster from your Extra Deck that mentions "Blue-Eyes White Dragon" or "Blue-Eyes Ultimate Dragon" as material, by shuffling the materials mentioned on it from your hand, field, and/or GY into the Deck, then, you can destroy face-up cards your opponent controls, up to the number of "Blue-Eyes White Dragon" and "Blue-Eyes Ultimate Dragon" used from the field as material. You can only activate 1 "Ultimate Fusion" per turn.
external_ids: local CARD_ID_0 = 23995346 --Blue-Eyes Ultimate Dragon
  local CARD_ID_1 = 89631139 --Blue-Eyes White Dragon
  
lua: local CARD_ID_0 = 23995346 --Blue-Eyes Ultimate Dragon
  local CARD_ID_1 = 89631139 --Blue-Eyes White Dragon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_1, CARD_ID_0)
  	--Activate
  	local e1 = FusionSpell.CreateSummonEffect(c, {
  		fusfilter = s.fusfilter,
  		pre_select_mat_location = LOCATION_HAND | LOCATION_MZONE | LOCATION_GRAVE,
  		mat_operation_code_map = {
  			{ [LOCATION_DECK] = FusionSpell.FUSION_OPERATION_GRAVE },
  			{ [0xff] = FusionSpell.FUSION_OPERATION_SHUFFLE },
  		},
  		additional_fcheck = s.fcheck,
  		stage_x_operation = s.stage_x_operation,
  	})
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_FUSION_SUMMON + CATEGORY_GRAVE_ACTION)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_MAIN_END)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.condition)
  	c:RegisterEffect(e1)
  end
  
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local ph = Duel.GetCurrentPhase()
  	return ph == PHASE_MAIN1 or ph == PHASE_MAIN2
  end
  
  function s.fusfilter(c)
  	return aux.IsMaterialListCode(c, CARD_ID_1) == true or aux.IsMaterialListCode(c, CARD_ID_0) == true
  end
  
  function s.fcheck(tp, mg, fc, mg_all)
  	if fc.ultimate_fusion_check ~= nil then
  		if fc.ultimate_fusion_check(tp, mg_all, fc) == false then
  			return false
  		end
  	elseif
  		not (
  			mg_all:IsExists(function(c)
  				return c:IsFusionCode(CARD_ID_1)
  			end, 1, nil) and aux.IsMaterialListCode(fc, CARD_ID_1) == true
  			or mg_all:IsExists(function(c)
  				return c:IsFusionCode(CARD_ID_0)
  			end, 1, nil) and aux.IsMaterialListCode(fc, CARD_ID_0) == true
  		)
  	then
  		return false
  	end
  	return true
  end
  
  function s.desfilter(c)
  	return c:IsFusionCode(CARD_ID_1, 23995346) and c:IsOnField()
  end
  
  function s.stage_x_operation(e, tc, tp, stage, mg_fuison_spell, mg_all)
  	if stage == FusionSpell.STAGE_BEFORE_MOVE_MATERIAL then
  		--- calculate the count of 青眼の白龍 and 青眼の究極竜
  		local destory_count = mg_all:FilterCount(s.desfilter, nil)
  		if destory_count > 0 then
  			e:SetLabel(destory_count)
  		else
  			e:SetLabel(0)
  		end
  	elseif stage == FusionSpell.STAGE_AT_SUMMON_OPERATION_FINISH then
  		local destory_count = e:GetLabel()
  		if destory_count > 0 and Duel.IsExistingMatchingCard(function(c)
  			return c:IsFaceup()
  		end, tp, 0, LOCATION_ONFIELD, 1, nil) and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  			local dg = Duel.SelectMatchingCard(tp, Card.IsFaceup, tp, 0, LOCATION_ONFIELD, 1, destory_count, nil)
  			Duel.HintSelection(dg)
  			Duel.Destroy(dg, REASON_EFFECT)
  			e:SetLabel(0)
  		end
  	end
  end
  
  
source_text: Ultimate
  During the Main Phase: Fusion Summon 1 Fusion Monster from your Extra Deck that mentions "Blue-Eyes White Dragon" or "Blue-Eyes Ultimate Dragon" as material, by shuffling the materials mentioned on it from your hand, field, and/or GY into the Deck, then, you can destroy face-up cards your opponent controls, up to the number of "Blue-Eyes White Dragon" and "Blue-Eyes Ultimate Dragon" used from the field as material. You can only activate 1 "Ultimate Fusion" per turn.
target_text: -- Ultimate
  local CARD_ID_0 = 23995346 --Blue-Eyes Ultimate Dragon
  local CARD_ID_1 = 89631139 --Blue-Eyes White Dragon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_1, CARD_ID_0)
  	--Activate
  	local e1 = FusionSpell.CreateSummonEffect(c, {
  		fusfilter = s.fusfilter,
  		pre_select_mat_location = LOCATION_HAND | LOCATION_MZONE | LOCATION_GRAVE,
  		mat_operation_code_map = {
  			{ [LOCATION_DECK] = FusionSpell.FUSION_OPERATION_GRAVE },
  			{ [0xff] = FusionSpell.FUSION_OPERATION_SHUFFLE },
  		},
  		additional_fcheck = s.fcheck,
  		stage_x_operation = s.stage_x_operation,
  	})
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_FUSION_SUMMON + CATEGORY_GRAVE_ACTION)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_MAIN_END)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.condition)
  	c:RegisterEffect(e1)
  end
  
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local ph = Duel.GetCurrentPhase()
  	return ph == PHASE_MAIN1 or ph == PHASE_MAIN2
  end
  
  function s.fusfilter(c)
  	return aux.IsMaterialListCode(c, CARD_ID_1) == true or aux.IsMaterialListCode(c, CARD_ID_0) == true
  end
  
  function s.fcheck(tp, mg, fc, mg_all)
  	if fc.ultimate_fusion_check ~= nil then
  		if fc.ultimate_fusion_check(tp, mg_all, fc) == false then
  			return false
  		end
  	elseif
  		not (
  			mg_all:IsExists(function(c)
  				return c:IsFusionCode(CARD_ID_1)
  			end, 1, nil) and aux.IsMaterialListCode(fc, CARD_ID_1) == true
  			or mg_all:IsExists(function(c)
  				return c:IsFusionCode(CARD_ID_0)
  			end, 1, nil) and aux.IsMaterialListCode(fc, CARD_ID_0) == true
  		)
  	then
  		return false
  	end
  	return true
  end
  
  function s.desfilter(c)
  	return c:IsFusionCode(CARD_ID_1, 23995346) and c:IsOnField()
  end
  
  function s.stage_x_operation(e, tc, tp, stage, mg_fuison_spell, mg_all)
  	if stage == FusionSpell.STAGE_BEFORE_MOVE_MATERIAL then
  		--- calculate the count of 青眼の白龍 and 青眼の究極竜
  		local destory_count = mg_all:FilterCount(s.desfilter, nil)
  		if destory_count > 0 then
  			e:SetLabel(destory_count)
  		else
  			e:SetLabel(0)
  		end
  	elseif stage == FusionSpell.STAGE_AT_SUMMON_OPERATION_FINISH then
  		local destory_count = e:GetLabel()
  		if destory_count > 0 and Duel.IsExistingMatchingCard(function(c)
  			return c:IsFaceup()
  		end, tp, 0, LOCATION_ONFIELD, 1, nil) and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  			local dg = Duel.SelectMatchingCard(tp, Card.IsFaceup, tp, 0, LOCATION_ONFIELD, 1, destory_count, nil)
  			Duel.HintSelection(dg)
  			Duel.Destroy(dg, REASON_EFFECT)
  			e:SetLabel(0)
  		end
  	end
  end
  
  