--Marionightte Puppetry local ref,id=GetID() Duel.LoadScript("Marionightte.lua") function ref.initial_effect(c) Marionightte.Induct(c,0) --Activate local e1=Effect.CreateEffect(c) e1:SetDescription(aux.Stringid(id,0)) e1:SetCategory(CATEGORY_SPECIAL_SUMMON+CATEGORY_SEARCH) e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetCode(EVENT_FREE_CHAIN) e1:SetProperty(EFFECT_FLAG_CARD_TARGET) e1:SetCountLimit(1,id) e1:SetTarget(ref.acttg) e1:SetOperation(ref.actop) c:RegisterEffect(e1) local e3=e1:Clone() e3:SetDescription(aux.Stringid(id,2)) e3:SetCountLimit(1,{id,2}) e3:SetCondition(function(e,tp) return Duel.GetFlagEffect(tp,id)>0 end) c:RegisterEffect(e3) --Recurr local e2=Effect.CreateEffect(c) e2:SetDescription(aux.Stringid(id,1)) e2:SetCategory(CATEGORY_TOHAND) e2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_O) e2:SetRange(LOCATION_GRAVE) e2:SetCode(EVENT_LEAVE_FIELD) e2:SetProperty(EFFECT_FLAG_DELAY) e2:SetCountLimit(1,{id,1}) e2:SetLabelObject(e1) e2:SetCondition(function(e,tp,eg,ep,ev,re,r,rp) return rp~=tp and eg:IsExists(ref.thcfilter,1,nil,tp) end) e2:SetCost(ref.thcost) e2:SetTarget(ref.thtg) e2:SetOperation(ref.thop) c:RegisterEffect(e2) end --Activate function ref.tgfilter(c,e,tp) return c:IsType(TYPE_MONSTER) and Duel.IsExistingMatchingCard(ref.ssfilter,tp,LOCATION_DECK,0,1,nil,c:GetRace(),e,tp) end function ref.ssfilter(c,typ,e,tp) return Marionightte.Is(c) and Marionightte.IsRaceInText(c,typ) and c:IsCanBeSpecialSummoned(e,0,tp,false,false) end function ref.acttg(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return ref.tgfilter(chkc,e,tp) and chkc:IsLocation(LOCATION_MZONE+LOCATION_GRAVE) end if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and Duel.IsExistingTarget(ref.tgfilter,tp,LOCATION_MZONE+LOCATION_GRAVE,LOCATION_MZONE+LOCATION_GRAVE,1,nil,e,tp) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TARGET) local g=Duel.SelectTarget(tp,ref.tgfilter,tp,LOCATION_MZONE+LOCATION_GRAVE,LOCATION_MZONE+LOCATION_GRAVE,1,1,nil,e,tp) Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_DECK+LOCATION_GRAVE) end function ref.actop(e,tp,eg,ep,ev,re,r,rp) local tc=Duel.GetFirstTarget() if Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and tc:IsRelateToEffect(e) then Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local g=Duel.SelectMatchingCard(tp,ref.ssfilter,tp,LOCATION_DECK+LOCATION_GRAVE,0,1,1,nil,tc:GetRace(),e,tp) if #g>0 and Duel.SpecialSummon(g,0,tp,tp,false,false,POS_FACEUP)~=0 then if not tc:IsRace(RACE_MACHINE) then Duel.RegisterFlagEffect(tp,Marionightte.ID,0,0,0) end local e1=Effect.CreateEffect(e:GetHandler()) e1:SetType(EFFECT_TYPE_FIELD) e1:SetCode(EFFECT_CANNOT_ACTIVATE) e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET) e1:SetTargetRange(1,0) e1:SetValue(ref.actlimit) e1:SetReset(RESET_PHASE+PHASE_END) Duel.RegisterEffect(e1,tp) end end end function ref.actlimit(e,re,rp) return re:IsActiveType(TYPE_MONSTER) and not (Duel.CheckEvent(EVENT_SUMMON_SUCCESS) or Duel.CheckEvent(EVENT_SPSUMMON_SUCCESS) or Duel.CheckEvent(EVENT_FLIP_SUMMON_SUCCESS)) end --Recurr function ref.thcfilter(c,tp) return c:GetPreviousControler()==tp and c:IsReason(REASON_EFFECT) end function ref.thcost(e,tp,eg,ep,ev,re,r,rp,chk) if chk==0 then return Duel.IsExistingMatchingCard(Card.IsAbleToRemove,tp,LOCATION_GRAVE,0,1,e:GetHandler()) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_REMOVE) local g=Duel.SelectMatchingCard(tp,Card.IsAbleToRemove,tp,LOCATION_GRAVE,0,1,1,e:GetHandler()) Duel.Remove(g,POS_FACEUP,REASON_COST) end function ref.thtg(e,tp,eg,ep,ev,re,r,rp,chk) local c=e:GetHandler() if chk==0 then return c:IsAbleToHand() end Duel.SetOperationInfo(0,CATEGORY_TOHAND,c,1,tp,LOCATION_GRAVE) end function ref.thop(e,tp,eg,ep,ev,re,r,rp) local c=e:GetHandler() if c:IsRelateToEffect(e) and Duel.SendtoHand(c,nil,REASON_EFFECT)~=0 then --e:GetLabelObject():UseCountLimit(tp,-1) Duel.RegisterFlagEffect(tp,id,RESET_PHASE+PHASE_END,0,1) end end