--爱莎-虚无引渡者
function c60150822.initial_effect(c)
	--search
    local e3=Effect.CreateEffect(c)
    e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
    e3:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O)
    e3:SetCode(EVENT_REMOVE)
    e3:SetProperty(EFFECT_FLAG_DELAY)
    e3:SetCountLimit(1,60150822)
    e3:SetTarget(c60150822.thtg2)
    e3:SetOperation(c60150822.thop)
    c:RegisterEffect(e3)
	--salvage
    local e1=Effect.CreateEffect(c)
    e1:SetDescription(aux.Stringid(60150822,1))
    e1:SetCategory(CATEGORY_TOHAND)
    e1:SetType(EFFECT_TYPE_IGNITION)
    e1:SetRange(LOCATION_REMOVED)
    e1:SetCountLimit(1,60150822)
    e1:SetCost(c60150822.cost)
    e1:SetTarget(c60150822.tg)
    e1:SetOperation(c60150822.op)
    c:RegisterEffect(e1)
end
function c60150822.filter(c,e,tp)
    return c:IsSetCard(0x3b23) and c:IsCanBeSpecialSummoned(e,0,tp,false,false)
end
function c60150822.thtg2(e,tp,eg,ep,ev,re,r,rp,chk)
    if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0
        and Duel.IsExistingMatchingCard(c60150822.filter,tp,LOCATION_GRAVE,0,1,nil,e,tp) end
    Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_GRAVE)
end
function c60150822.thop(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,aux.NecroValleyFilter(c60150822.filter),tp,LOCATION_GRAVE,0,1,1,nil,e,tp)
    local tc=g:GetFirst()
    if tc then
        Duel.SpecialSummon(tc,0,tp,tp,false,false,POS_FACEUP)
		--xyz limit
        local e4=Effect.CreateEffect(e:GetHandler())
		e4:SetDescription(aux.Stringid(60150822,0))
        e4:SetType(EFFECT_TYPE_SINGLE)
        e4:SetProperty(EFFECT_FLAG_UNCOPYABLE+EFFECT_FLAG_CLIENT_HINT)
        e4:SetCode(EFFECT_CANNOT_BE_XYZ_MATERIAL)
        e4:SetReset(RESET_EVENT+0xfe0000)
        e4:SetValue(c60150822.xyzlimit)
        tc:RegisterEffect(e4)
        Duel.SpecialSummonComplete()
    end
end
function c60150822.xyzlimit(e,c)
    if not c then return false end
    return not (c:IsAttribute(ATTRIBUTE_DARK) and c:IsRace(RACE_SPELLCASTER))
end
function c60150822.cost(e,tp,eg,ep,ev,re,r,rp,chk)
    if chk==0 then return e:GetHandler():IsAbleToGraveAsCost() end
    Duel.SendtoGrave(e:GetHandler(),REASON_COST+REASON_RETURN)
end
function c60150822.thfilter(c)
    return c:IsSetCard(0x3b23) and c:IsFaceup() and c:IsAbleToHand()
end
function c60150822.tg(e,tp,eg,ep,ev,re,r,rp,chk,chkc)
    if chk==0 then return Duel.IsExistingMatchingCard(c60150822.thfilter,tp,LOCATION_REMOVED,LOCATION_REMOVED,1,e:GetHandler()) end
    local g=Duel.GetMatchingGroup(c60150822.thfilter,tp,LOCATION_REMOVED,LOCATION_REMOVED,e:GetHandler())
    Duel.SetOperationInfo(0,CATEGORY_TOHAND,g,1,0,0)
end
function c60150822.op(e,tp,eg,ep,ev,re,r,rp)
    Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND)
    local g=Duel.SelectMatchingCard(tp,c60150822.thfilter,tp,LOCATION_REMOVED,LOCATION_REMOVED,1,1,nil)
    if g:GetCount()>0 then
        Duel.HintSelection(g)
        Duel.SendtoHand(g,tp,REASON_EFFECT)
    end
end
