--原质神剑
local s,id,o=GetID()
function s.initial_effect(c)
    --xyz summon
    aux.AddXyzProcedure(c,nil,3,3)
    c:EnableReviveLimit()
    --[[把这张卡2个超量素材取除才能发动。
    从额外卡组选2只「原质炉」超量怪兽特殊召唤。
    这个效果的发动后，直到回合结束时自己不是超量怪兽不能从额外卡组特殊召唤。]]
    local e1=Effect.CreateEffect(c)
    e1:SetDescription(aux.Stringid(id,1))
    e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
    e1:SetType(EFFECT_TYPE_IGNITION)
    e1:SetRange(LOCATION_MZONE)
    e1:SetCountLimit(1,id)
    e1:SetCost(s.cost1)
    e1:SetTarget(s.tg1)
    e1:SetOperation(s.op1)
    c:RegisterEffect(e1)
    --[[装备这张卡的通常怪兽的攻击力变成8000]]
    local e2=Effect.CreateEffect(c)
    e2:SetType(EFFECT_TYPE_EQUIP)
    e2:SetCode(EFFECT_SET_ATTACK)
    e2:SetCondition(s.con2)
    e2:SetValue(8000)
    c:RegisterEffect(e2)
    --[[以自己场上1只通常怪兽或者超量怪兽以外的「原质炉」怪兽为对象，从以下效果中选1个效果发动。
    ●把这张卡当作装备卡使用给那只怪兽装备。
    ●那只怪兽在这张卡下面重叠作为超量素材。]]
    local e3=Effect.CreateEffect(c)
    e3:SetDescription(aux.Stringid(id,3))
    e3:SetType(EFFECT_TYPE_IGNITION)
    e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
    e3:SetRange(LOCATION_MZONE)
    e3:SetCountLimit(1,id+id)
    e3:SetTarget(s.tg3)
    e3:SetOperation(s.op3)
    c:RegisterEffect(e3)
    local e4=e3:Clone()
    e3:SetDescription(aux.Stringid(id,2))
    e4:SetCategory(CATEGORY_EQUIP)
    e4:SetTarget(s.tg4)
    e4:SetOperation(s.op4)
    c:RegisterEffect(e4)
end
function s.cost1(e,tp,eg,ep,ev,re,r,rp,chk)
    if chk==0 then return e:GetHandler():CheckRemoveOverlayCard(tp,2,REASON_COST) end
    Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_REMOVEXYZ)
    e:GetHandler():RemoveOverlayCard(tp,2,2,REASON_COST)
end
function s.filter1(c,e,tp)
    return c:IsSetCard(0x160) and c:IsType(TYPE_XYZ) and c:IsCanBeSpecialSummoned(e,0,tp,false,false) and Duel.GetLocationCountFromEx(tp,tp,nil,c)>=2
end
function s.tg1(e,tp,eg,ep,ev,re,r,rp,chk)
    if chk==0 then return Duel.IsExistingMatchingCard(s.filter1,tp,LOCATION_EXTRA,0,2,nil,e,tp) end
    Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,2,tp,LOCATION_EXTRA)
end
function s.op1(e,tp,eg,ep,ev,re,r,rp)
    Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)
    local g=Duel.SelectMatchingCard(tp,s.filter1,tp,LOCATION_EXTRA,0,2,2,nil,e,tp)
    if g then Duel.SpecialSummon(g,0,tp,tp,false,false,POS_FACEUP) end
    local e1=Effect.CreateEffect(e:GetHandler())
    e1:SetType(EFFECT_TYPE_FIELD)
    e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
    e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
    e1:SetTargetRange(1,0)
    e1:SetTarget(s.splimit)
    e1:SetReset(RESET_PHASE+PHASE_END)
    Duel.RegisterEffect(e1,tp)
end
function s.splimit(e,c)
    return c:IsLocation(LOCATION_EXTRA) and not c:IsType(TYPE_XYZ)
end
function s.con2(e)
    return e:GetHandler():GetEquipTarget() and e:GetHandler():GetEquipTarget():IsType(TYPE_NORMAL)
end
function s.filter3(c)
    return (c:IsType(TYPE_NORMAL) or (c:IsSetCard(0x160) and not c:IsType(TYPE_XYZ))) and c:IsCanOverlay() and c:IsFaceup()
end
function s.tg3(e,tp,eg,ep,ev,re,r,rp,chk,chkc)
    if chkc then return chkc:IsLocation(LOCATION_MZONE) and s.filter3(chkc) end
    if chk==0 then return e:GetHandler():IsType(TYPE_XYZ)
        and Duel.IsExistingTarget(s.filter3,tp,LOCATION_MZONE,0,1,nil) end
    Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_XMATERIAL)
    Duel.SelectTarget(tp,s.filter3,tp,LOCATION_MZONE,0,1,1,nil)
end
function s.op3(e,tp,eg,ep,ev,re,r,rp)
    local c=e:GetHandler()
    local tc=Duel.GetFirstTarget()
    if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) and not tc:IsImmuneToEffect(e) then
        local og=tc:GetOverlayGroup()
        if og:GetCount()>0 then
            Duel.SendtoGrave(og,REASON_RULE)
        end
        Duel.Overlay(c,Group.FromCards(tc))
    end
end
function s.filter4(c)
    return c:IsFaceup() and (c:IsType(TYPE_NORMAL) or (c:IsSetCard(0x160) and not c:IsType(TYPE_XYZ)))
end
function s.tg4(e,tp,eg,ep,ev,re,r,rp,chk,chkc)
    local c=e:GetHandler()
    if chkc then return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.filter4(chkc) end
    if chk==0 then return Duel.GetLocationCount(tp,LOCATION_SZONE)>0
        and Duel.IsExistingTarget(s.filter4,tp,LOCATION_MZONE,0,1,nil) end
    Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_EQUIP)
    local g=Duel.SelectTarget(tp,s.filter4,tp,LOCATION_MZONE,0,1,1,nil)
    Duel.SetOperationInfo(0,CATEGORY_EQUIP,g,1,0,0)
end
function s.op4(e,tp,eg,ep,ev,re,r,rp)
    local c=e:GetHandler()
    local tc=Duel.GetFirstTarget()
    if not c:IsRelateToEffect(e) or c:IsFacedown() then return end
    if not tc:IsRelateToEffect(e) or not s.filter4(tc) then
        Duel.SendtoGrave(c,REASON_EFFECT)
        return
    end
    if not Duel.Equip(tp,c,tc) then return end
    local e1=Effect.CreateEffect(c)
    e1:SetType(EFFECT_TYPE_SINGLE)
    e1:SetCode(EFFECT_EQUIP_LIMIT)
    e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
    e1:SetReset(RESET_EVENT+RESETS_STANDARD)
    e1:SetValue(s.eqlimit)
    e1:SetLabelObject(tc)
    c:RegisterEffect(e1)
end
function s.eqlimit(e,c)
    return c==e:GetLabelObject()
end