name: Prologue
card_text: Send 1 "Destruction Sword" card and 1 "Buster Blader" monster from your Deck to the Graveyard, except "Prologue of the Destruction Swordsman"; Special Summon 1 "Buster Dragon" from your Extra Deck or Graveyard, but destroy it during the End Phase of the next turn. You can banish this card from your Graveyard; this turn, "Destruction Sword" cards you control cannot be destroyed by battle or card effects. You can only activate 1 "Prologue of the Destruction Swordsman" per turn.
external_ids: local CARD_ID_0 = 11790356 --Buster Dragon
  local SETCARD_ID_0 = 0xd6 --Destruction
  local SETCARD_ID_1 = 0xd7 --Buster
  
lua: local CARD_ID_0 = 11790356 --Buster Dragon
  local SETCARD_ID_0 = 0xd6 --Destruction
  local SETCARD_ID_1 = 0xd7 --Buster
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--Protect
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCost(aux.bfgcost)
  	e2:SetOperation(s.immop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter1(c, tp)
  	return c:IsSetCard(SETCARD_ID_1) and not c:IsCode(id) and c:IsAbleToGraveAsCost() and Duel.IsExistingMatchingCard(s.cfilter2, tp, LOCATION_DECK, 0, 1, c)
  end
  function s.cfilter2(c)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsType(TYPE_MONSTER) and c:IsAbleToGraveAsCost()
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter1, tp, LOCATION_DECK, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g1 = Duel.SelectMatchingCard(tp, s.cfilter1, tp, LOCATION_DECK, 0, 1, 1, nil, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g2 = Duel.SelectMatchingCard(tp, s.cfilter2, tp, LOCATION_DECK, 0, 1, 1, g1:GetFirst())
  	g1:Merge(g2)
  	Duel.SendtoGrave(g1, REASON_COST)
  end
  function s.filter(c, e, tp)
  	return c:IsCode(CARD_ID_0)
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  		and (c:IsLocation(LOCATION_GRAVE) and Duel.GetMZoneCount(tp) > 0 or c:IsLocation(LOCATION_EXTRA) and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_GRAVE + LOCATION_EXTRA, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE + LOCATION_EXTRA)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.filter), tp, LOCATION_GRAVE + LOCATION_EXTRA, 0, 1, 1, nil, e, tp)
  	local tc = g:GetFirst()
  	if tc and Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP) then
  		tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 2)
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e1:SetCode(EVENT_PHASE + PHASE_END)
  		e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  		e1:SetCondition(s.descon)
  		e1:SetOperation(s.desop)
  		e1:SetReset(RESET_PHASE + PHASE_END, 2)
  		e1:SetCountLimit(1)
  		e1:SetLabel(Duel.GetTurnCount())
  		e1:SetLabelObject(tc)
  		Duel.RegisterEffect(e1, tp)
  	end
  	Duel.SpecialSummonComplete()
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	return Duel.GetTurnCount() ~= e:GetLabel() and tc:GetFlagEffect(id) ~= 0
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	Duel.Destroy(tc, REASON_EFFECT)
  end
  function s.immop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e1:SetValue(1)
  	e1:SetTargetRange(LOCATION_ONFIELD, 0)
  	e1:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_1))
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	Duel.RegisterEffect(e2, tp)
  end
  
  
source_text: Prologue
  Send 1 "Destruction Sword" card and 1 "Buster Blader" monster from your Deck to the Graveyard, except "Prologue of the Destruction Swordsman"; Special Summon 1 "Buster Dragon" from your Extra Deck or Graveyard, but destroy it during the End Phase of the next turn. You can banish this card from your Graveyard; this turn, "Destruction Sword" cards you control cannot be destroyed by battle or card effects. You can only activate 1 "Prologue of the Destruction Swordsman" per turn.
target_text: -- Prologue
  local CARD_ID_0 = 11790356 --Buster Dragon
  local SETCARD_ID_0 = 0xd6 --Destruction
  local SETCARD_ID_1 = 0xd7 --Buster
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--Protect
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCost(aux.bfgcost)
  	e2:SetOperation(s.immop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter1(c, tp)
  	return c:IsSetCard(SETCARD_ID_1) and not c:IsCode(id) and c:IsAbleToGraveAsCost() and Duel.IsExistingMatchingCard(s.cfilter2, tp, LOCATION_DECK, 0, 1, c)
  end
  function s.cfilter2(c)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsType(TYPE_MONSTER) and c:IsAbleToGraveAsCost()
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter1, tp, LOCATION_DECK, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g1 = Duel.SelectMatchingCard(tp, s.cfilter1, tp, LOCATION_DECK, 0, 1, 1, nil, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g2 = Duel.SelectMatchingCard(tp, s.cfilter2, tp, LOCATION_DECK, 0, 1, 1, g1:GetFirst())
  	g1:Merge(g2)
  	Duel.SendtoGrave(g1, REASON_COST)
  end
  function s.filter(c, e, tp)
  	return c:IsCode(CARD_ID_0)
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  		and (c:IsLocation(LOCATION_GRAVE) and Duel.GetMZoneCount(tp) > 0 or c:IsLocation(LOCATION_EXTRA) and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_GRAVE + LOCATION_EXTRA, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE + LOCATION_EXTRA)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.filter), tp, LOCATION_GRAVE + LOCATION_EXTRA, 0, 1, 1, nil, e, tp)
  	local tc = g:GetFirst()
  	if tc and Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP) then
  		tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 2)
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e1:SetCode(EVENT_PHASE + PHASE_END)
  		e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  		e1:SetCondition(s.descon)
  		e1:SetOperation(s.desop)
  		e1:SetReset(RESET_PHASE + PHASE_END, 2)
  		e1:SetCountLimit(1)
  		e1:SetLabel(Duel.GetTurnCount())
  		e1:SetLabelObject(tc)
  		Duel.RegisterEffect(e1, tp)
  	end
  	Duel.SpecialSummonComplete()
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	return Duel.GetTurnCount() ~= e:GetLabel() and tc:GetFlagEffect(id) ~= 0
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	Duel.Destroy(tc, REASON_EFFECT)
  end
  function s.immop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e1:SetValue(1)
  	e1:SetTargetRange(LOCATION_ONFIELD, 0)
  	e1:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_1))
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	Duel.RegisterEffect(e2, tp)
  end
  
  