name: Branded
card_text: Fusion Summon 1 Fusion Monster from your Extra Deck, using monsters from your hand or field as material, including a Dragon monster. You can also banish monsters from your GY as material, if you use "Fallen of Albaz" as Fusion Material from your hand, field, or by banishing itself from your GY. During the End Phase, if this card is in the GY because it was sent there to activate the effect of "Fallen of Albaz" this turn: You can Set this card. You can only use each effect of "Branded in White" once per turn.
external_ids: local CARD_ID_0 = 68468459 --Fallen of Albaz
  
lua: local CARD_ID_0 = 68468459 --Fallen of Albaz
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--Activate
  	local e1 = FusionSpell.CreateSummonEffect(c, {
  		post_select_mat_location = LOCATION_GRAVE,
  		additional_fcheck = s.fcheck,
  		extra_target = s.extra_target,
  	})
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_FUSION_SUMMON + CATEGORY_REMOVE)
  	e1:SetCountLimit(1, id)
  	c:RegisterEffect(e1)
  	--to grave
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetCondition(s.regcon)
  	e2:SetOperation(s.regop)
  	c:RegisterEffect(e2)
  	--set
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_PHASE + PHASE_END)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id + o)
  	e3:SetCondition(s.setcon)
  	e3:SetTarget(s.settg)
  	e3:SetOperation(s.setop)
  	c:RegisterEffect(e3)
  end
  
  function s.fcheck(tp, mg, fc, mg_all)
  	--- Must include a Dragon monster
  	if not mg_all:IsExists(function(c)
  		return c:IsRace(RACE_DRAGON)
  	end, 1, nil) then
  		return false
  	end
  	--- if using Grave, must use own "Fallen of Albaz"
  	local has_grave = mg:IsExists(function(c)
  		return c:IsLocation(LOCATION_GRAVE)
  	end, 1, nil)
  	if has_grave == true then
  		if not mg_all:IsExists(function(c)
  			return c:IsControler(tp) and c:IsFusionCode(CARD_ID_0)
  		end, 1, nil) then
  			return false
  		end
  	end
  	return true
  end
  
  function s.extra_target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, nil, 0, tp, LOCATION_GRAVE)
  end
  
  function s.regcon(e, tp, eg, ep, ev, re, r, rp)
  	local code1, code2 = Duel.GetChainInfo(ev, CHAININFO_TRIGGERING_CODE, CHAININFO_TRIGGERING_CODE2)
  	return e:GetHandler():IsReason(REASON_COST) and re and re:IsActivated() and (code1 == CARD_ID_0 or code2 == CARD_ID_0)
  end
  
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  end
  
  function s.setcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) > 0
  end
  
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsSSetable()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, e:GetHandler(), 1, 0, 0)
  end
  
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SSet(tp, c)
  	end
  end
  
  
source_text: Branded
  Fusion Summon 1 Fusion Monster from your Extra Deck, using monsters from your hand or field as material, including a Dragon monster. You can also banish monsters from your GY as material, if you use "Fallen of Albaz" as Fusion Material from your hand, field, or by banishing itself from your GY. During the End Phase, if this card is in the GY because it was sent there to activate the effect of "Fallen of Albaz" this turn: You can Set this card. You can only use each effect of "Branded in White" once per turn.
target_text: -- Branded
  local CARD_ID_0 = 68468459 --Fallen of Albaz
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--Activate
  	local e1 = FusionSpell.CreateSummonEffect(c, {
  		post_select_mat_location = LOCATION_GRAVE,
  		additional_fcheck = s.fcheck,
  		extra_target = s.extra_target,
  	})
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_FUSION_SUMMON + CATEGORY_REMOVE)
  	e1:SetCountLimit(1, id)
  	c:RegisterEffect(e1)
  	--to grave
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetCondition(s.regcon)
  	e2:SetOperation(s.regop)
  	c:RegisterEffect(e2)
  	--set
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_PHASE + PHASE_END)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id + o)
  	e3:SetCondition(s.setcon)
  	e3:SetTarget(s.settg)
  	e3:SetOperation(s.setop)
  	c:RegisterEffect(e3)
  end
  
  function s.fcheck(tp, mg, fc, mg_all)
  	--- Must include a Dragon monster
  	if not mg_all:IsExists(function(c)
  		return c:IsRace(RACE_DRAGON)
  	end, 1, nil) then
  		return false
  	end
  	--- if using Grave, must use own "Fallen of Albaz"
  	local has_grave = mg:IsExists(function(c)
  		return c:IsLocation(LOCATION_GRAVE)
  	end, 1, nil)
  	if has_grave == true then
  		if not mg_all:IsExists(function(c)
  			return c:IsControler(tp) and c:IsFusionCode(CARD_ID_0)
  		end, 1, nil) then
  			return false
  		end
  	end
  	return true
  end
  
  function s.extra_target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, nil, 0, tp, LOCATION_GRAVE)
  end
  
  function s.regcon(e, tp, eg, ep, ev, re, r, rp)
  	local code1, code2 = Duel.GetChainInfo(ev, CHAININFO_TRIGGERING_CODE, CHAININFO_TRIGGERING_CODE2)
  	return e:GetHandler():IsReason(REASON_COST) and re and re:IsActivated() and (code1 == CARD_ID_0 or code2 == CARD_ID_0)
  end
  
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  end
  
  function s.setcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) > 0
  end
  
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsSSetable()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, e:GetHandler(), 1, 0, 0)
  end
  
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SSet(tp, c)
  	end
  end
  
  