name: King's
card_text: When your opponent's monster declares an attack on a Synchro Monster you control: Negate the attack, then you can apply the rest of this card's effect. Banish that Synchro Monster you control and 1 Tuner from your GY, and if you do, Special Summon from your Extra Deck 1 Synchro Monster whose Level equals the total Levels the banished monsters had. (This is treated as a Synchro Summon.)
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_REMOVE + CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetAttackTarget()
  	return tc and tc:IsFaceup() and tc:IsControler(tp) and tc:IsType(TYPE_SYNCHRO)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetTargetCard(Duel.GetAttackTarget())
  end
  function s.filter1(c, e, tp, tc)
  	local rlv = c:GetLevel() - tc:GetLevel()
  	return rlv > 0
  		and c:IsType(TYPE_SYNCHRO)
  		and c:IsCanBeSpecialSummoned(e, SUMMON_TYPE_SYNCHRO, tp, false, false)
  		and Duel.GetLocationCountFromEx(tp, tp, tc, c) > 0
  		and Duel.IsExistingMatchingCard(s.filter2, tp, LOCATION_GRAVE, 0, 1, nil, tp, rlv)
  end
  function s.filter2(c, tp, lv)
  	local rlv = lv - c:GetLevel()
  	return rlv == 0 and c:IsType(TYPE_TUNER) and c:IsAbleToRemove()
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetAttackTarget()
  	if
  		Duel.NegateAttack()
  		and tc:IsRelateToEffect(e)
  		and tc:IsAbleToRemove()
  		and not tc:IsImmuneToEffect(e)
  		and aux.MustMaterialCheck(nil, tp, EFFECT_MUST_BE_SMATERIAL)
  		and Duel.IsExistingMatchingCard(s.filter1, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, tc)
  		and Duel.SelectYesNo(tp, aux.Stringid(id, 0))
  	then
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g1 = Duel.SelectMatchingCard(tp, s.filter1, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, tc)
  		local lv = g1:GetFirst():GetLevel() - tc:GetLevel()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  		local g2 = Duel.SelectMatchingCard(tp, s.filter2, tp, LOCATION_GRAVE, 0, 1, 1, nil, tp, lv)
  		g2:AddCard(tc)
  		Duel.Remove(g2, POS_FACEUP, REASON_EFFECT)
  		g1:GetFirst():SetMaterial(nil)
  		Duel.SpecialSummon(g1, SUMMON_TYPE_SYNCHRO, tp, tp, false, false, POS_FACEUP)
  		g1:GetFirst():CompleteProcedure()
  	end
  end
  
  
source_text: King's
  When your opponent's monster declares an attack on a Synchro Monster you control: Negate the attack, then you can apply the rest of this card's effect. Banish that Synchro Monster you control and 1 Tuner from your GY, and if you do, Special Summon from your Extra Deck 1 Synchro Monster whose Level equals the total Levels the banished monsters had. (This is treated as a Synchro Summon.)
target_text: -- King's
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_REMOVE + CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetAttackTarget()
  	return tc and tc:IsFaceup() and tc:IsControler(tp) and tc:IsType(TYPE_SYNCHRO)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetTargetCard(Duel.GetAttackTarget())
  end
  function s.filter1(c, e, tp, tc)
  	local rlv = c:GetLevel() - tc:GetLevel()
  	return rlv > 0
  		and c:IsType(TYPE_SYNCHRO)
  		and c:IsCanBeSpecialSummoned(e, SUMMON_TYPE_SYNCHRO, tp, false, false)
  		and Duel.GetLocationCountFromEx(tp, tp, tc, c) > 0
  		and Duel.IsExistingMatchingCard(s.filter2, tp, LOCATION_GRAVE, 0, 1, nil, tp, rlv)
  end
  function s.filter2(c, tp, lv)
  	local rlv = lv - c:GetLevel()
  	return rlv == 0 and c:IsType(TYPE_TUNER) and c:IsAbleToRemove()
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetAttackTarget()
  	if
  		Duel.NegateAttack()
  		and tc:IsRelateToEffect(e)
  		and tc:IsAbleToRemove()
  		and not tc:IsImmuneToEffect(e)
  		and aux.MustMaterialCheck(nil, tp, EFFECT_MUST_BE_SMATERIAL)
  		and Duel.IsExistingMatchingCard(s.filter1, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, tc)
  		and Duel.SelectYesNo(tp, aux.Stringid(id, 0))
  	then
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g1 = Duel.SelectMatchingCard(tp, s.filter1, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, tc)
  		local lv = g1:GetFirst():GetLevel() - tc:GetLevel()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  		local g2 = Duel.SelectMatchingCard(tp, s.filter2, tp, LOCATION_GRAVE, 0, 1, 1, nil, tp, lv)
  		g2:AddCard(tc)
  		Duel.Remove(g2, POS_FACEUP, REASON_EFFECT)
  		g1:GetFirst():SetMaterial(nil)
  		Duel.SpecialSummon(g1, SUMMON_TYPE_SYNCHRO, tp, tp, false, false, POS_FACEUP)
  		g1:GetFirst():CompleteProcedure()
  	end
  end
  
  