name: Evoltile
card_text: At the end of the Battle Phase, if this card destroyed an opponent's monster by battle: You can Tribute this card; Special Summon 2 Level 6 or lower FIRE Dinosaur-Type monsters with the same name from your Deck. Their effects are negated and they are banished during the End Phase.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e1:SetCode(EVENT_BATTLE_DESTROYING)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e1:SetOperation(s.regop)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_PHASE + PHASE_BATTLE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCondition(s.spcon)
  	e2:SetCost(s.spcost)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) ~= 0
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsReleasable()
  	end
  	Duel.Release(e:GetHandler(), REASON_COST)
  end
  function s.filter(c, e, tp)
  	return c:IsLevelBelow(6) and c:IsRace(RACE_DINOSAUR) and c:IsAttribute(ATTRIBUTE_FIRE) and c:IsCanBeSpecialSummoned(e, SUMMON_VALUE_EVOLTILE, tp, false, false)
  end
  function s.filter2(c, g)
  	return g:IsExists(Card.IsCode, 1, c, c:GetCode())
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_DECK, 0, nil, e, tp)
  		return not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and g:IsExists(s.filter2, 1, nil, g)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 2, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		return
  	end
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) < 2 then
  		return
  	end
  	local c = e:GetHandler()
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_DECK, 0, nil, e, tp)
  	local dg = g:Filter(s.filter2, nil, g)
  	if dg:GetCount() >= 1 then
  		local fid = c:GetFieldID()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sg = dg:Select(tp, 1, 1, nil)
  		local tc1 = sg:GetFirst()
  		local tc2 = dg:Filter(Card.IsCode, tc1, tc1:GetCode()):GetFirst()
  		Duel.SpecialSummonStep(tc1, SUMMON_VALUE_EVOLTILE, tp, tp, false, false, POS_FACEUP)
  		Duel.SpecialSummonStep(tc2, SUMMON_VALUE_EVOLTILE, tp, tp, false, false, POS_FACEUP)
  		tc1:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1, fid)
  		tc2:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1, fid)
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc1:RegisterEffect(e1, true)
  		local e2 = e1:Clone()
  		tc2:RegisterEffect(e2, true)
  		local e3 = Effect.CreateEffect(c)
  		e3:SetType(EFFECT_TYPE_SINGLE)
  		e3:SetCode(EFFECT_DISABLE_EFFECT)
  		e3:SetValue(RESET_TURN_SET)
  		e3:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc1:RegisterEffect(e3, true)
  		local e4 = e3:Clone()
  		tc2:RegisterEffect(e4, true)
  		Duel.SpecialSummonComplete()
  		sg:AddCard(tc2)
  		sg:KeepAlive()
  		local e5 = Effect.CreateEffect(c)
  		e5:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e5:SetCode(EVENT_PHASE + PHASE_END)
  		e5:SetCountLimit(1)
  		e5:SetLabel(fid)
  		e5:SetLabelObject(sg)
  		e5:SetCondition(s.rmcon)
  		e5:SetOperation(s.rmop)
  		Duel.RegisterEffect(e5, tp)
  	end
  end
  function s.rmfilter(c, fid)
  	return c:GetFlagEffectLabel(id) == fid
  end
  function s.rmcon(e, tp, eg, ep, ev, re, r, rp)
  	local g = e:GetLabelObject()
  	if not g:IsExists(s.rmfilter, 1, nil, e:GetLabel()) then
  		g:DeleteGroup()
  		e:Reset()
  		return false
  	else
  		return true
  	end
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local g = e:GetLabelObject()
  	local tg = g:Filter(s.rmfilter, nil, e:GetLabel())
  	Duel.Remove(tg, POS_FACEUP, REASON_EFFECT)
  end
  
  
source_text: Evoltile
  At the end of the Battle Phase, if this card destroyed an opponent's monster by battle: You can Tribute this card; Special Summon 2 Level 6 or lower FIRE Dinosaur-Type monsters with the same name from your Deck. Their effects are negated and they are banished during the End Phase.
target_text: -- Evoltile
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e1:SetCode(EVENT_BATTLE_DESTROYING)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e1:SetOperation(s.regop)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_PHASE + PHASE_BATTLE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCondition(s.spcon)
  	e2:SetCost(s.spcost)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) ~= 0
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsReleasable()
  	end
  	Duel.Release(e:GetHandler(), REASON_COST)
  end
  function s.filter(c, e, tp)
  	return c:IsLevelBelow(6) and c:IsRace(RACE_DINOSAUR) and c:IsAttribute(ATTRIBUTE_FIRE) and c:IsCanBeSpecialSummoned(e, SUMMON_VALUE_EVOLTILE, tp, false, false)
  end
  function s.filter2(c, g)
  	return g:IsExists(Card.IsCode, 1, c, c:GetCode())
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_DECK, 0, nil, e, tp)
  		return not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and g:IsExists(s.filter2, 1, nil, g)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 2, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		return
  	end
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) < 2 then
  		return
  	end
  	local c = e:GetHandler()
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_DECK, 0, nil, e, tp)
  	local dg = g:Filter(s.filter2, nil, g)
  	if dg:GetCount() >= 1 then
  		local fid = c:GetFieldID()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sg = dg:Select(tp, 1, 1, nil)
  		local tc1 = sg:GetFirst()
  		local tc2 = dg:Filter(Card.IsCode, tc1, tc1:GetCode()):GetFirst()
  		Duel.SpecialSummonStep(tc1, SUMMON_VALUE_EVOLTILE, tp, tp, false, false, POS_FACEUP)
  		Duel.SpecialSummonStep(tc2, SUMMON_VALUE_EVOLTILE, tp, tp, false, false, POS_FACEUP)
  		tc1:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1, fid)
  		tc2:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1, fid)
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc1:RegisterEffect(e1, true)
  		local e2 = e1:Clone()
  		tc2:RegisterEffect(e2, true)
  		local e3 = Effect.CreateEffect(c)
  		e3:SetType(EFFECT_TYPE_SINGLE)
  		e3:SetCode(EFFECT_DISABLE_EFFECT)
  		e3:SetValue(RESET_TURN_SET)
  		e3:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc1:RegisterEffect(e3, true)
  		local e4 = e3:Clone()
  		tc2:RegisterEffect(e4, true)
  		Duel.SpecialSummonComplete()
  		sg:AddCard(tc2)
  		sg:KeepAlive()
  		local e5 = Effect.CreateEffect(c)
  		e5:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e5:SetCode(EVENT_PHASE + PHASE_END)
  		e5:SetCountLimit(1)
  		e5:SetLabel(fid)
  		e5:SetLabelObject(sg)
  		e5:SetCondition(s.rmcon)
  		e5:SetOperation(s.rmop)
  		Duel.RegisterEffect(e5, tp)
  	end
  end
  function s.rmfilter(c, fid)
  	return c:GetFlagEffectLabel(id) == fid
  end
  function s.rmcon(e, tp, eg, ep, ev, re, r, rp)
  	local g = e:GetLabelObject()
  	if not g:IsExists(s.rmfilter, 1, nil, e:GetLabel()) then
  		g:DeleteGroup()
  		e:Reset()
  		return false
  	else
  		return true
  	end
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local g = e:GetLabelObject()
  	local tg = g:Filter(s.rmfilter, nil, e:GetLabel())
  	Duel.Remove(tg, POS_FACEUP, REASON_EFFECT)
  end
  
  