name: Ultimaya
card_text: (This card's original Level is always treated as 12.)
  Cannot be Synchro Summoned. Must be Special Summoned (from your Extra Deck) by sending 2 Level 5 or higher monsters you control with the same Level to the GY (1 Tuner and 1 non-Tuner). Once per turn, when a Spell/Trap(s) is Set on your field (except during the Damage Step): You can Special Summon 1 "Power Tool" Synchro Monster or 1 Level 7 or 8 Dragon Synchro Monster from your Extra Deck. While you control another Synchro Monster, monsters cannot target this card for attacks, also neither player can target it with card effects.
external_ids: local SETCARD_ID_0 = 0xc2 --Power
  
lua: local SETCARD_ID_0 = 0xc2 --Power
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--spsummon condition
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	c:RegisterEffect(e1)
  	--special summon rule
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_SPSUMMON_PROC)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e2:SetRange(LOCATION_EXTRA)
  	e2:SetCondition(s.sprcon)
  	e2:SetTarget(s.sprtg)
  	e2:SetOperation(s.sprop)
  	c:RegisterEffect(e2)
  	--special summon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_SSET)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.spcon)
  	e3:SetTarget(s.sptg)
  	e3:SetOperation(s.spop)
  	c:RegisterEffect(e3)
  	--cannot be target
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_SINGLE)
  	e4:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e4:SetCode(EFFECT_CANNOT_BE_BATTLE_TARGET)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCondition(s.tgcon)
  	e4:SetValue(aux.imval1)
  	c:RegisterEffect(e4)
  	local e5 = e4:Clone()
  	e5:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e5:SetValue(1)
  	c:RegisterEffect(e5)
  end
  function s.sprfilter(c)
  	return c:IsFaceup() and c:IsLevelAbove(5) and c:IsAbleToGraveAsCost()
  end
  function s.fselect(g, tp, sc)
  	if not aux.gffcheck(g, Card.IsType, TYPE_TUNER, aux.NOT(Card.IsType), TYPE_TUNER) or Duel.GetLocationCountFromEx(tp, tp, g, sc) <= 0 then
  		return false
  	end
  	local tc1 = g:GetFirst()
  	local tc2 = g:GetNext()
  	return tc1:IsLevel(tc2:GetLevel())
  end
  function s.sprcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	local g = Duel.GetMatchingGroup(s.sprfilter, tp, LOCATION_MZONE, 0, nil)
  	return g:CheckSubGroup(s.fselect, 2, 2, tp, c)
  end
  function s.sprtg(e, tp, eg, ep, ev, re, r, rp, chk, c)
  	local g = Duel.GetMatchingGroup(s.sprfilter, tp, LOCATION_MZONE, 0, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local sg = g:SelectSubGroup(tp, s.fselect, true, 2, 2, tp, c)
  	if sg then
  		sg:KeepAlive()
  		e:SetLabelObject(sg)
  		return true
  	else
  		return false
  	end
  end
  function s.sprop(e, tp, eg, ep, ev, re, r, rp, c)
  	local g = e:GetLabelObject()
  	Duel.SendtoGrave(g, REASON_SPSUMMON)
  	g:DeleteGroup()
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(Card.IsControler, 1, nil, tp)
  end
  function s.spfilter(c, e, tp)
  	return (c:IsSetCard(SETCARD_ID_0) or (c:IsLevel(7, 8) and c:IsRace(RACE_DRAGON)))
  		and c:IsType(TYPE_SYNCHRO)
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  		and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.tgfilter(c)
  	return c:IsFaceup() and c:IsType(TYPE_SYNCHRO)
  end
  function s.tgcon(e)
  	return Duel.IsExistingMatchingCard(s.tgfilter, e:GetHandlerPlayer(), LOCATION_MZONE, 0, 1, e:GetHandler())
  end
  
  
source_text: Ultimaya
  (This card's original Level is always treated as 12.)
  Cannot be Synchro Summoned. Must be Special Summoned (from your Extra Deck) by sending 2 Level 5 or higher monsters you control with the same Level to the GY (1 Tuner and 1 non-Tuner). Once per turn, when a Spell/Trap(s) is Set on your field (except during the Damage Step): You can Special Summon 1 "Power Tool" Synchro Monster or 1 Level 7 or 8 Dragon Synchro Monster from your Extra Deck. While you control another Synchro Monster, monsters cannot target this card for attacks, also neither player can target it with card effects.
target_text: -- Ultimaya
  local SETCARD_ID_0 = 0xc2 --Power
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--spsummon condition
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	c:RegisterEffect(e1)
  	--special summon rule
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_SPSUMMON_PROC)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e2:SetRange(LOCATION_EXTRA)
  	e2:SetCondition(s.sprcon)
  	e2:SetTarget(s.sprtg)
  	e2:SetOperation(s.sprop)
  	c:RegisterEffect(e2)
  	--special summon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_SSET)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.spcon)
  	e3:SetTarget(s.sptg)
  	e3:SetOperation(s.spop)
  	c:RegisterEffect(e3)
  	--cannot be target
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_SINGLE)
  	e4:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e4:SetCode(EFFECT_CANNOT_BE_BATTLE_TARGET)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCondition(s.tgcon)
  	e4:SetValue(aux.imval1)
  	c:RegisterEffect(e4)
  	local e5 = e4:Clone()
  	e5:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e5:SetValue(1)
  	c:RegisterEffect(e5)
  end
  function s.sprfilter(c)
  	return c:IsFaceup() and c:IsLevelAbove(5) and c:IsAbleToGraveAsCost()
  end
  function s.fselect(g, tp, sc)
  	if not aux.gffcheck(g, Card.IsType, TYPE_TUNER, aux.NOT(Card.IsType), TYPE_TUNER) or Duel.GetLocationCountFromEx(tp, tp, g, sc) <= 0 then
  		return false
  	end
  	local tc1 = g:GetFirst()
  	local tc2 = g:GetNext()
  	return tc1:IsLevel(tc2:GetLevel())
  end
  function s.sprcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	local g = Duel.GetMatchingGroup(s.sprfilter, tp, LOCATION_MZONE, 0, nil)
  	return g:CheckSubGroup(s.fselect, 2, 2, tp, c)
  end
  function s.sprtg(e, tp, eg, ep, ev, re, r, rp, chk, c)
  	local g = Duel.GetMatchingGroup(s.sprfilter, tp, LOCATION_MZONE, 0, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local sg = g:SelectSubGroup(tp, s.fselect, true, 2, 2, tp, c)
  	if sg then
  		sg:KeepAlive()
  		e:SetLabelObject(sg)
  		return true
  	else
  		return false
  	end
  end
  function s.sprop(e, tp, eg, ep, ev, re, r, rp, c)
  	local g = e:GetLabelObject()
  	Duel.SendtoGrave(g, REASON_SPSUMMON)
  	g:DeleteGroup()
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(Card.IsControler, 1, nil, tp)
  end
  function s.spfilter(c, e, tp)
  	return (c:IsSetCard(SETCARD_ID_0) or (c:IsLevel(7, 8) and c:IsRace(RACE_DRAGON)))
  		and c:IsType(TYPE_SYNCHRO)
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  		and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.tgfilter(c)
  	return c:IsFaceup() and c:IsType(TYPE_SYNCHRO)
  end
  function s.tgcon(e)
  	return Duel.IsExistingMatchingCard(s.tgfilter, e:GetHandlerPlayer(), LOCATION_MZONE, 0, 1, e:GetHandler())
  end
  
  