--Mecha Blade Base Defender local m=88880213 local cm=_G["c"..m] function cm.initial_effect(c) --Link summon aux.AddLinkProcedure(c,aux.FilterBoolFunction(Card.IsLinkSetCard,0xffd),2,2) c:EnableReviveLimit() local e0=Effect.CreateEffect(c) e0:SetType(EFFECT_TYPE_FIELD) e0:SetCode(EFFECT_SPSUMMON_PROC) e0:SetProperty(EFFECT_FLAG_UNCOPYABLE+EFFECT_FLAG_IGNORE_IMMUNE) e0:SetRange(LOCATION_EXTRA) e0:SetCondition(cm.linkcon) e0:SetOperation(cm.linkop) e0:SetValue(SUMMON_TYPE_LINK) c:RegisterEffect(e0) local e1=Effect.CreateEffect(c) e1:SetCategory(CATEGORY_TOHAND+CATEGORY_SEARCH) e1:SetCode(EVENT_SPSUMMON_SUCCESS) e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_O) e1:SetProperty(EFFECT_FLAG_DELAY) e1:SetRange(LOCATION_MZONE) e1:SetCountLimit(1,m) e1:SetCondition(cm.thcon1) e1:SetTarget(cm.thtg1) e1:SetOperation(cm.thop1) c:RegisterEffect(e1) local e2=Effect.CreateEffect(c) e2:SetType(EFFECT_TYPE_QUICK_O) e2:SetProperty(EFFECT_FLAG_CARD_TARGET) e2:SetCode(EVENT_FREE_CHAIN) e2:SetCountLimit(1,m) e2:SetRange(LOCATION_MZONE) e2:SetTarget(cm.sptg) e2:SetOperation(cm.spop) c:RegisterEffect(e2) end function cm.filter1(c,e,tp) return c:IsFaceup() and c:IsType(TYPE_XYZ) and Duel.IsExistingMatchingCard(cm.filter2,tp,LOCATION_EXTRA,0,1,nil,e,tp,c,c:GetCode()) and aux.MustMaterialCheck(c,tp,EFFECT_MUST_BE_XMATERIAL) end function cm.filter2(c,e,tp,mc,code) return c:IsType(TYPE_XYZ) and c:IsSetCard(0xffd) and not c:IsCode(code) and mc:IsCanBeXyzMaterial(c) and c:IsCanBeSpecialSummoned(e,SUMMON_TYPE_XYZ,tp,false,false) and Duel.GetLocationCountFromEx(tp,tp,mc,c)>0 end function cm.sptg(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_MZONE) and cm.filter1(chkc,e,tp) end if chk==0 then return Duel.IsExistingTarget(cm.filter1,tp,LOCATION_MZONE,0,1,nil,e,tp) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TARGET) Duel.SelectTarget(tp,cm.filter1,tp,LOCATION_MZONE,0,1,1,nil,e,tp) Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_EXTRA) end function cm.spop(e,tp,eg,ep,ev,re,r,rp) local tc=Duel.GetFirstTarget() if not aux.MustMaterialCheck(tc,tp,EFFECT_MUST_BE_XMATERIAL) then return end if tc:IsFacedown() or not tc:IsRelateToEffect(e) or tc:IsControler(1-tp) or tc:IsImmuneToEffect(e) then return end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local g=Duel.SelectMatchingCard(tp,cm.filter2,tp,LOCATION_EXTRA,0,1,1,nil,e,tp,tc,tc:GetCode()) local sc=g:GetFirst() if sc then local mg=tc:GetOverlayGroup() if mg:GetCount()~=0 then Duel.Overlay(sc,mg) end sc:SetMaterial(Group.FromCards(tc)) Duel.Overlay(sc,Group.FromCards(tc)) Duel.SpecialSummon(sc,SUMMON_TYPE_XYZ,tp,tp,false,false,POS_FACEUP) sc:CompleteProcedure() end end function cm.linkfilter(c,tp) return c:IsFaceup() and ((c:IsType(TYPE_XYZ) and c:IsSetCard(0xffd)and c:GetOverlayGroup():GetCount()>0)) end function cm.cfilter(c,tp) return c:IsFaceup() and (c:IsType(TYPE_XYZ) and c:IsSetCard(0xffd)) end function cm.linkcon(e,c,tp,eg,ep,ev,re,r,rp) if c==nil then return true end local tp=c:GetControler() local g=Duel.GetFieldGroup(tp,LOCATION_MZONE,0) return Duel.IsExistingMatchingCard(cm.linkfilter,tp,LOCATION_MZONE,0,1,nil,tp) and g:FilterCount(cm.cfilter,nil)==1 end function cm.linkop(e,tp,eg,ep,ev,re,r,rp,c) local g1=Duel.SelectMatchingCard(tp,cm.linkfilter,tp,LOCATION_MZONE,0,1,1,nil,tp) c:SetMaterial(g1) Duel.SendtoGrave(g1,REASON_MATERIAL+REASON_LINK) end function cm.cfilter2(c,ec) return ec:GetLinkedGroup():IsContains(c) end function cm.thcon1(e,tp,eg,ep,ev,re,r,rp) return eg:IsExists(cm.cfilter2,1,nil,e:GetHandler()) end function cm.thfilter1(c) return c:IsSetCard(0xffd) and c:IsType(TYPE_SPELL+TYPE_TRAP) and c:IsAbleToHand() end function cm.thtg1(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.IsExistingMatchingCard(cm.thfilter1,tp,LOCATION_DECK,0,1,nil) end Duel.SetOperationInfo(0,CATEGORY_TOHAND,nil,1,tp,LOCATION_DECK) end function cm.thop1(e,tp,eg,ep,ev,re,r,rp) Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND) local g=Duel.SelectMatchingCard(tp,cm.thfilter1,tp,LOCATION_DECK,0,1,1,nil) if #g>0 then Duel.SendtoHand(g,nil,REASON_EFFECT) Duel.ConfirmCards(1-tp,g) end end