--机空援护 苍天降临 function c40009040.initial_effect(c) --activate local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetCode(EVENT_FREE_CHAIN) e1:SetHintTiming(0,TIMINGS_CHECK_MONSTER+TIMING_END_PHASE) c:RegisterEffect(e1) --synchro effect local e2=Effect.CreateEffect(c) e2:SetDescription(aux.Stringid(40009040,1)) e2:SetCategory(CATEGORY_SPECIAL_SUMMON) e2:SetType(EFFECT_TYPE_QUICK_O) e2:SetCode(EVENT_FREE_CHAIN) e2:SetRange(LOCATION_SZONE) e2:SetHintTiming(0,TIMING_BATTLE_START+TIMING_BATTLE_END) e2:SetCountLimit(1,40009040) e2:SetCondition(c40009040.sccon) e2:SetTarget(c40009040.target) e2:SetOperation(c40009040.activate) c:RegisterEffect(e2) --special summon local e3=Effect.CreateEffect(c) e3:SetDescription(aux.Stringid(40009040,2)) e3:SetCategory(CATEGORY_SPECIAL_SUMMON) e3:SetType(EFFECT_TYPE_QUICK_O) e3:SetProperty(EFFECT_FLAG_CARD_TARGET) e3:SetCode(EVENT_FREE_CHAIN) e3:SetRange(LOCATION_SZONE) e3:SetCountLimit(1,40009040) e3:SetCost(c40009040.spcost) e3:SetTarget(c40009040.sptg2) e3:SetOperation(c40009040.spop2) c:RegisterEffect(e3) end function c40009040.sccon(e,tp,eg,ep,ev,re,r,rp) if Duel.GetTurnPlayer()==tp then return false end local ph=Duel.GetCurrentPhase() return ph==PHASE_MAIN1 or (ph>=PHASE_BATTLE_START and ph<=PHASE_BATTLE) or ph==PHASE_MAIN2 end function c40009040.filter1(c) return c:IsLinkSummonable(nil) end function c40009040.target(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.IsExistingMatchingCard(c40009040.filter1,tp,LOCATION_EXTRA,0,1,nil) end Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,0,0) end function c40009040.activate(e,tp,eg,ep,ev,re,r,rp) Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local g=Duel.SelectMatchingCard(tp,c40009040.filter1,tp,LOCATION_EXTRA,0,1,1,nil) local tc=g:GetFirst() if tc then Duel.LinkSummon(tp,tc,nil) end end function c40009040.spcost(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return e:GetHandler():IsAbleToGraveAsCost() end Duel.SendtoGrave(e:GetHandler(),REASON_COST) end function c40009040.filter(c) return c:IsFaceup() and c:IsSetCard(0xf13) and c:IsType(TYPE_LINK) end function c40009040.spfilter2(c,e,tp) return c:IsSetCard(0xf13) and c:IsType(TYPE_LINK) and c:IsCanBeSpecialSummoned(e,0,tp,false,false,POS_FACEUP) end function c40009040.sptg2(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_MZONE) and c40009040.filter(chkc) end if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and Duel.IsExistingTarget(c40009040.filter,tp,LOCATION_MZONE,0,1,nil) and Duel.IsExistingMatchingCard(c40009040.spfilter2,tp,LOCATION_GRAVE,0,1,nil,e,tp) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FACEUP) Duel.SelectTarget(tp,c40009040.filter,tp,LOCATION_MZONE,0,1,1,nil) Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_GRAVE) end function c40009040.spop2(e,tp,eg,ep,ev,re,r,rp) local tc=Duel.GetFirstTarget() if not tc:IsRelateToEffect(e) then return end local ft=math.min(Duel.GetLocationCount(tp,LOCATION_MZONE),tc:GetLink()) if ft<=0 then return end if Duel.IsPlayerAffectedByEffect(tp,59822133) then ft=1 end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local g=Duel.SelectMatchingCard(tp,aux.NecroValleyFilter(c40009040.spfilter2),tp,LOCATION_GRAVE,0,1,ft,nil,e,tp) if g:GetCount()>0 then Duel.SpecialSummon(g,0,tp,tp,false,false,POS_FACEUP) end end