--Not yet finalized values --Custom constants EFFECT_STABLE =765 EFFECT_CANNOT_BE_POLARITY_MATERIAL =766 TYPE_POLARITY =0x400000000 TYPE_CUSTOM =TYPE_CUSTOM|TYPE_POLARITY CTYPE_POLARITY =0x4 CTYPE_CUSTOM =CTYPE_CUSTOM|CTYPE_POLARITY --Custom Type Table Auxiliary.Polarities={} --number as index = card, card as index = function() is_synchro table.insert(aux.CannotBeEDMatCodes,EFFECT_CANNOT_BE_POLARITY_MATERIAL) --overwrite constants TYPE_EXTRA =TYPE_EXTRA|TYPE_POLARITY --overwrite functions local get_type, get_orig_type, get_prev_type_field, get_level, get_syn_level, get_rit_level, get_orig_level, is_xyz_level, get_prev_level_field, is_level, is_level_below, is_level_above, syn_target = Card.GetType, Card.GetOriginalType, Card.GetPreviousTypeOnField, Card.GetLevel, Card.GetSynchroLevel, Card.GetRitualLevel, Card.GetOriginalLevel, Card.IsXyzLevel, Card.GetPreviousLevelOnField, Card.IsLevel, Card.IsLevelBelow, Card.IsLevelAbove, Auxiliary.SynTarget Card.GetType=function(c,scard,sumtype,p) local tpe=scard and get_type(c,scard,sumtype,p) or get_type(c) if Auxiliary.Polarities[c] then tpe=tpe|TYPE_POLARITY if not Auxiliary.Polarities[c]() then tpe=tpe&~TYPE_SYNCHRO end end return tpe end Card.GetOriginalType=function(c) local tpe=get_orig_type(c) if Auxiliary.Polarities[c] then tpe=tpe|TYPE_POLARITY if not Auxiliary.Polarities[c]() then tpe=tpe&~TYPE_SYNCHRO end end return tpe end Card.GetPreviousTypeOnField=function(c) local tpe=get_prev_type_field(c) if Auxiliary.Polarities[c] then tpe=tpe|TYPE_POLARITY if not Auxiliary.Polarities[c]() then tpe=tpe&~TYPE_SYNCHRO end end return tpe end Card.GetLevel=function(c) if Auxiliary.Polarities[c] and not Auxiliary.Polarities[c]() then return 0 end return get_level(c) end Card.GetSynchroLevel=function(c,sc) if Auxiliary.Polarities[c] and not Auxiliary.Polarities[c]() then return 0 end return get_syn_level(c,sc) end Card.GetRitualLevel=function(c,rc) if Auxiliary.Polarities[c] and not Auxiliary.Polarities[c]() then return 0 end return get_rit_level(c,rc) end Card.GetOriginalLevel=function(c) if Auxiliary.Polarities[c] and not Auxiliary.Polarities[c]() then return 0 end return get_orig_level(c) end Card.IsXyzLevel=function(c,xyz,lv) if Auxiliary.Polarities[c] and not Auxiliary.Polarities[c]() then return false end return is_xyz_level(c,xyz,lv) end Card.GetPreviousLevelOnField=function(c) if Auxiliary.Polarities[c] and not Auxiliary.Polarities[c]() then return 0 end return get_prev_level_field(c) end Card.IsLevel=function(c,...) if Auxiliary.Polarities[c] and not Auxiliary.Polarities[c]() then return false end local funs={...} for key,value in pairs(funs) do if c:GetLevel()==value then return true end end return false end Card.IsLevelBelow=function(c,lv) if Auxiliary.Polarities[c] and not Auxiliary.Polarities[c]() then return false end return is_level_below(c,lv) end Card.IsLevelAbove=function(c,lv) if Auxiliary.Polarities[c] and not Auxiliary.Polarities[c]() then return false end return is_level_above(c,lv) end Auxiliary.SynTarget=function(f1,f2,minc,maxc) return function(e,tp,eg,ep,ev,re,r,rp,chk,c,smat,mg,min,max) local res=syn_target(f1,f2,minc,maxc)(e,tp,eg,ep,ev,re,r,rp,chk,c,smat,mg,min,max) local g=e:GetLabelObject() if g and g:IsExists(function(tc) return Auxiliary.Polarities[tc] and not Auxiliary.Polarities[tc]() end,1,nil) then g:DeleteGroup() res=false end return res end end --Custom Functions function Card.GetStability(c) if not c:IsHasEffect(EFFECT_STABLE) then return 0 end local te=c:IsHasEffect(EFFECT_STABLE) if type(te:GetValue())=='function' then return te:GetValue()(te,c) else return te:GetValue() end end function Card.IsStability(c,...) for stability in pairs({...}) do if c:Getstability()==stability then return true end end return false end function Card.IsStabilityAbove(c,stability) return c:GetStability()>=stability end function Card.IsStabilityBelow(c,stability) local stb=c:GetStability() return stb>0 and stb<=stability end function Card.IsCanBePolarityMaterial(c,ec) if c:GetLevel()<=0 and not c:IsStatus(STATUS_NO_LEVEL) then return false end local tef={c:IsHasEffect(EFFECT_CANNOT_BE_POLARITY_MATERIAL)} for _,te in ipairs(tef) do if te:GetValue()(te,ec) then return false end end return true end function Auxiliary.AddOrigPolarityType(c,issynchro) table.insert(Auxiliary.Polarities,c) Auxiliary.Customs[c]=true local issynchro=issynchro==nil and false or issynchro Auxiliary.Polarities[c]=function() return issynchro end end function Auxiliary.AddPolarityProc(c,stability,f1,f2) local e1=Effect.CreateEffect(c) e1:SetType(EFFECT_TYPE_SINGLE) e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE) e1:SetCode(EFFECT_STABLE) e1:SetValue(Auxiliary.StabilityVal(stability)) c:RegisterEffect(e1) local e2=Effect.CreateEffect(c) e2:SetType(EFFECT_TYPE_FIELD) e2:SetCode(EFFECT_SPSUMMON_PROC) e2:SetProperty(EFFECT_FLAG_UNCOPYABLE+EFFECT_FLAG_CANNOT_DISABLE) e2:SetRange(LOCATION_EXTRA) e2:SetCondition(Auxiliary.PolarityCondition(f1,f2)) e2:SetTarget(Auxiliary.PolarityTarget(f1,f2)) e2:SetOperation(Auxiliary.PolarityOperation) e2:SetValue(765) c:RegisterEffect(e2) end function Auxiliary.StabilityVal(stability) return function(e,c) local stability=stability --insert modifications here return stability end end function Auxiliary.PolarityMatFilter(c,ec,tp,...) if not c:IsCanBePolarityMaterial(ec) then return false end for _,f in ipairs({...}) do if f(c,ec,tp) then return true end end return false end function Auxiliary.PolarCheckRecursive1(g2,pc,stability) return function(sg,e,tp,mg) local sg2=g2:Filter(aux.TRUE,sg) return Auxiliary.SelectUnselectGroup(sg2,e,tp,nil,nil,Auxiliary.PolarCheckRecursive2(sg,pc,stability),0) end end function Auxiliary.PolarCheckRecursive2(g1,pc,stability) return function(g2,e,tp,mg) local sg=g1:Clone() sg:Merge(g2) return Duel.GetLocationCountFromEx(tp,tp,sg,pc)>0 and math.abs(g1:GetSum(Card.GetLevel)-g2:GetSum(Card.GetLevel))==stability end end function Auxiliary.PolarityCondition(f1,f2) return function(e,c) if c==nil then return true end if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end local tp=c:GetControler() local stability=c:GetStability() local mg=Duel.GetMatchingGroup(Auxiliary.PolarityMatFilter,tp,LOCATION_MZONE,0,nil,c,tp,f1,f2) local g1=mg:Filter(f1,nil,c,tp) local g2=mg:Filter(f2,nil,c,tp) return Auxiliary.SelectUnselectGroup(g1,e,tp,nil,nil,Auxiliary.PolarCheckRecursive1(g2,c,stability),0) end end function Auxiliary.PolarityTarget(f1,f2) return function(e,tp,eg,ep,ev,re,r,rp,chk,c) local mg=Duel.GetMatchingGroup(Auxiliary.PolarityMatFilter,tp,LOCATION_MZONE,0,nil,c,tp,f1,f2) local g1=mg:Filter(f1,nil,c,tp) local g2=mg:Filter(f2,nil,c,tp) local sg1=Auxiliary.SelectUnselectGroup(g1,e,tp,nil,nil,Auxiliary.PolarCheckRecursive1(g2,c,stability),1,tp,0,aux.TRUE) local mg2=mg:Sub(sg1) if not Auxiliary.PolarCheckRecursive1(g2,c,stability)(sg1,e,tp,mg2) then return false end local sg=sg1:Clone() local sg2=Group.CreateGroup() while true do local tg=g2:Sub(sg2) local mg=g:Filter(Auxiliary.SelectUnselectLoop,sg,sg,tg,e,tp,1,99,Auxiliary.PolarCheckRecursive2(sg1,c,stability)) if #mg<=0 then break end Duel.Hint(HINT_SELECTMSG,tp,0) local tc=mg:SelectUnselect(sg,tp,true,true) if not tc then break end if sg2:IsContains(tc) then sg2:RemoveCard(tc) sg:RemoveCard(tc) elseif not sg:IsContains(tc) then sg2:AddCard(tc) sg:AddCard(tc) end end local tg=g2:Sub(sg2) if Auxiliary.PolarCheckRecursive2(sg1,c,stability)(sg2,e,tp,tg) then sg:KeepAlive() e:SetLabelObject(sg) return true else return false end end end function Auxiliary.PolarityOperation(e,tp,eg,ep,ev,re,r,rp,c,smat,mg) if Duel.SetSummonCancelable then Duel.SetSummonCancelable(true) end local g=e:GetLabelObject() c:SetMaterial(g) Duel.SendtoGrave(g,REASON_MATERIAL+0x40000000) g:DeleteGroup() end