name: Alviss
card_text: If only this card is banished by the effect of a "Nordic" Link Monster: You can send to the GY, 1 "Nordic" monster you control and 2 "Nordic" monsters from your Deck, whose total Levels equal 10, then Special Summon 1 "Aesir" monster from your Extra Deck. If an "Aesir" monster(s) in your possession is sent to your GY by your opponent's card: You can banish this card from your GY; Special Summon 1 "Aesir" monster from your Extra Deck, with a different name from the cards in your GY. You can only use this effect of "Alviss of the Nordic Alfar" once per Duel.
external_ids: local SETCARD_ID_0 = 0x4b --Aesir
  local SETCARD_ID_1 = 0x42 --Nordic
  
lua: local SETCARD_ID_0 = 0x4b --Aesir
  local SETCARD_ID_1 = 0x42 --Nordic
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOGRAVE)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_REMOVE)
  	e1:SetRange(LOCATION_REMOVED)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + EFFECT_COUNT_CODE_DUEL)
  	e2:SetCondition(s.spcon2)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.sptg2)
  	e2:SetOperation(s.spop2)
  	c:RegisterEffect(e2)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return #eg == 1 and eg:GetFirst() == e:GetHandler() and re and re:IsActiveType(TYPE_LINK) and re:GetHandler():IsSetCard(SETCARD_ID_1)
  end
  function s.matfilter(c)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsType(TYPE_MONSTER) and (c:IsFaceup() or c:IsLocation(LOCATION_DECK)) and c:IsLevelAbove(1)
  end
  function s.fgoal(sg, e, tp)
  	return sg:FilterCount(Card.IsLocation, nil, LOCATION_DECK) == 2 and sg:GetSum(Card.GetLevel) == 10 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, sg)
  end
  function s.spfilter(c, e, tp, mg)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and Duel.GetLocationCountFromEx(tp, tp, mg, c) > 0
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local mg = Duel.GetMatchingGroup(s.matfilter, tp, LOCATION_DECK + LOCATION_MZONE, 0, nil)
  		return mg:CheckSubGroup(s.fgoal, 3, 3, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 3, tp, LOCATION_DECK + LOCATION_MZONE)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local mg = Duel.GetMatchingGroup(s.matfilter, tp, LOCATION_DECK + LOCATION_MZONE, 0, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local sg = mg:SelectSubGroup(tp, s.fgoal, false, 3, 3, e, tp)
  	if sg and Duel.SendtoGrave(sg, REASON_EFFECT) == 3 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local tg = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, nil)
  		if tg:GetCount() > 0 then
  			Duel.BreakEffect()
  			Duel.SpecialSummon(tg, 0, tp, tp, false, false, POS_FACEUP)
  		end
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousSetCard(SETCARD_ID_1) and c:IsPreviousControler(tp)
  end
  function s.spcon2(e, tp, eg, ep, ev, re, r, rp)
  	return rp ~= tp and eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.spfilter2(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_1)
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  		and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0
  		and not Duel.IsExistingMatchingCard(Card.IsCode, tp, LOCATION_GRAVE, 0, 1, nil, c:GetCode())
  end
  function s.sptg2(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spfilter2, tp, LOCATION_EXTRA, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.spop2(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter2, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp)
  	if #g > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Alviss
  If only this card is banished by the effect of a "Nordic" Link Monster: You can send to the GY, 1 "Nordic" monster you control and 2 "Nordic" monsters from your Deck, whose total Levels equal 10, then Special Summon 1 "Aesir" monster from your Extra Deck. If an "Aesir" monster(s) in your possession is sent to your GY by your opponent's card: You can banish this card from your GY; Special Summon 1 "Aesir" monster from your Extra Deck, with a different name from the cards in your GY. You can only use this effect of "Alviss of the Nordic Alfar" once per Duel.
target_text: -- Alviss
  local SETCARD_ID_0 = 0x4b --Aesir
  local SETCARD_ID_1 = 0x42 --Nordic
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOGRAVE)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_REMOVE)
  	e1:SetRange(LOCATION_REMOVED)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + EFFECT_COUNT_CODE_DUEL)
  	e2:SetCondition(s.spcon2)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.sptg2)
  	e2:SetOperation(s.spop2)
  	c:RegisterEffect(e2)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return #eg == 1 and eg:GetFirst() == e:GetHandler() and re and re:IsActiveType(TYPE_LINK) and re:GetHandler():IsSetCard(SETCARD_ID_1)
  end
  function s.matfilter(c)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsType(TYPE_MONSTER) and (c:IsFaceup() or c:IsLocation(LOCATION_DECK)) and c:IsLevelAbove(1)
  end
  function s.fgoal(sg, e, tp)
  	return sg:FilterCount(Card.IsLocation, nil, LOCATION_DECK) == 2 and sg:GetSum(Card.GetLevel) == 10 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, sg)
  end
  function s.spfilter(c, e, tp, mg)
  	return c:IsSetCard(SETCARD_ID_1) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and Duel.GetLocationCountFromEx(tp, tp, mg, c) > 0
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local mg = Duel.GetMatchingGroup(s.matfilter, tp, LOCATION_DECK + LOCATION_MZONE, 0, nil)
  		return mg:CheckSubGroup(s.fgoal, 3, 3, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 3, tp, LOCATION_DECK + LOCATION_MZONE)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local mg = Duel.GetMatchingGroup(s.matfilter, tp, LOCATION_DECK + LOCATION_MZONE, 0, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local sg = mg:SelectSubGroup(tp, s.fgoal, false, 3, 3, e, tp)
  	if sg and Duel.SendtoGrave(sg, REASON_EFFECT) == 3 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local tg = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, nil)
  		if tg:GetCount() > 0 then
  			Duel.BreakEffect()
  			Duel.SpecialSummon(tg, 0, tp, tp, false, false, POS_FACEUP)
  		end
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousSetCard(SETCARD_ID_1) and c:IsPreviousControler(tp)
  end
  function s.spcon2(e, tp, eg, ep, ev, re, r, rp)
  	return rp ~= tp and eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.spfilter2(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_1)
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  		and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0
  		and not Duel.IsExistingMatchingCard(Card.IsCode, tp, LOCATION_GRAVE, 0, 1, nil, c:GetCode())
  end
  function s.sptg2(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spfilter2, tp, LOCATION_EXTRA, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.spop2(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter2, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp)
  	if #g > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  