游戏王残局简化版

Annotation For script/utility.txt
Login

Annotation For script/utility.txt

Origin for each line in script/utility.txt from check-in 748ed664c0:

748ed664c0 2023-06-29    1: Auxiliary={}
748ed664c0 2023-06-29    2: aux=Auxiliary
748ed664c0 2023-06-29    3: POS_FACEUP_DEFENCE=POS_FACEUP_DEFENSE
748ed664c0 2023-06-29    4: POS_FACEDOWN_DEFENCE=POS_FACEDOWN_DEFENSE
748ed664c0 2023-06-29    5: RACE_CYBERS=RACE_CYBERSE
748ed664c0 2023-06-29    6: 
748ed664c0 2023-06-29    7: function GetID()
748ed664c0 2023-06-29    8: 	local offset=self_code<100000000 and 1 or 100
748ed664c0 2023-06-29    9: 	return self_table,self_code,offset
748ed664c0 2023-06-29   10: end
748ed664c0 2023-06-29   11: 
748ed664c0 2023-06-29   12: --the lua version of the bit32 lib, which is deprecated in lua 5.3
748ed664c0 2023-06-29   13: bit={}
748ed664c0 2023-06-29   14: function bit.band(a,b)
748ed664c0 2023-06-29   15: 	return a&b
748ed664c0 2023-06-29   16: end
748ed664c0 2023-06-29   17: function bit.bor(a,b)
748ed664c0 2023-06-29   18: 	return a|b
748ed664c0 2023-06-29   19: end
748ed664c0 2023-06-29   20: function bit.bxor(a,b)
748ed664c0 2023-06-29   21: 	return a~b
748ed664c0 2023-06-29   22: end
748ed664c0 2023-06-29   23: function bit.lshift(a,b)
748ed664c0 2023-06-29   24: 	return a<<b
748ed664c0 2023-06-29   25: end
748ed664c0 2023-06-29   26: function bit.rshift(a,b)
748ed664c0 2023-06-29   27: 	return a>>b
748ed664c0 2023-06-29   28: end
748ed664c0 2023-06-29   29: function bit.bnot(a)
748ed664c0 2023-06-29   30: 	return ~a
748ed664c0 2023-06-29   31: end
748ed664c0 2023-06-29   32: local function fieldargs(f,width)
748ed664c0 2023-06-29   33: 	w=width or 1
748ed664c0 2023-06-29   34: 	assert(f>=0,"field cannot be negative")
748ed664c0 2023-06-29   35: 	assert(w>0,"width must be positive")
748ed664c0 2023-06-29   36: 	assert(f+w<=32,"trying to access non-existent bits")
748ed664c0 2023-06-29   37: 	return f,~(-1<<w)
748ed664c0 2023-06-29   38: end
748ed664c0 2023-06-29   39: function bit.extract(r,field,width)
748ed664c0 2023-06-29   40: 	local f,m=fieldargs(field,width)
748ed664c0 2023-06-29   41: 	return (r>>f)&m
748ed664c0 2023-06-29   42: end
748ed664c0 2023-06-29   43: function bit.replace(r,v,field,width)
748ed664c0 2023-06-29   44: 	local f,m=fieldargs(field,width)
748ed664c0 2023-06-29   45: 	return (r&~(m<<f))|((v&m)<< f)
748ed664c0 2023-06-29   46: end
748ed664c0 2023-06-29   47: 
748ed664c0 2023-06-29   48: --the table of xyz number
748ed664c0 2023-06-29   49: Auxiliary.xyz_number={}
748ed664c0 2023-06-29   50: function Auxiliary.GetXyzNumber(v)
748ed664c0 2023-06-29   51: 	local id
748ed664c0 2023-06-29   52: 	if Auxiliary.GetValueType(v)=="Card" then id=v:GetCode() end
748ed664c0 2023-06-29   53: 	if Auxiliary.GetValueType(v)=="number" then id=v end
748ed664c0 2023-06-29   54: 	return Auxiliary.xyz_number[id]
748ed664c0 2023-06-29   55: end
748ed664c0 2023-06-29   56: 
748ed664c0 2023-06-29   57: --the chain id of the results modified by EVENT_TOSS_DICE_NEGATE
748ed664c0 2023-06-29   58: Auxiliary.idx_table=table.pack(1,2,3,4,5,6,7,8)
748ed664c0 2023-06-29   59: 
748ed664c0 2023-06-29   60: function Auxiliary.Stringid(code,id)
748ed664c0 2023-06-29   61: 	return code*16+id
748ed664c0 2023-06-29   62: end
748ed664c0 2023-06-29   63: function Auxiliary.Next(g)
748ed664c0 2023-06-29   64: 	local first=true
748ed664c0 2023-06-29   65: 	return	function()
748ed664c0 2023-06-29   66: 				if first then first=false return g:GetFirst()
748ed664c0 2023-06-29   67: 				else return g:GetNext() end
748ed664c0 2023-06-29   68: 			end
748ed664c0 2023-06-29   69: end
748ed664c0 2023-06-29   70: function Auxiliary.NULL()
748ed664c0 2023-06-29   71: end
748ed664c0 2023-06-29   72: function Auxiliary.TRUE()
748ed664c0 2023-06-29   73: 	return true
748ed664c0 2023-06-29   74: end
748ed664c0 2023-06-29   75: function Auxiliary.FALSE()
748ed664c0 2023-06-29   76: 	return false
748ed664c0 2023-06-29   77: end
748ed664c0 2023-06-29   78: function Auxiliary.AND(...)
748ed664c0 2023-06-29   79: 	local function_list={...}
748ed664c0 2023-06-29   80: 	return	function(...)
748ed664c0 2023-06-29   81: 				local res=false
748ed664c0 2023-06-29   82: 				for i,f in ipairs(function_list) do
748ed664c0 2023-06-29   83: 					res=f(...)
748ed664c0 2023-06-29   84: 					if not res then return res end
748ed664c0 2023-06-29   85: 				end
748ed664c0 2023-06-29   86: 				return res
748ed664c0 2023-06-29   87: 			end
748ed664c0 2023-06-29   88: end
748ed664c0 2023-06-29   89: function Auxiliary.OR(...)
748ed664c0 2023-06-29   90: 	local function_list={...}
748ed664c0 2023-06-29   91: 	return	function(...)
748ed664c0 2023-06-29   92: 				local res=false
748ed664c0 2023-06-29   93: 				for i,f in ipairs(function_list) do
748ed664c0 2023-06-29   94: 					res=f(...)
748ed664c0 2023-06-29   95: 					if res then return res end
748ed664c0 2023-06-29   96: 				end
748ed664c0 2023-06-29   97: 				return res
748ed664c0 2023-06-29   98: 			end
748ed664c0 2023-06-29   99: end
748ed664c0 2023-06-29  100: function Auxiliary.NOT(f)
748ed664c0 2023-06-29  101: 	return	function(...)
748ed664c0 2023-06-29  102: 				return not f(...)
748ed664c0 2023-06-29  103: 			end
748ed664c0 2023-06-29  104: end
748ed664c0 2023-06-29  105: function Auxiliary.BeginPuzzle(effect)
748ed664c0 2023-06-29  106: 	local e1=Effect.GlobalEffect()
748ed664c0 2023-06-29  107: 	e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
748ed664c0 2023-06-29  108: 	e1:SetCode(EVENT_TURN_END)
748ed664c0 2023-06-29  109: 	e1:SetCountLimit(1)
748ed664c0 2023-06-29  110: 	e1:SetOperation(Auxiliary.PuzzleOp)
748ed664c0 2023-06-29  111: 	Duel.RegisterEffect(e1,0)
748ed664c0 2023-06-29  112: 	local e2=Effect.GlobalEffect()
748ed664c0 2023-06-29  113: 	e2:SetType(EFFECT_TYPE_FIELD)
748ed664c0 2023-06-29  114: 	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
748ed664c0 2023-06-29  115: 	e2:SetCode(EFFECT_SKIP_DP)
748ed664c0 2023-06-29  116: 	e2:SetTargetRange(1,0)
748ed664c0 2023-06-29  117: 	Duel.RegisterEffect(e2,0)
748ed664c0 2023-06-29  118: 	local e3=Effect.GlobalEffect()
748ed664c0 2023-06-29  119: 	e3:SetType(EFFECT_TYPE_FIELD)
748ed664c0 2023-06-29  120: 	e3:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
748ed664c0 2023-06-29  121: 	e3:SetCode(EFFECT_SKIP_SP)
748ed664c0 2023-06-29  122: 	e3:SetTargetRange(1,0)
748ed664c0 2023-06-29  123: 	Duel.RegisterEffect(e3,0)
748ed664c0 2023-06-29  124: end
748ed664c0 2023-06-29  125: function Auxiliary.PuzzleOp(e,tp)
748ed664c0 2023-06-29  126: 	Duel.SetLP(0,0)
748ed664c0 2023-06-29  127: end
748ed664c0 2023-06-29  128: --Duel.SelectOption with option condition
748ed664c0 2023-06-29  129: --Return value starts from 1, different from Duel.SelectOption
748ed664c0 2023-06-29  130: function Auxiliary.SelectFromOptions(tp,...)
748ed664c0 2023-06-29  131: 	local options={...}
748ed664c0 2023-06-29  132: 	local ops={}
748ed664c0 2023-06-29  133: 	local opvals={}
748ed664c0 2023-06-29  134: 	for i=1,#options do
748ed664c0 2023-06-29  135: 		if options[i][1] then
748ed664c0 2023-06-29  136: 			table.insert(ops,options[i][2])
748ed664c0 2023-06-29  137: 			table.insert(opvals,options[i][3] or i)
748ed664c0 2023-06-29  138: 		end
748ed664c0 2023-06-29  139: 	end
748ed664c0 2023-06-29  140: 	if #ops==0 then return nil end
748ed664c0 2023-06-29  141: 	local select=Duel.SelectOption(tp,table.unpack(ops))
748ed664c0 2023-06-29  142: 	return opvals[select+1]
748ed664c0 2023-06-29  143: end
748ed664c0 2023-06-29  144: function Auxiliary.IsDualState(effect)
748ed664c0 2023-06-29  145: 	local c=effect:GetHandler()
748ed664c0 2023-06-29  146: 	return not c:IsDisabled() and c:IsDualState()
748ed664c0 2023-06-29  147: end
748ed664c0 2023-06-29  148: function Auxiliary.IsNotDualState(effect)
748ed664c0 2023-06-29  149: 	local c=effect:GetHandler()
748ed664c0 2023-06-29  150: 	return c:IsDisabled() or not c:IsDualState()
748ed664c0 2023-06-29  151: end
748ed664c0 2023-06-29  152: function Auxiliary.DualNormalCondition(effect)
748ed664c0 2023-06-29  153: 	local c=effect:GetHandler()
748ed664c0 2023-06-29  154: 	return c:IsFaceup() and not c:IsDualState()
748ed664c0 2023-06-29  155: end
748ed664c0 2023-06-29  156: function Auxiliary.EnableDualAttribute(c)
748ed664c0 2023-06-29  157: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29  158: 	e1:SetType(EFFECT_TYPE_SINGLE)
748ed664c0 2023-06-29  159: 	e1:SetCode(EFFECT_DUAL_SUMMONABLE)
748ed664c0 2023-06-29  160: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29  161: 	local e2=Effect.CreateEffect(c)
748ed664c0 2023-06-29  162: 	e2:SetType(EFFECT_TYPE_SINGLE)
748ed664c0 2023-06-29  163: 	e2:SetCode(EFFECT_ADD_TYPE)
748ed664c0 2023-06-29  164: 	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE+EFFECT_FLAG_IGNORE_IMMUNE)
748ed664c0 2023-06-29  165: 	e2:SetRange(LOCATION_MZONE+LOCATION_GRAVE)
748ed664c0 2023-06-29  166: 	e2:SetCondition(aux.DualNormalCondition)
748ed664c0 2023-06-29  167: 	e2:SetValue(TYPE_NORMAL)
748ed664c0 2023-06-29  168: 	c:RegisterEffect(e2)
748ed664c0 2023-06-29  169: 	local e3=e2:Clone()
748ed664c0 2023-06-29  170: 	e3:SetCode(EFFECT_REMOVE_TYPE)
748ed664c0 2023-06-29  171: 	e3:SetValue(TYPE_EFFECT)
748ed664c0 2023-06-29  172: 	c:RegisterEffect(e3)
748ed664c0 2023-06-29  173: end
748ed664c0 2023-06-29  174: --register effect of return to hand for Spirit monsters
748ed664c0 2023-06-29  175: function Auxiliary.EnableSpiritReturn(c,event1,...)
748ed664c0 2023-06-29  176: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29  177: 	e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_CONTINUOUS)
748ed664c0 2023-06-29  178: 	e1:SetCode(event1)
748ed664c0 2023-06-29  179: 	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
748ed664c0 2023-06-29  180: 	e1:SetOperation(Auxiliary.SpiritReturnReg)
748ed664c0 2023-06-29  181: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29  182: 	for i,event in ipairs{...} do
748ed664c0 2023-06-29  183: 		local e2=e1:Clone()
748ed664c0 2023-06-29  184: 		e2:SetCode(event)
748ed664c0 2023-06-29  185: 		c:RegisterEffect(e2)
748ed664c0 2023-06-29  186: 	end
748ed664c0 2023-06-29  187: end
748ed664c0 2023-06-29  188: function Auxiliary.SpiritReturnReg(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29  189: 	local c=e:GetHandler()
748ed664c0 2023-06-29  190: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29  191: 	e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_F)
748ed664c0 2023-06-29  192: 	e1:SetDescription(1104)
748ed664c0 2023-06-29  193: 	e1:SetCategory(CATEGORY_TOHAND)
748ed664c0 2023-06-29  194: 	e1:SetCode(EVENT_PHASE+PHASE_END)
748ed664c0 2023-06-29  195: 	e1:SetRange(LOCATION_MZONE)
748ed664c0 2023-06-29  196: 	e1:SetCountLimit(1)
748ed664c0 2023-06-29  197: 	e1:SetReset(RESET_EVENT+0xd6e0000+RESET_PHASE+PHASE_END)
748ed664c0 2023-06-29  198: 	e1:SetCondition(Auxiliary.SpiritReturnConditionForced)
748ed664c0 2023-06-29  199: 	e1:SetTarget(Auxiliary.SpiritReturnTargetForced)
748ed664c0 2023-06-29  200: 	e1:SetOperation(Auxiliary.SpiritReturnOperation)
748ed664c0 2023-06-29  201: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29  202: 	local e2=e1:Clone()
748ed664c0 2023-06-29  203: 	e2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_O)
748ed664c0 2023-06-29  204: 	e2:SetCondition(Auxiliary.SpiritReturnConditionOptional)
748ed664c0 2023-06-29  205: 	e2:SetTarget(Auxiliary.SpiritReturnTargetOptional)
748ed664c0 2023-06-29  206: 	c:RegisterEffect(e2)
748ed664c0 2023-06-29  207: end
748ed664c0 2023-06-29  208: function Auxiliary.SpiritReturnConditionForced(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29  209: 	local c=e:GetHandler()
748ed664c0 2023-06-29  210: 	return not c:IsHasEffect(EFFECT_SPIRIT_DONOT_RETURN) and not c:IsHasEffect(EFFECT_SPIRIT_MAYNOT_RETURN)
748ed664c0 2023-06-29  211: end
748ed664c0 2023-06-29  212: function Auxiliary.SpiritReturnTargetForced(e,tp,eg,ep,ev,re,r,rp,chk)
748ed664c0 2023-06-29  213: 	if chk==0 then return true end
748ed664c0 2023-06-29  214: 	Duel.SetOperationInfo(0,CATEGORY_TOHAND,e:GetHandler(),1,0,0)
748ed664c0 2023-06-29  215: end
748ed664c0 2023-06-29  216: function Auxiliary.SpiritReturnConditionOptional(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29  217: 	local c=e:GetHandler()
748ed664c0 2023-06-29  218: 	return not c:IsHasEffect(EFFECT_SPIRIT_DONOT_RETURN) and c:IsHasEffect(EFFECT_SPIRIT_MAYNOT_RETURN)
748ed664c0 2023-06-29  219: end
748ed664c0 2023-06-29  220: function Auxiliary.SpiritReturnTargetOptional(e,tp,eg,ep,ev,re,r,rp,chk)
748ed664c0 2023-06-29  221: 	if chk==0 then return e:GetHandler():IsAbleToHand() end
748ed664c0 2023-06-29  222: 	Duel.SetOperationInfo(0,CATEGORY_TOHAND,e:GetHandler(),1,0,0)
748ed664c0 2023-06-29  223: end
748ed664c0 2023-06-29  224: function Auxiliary.SpiritReturnOperation(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29  225: 	local c=e:GetHandler()
748ed664c0 2023-06-29  226: 	if c:IsRelateToEffect(e) then
748ed664c0 2023-06-29  227: 		Duel.SendtoHand(c,nil,REASON_EFFECT)
748ed664c0 2023-06-29  228: 	end
748ed664c0 2023-06-29  229: end
748ed664c0 2023-06-29  230: function Auxiliary.EnableNeosReturn(c,operation,set_category)
748ed664c0 2023-06-29  231: 	--return
748ed664c0 2023-06-29  232: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29  233: 	e1:SetDescription(1193)
748ed664c0 2023-06-29  234: 	e1:SetCategory(CATEGORY_TODECK)
748ed664c0 2023-06-29  235: 	e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_F)
748ed664c0 2023-06-29  236: 	e1:SetCode(EVENT_PHASE+PHASE_END)
748ed664c0 2023-06-29  237: 	e1:SetRange(LOCATION_MZONE)
748ed664c0 2023-06-29  238: 	e1:SetCountLimit(1)
748ed664c0 2023-06-29  239: 	e1:SetCondition(Auxiliary.NeosReturnConditionForced)
748ed664c0 2023-06-29  240: 	e1:SetTarget(Auxiliary.NeosReturnTargetForced(set_category))
748ed664c0 2023-06-29  241: 	e1:SetOperation(operation)
748ed664c0 2023-06-29  242: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29  243: 	local e2=e1:Clone()
748ed664c0 2023-06-29  244: 	e2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_O)
748ed664c0 2023-06-29  245: 	e2:SetCondition(Auxiliary.NeosReturnConditionOptional)
748ed664c0 2023-06-29  246: 	e2:SetTarget(Auxiliary.NeosReturnTargetOptional(set_category))
748ed664c0 2023-06-29  247: 	c:RegisterEffect(e2)
748ed664c0 2023-06-29  248: 	return e1,e2
748ed664c0 2023-06-29  249: end
748ed664c0 2023-06-29  250: function Auxiliary.NeosReturnConditionForced(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29  251: 	return not e:GetHandler():IsHasEffect(42015635)
748ed664c0 2023-06-29  252: end
748ed664c0 2023-06-29  253: function Auxiliary.NeosReturnTargetForced(set_category)
748ed664c0 2023-06-29  254: 	return	function(e,tp,eg,ep,ev,re,r,rp,chk)
748ed664c0 2023-06-29  255: 				if chk==0 then return true end
748ed664c0 2023-06-29  256: 				Duel.SetOperationInfo(0,CATEGORY_TODECK,e:GetHandler(),1,0,0)
748ed664c0 2023-06-29  257: 				if set_category then set_category(e,tp,eg,ep,ev,re,r,rp) end
748ed664c0 2023-06-29  258: 			end
748ed664c0 2023-06-29  259: end
748ed664c0 2023-06-29  260: function Auxiliary.NeosReturnConditionOptional(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29  261: 	return e:GetHandler():IsHasEffect(42015635)
748ed664c0 2023-06-29  262: end
748ed664c0 2023-06-29  263: function Auxiliary.NeosReturnTargetOptional(set_category)
748ed664c0 2023-06-29  264: 	return	function(e,tp,eg,ep,ev,re,r,rp,chk)
748ed664c0 2023-06-29  265: 				if chk==0 then return e:GetHandler():IsAbleToExtra() end
748ed664c0 2023-06-29  266: 				Duel.SetOperationInfo(0,CATEGORY_TODECK,e:GetHandler(),1,0,0)
748ed664c0 2023-06-29  267: 				if set_category then set_category(e,tp,eg,ep,ev,re,r,rp) end
748ed664c0 2023-06-29  268: 			end
748ed664c0 2023-06-29  269: end
748ed664c0 2023-06-29  270: function Auxiliary.IsUnionState(effect)
748ed664c0 2023-06-29  271: 	local c=effect:GetHandler()
748ed664c0 2023-06-29  272: 	return c:IsHasEffect(EFFECT_UNION_STATUS) and c:GetEquipTarget()
748ed664c0 2023-06-29  273: end
748ed664c0 2023-06-29  274: --set EFFECT_EQUIP_LIMIT after equipping
748ed664c0 2023-06-29  275: function Auxiliary.SetUnionState(c)
748ed664c0 2023-06-29  276: 	local eset={c:IsHasEffect(EFFECT_UNION_LIMIT)}
748ed664c0 2023-06-29  277: 	if #eset==0 then return end
748ed664c0 2023-06-29  278: 	local e0=Effect.CreateEffect(c)
748ed664c0 2023-06-29  279: 	e0:SetType(EFFECT_TYPE_SINGLE)
748ed664c0 2023-06-29  280: 	e0:SetCode(EFFECT_EQUIP_LIMIT)
748ed664c0 2023-06-29  281: 	e0:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
748ed664c0 2023-06-29  282: 	e0:SetValue(eset[1]:GetValue())
748ed664c0 2023-06-29  283: 	e0:SetReset(RESET_EVENT+RESETS_STANDARD)
748ed664c0 2023-06-29  284: 	c:RegisterEffect(e0)
748ed664c0 2023-06-29  285: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29  286: 	e1:SetType(EFFECT_TYPE_SINGLE)
748ed664c0 2023-06-29  287: 	e1:SetCode(EFFECT_UNION_STATUS)
748ed664c0 2023-06-29  288: 	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
748ed664c0 2023-06-29  289: 	e1:SetReset(RESET_EVENT+RESETS_STANDARD)
748ed664c0 2023-06-29  290: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29  291: 	if c.old_union then
748ed664c0 2023-06-29  292: 		local e2=e1:Clone()
748ed664c0 2023-06-29  293: 		e2:SetCode(EFFECT_OLDUNION_STATUS)
748ed664c0 2023-06-29  294: 		c:RegisterEffect(e2)
748ed664c0 2023-06-29  295: 	end
748ed664c0 2023-06-29  296: end
748ed664c0 2023-06-29  297: --uc: the union monster to be equipped, tc: the target monster
748ed664c0 2023-06-29  298: function Auxiliary.CheckUnionEquip(uc,tc,exclude_modern_count)
748ed664c0 2023-06-29  299: 	local modern_count,old_count=tc:GetUnionCount()
748ed664c0 2023-06-29  300: 	if exclude_modern_count then modern_count=modern_count-exclude_modern_count end
748ed664c0 2023-06-29  301: 	if uc.old_union then return modern_count==0
748ed664c0 2023-06-29  302: 	else return old_count==0 end
748ed664c0 2023-06-29  303: end
748ed664c0 2023-06-29  304: --EFFECT_DESTROY_SUBSTITUTE filter for modern union monsters
748ed664c0 2023-06-29  305: function Auxiliary.UnionReplaceFilter(e,re,r,rp)
748ed664c0 2023-06-29  306: 	return r&(REASON_BATTLE+REASON_EFFECT)~=0
748ed664c0 2023-06-29  307: end
748ed664c0 2023-06-29  308: --add effect to modern union monsters
748ed664c0 2023-06-29  309: function Auxiliary.EnableUnionAttribute(c,f)
748ed664c0 2023-06-29  310: 	--destroy sub
748ed664c0 2023-06-29  311: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29  312: 	e1:SetType(EFFECT_TYPE_EQUIP)
748ed664c0 2023-06-29  313: 	e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
748ed664c0 2023-06-29  314: 	e1:SetCode(EFFECT_DESTROY_SUBSTITUTE)
748ed664c0 2023-06-29  315: 	e1:SetValue(aux.UnionReplaceFilter)
748ed664c0 2023-06-29  316: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29  317: 	--limit
748ed664c0 2023-06-29  318: 	local e2=Effect.CreateEffect(c)
748ed664c0 2023-06-29  319: 	e2:SetType(EFFECT_TYPE_SINGLE)
748ed664c0 2023-06-29  320: 	e2:SetCode(EFFECT_UNION_LIMIT)
748ed664c0 2023-06-29  321: 	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
748ed664c0 2023-06-29  322: 	e2:SetValue(f)
748ed664c0 2023-06-29  323: 	c:RegisterEffect(e2)
748ed664c0 2023-06-29  324: end
748ed664c0 2023-06-29  325: function Auxiliary.EnableChangeCode(c,code,location,condition)
748ed664c0 2023-06-29  326: 	Auxiliary.AddCodeList(c,code)
748ed664c0 2023-06-29  327: 	local loc=c:GetOriginalType()&TYPE_MONSTER~=0 and LOCATION_MZONE or LOCATION_SZONE
748ed664c0 2023-06-29  328: 	loc=location or loc
748ed664c0 2023-06-29  329: 	if condition==nil then condition=Auxiliary.TRUE end
748ed664c0 2023-06-29  330: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29  331: 	e1:SetType(EFFECT_TYPE_SINGLE)
748ed664c0 2023-06-29  332: 	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
748ed664c0 2023-06-29  333: 	e1:SetCode(EFFECT_CHANGE_CODE)
748ed664c0 2023-06-29  334: 	e1:SetRange(loc)
748ed664c0 2023-06-29  335: 	e1:SetCondition(condition)
748ed664c0 2023-06-29  336: 	e1:SetValue(code)
748ed664c0 2023-06-29  337: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29  338: 	return e1
748ed664c0 2023-06-29  339: end
748ed664c0 2023-06-29  340: function Auxiliary.TargetEqualFunction(f,value,...)
748ed664c0 2023-06-29  341: 	local ext_params={...}
748ed664c0 2023-06-29  342: 	return	function(effect,target)
748ed664c0 2023-06-29  343: 				return f(target,table.unpack(ext_params))==value
748ed664c0 2023-06-29  344: 			end
748ed664c0 2023-06-29  345: end
748ed664c0 2023-06-29  346: function Auxiliary.TargetBoolFunction(f,...)
748ed664c0 2023-06-29  347: 	local ext_params={...}
748ed664c0 2023-06-29  348: 	return	function(effect,target)
748ed664c0 2023-06-29  349: 				return f(target,table.unpack(ext_params))
748ed664c0 2023-06-29  350: 			end
748ed664c0 2023-06-29  351: end
748ed664c0 2023-06-29  352: function Auxiliary.FilterEqualFunction(f,value,...)
748ed664c0 2023-06-29  353: 	local ext_params={...}
748ed664c0 2023-06-29  354: 	return	function(target)
748ed664c0 2023-06-29  355: 				return f(target,table.unpack(ext_params))==value
748ed664c0 2023-06-29  356: 			end
748ed664c0 2023-06-29  357: end
748ed664c0 2023-06-29  358: function Auxiliary.FilterBoolFunction(f,...)
748ed664c0 2023-06-29  359: 	local ext_params={...}
748ed664c0 2023-06-29  360: 	return	function(target)
748ed664c0 2023-06-29  361: 				return f(target,table.unpack(ext_params))
748ed664c0 2023-06-29  362: 			end
748ed664c0 2023-06-29  363: end
748ed664c0 2023-06-29  364: function Auxiliary.Tuner(f,...)
748ed664c0 2023-06-29  365: 	local ext_params={...}
748ed664c0 2023-06-29  366: 	return	function(target,syncard)
748ed664c0 2023-06-29  367: 				return target:IsTuner(syncard) and (not f or f(target,table.unpack(ext_params)))
748ed664c0 2023-06-29  368: 			end
748ed664c0 2023-06-29  369: end
748ed664c0 2023-06-29  370: function Auxiliary.NonTuner(f,...)
748ed664c0 2023-06-29  371: 	local ext_params={...}
748ed664c0 2023-06-29  372: 	return	function(target,syncard)
748ed664c0 2023-06-29  373: 				return target:IsNotTuner(syncard) and (not f or f(target,table.unpack(ext_params)))
748ed664c0 2023-06-29  374: 			end
748ed664c0 2023-06-29  375: end
748ed664c0 2023-06-29  376: function Auxiliary.GetValueType(v)
748ed664c0 2023-06-29  377: 	local t=type(v)
748ed664c0 2023-06-29  378: 	if t=="userdata" then
748ed664c0 2023-06-29  379: 		local mt=getmetatable(v)
748ed664c0 2023-06-29  380: 		if mt==Group then return "Group"
748ed664c0 2023-06-29  381: 		elseif mt==Effect then return "Effect"
748ed664c0 2023-06-29  382: 		else return "Card" end
748ed664c0 2023-06-29  383: 	else return t end
748ed664c0 2023-06-29  384: end
748ed664c0 2023-06-29  385: function Auxiliary.MustMaterialCheck(v,tp,code)
748ed664c0 2023-06-29  386: 	local g=Duel.GetMustMaterial(tp,code)
748ed664c0 2023-06-29  387: 	if not v then
748ed664c0 2023-06-29  388: 		if code==EFFECT_MUST_BE_XMATERIAL and Duel.IsPlayerAffectedByEffect(tp,67120578) then return false end
748ed664c0 2023-06-29  389: 		return #g==0
748ed664c0 2023-06-29  390: 	end
748ed664c0 2023-06-29  391: 	return Duel.CheckMustMaterial(tp,v,code)
748ed664c0 2023-06-29  392: end
748ed664c0 2023-06-29  393: function Auxiliary.MustMaterialCounterFilter(c,g)
748ed664c0 2023-06-29  394: 	return not g:IsContains(c)
748ed664c0 2023-06-29  395: end
748ed664c0 2023-06-29  396: --Synchro monster, 1 tuner + min to max monsters
748ed664c0 2023-06-29  397: function Auxiliary.AddSynchroProcedure(c,f1,f2,minc,maxc)
748ed664c0 2023-06-29  398: 	if maxc==nil then maxc=99 end
748ed664c0 2023-06-29  399: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29  400: 	e1:SetDescription(1164)
748ed664c0 2023-06-29  401: 	e1:SetType(EFFECT_TYPE_FIELD)
748ed664c0 2023-06-29  402: 	e1:SetCode(EFFECT_SPSUMMON_PROC)
748ed664c0 2023-06-29  403: 	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
748ed664c0 2023-06-29  404: 	e1:SetRange(LOCATION_EXTRA)
748ed664c0 2023-06-29  405: 	e1:SetCondition(Auxiliary.SynCondition(f1,f2,minc,maxc))
748ed664c0 2023-06-29  406: 	e1:SetTarget(Auxiliary.SynTarget(f1,f2,minc,maxc))
748ed664c0 2023-06-29  407: 	e1:SetOperation(Auxiliary.SynOperation(f1,f2,minc,maxc))
748ed664c0 2023-06-29  408: 	e1:SetValue(SUMMON_TYPE_SYNCHRO)
748ed664c0 2023-06-29  409: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29  410: end
748ed664c0 2023-06-29  411: function Auxiliary.SynCondition(f1,f2,minc,maxc)
748ed664c0 2023-06-29  412: 	return	function(e,c,smat,mg,min,max)
748ed664c0 2023-06-29  413: 				if c==nil then return true end
748ed664c0 2023-06-29  414: 				if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end
748ed664c0 2023-06-29  415: 				local minc=minc
748ed664c0 2023-06-29  416: 				local maxc=maxc
748ed664c0 2023-06-29  417: 				if min then
748ed664c0 2023-06-29  418: 					if min>minc then minc=min end
748ed664c0 2023-06-29  419: 					if max<maxc then maxc=max end
748ed664c0 2023-06-29  420: 					if minc>maxc then return false end
748ed664c0 2023-06-29  421: 				end
748ed664c0 2023-06-29  422: 				if smat and smat:IsTuner(c) and (not f1 or f1(smat)) then
748ed664c0 2023-06-29  423: 					return Duel.CheckTunerMaterial(c,smat,f1,f2,minc,maxc,mg) end
748ed664c0 2023-06-29  424: 				return Duel.CheckSynchroMaterial(c,f1,f2,minc,maxc,smat,mg)
748ed664c0 2023-06-29  425: 			end
748ed664c0 2023-06-29  426: end
748ed664c0 2023-06-29  427: function Auxiliary.SynTarget(f1,f2,minc,maxc)
748ed664c0 2023-06-29  428: 	return	function(e,tp,eg,ep,ev,re,r,rp,chk,c,smat,mg,min,max)
748ed664c0 2023-06-29  429: 				local minc=minc
748ed664c0 2023-06-29  430: 				local maxc=maxc
748ed664c0 2023-06-29  431: 				if min then
748ed664c0 2023-06-29  432: 					if min>minc then minc=min end
748ed664c0 2023-06-29  433: 					if max<maxc then maxc=max end
748ed664c0 2023-06-29  434: 					if minc>maxc then return false end
748ed664c0 2023-06-29  435: 				end
748ed664c0 2023-06-29  436: 				local g=nil
748ed664c0 2023-06-29  437: 				if smat and smat:IsTuner(c) and (not f1 or f1(smat)) then
748ed664c0 2023-06-29  438: 					g=Duel.SelectTunerMaterial(c:GetControler(),c,smat,f1,f2,minc,maxc,mg)
748ed664c0 2023-06-29  439: 				else
748ed664c0 2023-06-29  440: 					g=Duel.SelectSynchroMaterial(c:GetControler(),c,f1,f2,minc,maxc,smat,mg)
748ed664c0 2023-06-29  441: 				end
748ed664c0 2023-06-29  442: 				if g then
748ed664c0 2023-06-29  443: 					g:KeepAlive()
748ed664c0 2023-06-29  444: 					e:SetLabelObject(g)
748ed664c0 2023-06-29  445: 					return true
748ed664c0 2023-06-29  446: 				else return false end
748ed664c0 2023-06-29  447: 			end
748ed664c0 2023-06-29  448: end
748ed664c0 2023-06-29  449: function Auxiliary.SynOperation(f1,f2,minct,maxc)
748ed664c0 2023-06-29  450: 	return	function(e,tp,eg,ep,ev,re,r,rp,c,smat,mg,min,max)
748ed664c0 2023-06-29  451: 				local g=e:GetLabelObject()
748ed664c0 2023-06-29  452: 				c:SetMaterial(g)
748ed664c0 2023-06-29  453: 				Duel.SendtoGrave(g,REASON_MATERIAL+REASON_SYNCHRO)
748ed664c0 2023-06-29  454: 				g:DeleteGroup()
748ed664c0 2023-06-29  455: 			end
748ed664c0 2023-06-29  456: end
748ed664c0 2023-06-29  457: --Synchro monster, 1 tuner + 1 monster
748ed664c0 2023-06-29  458: --backward compatibility
748ed664c0 2023-06-29  459: function Auxiliary.AddSynchroProcedure2(c,f1,f2)
748ed664c0 2023-06-29  460: 	Auxiliary.AddSynchroProcedure(c,f1,f2,1,1)
748ed664c0 2023-06-29  461: end
748ed664c0 2023-06-29  462: --Synchro monster, f1~f3 each 1 MONSTER + f4 min to max monsters
748ed664c0 2023-06-29  463: function Auxiliary.AddSynchroMixProcedure(c,f1,f2,f3,f4,minc,maxc,gc)
748ed664c0 2023-06-29  464: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29  465: 	e1:SetDescription(1164)
748ed664c0 2023-06-29  466: 	e1:SetType(EFFECT_TYPE_FIELD)
748ed664c0 2023-06-29  467: 	e1:SetCode(EFFECT_SPSUMMON_PROC)
748ed664c0 2023-06-29  468: 	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
748ed664c0 2023-06-29  469: 	e1:SetRange(LOCATION_EXTRA)
748ed664c0 2023-06-29  470: 	e1:SetCondition(Auxiliary.SynMixCondition(f1,f2,f3,f4,minc,maxc,gc))
748ed664c0 2023-06-29  471: 	e1:SetTarget(Auxiliary.SynMixTarget(f1,f2,f3,f4,minc,maxc,gc))
748ed664c0 2023-06-29  472: 	e1:SetOperation(Auxiliary.SynMixOperation(f1,f2,f3,f4,minc,maxc,gc))
748ed664c0 2023-06-29  473: 	e1:SetValue(SUMMON_TYPE_SYNCHRO)
748ed664c0 2023-06-29  474: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29  475: end
748ed664c0 2023-06-29  476: function Auxiliary.SynMaterialFilter(c,syncard)
748ed664c0 2023-06-29  477: 	return c:IsFaceupEx() and c:IsCanBeSynchroMaterial(syncard)
748ed664c0 2023-06-29  478: end
748ed664c0 2023-06-29  479: function Auxiliary.SynLimitFilter(c,f,e,syncard)
748ed664c0 2023-06-29  480: 	return f and not f(e,c,syncard)
748ed664c0 2023-06-29  481: end
748ed664c0 2023-06-29  482: function Auxiliary.GetSynchroLevelFlowerCardian(c)
748ed664c0 2023-06-29  483: 	return 2
748ed664c0 2023-06-29  484: end
748ed664c0 2023-06-29  485: function Auxiliary.GetSynMaterials(tp,syncard)
748ed664c0 2023-06-29  486: 	local mg=Duel.GetSynchroMaterial(tp):Filter(Auxiliary.SynMaterialFilter,nil,syncard)
748ed664c0 2023-06-29  487: 	if mg:IsExists(Card.GetHandSynchro,1,nil) then
748ed664c0 2023-06-29  488: 		local mg2=Duel.GetMatchingGroup(Card.IsCanBeSynchroMaterial,tp,LOCATION_HAND,0,nil,syncard)
748ed664c0 2023-06-29  489: 		if mg2:GetCount()>0 then mg:Merge(mg2) end
748ed664c0 2023-06-29  490: 	end
748ed664c0 2023-06-29  491: 	return mg
748ed664c0 2023-06-29  492: end
748ed664c0 2023-06-29  493: function Auxiliary.SynMixCondition(f1,f2,f3,f4,minc,maxc,gc)
748ed664c0 2023-06-29  494: 	return	function(e,c,smat,mg1,min,max)
748ed664c0 2023-06-29  495: 				if c==nil then return true end
748ed664c0 2023-06-29  496: 				if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end
748ed664c0 2023-06-29  497: 				local minc=minc
748ed664c0 2023-06-29  498: 				local maxc=maxc
748ed664c0 2023-06-29  499: 				if min then
748ed664c0 2023-06-29  500: 					if min>minc then minc=min end
748ed664c0 2023-06-29  501: 					if max<maxc then maxc=max end
748ed664c0 2023-06-29  502: 					if minc>maxc then return false end
748ed664c0 2023-06-29  503: 				end
748ed664c0 2023-06-29  504: 				if smat and not smat:IsCanBeSynchroMaterial(c) then return false end
748ed664c0 2023-06-29  505: 				local tp=c:GetControler()
748ed664c0 2023-06-29  506: 				local mg
748ed664c0 2023-06-29  507: 				local mgchk=false
748ed664c0 2023-06-29  508: 				if mg1 then
748ed664c0 2023-06-29  509: 					mg=mg1
748ed664c0 2023-06-29  510: 					mgchk=true
748ed664c0 2023-06-29  511: 				else
748ed664c0 2023-06-29  512: 					mg=Auxiliary.GetSynMaterials(tp,c)
748ed664c0 2023-06-29  513: 				end
748ed664c0 2023-06-29  514: 				if smat~=nil then mg:AddCard(smat) end
748ed664c0 2023-06-29  515: 				return mg:IsExists(Auxiliary.SynMixFilter1,1,nil,f1,f2,f3,f4,minc,maxc,c,mg,smat,gc,mgchk)
748ed664c0 2023-06-29  516: 			end
748ed664c0 2023-06-29  517: end
748ed664c0 2023-06-29  518: function Auxiliary.SynMixTarget(f1,f2,f3,f4,minc,maxc,gc)
748ed664c0 2023-06-29  519: 	return	function(e,tp,eg,ep,ev,re,r,rp,chk,c,smat,mg1,min,max)
748ed664c0 2023-06-29  520: 				local minc=minc
748ed664c0 2023-06-29  521: 				local maxc=maxc
748ed664c0 2023-06-29  522: 				if min then
748ed664c0 2023-06-29  523: 					if min>minc then minc=min end
748ed664c0 2023-06-29  524: 					if max<maxc then maxc=max end
748ed664c0 2023-06-29  525: 					if minc>maxc then return false end
748ed664c0 2023-06-29  526: 				end
748ed664c0 2023-06-29  527: 				::SynMixTargetSelectStart::
748ed664c0 2023-06-29  528: 				local g=Group.CreateGroup()
748ed664c0 2023-06-29  529: 				local mg
748ed664c0 2023-06-29  530: 				local mgchk=false
748ed664c0 2023-06-29  531: 				if mg1 then
748ed664c0 2023-06-29  532: 					mg=mg1
748ed664c0 2023-06-29  533: 					mgchk=true
748ed664c0 2023-06-29  534: 				else
748ed664c0 2023-06-29  535: 					mg=Auxiliary.GetSynMaterials(tp,c)
748ed664c0 2023-06-29  536: 				end
748ed664c0 2023-06-29  537: 				if smat~=nil then mg:AddCard(smat) end
748ed664c0 2023-06-29  538: 				local c1
748ed664c0 2023-06-29  539: 				local c2
748ed664c0 2023-06-29  540: 				local c3
748ed664c0 2023-06-29  541: 				local cancel=Duel.IsSummonCancelable()
748ed664c0 2023-06-29  542: 				Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SMATERIAL)
748ed664c0 2023-06-29  543: 				c1=mg:Filter(Auxiliary.SynMixFilter1,nil,f1,f2,f3,f4,minc,maxc,c,mg,smat,gc,mgchk):SelectUnselect(g,tp,false,cancel,1,1)
748ed664c0 2023-06-29  544: 				if not c1 then return false end
748ed664c0 2023-06-29  545: 				g:AddCard(c1)
748ed664c0 2023-06-29  546: 				if f2 then
748ed664c0 2023-06-29  547: 					Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SMATERIAL)
748ed664c0 2023-06-29  548: 					c2=mg:Filter(Auxiliary.SynMixFilter2,g,f2,f3,f4,minc,maxc,c,mg,smat,c1,gc,mgchk):SelectUnselect(g,tp,false,cancel,1,1)
748ed664c0 2023-06-29  549: 					if not c2 then return false end
748ed664c0 2023-06-29  550: 					if g:IsContains(c2) then goto SynMixTargetSelectStart end
748ed664c0 2023-06-29  551: 					g:AddCard(c2)
748ed664c0 2023-06-29  552: 					if f3 then
748ed664c0 2023-06-29  553: 						Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SMATERIAL)
748ed664c0 2023-06-29  554: 						c3=mg:Filter(Auxiliary.SynMixFilter3,g,f3,f4,minc,maxc,c,mg,smat,c1,c2,gc,mgchk):SelectUnselect(g,tp,false,cancel,1,1)
748ed664c0 2023-06-29  555: 						if not c3 then return false end
748ed664c0 2023-06-29  556: 						if g:IsContains(c3) then goto SynMixTargetSelectStart end
748ed664c0 2023-06-29  557: 						g:AddCard(c3)
748ed664c0 2023-06-29  558: 					end
748ed664c0 2023-06-29  559: 				end
748ed664c0 2023-06-29  560: 				local g4=Group.CreateGroup()
748ed664c0 2023-06-29  561: 				for i=0,maxc-1 do
748ed664c0 2023-06-29  562: 					local mg2=mg:Clone()
748ed664c0 2023-06-29  563: 					if f4 then
748ed664c0 2023-06-29  564: 						mg2=mg2:Filter(f4,g,c,c1,c2,c3)
748ed664c0 2023-06-29  565: 					else
748ed664c0 2023-06-29  566: 						mg2:Sub(g)
748ed664c0 2023-06-29  567: 					end
748ed664c0 2023-06-29  568: 					local cg=mg2:Filter(Auxiliary.SynMixCheckRecursive,g4,tp,g4,mg2,i,minc,maxc,c,g,smat,gc,mgchk)
748ed664c0 2023-06-29  569: 					if cg:GetCount()==0 then break end
748ed664c0 2023-06-29  570: 					local finish=Auxiliary.SynMixCheckGoal(tp,g4,minc,i,c,g,smat,gc,mgchk)
748ed664c0 2023-06-29  571: 					Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SMATERIAL)
748ed664c0 2023-06-29  572: 					local c4=cg:SelectUnselect(g+g4,tp,finish,cancel,minc,maxc)
748ed664c0 2023-06-29  573: 					if not c4 then
748ed664c0 2023-06-29  574: 						if finish then break
748ed664c0 2023-06-29  575: 						else return false end
748ed664c0 2023-06-29  576: 					end
748ed664c0 2023-06-29  577: 					if g:IsContains(c4) or g4:IsContains(c4) then goto SynMixTargetSelectStart end
748ed664c0 2023-06-29  578: 					g4:AddCard(c4)
748ed664c0 2023-06-29  579: 				end
748ed664c0 2023-06-29  580: 				g:Merge(g4)
748ed664c0 2023-06-29  581: 				if g:GetCount()>0 then
748ed664c0 2023-06-29  582: 					g:KeepAlive()
748ed664c0 2023-06-29  583: 					e:SetLabelObject(g)
748ed664c0 2023-06-29  584: 					return true
748ed664c0 2023-06-29  585: 				else return false end
748ed664c0 2023-06-29  586: 			end
748ed664c0 2023-06-29  587: end
748ed664c0 2023-06-29  588: function Auxiliary.SynMixOperation(f1,f2,f3,f4,minct,maxc,gc)
748ed664c0 2023-06-29  589: 	return	function(e,tp,eg,ep,ev,re,r,rp,c,smat,mg,min,max)
748ed664c0 2023-06-29  590: 				local g=e:GetLabelObject()
748ed664c0 2023-06-29  591: 				c:SetMaterial(g)
748ed664c0 2023-06-29  592: 				Duel.SendtoGrave(g,REASON_MATERIAL+REASON_SYNCHRO)
748ed664c0 2023-06-29  593: 				g:DeleteGroup()
748ed664c0 2023-06-29  594: 			end
748ed664c0 2023-06-29  595: end
748ed664c0 2023-06-29  596: function Auxiliary.SynMixFilter1(c,f1,f2,f3,f4,minc,maxc,syncard,mg,smat,gc,mgchk)
748ed664c0 2023-06-29  597: 	return (not f1 or f1(c,syncard)) and mg:IsExists(Auxiliary.SynMixFilter2,1,c,f2,f3,f4,minc,maxc,syncard,mg,smat,c,gc,mgchk)
748ed664c0 2023-06-29  598: end
748ed664c0 2023-06-29  599: function Auxiliary.SynMixFilter2(c,f2,f3,f4,minc,maxc,syncard,mg,smat,c1,gc,mgchk)
748ed664c0 2023-06-29  600: 	if f2 then
748ed664c0 2023-06-29  601: 		return f2(c,syncard,c1)
748ed664c0 2023-06-29  602: 			and (mg:IsExists(Auxiliary.SynMixFilter3,1,Group.FromCards(c1,c),f3,f4,minc,maxc,syncard,mg,smat,c1,c,gc,mgchk)
748ed664c0 2023-06-29  603: 				or minc==0 and Auxiliary.SynMixFilter4(c,nil,1,1,syncard,mg,smat,c1,nil,nil,gc,mgchk))
748ed664c0 2023-06-29  604: 	else
748ed664c0 2023-06-29  605: 		return mg:IsExists(Auxiliary.SynMixFilter4,1,c1,f4,minc,maxc,syncard,mg,smat,c1,nil,nil,gc,mgchk)
748ed664c0 2023-06-29  606: 	end
748ed664c0 2023-06-29  607: end
748ed664c0 2023-06-29  608: function Auxiliary.SynMixFilter3(c,f3,f4,minc,maxc,syncard,mg,smat,c1,c2,gc,mgchk)
748ed664c0 2023-06-29  609: 	if f3 then
748ed664c0 2023-06-29  610: 		return f3(c,syncard,c1,c2)
748ed664c0 2023-06-29  611: 			and (mg:IsExists(Auxiliary.SynMixFilter4,1,Group.FromCards(c1,c2,c),f4,minc,maxc,syncard,mg,smat,c1,c2,c,gc,mgchk)
748ed664c0 2023-06-29  612: 				or minc==0 and Auxiliary.SynMixFilter4(c,nil,1,1,syncard,mg,smat,c1,c2,nil,gc,mgchk))
748ed664c0 2023-06-29  613: 	else
748ed664c0 2023-06-29  614: 		return mg:IsExists(Auxiliary.SynMixFilter4,1,Group.FromCards(c1,c2),f4,minc,maxc,syncard,mg,smat,c1,c2,nil,gc,mgchk)
748ed664c0 2023-06-29  615: 	end
748ed664c0 2023-06-29  616: end
748ed664c0 2023-06-29  617: function Auxiliary.SynMixFilter4(c,f4,minc,maxc,syncard,mg1,smat,c1,c2,c3,gc,mgchk)
748ed664c0 2023-06-29  618: 	if f4 and not f4(c,syncard,c1,c2,c3) then return false end
748ed664c0 2023-06-29  619: 	local sg=Group.FromCards(c1,c)
748ed664c0 2023-06-29  620: 	sg:AddCard(c1)
748ed664c0 2023-06-29  621: 	if c2 then sg:AddCard(c2) end
748ed664c0 2023-06-29  622: 	if c3 then sg:AddCard(c3) end
748ed664c0 2023-06-29  623: 	local mg=mg1:Clone()
748ed664c0 2023-06-29  624: 	if f4 then
748ed664c0 2023-06-29  625: 		mg=mg:Filter(f4,sg,syncard,c1,c2,c3)
748ed664c0 2023-06-29  626: 	else
748ed664c0 2023-06-29  627: 		mg:Sub(sg)
748ed664c0 2023-06-29  628: 	end
748ed664c0 2023-06-29  629: 	return Auxiliary.SynMixCheck(mg,sg,minc-1,maxc-1,syncard,smat,gc,mgchk)
748ed664c0 2023-06-29  630: end
748ed664c0 2023-06-29  631: function Auxiliary.SynMixCheck(mg,sg1,minc,maxc,syncard,smat,gc,mgchk)
748ed664c0 2023-06-29  632: 	local tp=syncard:GetControler()
748ed664c0 2023-06-29  633: 	local sg=Group.CreateGroup()
748ed664c0 2023-06-29  634: 	if minc<=0 and Auxiliary.SynMixCheckGoal(tp,sg1,0,0,syncard,sg,smat,gc,mgchk) then return true end
748ed664c0 2023-06-29  635: 	if maxc==0 then return false end
748ed664c0 2023-06-29  636: 	return mg:IsExists(Auxiliary.SynMixCheckRecursive,1,nil,tp,sg,mg,0,minc,maxc,syncard,sg1,smat,gc,mgchk)
748ed664c0 2023-06-29  637: end
748ed664c0 2023-06-29  638: function Auxiliary.SynMixCheckRecursive(c,tp,sg,mg,ct,minc,maxc,syncard,sg1,smat,gc,mgchk)
748ed664c0 2023-06-29  639: 	sg:AddCard(c)
748ed664c0 2023-06-29  640: 	ct=ct+1
748ed664c0 2023-06-29  641: 	local res=Auxiliary.SynMixCheckGoal(tp,sg,minc,ct,syncard,sg1,smat,gc,mgchk)
748ed664c0 2023-06-29  642: 		or (ct<maxc and mg:IsExists(Auxiliary.SynMixCheckRecursive,1,sg,tp,sg,mg,ct,minc,maxc,syncard,sg1,smat,gc,mgchk))
748ed664c0 2023-06-29  643: 	sg:RemoveCard(c)
748ed664c0 2023-06-29  644: 	ct=ct-1
748ed664c0 2023-06-29  645: 	return res
748ed664c0 2023-06-29  646: end
748ed664c0 2023-06-29  647: -- the material is in hand and don't has extra synchro material effect itself
748ed664c0 2023-06-29  648: -- that mean some other tuner added it as material
748ed664c0 2023-06-29  649: function Auxiliary.SynMixHandFilter(c,tp,syncard)
748ed664c0 2023-06-29  650: 	if not c:IsLocation(LOCATION_HAND) then return false end
748ed664c0 2023-06-29  651: 	local le={c:IsHasEffect(EFFECT_EXTRA_SYNCHRO_MATERIAL,tp)}
748ed664c0 2023-06-29  652: 	for _,te in pairs(le) do
748ed664c0 2023-06-29  653: 		local tf=te:GetValue()
748ed664c0 2023-06-29  654: 		if Auxiliary.GetValueType(tf)=="function" then
748ed664c0 2023-06-29  655: 			if tf(te,syncard) then return false end
748ed664c0 2023-06-29  656: 		else
748ed664c0 2023-06-29  657: 			if tf~=0 then return false end
748ed664c0 2023-06-29  658: 		end
748ed664c0 2023-06-29  659: 	end
748ed664c0 2023-06-29  660: 	return true
748ed664c0 2023-06-29  661: end
748ed664c0 2023-06-29  662: function Auxiliary.SynMixCheckGoal(tp,sg,minc,ct,syncard,sg1,smat,gc,mgchk)
748ed664c0 2023-06-29  663: 	if ct<minc then return false end
748ed664c0 2023-06-29  664: 	local g=sg:Clone()
748ed664c0 2023-06-29  665: 	g:Merge(sg1)
748ed664c0 2023-06-29  666: 	if Duel.GetLocationCountFromEx(tp,tp,g,syncard)<=0 then return false end
748ed664c0 2023-06-29  667: 	if gc and not gc(g) then return false end
748ed664c0 2023-06-29  668: 	if smat and not g:IsContains(smat) then return false end
748ed664c0 2023-06-29  669: 	if not Auxiliary.MustMaterialCheck(g,tp,EFFECT_MUST_BE_SMATERIAL) then return false end
748ed664c0 2023-06-29  670: 	if not g:CheckWithSumEqual(Card.GetSynchroLevel,syncard:GetLevel(),g:GetCount(),g:GetCount(),syncard)
748ed664c0 2023-06-29  671: 		and (not g:IsExists(Card.IsHasEffect,1,nil,89818984)
748ed664c0 2023-06-29  672: 		or not g:CheckWithSumEqual(Auxiliary.GetSynchroLevelFlowerCardian,syncard:GetLevel(),g:GetCount(),g:GetCount(),syncard))
748ed664c0 2023-06-29  673: 		then return false end
748ed664c0 2023-06-29  674: 	local hg=g:Filter(Auxiliary.SynMixHandFilter,nil,tp,syncard)
748ed664c0 2023-06-29  675: 	local hct=hg:GetCount()
748ed664c0 2023-06-29  676: 	if hct>0 and not mgchk then
748ed664c0 2023-06-29  677: 		local found=false
748ed664c0 2023-06-29  678: 		for c in aux.Next(g) do
748ed664c0 2023-06-29  679: 			local he,hf,hmin,hmax=c:GetHandSynchro()
748ed664c0 2023-06-29  680: 			if he then
748ed664c0 2023-06-29  681: 				found=true
748ed664c0 2023-06-29  682: 				if hf and hg:IsExists(Auxiliary.SynLimitFilter,1,c,hf,he,syncard) then return false end
748ed664c0 2023-06-29  683: 				if (hmin and hct<hmin) or (hmax and hct>hmax) then return false end
748ed664c0 2023-06-29  684: 			end
748ed664c0 2023-06-29  685: 		end
748ed664c0 2023-06-29  686: 		if not found then return false end
748ed664c0 2023-06-29  687: 	end
748ed664c0 2023-06-29  688: 	for c in aux.Next(g) do
748ed664c0 2023-06-29  689: 		local le,lf,lloc,lmin,lmax=c:GetTunerLimit()
748ed664c0 2023-06-29  690: 		if le then
748ed664c0 2023-06-29  691: 			local lct=g:GetCount()-1
748ed664c0 2023-06-29  692: 			if lloc then
748ed664c0 2023-06-29  693: 				local llct=g:FilterCount(Card.IsLocation,c,lloc)
748ed664c0 2023-06-29  694: 				if llct~=lct then return false end
748ed664c0 2023-06-29  695: 			end
748ed664c0 2023-06-29  696: 			if lf and g:IsExists(Auxiliary.SynLimitFilter,1,c,lf,le,syncard) then return false end
748ed664c0 2023-06-29  697: 			if (lmin and lct<lmin) or (lmax and lct>lmax) then return false end
748ed664c0 2023-06-29  698: 		end
748ed664c0 2023-06-29  699: 	end
748ed664c0 2023-06-29  700: 	return true
748ed664c0 2023-06-29  701: end
748ed664c0 2023-06-29  702: --Checking Tune Magician
748ed664c0 2023-06-29  703: function Auxiliary.TuneMagicianFilter(c,e)
748ed664c0 2023-06-29  704: 	local f=e:GetValue()
748ed664c0 2023-06-29  705: 	return f(e,c)
748ed664c0 2023-06-29  706: end
748ed664c0 2023-06-29  707: function Auxiliary.TuneMagicianCheckX(c,sg,ecode)
748ed664c0 2023-06-29  708: 	local eset={c:IsHasEffect(ecode)}
748ed664c0 2023-06-29  709: 	for _,te in pairs(eset) do
748ed664c0 2023-06-29  710: 		if sg:IsExists(Auxiliary.TuneMagicianFilter,1,c,te) then return true end
748ed664c0 2023-06-29  711: 	end
748ed664c0 2023-06-29  712: 	return false
748ed664c0 2023-06-29  713: end
748ed664c0 2023-06-29  714: function Auxiliary.TuneMagicianCheckAdditionalX(ecode)
748ed664c0 2023-06-29  715: 	return	function(g)
748ed664c0 2023-06-29  716: 				return not g:IsExists(Auxiliary.TuneMagicianCheckX,1,nil,g,ecode)
748ed664c0 2023-06-29  717: 			end
748ed664c0 2023-06-29  718: end
748ed664c0 2023-06-29  719: function Auxiliary.XyzAlterFilter(c,alterf,xyzc,e,tp,alterop)
748ed664c0 2023-06-29  720: 	return alterf(c) and c:IsCanBeXyzMaterial(xyzc) and Duel.GetLocationCountFromEx(tp,tp,c,xyzc)>0
748ed664c0 2023-06-29  721: 		and Auxiliary.MustMaterialCheck(c,tp,EFFECT_MUST_BE_XMATERIAL) and (not alterop or alterop(e,tp,0,c))
748ed664c0 2023-06-29  722: end
748ed664c0 2023-06-29  723: --Xyz monster, lv k*n
748ed664c0 2023-06-29  724: function Auxiliary.AddXyzProcedure(c,f,lv,ct,alterf,alterdesc,maxct,alterop)
748ed664c0 2023-06-29  725: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29  726: 	e1:SetDescription(1165)
748ed664c0 2023-06-29  727: 	e1:SetType(EFFECT_TYPE_FIELD)
748ed664c0 2023-06-29  728: 	e1:SetCode(EFFECT_SPSUMMON_PROC)
748ed664c0 2023-06-29  729: 	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
748ed664c0 2023-06-29  730: 	e1:SetRange(LOCATION_EXTRA)
748ed664c0 2023-06-29  731: 	if not maxct then maxct=ct end
748ed664c0 2023-06-29  732: 	if alterf then
748ed664c0 2023-06-29  733: 		e1:SetCondition(Auxiliary.XyzConditionAlter(f,lv,ct,maxct,alterf,alterdesc,alterop))
748ed664c0 2023-06-29  734: 		e1:SetTarget(Auxiliary.XyzTargetAlter(f,lv,ct,maxct,alterf,alterdesc,alterop))
748ed664c0 2023-06-29  735: 		e1:SetOperation(Auxiliary.XyzOperationAlter(f,lv,ct,maxct,alterf,alterdesc,alterop))
748ed664c0 2023-06-29  736: 	else
748ed664c0 2023-06-29  737: 		e1:SetCondition(Auxiliary.XyzCondition(f,lv,ct,maxct))
748ed664c0 2023-06-29  738: 		e1:SetTarget(Auxiliary.XyzTarget(f,lv,ct,maxct))
748ed664c0 2023-06-29  739: 		e1:SetOperation(Auxiliary.XyzOperation(f,lv,ct,maxct))
748ed664c0 2023-06-29  740: 	end
748ed664c0 2023-06-29  741: 	e1:SetValue(SUMMON_TYPE_XYZ)
748ed664c0 2023-06-29  742: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29  743: end
748ed664c0 2023-06-29  744: --Xyz Summon(normal)
748ed664c0 2023-06-29  745: function Auxiliary.XyzCondition(f,lv,minc,maxc)
748ed664c0 2023-06-29  746: 	--og: use special material
748ed664c0 2023-06-29  747: 	return	function(e,c,og,min,max)
748ed664c0 2023-06-29  748: 				if c==nil then return true end
748ed664c0 2023-06-29  749: 				if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end
748ed664c0 2023-06-29  750: 				local tp=c:GetControler()
748ed664c0 2023-06-29  751: 				local minc=minc
748ed664c0 2023-06-29  752: 				local maxc=maxc
748ed664c0 2023-06-29  753: 				if min then
748ed664c0 2023-06-29  754: 					if min>minc then minc=min end
748ed664c0 2023-06-29  755: 					if max<maxc then maxc=max end
748ed664c0 2023-06-29  756: 					if minc>maxc then return false end
748ed664c0 2023-06-29  757: 				end
748ed664c0 2023-06-29  758: 				return Duel.CheckXyzMaterial(c,f,lv,minc,maxc,og)
748ed664c0 2023-06-29  759: 			end
748ed664c0 2023-06-29  760: end
748ed664c0 2023-06-29  761: function Auxiliary.XyzTarget(f,lv,minc,maxc)
748ed664c0 2023-06-29  762: 	return	function(e,tp,eg,ep,ev,re,r,rp,chk,c,og,min,max)
748ed664c0 2023-06-29  763: 				if og and not min then
748ed664c0 2023-06-29  764: 					return true
748ed664c0 2023-06-29  765: 				end
748ed664c0 2023-06-29  766: 				local minc=minc
748ed664c0 2023-06-29  767: 				local maxc=maxc
748ed664c0 2023-06-29  768: 				if min then
748ed664c0 2023-06-29  769: 					if min>minc then minc=min end
748ed664c0 2023-06-29  770: 					if max<maxc then maxc=max end
748ed664c0 2023-06-29  771: 				end
748ed664c0 2023-06-29  772: 				local g=Duel.SelectXyzMaterial(tp,c,f,lv,minc,maxc,og)
748ed664c0 2023-06-29  773: 				if g then
748ed664c0 2023-06-29  774: 					g:KeepAlive()
748ed664c0 2023-06-29  775: 					e:SetLabelObject(g)
748ed664c0 2023-06-29  776: 					return true
748ed664c0 2023-06-29  777: 				else return false end
748ed664c0 2023-06-29  778: 			end
748ed664c0 2023-06-29  779: end
748ed664c0 2023-06-29  780: function Auxiliary.XyzOperation(f,lv,minc,maxc)
748ed664c0 2023-06-29  781: 	return	function(e,tp,eg,ep,ev,re,r,rp,c,og,min,max)
748ed664c0 2023-06-29  782: 				if og and not min then
748ed664c0 2023-06-29  783: 					local sg=Group.CreateGroup()
748ed664c0 2023-06-29  784: 					local tc=og:GetFirst()
748ed664c0 2023-06-29  785: 					while tc do
748ed664c0 2023-06-29  786: 						local sg1=tc:GetOverlayGroup()
748ed664c0 2023-06-29  787: 						sg:Merge(sg1)
748ed664c0 2023-06-29  788: 						tc=og:GetNext()
748ed664c0 2023-06-29  789: 					end
748ed664c0 2023-06-29  790: 					Duel.SendtoGrave(sg,REASON_RULE)
748ed664c0 2023-06-29  791: 					c:SetMaterial(og)
748ed664c0 2023-06-29  792: 					Duel.Overlay(c,og)
748ed664c0 2023-06-29  793: 				else
748ed664c0 2023-06-29  794: 					local mg=e:GetLabelObject()
748ed664c0 2023-06-29  795: 					local sg=Group.CreateGroup()
748ed664c0 2023-06-29  796: 					local tc=mg:GetFirst()
748ed664c0 2023-06-29  797: 					while tc do
748ed664c0 2023-06-29  798: 						local sg1=tc:GetOverlayGroup()
748ed664c0 2023-06-29  799: 						sg:Merge(sg1)
748ed664c0 2023-06-29  800: 						tc=mg:GetNext()
748ed664c0 2023-06-29  801: 					end
748ed664c0 2023-06-29  802: 					Duel.SendtoGrave(sg,REASON_RULE)
748ed664c0 2023-06-29  803: 					c:SetMaterial(mg)
748ed664c0 2023-06-29  804: 					Duel.Overlay(c,mg)
748ed664c0 2023-06-29  805: 					mg:DeleteGroup()
748ed664c0 2023-06-29  806: 				end
748ed664c0 2023-06-29  807: 			end
748ed664c0 2023-06-29  808: end
748ed664c0 2023-06-29  809: --Xyz summon(alterf)
748ed664c0 2023-06-29  810: function Auxiliary.XyzConditionAlter(f,lv,minc,maxc,alterf,alterdesc,alterop)
748ed664c0 2023-06-29  811: 	return	function(e,c,og,min,max)
748ed664c0 2023-06-29  812: 				if c==nil then return true end
748ed664c0 2023-06-29  813: 				if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end
748ed664c0 2023-06-29  814: 				local tp=c:GetControler()
748ed664c0 2023-06-29  815: 				local mg=nil
748ed664c0 2023-06-29  816: 				if og then
748ed664c0 2023-06-29  817: 					mg=og
748ed664c0 2023-06-29  818: 				else
748ed664c0 2023-06-29  819: 					mg=Duel.GetFieldGroup(tp,LOCATION_MZONE,0)
748ed664c0 2023-06-29  820: 				end
748ed664c0 2023-06-29  821: 				if (not min or min<=1) and mg:IsExists(Auxiliary.XyzAlterFilter,1,nil,alterf,c,e,tp,alterop) then
748ed664c0 2023-06-29  822: 					return true
748ed664c0 2023-06-29  823: 				end
748ed664c0 2023-06-29  824: 				local minc=minc
748ed664c0 2023-06-29  825: 				local maxc=maxc
748ed664c0 2023-06-29  826: 				if min then
748ed664c0 2023-06-29  827: 					if min>minc then minc=min end
748ed664c0 2023-06-29  828: 					if max<maxc then maxc=max end
748ed664c0 2023-06-29  829: 					if minc>maxc then return false end
748ed664c0 2023-06-29  830: 				end
748ed664c0 2023-06-29  831: 				return Duel.CheckXyzMaterial(c,f,lv,minc,maxc,og)
748ed664c0 2023-06-29  832: 			end
748ed664c0 2023-06-29  833: end
748ed664c0 2023-06-29  834: function Auxiliary.XyzTargetAlter(f,lv,minc,maxc,alterf,alterdesc,alterop)
748ed664c0 2023-06-29  835: 	return	function(e,tp,eg,ep,ev,re,r,rp,chk,c,og,min,max)
748ed664c0 2023-06-29  836: 				if og and not min then
748ed664c0 2023-06-29  837: 					return true
748ed664c0 2023-06-29  838: 				end
748ed664c0 2023-06-29  839: 				local minc=minc
748ed664c0 2023-06-29  840: 				local maxc=maxc
748ed664c0 2023-06-29  841: 				if min then
748ed664c0 2023-06-29  842: 					if min>minc then minc=min end
748ed664c0 2023-06-29  843: 					if max<maxc then maxc=max end
748ed664c0 2023-06-29  844: 				end
748ed664c0 2023-06-29  845: 				local mg=nil
748ed664c0 2023-06-29  846: 				if og then
748ed664c0 2023-06-29  847: 					mg=og
748ed664c0 2023-06-29  848: 				else
748ed664c0 2023-06-29  849: 					mg=Duel.GetFieldGroup(tp,LOCATION_MZONE,0)
748ed664c0 2023-06-29  850: 				end
748ed664c0 2023-06-29  851: 				local altg=mg:Filter(Auxiliary.XyzAlterFilter,nil,alterf,c,e,tp,alterop)
748ed664c0 2023-06-29  852: 				local b1=Duel.CheckXyzMaterial(c,f,lv,minc,maxc,og)
748ed664c0 2023-06-29  853: 				local b2=(not min or min<=1) and #altg>0
748ed664c0 2023-06-29  854: 				local g=nil
748ed664c0 2023-06-29  855: 				local cancel=Duel.IsSummonCancelable()
748ed664c0 2023-06-29  856: 				if b2 and (not b1 or Duel.SelectYesNo(tp,alterdesc)) then
748ed664c0 2023-06-29  857: 					e:SetLabel(1)
748ed664c0 2023-06-29  858: 					Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_XMATERIAL)
748ed664c0 2023-06-29  859: 					local tc=altg:SelectUnselect(nil,tp,false,cancel,1,1)
748ed664c0 2023-06-29  860: 					if tc then
748ed664c0 2023-06-29  861: 						g=Group.FromCards(tc)
748ed664c0 2023-06-29  862: 						if alterop then alterop(e,tp,1,tc) end
748ed664c0 2023-06-29  863: 					end
748ed664c0 2023-06-29  864: 				else
748ed664c0 2023-06-29  865: 					e:SetLabel(0)
748ed664c0 2023-06-29  866: 					g=Duel.SelectXyzMaterial(tp,c,f,lv,minc,maxc,og)
748ed664c0 2023-06-29  867: 				end
748ed664c0 2023-06-29  868: 				if g then
748ed664c0 2023-06-29  869: 					g:KeepAlive()
748ed664c0 2023-06-29  870: 					e:SetLabelObject(g)
748ed664c0 2023-06-29  871: 					return true
748ed664c0 2023-06-29  872: 				else return false end
748ed664c0 2023-06-29  873: 			end
748ed664c0 2023-06-29  874: end
748ed664c0 2023-06-29  875: function Auxiliary.XyzOperationAlter(f,lv,minc,maxc,alterf,alterdesc,alterop)
748ed664c0 2023-06-29  876: 	return	function(e,tp,eg,ep,ev,re,r,rp,c,og,min,max)
748ed664c0 2023-06-29  877: 				if og and not min then
748ed664c0 2023-06-29  878: 					local sg=Group.CreateGroup()
748ed664c0 2023-06-29  879: 					local tc=og:GetFirst()
748ed664c0 2023-06-29  880: 					while tc do
748ed664c0 2023-06-29  881: 						local sg1=tc:GetOverlayGroup()
748ed664c0 2023-06-29  882: 						sg:Merge(sg1)
748ed664c0 2023-06-29  883: 						tc=og:GetNext()
748ed664c0 2023-06-29  884: 					end
748ed664c0 2023-06-29  885: 					Duel.SendtoGrave(sg,REASON_RULE)
748ed664c0 2023-06-29  886: 					c:SetMaterial(og)
748ed664c0 2023-06-29  887: 					Duel.Overlay(c,og)
748ed664c0 2023-06-29  888: 				else
748ed664c0 2023-06-29  889: 					local mg=e:GetLabelObject()
748ed664c0 2023-06-29  890: 					if e:GetLabel()==1 then
748ed664c0 2023-06-29  891: 						local mg2=mg:GetFirst():GetOverlayGroup()
748ed664c0 2023-06-29  892: 						if mg2:GetCount()~=0 then
748ed664c0 2023-06-29  893: 							Duel.Overlay(c,mg2)
748ed664c0 2023-06-29  894: 						end
748ed664c0 2023-06-29  895: 					else
748ed664c0 2023-06-29  896: 						local sg=Group.CreateGroup()
748ed664c0 2023-06-29  897: 						local tc=mg:GetFirst()
748ed664c0 2023-06-29  898: 						while tc do
748ed664c0 2023-06-29  899: 							local sg1=tc:GetOverlayGroup()
748ed664c0 2023-06-29  900: 							sg:Merge(sg1)
748ed664c0 2023-06-29  901: 							tc=mg:GetNext()
748ed664c0 2023-06-29  902: 						end
748ed664c0 2023-06-29  903: 						Duel.SendtoGrave(sg,REASON_RULE)
748ed664c0 2023-06-29  904: 					end
748ed664c0 2023-06-29  905: 					c:SetMaterial(mg)
748ed664c0 2023-06-29  906: 					Duel.Overlay(c,mg)
748ed664c0 2023-06-29  907: 					mg:DeleteGroup()
748ed664c0 2023-06-29  908: 				end
748ed664c0 2023-06-29  909: 			end
748ed664c0 2023-06-29  910: end
748ed664c0 2023-06-29  911: function Auxiliary.AddXyzProcedureLevelFree(c,f,gf,minc,maxc,alterf,alterdesc,alterop)
748ed664c0 2023-06-29  912: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29  913: 	e1:SetDescription(1165)
748ed664c0 2023-06-29  914: 	e1:SetType(EFFECT_TYPE_FIELD)
748ed664c0 2023-06-29  915: 	e1:SetCode(EFFECT_SPSUMMON_PROC)
748ed664c0 2023-06-29  916: 	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
748ed664c0 2023-06-29  917: 	e1:SetRange(LOCATION_EXTRA)
748ed664c0 2023-06-29  918: 	if alterf then
748ed664c0 2023-06-29  919: 		e1:SetCondition(Auxiliary.XyzLevelFreeConditionAlter(f,gf,minc,maxc,alterf,alterdesc,alterop))
748ed664c0 2023-06-29  920: 		e1:SetTarget(Auxiliary.XyzLevelFreeTargetAlter(f,gf,minc,maxc,alterf,alterdesc,alterop))
748ed664c0 2023-06-29  921: 		e1:SetOperation(Auxiliary.XyzLevelFreeOperationAlter(f,gf,minc,maxc,alterf,alterdesc,alterop))
748ed664c0 2023-06-29  922: 	else
748ed664c0 2023-06-29  923: 		e1:SetCondition(Auxiliary.XyzLevelFreeCondition(f,gf,minc,maxc))
748ed664c0 2023-06-29  924: 		e1:SetTarget(Auxiliary.XyzLevelFreeTarget(f,gf,minc,maxc))
748ed664c0 2023-06-29  925: 		e1:SetOperation(Auxiliary.XyzLevelFreeOperation(f,gf,minc,maxc))
748ed664c0 2023-06-29  926: 	end
748ed664c0 2023-06-29  927: 	e1:SetValue(SUMMON_TYPE_XYZ)
748ed664c0 2023-06-29  928: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29  929: end
748ed664c0 2023-06-29  930: --Xyz Summon(level free)
748ed664c0 2023-06-29  931: function Auxiliary.XyzLevelFreeFilter(c,xyzc,f)
748ed664c0 2023-06-29  932: 	return (not c:IsOnField() or c:IsFaceup()) and c:IsCanBeXyzMaterial(xyzc) and (not f or f(c,xyzc))
748ed664c0 2023-06-29  933: end
748ed664c0 2023-06-29  934: function Auxiliary.XyzLevelFreeGoal(g,tp,xyzc,gf)
748ed664c0 2023-06-29  935: 	return (not gf or gf(g)) and Duel.GetLocationCountFromEx(tp,tp,g,xyzc)>0
748ed664c0 2023-06-29  936: end
748ed664c0 2023-06-29  937: function Auxiliary.XyzLevelFreeCondition(f,gf,minct,maxct)
748ed664c0 2023-06-29  938: 	return	function(e,c,og,min,max)
748ed664c0 2023-06-29  939: 				if c==nil then return true end
748ed664c0 2023-06-29  940: 				if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end
748ed664c0 2023-06-29  941: 				local tp=c:GetControler()
748ed664c0 2023-06-29  942: 				local minc=minct
748ed664c0 2023-06-29  943: 				local maxc=maxct
748ed664c0 2023-06-29  944: 				if min then
748ed664c0 2023-06-29  945: 					minc=math.max(minc,min)
748ed664c0 2023-06-29  946: 					maxc=math.min(maxc,max)
748ed664c0 2023-06-29  947: 				end
748ed664c0 2023-06-29  948: 				if maxc<minc then return false end
748ed664c0 2023-06-29  949: 				local mg=nil
748ed664c0 2023-06-29  950: 				if og then
748ed664c0 2023-06-29  951: 					mg=og:Filter(Auxiliary.XyzLevelFreeFilter,nil,c,f)
748ed664c0 2023-06-29  952: 				else
748ed664c0 2023-06-29  953: 					mg=Duel.GetMatchingGroup(Auxiliary.XyzLevelFreeFilter,tp,LOCATION_MZONE,0,nil,c,f)
748ed664c0 2023-06-29  954: 				end
748ed664c0 2023-06-29  955: 				local sg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_XMATERIAL)
748ed664c0 2023-06-29  956: 				if sg:IsExists(Auxiliary.MustMaterialCounterFilter,1,nil,mg) then return false end
748ed664c0 2023-06-29  957: 				Duel.SetSelectedCard(sg)
748ed664c0 2023-06-29  958: 				Auxiliary.GCheckAdditional=Auxiliary.TuneMagicianCheckAdditionalX(EFFECT_TUNE_MAGICIAN_X)
748ed664c0 2023-06-29  959: 				local res=mg:CheckSubGroup(Auxiliary.XyzLevelFreeGoal,minc,maxc,tp,c,gf)
748ed664c0 2023-06-29  960: 				Auxiliary.GCheckAdditional=nil
748ed664c0 2023-06-29  961: 				return res
748ed664c0 2023-06-29  962: 			end
748ed664c0 2023-06-29  963: end
748ed664c0 2023-06-29  964: function Auxiliary.XyzLevelFreeTarget(f,gf,minct,maxct)
748ed664c0 2023-06-29  965: 	return	function(e,tp,eg,ep,ev,re,r,rp,chk,c,og,min,max)
748ed664c0 2023-06-29  966: 				if og and not min then
748ed664c0 2023-06-29  967: 					return true
748ed664c0 2023-06-29  968: 				end
748ed664c0 2023-06-29  969: 				local minc=minct
748ed664c0 2023-06-29  970: 				local maxc=maxct
748ed664c0 2023-06-29  971: 				if min then
748ed664c0 2023-06-29  972: 					if min>minc then minc=min end
748ed664c0 2023-06-29  973: 					if max<maxc then maxc=max end
748ed664c0 2023-06-29  974: 				end
748ed664c0 2023-06-29  975: 				local mg=nil
748ed664c0 2023-06-29  976: 				if og then
748ed664c0 2023-06-29  977: 					mg=og:Filter(Auxiliary.XyzLevelFreeFilter,nil,c,f)
748ed664c0 2023-06-29  978: 				else
748ed664c0 2023-06-29  979: 					mg=Duel.GetMatchingGroup(Auxiliary.XyzLevelFreeFilter,tp,LOCATION_MZONE,0,nil,c,f)
748ed664c0 2023-06-29  980: 				end
748ed664c0 2023-06-29  981: 				local sg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_XMATERIAL)
748ed664c0 2023-06-29  982: 				Duel.SetSelectedCard(sg)
748ed664c0 2023-06-29  983: 				Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_XMATERIAL)
748ed664c0 2023-06-29  984: 				local cancel=Duel.IsSummonCancelable()
748ed664c0 2023-06-29  985: 				Auxiliary.GCheckAdditional=Auxiliary.TuneMagicianCheckAdditionalX(EFFECT_TUNE_MAGICIAN_X)
748ed664c0 2023-06-29  986: 				local g=mg:SelectSubGroup(tp,Auxiliary.XyzLevelFreeGoal,cancel,minc,maxc,tp,c,gf)
748ed664c0 2023-06-29  987: 				Auxiliary.GCheckAdditional=nil
748ed664c0 2023-06-29  988: 				if g and g:GetCount()>0 then
748ed664c0 2023-06-29  989: 					g:KeepAlive()
748ed664c0 2023-06-29  990: 					e:SetLabelObject(g)
748ed664c0 2023-06-29  991: 					return true
748ed664c0 2023-06-29  992: 				else return false end
748ed664c0 2023-06-29  993: 			end
748ed664c0 2023-06-29  994: end
748ed664c0 2023-06-29  995: function Auxiliary.XyzLevelFreeOperation(f,gf,minct,maxct)
748ed664c0 2023-06-29  996: 	return	function(e,tp,eg,ep,ev,re,r,rp,c,og,min,max)
748ed664c0 2023-06-29  997: 				if og and not min then
748ed664c0 2023-06-29  998: 					local sg=Group.CreateGroup()
748ed664c0 2023-06-29  999: 					local tc=og:GetFirst()
748ed664c0 2023-06-29 1000: 					while tc do
748ed664c0 2023-06-29 1001: 						local sg1=tc:GetOverlayGroup()
748ed664c0 2023-06-29 1002: 						sg:Merge(sg1)
748ed664c0 2023-06-29 1003: 						tc=og:GetNext()
748ed664c0 2023-06-29 1004: 					end
748ed664c0 2023-06-29 1005: 					Duel.SendtoGrave(sg,REASON_RULE)
748ed664c0 2023-06-29 1006: 					c:SetMaterial(og)
748ed664c0 2023-06-29 1007: 					Duel.Overlay(c,og)
748ed664c0 2023-06-29 1008: 				else
748ed664c0 2023-06-29 1009: 					local mg=e:GetLabelObject()
748ed664c0 2023-06-29 1010: 					if e:GetLabel()==1 then
748ed664c0 2023-06-29 1011: 						local mg2=mg:GetFirst():GetOverlayGroup()
748ed664c0 2023-06-29 1012: 						if mg2:GetCount()~=0 then
748ed664c0 2023-06-29 1013: 							Duel.Overlay(c,mg2)
748ed664c0 2023-06-29 1014: 						end
748ed664c0 2023-06-29 1015: 					else
748ed664c0 2023-06-29 1016: 						local sg=Group.CreateGroup()
748ed664c0 2023-06-29 1017: 						local tc=mg:GetFirst()
748ed664c0 2023-06-29 1018: 						while tc do
748ed664c0 2023-06-29 1019: 							local sg1=tc:GetOverlayGroup()
748ed664c0 2023-06-29 1020: 							sg:Merge(sg1)
748ed664c0 2023-06-29 1021: 							tc=mg:GetNext()
748ed664c0 2023-06-29 1022: 						end
748ed664c0 2023-06-29 1023: 						Duel.SendtoGrave(sg,REASON_RULE)
748ed664c0 2023-06-29 1024: 					end
748ed664c0 2023-06-29 1025: 					c:SetMaterial(mg)
748ed664c0 2023-06-29 1026: 					Duel.Overlay(c,mg)
748ed664c0 2023-06-29 1027: 					mg:DeleteGroup()
748ed664c0 2023-06-29 1028: 				end
748ed664c0 2023-06-29 1029: 			end
748ed664c0 2023-06-29 1030: end
748ed664c0 2023-06-29 1031: --Xyz summon(level free&alterf)
748ed664c0 2023-06-29 1032: function Auxiliary.XyzLevelFreeConditionAlter(f,gf,minct,maxct,alterf,alterdesc,alterop)
748ed664c0 2023-06-29 1033: 	return	function(e,c,og,min,max)
748ed664c0 2023-06-29 1034: 				if c==nil then return true end
748ed664c0 2023-06-29 1035: 				if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end
748ed664c0 2023-06-29 1036: 				local tp=c:GetControler()
748ed664c0 2023-06-29 1037: 				local mg=nil
748ed664c0 2023-06-29 1038: 				if og then
748ed664c0 2023-06-29 1039: 					mg=og
748ed664c0 2023-06-29 1040: 				else
748ed664c0 2023-06-29 1041: 					mg=Duel.GetFieldGroup(tp,LOCATION_MZONE,0)
748ed664c0 2023-06-29 1042: 				end
748ed664c0 2023-06-29 1043: 				local altg=mg:Filter(Auxiliary.XyzAlterFilter,nil,alterf,c,e,tp,alterop)
748ed664c0 2023-06-29 1044: 				if (not min or min<=1) and altg:GetCount()>0 then
748ed664c0 2023-06-29 1045: 					return true
748ed664c0 2023-06-29 1046: 				end
748ed664c0 2023-06-29 1047: 				local minc=minct
748ed664c0 2023-06-29 1048: 				local maxc=maxct
748ed664c0 2023-06-29 1049: 				if min then
748ed664c0 2023-06-29 1050: 					if min>minc then minc=min end
748ed664c0 2023-06-29 1051: 					if max<maxc then maxc=max end
748ed664c0 2023-06-29 1052: 					if minc>maxc then return false end
748ed664c0 2023-06-29 1053: 				end
748ed664c0 2023-06-29 1054: 				mg=mg:Filter(Auxiliary.XyzLevelFreeFilter,nil,c,f)
748ed664c0 2023-06-29 1055: 				local sg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_XMATERIAL)
748ed664c0 2023-06-29 1056: 				if sg:IsExists(Auxiliary.MustMaterialCounterFilter,1,nil,mg) then return false end
748ed664c0 2023-06-29 1057: 				Duel.SetSelectedCard(sg)
748ed664c0 2023-06-29 1058: 				Auxiliary.GCheckAdditional=Auxiliary.TuneMagicianCheckAdditionalX(EFFECT_TUNE_MAGICIAN_X)
748ed664c0 2023-06-29 1059: 				local res=mg:CheckSubGroup(Auxiliary.XyzLevelFreeGoal,minc,maxc,tp,c,gf)
748ed664c0 2023-06-29 1060: 				Auxiliary.GCheckAdditional=nil
748ed664c0 2023-06-29 1061: 				return res
748ed664c0 2023-06-29 1062: 			end
748ed664c0 2023-06-29 1063: end
748ed664c0 2023-06-29 1064: function Auxiliary.XyzLevelFreeTargetAlter(f,gf,minct,maxct,alterf,alterdesc,alterop)
748ed664c0 2023-06-29 1065: 	return	function(e,tp,eg,ep,ev,re,r,rp,chk,c,og,min,max)
748ed664c0 2023-06-29 1066: 				if og and not min then
748ed664c0 2023-06-29 1067: 					return true
748ed664c0 2023-06-29 1068: 				end
748ed664c0 2023-06-29 1069: 				local minc=minct
748ed664c0 2023-06-29 1070: 				local maxc=maxct
748ed664c0 2023-06-29 1071: 				if min then
748ed664c0 2023-06-29 1072: 					if min>minc then minc=min end
748ed664c0 2023-06-29 1073: 					if max<maxc then maxc=max end
748ed664c0 2023-06-29 1074: 				end
748ed664c0 2023-06-29 1075: 				local mg=nil
748ed664c0 2023-06-29 1076: 				if og then
748ed664c0 2023-06-29 1077: 					mg=og
748ed664c0 2023-06-29 1078: 				else
748ed664c0 2023-06-29 1079: 					mg=Duel.GetFieldGroup(tp,LOCATION_MZONE,0)
748ed664c0 2023-06-29 1080: 				end
748ed664c0 2023-06-29 1081: 				local sg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_XMATERIAL)
748ed664c0 2023-06-29 1082: 				local altg=mg:Filter(Auxiliary.XyzAlterFilter,nil,alterf,c,e,tp,alterop)
748ed664c0 2023-06-29 1083: 				local mg2=mg:Filter(Auxiliary.XyzLevelFreeFilter,nil,c,f)
748ed664c0 2023-06-29 1084: 				Duel.SetSelectedCard(sg)
748ed664c0 2023-06-29 1085: 				local b1=mg2:CheckSubGroup(Auxiliary.XyzLevelFreeGoal,minc,maxc,tp,c,gf)
748ed664c0 2023-06-29 1086: 				local b2=(not min or min<=1) and #altg>0
748ed664c0 2023-06-29 1087: 				local g=nil
748ed664c0 2023-06-29 1088: 				local cancel=Duel.IsSummonCancelable()
748ed664c0 2023-06-29 1089: 				if b2 and (not b1 or Duel.SelectYesNo(tp,alterdesc)) then
748ed664c0 2023-06-29 1090: 					e:SetLabel(1)
748ed664c0 2023-06-29 1091: 					Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_XMATERIAL)
748ed664c0 2023-06-29 1092: 					local tc=altg:SelectUnselect(nil,tp,false,cancel,1,1)
748ed664c0 2023-06-29 1093: 					if tc then
748ed664c0 2023-06-29 1094: 						g=Group.FromCards(tc)
748ed664c0 2023-06-29 1095: 						if alterop then alterop(e,tp,1,tc) end
748ed664c0 2023-06-29 1096: 					end
748ed664c0 2023-06-29 1097: 				else
748ed664c0 2023-06-29 1098: 					e:SetLabel(0)
748ed664c0 2023-06-29 1099: 					Duel.SetSelectedCard(sg)
748ed664c0 2023-06-29 1100: 					Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_XMATERIAL)
748ed664c0 2023-06-29 1101: 					Auxiliary.GCheckAdditional=Auxiliary.TuneMagicianCheckAdditionalX(EFFECT_TUNE_MAGICIAN_X)
748ed664c0 2023-06-29 1102: 					g=mg2:SelectSubGroup(tp,Auxiliary.XyzLevelFreeGoal,cancel,minc,maxc,tp,c,gf)
748ed664c0 2023-06-29 1103: 					Auxiliary.GCheckAdditional=nil
748ed664c0 2023-06-29 1104: 				end
748ed664c0 2023-06-29 1105: 				if g and g:GetCount()>0 then
748ed664c0 2023-06-29 1106: 					g:KeepAlive()
748ed664c0 2023-06-29 1107: 					e:SetLabelObject(g)
748ed664c0 2023-06-29 1108: 					return true
748ed664c0 2023-06-29 1109: 				else return false end
748ed664c0 2023-06-29 1110: 			end
748ed664c0 2023-06-29 1111: end
748ed664c0 2023-06-29 1112: function Auxiliary.XyzLevelFreeOperationAlter(f,gf,minct,maxct,alterf,alterdesc,alterop)
748ed664c0 2023-06-29 1113: 	return	function(e,tp,eg,ep,ev,re,r,rp,c,og,min,max)
748ed664c0 2023-06-29 1114: 				if og and not min then
748ed664c0 2023-06-29 1115: 					local sg=Group.CreateGroup()
748ed664c0 2023-06-29 1116: 					local tc=og:GetFirst()
748ed664c0 2023-06-29 1117: 					while tc do
748ed664c0 2023-06-29 1118: 						local sg1=tc:GetOverlayGroup()
748ed664c0 2023-06-29 1119: 						sg:Merge(sg1)
748ed664c0 2023-06-29 1120: 						tc=og:GetNext()
748ed664c0 2023-06-29 1121: 					end
748ed664c0 2023-06-29 1122: 					Duel.SendtoGrave(sg,REASON_RULE)
748ed664c0 2023-06-29 1123: 					c:SetMaterial(og)
748ed664c0 2023-06-29 1124: 					Duel.Overlay(c,og)
748ed664c0 2023-06-29 1125: 				else
748ed664c0 2023-06-29 1126: 					local mg=e:GetLabelObject()
748ed664c0 2023-06-29 1127: 					if e:GetLabel()==1 then
748ed664c0 2023-06-29 1128: 						local mg2=mg:GetFirst():GetOverlayGroup()
748ed664c0 2023-06-29 1129: 						if mg2:GetCount()~=0 then
748ed664c0 2023-06-29 1130: 							Duel.Overlay(c,mg2)
748ed664c0 2023-06-29 1131: 						end
748ed664c0 2023-06-29 1132: 					else
748ed664c0 2023-06-29 1133: 						local sg=Group.CreateGroup()
748ed664c0 2023-06-29 1134: 						local tc=mg:GetFirst()
748ed664c0 2023-06-29 1135: 						while tc do
748ed664c0 2023-06-29 1136: 							local sg1=tc:GetOverlayGroup()
748ed664c0 2023-06-29 1137: 							sg:Merge(sg1)
748ed664c0 2023-06-29 1138: 							tc=mg:GetNext()
748ed664c0 2023-06-29 1139: 						end
748ed664c0 2023-06-29 1140: 						Duel.SendtoGrave(sg,REASON_RULE)
748ed664c0 2023-06-29 1141: 					end
748ed664c0 2023-06-29 1142: 					c:SetMaterial(mg)
748ed664c0 2023-06-29 1143: 					Duel.Overlay(c,mg)
748ed664c0 2023-06-29 1144: 					mg:DeleteGroup()
748ed664c0 2023-06-29 1145: 				end
748ed664c0 2023-06-29 1146: 			end
748ed664c0 2023-06-29 1147: end
748ed664c0 2023-06-29 1148: --material: names in material list
748ed664c0 2023-06-29 1149: --Fusion monster, mixed materials
748ed664c0 2023-06-29 1150: function Auxiliary.AddFusionProcMix(c,sub,insf,...)
748ed664c0 2023-06-29 1151: 	if c:IsStatus(STATUS_COPYING_EFFECT) then return end
748ed664c0 2023-06-29 1152: 	local val={...}
748ed664c0 2023-06-29 1153: 	local fun={}
748ed664c0 2023-06-29 1154: 	local mat={}
748ed664c0 2023-06-29 1155: 	for i=1,#val do
748ed664c0 2023-06-29 1156: 		if type(val[i])=='function' then
748ed664c0 2023-06-29 1157: 			fun[i]=function(c,fc,sub,mg,sg) return val[i](c,fc,sub,mg,sg) and not c:IsHasEffect(6205579) end
748ed664c0 2023-06-29 1158: 		elseif type(val[i])=='table' then
748ed664c0 2023-06-29 1159: 			fun[i]=function(c,fc,sub,mg,sg)
748ed664c0 2023-06-29 1160: 					for _,fcode in ipairs(val[i]) do
748ed664c0 2023-06-29 1161: 						if type(fcode)=='function' then
748ed664c0 2023-06-29 1162: 							if fcode(c,fc,sub,mg,sg) and not c:IsHasEffect(6205579) then return true end
748ed664c0 2023-06-29 1163: 						else
748ed664c0 2023-06-29 1164: 							if c:IsFusionCode(fcode) or (sub and c:CheckFusionSubstitute(fc)) then return true end
748ed664c0 2023-06-29 1165: 						end
748ed664c0 2023-06-29 1166: 					end
748ed664c0 2023-06-29 1167: 					return false
748ed664c0 2023-06-29 1168: 			end
748ed664c0 2023-06-29 1169: 			for _,fcode in ipairs(val[i]) do
748ed664c0 2023-06-29 1170: 				if type(fcode)~='function' then mat[fcode]=true end
748ed664c0 2023-06-29 1171: 			end
748ed664c0 2023-06-29 1172: 		else
748ed664c0 2023-06-29 1173: 			fun[i]=function(c,fc,sub) return c:IsFusionCode(val[i]) or (sub and c:CheckFusionSubstitute(fc)) end
748ed664c0 2023-06-29 1174: 			mat[val[i]]=true
748ed664c0 2023-06-29 1175: 		end
748ed664c0 2023-06-29 1176: 	end
748ed664c0 2023-06-29 1177: 	local mt=getmetatable(c)
748ed664c0 2023-06-29 1178: 	if mt.material==nil then
748ed664c0 2023-06-29 1179: 		mt.material=mat
748ed664c0 2023-06-29 1180: 	end
748ed664c0 2023-06-29 1181: 	if mt.material_count==nil then
748ed664c0 2023-06-29 1182: 		mt.material_count={#fun,#fun}
748ed664c0 2023-06-29 1183: 	end
748ed664c0 2023-06-29 1184: 	for index,_ in pairs(mat) do
748ed664c0 2023-06-29 1185: 		Auxiliary.AddCodeList(c,index)
748ed664c0 2023-06-29 1186: 	end
748ed664c0 2023-06-29 1187: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29 1188: 	e1:SetType(EFFECT_TYPE_SINGLE)
748ed664c0 2023-06-29 1189: 	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
748ed664c0 2023-06-29 1190: 	e1:SetCode(EFFECT_FUSION_MATERIAL)
748ed664c0 2023-06-29 1191: 	e1:SetCondition(Auxiliary.FConditionMix(insf,sub,table.unpack(fun)))
748ed664c0 2023-06-29 1192: 	e1:SetOperation(Auxiliary.FOperationMix(insf,sub,table.unpack(fun)))
748ed664c0 2023-06-29 1193: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29 1194: end
748ed664c0 2023-06-29 1195: function Auxiliary.FConditionMix(insf,sub,...)
748ed664c0 2023-06-29 1196: 	--g:Material group(nil for Instant Fusion)
748ed664c0 2023-06-29 1197: 	--gc:Material already used
748ed664c0 2023-06-29 1198: 	--chkf: check field, default:PLAYER_NONE
748ed664c0 2023-06-29 1199: 	--chkf&0x100: Not fusion summon
748ed664c0 2023-06-29 1200: 	--chkf&0x200: Concat fusion
748ed664c0 2023-06-29 1201: 	local funs={...}
748ed664c0 2023-06-29 1202: 	return	function(e,g,gc,chkfnf)
748ed664c0 2023-06-29 1203: 				if g==nil then return insf and Auxiliary.MustMaterialCheck(nil,e:GetHandlerPlayer(),EFFECT_MUST_BE_FMATERIAL) end
748ed664c0 2023-06-29 1204: 				local c=e:GetHandler()
748ed664c0 2023-06-29 1205: 				local tp=c:GetControler()
748ed664c0 2023-06-29 1206: 				local notfusion=chkfnf&0x100>0
748ed664c0 2023-06-29 1207: 				local concat_fusion=chkfnf&0x200>0
748ed664c0 2023-06-29 1208: 				local sub=(sub or notfusion) and not concat_fusion
748ed664c0 2023-06-29 1209: 				local mg=g:Filter(Auxiliary.FConditionFilterMix,c,c,sub,concat_fusion,table.unpack(funs))
748ed664c0 2023-06-29 1210: 				if gc then
748ed664c0 2023-06-29 1211: 					if not mg:IsContains(gc) then return false end
748ed664c0 2023-06-29 1212: 					Duel.SetSelectedCard(Group.FromCards(gc))
748ed664c0 2023-06-29 1213: 				end
748ed664c0 2023-06-29 1214: 				return mg:CheckSubGroup(Auxiliary.FCheckMixGoal,#funs,#funs,tp,c,sub,chkfnf,table.unpack(funs))
748ed664c0 2023-06-29 1215: 			end
748ed664c0 2023-06-29 1216: end
748ed664c0 2023-06-29 1217: function Auxiliary.FOperationMix(insf,sub,...)
748ed664c0 2023-06-29 1218: 	local funs={...}
748ed664c0 2023-06-29 1219: 	return	function(e,tp,eg,ep,ev,re,r,rp,gc,chkfnf)
748ed664c0 2023-06-29 1220: 				local c=e:GetHandler()
748ed664c0 2023-06-29 1221: 				local tp=c:GetControler()
748ed664c0 2023-06-29 1222: 				local notfusion=chkfnf&0x100>0
748ed664c0 2023-06-29 1223: 				local concat_fusion=chkfnf&0x200>0
748ed664c0 2023-06-29 1224: 				local sub=(sub or notfusion) and not concat_fusion
748ed664c0 2023-06-29 1225: 				local mg=eg:Filter(Auxiliary.FConditionFilterMix,c,c,sub,concat_fusion,table.unpack(funs))
748ed664c0 2023-06-29 1226: 				if gc then Duel.SetSelectedCard(Group.FromCards(gc)) end
748ed664c0 2023-06-29 1227: 				Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FMATERIAL)
748ed664c0 2023-06-29 1228: 				local sg=mg:SelectSubGroup(tp,Auxiliary.FCheckMixGoal,false,#funs,#funs,tp,c,sub,chkfnf,table.unpack(funs))
748ed664c0 2023-06-29 1229: 				Duel.SetFusionMaterial(sg)
748ed664c0 2023-06-29 1230: 			end
748ed664c0 2023-06-29 1231: end
748ed664c0 2023-06-29 1232: function Auxiliary.FConditionFilterMix(c,fc,sub,concat_fusion,...)
748ed664c0 2023-06-29 1233: 	local fusion_type=concat_fusion and SUMMON_TYPE_SPECIAL or SUMMON_TYPE_FUSION
748ed664c0 2023-06-29 1234: 	if not c:IsCanBeFusionMaterial(fc,fusion_type) then return false end
748ed664c0 2023-06-29 1235: 	for i,f in ipairs({...}) do
748ed664c0 2023-06-29 1236: 		if f(c,fc,sub) then return true end
748ed664c0 2023-06-29 1237: 	end
748ed664c0 2023-06-29 1238: 	return false
748ed664c0 2023-06-29 1239: end
748ed664c0 2023-06-29 1240: function Auxiliary.FCheckMix(c,mg,sg,fc,sub,fun1,fun2,...)
748ed664c0 2023-06-29 1241: 	if fun2 then
748ed664c0 2023-06-29 1242: 		sg:AddCard(c)
748ed664c0 2023-06-29 1243: 		local res=false
748ed664c0 2023-06-29 1244: 		if fun1(c,fc,false,mg,sg) then
748ed664c0 2023-06-29 1245: 			res=mg:IsExists(Auxiliary.FCheckMix,1,sg,mg,sg,fc,sub,fun2,...)
748ed664c0 2023-06-29 1246: 		elseif sub and fun1(c,fc,true,mg,sg) then
748ed664c0 2023-06-29 1247: 			res=mg:IsExists(Auxiliary.FCheckMix,1,sg,mg,sg,fc,false,fun2,...)
748ed664c0 2023-06-29 1248: 		end
748ed664c0 2023-06-29 1249: 		sg:RemoveCard(c)
748ed664c0 2023-06-29 1250: 		return res
748ed664c0 2023-06-29 1251: 	else
748ed664c0 2023-06-29 1252: 		return fun1(c,fc,sub,mg,sg)
748ed664c0 2023-06-29 1253: 	end
748ed664c0 2023-06-29 1254: end
748ed664c0 2023-06-29 1255: --if sg1 is subset of sg2 then not Auxiliary.FCheckAdditional(tp,sg1,fc) -> not Auxiliary.FCheckAdditional(tp,sg2,fc)
748ed664c0 2023-06-29 1256: Auxiliary.FCheckAdditional=nil
748ed664c0 2023-06-29 1257: Auxiliary.FGoalCheckAdditional=nil
748ed664c0 2023-06-29 1258: function Auxiliary.FCheckMixGoal(sg,tp,fc,sub,chkfnf,...)
748ed664c0 2023-06-29 1259: 	local chkf=chkfnf&0xff
748ed664c0 2023-06-29 1260: 	local concat_fusion=chkfnf&0x200>0
748ed664c0 2023-06-29 1261: 	if not concat_fusion and sg:IsExists(Auxiliary.TuneMagicianCheckX,1,nil,sg,EFFECT_TUNE_MAGICIAN_F) then return false end
748ed664c0 2023-06-29 1262: 	if not Auxiliary.MustMaterialCheck(sg,tp,EFFECT_MUST_BE_FMATERIAL) then return false end
748ed664c0 2023-06-29 1263: 	local g=Group.CreateGroup()
748ed664c0 2023-06-29 1264: 	return sg:IsExists(Auxiliary.FCheckMix,1,nil,sg,g,fc,sub,...) and (chkf==PLAYER_NONE or Duel.GetLocationCountFromEx(tp,tp,sg,fc)>0)
748ed664c0 2023-06-29 1265: 		and (not Auxiliary.FCheckAdditional or Auxiliary.FCheckAdditional(tp,sg,fc))
748ed664c0 2023-06-29 1266: 		and (not Auxiliary.FGoalCheckAdditional or Auxiliary.FGoalCheckAdditional(tp,sg,fc))
748ed664c0 2023-06-29 1267: end
748ed664c0 2023-06-29 1268: --Fusion monster, mixed material * minc to maxc + material + ...
748ed664c0 2023-06-29 1269: function Auxiliary.AddFusionProcMixRep(c,sub,insf,fun1,minc,maxc,...)
748ed664c0 2023-06-29 1270: 	if c:IsStatus(STATUS_COPYING_EFFECT) then return end
748ed664c0 2023-06-29 1271: 	local val={fun1,...}
748ed664c0 2023-06-29 1272: 	local fun={}
748ed664c0 2023-06-29 1273: 	local mat={}
748ed664c0 2023-06-29 1274: 	for i=1,#val do
748ed664c0 2023-06-29 1275: 		if type(val[i])=='function' then
748ed664c0 2023-06-29 1276: 			fun[i]=function(c,fc,sub,mg,sg) return val[i](c,fc,sub,mg,sg) and not c:IsHasEffect(6205579) end
748ed664c0 2023-06-29 1277: 		elseif type(val[i])=='table' then
748ed664c0 2023-06-29 1278: 			fun[i]=function(c,fc,sub,mg,sg)
748ed664c0 2023-06-29 1279: 					for _,fcode in ipairs(val[i]) do
748ed664c0 2023-06-29 1280: 						if type(fcode)=='function' then
748ed664c0 2023-06-29 1281: 							if fcode(c,fc,sub,mg,sg) and not c:IsHasEffect(6205579) then return true end
748ed664c0 2023-06-29 1282: 						else
748ed664c0 2023-06-29 1283: 							if c:IsFusionCode(fcode) or (sub and c:CheckFusionSubstitute(fc)) then return true end
748ed664c0 2023-06-29 1284: 						end
748ed664c0 2023-06-29 1285: 					end
748ed664c0 2023-06-29 1286: 					return false
748ed664c0 2023-06-29 1287: 			end
748ed664c0 2023-06-29 1288: 			for _,fcode in ipairs(val[i]) do
748ed664c0 2023-06-29 1289: 				if type(fcode)~='function' then mat[fcode]=true end
748ed664c0 2023-06-29 1290: 			end
748ed664c0 2023-06-29 1291: 		else
748ed664c0 2023-06-29 1292: 			fun[i]=function(c,fc,sub) return c:IsFusionCode(val[i]) or (sub and c:CheckFusionSubstitute(fc)) end
748ed664c0 2023-06-29 1293: 			mat[val[i]]=true
748ed664c0 2023-06-29 1294: 		end
748ed664c0 2023-06-29 1295: 	end
748ed664c0 2023-06-29 1296: 	local mt=getmetatable(c)
748ed664c0 2023-06-29 1297: 	if mt.material==nil then
748ed664c0 2023-06-29 1298: 		mt.material=mat
748ed664c0 2023-06-29 1299: 	end
748ed664c0 2023-06-29 1300: 	if mt.material_count==nil then
748ed664c0 2023-06-29 1301: 		mt.material_count={#fun+minc-1,#fun+maxc-1}
748ed664c0 2023-06-29 1302: 	end
748ed664c0 2023-06-29 1303: 	for index,_ in pairs(mat) do
748ed664c0 2023-06-29 1304: 		Auxiliary.AddCodeList(c,index)
748ed664c0 2023-06-29 1305: 	end
748ed664c0 2023-06-29 1306: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29 1307: 	e1:SetType(EFFECT_TYPE_SINGLE)
748ed664c0 2023-06-29 1308: 	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
748ed664c0 2023-06-29 1309: 	e1:SetCode(EFFECT_FUSION_MATERIAL)
748ed664c0 2023-06-29 1310: 	e1:SetCondition(Auxiliary.FConditionMixRep(insf,sub,fun[1],minc,maxc,table.unpack(fun,2)))
748ed664c0 2023-06-29 1311: 	e1:SetOperation(Auxiliary.FOperationMixRep(insf,sub,fun[1],minc,maxc,table.unpack(fun,2)))
748ed664c0 2023-06-29 1312: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29 1313: end
748ed664c0 2023-06-29 1314: function Auxiliary.FConditionMixRep(insf,sub,fun1,minc,maxc,...)
748ed664c0 2023-06-29 1315: 	local funs={...}
748ed664c0 2023-06-29 1316: 	return	function(e,g,gc,chkfnf)
748ed664c0 2023-06-29 1317: 				if g==nil then return insf and Auxiliary.MustMaterialCheck(nil,e:GetHandlerPlayer(),EFFECT_MUST_BE_FMATERIAL) end
748ed664c0 2023-06-29 1318: 				local c=e:GetHandler()
748ed664c0 2023-06-29 1319: 				local tp=c:GetControler()
748ed664c0 2023-06-29 1320: 				local notfusion=chkfnf&0x100>0
748ed664c0 2023-06-29 1321: 				local concat_fusion=chkfnf&0x200>0
748ed664c0 2023-06-29 1322: 				local sub=(sub or notfusion) and not concat_fusion
748ed664c0 2023-06-29 1323: 				local mg=g:Filter(Auxiliary.FConditionFilterMix,c,c,sub,concat_fusion,fun1,table.unpack(funs))
748ed664c0 2023-06-29 1324: 				if gc then
748ed664c0 2023-06-29 1325: 					if not mg:IsContains(gc) then return false end
748ed664c0 2023-06-29 1326: 					local sg=Group.CreateGroup()
748ed664c0 2023-06-29 1327: 					return Auxiliary.FSelectMixRep(gc,tp,mg,sg,c,sub,chkfnf,fun1,minc,maxc,table.unpack(funs))
748ed664c0 2023-06-29 1328: 				end
748ed664c0 2023-06-29 1329: 				local sg=Group.CreateGroup()
748ed664c0 2023-06-29 1330: 				return mg:IsExists(Auxiliary.FSelectMixRep,1,nil,tp,mg,sg,c,sub,chkfnf,fun1,minc,maxc,table.unpack(funs))
748ed664c0 2023-06-29 1331: 			end
748ed664c0 2023-06-29 1332: end
748ed664c0 2023-06-29 1333: function Auxiliary.FOperationMixRep(insf,sub,fun1,minc,maxc,...)
748ed664c0 2023-06-29 1334: 	local funs={...}
748ed664c0 2023-06-29 1335: 	return	function(e,tp,eg,ep,ev,re,r,rp,gc,chkfnf)
748ed664c0 2023-06-29 1336: 				local c=e:GetHandler()
748ed664c0 2023-06-29 1337: 				local tp=c:GetControler()
748ed664c0 2023-06-29 1338: 				local notfusion=chkfnf&0x100>0
748ed664c0 2023-06-29 1339: 				local concat_fusion=chkfnf&0x200>0
748ed664c0 2023-06-29 1340: 				local sub=(sub or notfusion) and not concat_fusion
748ed664c0 2023-06-29 1341: 				local mg=eg:Filter(Auxiliary.FConditionFilterMix,c,c,sub,concat_fusion,fun1,table.unpack(funs))
748ed664c0 2023-06-29 1342: 				local sg=Group.CreateGroup()
748ed664c0 2023-06-29 1343: 				if gc then sg:AddCard(gc) end
748ed664c0 2023-06-29 1344: 				while sg:GetCount()<maxc+#funs do
748ed664c0 2023-06-29 1345: 					local cg=mg:Filter(Auxiliary.FSelectMixRep,sg,tp,mg,sg,c,sub,chkfnf,fun1,minc,maxc,table.unpack(funs))
748ed664c0 2023-06-29 1346: 					if cg:GetCount()==0 then break end
748ed664c0 2023-06-29 1347: 					local finish=Auxiliary.FCheckMixRepGoal(tp,sg,c,sub,chkfnf,fun1,minc,maxc,table.unpack(funs))
748ed664c0 2023-06-29 1348: 					local cancel_group=sg:Clone()
748ed664c0 2023-06-29 1349: 					if gc then cancel_group:RemoveCard(gc) end
748ed664c0 2023-06-29 1350: 					Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FMATERIAL)
748ed664c0 2023-06-29 1351: 					local tc=cg:SelectUnselect(cancel_group,tp,finish,false,minc+#funs,maxc+#funs)
748ed664c0 2023-06-29 1352: 					if not tc then break end
748ed664c0 2023-06-29 1353: 					if sg:IsContains(tc) then
748ed664c0 2023-06-29 1354: 						sg:RemoveCard(tc)
748ed664c0 2023-06-29 1355: 					else
748ed664c0 2023-06-29 1356: 						sg:AddCard(tc)
748ed664c0 2023-06-29 1357: 					end
748ed664c0 2023-06-29 1358: 				end
748ed664c0 2023-06-29 1359: 				Duel.SetFusionMaterial(sg)
748ed664c0 2023-06-29 1360: 			end
748ed664c0 2023-06-29 1361: end
748ed664c0 2023-06-29 1362: function Auxiliary.FCheckMixRep(sg,g,fc,sub,chkf,fun1,minc,maxc,fun2,...)
748ed664c0 2023-06-29 1363: 	if fun2 then
748ed664c0 2023-06-29 1364: 		return sg:IsExists(Auxiliary.FCheckMixRepFilter,1,g,sg,g,fc,sub,chkf,fun1,minc,maxc,fun2,...)
748ed664c0 2023-06-29 1365: 	else
748ed664c0 2023-06-29 1366: 		local ct1=sg:FilterCount(fun1,g,fc,sub,mg,sg)
748ed664c0 2023-06-29 1367: 		local ct2=sg:FilterCount(fun1,g,fc,false,mg,sg)
748ed664c0 2023-06-29 1368: 		return ct1==sg:GetCount()-g:GetCount() and ct1-ct2<=1
748ed664c0 2023-06-29 1369: 	end
748ed664c0 2023-06-29 1370: end
748ed664c0 2023-06-29 1371: function Auxiliary.FCheckMixRepFilter(c,sg,g,fc,sub,chkf,fun1,minc,maxc,fun2,...)
748ed664c0 2023-06-29 1372: 	if fun2(c,fc,sub,mg,sg) then
748ed664c0 2023-06-29 1373: 		g:AddCard(c)
748ed664c0 2023-06-29 1374: 		local sub=sub and fun2(c,fc,false,mg,sg)
748ed664c0 2023-06-29 1375: 		local res=Auxiliary.FCheckMixRep(sg,g,fc,sub,chkf,fun1,minc,maxc,...)
748ed664c0 2023-06-29 1376: 		g:RemoveCard(c)
748ed664c0 2023-06-29 1377: 		return res
748ed664c0 2023-06-29 1378: 	end
748ed664c0 2023-06-29 1379: 	return false
748ed664c0 2023-06-29 1380: end
748ed664c0 2023-06-29 1381: function Auxiliary.FCheckMixRepGoalCheck(tp,sg,fc,chkfnf)
748ed664c0 2023-06-29 1382: 	local concat_fusion=chkfnf&0x200>0
748ed664c0 2023-06-29 1383: 	if not concat_fusion and sg:IsExists(Auxiliary.TuneMagicianCheckX,1,nil,sg,EFFECT_TUNE_MAGICIAN_F) then return false end
748ed664c0 2023-06-29 1384: 	if not Auxiliary.MustMaterialCheck(sg,tp,EFFECT_MUST_BE_FMATERIAL) then return false end
748ed664c0 2023-06-29 1385: 	if Auxiliary.FGoalCheckAdditional and not Auxiliary.FGoalCheckAdditional(tp,sg,fc) then return false end
748ed664c0 2023-06-29 1386: 	return true
748ed664c0 2023-06-29 1387: end
748ed664c0 2023-06-29 1388: function Auxiliary.FCheckMixRepGoal(tp,sg,fc,sub,chkfnf,fun1,minc,maxc,...)
748ed664c0 2023-06-29 1389: 	local chkf=chkfnf&0xff
748ed664c0 2023-06-29 1390: 	if sg:GetCount()<minc+#{...} or sg:GetCount()>maxc+#{...} then return false end
748ed664c0 2023-06-29 1391: 	if not (chkf==PLAYER_NONE or Duel.GetLocationCountFromEx(tp,tp,sg,fc)>0) then return false end
748ed664c0 2023-06-29 1392: 	if Auxiliary.FCheckAdditional and not Auxiliary.FCheckAdditional(tp,sg,fc) then return false end
748ed664c0 2023-06-29 1393: 	if not Auxiliary.FCheckMixRepGoalCheck(tp,sg,fc,chkfnf) then return false end
748ed664c0 2023-06-29 1394: 	local g=Group.CreateGroup()
748ed664c0 2023-06-29 1395: 	return Auxiliary.FCheckMixRep(sg,g,fc,sub,chkf,fun1,minc,maxc,...)
748ed664c0 2023-06-29 1396: end
748ed664c0 2023-06-29 1397: function Auxiliary.FCheckMixRepTemplate(c,cond,tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,...)
748ed664c0 2023-06-29 1398: 	for i,f in ipairs({...}) do
748ed664c0 2023-06-29 1399: 		if f(c,fc,sub,mg,sg) then
748ed664c0 2023-06-29 1400: 			g:AddCard(c)
748ed664c0 2023-06-29 1401: 			local sub=sub and f(c,fc,false,mg,sg)
748ed664c0 2023-06-29 1402: 			local t={...}
748ed664c0 2023-06-29 1403: 			table.remove(t,i)
748ed664c0 2023-06-29 1404: 			local res=cond(tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,table.unpack(t))
748ed664c0 2023-06-29 1405: 			g:RemoveCard(c)
748ed664c0 2023-06-29 1406: 			if res then return true end
748ed664c0 2023-06-29 1407: 		end
748ed664c0 2023-06-29 1408: 	end
748ed664c0 2023-06-29 1409: 	if maxc>0 then
748ed664c0 2023-06-29 1410: 		if fun1(c,fc,sub,mg,sg) then
748ed664c0 2023-06-29 1411: 			g:AddCard(c)
748ed664c0 2023-06-29 1412: 			local sub=sub and fun1(c,fc,false,mg,sg)
748ed664c0 2023-06-29 1413: 			local res=cond(tp,mg,sg,g,fc,sub,chkfnf,fun1,minc-1,maxc-1,...)
748ed664c0 2023-06-29 1414: 			g:RemoveCard(c)
748ed664c0 2023-06-29 1415: 			if res then return true end
748ed664c0 2023-06-29 1416: 		end
748ed664c0 2023-06-29 1417: 	end
748ed664c0 2023-06-29 1418: 	return false
748ed664c0 2023-06-29 1419: end
748ed664c0 2023-06-29 1420: function Auxiliary.FCheckMixRepSelectedCond(tp,mg,sg,g,...)
748ed664c0 2023-06-29 1421: 	if g:GetCount()<sg:GetCount() then
748ed664c0 2023-06-29 1422: 		return sg:IsExists(Auxiliary.FCheckMixRepSelected,1,g,tp,mg,sg,g,...)
748ed664c0 2023-06-29 1423: 	else
748ed664c0 2023-06-29 1424: 		return Auxiliary.FCheckSelectMixRep(tp,mg,sg,g,...)
748ed664c0 2023-06-29 1425: 	end
748ed664c0 2023-06-29 1426: end
748ed664c0 2023-06-29 1427: function Auxiliary.FCheckMixRepSelected(c,...)
748ed664c0 2023-06-29 1428: 	return Auxiliary.FCheckMixRepTemplate(c,Auxiliary.FCheckMixRepSelectedCond,...)
748ed664c0 2023-06-29 1429: end
748ed664c0 2023-06-29 1430: function Auxiliary.FCheckSelectMixRep(tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,...)
748ed664c0 2023-06-29 1431: 	local chkf=chkfnf&0xff
748ed664c0 2023-06-29 1432: 	if Auxiliary.FCheckAdditional and not Auxiliary.FCheckAdditional(tp,g,fc) then return false end
748ed664c0 2023-06-29 1433: 	if chkf==PLAYER_NONE or Duel.GetLocationCountFromEx(tp,tp,g,fc)>0 then
748ed664c0 2023-06-29 1434: 		if minc<=0 and #{...}==0 and Auxiliary.FCheckMixRepGoalCheck(tp,g,fc,chkfnf) then return true end
748ed664c0 2023-06-29 1435: 		return mg:IsExists(Auxiliary.FCheckSelectMixRepAll,1,g,tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,...)
748ed664c0 2023-06-29 1436: 	else
748ed664c0 2023-06-29 1437: 		return mg:IsExists(Auxiliary.FCheckSelectMixRepM,1,g,tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,...)
748ed664c0 2023-06-29 1438: 	end
748ed664c0 2023-06-29 1439: end
748ed664c0 2023-06-29 1440: function Auxiliary.FCheckSelectMixRepAll(c,tp,mg,sg,g,fc,sub,chkf,fun1,minc,maxc,fun2,...)
748ed664c0 2023-06-29 1441: 	if fun2 then
748ed664c0 2023-06-29 1442: 		if fun2(c,fc,sub,mg,sg) then
748ed664c0 2023-06-29 1443: 			g:AddCard(c)
748ed664c0 2023-06-29 1444: 			local sub=sub and fun2(c,fc,false,mg,sg)
748ed664c0 2023-06-29 1445: 			local res=Auxiliary.FCheckSelectMixRep(tp,mg,sg,g,fc,sub,chkf,fun1,minc,maxc,...)
748ed664c0 2023-06-29 1446: 			g:RemoveCard(c)
748ed664c0 2023-06-29 1447: 			return res
748ed664c0 2023-06-29 1448: 		end
748ed664c0 2023-06-29 1449: 	elseif maxc>0 and fun1(c,fc,sub,mg,sg) then
748ed664c0 2023-06-29 1450: 		g:AddCard(c)
748ed664c0 2023-06-29 1451: 		local sub=sub and fun1(c,fc,false,mg,sg)
748ed664c0 2023-06-29 1452: 		local res=Auxiliary.FCheckSelectMixRep(tp,mg,sg,g,fc,sub,chkf,fun1,minc-1,maxc-1)
748ed664c0 2023-06-29 1453: 		g:RemoveCard(c)
748ed664c0 2023-06-29 1454: 		return res
748ed664c0 2023-06-29 1455: 	end
748ed664c0 2023-06-29 1456: 	return false
748ed664c0 2023-06-29 1457: end
748ed664c0 2023-06-29 1458: function Auxiliary.FCheckSelectMixRepM(c,tp,...)
748ed664c0 2023-06-29 1459: 	return c:IsControler(tp) and c:IsLocation(LOCATION_MZONE)
748ed664c0 2023-06-29 1460: 		and Auxiliary.FCheckMixRepTemplate(c,Auxiliary.FCheckSelectMixRep,tp,...)
748ed664c0 2023-06-29 1461: end
748ed664c0 2023-06-29 1462: function Auxiliary.FSelectMixRep(c,tp,mg,sg,fc,sub,chkfnf,...)
748ed664c0 2023-06-29 1463: 	sg:AddCard(c)
748ed664c0 2023-06-29 1464: 	local res=false
748ed664c0 2023-06-29 1465: 	if Auxiliary.FCheckAdditional and not Auxiliary.FCheckAdditional(tp,sg,fc) then
748ed664c0 2023-06-29 1466: 		res=false
748ed664c0 2023-06-29 1467: 	elseif Auxiliary.FCheckMixRepGoal(tp,sg,fc,sub,chkfnf,...) then
748ed664c0 2023-06-29 1468: 		res=true
748ed664c0 2023-06-29 1469: 	else
748ed664c0 2023-06-29 1470: 		local g=Group.CreateGroup()
748ed664c0 2023-06-29 1471: 		res=sg:IsExists(Auxiliary.FCheckMixRepSelected,1,nil,tp,mg,sg,g,fc,sub,chkfnf,...)
748ed664c0 2023-06-29 1472: 	end
748ed664c0 2023-06-29 1473: 	sg:RemoveCard(c)
748ed664c0 2023-06-29 1474: 	return res
748ed664c0 2023-06-29 1475: end
748ed664c0 2023-06-29 1476: --Fusion monster, name + name
748ed664c0 2023-06-29 1477: function Auxiliary.AddFusionProcCode2(c,code1,code2,sub,insf)
748ed664c0 2023-06-29 1478: 	Auxiliary.AddFusionProcMix(c,sub,insf,code1,code2)
748ed664c0 2023-06-29 1479: end
748ed664c0 2023-06-29 1480: --Fusion monster, name + name + name
748ed664c0 2023-06-29 1481: function Auxiliary.AddFusionProcCode3(c,code1,code2,code3,sub,insf)
748ed664c0 2023-06-29 1482: 	Auxiliary.AddFusionProcMix(c,sub,insf,code1,code2,code3)
748ed664c0 2023-06-29 1483: end
748ed664c0 2023-06-29 1484: --Fusion monster, name + name + name + name
748ed664c0 2023-06-29 1485: function Auxiliary.AddFusionProcCode4(c,code1,code2,code3,code4,sub,insf)
748ed664c0 2023-06-29 1486: 	Auxiliary.AddFusionProcMix(c,sub,insf,code1,code2,code3,code4)
748ed664c0 2023-06-29 1487: end
748ed664c0 2023-06-29 1488: --Fusion monster, name * n
748ed664c0 2023-06-29 1489: function Auxiliary.AddFusionProcCodeRep(c,code1,cc,sub,insf)
748ed664c0 2023-06-29 1490: 	local code={}
748ed664c0 2023-06-29 1491: 	for i=1,cc do
748ed664c0 2023-06-29 1492: 		code[i]=code1
748ed664c0 2023-06-29 1493: 	end
748ed664c0 2023-06-29 1494: 	Auxiliary.AddFusionProcMix(c,sub,insf,table.unpack(code))
748ed664c0 2023-06-29 1495: end
748ed664c0 2023-06-29 1496: --Fusion monster, name * minc to maxc
748ed664c0 2023-06-29 1497: function Auxiliary.AddFusionProcCodeRep2(c,code1,minc,maxc,sub,insf)
748ed664c0 2023-06-29 1498: 	Auxiliary.AddFusionProcMixRep(c,sub,insf,code1,minc,maxc)
748ed664c0 2023-06-29 1499: end
748ed664c0 2023-06-29 1500: --Fusion monster, name + condition * n
748ed664c0 2023-06-29 1501: function Auxiliary.AddFusionProcCodeFun(c,code1,f,cc,sub,insf)
748ed664c0 2023-06-29 1502: 	local fun={}
748ed664c0 2023-06-29 1503: 	for i=1,cc do
748ed664c0 2023-06-29 1504: 		fun[i]=f
748ed664c0 2023-06-29 1505: 	end
748ed664c0 2023-06-29 1506: 	Auxiliary.AddFusionProcMix(c,sub,insf,code1,table.unpack(fun))
748ed664c0 2023-06-29 1507: end
748ed664c0 2023-06-29 1508: --Fusion monster, condition + condition
748ed664c0 2023-06-29 1509: function Auxiliary.AddFusionProcFun2(c,f1,f2,insf)
748ed664c0 2023-06-29 1510: 	Auxiliary.AddFusionProcMix(c,false,insf,f1,f2)
748ed664c0 2023-06-29 1511: end
748ed664c0 2023-06-29 1512: --Fusion monster, condition * n
748ed664c0 2023-06-29 1513: function Auxiliary.AddFusionProcFunRep(c,f,cc,insf)
748ed664c0 2023-06-29 1514: 	local fun={}
748ed664c0 2023-06-29 1515: 	for i=1,cc do
748ed664c0 2023-06-29 1516: 		fun[i]=f
748ed664c0 2023-06-29 1517: 	end
748ed664c0 2023-06-29 1518: 	Auxiliary.AddFusionProcMix(c,false,insf,table.unpack(fun))
748ed664c0 2023-06-29 1519: end
748ed664c0 2023-06-29 1520: --Fusion monster, condition * minc to maxc
748ed664c0 2023-06-29 1521: function Auxiliary.AddFusionProcFunRep2(c,f,minc,maxc,insf)
748ed664c0 2023-06-29 1522: 	Auxiliary.AddFusionProcMixRep(c,false,insf,f,minc,maxc)
748ed664c0 2023-06-29 1523: end
748ed664c0 2023-06-29 1524: --Fusion monster, condition1 + condition2 * n
748ed664c0 2023-06-29 1525: function Auxiliary.AddFusionProcFunFun(c,f1,f2,cc,insf)
748ed664c0 2023-06-29 1526: 	local fun={}
748ed664c0 2023-06-29 1527: 	for i=1,cc do
748ed664c0 2023-06-29 1528: 		fun[i]=f2
748ed664c0 2023-06-29 1529: 	end
748ed664c0 2023-06-29 1530: 	Auxiliary.AddFusionProcMix(c,false,insf,f1,table.unpack(fun))
748ed664c0 2023-06-29 1531: end
748ed664c0 2023-06-29 1532: --Fusion monster, condition1 + condition2 * minc to maxc
748ed664c0 2023-06-29 1533: function Auxiliary.AddFusionProcFunFunRep(c,f1,f2,minc,maxc,insf)
748ed664c0 2023-06-29 1534: 	Auxiliary.AddFusionProcMixRep(c,false,insf,f2,minc,maxc,f1)
748ed664c0 2023-06-29 1535: end
748ed664c0 2023-06-29 1536: --Fusion monster, name + condition * minc to maxc
748ed664c0 2023-06-29 1537: function Auxiliary.AddFusionProcCodeFunRep(c,code1,f,minc,maxc,sub,insf)
748ed664c0 2023-06-29 1538: 	Auxiliary.AddFusionProcMixRep(c,sub,insf,f,minc,maxc,code1)
748ed664c0 2023-06-29 1539: end
748ed664c0 2023-06-29 1540: --Fusion monster, name + name + condition * minc to maxc
748ed664c0 2023-06-29 1541: function Auxiliary.AddFusionProcCode2FunRep(c,code1,code2,f,minc,maxc,sub,insf)
748ed664c0 2023-06-29 1542: 	Auxiliary.AddFusionProcMixRep(c,sub,insf,f,minc,maxc,code1,code2)
748ed664c0 2023-06-29 1543: end
748ed664c0 2023-06-29 1544: --Fusion monster, Shaddoll materials
748ed664c0 2023-06-29 1545: function Auxiliary.AddFusionProcShaddoll(c,attr)
748ed664c0 2023-06-29 1546: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29 1547: 	e1:SetType(EFFECT_TYPE_SINGLE)
748ed664c0 2023-06-29 1548: 	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
748ed664c0 2023-06-29 1549: 	e1:SetCode(EFFECT_FUSION_MATERIAL)
748ed664c0 2023-06-29 1550: 	e1:SetCondition(Auxiliary.FShaddollCondition(attr))
748ed664c0 2023-06-29 1551: 	e1:SetOperation(Auxiliary.FShaddollOperation(attr))
748ed664c0 2023-06-29 1552: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29 1553: end
748ed664c0 2023-06-29 1554: function Auxiliary.FShaddollFilter(c,fc,attr)
748ed664c0 2023-06-29 1555: 	return (Auxiliary.FShaddollFilter1(c) or Auxiliary.FShaddollFilter2(c,attr)) and c:IsCanBeFusionMaterial(fc) and not c:IsHasEffect(6205579)
748ed664c0 2023-06-29 1556: end
748ed664c0 2023-06-29 1557: function Auxiliary.FShaddollExFilter(c,fc,attr,fe)
748ed664c0 2023-06-29 1558: 	return c:IsFaceup() and not c:IsImmuneToEffect(fe) and Auxiliary.FShaddollFilter(c,fc,attr)
748ed664c0 2023-06-29 1559: end
748ed664c0 2023-06-29 1560: function Auxiliary.FShaddollFilter1(c)
748ed664c0 2023-06-29 1561: 	return c:IsFusionSetCard(0x9d)
748ed664c0 2023-06-29 1562: end
748ed664c0 2023-06-29 1563: function Auxiliary.FShaddollFilter2(c,attr)
748ed664c0 2023-06-29 1564: 	return c:IsFusionAttribute(attr) or c:IsHasEffect(4904633)
748ed664c0 2023-06-29 1565: end
748ed664c0 2023-06-29 1566: function Auxiliary.FShaddollSpFilter1(c,fc,tp,mg,exg,attr,chkf)
748ed664c0 2023-06-29 1567: 	return mg:IsExists(Auxiliary.FShaddollSpFilter2,1,c,fc,tp,c,attr,chkf)
748ed664c0 2023-06-29 1568: 		or (exg and exg:IsExists(Auxiliary.FShaddollSpFilter2,1,c,fc,tp,c,attr,chkf))
748ed664c0 2023-06-29 1569: end
748ed664c0 2023-06-29 1570: function Auxiliary.FShaddollSpFilter2(c,fc,tp,mc,attr,chkf)
748ed664c0 2023-06-29 1571: 	local sg=Group.FromCards(c,mc)
748ed664c0 2023-06-29 1572: 	if sg:IsExists(Auxiliary.TuneMagicianCheckX,1,nil,sg,EFFECT_TUNE_MAGICIAN_F) then return false end
748ed664c0 2023-06-29 1573: 	if not Auxiliary.MustMaterialCheck(sg,tp,EFFECT_MUST_BE_FMATERIAL) then return false end
748ed664c0 2023-06-29 1574: 	if Auxiliary.FCheckAdditional and not Auxiliary.FCheckAdditional(tp,sg,fc)
748ed664c0 2023-06-29 1575: 		or Auxiliary.FGoalCheckAdditional and not Auxiliary.FGoalCheckAdditional(tp,sg,fc) then return false end
748ed664c0 2023-06-29 1576: 	return ((Auxiliary.FShaddollFilter1(c) and Auxiliary.FShaddollFilter2(mc,attr))
748ed664c0 2023-06-29 1577: 		or (Auxiliary.FShaddollFilter2(c,attr) and Auxiliary.FShaddollFilter1(mc)))
748ed664c0 2023-06-29 1578: 		and (chkf==PLAYER_NONE or Duel.GetLocationCountFromEx(tp,tp,sg,fc)>0)
748ed664c0 2023-06-29 1579: end
748ed664c0 2023-06-29 1580: function Auxiliary.FShaddollCondition(attr)
748ed664c0 2023-06-29 1581: 	return 	function(e,g,gc,chkf)
748ed664c0 2023-06-29 1582: 				if g==nil then return Auxiliary.MustMaterialCheck(nil,e:GetHandlerPlayer(),EFFECT_MUST_BE_FMATERIAL) end
748ed664c0 2023-06-29 1583: 				local c=e:GetHandler()
748ed664c0 2023-06-29 1584: 				local mg=g:Filter(Auxiliary.FShaddollFilter,nil,c,attr)
748ed664c0 2023-06-29 1585: 				local tp=e:GetHandlerPlayer()
748ed664c0 2023-06-29 1586: 				local fc=Duel.GetFieldCard(tp,LOCATION_FZONE,0)
748ed664c0 2023-06-29 1587: 				local exg=nil
748ed664c0 2023-06-29 1588: 				if fc and fc:IsHasEffect(81788994) and fc:IsCanRemoveCounter(tp,0x16,3,REASON_EFFECT) then
748ed664c0 2023-06-29 1589: 					local fe=fc:IsHasEffect(81788994)
748ed664c0 2023-06-29 1590: 					exg=Duel.GetMatchingGroup(Auxiliary.FShaddollExFilter,tp,0,LOCATION_MZONE,mg,c,attr,fe)
748ed664c0 2023-06-29 1591: 				end
748ed664c0 2023-06-29 1592: 				if gc then
748ed664c0 2023-06-29 1593: 					if not mg:IsContains(gc) then return false end
748ed664c0 2023-06-29 1594: 					return Auxiliary.FShaddollSpFilter1(gc,c,tp,mg,exg,attr,chkf)
748ed664c0 2023-06-29 1595: 				end
748ed664c0 2023-06-29 1596: 				return mg:IsExists(Auxiliary.FShaddollSpFilter1,1,nil,c,tp,mg,exg,attr,chkf)
748ed664c0 2023-06-29 1597: 			end
748ed664c0 2023-06-29 1598: end
748ed664c0 2023-06-29 1599: function Auxiliary.FShaddollOperation(attr)
748ed664c0 2023-06-29 1600: 	return	function(e,tp,eg,ep,ev,re,r,rp,gc,chkf)
748ed664c0 2023-06-29 1601: 				local c=e:GetHandler()
748ed664c0 2023-06-29 1602: 				local mg=eg:Filter(Auxiliary.FShaddollFilter,nil,c,attr)
748ed664c0 2023-06-29 1603: 				local fc=Duel.GetFieldCard(tp,LOCATION_FZONE,0)
748ed664c0 2023-06-29 1604: 				local exg=nil
748ed664c0 2023-06-29 1605: 				if fc and fc:IsHasEffect(81788994) and fc:IsCanRemoveCounter(tp,0x16,3,REASON_EFFECT) then
748ed664c0 2023-06-29 1606: 					local fe=fc:IsHasEffect(81788994)
748ed664c0 2023-06-29 1607: 					exg=Duel.GetMatchingGroup(Auxiliary.FShaddollExFilter,tp,0,LOCATION_MZONE,mg,c,attr,fe)
748ed664c0 2023-06-29 1608: 				end
748ed664c0 2023-06-29 1609: 				local g=nil
748ed664c0 2023-06-29 1610: 				if gc then
748ed664c0 2023-06-29 1611: 					g=Group.FromCards(gc)
748ed664c0 2023-06-29 1612: 					mg:RemoveCard(gc)
748ed664c0 2023-06-29 1613: 				else
748ed664c0 2023-06-29 1614: 					Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FMATERIAL)
748ed664c0 2023-06-29 1615: 					g=mg:FilterSelect(tp,Auxiliary.FShaddollSpFilter1,1,1,nil,c,tp,mg,exg,attr,chkf)
748ed664c0 2023-06-29 1616: 					mg:Sub(g)
748ed664c0 2023-06-29 1617: 				end
748ed664c0 2023-06-29 1618: 				if exg and exg:IsExists(Auxiliary.FShaddollSpFilter2,1,nil,c,tp,g:GetFirst(),attr,chkf)
748ed664c0 2023-06-29 1619: 					and (mg:GetCount()==0 or (exg:GetCount()>0 and Duel.SelectYesNo(tp,aux.Stringid(81788994,0)))) then
748ed664c0 2023-06-29 1620: 					fc:RemoveCounter(tp,0x16,3,REASON_EFFECT)
748ed664c0 2023-06-29 1621: 					Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FMATERIAL)
748ed664c0 2023-06-29 1622: 					local sg=exg:FilterSelect(tp,Auxiliary.FShaddollSpFilter2,1,1,nil,c,tp,g:GetFirst(),attr,chkf)
748ed664c0 2023-06-29 1623: 					g:Merge(sg)
748ed664c0 2023-06-29 1624: 				else
748ed664c0 2023-06-29 1625: 					Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_FMATERIAL)
748ed664c0 2023-06-29 1626: 					local sg=mg:FilterSelect(tp,Auxiliary.FShaddollSpFilter2,1,1,nil,c,tp,g:GetFirst(),attr,chkf)
748ed664c0 2023-06-29 1627: 					g:Merge(sg)
748ed664c0 2023-06-29 1628: 				end
748ed664c0 2023-06-29 1629: 				Duel.SetFusionMaterial(g)
748ed664c0 2023-06-29 1630: 			end
748ed664c0 2023-06-29 1631: end
748ed664c0 2023-06-29 1632: function Auxiliary.AddContactFusionProcedure(c,filter,self_location,opponent_location,mat_operation,...)
748ed664c0 2023-06-29 1633: 	local self_location=self_location or 0
748ed664c0 2023-06-29 1634: 	local opponent_location=opponent_location or 0
748ed664c0 2023-06-29 1635: 	local operation_params={...}
748ed664c0 2023-06-29 1636: 	local e2=Effect.CreateEffect(c)
748ed664c0 2023-06-29 1637: 	e2:SetType(EFFECT_TYPE_FIELD)
748ed664c0 2023-06-29 1638: 	e2:SetCode(EFFECT_SPSUMMON_PROC)
748ed664c0 2023-06-29 1639: 	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
748ed664c0 2023-06-29 1640: 	e2:SetRange(LOCATION_EXTRA)
748ed664c0 2023-06-29 1641: 	e2:SetCondition(Auxiliary.ContactFusionCondition(filter,self_location,opponent_location))
748ed664c0 2023-06-29 1642: 	e2:SetOperation(Auxiliary.ContactFusionOperation(filter,self_location,opponent_location,mat_operation,operation_params))
748ed664c0 2023-06-29 1643: 	c:RegisterEffect(e2)
748ed664c0 2023-06-29 1644: 	return e2
748ed664c0 2023-06-29 1645: end
748ed664c0 2023-06-29 1646: function Auxiliary.ContactFusionMaterialFilter(c,fc,filter)
748ed664c0 2023-06-29 1647: 	return c:IsCanBeFusionMaterial(fc,SUMMON_TYPE_SPECIAL) and (not filter or filter(c,fc))
748ed664c0 2023-06-29 1648: end
748ed664c0 2023-06-29 1649: function Auxiliary.ContactFusionCondition(filter,self_location,opponent_location)
748ed664c0 2023-06-29 1650: 	return	function(e,c)
748ed664c0 2023-06-29 1651: 				if c==nil then return true end
748ed664c0 2023-06-29 1652: 				if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end
748ed664c0 2023-06-29 1653: 				local tp=c:GetControler()
748ed664c0 2023-06-29 1654: 				local mg=Duel.GetMatchingGroup(Auxiliary.ContactFusionMaterialFilter,tp,self_location,opponent_location,c,c,filter)
748ed664c0 2023-06-29 1655: 				return c:CheckFusionMaterial(mg,nil,tp|0x200)
748ed664c0 2023-06-29 1656: 			end
748ed664c0 2023-06-29 1657: end
748ed664c0 2023-06-29 1658: function Auxiliary.ContactFusionOperation(filter,self_location,opponent_location,mat_operation,operation_params)
748ed664c0 2023-06-29 1659: 	return	function(e,tp,eg,ep,ev,re,r,rp,c)
748ed664c0 2023-06-29 1660: 				local mg=Duel.GetMatchingGroup(Auxiliary.ContactFusionMaterialFilter,tp,self_location,opponent_location,c,c,filter)
748ed664c0 2023-06-29 1661: 				local g=Duel.SelectFusionMaterial(tp,c,mg,nil,tp|0x200)
748ed664c0 2023-06-29 1662: 				c:SetMaterial(g)
748ed664c0 2023-06-29 1663: 				mat_operation(g,table.unpack(operation_params))
748ed664c0 2023-06-29 1664: 			end
748ed664c0 2023-06-29 1665: end
748ed664c0 2023-06-29 1666: function Auxiliary.AddRitualProcUltimate(c,filter,level_function,greater_or_equal,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1667: 	summon_location=summon_location or LOCATION_HAND
748ed664c0 2023-06-29 1668: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29 1669: 	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
748ed664c0 2023-06-29 1670: 	e1:SetType(EFFECT_TYPE_ACTIVATE)
748ed664c0 2023-06-29 1671: 	e1:SetCode(EVENT_FREE_CHAIN)
748ed664c0 2023-06-29 1672: 	e1:SetTarget(Auxiliary.RitualUltimateTarget(filter,level_function,greater_or_equal,summon_location,grave_filter,mat_filter,extra_target))
748ed664c0 2023-06-29 1673: 	e1:SetOperation(Auxiliary.RitualUltimateOperation(filter,level_function,greater_or_equal,summon_location,grave_filter,mat_filter,extra_operation))
748ed664c0 2023-06-29 1674: 	if not pause then
748ed664c0 2023-06-29 1675: 		c:RegisterEffect(e1)
748ed664c0 2023-06-29 1676: 	end
748ed664c0 2023-06-29 1677: 	return e1
748ed664c0 2023-06-29 1678: end
748ed664c0 2023-06-29 1679: function Auxiliary.RitualCheckGreater(g,c,lv)
748ed664c0 2023-06-29 1680: 	Duel.SetSelectedCard(g)
748ed664c0 2023-06-29 1681: 	return g:CheckWithSumGreater(Card.GetRitualLevel,lv,c)
748ed664c0 2023-06-29 1682: end
748ed664c0 2023-06-29 1683: function Auxiliary.RitualCheckEqual(g,c,lv)
748ed664c0 2023-06-29 1684: 	return g:CheckWithSumEqual(Card.GetRitualLevel,lv,#g,#g,c)
748ed664c0 2023-06-29 1685: end
748ed664c0 2023-06-29 1686: Auxiliary.RCheckAdditional=nil
748ed664c0 2023-06-29 1687: function Auxiliary.RitualCheck(g,tp,c,lv,greater_or_equal)
748ed664c0 2023-06-29 1688: 	return Auxiliary["RitualCheck"..greater_or_equal](g,c,lv) and Duel.GetMZoneCount(tp,g,tp)>0 and (not c.mat_group_check or c.mat_group_check(g,tp))
748ed664c0 2023-06-29 1689: 		and (not Auxiliary.RCheckAdditional or Auxiliary.RCheckAdditional(tp,g,c))
748ed664c0 2023-06-29 1690: end
748ed664c0 2023-06-29 1691: function Auxiliary.RitualCheckAdditionalLevel(c,rc)
748ed664c0 2023-06-29 1692: 	local raw_level=c:GetRitualLevel(rc)
748ed664c0 2023-06-29 1693: 	local lv1=raw_level&0xffff
748ed664c0 2023-06-29 1694: 	local lv2=raw_level>>16
748ed664c0 2023-06-29 1695: 	if lv2>0 then
748ed664c0 2023-06-29 1696: 		return math.min(lv1,lv2)
748ed664c0 2023-06-29 1697: 	else
748ed664c0 2023-06-29 1698: 		return lv1
748ed664c0 2023-06-29 1699: 	end
748ed664c0 2023-06-29 1700: end
748ed664c0 2023-06-29 1701: Auxiliary.RGCheckAdditional=nil
748ed664c0 2023-06-29 1702: function Auxiliary.RitualCheckAdditional(c,lv,greater_or_equal)
748ed664c0 2023-06-29 1703: 	if greater_or_equal=="Equal" then
748ed664c0 2023-06-29 1704: 		return	function(g)
748ed664c0 2023-06-29 1705: 					return (not Auxiliary.RGCheckAdditional or Auxiliary.RGCheckAdditional(g)) and g:GetSum(Auxiliary.RitualCheckAdditionalLevel,c)<=lv
748ed664c0 2023-06-29 1706: 				end
748ed664c0 2023-06-29 1707: 	else
748ed664c0 2023-06-29 1708: 		return	function(g,ec)
748ed664c0 2023-06-29 1709: 					if ec then
748ed664c0 2023-06-29 1710: 						return (not Auxiliary.RGCheckAdditional or Auxiliary.RGCheckAdditional(g,ec)) and g:GetSum(Auxiliary.RitualCheckAdditionalLevel,c)-Auxiliary.RitualCheckAdditionalLevel(ec,c)<=lv
748ed664c0 2023-06-29 1711: 					else
748ed664c0 2023-06-29 1712: 						return not Auxiliary.RGCheckAdditional or Auxiliary.RGCheckAdditional(g)
748ed664c0 2023-06-29 1713: 					end
748ed664c0 2023-06-29 1714: 				end
748ed664c0 2023-06-29 1715: 	end
748ed664c0 2023-06-29 1716: end
748ed664c0 2023-06-29 1717: function Auxiliary.RitualUltimateFilter(c,filter,e,tp,m1,m2,level_function,greater_or_equal,chk)
748ed664c0 2023-06-29 1718: 	if bit.band(c:GetType(),0x81)~=0x81 or (filter and not filter(c,e,tp,chk)) or not c:IsCanBeSpecialSummoned(e,SUMMON_TYPE_RITUAL,tp,false,true) then return false end
748ed664c0 2023-06-29 1719: 	local mg=m1:Filter(Card.IsCanBeRitualMaterial,c,c)
748ed664c0 2023-06-29 1720: 	if m2 then
748ed664c0 2023-06-29 1721: 		mg:Merge(m2)
748ed664c0 2023-06-29 1722: 	end
748ed664c0 2023-06-29 1723: 	if c.mat_filter then
748ed664c0 2023-06-29 1724: 		mg=mg:Filter(c.mat_filter,c,tp)
748ed664c0 2023-06-29 1725: 	else
748ed664c0 2023-06-29 1726: 		mg:RemoveCard(c)
748ed664c0 2023-06-29 1727: 	end
748ed664c0 2023-06-29 1728: 	local lv=level_function(c)
748ed664c0 2023-06-29 1729: 	Auxiliary.GCheckAdditional=Auxiliary.RitualCheckAdditional(c,lv,greater_or_equal)
748ed664c0 2023-06-29 1730: 	local res=mg:CheckSubGroup(Auxiliary.RitualCheck,1,lv,tp,c,lv,greater_or_equal)
748ed664c0 2023-06-29 1731: 	Auxiliary.GCheckAdditional=nil
748ed664c0 2023-06-29 1732: 	return res
748ed664c0 2023-06-29 1733: end
748ed664c0 2023-06-29 1734: function Auxiliary.RitualExtraFilter(c,f)
748ed664c0 2023-06-29 1735: 	return c:GetLevel()>0 and f(c) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemove()
748ed664c0 2023-06-29 1736: end
748ed664c0 2023-06-29 1737: function Auxiliary.RitualUltimateTarget(filter,level_function,greater_or_equal,summon_location,grave_filter,mat_filter,extra_target)
748ed664c0 2023-06-29 1738: 	return	function(e,tp,eg,ep,ev,re,r,rp,chk)
748ed664c0 2023-06-29 1739: 				if chk==0 then
748ed664c0 2023-06-29 1740: 					local mg=Duel.GetRitualMaterial(tp)
748ed664c0 2023-06-29 1741: 					if mat_filter then mg=mg:Filter(mat_filter,nil,e,tp,true) end
748ed664c0 2023-06-29 1742: 					local exg=nil
748ed664c0 2023-06-29 1743: 					if grave_filter then
748ed664c0 2023-06-29 1744: 						exg=Duel.GetMatchingGroup(Auxiliary.RitualExtraFilter,tp,LOCATION_GRAVE,0,nil,grave_filter)
748ed664c0 2023-06-29 1745: 					end
748ed664c0 2023-06-29 1746: 					return Duel.IsExistingMatchingCard(Auxiliary.RitualUltimateFilter,tp,summon_location,0,1,nil,filter,e,tp,mg,exg,level_function,greater_or_equal,true)
748ed664c0 2023-06-29 1747: 				end
748ed664c0 2023-06-29 1748: 				Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,summon_location)
748ed664c0 2023-06-29 1749: 				if grave_filter then
748ed664c0 2023-06-29 1750: 					Duel.SetOperationInfo(0,CATEGORY_REMOVE,nil,0,tp,LOCATION_GRAVE)
748ed664c0 2023-06-29 1751: 				end
748ed664c0 2023-06-29 1752: 				if extra_target then
748ed664c0 2023-06-29 1753: 					extra_target(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 1754: 				end
748ed664c0 2023-06-29 1755: 			end
748ed664c0 2023-06-29 1756: end
748ed664c0 2023-06-29 1757: function Auxiliary.RitualUltimateOperation(filter,level_function,greater_or_equal,summon_location,grave_filter,mat_filter,extra_operation)
748ed664c0 2023-06-29 1758: 	return	function(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 1759: 				::RitualUltimateSelectStart::
748ed664c0 2023-06-29 1760: 				local mg=Duel.GetRitualMaterial(tp)
748ed664c0 2023-06-29 1761: 				if mat_filter then mg=mg:Filter(mat_filter,nil,e,tp) end
748ed664c0 2023-06-29 1762: 				local exg=nil
748ed664c0 2023-06-29 1763: 				if grave_filter then
748ed664c0 2023-06-29 1764: 					exg=Duel.GetMatchingGroup(Auxiliary.RitualExtraFilter,tp,LOCATION_GRAVE,0,nil,grave_filter)
748ed664c0 2023-06-29 1765: 				end
748ed664c0 2023-06-29 1766: 				Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)
748ed664c0 2023-06-29 1767: 				local tg=Duel.SelectMatchingCard(tp,Auxiliary.NecroValleyFilter(Auxiliary.RitualUltimateFilter),tp,summon_location,0,1,1,nil,filter,e,tp,mg,exg,level_function,greater_or_equal)
748ed664c0 2023-06-29 1768: 				local tc=tg:GetFirst()
748ed664c0 2023-06-29 1769: 				local mat
748ed664c0 2023-06-29 1770: 				if tc then
748ed664c0 2023-06-29 1771: 					mg=mg:Filter(Card.IsCanBeRitualMaterial,tc,tc)
748ed664c0 2023-06-29 1772: 					if exg then
748ed664c0 2023-06-29 1773: 						mg:Merge(exg)
748ed664c0 2023-06-29 1774: 					end
748ed664c0 2023-06-29 1775: 					if tc.mat_filter then
748ed664c0 2023-06-29 1776: 						mg=mg:Filter(tc.mat_filter,tc,tp)
748ed664c0 2023-06-29 1777: 					else
748ed664c0 2023-06-29 1778: 						mg:RemoveCard(tc)
748ed664c0 2023-06-29 1779: 					end
748ed664c0 2023-06-29 1780: 					Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_RELEASE)
748ed664c0 2023-06-29 1781: 					local lv=level_function(tc)
748ed664c0 2023-06-29 1782: 					Auxiliary.GCheckAdditional=Auxiliary.RitualCheckAdditional(tc,lv,greater_or_equal)
748ed664c0 2023-06-29 1783: 					mat=mg:SelectSubGroup(tp,Auxiliary.RitualCheck,true,1,lv,tp,tc,lv,greater_or_equal)
748ed664c0 2023-06-29 1784: 					Auxiliary.GCheckAdditional=nil
748ed664c0 2023-06-29 1785: 					if not mat then goto RitualUltimateSelectStart end
748ed664c0 2023-06-29 1786: 					tc:SetMaterial(mat)
748ed664c0 2023-06-29 1787: 					Duel.ReleaseRitualMaterial(mat)
748ed664c0 2023-06-29 1788: 					Duel.BreakEffect()
748ed664c0 2023-06-29 1789: 					Duel.SpecialSummon(tc,SUMMON_TYPE_RITUAL,tp,tp,false,true,POS_FACEUP)
748ed664c0 2023-06-29 1790: 					tc:CompleteProcedure()
748ed664c0 2023-06-29 1791: 				end
748ed664c0 2023-06-29 1792: 				if extra_operation then
748ed664c0 2023-06-29 1793: 					extra_operation(e,tp,eg,ep,ev,re,r,rp,tc,mat)
748ed664c0 2023-06-29 1794: 				end
748ed664c0 2023-06-29 1795: 			end
748ed664c0 2023-06-29 1796: end
748ed664c0 2023-06-29 1797: --Ritual Summon, geq fixed lv
748ed664c0 2023-06-29 1798: function Auxiliary.AddRitualProcGreater(c,filter,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1799: 	return Auxiliary.AddRitualProcUltimate(c,filter,Card.GetOriginalLevel,"Greater",summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1800: end
748ed664c0 2023-06-29 1801: function Auxiliary.AddRitualProcGreaterCode(c,code1,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1802: 	Auxiliary.AddCodeList(c,code1)
748ed664c0 2023-06-29 1803: 	return Auxiliary.AddRitualProcGreater(c,Auxiliary.FilterBoolFunction(Card.IsCode,code1),summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1804: end
748ed664c0 2023-06-29 1805: --Ritual Summon, equal to fixed lv
748ed664c0 2023-06-29 1806: function Auxiliary.AddRitualProcEqual(c,filter,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1807: 	return Auxiliary.AddRitualProcUltimate(c,filter,Card.GetOriginalLevel,"Equal",summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1808: end
748ed664c0 2023-06-29 1809: function Auxiliary.AddRitualProcEqualCode(c,code1,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1810: 	Auxiliary.AddCodeList(c,code1)
748ed664c0 2023-06-29 1811: 	return Auxiliary.AddRitualProcEqual(c,Auxiliary.FilterBoolFunction(Card.IsCode,code1),summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1812: end
748ed664c0 2023-06-29 1813: --Ritual Summon, equal to monster lv
748ed664c0 2023-06-29 1814: function Auxiliary.AddRitualProcEqual2(c,filter,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1815: 	return Auxiliary.AddRitualProcUltimate(c,filter,Card.GetLevel,"Equal",summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1816: end
748ed664c0 2023-06-29 1817: function Auxiliary.AddRitualProcEqual2Code(c,code1,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1818: 	Auxiliary.AddCodeList(c,code1)
748ed664c0 2023-06-29 1819: 	return Auxiliary.AddRitualProcEqual2(c,Auxiliary.FilterBoolFunction(Card.IsCode,code1),summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1820: end
748ed664c0 2023-06-29 1821: function Auxiliary.AddRitualProcEqual2Code2(c,code1,code2,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1822: 	Auxiliary.AddCodeList(c,code1,code2)
748ed664c0 2023-06-29 1823: 	return Auxiliary.AddRitualProcEqual2(c,Auxiliary.FilterBoolFunction(Card.IsCode,code1,code2),summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1824: end
748ed664c0 2023-06-29 1825: --Ritual Summon, geq monster lv
748ed664c0 2023-06-29 1826: function Auxiliary.AddRitualProcGreater2(c,filter,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1827: 	return Auxiliary.AddRitualProcUltimate(c,filter,Card.GetLevel,"Greater",summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1828: end
748ed664c0 2023-06-29 1829: function Auxiliary.AddRitualProcGreater2Code(c,code1,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1830: 	Auxiliary.AddCodeList(c,code1)
748ed664c0 2023-06-29 1831: 	return Auxiliary.AddRitualProcGreater2(c,Auxiliary.FilterBoolFunction(Card.IsCode,code1),summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1832: end
748ed664c0 2023-06-29 1833: function Auxiliary.AddRitualProcGreater2Code2(c,code1,code2,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1834: 	Auxiliary.AddCodeList(c,code1,code2)
748ed664c0 2023-06-29 1835: 	return Auxiliary.AddRitualProcGreater2(c,Auxiliary.FilterBoolFunction(Card.IsCode,code1,code2),summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)
748ed664c0 2023-06-29 1836: end
748ed664c0 2023-06-29 1837: --add procedure to Pendulum monster, also allows registeration of activation effect
748ed664c0 2023-06-29 1838: function Auxiliary.EnablePendulumAttribute(c,reg)
748ed664c0 2023-06-29 1839: 	if not Auxiliary.PendulumChecklist then
748ed664c0 2023-06-29 1840: 		Auxiliary.PendulumChecklist=0
748ed664c0 2023-06-29 1841: 		local ge1=Effect.GlobalEffect()
748ed664c0 2023-06-29 1842: 		ge1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
748ed664c0 2023-06-29 1843: 		ge1:SetCode(EVENT_PHASE_START+PHASE_DRAW)
748ed664c0 2023-06-29 1844: 		ge1:SetOperation(Auxiliary.PendulumReset)
748ed664c0 2023-06-29 1845: 		Duel.RegisterEffect(ge1,0)
748ed664c0 2023-06-29 1846: 	end
748ed664c0 2023-06-29 1847: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29 1848: 	e1:SetDescription(1163)
748ed664c0 2023-06-29 1849: 	e1:SetType(EFFECT_TYPE_FIELD)
748ed664c0 2023-06-29 1850: 	e1:SetCode(EFFECT_SPSUMMON_PROC_G)
748ed664c0 2023-06-29 1851: 	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
748ed664c0 2023-06-29 1852: 	e1:SetRange(LOCATION_PZONE)
748ed664c0 2023-06-29 1853: 	e1:SetCondition(Auxiliary.PendCondition())
748ed664c0 2023-06-29 1854: 	e1:SetOperation(Auxiliary.PendOperation())
748ed664c0 2023-06-29 1855: 	e1:SetValue(SUMMON_TYPE_PENDULUM)
748ed664c0 2023-06-29 1856: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29 1857: 	--register by default
748ed664c0 2023-06-29 1858: 	if reg==nil or reg then
748ed664c0 2023-06-29 1859: 		local e2=Effect.CreateEffect(c)
748ed664c0 2023-06-29 1860: 		e2:SetDescription(1160)
748ed664c0 2023-06-29 1861: 		e2:SetType(EFFECT_TYPE_ACTIVATE)
748ed664c0 2023-06-29 1862: 		e2:SetCode(EVENT_FREE_CHAIN)
748ed664c0 2023-06-29 1863: 		e2:SetRange(LOCATION_HAND)
748ed664c0 2023-06-29 1864: 		c:RegisterEffect(e2)
748ed664c0 2023-06-29 1865: 	end
748ed664c0 2023-06-29 1866: end
748ed664c0 2023-06-29 1867: function Auxiliary.PendulumReset(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 1868: 	Auxiliary.PendulumChecklist=0
748ed664c0 2023-06-29 1869: end
748ed664c0 2023-06-29 1870: function Auxiliary.PConditionExtraFilterSpecific(c,e,tp,lscale,rscale,te)
748ed664c0 2023-06-29 1871: 	if not te then return true end
748ed664c0 2023-06-29 1872: 	local f=te:GetValue()
748ed664c0 2023-06-29 1873: 	return not f or f(te,c,e,tp,lscale,rscale)
748ed664c0 2023-06-29 1874: end
748ed664c0 2023-06-29 1875: function Auxiliary.PConditionExtraFilter(c,e,tp,lscale,rscale,eset)
748ed664c0 2023-06-29 1876: 	for _,te in ipairs(eset) do
748ed664c0 2023-06-29 1877: 		if Auxiliary.PConditionExtraFilterSpecific(c,e,tp,lscale,rscale,te) then return true end
748ed664c0 2023-06-29 1878: 	end
748ed664c0 2023-06-29 1879: 	return false
748ed664c0 2023-06-29 1880: end
748ed664c0 2023-06-29 1881: function Auxiliary.PConditionFilter(c,e,tp,lscale,rscale,eset)
748ed664c0 2023-06-29 1882: 	local lv=0
748ed664c0 2023-06-29 1883: 	if c.pendulum_level then
748ed664c0 2023-06-29 1884: 		lv=c.pendulum_level
748ed664c0 2023-06-29 1885: 	else
748ed664c0 2023-06-29 1886: 		lv=c:GetLevel()
748ed664c0 2023-06-29 1887: 	end
748ed664c0 2023-06-29 1888: 	local bool=Auxiliary.PendulumSummonableBool(c)
748ed664c0 2023-06-29 1889: 	return (c:IsLocation(LOCATION_HAND) or (c:IsFaceup() and c:IsType(TYPE_PENDULUM)))
748ed664c0 2023-06-29 1890: 		and lv>lscale and lv<rscale and c:IsCanBeSpecialSummoned(e,SUMMON_TYPE_PENDULUM,tp,bool,bool)
748ed664c0 2023-06-29 1891: 		and not c:IsForbidden()
748ed664c0 2023-06-29 1892: 		and (Auxiliary.PendulumChecklist&(0x1<<tp)==0 or Auxiliary.PConditionExtraFilter(c,e,tp,lscale,rscale,eset))
748ed664c0 2023-06-29 1893: end
748ed664c0 2023-06-29 1894: function Auxiliary.PendCondition()
748ed664c0 2023-06-29 1895: 	return	function(e,c,og)
748ed664c0 2023-06-29 1896: 				if c==nil then return true end
748ed664c0 2023-06-29 1897: 				local tp=c:GetControler()
748ed664c0 2023-06-29 1898: 				local eset={Duel.IsPlayerAffectedByEffect(tp,EFFECT_EXTRA_PENDULUM_SUMMON)}
748ed664c0 2023-06-29 1899: 				if Auxiliary.PendulumChecklist&(0x1<<tp)~=0 and #eset==0 then return false end
748ed664c0 2023-06-29 1900: 				local rpz=Duel.GetFieldCard(tp,LOCATION_PZONE,1)
748ed664c0 2023-06-29 1901: 				if rpz==nil or c==rpz then return false end
748ed664c0 2023-06-29 1902: 				local lscale=c:GetLeftScale()
748ed664c0 2023-06-29 1903: 				local rscale=rpz:GetRightScale()
748ed664c0 2023-06-29 1904: 				if lscale>rscale then lscale,rscale=rscale,lscale end
748ed664c0 2023-06-29 1905: 				local loc=0
748ed664c0 2023-06-29 1906: 				if Duel.GetLocationCount(tp,LOCATION_MZONE)>0 then loc=loc+LOCATION_HAND end
748ed664c0 2023-06-29 1907: 				if Duel.GetLocationCountFromEx(tp,tp,nil,TYPE_PENDULUM)>0 then loc=loc+LOCATION_EXTRA end
748ed664c0 2023-06-29 1908: 				if loc==0 then return false end
748ed664c0 2023-06-29 1909: 				local g=nil
748ed664c0 2023-06-29 1910: 				if og then
748ed664c0 2023-06-29 1911: 					g=og:Filter(Card.IsLocation,nil,loc)
748ed664c0 2023-06-29 1912: 				else
748ed664c0 2023-06-29 1913: 					g=Duel.GetFieldGroup(tp,loc,0)
748ed664c0 2023-06-29 1914: 				end
748ed664c0 2023-06-29 1915: 				return g:IsExists(Auxiliary.PConditionFilter,1,nil,e,tp,lscale,rscale,eset)
748ed664c0 2023-06-29 1916: 			end
748ed664c0 2023-06-29 1917: end
748ed664c0 2023-06-29 1918: function Auxiliary.PendOperationCheck(ft1,ft2,ft)
748ed664c0 2023-06-29 1919: 	return	function(g)
748ed664c0 2023-06-29 1920: 				local exg=g:Filter(Card.IsLocation,nil,LOCATION_EXTRA)
748ed664c0 2023-06-29 1921: 				local mg=g-exg
748ed664c0 2023-06-29 1922: 				return #g<=ft and #exg<=ft2 and #mg<=ft1
748ed664c0 2023-06-29 1923: 			end
748ed664c0 2023-06-29 1924: end
748ed664c0 2023-06-29 1925: function Auxiliary.PendOperation()
748ed664c0 2023-06-29 1926: 	return	function(e,tp,eg,ep,ev,re,r,rp,c,sg,og)
748ed664c0 2023-06-29 1927: 				local rpz=Duel.GetFieldCard(tp,LOCATION_PZONE,1)
748ed664c0 2023-06-29 1928: 				local lscale=c:GetLeftScale()
748ed664c0 2023-06-29 1929: 				local rscale=rpz:GetRightScale()
748ed664c0 2023-06-29 1930: 				if lscale>rscale then lscale,rscale=rscale,lscale end
748ed664c0 2023-06-29 1931: 				local eset={Duel.IsPlayerAffectedByEffect(tp,EFFECT_EXTRA_PENDULUM_SUMMON)}
748ed664c0 2023-06-29 1932: 				local tg=nil
748ed664c0 2023-06-29 1933: 				local loc=0
748ed664c0 2023-06-29 1934: 				local ft1=Duel.GetLocationCount(tp,LOCATION_MZONE)
748ed664c0 2023-06-29 1935: 				local ft2=Duel.GetLocationCountFromEx(tp,tp,nil,TYPE_PENDULUM)
748ed664c0 2023-06-29 1936: 				local ft=Duel.GetUsableMZoneCount(tp)
748ed664c0 2023-06-29 1937: 				local ect=c29724053 and Duel.IsPlayerAffectedByEffect(tp,29724053) and c29724053[tp]
748ed664c0 2023-06-29 1938: 				if ect and ect<ft2 then ft2=ect end
748ed664c0 2023-06-29 1939: 				if Duel.IsPlayerAffectedByEffect(tp,59822133) then
748ed664c0 2023-06-29 1940: 					if ft1>0 then ft1=1 end
748ed664c0 2023-06-29 1941: 					if ft2>0 then ft2=1 end
748ed664c0 2023-06-29 1942: 					ft=1
748ed664c0 2023-06-29 1943: 				end
748ed664c0 2023-06-29 1944: 				if ft1>0 then loc=loc|LOCATION_HAND end
748ed664c0 2023-06-29 1945: 				if ft2>0 then loc=loc|LOCATION_EXTRA end
748ed664c0 2023-06-29 1946: 				if og then
748ed664c0 2023-06-29 1947: 					tg=og:Filter(Card.IsLocation,nil,loc):Filter(Auxiliary.PConditionFilter,nil,e,tp,lscale,rscale,eset)
748ed664c0 2023-06-29 1948: 				else
748ed664c0 2023-06-29 1949: 					tg=Duel.GetMatchingGroup(Auxiliary.PConditionFilter,tp,loc,0,nil,e,tp,lscale,rscale,eset)
748ed664c0 2023-06-29 1950: 				end
748ed664c0 2023-06-29 1951: 				local ce=nil
748ed664c0 2023-06-29 1952: 				local b1=Auxiliary.PendulumChecklist&(0x1<<tp)==0
748ed664c0 2023-06-29 1953: 				local b2=#eset>0
748ed664c0 2023-06-29 1954: 				if b1 and b2 then
748ed664c0 2023-06-29 1955: 					local options={1163}
748ed664c0 2023-06-29 1956: 					for _,te in ipairs(eset) do
748ed664c0 2023-06-29 1957: 						table.insert(options,te:GetDescription())
748ed664c0 2023-06-29 1958: 					end
748ed664c0 2023-06-29 1959: 					local op=Duel.SelectOption(tp,table.unpack(options))
748ed664c0 2023-06-29 1960: 					if op>0 then
748ed664c0 2023-06-29 1961: 						ce=eset[op]
748ed664c0 2023-06-29 1962: 					end
748ed664c0 2023-06-29 1963: 				elseif b2 and not b1 then
748ed664c0 2023-06-29 1964: 					local options={}
748ed664c0 2023-06-29 1965: 					for _,te in ipairs(eset) do
748ed664c0 2023-06-29 1966: 						table.insert(options,te:GetDescription())
748ed664c0 2023-06-29 1967: 					end
748ed664c0 2023-06-29 1968: 					local op=Duel.SelectOption(tp,table.unpack(options))
748ed664c0 2023-06-29 1969: 					ce=eset[op+1]
748ed664c0 2023-06-29 1970: 				end
748ed664c0 2023-06-29 1971: 				if ce then
748ed664c0 2023-06-29 1972: 					tg=tg:Filter(Auxiliary.PConditionExtraFilterSpecific,nil,e,tp,lscale,rscale,ce)
748ed664c0 2023-06-29 1973: 				end
748ed664c0 2023-06-29 1974: 				Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)
748ed664c0 2023-06-29 1975: 				Auxiliary.GCheckAdditional=Auxiliary.PendOperationCheck(ft1,ft2,ft)
748ed664c0 2023-06-29 1976: 				local g=tg:SelectSubGroup(tp,aux.TRUE,true,1,math.min(#tg,ft))
748ed664c0 2023-06-29 1977: 				Auxiliary.GCheckAdditional=nil
748ed664c0 2023-06-29 1978: 				if not g then return end
748ed664c0 2023-06-29 1979: 				if ce then
748ed664c0 2023-06-29 1980: 					Duel.Hint(HINT_CARD,0,ce:GetOwner():GetOriginalCode())
748ed664c0 2023-06-29 1981: 					ce:UseCountLimit(tp)
748ed664c0 2023-06-29 1982: 				else
748ed664c0 2023-06-29 1983: 					Auxiliary.PendulumChecklist=Auxiliary.PendulumChecklist|(0x1<<tp)
748ed664c0 2023-06-29 1984: 				end
748ed664c0 2023-06-29 1985: 				sg:Merge(g)
748ed664c0 2023-06-29 1986: 				Duel.HintSelection(Group.FromCards(c))
748ed664c0 2023-06-29 1987: 				Duel.HintSelection(Group.FromCards(rpz))
748ed664c0 2023-06-29 1988: 			end
748ed664c0 2023-06-29 1989: end
748ed664c0 2023-06-29 1990: --enable revive limit for monsters that are also pendulum sumonable from certain locations (Odd-Eyes Revolution Dragon)
748ed664c0 2023-06-29 1991: function Auxiliary.EnableReviveLimitPendulumSummonable(c, loc)
748ed664c0 2023-06-29 1992: 	if c:IsStatus(STATUS_COPYING_EFFECT) then return end
748ed664c0 2023-06-29 1993: 	c:EnableReviveLimit()
748ed664c0 2023-06-29 1994: 	local mt=getmetatable(c)
748ed664c0 2023-06-29 1995: 	if loc==nil then loc=0xff end
748ed664c0 2023-06-29 1996: 	mt.psummonable_location=loc
748ed664c0 2023-06-29 1997: 	--complete procedure on pendulum summon success
748ed664c0 2023-06-29 1998: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29 1999: 	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
748ed664c0 2023-06-29 2000: 	e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_CONTINUOUS)
748ed664c0 2023-06-29 2001: 	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
748ed664c0 2023-06-29 2002: 	e1:SetOperation(Auxiliary.PSSCompleteProcedure)
748ed664c0 2023-06-29 2003: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29 2004: end
748ed664c0 2023-06-29 2005: function Auxiliary.PendulumSummonableBool(c)
748ed664c0 2023-06-29 2006: 	return c.psummonable_location~=nil and c:GetLocation()&c.psummonable_location>0
748ed664c0 2023-06-29 2007: end
748ed664c0 2023-06-29 2008: function Auxiliary.PSSCompleteProcedure(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 2009: 	local c=e:GetHandler()
748ed664c0 2023-06-29 2010: 	if c:IsSummonType(SUMMON_TYPE_PENDULUM) then
748ed664c0 2023-06-29 2011: 		c:CompleteProcedure()
748ed664c0 2023-06-29 2012: 	end
748ed664c0 2023-06-29 2013: end
748ed664c0 2023-06-29 2014: --Link Summon
748ed664c0 2023-06-29 2015: function Auxiliary.AddLinkProcedure(c,f,min,max,gf)
748ed664c0 2023-06-29 2016: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29 2017: 	e1:SetDescription(1166)
748ed664c0 2023-06-29 2018: 	e1:SetType(EFFECT_TYPE_FIELD)
748ed664c0 2023-06-29 2019: 	e1:SetCode(EFFECT_SPSUMMON_PROC)
748ed664c0 2023-06-29 2020: 	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
748ed664c0 2023-06-29 2021: 	e1:SetRange(LOCATION_EXTRA)
748ed664c0 2023-06-29 2022: 	if max==nil then max=c:GetLink() end
748ed664c0 2023-06-29 2023: 	e1:SetCondition(Auxiliary.LinkCondition(f,min,max,gf))
748ed664c0 2023-06-29 2024: 	e1:SetTarget(Auxiliary.LinkTarget(f,min,max,gf))
748ed664c0 2023-06-29 2025: 	e1:SetOperation(Auxiliary.LinkOperation(f,min,max,gf))
748ed664c0 2023-06-29 2026: 	e1:SetValue(SUMMON_TYPE_LINK)
748ed664c0 2023-06-29 2027: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29 2028: 	return e1
748ed664c0 2023-06-29 2029: end
748ed664c0 2023-06-29 2030: function Auxiliary.LConditionFilter(c,f,lc,e)
748ed664c0 2023-06-29 2031: 	return (c:IsFaceup() or not c:IsOnField() or e:IsHasProperty(EFFECT_FLAG_SET_AVAILABLE))
748ed664c0 2023-06-29 2032: 		and c:IsCanBeLinkMaterial(lc) and (not f or f(c))
748ed664c0 2023-06-29 2033: end
748ed664c0 2023-06-29 2034: function Auxiliary.LExtraFilter(c,f,lc,tp)
748ed664c0 2023-06-29 2035: 	if c:IsOnField() and c:IsFacedown() then return false end
748ed664c0 2023-06-29 2036: 	if not c:IsCanBeLinkMaterial(lc) or f and not f(c) then return false end
748ed664c0 2023-06-29 2037: 	local le={c:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)}
748ed664c0 2023-06-29 2038: 	for _,te in pairs(le) do
748ed664c0 2023-06-29 2039: 		local tf=te:GetValue()
748ed664c0 2023-06-29 2040: 		local related,valid=tf(te,lc,nil,c,tp)
748ed664c0 2023-06-29 2041: 		if related then return true end
748ed664c0 2023-06-29 2042: 	end
748ed664c0 2023-06-29 2043: 	return false
748ed664c0 2023-06-29 2044: end
748ed664c0 2023-06-29 2045: function Auxiliary.GetLinkCount(c)
748ed664c0 2023-06-29 2046: 	if c:IsType(TYPE_LINK) and c:GetLink()>1 then
748ed664c0 2023-06-29 2047: 		return 1+0x10000*c:GetLink()
748ed664c0 2023-06-29 2048: 	else return 1 end
748ed664c0 2023-06-29 2049: end
748ed664c0 2023-06-29 2050: function Auxiliary.GetLinkMaterials(tp,f,lc,e)
748ed664c0 2023-06-29 2051: 	local mg=Duel.GetMatchingGroup(Auxiliary.LConditionFilter,tp,LOCATION_MZONE,0,nil,f,lc,e)
748ed664c0 2023-06-29 2052: 	local mg2=Duel.GetMatchingGroup(Auxiliary.LExtraFilter,tp,LOCATION_HAND+LOCATION_SZONE,LOCATION_ONFIELD,nil,f,lc,tp)
748ed664c0 2023-06-29 2053: 	if mg2:GetCount()>0 then mg:Merge(mg2) end
748ed664c0 2023-06-29 2054: 	return mg
748ed664c0 2023-06-29 2055: end
748ed664c0 2023-06-29 2056: function Auxiliary.LCheckOtherMaterial(c,mg,lc,tp)
748ed664c0 2023-06-29 2057: 	local le={c:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)}
748ed664c0 2023-06-29 2058: 	local res1=false
748ed664c0 2023-06-29 2059: 	local res2=true
748ed664c0 2023-06-29 2060: 	for _,te in pairs(le) do
748ed664c0 2023-06-29 2061: 		local f=te:GetValue()
748ed664c0 2023-06-29 2062: 		local related,valid=f(te,lc,mg,c,tp)
748ed664c0 2023-06-29 2063: 		if related then res2=false end
748ed664c0 2023-06-29 2064: 		if related and valid then res1=true end
748ed664c0 2023-06-29 2065: 	end
748ed664c0 2023-06-29 2066: 	return res1 or res2
748ed664c0 2023-06-29 2067: end
748ed664c0 2023-06-29 2068: function Auxiliary.LUncompatibilityFilter(c,sg,lc,tp)
748ed664c0 2023-06-29 2069: 	local mg=sg:Filter(aux.TRUE,c)
748ed664c0 2023-06-29 2070: 	return not Auxiliary.LCheckOtherMaterial(c,mg,lc,tp)
748ed664c0 2023-06-29 2071: end
748ed664c0 2023-06-29 2072: function Auxiliary.LCheckGoal(sg,tp,lc,gf,lmat)
748ed664c0 2023-06-29 2073: 	return sg:CheckWithSumEqual(Auxiliary.GetLinkCount,lc:GetLink(),#sg,#sg)
748ed664c0 2023-06-29 2074: 		and Duel.GetLocationCountFromEx(tp,tp,sg,lc)>0 and (not gf or gf(sg,lc,tp))
748ed664c0 2023-06-29 2075: 		and not sg:IsExists(Auxiliary.LUncompatibilityFilter,1,nil,sg,lc,tp)
748ed664c0 2023-06-29 2076: 		and (not lmat or sg:IsContains(lmat))
748ed664c0 2023-06-29 2077: end
748ed664c0 2023-06-29 2078: function Auxiliary.LExtraMaterialCount(mg,lc,tp)
748ed664c0 2023-06-29 2079: 	for tc in aux.Next(mg) do
748ed664c0 2023-06-29 2080: 		local le={tc:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)}
748ed664c0 2023-06-29 2081: 		for _,te in pairs(le) do
748ed664c0 2023-06-29 2082: 			local sg=mg:Filter(aux.TRUE,tc)
748ed664c0 2023-06-29 2083: 			local f=te:GetValue()
748ed664c0 2023-06-29 2084: 			local related,valid=f(te,lc,sg,tc,tp)
748ed664c0 2023-06-29 2085: 			if related and valid then
748ed664c0 2023-06-29 2086: 				te:UseCountLimit(tp)
748ed664c0 2023-06-29 2087: 			end
748ed664c0 2023-06-29 2088: 		end
748ed664c0 2023-06-29 2089: 	end
748ed664c0 2023-06-29 2090: end
748ed664c0 2023-06-29 2091: function Auxiliary.LinkCondition(f,minc,maxc,gf)
748ed664c0 2023-06-29 2092: 	return	function(e,c,og,lmat,min,max)
748ed664c0 2023-06-29 2093: 				if c==nil then return true end
748ed664c0 2023-06-29 2094: 				if c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end
748ed664c0 2023-06-29 2095: 				local minc=minc
748ed664c0 2023-06-29 2096: 				local maxc=maxc
748ed664c0 2023-06-29 2097: 				if min then
748ed664c0 2023-06-29 2098: 					if min>minc then minc=min end
748ed664c0 2023-06-29 2099: 					if max<maxc then maxc=max end
748ed664c0 2023-06-29 2100: 					if minc>maxc then return false end
748ed664c0 2023-06-29 2101: 				end
748ed664c0 2023-06-29 2102: 				local tp=c:GetControler()
748ed664c0 2023-06-29 2103: 				local mg=nil
748ed664c0 2023-06-29 2104: 				if og then
748ed664c0 2023-06-29 2105: 					mg=og:Filter(Auxiliary.LConditionFilter,nil,f,c,e)
748ed664c0 2023-06-29 2106: 				else
748ed664c0 2023-06-29 2107: 					mg=Auxiliary.GetLinkMaterials(tp,f,c,e)
748ed664c0 2023-06-29 2108: 				end
748ed664c0 2023-06-29 2109: 				if lmat~=nil then
748ed664c0 2023-06-29 2110: 					if not Auxiliary.LConditionFilter(lmat,f,c,e) then return false end
748ed664c0 2023-06-29 2111: 					mg:AddCard(lmat)
748ed664c0 2023-06-29 2112: 				end
748ed664c0 2023-06-29 2113: 				local fg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_LMATERIAL)
748ed664c0 2023-06-29 2114: 				if fg:IsExists(Auxiliary.MustMaterialCounterFilter,1,nil,mg) then return false end
748ed664c0 2023-06-29 2115: 				Duel.SetSelectedCard(fg)
748ed664c0 2023-06-29 2116: 				return mg:CheckSubGroup(Auxiliary.LCheckGoal,minc,maxc,tp,c,gf,lmat)
748ed664c0 2023-06-29 2117: 			end
748ed664c0 2023-06-29 2118: end
748ed664c0 2023-06-29 2119: function Auxiliary.LinkTarget(f,minc,maxc,gf)
748ed664c0 2023-06-29 2120: 	return	function(e,tp,eg,ep,ev,re,r,rp,chk,c,og,lmat,min,max)
748ed664c0 2023-06-29 2121: 				local minc=minc
748ed664c0 2023-06-29 2122: 				local maxc=maxc
748ed664c0 2023-06-29 2123: 				if min then
748ed664c0 2023-06-29 2124: 					if min>minc then minc=min end
748ed664c0 2023-06-29 2125: 					if max<maxc then maxc=max end
748ed664c0 2023-06-29 2126: 					if minc>maxc then return false end
748ed664c0 2023-06-29 2127: 				end
748ed664c0 2023-06-29 2128: 				local mg=nil
748ed664c0 2023-06-29 2129: 				if og then
748ed664c0 2023-06-29 2130: 					mg=og:Filter(Auxiliary.LConditionFilter,nil,f,c,e)
748ed664c0 2023-06-29 2131: 				else
748ed664c0 2023-06-29 2132: 					mg=Auxiliary.GetLinkMaterials(tp,f,c,e)
748ed664c0 2023-06-29 2133: 				end
748ed664c0 2023-06-29 2134: 				if lmat~=nil then
748ed664c0 2023-06-29 2135: 					if not Auxiliary.LConditionFilter(lmat,f,c,e) then return false end
748ed664c0 2023-06-29 2136: 					mg:AddCard(lmat)
748ed664c0 2023-06-29 2137: 				end
748ed664c0 2023-06-29 2138: 				local fg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_LMATERIAL)
748ed664c0 2023-06-29 2139: 				Duel.SetSelectedCard(fg)
748ed664c0 2023-06-29 2140: 				Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_LMATERIAL)
748ed664c0 2023-06-29 2141: 				local cancel=Duel.IsSummonCancelable()
748ed664c0 2023-06-29 2142: 				local sg=mg:SelectSubGroup(tp,Auxiliary.LCheckGoal,cancel,minc,maxc,tp,c,gf,lmat)
748ed664c0 2023-06-29 2143: 				if sg then
748ed664c0 2023-06-29 2144: 					sg:KeepAlive()
748ed664c0 2023-06-29 2145: 					e:SetLabelObject(sg)
748ed664c0 2023-06-29 2146: 					return true
748ed664c0 2023-06-29 2147: 				else return false end
748ed664c0 2023-06-29 2148: 			end
748ed664c0 2023-06-29 2149: end
748ed664c0 2023-06-29 2150: function Auxiliary.LinkOperation(f,minc,maxc,gf)
748ed664c0 2023-06-29 2151: 	return	function(e,tp,eg,ep,ev,re,r,rp,c,og,lmat,min,max)
748ed664c0 2023-06-29 2152: 				local g=e:GetLabelObject()
748ed664c0 2023-06-29 2153: 				c:SetMaterial(g)
748ed664c0 2023-06-29 2154: 				Auxiliary.LExtraMaterialCount(g,c,tp)
748ed664c0 2023-06-29 2155: 				Duel.SendtoGrave(g,REASON_MATERIAL+REASON_LINK)
748ed664c0 2023-06-29 2156: 				g:DeleteGroup()
748ed664c0 2023-06-29 2157: 			end
748ed664c0 2023-06-29 2158: end
748ed664c0 2023-06-29 2159: function Auxiliary.EnableExtraDeckSummonCountLimit()
748ed664c0 2023-06-29 2160: 	if Auxiliary.ExtraDeckSummonCountLimit~=nil then return end
748ed664c0 2023-06-29 2161: 	Auxiliary.ExtraDeckSummonCountLimit={}
748ed664c0 2023-06-29 2162: 	Auxiliary.ExtraDeckSummonCountLimit[0]=1
748ed664c0 2023-06-29 2163: 	Auxiliary.ExtraDeckSummonCountLimit[1]=1
748ed664c0 2023-06-29 2164: 	local ge1=Effect.GlobalEffect()
748ed664c0 2023-06-29 2165: 	ge1:SetType(EFFECT_TYPE_CONTINUOUS+EFFECT_TYPE_FIELD)
748ed664c0 2023-06-29 2166: 	ge1:SetCode(EVENT_PHASE_START+PHASE_DRAW)
748ed664c0 2023-06-29 2167: 	ge1:SetOperation(Auxiliary.ExtraDeckSummonCountLimitReset)
748ed664c0 2023-06-29 2168: 	Duel.RegisterEffect(ge1,0)
748ed664c0 2023-06-29 2169: end
748ed664c0 2023-06-29 2170: function Auxiliary.ExtraDeckSummonCountLimitReset()
748ed664c0 2023-06-29 2171: 	Auxiliary.ExtraDeckSummonCountLimit[0]=1
748ed664c0 2023-06-29 2172: 	Auxiliary.ExtraDeckSummonCountLimit[1]=1
748ed664c0 2023-06-29 2173: end
748ed664c0 2023-06-29 2174: --Fusion Monster is unnecessary to use this
748ed664c0 2023-06-29 2175: function Auxiliary.AddMaterialCodeList(c,...)
748ed664c0 2023-06-29 2176: 	if c:IsStatus(STATUS_COPYING_EFFECT) then return end
748ed664c0 2023-06-29 2177: 	local mat={}
748ed664c0 2023-06-29 2178: 	for _,code in ipairs{...} do
748ed664c0 2023-06-29 2179: 		mat[code]=true
748ed664c0 2023-06-29 2180: 	end
748ed664c0 2023-06-29 2181: 	if c.material==nil then
748ed664c0 2023-06-29 2182: 		local mt=getmetatable(c)
748ed664c0 2023-06-29 2183: 		mt.material=mat
748ed664c0 2023-06-29 2184: 	end
748ed664c0 2023-06-29 2185: 	for index,_ in pairs(mat) do
748ed664c0 2023-06-29 2186: 		Auxiliary.AddCodeList(c,index)
748ed664c0 2023-06-29 2187: 	end
748ed664c0 2023-06-29 2188: end
748ed664c0 2023-06-29 2189: function Auxiliary.IsMaterialListCode(c,code)
748ed664c0 2023-06-29 2190: 	return c.material and c.material[code]
748ed664c0 2023-06-29 2191: end
748ed664c0 2023-06-29 2192: function Auxiliary.IsMaterialListSetCard(c,setcode)
748ed664c0 2023-06-29 2193: 	if not c.material_setcode then return false end
748ed664c0 2023-06-29 2194: 	if type(c.material_setcode)=='table' then
748ed664c0 2023-06-29 2195: 		for i,scode in ipairs(c.material_setcode) do
748ed664c0 2023-06-29 2196: 			if setcode&0xfff==scode&0xfff and setcode&scode==setcode then return true end
748ed664c0 2023-06-29 2197: 		end
748ed664c0 2023-06-29 2198: 	else
748ed664c0 2023-06-29 2199: 		return setcode&0xfff==c.material_setcode&0xfff and setcode&c.material_setcode==setcode
748ed664c0 2023-06-29 2200: 	end
748ed664c0 2023-06-29 2201: 	return false
748ed664c0 2023-06-29 2202: end
748ed664c0 2023-06-29 2203: function Auxiliary.IsMaterialListType(c,type)
748ed664c0 2023-06-29 2204: 	return c.material_type and type&c.material_type==type
748ed664c0 2023-06-29 2205: end
748ed664c0 2023-06-29 2206: function Auxiliary.GetMaterialListCount(c)
748ed664c0 2023-06-29 2207: 	if not c.material_count then return 0,0 end
748ed664c0 2023-06-29 2208: 	return c.material_count[1],c.material_count[2]
748ed664c0 2023-06-29 2209: end
748ed664c0 2023-06-29 2210: function Auxiliary.AddCodeList(c,...)
748ed664c0 2023-06-29 2211: 	if c:IsStatus(STATUS_COPYING_EFFECT) then return end
748ed664c0 2023-06-29 2212: 	if c.card_code_list==nil then
748ed664c0 2023-06-29 2213: 		local mt=getmetatable(c)
748ed664c0 2023-06-29 2214: 		mt.card_code_list={}
748ed664c0 2023-06-29 2215: 		for _,code in ipairs{...} do
748ed664c0 2023-06-29 2216: 			mt.card_code_list[code]=true
748ed664c0 2023-06-29 2217: 		end
748ed664c0 2023-06-29 2218: 	else
748ed664c0 2023-06-29 2219: 		for _,code in ipairs{...} do
748ed664c0 2023-06-29 2220: 			c.card_code_list[code]=true
748ed664c0 2023-06-29 2221: 		end
748ed664c0 2023-06-29 2222: 	end
748ed664c0 2023-06-29 2223: end
748ed664c0 2023-06-29 2224: function Auxiliary.IsCodeListed(c,code)
748ed664c0 2023-06-29 2225: 	return c.card_code_list and c.card_code_list[code]
748ed664c0 2023-06-29 2226: end
748ed664c0 2023-06-29 2227: function Auxiliary.AddSetNameMonsterList(c,...)
748ed664c0 2023-06-29 2228: 	if c:IsStatus(STATUS_COPYING_EFFECT) then return end
748ed664c0 2023-06-29 2229: 	if c.setcode_monster_list==nil then
748ed664c0 2023-06-29 2230: 		local mt=getmetatable(c)
748ed664c0 2023-06-29 2231: 		mt.setcode_monster_list={}
748ed664c0 2023-06-29 2232: 		for i,scode in ipairs{...} do
748ed664c0 2023-06-29 2233: 			mt.setcode_monster_list[i]=scode
748ed664c0 2023-06-29 2234: 		end
748ed664c0 2023-06-29 2235: 	else
748ed664c0 2023-06-29 2236: 		for i,scode in ipairs{...} do
748ed664c0 2023-06-29 2237: 			c.setcode_monster_list[i]=scode
748ed664c0 2023-06-29 2238: 		end
748ed664c0 2023-06-29 2239: 	end
748ed664c0 2023-06-29 2240: end
748ed664c0 2023-06-29 2241: function Auxiliary.IsSetNameMonsterListed(c,setcode)
748ed664c0 2023-06-29 2242: 	if not c.setcode_monster_list then return false end
748ed664c0 2023-06-29 2243: 	for i,scode in ipairs(c.setcode_monster_list) do
748ed664c0 2023-06-29 2244: 		if setcode&0xfff==scode&0xfff and setcode&scode==setcode then return true end
748ed664c0 2023-06-29 2245: 	end
748ed664c0 2023-06-29 2246: 	return false
748ed664c0 2023-06-29 2247: end
748ed664c0 2023-06-29 2248: function Auxiliary.IsCounterAdded(c,counter)
748ed664c0 2023-06-29 2249: 	if not c.counter_add_list then return false end
748ed664c0 2023-06-29 2250: 	for i,ccounter in ipairs(c.counter_add_list) do
748ed664c0 2023-06-29 2251: 		if counter==ccounter then return true end
748ed664c0 2023-06-29 2252: 	end
748ed664c0 2023-06-29 2253: 	return false
748ed664c0 2023-06-29 2254: end
748ed664c0 2023-06-29 2255: function Auxiliary.IsTypeInText(c,type)
748ed664c0 2023-06-29 2256: 	return c.has_text_type and type&c.has_text_type==type
748ed664c0 2023-06-29 2257: end
748ed664c0 2023-06-29 2258: function Auxiliary.GetAttributeCount(g)
748ed664c0 2023-06-29 2259: 	if #g==0 then return 0 end
748ed664c0 2023-06-29 2260: 	local att=0
748ed664c0 2023-06-29 2261: 	for tc in Auxiliary.Next(g) do
748ed664c0 2023-06-29 2262: 		att=att|tc:GetAttribute()
748ed664c0 2023-06-29 2263: 	end
748ed664c0 2023-06-29 2264: 	local ct=0
748ed664c0 2023-06-29 2265: 	while att~=0 do
748ed664c0 2023-06-29 2266: 		if att&0x1~=0 then ct=ct+1 end
748ed664c0 2023-06-29 2267: 		att=att>>1
748ed664c0 2023-06-29 2268: 	end
748ed664c0 2023-06-29 2269: 	return ct
748ed664c0 2023-06-29 2270: end
748ed664c0 2023-06-29 2271: function Auxiliary.IsInGroup(c,g)
748ed664c0 2023-06-29 2272: 	return g:IsContains(c)
748ed664c0 2023-06-29 2273: end
748ed664c0 2023-06-29 2274: --return the column of card c (from the viewpoint of p)
748ed664c0 2023-06-29 2275: function Auxiliary.GetColumn(c,p)
748ed664c0 2023-06-29 2276: 	local seq=c:GetSequence()
748ed664c0 2023-06-29 2277: 	if c:IsLocation(LOCATION_MZONE) then
748ed664c0 2023-06-29 2278: 		if seq==5 then
748ed664c0 2023-06-29 2279: 			seq=1
748ed664c0 2023-06-29 2280: 		elseif seq==6 then
748ed664c0 2023-06-29 2281: 			seq=3
748ed664c0 2023-06-29 2282: 		end
748ed664c0 2023-06-29 2283: 	elseif c:IsLocation(LOCATION_SZONE) then
748ed664c0 2023-06-29 2284: 		if seq>4 then
748ed664c0 2023-06-29 2285: 			return nil
748ed664c0 2023-06-29 2286: 		end
748ed664c0 2023-06-29 2287: 	else
748ed664c0 2023-06-29 2288: 		return nil
748ed664c0 2023-06-29 2289: 	end
748ed664c0 2023-06-29 2290: 	if c:IsControler(p or 0) then
748ed664c0 2023-06-29 2291: 		return seq
748ed664c0 2023-06-29 2292: 	else
748ed664c0 2023-06-29 2293: 		return 4-seq
748ed664c0 2023-06-29 2294: 	end
748ed664c0 2023-06-29 2295: end
748ed664c0 2023-06-29 2296: --return the column of monster zone seq (from the viewpoint of controller)
748ed664c0 2023-06-29 2297: function Auxiliary.MZoneSequence(seq)
748ed664c0 2023-06-29 2298: 	if seq==5 then return 1 end
748ed664c0 2023-06-29 2299: 	if seq==6 then return 3 end
748ed664c0 2023-06-29 2300: 	return seq
748ed664c0 2023-06-29 2301: end
748ed664c0 2023-06-29 2302: --return the column of spell/trap zone seq (from the viewpoint of controller)
748ed664c0 2023-06-29 2303: function Auxiliary.SZoneSequence(seq)
748ed664c0 2023-06-29 2304: 	if seq>4 then return nil end
748ed664c0 2023-06-29 2305: 	return seq
748ed664c0 2023-06-29 2306: end
748ed664c0 2023-06-29 2307: --generate the value function of EFFECT_CHANGE_BATTLE_DAMAGE on monsters
748ed664c0 2023-06-29 2308: function Auxiliary.ChangeBattleDamage(player,value)
748ed664c0 2023-06-29 2309: 	return	function(e,damp)
748ed664c0 2023-06-29 2310: 				if player==0 then
748ed664c0 2023-06-29 2311: 					if e:GetOwnerPlayer()==damp then
748ed664c0 2023-06-29 2312: 						return value
748ed664c0 2023-06-29 2313: 					else
748ed664c0 2023-06-29 2314: 						return -1
748ed664c0 2023-06-29 2315: 					end
748ed664c0 2023-06-29 2316: 				elseif player==1 then
748ed664c0 2023-06-29 2317: 					if e:GetOwnerPlayer()==1-damp then
748ed664c0 2023-06-29 2318: 						return value
748ed664c0 2023-06-29 2319: 					else
748ed664c0 2023-06-29 2320: 						return -1
748ed664c0 2023-06-29 2321: 					end
748ed664c0 2023-06-29 2322: 				end
748ed664c0 2023-06-29 2323: 			end
748ed664c0 2023-06-29 2324: end
748ed664c0 2023-06-29 2325: --filter for "negate the effects of a face-up monster" (無限泡影/Infinite Impermanence)
748ed664c0 2023-06-29 2326: function Auxiliary.NegateMonsterFilter(c)
748ed664c0 2023-06-29 2327: 	return c:IsFaceup() and not c:IsDisabled() and (c:IsType(TYPE_EFFECT) or c:GetOriginalType()&TYPE_EFFECT~=0)
748ed664c0 2023-06-29 2328: end
748ed664c0 2023-06-29 2329: --filter for "negate the effects of an Effect Monster" (エフェクト・ヴェーラー/Effect Veiler)
748ed664c0 2023-06-29 2330: function Auxiliary.NegateEffectMonsterFilter(c)
748ed664c0 2023-06-29 2331: 	return c:IsFaceup() and not c:IsDisabled() and c:IsType(TYPE_EFFECT)
748ed664c0 2023-06-29 2332: end
748ed664c0 2023-06-29 2333: --filter for "negate the effects of a face-up card"
748ed664c0 2023-06-29 2334: function Auxiliary.NegateAnyFilter(c)
748ed664c0 2023-06-29 2335: 	if c:IsType(TYPE_TRAPMONSTER) then
748ed664c0 2023-06-29 2336: 		return c:IsFaceup()
748ed664c0 2023-06-29 2337: 	elseif c:IsType(TYPE_SPELL+TYPE_TRAP) then
748ed664c0 2023-06-29 2338: 		return c:IsFaceup() and not c:IsDisabled()
748ed664c0 2023-06-29 2339: 	else
748ed664c0 2023-06-29 2340: 		return aux.NegateMonsterFilter(c)
748ed664c0 2023-06-29 2341: 	end
748ed664c0 2023-06-29 2342: end
748ed664c0 2023-06-29 2343: --alias for compatibility
748ed664c0 2023-06-29 2344: Auxiliary.disfilter1=Auxiliary.NegateAnyFilter
748ed664c0 2023-06-29 2345: --condition of EVENT_BATTLE_DESTROYING
748ed664c0 2023-06-29 2346: function Auxiliary.bdcon(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 2347: 	local c=e:GetHandler()
748ed664c0 2023-06-29 2348: 	return c:IsRelateToBattle()
748ed664c0 2023-06-29 2349: end
748ed664c0 2023-06-29 2350: --condition of EVENT_BATTLE_DESTROYING + opponent monster
748ed664c0 2023-06-29 2351: function Auxiliary.bdocon(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 2352: 	local c=e:GetHandler()
748ed664c0 2023-06-29 2353: 	return c:IsRelateToBattle() and c:IsStatus(STATUS_OPPO_BATTLE)
748ed664c0 2023-06-29 2354: end
748ed664c0 2023-06-29 2355: --condition of EVENT_BATTLE_DESTROYING + to_grave
748ed664c0 2023-06-29 2356: function Auxiliary.bdgcon(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 2357: 	local c=e:GetHandler()
748ed664c0 2023-06-29 2358: 	local bc=c:GetBattleTarget()
748ed664c0 2023-06-29 2359: 	return c:IsRelateToBattle() and bc:IsLocation(LOCATION_GRAVE) and bc:IsType(TYPE_MONSTER)
748ed664c0 2023-06-29 2360: end
748ed664c0 2023-06-29 2361: --condition of EVENT_BATTLE_DESTROYING + opponent monster + to_grave
748ed664c0 2023-06-29 2362: function Auxiliary.bdogcon(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 2363: 	local c=e:GetHandler()
748ed664c0 2023-06-29 2364: 	local bc=c:GetBattleTarget()
748ed664c0 2023-06-29 2365: 	return c:IsRelateToBattle() and c:IsStatus(STATUS_OPPO_BATTLE) and bc:IsLocation(LOCATION_GRAVE) and bc:IsType(TYPE_MONSTER)
748ed664c0 2023-06-29 2366: end
748ed664c0 2023-06-29 2367: --condition of EVENT_DAMAGE_STEP_END + this monster is releate to battle
748ed664c0 2023-06-29 2368: function Auxiliary.dsercon(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 2369: 	local c=e:GetHandler()
748ed664c0 2023-06-29 2370: 	return c:IsRelateToBattle() or c:IsStatus(STATUS_BATTLE_DESTROYED)
748ed664c0 2023-06-29 2371: end
748ed664c0 2023-06-29 2372: --condition of EVENT_TO_GRAVE + destroyed by opponent
748ed664c0 2023-06-29 2373: function Auxiliary.dogcon(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 2374: 	local c=e:GetHandler()
748ed664c0 2023-06-29 2375: 	return c:IsPreviousControler(tp) and c:IsReason(REASON_DESTROY) and rp==1-tp
748ed664c0 2023-06-29 2376: end
748ed664c0 2023-06-29 2377: --condition of EVENT_TO_GRAVE + destroyed by opponent + from field
748ed664c0 2023-06-29 2378: function Auxiliary.dogfcon(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 2379: 	local c=e:GetHandler()
748ed664c0 2023-06-29 2380: 	return c:IsPreviousLocation(LOCATION_ONFIELD) and c:IsPreviousControler(tp)
748ed664c0 2023-06-29 2381: 		and c:IsReason(REASON_DESTROY) and rp==1-tp
748ed664c0 2023-06-29 2382: end
748ed664c0 2023-06-29 2383: --condition of "except the turn this card was sent to the Graveyard"
748ed664c0 2023-06-29 2384: function Auxiliary.exccon(e)
748ed664c0 2023-06-29 2385: 	return Duel.GetTurnCount()~=e:GetHandler():GetTurnID() or e:GetHandler():IsReason(REASON_RETURN)
748ed664c0 2023-06-29 2386: end
748ed664c0 2023-06-29 2387: --condition of checking battle phase availability
748ed664c0 2023-06-29 2388: function Auxiliary.bpcon(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 2389: 	return Duel.IsAbleToEnterBP() or (Duel.GetCurrentPhase()>=PHASE_BATTLE_START and Duel.GetCurrentPhase()<=PHASE_BATTLE)
748ed664c0 2023-06-29 2390: end
748ed664c0 2023-06-29 2391: --condition of free chain effects changing ATK/DEF
748ed664c0 2023-06-29 2392: function Auxiliary.dscon(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 2393: 	return Duel.GetCurrentPhase()~=PHASE_DAMAGE or not Duel.IsDamageCalculated()
748ed664c0 2023-06-29 2394: end
748ed664c0 2023-06-29 2395: --flag effect for spell counter
748ed664c0 2023-06-29 2396: function Auxiliary.chainreg(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 2397: 	if e:GetHandler():GetFlagEffect(1)==0 then
748ed664c0 2023-06-29 2398: 		e:GetHandler():RegisterFlagEffect(1,RESET_EVENT+RESETS_STANDARD-RESET_TURN_SET+RESET_CHAIN,0,1)
748ed664c0 2023-06-29 2399: 	end
748ed664c0 2023-06-29 2400: end
748ed664c0 2023-06-29 2401: --default filter for EFFECT_CANNOT_BE_BATTLE_TARGET
748ed664c0 2023-06-29 2402: function Auxiliary.imval1(e,c)
748ed664c0 2023-06-29 2403: 	return not c:IsImmuneToEffect(e)
748ed664c0 2023-06-29 2404: end
748ed664c0 2023-06-29 2405: --filter for EFFECT_INDESTRUCTABLE_EFFECT + self
748ed664c0 2023-06-29 2406: function Auxiliary.indsval(e,re,rp)
748ed664c0 2023-06-29 2407: 	return rp==e:GetHandlerPlayer()
748ed664c0 2023-06-29 2408: end
748ed664c0 2023-06-29 2409: --filter for EFFECT_INDESTRUCTABLE_EFFECT + opponent
748ed664c0 2023-06-29 2410: function Auxiliary.indoval(e,re,rp)
748ed664c0 2023-06-29 2411: 	return rp==1-e:GetHandlerPlayer()
748ed664c0 2023-06-29 2412: end
748ed664c0 2023-06-29 2413: --filter for EFFECT_CANNOT_BE_EFFECT_TARGET + self
748ed664c0 2023-06-29 2414: function Auxiliary.tgsval(e,re,rp)
748ed664c0 2023-06-29 2415: 	return rp==e:GetHandlerPlayer()
748ed664c0 2023-06-29 2416: end
748ed664c0 2023-06-29 2417: --filter for EFFECT_CANNOT_BE_EFFECT_TARGET + opponent
748ed664c0 2023-06-29 2418: function Auxiliary.tgoval(e,re,rp)
748ed664c0 2023-06-29 2419: 	return rp==1-e:GetHandlerPlayer()
748ed664c0 2023-06-29 2420: end
748ed664c0 2023-06-29 2421: --filter for non-zero ATK
748ed664c0 2023-06-29 2422: function Auxiliary.nzatk(c)
748ed664c0 2023-06-29 2423: 	return c:IsFaceup() and c:GetAttack()>0
748ed664c0 2023-06-29 2424: end
748ed664c0 2023-06-29 2425: --filter for non-zero DEF
748ed664c0 2023-06-29 2426: function Auxiliary.nzdef(c)
748ed664c0 2023-06-29 2427: 	return c:IsFaceup() and c:GetDefense()>0
748ed664c0 2023-06-29 2428: end
748ed664c0 2023-06-29 2429: --flag effect for summon/sp_summon turn
748ed664c0 2023-06-29 2430: function Auxiliary.sumreg(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 2431: 	local tc=eg:GetFirst()
748ed664c0 2023-06-29 2432: 	local code=e:GetLabel()
748ed664c0 2023-06-29 2433: 	while tc do
748ed664c0 2023-06-29 2434: 		if tc:GetOriginalCode()==code then
748ed664c0 2023-06-29 2435: 			tc:RegisterFlagEffect(code,RESET_EVENT+0x1ec0000+RESET_PHASE+PHASE_END,0,1)
748ed664c0 2023-06-29 2436: 		end
748ed664c0 2023-06-29 2437: 		tc=eg:GetNext()
748ed664c0 2023-06-29 2438: 	end
748ed664c0 2023-06-29 2439: end
748ed664c0 2023-06-29 2440: --for EVENT_BE_MATERIAL effect releated to the summoned monster
748ed664c0 2023-06-29 2441: function Auxiliary.CreateMaterialReasonCardRelation(c,te)
748ed664c0 2023-06-29 2442: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29 2443: 	e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_CONTINUOUS)
748ed664c0 2023-06-29 2444: 	e1:SetCode(EVENT_BE_MATERIAL)
748ed664c0 2023-06-29 2445: 	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
748ed664c0 2023-06-29 2446: 	e1:SetOperation(Auxiliary.MaterialReasonCardReg)
748ed664c0 2023-06-29 2447: 	e1:SetLabelObject(te)
748ed664c0 2023-06-29 2448: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29 2449: end
748ed664c0 2023-06-29 2450: function Auxiliary.MaterialReasonCardReg(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 2451: 	local c=e:GetHandler()
748ed664c0 2023-06-29 2452: 	local te=e:GetLabelObject()
748ed664c0 2023-06-29 2453: 	c:GetReasonCard():CreateEffectRelation(te)
748ed664c0 2023-06-29 2454: end
748ed664c0 2023-06-29 2455: --sp_summon condition for fusion monster
748ed664c0 2023-06-29 2456: function Auxiliary.fuslimit(e,se,sp,st)
748ed664c0 2023-06-29 2457: 	return st&SUMMON_TYPE_FUSION==SUMMON_TYPE_FUSION
748ed664c0 2023-06-29 2458: end
748ed664c0 2023-06-29 2459: --sp_summon condition for ritual monster
748ed664c0 2023-06-29 2460: function Auxiliary.ritlimit(e,se,sp,st)
748ed664c0 2023-06-29 2461: 	return st&SUMMON_TYPE_RITUAL==SUMMON_TYPE_RITUAL
748ed664c0 2023-06-29 2462: end
748ed664c0 2023-06-29 2463: --sp_summon condition for synchro monster
748ed664c0 2023-06-29 2464: function Auxiliary.synlimit(e,se,sp,st)
748ed664c0 2023-06-29 2465: 	return st&SUMMON_TYPE_SYNCHRO==SUMMON_TYPE_SYNCHRO
748ed664c0 2023-06-29 2466: end
748ed664c0 2023-06-29 2467: --sp_summon condition for xyz monster
748ed664c0 2023-06-29 2468: function Auxiliary.xyzlimit(e,se,sp,st)
748ed664c0 2023-06-29 2469: 	return st&SUMMON_TYPE_XYZ==SUMMON_TYPE_XYZ
748ed664c0 2023-06-29 2470: end
748ed664c0 2023-06-29 2471: --sp_summon condition for pendulum monster
748ed664c0 2023-06-29 2472: function Auxiliary.penlimit(e,se,sp,st)
748ed664c0 2023-06-29 2473: 	return st&SUMMON_TYPE_PENDULUM==SUMMON_TYPE_PENDULUM
748ed664c0 2023-06-29 2474: end
748ed664c0 2023-06-29 2475: --sp_summon condition for link monster
748ed664c0 2023-06-29 2476: function Auxiliary.linklimit(e,se,sp,st)
748ed664c0 2023-06-29 2477: 	return st&SUMMON_TYPE_LINK==SUMMON_TYPE_LINK
748ed664c0 2023-06-29 2478: end
748ed664c0 2023-06-29 2479: --effects inflicting damage to tp
748ed664c0 2023-06-29 2480: function Auxiliary.damcon1(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 2481: 	local e1=Duel.IsPlayerAffectedByEffect(tp,EFFECT_REVERSE_DAMAGE)
748ed664c0 2023-06-29 2482: 	local e2=Duel.IsPlayerAffectedByEffect(tp,EFFECT_REVERSE_RECOVER)
748ed664c0 2023-06-29 2483: 	local rd=e1 and not e2
748ed664c0 2023-06-29 2484: 	local rr=not e1 and e2
748ed664c0 2023-06-29 2485: 	local ex,cg,ct,cp,cv=Duel.GetOperationInfo(ev,CATEGORY_DAMAGE)
748ed664c0 2023-06-29 2486: 	if ex and (cp==tp or cp==PLAYER_ALL) and not rd and not Duel.IsPlayerAffectedByEffect(tp,EFFECT_NO_EFFECT_DAMAGE) then
748ed664c0 2023-06-29 2487: 		return true
748ed664c0 2023-06-29 2488: 	end
748ed664c0 2023-06-29 2489: 	ex,cg,ct,cp,cv=Duel.GetOperationInfo(ev,CATEGORY_RECOVER)
748ed664c0 2023-06-29 2490: 	return ex and (cp==tp or cp==PLAYER_ALL) and rr and not Duel.IsPlayerAffectedByEffect(tp,EFFECT_NO_EFFECT_DAMAGE)
748ed664c0 2023-06-29 2491: end
748ed664c0 2023-06-29 2492: --filter for the immune effect of qli monsters
748ed664c0 2023-06-29 2493: function Auxiliary.qlifilter(e,te)
748ed664c0 2023-06-29 2494: 	if te:IsActiveType(TYPE_MONSTER) and te:IsActivated() then
748ed664c0 2023-06-29 2495: 		local lv=e:GetHandler():GetLevel()
748ed664c0 2023-06-29 2496: 		local ec=te:GetOwner()
748ed664c0 2023-06-29 2497: 		if ec:IsType(TYPE_LINK) then
748ed664c0 2023-06-29 2498: 			return false
748ed664c0 2023-06-29 2499: 		elseif ec:IsType(TYPE_XYZ) then
748ed664c0 2023-06-29 2500: 			return ec:GetOriginalRank()<lv
748ed664c0 2023-06-29 2501: 		else
748ed664c0 2023-06-29 2502: 			return ec:GetOriginalLevel()<lv
748ed664c0 2023-06-29 2503: 		end
748ed664c0 2023-06-29 2504: 	else
748ed664c0 2023-06-29 2505: 		return false
748ed664c0 2023-06-29 2506: 	end
748ed664c0 2023-06-29 2507: end
748ed664c0 2023-06-29 2508: --sp_summon condition for gladiator beast monsters
748ed664c0 2023-06-29 2509: function Auxiliary.gbspcon(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 2510: 	local st=e:GetHandler():GetSummonType()
748ed664c0 2023-06-29 2511: 	return st&SUMMON_VALUE_GLADIATOR>0
748ed664c0 2023-06-29 2512: end
748ed664c0 2023-06-29 2513: --sp_summon condition for evolsaur monsters
748ed664c0 2023-06-29 2514: function Auxiliary.evospcon(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 2515: 	local st=e:GetHandler():GetSummonType()
748ed664c0 2023-06-29 2516: 	return st&SUMMON_VALUE_EVOLTILE>0
748ed664c0 2023-06-29 2517: end
748ed664c0 2023-06-29 2518: --filter for necro_valley test
748ed664c0 2023-06-29 2519: function Auxiliary.NecroValleyFilter(f)
748ed664c0 2023-06-29 2520: 	return	function(target,...)
748ed664c0 2023-06-29 2521: 				return (not f or f(target,...)) and not target:IsHasEffect(EFFECT_NECRO_VALLEY)
748ed664c0 2023-06-29 2522: 			end
748ed664c0 2023-06-29 2523: end
748ed664c0 2023-06-29 2524: --Necrovalley test for effect with not certain target or not certain action
748ed664c0 2023-06-29 2525: function Auxiliary.NecroValleyNegateCheck(v)
748ed664c0 2023-06-29 2526: 	if not Duel.IsChainDisablable(0) then return false end
748ed664c0 2023-06-29 2527: 	local g=Group.CreateGroup()
748ed664c0 2023-06-29 2528: 	if Auxiliary.GetValueType(v)=="Card" then g:AddCard(v) end
748ed664c0 2023-06-29 2529: 	if Auxiliary.GetValueType(v)=="Group" then g:Merge(v) end
748ed664c0 2023-06-29 2530: 	if g:IsExists(Card.IsHasEffect,1,nil,EFFECT_NECRO_VALLEY) then
748ed664c0 2023-06-29 2531: 		Duel.NegateEffect(0)
748ed664c0 2023-06-29 2532: 		return true
748ed664c0 2023-06-29 2533: 	end
748ed664c0 2023-06-29 2534: 	return false
748ed664c0 2023-06-29 2535: end
748ed664c0 2023-06-29 2536: --Ursarctic common summon from hand effect
748ed664c0 2023-06-29 2537: function Auxiliary.AddUrsarcticSpSummonEffect(c)
748ed664c0 2023-06-29 2538: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29 2539: 	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
748ed664c0 2023-06-29 2540: 	e1:SetType(EFFECT_TYPE_QUICK_O)
748ed664c0 2023-06-29 2541: 	e1:SetCode(EVENT_FREE_CHAIN)
748ed664c0 2023-06-29 2542: 	e1:SetRange(LOCATION_HAND)
748ed664c0 2023-06-29 2543: 	e1:SetHintTiming(0,TIMINGS_CHECK_MONSTER+TIMING_MAIN_END)
748ed664c0 2023-06-29 2544: 	e1:SetCondition(Auxiliary.UrsarcticSpSummonCondition)
748ed664c0 2023-06-29 2545: 	e1:SetCost(Auxiliary.UrsarcticSpSummonCost)
748ed664c0 2023-06-29 2546: 	e1:SetTarget(Auxiliary.UrsarcticSpSummonTarget)
748ed664c0 2023-06-29 2547: 	e1:SetOperation(Auxiliary.UrsarcticSpSummonOperation)
748ed664c0 2023-06-29 2548: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29 2549: 	return e1
748ed664c0 2023-06-29 2550: end
748ed664c0 2023-06-29 2551: function Auxiliary.UrsarcticSpSummonCondition(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 2552: 	return Duel.GetCurrentPhase()==PHASE_MAIN1 or Duel.GetCurrentPhase()==PHASE_MAIN2
748ed664c0 2023-06-29 2553: end
748ed664c0 2023-06-29 2554: function Auxiliary.UrsarcticReleaseFilter(c)
748ed664c0 2023-06-29 2555: 	return c:IsLevelAbove(7) and c:IsLocation(LOCATION_HAND)
748ed664c0 2023-06-29 2556: end
748ed664c0 2023-06-29 2557: function Auxiliary.UrsarcticExCostFilter(c,tp)
748ed664c0 2023-06-29 2558: 	return c:IsAbleToRemoveAsCost() and (c:IsHasEffect(16471775,tp) or c:IsHasEffect(89264428,tp))
748ed664c0 2023-06-29 2559: end
748ed664c0 2023-06-29 2560: function Auxiliary.UrsarcticSpSummonCost(e,tp,eg,ep,ev,re,r,rp,chk)
748ed664c0 2023-06-29 2561: 	local g1=Duel.GetReleaseGroup(tp,true):Filter(Auxiliary.UrsarcticReleaseFilter,e:GetHandler())
748ed664c0 2023-06-29 2562: 	local g2=Duel.GetMatchingGroup(Auxiliary.UrsarcticExCostFilter,tp,LOCATION_GRAVE,0,nil,tp)
748ed664c0 2023-06-29 2563: 	g1:Merge(g2)
748ed664c0 2023-06-29 2564: 	if chk==0 then return g1:GetCount()>0 end
748ed664c0 2023-06-29 2565: 	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_RELEASE)
748ed664c0 2023-06-29 2566: 	local tc=g1:Select(tp,1,1,nil):GetFirst()
748ed664c0 2023-06-29 2567: 	local te=tc:IsHasEffect(16471775,tp) or tc:IsHasEffect(89264428,tp)
748ed664c0 2023-06-29 2568: 	if te then
748ed664c0 2023-06-29 2569: 		te:UseCountLimit(tp)
748ed664c0 2023-06-29 2570: 		Duel.Remove(tc,POS_FACEUP,REASON_EFFECT+REASON_REPLACE)
748ed664c0 2023-06-29 2571: 	else
748ed664c0 2023-06-29 2572: 		Duel.Release(tc,REASON_COST)
748ed664c0 2023-06-29 2573: 	end
748ed664c0 2023-06-29 2574: end
748ed664c0 2023-06-29 2575: function Auxiliary.UrsarcticSpSummonTarget(e,tp,eg,ep,ev,re,r,rp,chk)
748ed664c0 2023-06-29 2576: 	if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0
748ed664c0 2023-06-29 2577: 		and e:GetHandler():IsCanBeSpecialSummoned(e,0,tp,false,false) end
748ed664c0 2023-06-29 2578: 	Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,e:GetHandler(),1,0,0)
748ed664c0 2023-06-29 2579: end
748ed664c0 2023-06-29 2580: function Auxiliary.UrsarcticSpSummonOperation(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 2581: 	local c=e:GetHandler()
748ed664c0 2023-06-29 2582: 	if c:IsRelateToEffect(e) then
748ed664c0 2023-06-29 2583: 		Duel.SpecialSummon(c,0,tp,tp,false,false,POS_FACEUP)
748ed664c0 2023-06-29 2584: 	end
748ed664c0 2023-06-29 2585: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29 2586: 	e1:SetType(EFFECT_TYPE_FIELD)
748ed664c0 2023-06-29 2587: 	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
748ed664c0 2023-06-29 2588: 	e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
748ed664c0 2023-06-29 2589: 	e1:SetTargetRange(1,0)
748ed664c0 2023-06-29 2590: 	e1:SetTarget(Auxiliary.UrsarcticSpSummonLimit)
748ed664c0 2023-06-29 2591: 	e1:SetReset(RESET_PHASE+PHASE_END)
748ed664c0 2023-06-29 2592: 	Duel.RegisterEffect(e1,tp)
748ed664c0 2023-06-29 2593: end
748ed664c0 2023-06-29 2594: function Auxiliary.UrsarcticSpSummonLimit(e,c)
748ed664c0 2023-06-29 2595: 	return c:IsLevel(0)
748ed664c0 2023-06-29 2596: end
748ed664c0 2023-06-29 2597: --Drytron common summon effect
748ed664c0 2023-06-29 2598: function Auxiliary.AddDrytronSpSummonEffect(c,func)
748ed664c0 2023-06-29 2599: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29 2600: 	e1:SetType(EFFECT_TYPE_IGNITION)
748ed664c0 2023-06-29 2601: 	e1:SetRange(LOCATION_HAND+LOCATION_GRAVE)
748ed664c0 2023-06-29 2602: 	e1:SetCost(Auxiliary.DrytronSpSummonCost)
748ed664c0 2023-06-29 2603: 	e1:SetTarget(Auxiliary.DrytronSpSummonTarget)
748ed664c0 2023-06-29 2604: 	e1:SetOperation(Auxiliary.DrytronSpSummonOperation(func))
748ed664c0 2023-06-29 2605: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29 2606: 	Duel.AddCustomActivityCounter(97148796,ACTIVITY_SPSUMMON,Auxiliary.DrytronCounterFilter)
748ed664c0 2023-06-29 2607: 	return e1
748ed664c0 2023-06-29 2608: end
748ed664c0 2023-06-29 2609: function Auxiliary.DrytronCounterFilter(c)
748ed664c0 2023-06-29 2610: 	return not c:IsSummonableCard()
748ed664c0 2023-06-29 2611: end
748ed664c0 2023-06-29 2612: function Auxiliary.DrytronCostFilter(c,tp)
748ed664c0 2023-06-29 2613: 	return (c:IsSetCard(0x154) or c:IsType(TYPE_RITUAL)) and c:IsType(TYPE_MONSTER) and Duel.GetMZoneCount(tp,c)>0
748ed664c0 2023-06-29 2614: 		and (c:IsControler(tp) or c:IsFaceup())
748ed664c0 2023-06-29 2615: end
748ed664c0 2023-06-29 2616: function Auxiliary.DrytronExtraCostFilter(c,tp)
748ed664c0 2023-06-29 2617: 	return c:IsAbleToRemove() and c:IsHasEffect(89771220,tp)
748ed664c0 2023-06-29 2618: end
748ed664c0 2023-06-29 2619: function Auxiliary.DrytronSpSummonCost(e,tp,eg,ep,ev,re,r,rp,chk)
748ed664c0 2023-06-29 2620: 	e:SetLabel(100)
748ed664c0 2023-06-29 2621: 	local g1=Duel.GetReleaseGroup(tp,true):Filter(Auxiliary.DrytronCostFilter,e:GetHandler(),tp)
748ed664c0 2023-06-29 2622: 	local g2=Duel.GetMatchingGroup(Auxiliary.DrytronExtraCostFilter,tp,LOCATION_GRAVE,0,nil,tp)
748ed664c0 2023-06-29 2623: 	g1:Merge(g2)
748ed664c0 2023-06-29 2624: 	if chk==0 then return #g1>0 and Duel.GetCustomActivityCount(97148796,tp,ACTIVITY_SPSUMMON)==0 end
748ed664c0 2023-06-29 2625: 	local e1=Effect.CreateEffect(e:GetHandler())
748ed664c0 2023-06-29 2626: 	e1:SetType(EFFECT_TYPE_FIELD)
748ed664c0 2023-06-29 2627: 	e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
748ed664c0 2023-06-29 2628: 	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET+EFFECT_FLAG_OATH)
748ed664c0 2023-06-29 2629: 	e1:SetTargetRange(1,0)
748ed664c0 2023-06-29 2630: 	e1:SetTarget(Auxiliary.DrytronSpSummonLimit)
748ed664c0 2023-06-29 2631: 	e1:SetReset(RESET_PHASE+PHASE_END)
748ed664c0 2023-06-29 2632: 	Duel.RegisterEffect(e1,tp)
748ed664c0 2023-06-29 2633: 	--cant special summon summonable card check
748ed664c0 2023-06-29 2634: 	local e2=Effect.CreateEffect(e:GetHandler())
748ed664c0 2023-06-29 2635: 	e2:SetType(EFFECT_TYPE_FIELD)
748ed664c0 2023-06-29 2636: 	e2:SetCode(97148796)
748ed664c0 2023-06-29 2637: 	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET+EFFECT_FLAG_OATH)
748ed664c0 2023-06-29 2638: 	e2:SetTargetRange(1,0)
748ed664c0 2023-06-29 2639: 	e2:SetReset(RESET_PHASE+PHASE_END)
748ed664c0 2023-06-29 2640: 	Duel.RegisterEffect(e2,tp)
748ed664c0 2023-06-29 2641: 	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_RELEASE)
748ed664c0 2023-06-29 2642: 	local rg=g1:Select(tp,1,1,nil)
748ed664c0 2023-06-29 2643: 	local tc=rg:GetFirst()
748ed664c0 2023-06-29 2644: 	local te=tc:IsHasEffect(89771220,tp)
748ed664c0 2023-06-29 2645: 	if te then
748ed664c0 2023-06-29 2646: 		te:UseCountLimit(tp)
748ed664c0 2023-06-29 2647: 		Duel.Remove(tc,POS_FACEUP,REASON_EFFECT+REASON_REPLACE)
748ed664c0 2023-06-29 2648: 	else
748ed664c0 2023-06-29 2649: 		Auxiliary.UseExtraReleaseCount(rg,tp)
748ed664c0 2023-06-29 2650: 		Duel.Release(tc,REASON_COST)
748ed664c0 2023-06-29 2651: 	end
748ed664c0 2023-06-29 2652: end
748ed664c0 2023-06-29 2653: function Auxiliary.DrytronSpSummonLimit(e,c,sump,sumtype,sumpos,targetp,se)
748ed664c0 2023-06-29 2654: 	return c:IsSummonableCard()
748ed664c0 2023-06-29 2655: end
748ed664c0 2023-06-29 2656: function Auxiliary.DrytronSpSummonTarget(e,tp,eg,ep,ev,re,r,rp,chk)
748ed664c0 2023-06-29 2657: 	local res=e:GetLabel()==100 or Duel.GetLocationCount(tp,LOCATION_MZONE)>0
748ed664c0 2023-06-29 2658: 	if chk==0 then
748ed664c0 2023-06-29 2659: 		e:SetLabel(0)
748ed664c0 2023-06-29 2660: 		return res and e:GetHandler():IsCanBeSpecialSummoned(e,0,tp,false,false,POS_FACEUP_DEFENSE)
748ed664c0 2023-06-29 2661: 	end
748ed664c0 2023-06-29 2662: 	e:SetLabel(0)
748ed664c0 2023-06-29 2663: 	Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,e:GetHandler(),1,0,0)
748ed664c0 2023-06-29 2664: end
748ed664c0 2023-06-29 2665: function Auxiliary.DrytronSpSummonOperation(func)
748ed664c0 2023-06-29 2666: 	return function(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 2667: 		local c=e:GetHandler()
748ed664c0 2023-06-29 2668: 		if not c:IsRelateToEffect(e) then return end
748ed664c0 2023-06-29 2669: 		if Duel.SpecialSummon(c,0,tp,tp,false,false,POS_FACEUP_DEFENSE)~=0 then func(e,tp) end
748ed664c0 2023-06-29 2670: 	end
748ed664c0 2023-06-29 2671: end
748ed664c0 2023-06-29 2672: --additional destroy effect for the Labrynth field
748ed664c0 2023-06-29 2673: function Auxiliary.LabrynthDestroyOp(e,tp,res)
748ed664c0 2023-06-29 2674: 	local c=e:GetHandler()
748ed664c0 2023-06-29 2675: 	local chk=not c:IsStatus(STATUS_ACT_FROM_HAND) and c:IsSetCard(0x117e) and c:GetType()==TYPE_TRAP and e:IsHasType(EFFECT_TYPE_ACTIVATE)
748ed664c0 2023-06-29 2676: 	local exc=nil
748ed664c0 2023-06-29 2677: 	if c:IsStatus(STATUS_LEAVE_CONFIRMED) then exc=c end
748ed664c0 2023-06-29 2678: 	local te=Duel.IsPlayerAffectedByEffect(tp,33407125)
748ed664c0 2023-06-29 2679: 	if chk and te
748ed664c0 2023-06-29 2680: 		and Duel.IsExistingMatchingCard(nil,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,1,exc)
748ed664c0 2023-06-29 2681: 		and Duel.SelectYesNo(tp,aux.Stringid(33407125,0)) then
748ed664c0 2023-06-29 2682: 		if res>0 then Duel.BreakEffect() end
748ed664c0 2023-06-29 2683: 		Duel.Hint(HINT_CARD,0,33407125)
748ed664c0 2023-06-29 2684: 		Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_DESTROY)
748ed664c0 2023-06-29 2685: 		local dg=Duel.SelectMatchingCard(tp,nil,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,1,1,exc)
748ed664c0 2023-06-29 2686: 		Duel.HintSelection(dg)
748ed664c0 2023-06-29 2687: 		Duel.Destroy(dg,REASON_EFFECT)
748ed664c0 2023-06-29 2688: 		te:UseCountLimit(tp)
748ed664c0 2023-06-29 2689: 	end
748ed664c0 2023-06-29 2690: end
748ed664c0 2023-06-29 2691: --shortcut for Gizmek cards
748ed664c0 2023-06-29 2692: function Auxiliary.AtkEqualsDef(c)
748ed664c0 2023-06-29 2693: 	if not c:IsType(TYPE_MONSTER) or c:IsType(TYPE_LINK) then return false end
748ed664c0 2023-06-29 2694: 	if c:GetAttack()~=c:GetDefense() then return false end
748ed664c0 2023-06-29 2695: 	return c:IsLocation(LOCATION_MZONE) or c:GetTextAttack()>=0 and c:GetTextDefense()>=0
748ed664c0 2023-06-29 2696: end
748ed664c0 2023-06-29 2697: --shortcut for self-banish costs
748ed664c0 2023-06-29 2698: function Auxiliary.bfgcost(e,tp,eg,ep,ev,re,r,rp,chk)
748ed664c0 2023-06-29 2699: 	if chk==0 then return e:GetHandler():IsAbleToRemoveAsCost() end
748ed664c0 2023-06-29 2700: 	Duel.Remove(e:GetHandler(),POS_FACEUP,REASON_COST)
748ed664c0 2023-06-29 2701: end
748ed664c0 2023-06-29 2702: --check for cards with different names
748ed664c0 2023-06-29 2703: function Auxiliary.dncheck(g)
748ed664c0 2023-06-29 2704: 	return g:GetClassCount(Card.GetCode)==#g
748ed664c0 2023-06-29 2705: end
748ed664c0 2023-06-29 2706: --check for cards with different levels
748ed664c0 2023-06-29 2707: function Auxiliary.dlvcheck(g)
748ed664c0 2023-06-29 2708: 	return g:GetClassCount(Card.GetLevel)==#g
748ed664c0 2023-06-29 2709: end
748ed664c0 2023-06-29 2710: --check for cards with different ranks
748ed664c0 2023-06-29 2711: function Auxiliary.drkcheck(g)
748ed664c0 2023-06-29 2712: 	return g:GetClassCount(Card.GetRank)==#g
748ed664c0 2023-06-29 2713: end
748ed664c0 2023-06-29 2714: --check for cards with different links
748ed664c0 2023-06-29 2715: function Auxiliary.dlkcheck(g)
748ed664c0 2023-06-29 2716: 	return g:GetClassCount(Card.GetLink)==#g
748ed664c0 2023-06-29 2717: end
748ed664c0 2023-06-29 2718: --check for cards with different attributes
748ed664c0 2023-06-29 2719: function Auxiliary.dabcheck(g)
748ed664c0 2023-06-29 2720: 	return g:GetClassCount(Card.GetAttribute)==#g
748ed664c0 2023-06-29 2721: end
748ed664c0 2023-06-29 2722: --check for cards with different races
748ed664c0 2023-06-29 2723: function Auxiliary.drccheck(g)
748ed664c0 2023-06-29 2724: 	return g:GetClassCount(Card.GetRace)==#g
748ed664c0 2023-06-29 2725: end
748ed664c0 2023-06-29 2726: --check for group with 2 cards, each card match f with a1/a2 as argument
748ed664c0 2023-06-29 2727: function Auxiliary.gfcheck(g,f,a1,a2)
748ed664c0 2023-06-29 2728: 	if #g~=2 then return false end
748ed664c0 2023-06-29 2729: 	local c1=g:GetFirst()
748ed664c0 2023-06-29 2730: 	local c2=g:GetNext()
748ed664c0 2023-06-29 2731: 	return f(c1,a1) and f(c2,a2) or f(c2,a1) and f(c1,a2)
748ed664c0 2023-06-29 2732: end
748ed664c0 2023-06-29 2733: --check for group with 2 cards, each card match f1 with a1, f2 with a2 as argument
748ed664c0 2023-06-29 2734: function Auxiliary.gffcheck(g,f1,a1,f2,a2)
748ed664c0 2023-06-29 2735: 	if #g~=2 then return false end
748ed664c0 2023-06-29 2736: 	local c1=g:GetFirst()
748ed664c0 2023-06-29 2737: 	local c2=g:GetNext()
748ed664c0 2023-06-29 2738: 	return f1(c1,a1) and f2(c2,a2) or f1(c2,a1) and f2(c1,a2)
748ed664c0 2023-06-29 2739: end
748ed664c0 2023-06-29 2740: function Auxiliary.mzctcheck(g,tp)
748ed664c0 2023-06-29 2741: 	return Duel.GetMZoneCount(tp,g)>0
748ed664c0 2023-06-29 2742: end
748ed664c0 2023-06-29 2743: function Auxiliary.mzctcheckrel(g,tp)
748ed664c0 2023-06-29 2744: 	return Duel.GetMZoneCount(tp,g)>0 and Duel.CheckReleaseGroup(tp,Auxiliary.IsInGroup,#g,nil,g)
748ed664c0 2023-06-29 2745: end
748ed664c0 2023-06-29 2746: --used for "except this card"
748ed664c0 2023-06-29 2747: function Auxiliary.ExceptThisCard(e)
748ed664c0 2023-06-29 2748: 	local c=e:GetHandler()
748ed664c0 2023-06-29 2749: 	if c:IsRelateToChain() then return c else return nil end
748ed664c0 2023-06-29 2750: end
748ed664c0 2023-06-29 2751: --used for multi-linked zone(zone linked by two or more link monsters)
748ed664c0 2023-06-29 2752: function Auxiliary.GetMultiLinkedZone(tp)
748ed664c0 2023-06-29 2753: 	local f=function(c)
748ed664c0 2023-06-29 2754: 		return c:IsFaceup() and c:IsType(TYPE_LINK)
748ed664c0 2023-06-29 2755: 	end
748ed664c0 2023-06-29 2756: 	local lg=Duel.GetMatchingGroup(f,tp,LOCATION_MZONE,LOCATION_MZONE,nil)
748ed664c0 2023-06-29 2757: 	local multi_linked_zone=0
748ed664c0 2023-06-29 2758: 	local single_linked_zone=0
748ed664c0 2023-06-29 2759: 	for tc in aux.Next(lg) do
748ed664c0 2023-06-29 2760: 		local zone=tc:GetLinkedZone(tp)&0x7f
748ed664c0 2023-06-29 2761: 		multi_linked_zone=single_linked_zone&zone|multi_linked_zone
748ed664c0 2023-06-29 2762: 		single_linked_zone=single_linked_zone~zone
748ed664c0 2023-06-29 2763: 	end
748ed664c0 2023-06-29 2764: 	return multi_linked_zone
748ed664c0 2023-06-29 2765: end
748ed664c0 2023-06-29 2766: Auxiliary.SubGroupCaptured=nil
748ed664c0 2023-06-29 2767: Auxiliary.GCheckAdditional=nil
748ed664c0 2023-06-29 2768: function Auxiliary.CheckGroupRecursive(c,sg,g,f,min,max,ext_params)
748ed664c0 2023-06-29 2769: 	sg:AddCard(c)
748ed664c0 2023-06-29 2770: 	if Auxiliary.GCheckAdditional and not Auxiliary.GCheckAdditional(sg,c,g,f,min,max,ext_params) then
748ed664c0 2023-06-29 2771: 		sg:RemoveCard(c)
748ed664c0 2023-06-29 2772: 		return false
748ed664c0 2023-06-29 2773: 	end
748ed664c0 2023-06-29 2774: 	local res=(#sg>=min and #sg<=max and f(sg,table.unpack(ext_params)))
748ed664c0 2023-06-29 2775: 		or (#sg<max and g:IsExists(Auxiliary.CheckGroupRecursive,1,sg,sg,g,f,min,max,ext_params))
748ed664c0 2023-06-29 2776: 	sg:RemoveCard(c)
748ed664c0 2023-06-29 2777: 	return res
748ed664c0 2023-06-29 2778: end
748ed664c0 2023-06-29 2779: function Auxiliary.CheckGroupRecursiveCapture(c,sg,g,f,min,max,ext_params)
748ed664c0 2023-06-29 2780: 	sg:AddCard(c)
748ed664c0 2023-06-29 2781: 	if Auxiliary.GCheckAdditional and not Auxiliary.GCheckAdditional(sg,c,g,f,min,max,ext_params) then
748ed664c0 2023-06-29 2782: 		sg:RemoveCard(c)
748ed664c0 2023-06-29 2783: 		return false
748ed664c0 2023-06-29 2784: 	end
748ed664c0 2023-06-29 2785: 	local res=#sg>=min and #sg<=max and f(sg,table.unpack(ext_params))
748ed664c0 2023-06-29 2786: 	if res then
748ed664c0 2023-06-29 2787: 		Auxiliary.SubGroupCaptured:Clear()
748ed664c0 2023-06-29 2788: 		Auxiliary.SubGroupCaptured:Merge(sg)
748ed664c0 2023-06-29 2789: 	else
748ed664c0 2023-06-29 2790: 		res=#sg<max and g:IsExists(Auxiliary.CheckGroupRecursiveCapture,1,sg,sg,g,f,min,max,ext_params)
748ed664c0 2023-06-29 2791: 	end
748ed664c0 2023-06-29 2792: 	sg:RemoveCard(c)
748ed664c0 2023-06-29 2793: 	return res
748ed664c0 2023-06-29 2794: end
748ed664c0 2023-06-29 2795: function Group.CheckSubGroup(g,f,min,max,...)
748ed664c0 2023-06-29 2796: 	local min=min or 1
748ed664c0 2023-06-29 2797: 	local max=max or #g
748ed664c0 2023-06-29 2798: 	if min>max then return false end
748ed664c0 2023-06-29 2799: 	local ext_params={...}
748ed664c0 2023-06-29 2800: 	local sg=Duel.GrabSelectedCard()
748ed664c0 2023-06-29 2801: 	if #sg>max or #(g+sg)<min then return false end
748ed664c0 2023-06-29 2802: 	if #sg==max and (not f(sg,...) or Auxiliary.GCheckAdditional and not Auxiliary.GCheckAdditional(sg,nil,g,f,min,max,ext_params)) then return false end
748ed664c0 2023-06-29 2803: 	if #sg>=min and #sg<=max and f(sg,...) and (not Auxiliary.GCheckAdditional or Auxiliary.GCheckAdditional(sg,nil,g,f,min,max,ext_params)) then return true end
748ed664c0 2023-06-29 2804: 	local eg=g:Clone()
748ed664c0 2023-06-29 2805: 	for c in aux.Next(g-sg) do
748ed664c0 2023-06-29 2806: 		if Auxiliary.CheckGroupRecursive(c,sg,eg,f,min,max,ext_params) then return true end
748ed664c0 2023-06-29 2807: 		eg:RemoveCard(c)
748ed664c0 2023-06-29 2808: 	end
748ed664c0 2023-06-29 2809: 	return false
748ed664c0 2023-06-29 2810: end
748ed664c0 2023-06-29 2811: function Group.SelectSubGroup(g,tp,f,cancelable,min,max,...)
748ed664c0 2023-06-29 2812: 	Auxiliary.SubGroupCaptured=Group.CreateGroup()
748ed664c0 2023-06-29 2813: 	local min=min or 1
748ed664c0 2023-06-29 2814: 	local max=max or #g
748ed664c0 2023-06-29 2815: 	local ext_params={...}
748ed664c0 2023-06-29 2816: 	local sg=Group.CreateGroup()
748ed664c0 2023-06-29 2817: 	local fg=Duel.GrabSelectedCard()
748ed664c0 2023-06-29 2818: 	if #fg>max or min>max or #(g+fg)<min then return nil end
748ed664c0 2023-06-29 2819: 	for tc in aux.Next(fg) do
748ed664c0 2023-06-29 2820: 		fg:SelectUnselect(sg,tp,false,false,min,max)
748ed664c0 2023-06-29 2821: 	end
748ed664c0 2023-06-29 2822: 	sg:Merge(fg)
748ed664c0 2023-06-29 2823: 	local finish=(#sg>=min and #sg<=max and f(sg,...))
748ed664c0 2023-06-29 2824: 	while #sg<max do
748ed664c0 2023-06-29 2825: 		local cg=Group.CreateGroup()
748ed664c0 2023-06-29 2826: 		local eg=g:Clone()
748ed664c0 2023-06-29 2827: 		for c in aux.Next(g-sg) do
748ed664c0 2023-06-29 2828: 			if not cg:IsContains(c) then
748ed664c0 2023-06-29 2829: 				if Auxiliary.CheckGroupRecursiveCapture(c,sg,eg,f,min,max,ext_params) then
748ed664c0 2023-06-29 2830: 					cg:Merge(Auxiliary.SubGroupCaptured)
748ed664c0 2023-06-29 2831: 				else
748ed664c0 2023-06-29 2832: 					eg:RemoveCard(c)
748ed664c0 2023-06-29 2833: 				end
748ed664c0 2023-06-29 2834: 			end
748ed664c0 2023-06-29 2835: 		end
748ed664c0 2023-06-29 2836: 		cg:Sub(sg)
748ed664c0 2023-06-29 2837: 		finish=(#sg>=min and #sg<=max and f(sg,...))
748ed664c0 2023-06-29 2838: 		if #cg==0 then break end
748ed664c0 2023-06-29 2839: 		local cancel=not finish and cancelable
748ed664c0 2023-06-29 2840: 		local tc=cg:SelectUnselect(sg,tp,finish,cancel,min,max)
748ed664c0 2023-06-29 2841: 		if not tc then break end
748ed664c0 2023-06-29 2842: 		if not fg:IsContains(tc) then
748ed664c0 2023-06-29 2843: 			if not sg:IsContains(tc) then
748ed664c0 2023-06-29 2844: 				sg:AddCard(tc)
748ed664c0 2023-06-29 2845: 				if #sg==max then finish=true end
748ed664c0 2023-06-29 2846: 			else
748ed664c0 2023-06-29 2847: 				sg:RemoveCard(tc)
748ed664c0 2023-06-29 2848: 			end
748ed664c0 2023-06-29 2849: 		elseif cancelable then
748ed664c0 2023-06-29 2850: 			return nil
748ed664c0 2023-06-29 2851: 		end
748ed664c0 2023-06-29 2852: 	end
748ed664c0 2023-06-29 2853: 	if finish then
748ed664c0 2023-06-29 2854: 		return sg
748ed664c0 2023-06-29 2855: 	else
748ed664c0 2023-06-29 2856: 		return nil
748ed664c0 2023-06-29 2857: 	end
748ed664c0 2023-06-29 2858: end
748ed664c0 2023-06-29 2859: function Auxiliary.CreateChecks(f,list)
748ed664c0 2023-06-29 2860: 	local checks={}
748ed664c0 2023-06-29 2861: 	for i=1,#list do
748ed664c0 2023-06-29 2862: 		checks[i]=function(c) return f(c,list[i]) end
748ed664c0 2023-06-29 2863: 	end
748ed664c0 2023-06-29 2864: 	return checks
748ed664c0 2023-06-29 2865: end
748ed664c0 2023-06-29 2866: function Auxiliary.CheckGroupRecursiveEach(c,sg,g,f,checks,ext_params)
748ed664c0 2023-06-29 2867: 	if not checks[1+#sg](c) then
748ed664c0 2023-06-29 2868: 		return false
748ed664c0 2023-06-29 2869: 	end
748ed664c0 2023-06-29 2870: 	sg:AddCard(c)
748ed664c0 2023-06-29 2871: 	if Auxiliary.GCheckAdditional and not Auxiliary.GCheckAdditional(sg,c,g,f,min,max,ext_params) then
748ed664c0 2023-06-29 2872: 		sg:RemoveCard(c)
748ed664c0 2023-06-29 2873: 		return false
748ed664c0 2023-06-29 2874: 	end
748ed664c0 2023-06-29 2875: 	local res
748ed664c0 2023-06-29 2876: 	if #sg==#checks then
748ed664c0 2023-06-29 2877: 		res=f(sg,table.unpack(ext_params))
748ed664c0 2023-06-29 2878: 	else
748ed664c0 2023-06-29 2879: 		res=g:IsExists(Auxiliary.CheckGroupRecursiveEach,1,sg,sg,g,f,checks,ext_params)
748ed664c0 2023-06-29 2880: 	end
748ed664c0 2023-06-29 2881: 	sg:RemoveCard(c)
748ed664c0 2023-06-29 2882: 	return res
748ed664c0 2023-06-29 2883: end
748ed664c0 2023-06-29 2884: function Group.CheckSubGroupEach(g,checks,f,...)
748ed664c0 2023-06-29 2885: 	if f==nil then f=Auxiliary.TRUE end
748ed664c0 2023-06-29 2886: 	if #g<#checks then return false end
748ed664c0 2023-06-29 2887: 	local ext_params={...}
748ed664c0 2023-06-29 2888: 	local sg=Group.CreateGroup()
748ed664c0 2023-06-29 2889: 	return g:IsExists(Auxiliary.CheckGroupRecursiveEach,1,sg,sg,g,f,checks,ext_params)
748ed664c0 2023-06-29 2890: end
748ed664c0 2023-06-29 2891: function Group.SelectSubGroupEach(g,tp,checks,cancelable,f,...)
748ed664c0 2023-06-29 2892: 	if cancelable==nil then cancelable=false end
748ed664c0 2023-06-29 2893: 	if f==nil then f=Auxiliary.TRUE end
748ed664c0 2023-06-29 2894: 	local ct=#checks
748ed664c0 2023-06-29 2895: 	local ext_params={...}
748ed664c0 2023-06-29 2896: 	local sg=Group.CreateGroup()
748ed664c0 2023-06-29 2897: 	local finish=false
748ed664c0 2023-06-29 2898: 	while #sg<ct do
748ed664c0 2023-06-29 2899: 		local cg=g:Filter(Auxiliary.CheckGroupRecursiveEach,sg,sg,g,f,checks,ext_params)
748ed664c0 2023-06-29 2900: 		if #cg==0 then break end
748ed664c0 2023-06-29 2901: 		local tc=cg:SelectUnselect(sg,tp,false,cancelable,ct,ct)
748ed664c0 2023-06-29 2902: 		if not tc then break end
748ed664c0 2023-06-29 2903: 		if not sg:IsContains(tc) then
748ed664c0 2023-06-29 2904: 			sg:AddCard(tc)
748ed664c0 2023-06-29 2905: 			if #sg==ct then finish=true end
748ed664c0 2023-06-29 2906: 		else
748ed664c0 2023-06-29 2907: 			sg:Clear()
748ed664c0 2023-06-29 2908: 		end
748ed664c0 2023-06-29 2909: 	end
748ed664c0 2023-06-29 2910: 	if finish then
748ed664c0 2023-06-29 2911: 		return sg
748ed664c0 2023-06-29 2912: 	else
748ed664c0 2023-06-29 2913: 		return nil
748ed664c0 2023-06-29 2914: 	end
748ed664c0 2023-06-29 2915: end
748ed664c0 2023-06-29 2916: --condition of "negate activation and banish"
748ed664c0 2023-06-29 2917: function Auxiliary.nbcon(tp,re)
748ed664c0 2023-06-29 2918: 	local rc=re:GetHandler()
748ed664c0 2023-06-29 2919: 	return Duel.IsPlayerCanRemove(tp)
748ed664c0 2023-06-29 2920: 		and (not rc:IsRelateToEffect(re) or rc:IsAbleToRemove())
748ed664c0 2023-06-29 2921: end
748ed664c0 2023-06-29 2922: function Auxiliary.nbtg(e,tp,eg,ep,ev,re,r,rp,chk)
748ed664c0 2023-06-29 2923: 	if chk==0 then return aux.nbcon(tp,re) end
748ed664c0 2023-06-29 2924: 	Duel.SetOperationInfo(0,CATEGORY_NEGATE,eg,1,0,0)
748ed664c0 2023-06-29 2925: 	if re:GetHandler():IsRelateToEffect(re) then
748ed664c0 2023-06-29 2926: 		Duel.SetOperationInfo(0,CATEGORY_REMOVE,eg,1,0,0)
748ed664c0 2023-06-29 2927: 	end
748ed664c0 2023-06-29 2928: 	if re:GetActivateLocation()==LOCATION_GRAVE then
748ed664c0 2023-06-29 2929: 		e:SetCategory(e:GetCategory()|CATEGORY_GRAVE_ACTION)
748ed664c0 2023-06-29 2930: 	else
748ed664c0 2023-06-29 2931: 		e:SetCategory(e:GetCategory()&~CATEGORY_GRAVE_ACTION)
748ed664c0 2023-06-29 2932: 	end
748ed664c0 2023-06-29 2933: end
748ed664c0 2023-06-29 2934: --condition of "negate activation and return to deck"
748ed664c0 2023-06-29 2935: function Auxiliary.ndcon(tp,re)
748ed664c0 2023-06-29 2936: 	local rc=re:GetHandler()
748ed664c0 2023-06-29 2937: 	return re:IsHasType(EFFECT_TYPE_ACTIVATE) or not rc:IsRelateToEffect(re) or rc:IsAbleToDeck()
748ed664c0 2023-06-29 2938: end
748ed664c0 2023-06-29 2939: --send to deck of contact fusion
748ed664c0 2023-06-29 2940: function Auxiliary.tdcfop(c)
748ed664c0 2023-06-29 2941: 	return	function(g)
748ed664c0 2023-06-29 2942: 				local cg=g:Filter(Card.IsFacedown,nil)
748ed664c0 2023-06-29 2943: 				if cg:GetCount()>0 then
748ed664c0 2023-06-29 2944: 					Duel.ConfirmCards(1-c:GetControler(),cg)
748ed664c0 2023-06-29 2945: 				end
748ed664c0 2023-06-29 2946: 				Duel.SendtoDeck(g,nil,SEQ_DECKSHUFFLE,REASON_COST)
748ed664c0 2023-06-29 2947: 			end
748ed664c0 2023-06-29 2948: end
748ed664c0 2023-06-29 2949: --return the global index of the zone in (p,loc,seq)
748ed664c0 2023-06-29 2950: function Auxiliary.SequenceToGlobal(p,loc,seq)
748ed664c0 2023-06-29 2951: 	if p~=0 and p~=1 then
748ed664c0 2023-06-29 2952: 		return 0
748ed664c0 2023-06-29 2953: 	end
748ed664c0 2023-06-29 2954: 	if loc==LOCATION_MZONE then
748ed664c0 2023-06-29 2955: 		if seq<=6 then
748ed664c0 2023-06-29 2956: 			return 0x0001<<(16*p+seq)
748ed664c0 2023-06-29 2957: 		else
748ed664c0 2023-06-29 2958: 			return 0
748ed664c0 2023-06-29 2959: 		end
748ed664c0 2023-06-29 2960: 	elseif loc == LOCATION_SZONE then
748ed664c0 2023-06-29 2961: 		if seq<=4 then
748ed664c0 2023-06-29 2962: 			return 0x0100<<(16*p+seq)
748ed664c0 2023-06-29 2963: 		else
748ed664c0 2023-06-29 2964: 			return 0
748ed664c0 2023-06-29 2965: 		end
748ed664c0 2023-06-29 2966: 	else
748ed664c0 2023-06-29 2967: 		return 0
748ed664c0 2023-06-29 2968: 	end
748ed664c0 2023-06-29 2969: end
748ed664c0 2023-06-29 2970: --use the count limit of Lair of Darkness if the tributes are not selected by Duel.SelectReleaseGroup
748ed664c0 2023-06-29 2971: function Auxiliary.UseExtraReleaseCount(g,tp)
748ed664c0 2023-06-29 2972: 	local eg=g:Filter(Auxiliary.ExtraReleaseFilter,nil,tp)
748ed664c0 2023-06-29 2973: 	for ec in Auxiliary.Next(eg) do
748ed664c0 2023-06-29 2974: 		local te=ec:IsHasEffect(EFFECT_EXTRA_RELEASE_NONSUM,tp)
748ed664c0 2023-06-29 2975: 		if te then te:UseCountLimit(tp) end
748ed664c0 2023-06-29 2976: 	end
748ed664c0 2023-06-29 2977: end
748ed664c0 2023-06-29 2978: function Auxiliary.ExtraReleaseFilter(c,tp)
748ed664c0 2023-06-29 2979: 	return c:IsControler(1-tp) and c:IsHasEffect(EFFECT_EXTRA_RELEASE_NONSUM,tp)
748ed664c0 2023-06-29 2980: end
748ed664c0 2023-06-29 2981: function Auxiliary.IsSpecialSummonedByEffect(e)
748ed664c0 2023-06-29 2982: 	return not ((e:GetCode()==EFFECT_SPSUMMON_PROC or e:GetCode()==EFFECT_SPSUMMON_PROC_G) and e:GetProperty()&(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)==(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE))
748ed664c0 2023-06-29 2983: end
748ed664c0 2023-06-29 2984: --
748ed664c0 2023-06-29 2985: function Auxiliary.GetCappedLevel(c)
748ed664c0 2023-06-29 2986: 	local lv=c:GetLevel()
748ed664c0 2023-06-29 2987: 	if lv>MAX_PARAMETER then
748ed664c0 2023-06-29 2988: 		return MAX_PARAMETER
748ed664c0 2023-06-29 2989: 	else
748ed664c0 2023-06-29 2990: 		return lv
748ed664c0 2023-06-29 2991: 	end
748ed664c0 2023-06-29 2992: end
748ed664c0 2023-06-29 2993: --
748ed664c0 2023-06-29 2994: function Auxiliary.GetCappedAttack(c)
748ed664c0 2023-06-29 2995: 	local x=c:GetAttack()
748ed664c0 2023-06-29 2996: 	if x>MAX_PARAMETER then
748ed664c0 2023-06-29 2997: 		return MAX_PARAMETER
748ed664c0 2023-06-29 2998: 	else
748ed664c0 2023-06-29 2999: 		return x
748ed664c0 2023-06-29 3000: 	end
748ed664c0 2023-06-29 3001: end
748ed664c0 2023-06-29 3002: --when this card is sent to grave, record the reason effect
748ed664c0 2023-06-29 3003: --to check whether the reason effect do something simultaneously
748ed664c0 2023-06-29 3004: --so the "while this card is in your GY" condition isn't met
748ed664c0 2023-06-29 3005: function Auxiliary.AddThisCardInGraveAlreadyCheck(c)
748ed664c0 2023-06-29 3006: 	local e1=Effect.CreateEffect(c)
748ed664c0 2023-06-29 3007: 	e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_CONTINUOUS)
748ed664c0 2023-06-29 3008: 	e1:SetCode(EVENT_TO_GRAVE)
748ed664c0 2023-06-29 3009: 	e1:SetCondition(Auxiliary.ThisCardInGraveAlreadyCheckReg)
748ed664c0 2023-06-29 3010: 	c:RegisterEffect(e1)
748ed664c0 2023-06-29 3011: 	return e1
748ed664c0 2023-06-29 3012: end
748ed664c0 2023-06-29 3013: function Auxiliary.ThisCardInGraveAlreadyCheckReg(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 3014: 	--condition of continous effect will be checked before other effects
748ed664c0 2023-06-29 3015: 	if re==nil then return false end
748ed664c0 2023-06-29 3016: 	if e:GetLabelObject()~=nil then return false end
748ed664c0 2023-06-29 3017: 	if (r&REASON_EFFECT)>0 then
748ed664c0 2023-06-29 3018: 		e:SetLabelObject(re)
748ed664c0 2023-06-29 3019: 		local e1=Effect.CreateEffect(e:GetHandler())
748ed664c0 2023-06-29 3020: 		e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
748ed664c0 2023-06-29 3021: 		e1:SetCode(EVENT_CHAIN_END)
748ed664c0 2023-06-29 3022: 		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
748ed664c0 2023-06-29 3023: 		e1:SetOperation(Auxiliary.ThisCardInGraveAlreadyReset1)
748ed664c0 2023-06-29 3024: 		e1:SetLabelObject(e)
748ed664c0 2023-06-29 3025: 		Duel.RegisterEffect(e1,tp)
748ed664c0 2023-06-29 3026: 		local e2=e1:Clone()
748ed664c0 2023-06-29 3027: 		e2:SetCode(EVENT_BREAK_EFFECT)
748ed664c0 2023-06-29 3028: 		e2:SetOperation(Auxiliary.ThisCardInGraveAlreadyReset2)
748ed664c0 2023-06-29 3029: 		e2:SetReset(RESET_CHAIN)
748ed664c0 2023-06-29 3030: 		e2:SetLabelObject(e1)
748ed664c0 2023-06-29 3031: 		Duel.RegisterEffect(e2,tp)
748ed664c0 2023-06-29 3032: 	elseif (r&REASON_MATERIAL)>0 or not re:IsActivated() and (r&REASON_COST)>0 then
748ed664c0 2023-06-29 3033: 		e:SetLabelObject(re)
748ed664c0 2023-06-29 3034: 		local reset_event=EVENT_SPSUMMON
748ed664c0 2023-06-29 3035: 		if re:GetCode()~=EFFECT_SPSUMMON_PROC then reset_event=EVENT_SUMMON end
748ed664c0 2023-06-29 3036: 		local e1=Effect.CreateEffect(e:GetHandler())
748ed664c0 2023-06-29 3037: 		e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
748ed664c0 2023-06-29 3038: 		e1:SetCode(reset_event)
748ed664c0 2023-06-29 3039: 		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
748ed664c0 2023-06-29 3040: 		e1:SetOperation(Auxiliary.ThisCardInGraveAlreadyReset1)
748ed664c0 2023-06-29 3041: 		e1:SetLabelObject(e)
748ed664c0 2023-06-29 3042: 		Duel.RegisterEffect(e1,tp)
748ed664c0 2023-06-29 3043: 	end
748ed664c0 2023-06-29 3044: 	return false
748ed664c0 2023-06-29 3045: end
748ed664c0 2023-06-29 3046: function Auxiliary.ThisCardInGraveAlreadyReset1(e)
748ed664c0 2023-06-29 3047: 	--this will run after EVENT_SPSUMMON_SUCCESS
748ed664c0 2023-06-29 3048: 	e:GetLabelObject():SetLabelObject(nil)
748ed664c0 2023-06-29 3049: 	e:Reset()
748ed664c0 2023-06-29 3050: end
748ed664c0 2023-06-29 3051: function Auxiliary.ThisCardInGraveAlreadyReset2(e)
748ed664c0 2023-06-29 3052: 	local e1=e:GetLabelObject()
748ed664c0 2023-06-29 3053: 	e1:GetLabelObject():SetLabelObject(nil)
748ed664c0 2023-06-29 3054: 	e1:Reset()
748ed664c0 2023-06-29 3055: 	e:Reset()
748ed664c0 2023-06-29 3056: end
748ed664c0 2023-06-29 3057: --Player p place g on the top of Deck in any order
748ed664c0 2023-06-29 3058: function Auxiliary.PlaceCardsOnDeckTop(p,g,reason)
748ed664c0 2023-06-29 3059: 	if reason==nil then reason=REASON_EFFECT end
748ed664c0 2023-06-29 3060: 	Duel.SendtoDeck(g,nil,SEQ_DECKTOP,reason)
748ed664c0 2023-06-29 3061: 	local rg=Duel.GetOperatedGroup()
748ed664c0 2023-06-29 3062: 	local og=rg:Filter(Card.IsLocation,nil,LOCATION_DECK)
748ed664c0 2023-06-29 3063: 	local ct1=og:FilterCount(Card.IsControler,nil,p)
748ed664c0 2023-06-29 3064: 	local ct2=og:FilterCount(Card.IsControler,nil,1-p)
748ed664c0 2023-06-29 3065: 	if ct1>1 then
748ed664c0 2023-06-29 3066: 		Duel.SortDecktop(p,p,ct1)
748ed664c0 2023-06-29 3067: 	end
748ed664c0 2023-06-29 3068: 	if ct2>1 then
748ed664c0 2023-06-29 3069: 		Duel.SortDecktop(p,1-p,ct2)
748ed664c0 2023-06-29 3070: 	end
748ed664c0 2023-06-29 3071: 	return #rg
748ed664c0 2023-06-29 3072: end
748ed664c0 2023-06-29 3073: --Player p place g on the bottom of Deck in any order
748ed664c0 2023-06-29 3074: function Auxiliary.PlaceCardsOnDeckBottom(p,g,reason)
748ed664c0 2023-06-29 3075: 	if reason==nil then reason=REASON_EFFECT end
748ed664c0 2023-06-29 3076: 	Duel.SendtoDeck(g,nil,SEQ_DECKTOP,reason)
748ed664c0 2023-06-29 3077: 	local rg=Duel.GetOperatedGroup()
748ed664c0 2023-06-29 3078: 	local og=rg:Filter(Card.IsLocation,nil,LOCATION_DECK)
748ed664c0 2023-06-29 3079: 	local ct1=og:FilterCount(Card.IsControler,nil,p)
748ed664c0 2023-06-29 3080: 	local ct2=og:FilterCount(Card.IsControler,nil,1-p)
748ed664c0 2023-06-29 3081: 	if ct1>0 then
748ed664c0 2023-06-29 3082: 		if ct1>1 then
748ed664c0 2023-06-29 3083: 			Duel.SortDecktop(p,p,ct1)
748ed664c0 2023-06-29 3084: 		end
748ed664c0 2023-06-29 3085: 		for i=1,ct1 do
748ed664c0 2023-06-29 3086: 			local tc=Duel.GetDecktopGroup(p,1):GetFirst()
748ed664c0 2023-06-29 3087: 			Duel.MoveSequence(tc,SEQ_DECKBOTTOM)
748ed664c0 2023-06-29 3088: 		end
748ed664c0 2023-06-29 3089: 	end
748ed664c0 2023-06-29 3090: 	if ct2>0 then
748ed664c0 2023-06-29 3091: 		if ct2>1 then
748ed664c0 2023-06-29 3092: 			Duel.SortDecktop(p,1-p,ct2)
748ed664c0 2023-06-29 3093: 		end
748ed664c0 2023-06-29 3094: 		for i=1,ct2 do
748ed664c0 2023-06-29 3095: 			local tc=Duel.GetDecktopGroup(1-p,1):GetFirst()
748ed664c0 2023-06-29 3096: 			Duel.MoveSequence(tc,SEQ_DECKBOTTOM)
748ed664c0 2023-06-29 3097: 		end
748ed664c0 2023-06-29 3098: 	end
748ed664c0 2023-06-29 3099: 	return #rg
748ed664c0 2023-06-29 3100: end
748ed664c0 2023-06-29 3101: --The event is triggered multiple times in a chain
748ed664c0 2023-06-29 3102: --but only 1 event with EVENT_CUSTOM+code will be triggered at EVENT_CHAIN_END, or immediately if not in chain
748ed664c0 2023-06-29 3103: --NOTE: re,r,rp,ep,ev of that custom event ARE NOT releated to the real event that trigger this custom event
748ed664c0 2023-06-29 3104: function Auxiliary.RegisterMergedDelayedEvent(c,code,event,g)
748ed664c0 2023-06-29 3105: 	local mt=getmetatable(c)
748ed664c0 2023-06-29 3106: 	if mt[event]==true then return end
748ed664c0 2023-06-29 3107: 	mt[event]=true
748ed664c0 2023-06-29 3108: 	if not g then g=Group.CreateGroup() end
748ed664c0 2023-06-29 3109: 	g:KeepAlive()
748ed664c0 2023-06-29 3110: 	local ge1=Effect.CreateEffect(c)
748ed664c0 2023-06-29 3111: 	ge1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
748ed664c0 2023-06-29 3112: 	ge1:SetCode(event)
748ed664c0 2023-06-29 3113: 	ge1:SetLabel(code)
748ed664c0 2023-06-29 3114: 	ge1:SetLabelObject(g)
748ed664c0 2023-06-29 3115: 	ge1:SetOperation(Auxiliary.MergedDelayEventCheck1)
748ed664c0 2023-06-29 3116: 	Duel.RegisterEffect(ge1,0)
748ed664c0 2023-06-29 3117: 	local ge2=ge1:Clone()
748ed664c0 2023-06-29 3118: 	ge2:SetCode(EVENT_CHAIN_END)
748ed664c0 2023-06-29 3119: 	ge2:SetOperation(Auxiliary.MergedDelayEventCheck2)
748ed664c0 2023-06-29 3120: 	Duel.RegisterEffect(ge2,0)
748ed664c0 2023-06-29 3121: end
748ed664c0 2023-06-29 3122: function Auxiliary.MergedDelayEventCheck1(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 3123: 	local g=e:GetLabelObject()
748ed664c0 2023-06-29 3124: 	g:Merge(eg)
748ed664c0 2023-06-29 3125: 	if Duel.GetCurrentChain()==0 and not Duel.CheckEvent(EVENT_CHAIN_END) then
748ed664c0 2023-06-29 3126: 		local _eg=g:Clone()
748ed664c0 2023-06-29 3127: 		Duel.RaiseEvent(_eg,EVENT_CUSTOM+e:GetLabel(),re,r,rp,ep,ev)
748ed664c0 2023-06-29 3128: 		g:Clear()
748ed664c0 2023-06-29 3129: 	end
748ed664c0 2023-06-29 3130: end
748ed664c0 2023-06-29 3131: function Auxiliary.MergedDelayEventCheck2(e,tp,eg,ep,ev,re,r,rp)
748ed664c0 2023-06-29 3132: 	local g=e:GetLabelObject()
748ed664c0 2023-06-29 3133: 	if #g>0 then
748ed664c0 2023-06-29 3134: 		local _eg=g:Clone()
748ed664c0 2023-06-29 3135: 		Duel.RaiseEvent(_eg,EVENT_CUSTOM+e:GetLabel(),re,r,rp,ep,ev)
748ed664c0 2023-06-29 3136: 		g:Clear()
748ed664c0 2023-06-29 3137: 	end
748ed664c0 2023-06-29 3138: end