游戏王残局简化版

Annotation For script/utility.lua
Login

Annotation For script/utility.lua

Origin for each line in script/utility.lua from check-in c83543efed:

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