function c249000647.initial_effect(c) --Activate local e1=Effect.CreateEffect(c) e1:SetCategory(CATEGORY_SPECIAL_SUMMON) e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetCode(EVENT_FREE_CHAIN) e1:SetProperty(EFFECT_FLAG_CARD_TARGET) e1:SetCost(c249000647.cost) e1:SetTarget(c249000647.target) e1:SetOperation(c249000647.activate) c:RegisterEffect(e1) end function c249000647.costfilter(c) return c:IsSetCard(0x1E2) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemoveAsCost() end function c249000647.costfilter2(c,e) return c:IsSetCard(0x1E2) and c:IsType(TYPE_MONSTER) and not c:IsPublic() end function c249000647.cost(e,tp,eg,ep,ev,re,r,rp,chk) local c=e:GetHandler() if chk==0 then return (Duel.IsExistingMatchingCard(c249000647.costfilter,tp,LOCATION_GRAVE,0,1,nil) or Duel.IsExistingMatchingCard(c249000647.costfilter2,tp,LOCATION_HAND,0,1,c)) end local option if Duel.IsExistingMatchingCard(c249000647.costfilter2,tp,LOCATION_HAND,0,1,c) then option=0 end if Duel.IsExistingMatchingCard(c249000647.costfilter,tp,LOCATION_GRAVE,0,1,nil) then option=1 end if Duel.IsExistingMatchingCard(c249000647.costfilter,tp,LOCATION_GRAVE,0,1,nil) and Duel.IsExistingMatchingCard(c249000647.costfilter2,tp,LOCATION_HAND,0,1,c) then option=Duel.SelectOption(tp,526,1102) end if option==0 then g=Duel.SelectMatchingCard(tp,c249000647.costfilter2,tp,LOCATION_HAND,0,1,1,c) Duel.ConfirmCards(1-tp,g) Duel.ShuffleHand(tp) end if option==1 then Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_REMOVE) local g=Duel.SelectMatchingCard(tp,c249000647.costfilter,tp,LOCATION_GRAVE,0,1,1,nil) Duel.Remove(g,POS_FACEUP,REASON_COST) end end function c249000647.filter(c,e,tp) local rk=c:GetRank() local att=c:GetAttribute() return rk>0 and c:IsFaceup() and Duel.IsExistingMatchingCard(c249000647.spfilter,tp,LOCATION_EXTRA,0,1,nil,e,tp,rk,att,c) end function c249000647.spfilter(c,e,tp,rk,att,mc) return c:IsType(TYPE_XYZ) and c:GetRank()>rk and c:GetRank() <=rk+2 and c:IsAttribute(att) and c:IsCanBeSpecialSummoned(e,SUMMON_TYPE_XYZ,tp,false,false) and Duel.GetLocationCountFromEx(tp,tp,mc,c)>0 end function c249000647.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc) if chkc then return false end if chk==0 then return Duel.IsExistingTarget(c249000647.filter,tp,LOCATION_MZONE,0,1,nil,e,tp) end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TOGRAVE) local g=Duel.SelectTarget(tp,c249000647.filter,tp,LOCATION_MZONE,0,1,1,nil,e,tp) Duel.SetOperationInfo(0,CATEGORY_TOGRAVE,g,1,0,0) Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_EXTRA) e:SetLabelObject(g:GetFirst()) end function c249000647.activate(e,tp,eg,ep,ev,re,r,rp) local tc=Duel.GetFirstTarget() if not tc:IsRelateToEffect(e) then return end local att=tc:GetAttribute() local rk=tc:GetRank() if Duel.SendtoGrave(tc,REASON_EFFECT)==0 then return end Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) local g=Duel.SelectMatchingCard(tp,c249000647.spfilter,tp,LOCATION_EXTRA,0,1,1,nil,e,tp,rk,att,nil) if g:GetCount()>0 then Duel.BreakEffect() Duel.SpecialSummon(g,SUMMON_TYPE_XYZ,tp,tp,false,false,POS_FACEUP) g:GetFirst():CompleteProcedure() local tc2=Duel.GetFieldCard(tp,LOCATION_GRAVE,Duel.GetFieldGroupCount(tp,LOCATION_GRAVE,0)-1) if tc2 then Duel.Overlay(g:GetFirst(),tc2) end tc2=Duel.GetFieldCard(tp,LOCATION_GRAVE,Duel.GetFieldGroupCount(tp,LOCATION_GRAVE,0)-1) if tc2 then Duel.Overlay(g:GetFirst(),tc2) end local e1=Effect.CreateEffect(e:GetHandler()) e1:SetType(EFFECT_TYPE_FIELD) e1:SetCode(EFFECT_CHANGE_DAMAGE) e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET) e1:SetTargetRange(0,1) e1:SetValue(c249000647.damval) e1:SetReset(RESET_PHASE+PHASE_END) Duel.RegisterEffect(e1,tp) end end function c249000647.damval(e,re,val,r,rp,rc) return math.floor(val/2) end