name: Neo
card_text: 2+ Effect Monsters including a "Super Quant" monster
  This Link Summoned card cannot be destroyed by your opponent's card effects. Each time a "Super Quant" Xyz Monster(s) with a different name from the cards you control is Special Summoned from the Extra Deck to a zone(s) this card points to: Draw 1 card. If a face-up Xyz Monster(s) this card points to is destroyed by battle or an opponent's card effect: You can Special Summon 1 "Super Quant" monster from your Deck with the same original Attribute as 1 of those destroyed Xyz Monsters. You can only use this effect of "Neo Super Quantal Mech King Blaster Magna" once per turn.
external_ids: local SETCARD_ID_0 = 0xdc --Super
  
lua: local SETCARD_ID_0 = 0xdc --Super
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkType, TYPE_EFFECT), 2, 99, s.lcheck)
  	c:EnableReviveLimit()
  	--indes
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e1:SetCondition(s.indcon)
  	e1:SetValue(aux.indoval)
  	c:RegisterEffect(e1)
  	--draw
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_DRAW)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCondition(s.drcon)
  	e2:SetTarget(s.drtg)
  	e2:SetOperation(s.drop)
  	c:RegisterEffect(e2)
  	--to hand
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_DAMAGE_STEP)
  	e3:SetCode(EVENT_DESTROYED)
  	e3:SetCountLimit(1, id)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCondition(s.spcon)
  	e3:SetTarget(s.sptg)
  	e3:SetOperation(s.spop)
  	c:RegisterEffect(e3)
  end
  function s.lcheck(g)
  	return g:IsExists(Card.IsLinkSetCard, 1, nil, 0xdc)
  end
  function s.indcon(e)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_LINK)
  end
  function s.cfilter(c, lg, tp)
  	return c:IsSetCard(SETCARD_ID_0)
  		and c:IsType(TYPE_XYZ)
  		and c:IsSummonLocation(LOCATION_EXTRA)
  		and lg:IsContains(c)
  		and not Duel.IsExistingMatchingCard(s.drfilter, tp, LOCATION_MZONE, 0, 1, c, c:GetCode())
  end
  function s.drfilter(c, code)
  	return c:IsFaceup() and c:IsCode(code)
  end
  function s.drcon(e, tp, eg, ep, ev, re, r, rp)
  	local lg = e:GetHandler():GetLinkedGroup()
  	return eg:IsExists(s.cfilter, 1, nil, lg, tp)
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(1)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Draw(p, d, REASON_EFFECT)
  end
  function s.cfilter2(c, tp, zone)
  	local seq = c:GetPreviousSequence()
  	if c:IsPreviousControler(1 - tp) then
  		seq = seq + 16
  	end
  	return c:IsPreviousLocation(LOCATION_MZONE) and bit.extract(zone, seq) ~= 0 and c:IsType(TYPE_XYZ) and (c:IsReason(REASON_BATTLE) or c:IsReason(REASON_EFFECT) and c:GetReasonPlayer() == 1 - tp)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local zone = e:GetHandler():GetLinkedZone()
  	local g = eg:Filter(s.cfilter2, nil, tp, zone)
  	local attr = 0
  	for tc in aux.Next(g) do
  		attr = attr | tc:GetOriginalAttribute()
  	end
  	e:SetLabel(attr)
  	return #g > 0
  end
  function s.spfilter(c, e, tp, attr)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and c:GetOriginalAttribute() & attr > 0
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp, e:GetLabel())
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp, e:GetLabel())
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Neo
  2+ Effect Monsters including a "Super Quant" monster
  This Link Summoned card cannot be destroyed by your opponent's card effects. Each time a "Super Quant" Xyz Monster(s) with a different name from the cards you control is Special Summoned from the Extra Deck to a zone(s) this card points to: Draw 1 card. If a face-up Xyz Monster(s) this card points to is destroyed by battle or an opponent's card effect: You can Special Summon 1 "Super Quant" monster from your Deck with the same original Attribute as 1 of those destroyed Xyz Monsters. You can only use this effect of "Neo Super Quantal Mech King Blaster Magna" once per turn.
target_text: -- Neo
  local SETCARD_ID_0 = 0xdc --Super
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkType, TYPE_EFFECT), 2, 99, s.lcheck)
  	c:EnableReviveLimit()
  	--indes
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e1:SetCondition(s.indcon)
  	e1:SetValue(aux.indoval)
  	c:RegisterEffect(e1)
  	--draw
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_DRAW)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCondition(s.drcon)
  	e2:SetTarget(s.drtg)
  	e2:SetOperation(s.drop)
  	c:RegisterEffect(e2)
  	--to hand
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_DAMAGE_STEP)
  	e3:SetCode(EVENT_DESTROYED)
  	e3:SetCountLimit(1, id)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCondition(s.spcon)
  	e3:SetTarget(s.sptg)
  	e3:SetOperation(s.spop)
  	c:RegisterEffect(e3)
  end
  function s.lcheck(g)
  	return g:IsExists(Card.IsLinkSetCard, 1, nil, 0xdc)
  end
  function s.indcon(e)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_LINK)
  end
  function s.cfilter(c, lg, tp)
  	return c:IsSetCard(SETCARD_ID_0)
  		and c:IsType(TYPE_XYZ)
  		and c:IsSummonLocation(LOCATION_EXTRA)
  		and lg:IsContains(c)
  		and not Duel.IsExistingMatchingCard(s.drfilter, tp, LOCATION_MZONE, 0, 1, c, c:GetCode())
  end
  function s.drfilter(c, code)
  	return c:IsFaceup() and c:IsCode(code)
  end
  function s.drcon(e, tp, eg, ep, ev, re, r, rp)
  	local lg = e:GetHandler():GetLinkedGroup()
  	return eg:IsExists(s.cfilter, 1, nil, lg, tp)
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(1)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Draw(p, d, REASON_EFFECT)
  end
  function s.cfilter2(c, tp, zone)
  	local seq = c:GetPreviousSequence()
  	if c:IsPreviousControler(1 - tp) then
  		seq = seq + 16
  	end
  	return c:IsPreviousLocation(LOCATION_MZONE) and bit.extract(zone, seq) ~= 0 and c:IsType(TYPE_XYZ) and (c:IsReason(REASON_BATTLE) or c:IsReason(REASON_EFFECT) and c:GetReasonPlayer() == 1 - tp)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local zone = e:GetHandler():GetLinkedZone()
  	local g = eg:Filter(s.cfilter2, nil, tp, zone)
  	local attr = 0
  	for tc in aux.Next(g) do
  		attr = attr | tc:GetOriginalAttribute()
  	end
  	e:SetLabel(attr)
  	return #g > 0
  end
  function s.spfilter(c, e, tp, attr)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and c:GetOriginalAttribute() & attr > 0
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp, e:GetLabel())
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp, e:GetLabel())
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  