{"v":1,"manifest":{"v":1,"license":"GPL-2.0","base":{"repo":"mycard/ygopro-scripts","sha":"b83db1cc3f512d3bec2faafb9ecf199143332be1"},"formats":{"edison":{"date":"2010-04-24","overrides":[{"code":50321796,"name":"Brionac, Dragon of the Ice Barrier","file":"c50321796.lua","baseSha256":"a77e8b6c84c218c29e32724f09667b1045ee8f6c4cd58962885f7a417259274c","summary":"Discard any number of cards to return that many cards on the field, on either side, to the hand. No once-per-turn limit.","then":{"printing":"DT01-EN031","set":"Duel Terminal 1","date":"2010-01-29"},"yugipedia":{"page":"Card Errata:Brionac, Dragon of the Ice Barrier","revid":5762410},"community":"https://www.edisonformat.com/functional-errata.html"},{"code":7391448,"name":"Goyo Guardian","file":"c7391448.lua","baseSha256":"483c0b879c015fa020944ab5026aa3364374585163a7df57973b6e1f54ef0aeb","summary":"1 Tuner of any Attribute + 1 or more non-Tuner monsters.","then":{"printing":"DT01-EN087","set":"Duel Terminal 1","date":"2010-01-29"},"yugipedia":{"page":"Card Errata:Goyo Guardian","revid":5704864},"community":"https://www.edisonformat.com/functional-errata.html"},{"code":87910978,"name":"Brain Control","file":"c87910978.lua","baseSha256":"18173c3616795ec2f4995bae7190f87549bbfedce34707006f83a7b32630d865","summary":"Takes any face-up monster the opponent controls, Synchro, Fusion and Special-Summon-only monsters included.","then":{"printing":"YSDJ-EN030","set":"Starter Deck: Jaden Yuki","date":"2007-07-25"},"yugipedia":{"page":"Card Errata:Brain Control","revid":5704504},"community":"https://www.edisonformat.com/functional-errata.html"},{"code":25862681,"name":"Ancient Fairy Dragon","file":"c25862681.lua","baseSha256":"3ffda16b363855d156fc0d8e160ed58bd345b0037c53f568b5c0f2cb0a2c288b","summary":"Each effect is once per turn per copy, in either Main Phase. Destroys one Field Spell without targeting; if it does, gain 1000 LP and you may add any Field Spell from the Deck.","then":{"printing":"CT06-EN002","set":"Collectible Tins 2009 Wave 1","date":"2009-08-18"},"yugipedia":{"page":"Card Errata:Ancient Fairy Dragon","revid":5704390},"community":"https://www.edisonformat.com/functional-errata.html"},{"code":26202165,"name":"Sangan","file":"c26202165.lua","baseSha256":"238d78bc971fc4d358e5c1bbe1a4e9daa4968a608ac32dbecd41d7284b9e9268","summary":"Searches every time it goes from the field to the GY, and the searched card can be used that turn.","then":{"printing":"SYE-018","set":"Starter Deck: Yugi Evolution","date":"2004-03-01"},"yugipedia":{"page":"Card Errata:Sangan","revid":5705263},"community":"https://www.edisonformat.com/functional-errata.html"},{"code":77565204,"name":"Future Fusion","file":"c77565204.lua","baseSha256":"5b927b5617e60a0271cfa49abc0704ef7cecc4832a7b5abbfc0b694120631af0","summary":"Sends the Fusion Materials from the Deck to the GY as it resolves; the Fusion Monster comes in your 2nd Standby Phase.","then":{"printing":"GLD2-EN039","set":"Gold Series 2009","date":"2009-04-21"},"yugipedia":{"page":"Card Errata:Future Fusion","revid":5802708},"community":"https://www.edisonformat.com/functional-errata.html"},{"code":14878871,"name":"Rescue Cat","file":"c14878871.lua","baseSha256":"2a9547168cbdb08204e7c000655b2e78982e76d9d417b8e18e8d57a336dc46ef","summary":"The two Beasts keep their effects, and the effect has no once-per-turn limit.","then":{"printing":"CP05-EN015","set":"Champion Pack: Game Five","date":"2008-01-08"},"yugipedia":{"page":"Card Errata:Rescue Cat","revid":5789261},"community":"https://www.edisonformat.com/functional-errata.html"},{"code":88264978,"name":"Red-Eyes Darkness Metal Dragon","file":"c88264978.lua","baseSha256":"ace84bec433e5311ddf0c042c6ca89a86a2dcb94ff5eb5b3f705ddc00b38ba44","summary":"Summons itself any number of times a turn; its revive is once per turn per copy, not by name.","then":{"printing":"ABPF-ENSE2","set":"Absolute Powerforce: Special Edition","date":"2010-03-30"},"yugipedia":{"page":"Card Errata:Red-Eyes Darkness Metal Dragon","revid":5789293},"community":"https://www.edisonformat.com/functional-errata.html"},{"code":16226786,"name":"Night Assailant","file":"c16226786.lua","baseSha256":"2be968355979b7d879d25555b28981a38f9f937576cb265dcd8a5623cace5035","summary":"When discarded, returns any Flip monster from the GY, another Night Assailant included.","then":{"printing":"AST-080","set":"Ancient Sanctuary","date":"2004-06-01"},"yugipedia":{"page":"Card Errata:Night Assailant","revid":5705122},"community":null},{"code":47297616,"name":"Light and Darkness Dragon","file":"c47297616.lua","baseSha256":"500fe61369adf80f4300af99840e24338bef51cb0f82f20d950e3c7b9bbbe67e","summary":"Negates every Spell/Trap activation and every monster effect activation, each costing 500 ATK/DEF, several in one chain included.","then":{"printing":"YG01-EN001","set":"Yu-Gi-Oh! GX Volume 1 promotional card","date":"2007-11-06"},"yugipedia":{"page":"Card Errata:Light and Darkness Dragon","revid":5364877},"community":"https://www.edisonformat.com/functional-errata.html"},{"code":47355498,"name":"Necrovalley","file":"c47355498.lua","baseSha256":"083379c8b5728f1f768dfe876212b5fbacc389130b33e45d07572ae3e51b4085","summary":"Negates only effects that target a card in a GY, and such an effect cannot be activated. Cards in a GY cannot be removed from play. Effects that don't target a GY card work.","then":{"printing":"TU02-EN014","set":"Turbo Pack: Booster Two","date":"2010-01-09"},"yugipedia":{"page":"Card Errata:Necrovalley","revid":5848534},"community":"https://www.edisonformat.com/functional-errata.html","note":"edisonformat.com says only that the effect \"only negates effects that target\", and its per-card rulings (rulings/individual-rulings-l-o) say such effects are \"negated by Necrovalley\". Neither says whether they can be activated. The activation block is carried over from the pre-2009 TCG ruling (the same one goatformat.com records for Goat): Yugipedia, Card Rulings:Necrovalley (revision 5742796), UDE Rulings (previously official): \"If Necrovalley is active, neither player may activate Book of Life\". No Edison-era (2009–2010) ruling on activation was found. Edison's published text is the negation, not the block."},{"code":29071332,"name":"Armory Arm","file":"c29071332.lua","baseSha256":"203f26cd9df396c9c25cc5ea57e38fe7475fdfd5ab206a824f9ca40920e4082f","summary":"The damage is the ATK the destroyed monster had on the field, boosts included, even if it has left the GY by then.","then":{"printing":"DP08-EN016","set":"Duelist Pack: Yusei","date":"2009-02-24"},"yugipedia":{"page":"Card Errata:Armory Arm","revid":5710970},"community":"https://www.edisonformat.com/functional-errata.html","note":"Printed text: \"equal to the destroyed monster's ATK\". Which ATK, and that the damage stands if it leaves the GY, are edisonformat's rulings."},{"code":21502796,"name":"Ryko, Lightsworn Hunter","file":"c21502796.lua","baseSha256":"de783207371ecb34c1909e68925cf4d133b79c3058a7a6a99d7cd8ae7f53840f","summary":"FLIP: you may target 1 card on the field as it activates; destroy it, then send the top 3 cards of your Deck to the GY.","then":{"printing":"LODT-EN022","set":"Light of Destruction","date":"2008-05-13"},"yugipedia":{"page":"Card Errata:Ryko, Lightsworn Hunter","revid":5114250},"community":"https://www.edisonformat.com/functional-errata.html","note":"The printing says \"You can destroy 1 card on the field\" and does not mention a target. The targeting (\"targets 1 card on the field (OPTIONAL)\") is edisonformat's ruling."},{"code":89312388,"name":"Elemental HERO Prisma","file":"c89312388.lua","baseSha256":"ae483113a2f190f384896e219ecef73db13b4afb61881bbe0de81753889386f8","summary":"Reveals the Fusion Monster and sends the Material as it resolves, not as a cost; nothing is sent if Prisma is no longer face-up.","then":{"printing":"DPCT-EN002","set":"Duelist Pack Collection Tin: Jaden Yuki","date":"2008-03-23"},"yugipedia":{"page":"Card Errata:Elemental HERO Prisma","revid":5721764},"community":"https://www.edisonformat.com/functional-errata.html","note":"Not a cost, and nothing sent when Prisma is not face-up: both are edisonformat's notes on the card."},{"code":68005187,"name":"Soul Exchange","file":"c68005187.lua","baseSha256":"571a463ba3eed59f23aa85c427252f090420fed77f68149e97b3b08468ea882c","summary":"You may Tribute the selected monster this turn as if you controlled it; you don't have to.","then":{"printing":"DTP1-EN010","set":"Duel Terminal - Preview Wave 1","date":"2008-07-24"},"yugipedia":{"page":"Card Errata:Soul Exchange","revid":5884065},"community":"https://www.edisonformat.com/functional-errata.html","note":"Printed: \"This turn you can Tribute that monster as if you controlled it.\" edisonformat: \"Tributing the opponent's monster is optional.\""},{"code":9126351,"name":"Swap Frog","file":"c9126351.lua","baseSha256":"782c90652cc8faef789db2802431ae0a3efaf979f3c4596e73bf321aed0e061e","summary":"Each Swap Frog can bounce a monster once per turn even after the extra Normal Summon was gained; you still gain only one.","then":{"printing":"SOVR-EN034","set":"Stardust Overdrive","date":"2009-11-17"},"yugipedia":{"page":"Card Errata:Swap Frog","revid":5732452},"community":"https://www.edisonformat.com/functional-errata.html","note":"Both halves are edisonformat's notes. The printing also excludes \"Frog the Jam\" from the extra Summon; that card is not in our card table, so it is not modelled."},{"code":69279219,"name":"My Body as a Shield","file":"c69279219.lua","baseSha256":"59f72c74f96bb534464899b9026777bc0713f497790da9370adbc2237927929d","summary":"Can answer an effect of a face-up Spell or Trap that would destroy a monster, not only a card activation or a monster effect.","then":{"printing":"TU02-EN007","set":"Turbo Pack: Booster Two","date":"2010-01-09"},"yugipedia":{"page":"Card Errata:My Body as a Shield","revid":5790168},"community":"https://www.edisonformat.com/functional-errata.html","note":"Printed: \"when your opponent activates a card with an effect that would destroy\". That it can chain to an effect of a face-up card is edisonformat's note."},{"code":45247637,"name":"Mark of the Rose","file":"c45247637.lua","baseSha256":"cc83f1b38ffbe12c28238ff8965f29878a579f60ea9d05da1a8878df8a04e104","summary":"You take control back in your Standby Phase by a trigger that starts a Chain, as you give it back in the End Phase.","then":{"printing":"CSOC-EN047","set":"Crossroads of Chaos","date":"2008-11-18"},"yugipedia":{"page":"Card Errata:Mark of the Rose","revid":5801986},"community":"https://www.edisonformat.com/functional-errata.html","note":"\"There are 2 [Trigger] effects, both start a Chain\" is edisonformat's note."},{"code":71645242,"name":"Black Garden","file":"c71645242.lua","baseSha256":"f13b1225985a7d27bad20bae8270caaf14256445d00a9a564463b5f14efb67ff","summary":"Its Ignition effect does not target: the monster whose ATK equals the total of the destroyed Plants is chosen as it resolves.","then":{"printing":"CSOC-EN048","set":"Crossroads of Chaos","date":"2008-11-18"},"yugipedia":{"page":"Card Errata:Black Garden","revid":5802027},"community":"https://www.edisonformat.com/functional-errata.html","note":"The printing does not target (\"Special Summon 1 monster with ATK equal to the total ATK of those monsters from your Graveyard\"). edisonformat also says the token trigger activates for a face-down Special Summon; that is not modelled, so face-down Summons play today's text."},{"code":20932152,"name":"Quickdraw Synchron","file":"c20932152.lua","baseSha256":"72571fcf4b2add97268065cffe189b5fa3d5e67b697d5a2221d1b1b5c1bcef07","status":"community-ruling","summary":"Its Special Summon is an Ignition effect from the hand that starts a Chain: the monster from your hand goes to the Graveyard as it resolves, not as a cost, so negating it sends nothing (ruled at SJC Edison 2010).","then":{"printing":"SOVR-EN004","set":"Stardust Overdrive","date":"2009-11-17"},"yugipedia":{"page":"Card Errata:Quickdraw Synchron","revid":5705187},"community":"https://www.edisonformat.com/home/rules-update-quickdraws-summon-is-an-activated-effect","note":"reported SJC Edison 2010 head-judge ruling via edisonformat; no written UDE or Konami FAQ"}],"known":[{"code":79575620,"name":"Injection Fairy Lily","status":"same","note":"Once per battle then and now.","sources":["https://www.goatformat.com/rulings4.html","https://www.edisonformat.com/rulings/individual-rulings-i-k"]},{"code":41006930,"name":"Strike Ninja","status":"deferred","note":"edisonformat: once per turn per copy (\"Multiple Strike Ninja can use this effect in the same turn\"); today it is once per turn by name. In 1 of 1,221 Edison decks.","sources":["https://www.edisonformat.com/functional-errata.html"]}]},"goat":{"date":"2005-08-20","overrides":[{"code":83555666,"name":"Ring of Destruction","file":"c83555666.lua","baseSha256":"86ef22d55914769b60a694f0bfdff6db81dbdf1d2845f0726e0fd65234bf29ae","summary":"Any turn, any face-up monster on either side: destroy it and both players take damage equal to its ATK at once.","then":{"printing":"IOC-SE3","set":"Invasion of Chaos: Special Edition","date":"2004-04"},"yugipedia":{"page":"Card Errata:Ring of Destruction","revid":5801962},"community":"https://www.goatformat.com/rulings6.html"},{"code":26202165,"name":"Sangan","file":"c26202165.lua","baseSha256":"238d78bc971fc4d358e5c1bbe1a4e9daa4968a608ac32dbecd41d7284b9e9268","summary":"Searches every time it goes from the field to the GY, and the searched card can be used that turn.","then":{"printing":"SYE-018","set":"Starter Deck: Yugi Evolution","date":"2004-03-01"},"yugipedia":{"page":"Card Errata:Sangan","revid":5705263},"community":"https://www.goatformat.com/rulings7.html"},{"code":8131171,"name":"Sinister Serpent","file":"c8131171.lua","baseSha256":"c2a1f3231702ee158a0f4f204f64482b63e8b7586673e46a8c69860152a310f0","summary":"Returns from the GY to the hand in each of your Standby Phases; no limit and nothing is banished.","then":{"printing":"SDD-002","set":"Stairway to the Destined Duel promotional cards","date":"2003-04-15"},"yugipedia":{"page":"Card Errata:Sinister Serpent","revid":5705296},"community":"https://www.goatformat.com/rulings7.html"},{"code":87910978,"name":"Brain Control","file":"c87910978.lua","baseSha256":"18173c3616795ec2f4995bae7190f87549bbfedce34707006f83a7b32630d865","summary":"Takes any face-up monster the opponent controls, Fusion and Special-Summon-only monsters included.","then":{"printing":"TLM-EN038","set":"The Lost Millennium","date":"2005-06-01"},"yugipedia":{"page":"Card Errata:Brain Control","revid":5704504},"community":"https://www.goatformat.com/rulings1.html"},{"code":16226786,"name":"Night Assailant","file":"c16226786.lua","baseSha256":"2be968355979b7d879d25555b28981a38f9f937576cb265dcd8a5623cace5035","summary":"When discarded, returns any Flip monster from the GY, another Night Assailant included.","then":{"printing":"AST-080","set":"Ancient Sanctuary","date":"2004-06-01"},"yugipedia":{"page":"Card Errata:Night Assailant","revid":5705122},"community":"https://www.goatformat.com/rulings5.html"},{"code":40737112,"name":"Dark Magician of Chaos","file":"c40737112.lua","baseSha256":"1d522f1d93b07f34aa5107f3be434a2b3921e17c8c1d32b6db2431b84d08e054","summary":"Adds a Spell from the GY as soon as it is Summoned, with no once-per-turn limit.","then":{"printing":"IOC-EN065","set":"Invasion of Chaos","date":"2004-03-01"},"yugipedia":{"page":"Card Errata:Dark Magician of Chaos","revid":5739946},"community":"https://www.goatformat.com/rulings2.html"},{"code":14878871,"name":"Rescue Cat","file":"c14878871.lua","baseSha256":"2a9547168cbdb08204e7c000655b2e78982e76d9d417b8e18e8d57a336dc46ef","summary":"The two Beasts keep their effects, and the effect has no once-per-turn limit.","then":{"printing":"FET-EN033","set":"Flaming Eternity","date":"2005-03-01"},"yugipedia":{"page":"Card Errata:Rescue Cat","revid":5789261},"community":"https://www.goatformat.com/rulings6.html"},{"code":47355498,"name":"Necrovalley","file":"c47355498.lua","baseSha256":"083379c8b5728f1f768dfe876212b5fbacc389130b33e45d07572ae3e51b4085","summary":"Effects that target a card in a GY cannot be activated and are negated. Cards in a GY cannot be removed from play. Skilled Dark and White Magician summon from the hand or Deck only. Other effects that don't target a GY card work.","then":{"printing":"DR1-EN032","set":"Dark Revelation Volume 1","date":"2005-03-19"},"yugipedia":{"page":"Card Errata:Necrovalley","revid":5848534},"community":"https://www.goatformat.com/rulings5.html","note":"Plays the targeting rule from goatformat.com's Individual Card FAQs and Netrep rulings (\"negate and prevent the activation of any effects that target the Graveyard\"; Yugipedia, Card Rulings:Necrovalley (revision 5742796), UDE Rulings (previously official): \"If Necrovalley is active, neither player may activate Book of Life\"). Necrovalley's text reaches two non-targeting cards in our Goat decks by ruling, listed under `reaches`. goatformat names other non-targeting cards it negates (Question, Fiber Jar, Penguin Knight, Agido, Big Burn, Gilasaurus's summon for the opponent); none of them is in a Goat deck we hold, so this override does not negate them.","reaches":[{"code":73752131,"name":"Skilled Dark Magician","reached":true,"note":"Summons Dark Magician from the hand or Deck only. goatformat.com/rulings5.html, Netrep Q&A, Curtis Schultz 2003-12-30: Necrovalley vs. Skilled Dark/White Magician, \"Hand or Deck only in this situation.\" Activation is as today's script has it: it can be activated with a Dark Magician only in the GY, and then summons nothing."},{"code":46363422,"name":"Skilled White Magician","reached":true,"note":"Summons Buster Blader from the hand or Deck only. goatformat.com/rulings5.html, Netrep Q&A, Curtis Schultz 2003-12-30: Necrovalley vs. Skilled Dark/White Magician, \"Hand or Deck only in this situation.\" Activation is as today's script has it."},{"code":69542930,"name":"Dedication through Light and Darkness","reached":false,"note":"Summons Dark Magician of Chaos from the GY too in Goat: it does not target (goatformat rulings2), and no period ruling says Necrovalley stops it."},{"code":87210505,"name":"Knight's Title","reached":false,"note":"Summons Dark Magician Knight from the GY too in Goat: it does not target, and no period ruling says Necrovalley stops it."}]},{"code":85602018,"name":"Last Will","file":"c85602018.lua","baseSha256":"488750f202e31ba25e58c465015860aa8adc76089b17bd409ef40d6b57807c08","summary":"Activating it waits for the next time this turn one of your monsters goes from the field to your GY; then you may summon a 1500-or-less monster from your Deck. Earlier sends don't count; each Last Will gives one Summon.","then":{"printing":"SYE-031","set":"Starter Deck: Yugi Evolution","date":"2004-03-01"},"yugipedia":{"page":"Card Errata:Last Will","revid":5883719},"community":"https://www.goatformat.com/rulings5.html","note":"goatformat's Individual Card FAQs: the state applies to \"the next time during that turn\", \"These states accumulate\", and it resolves \"at that time (just like Giant Rat)\". It is modelled as a mandatory delayed trigger that each activation registers: it fires on the next send, asks whether to Summon, and then ends."}],"known":[{"code":23205979,"name":"Spirit Reaper","status":"unverified","note":"The 2005 text destroys it when it is targeted; today's after the effect resolves. No period ruling found yet.","sources":[]},{"code":79575620,"name":"Injection Fairy Lily","status":"same","note":"Once per battle then and now.","sources":["https://www.goatformat.com/rulings4.html","https://www.edisonformat.com/rulings/individual-rulings-i-k"]},{"code":43586926,"name":"Twin-Headed Behemoth","status":"deferred","note":"SD1-EN004 (2005-01-01): \"it will be Special Summoned during the End Phase\", a mandatory summon; today \"You can\". In 10 of 214 Goat decks, below the threshold of 11.","sources":["https://www.goatformat.com/rulings7.html","https://yugipedia.com/wiki/Card_Errata:Twin-Headed_Behemoth (revision 5982196)"]},{"code":41006930,"name":"Strike Ninja","status":"deferred","note":"IOC-007 (2004-03-01): \"You can only use this effect once per turn\", read per copy; today once per turn by name. In 4 of 214 Goat decks.","sources":["https://www.goatformat.com/rulings7.html","https://yugipedia.com/wiki/Card_Errata:Strike_Ninja (revision 5145846)"]},{"code":68005187,"name":"Soul Exchange","status":"same","note":"SKE-033 (2004-03-01): \"When you offer your monster as a Tribute, offer the selected monster in place of 1 of your monsters.\" That is a replacement you must make, as today's \"you must Tribute that target\". goatformat's netrep note that the effect \"disappears\" if unused does not make it optional.","sources":["https://www.goatformat.com/rulings7.html","https://yugipedia.com/wiki/Card_Errata:Soul_Exchange (revision 5884065)"]}]}},"fixes":[{"file":"utility.lua","code":null,"name":"utility.lua (shared by every card script)","baseSha256":"e0f24e14336aca7f81f675e9b9250c81a5603b821b59b7f82bc8013c464c293d","summary":"Asking an attacker that has become Xyz Material for its attack targets no longer crashes the duel (Apple and Chocolate Magician Girl, after an attacker ranks up).","bug":"The core's field::get_attack_target reads player[1 - controller]. A card that left the field as Xyz Material has controller PLAYER_NONE (2), so Card.GetAttackableTarget on it reads out of bounds and the WASM traps ('memory access out of bounds'). The attacker stays Duel.GetAttacker() after it becomes material, and 14 pinned scripts call GetAttackableTarget, Apple and Chocolate Magician Girl on the attacker. In the browser the table was replaced by the bare error.","fix":"Card.GetAttackableTarget returns an empty group and false for a card whose controller is neither player; every other call goes to the pinned function unchanged.","repro":{"jobs":[47379,47378],"test":"tests/duel-fixes.test.ts"},"upstream":"not reported (owner decision 2026-10-11)"},{"file":"c76666602.lua","code":76666602,"name":"The Dragon that Devours the Dogma","baseSha256":"774aebd4c1121d83f8e5a1f089b7f3c547560ef3bb0d76adc8643d07afa7f76b","summary":"No longer loops forever (Lua 'C stack overflow') beside a card that adds an archetype, such as Ninjitsu Art Tool - Iron Digger.","bug":"Its ATK and immunity condition checks every monster on the field and in the GYs for the Dogmatika archetype, itself included. With an equip that adds an archetype, deciding whether that equip applies asks whether this card is immune, which asks the condition again, without end: about 80 'C stack overflow' errors per engine step, and its effects then resolve from a failed check.","fix":"The condition no longer counts this card itself (IsExistingMatchingCard's exception argument). It only differs when something gives this card the Dogmatika archetype.","repro":{"jobs":[39878],"test":"tests/duel-fixes.test.ts"},"upstream":"not reported (owner decision 2026-10-11)"},{"file":"c56562619.lua","code":56562619,"name":"Black Dragon Ninja","baseSha256":"ba3ad98fe50196806521ebfe67e008518195098e1be04507c3f56a50ba088a3b","summary":"Its banish effect does nothing, instead of raising a script error, when its cost took away the only target.","bug":"The activation check counts a target that paying the cost can remove (sending Ninjitsu Art of Dancing Leaves takes its monster with it). The effect then resolves with no target and indexes a nil 'tc'.","fix":"The operation checks that there is a target.","repro":{"jobs":[16686,3020],"test":"tests/duel-fixes.test.ts"},"upstream":"not reported (owner decision 2026-10-11)"},{"file":"c32756828.lua","code":32756828,"name":"Branded Beast","baseSha256":"448bf53ab5c8f516d1667c5452fcce9cfdccbc45c352771e8b90b34c57331162","summary":"Its destroy effect does nothing, instead of raising a script error, when its cost took away the only target.","bug":"The activation check counts a target that paying the cost can remove (the Tributed monster's equip card leaves with it). The effect then resolves with no target and indexes a nil 'tc'.","fix":"The operation checks that there is a target.","repro":{"jobs":[39723],"test":"tests/duel-fixes.test.ts"},"upstream":"not reported (owner decision 2026-10-11)"},{"file":"procedure.lua","code":null,"name":"procedure.lua (the Synchro, Xyz, Fusion and Link procedures every Extra Deck script uses)","baseSha256":"aae9067432e47ab1082ae27ff5dbf5a2d9688950d3af40f333d0859b3493d3b0","summary":"Checking whether a Synchro Monster with a \"Tuner + 1 or more\" material rule can be summoned no longer takes most of a second on a board full of Tuners (Kewl Tune, Elf Tune). Picking the materials for a Fusion Monster with an \"A + 1 or more B\" rule (Frightfur) no longer hangs the duel when a pick cannot complete.","bug":"Auxiliary.SynMixCheck, the material search behind AddSynchroMixProcedure, walked every ordering of every subset of the candidate materials (n! paths for n candidates), switched its level pruning off when there were five or fewer, and is entered once per pair of first materials. One check for Kewl Tune Loudness War (Tuner + 1 to 5 Tuners) on an Elf Tune board with three Kewl Tune monsters and hand Tuners ran the goal check 60,000 times; the engine answer that builds the idle-command list cost about 720 ms, and a bot plan on that board 4 to 5 seconds (QA lane, 2026-10-12; docs/playtest.md, M7.5 clarification). F14: the Fusion-repeat material check (Auxiliary.FCheckMixRepSelectedCond, FCheckSelectMixRep, behind AddFusionProcMixRep and the CodeRep/FunRep/FunFunRep/CodeFunRep/Code2FunRep procedures) assigned roles to the already-selected materials by trying them in every order (k! for k selected) and picked the repeat-role materials as sequences (n!/(n-k)! for n candidates); a selection that cannot complete, such as a second copy of the fixed-role card, ran the whole space: Frightfur Fusion with 12 materials picked from a 28-card graveyard never returned (QA sweep job 25800 at 052856c).","fix":"SynMixCheck and SynMixCheckRecursive (also the material selection's filter at SynMixTarget) visit each subset once, taking the candidates in ascending minimum Synchro Level so the pruning cuts exactly the subsets it cut before. The goal and prune checks read the chosen cards as a set, so the result is the same for every input: 500 synchro-mix sweep duels and the widened cross-bucket Synchro set replayed byte for byte identical under the fix, and a search that skips one candidate changes some. The same pass costs 120 ms; the plan 0.9 to 1.3 s. F14 (a second block at the end): the selected materials take their roles in a fixed order (each must take one), and once the fixed roles are filled the repeat-role picks are combinations in candidate order; the goal checks read the chosen cards as a set, so the answer is the same: 1,186 Fusion-Summon sweep duels across every bucket and the 342 old failure jobs replayed byte for byte identical, a mutant that lets the last selected material take no role changes 54, and job 25800's pick returns in 1 ms.","repro":{"jobs":[9090,25800,38194],"test":"tests/duel-fixes.test.ts"},"upstream":"not reported (owner decision 2026-10-11)"},{"file":"c83121692.lua","code":83121692,"name":"Elemental HERO Tempest","baseSha256":"0b0a3d56af0b6ec9695b51998d4138583654b89239b9519986126fc458fc4c87","summary":"Its protection effect does nothing, instead of raising a script error, when its cost took away the only target.","bug":"Its cost sends a card you control to the GY and can take away the only monster its target filter accepts, so the target selection is empty and the operation indexes a nil 'tc'.","fix":"The operation checks that there is a target (one nil check, as F9 and F10).","repro":{"jobs":[1685],"test":"tests/duel-fixes.test.ts"},"upstream":"not reported (owner decision 2026-10-11)"},{"file":"c61840587.lua","code":61840587,"name":"Portable Battery Pack","baseSha256":"46f7e6aaefb36b4570a64f39e10cba94b91a4aec557164f0826c809541a956b5","summary":"Leaving the field no longer raises a script error when its activation effect is already gone.","bug":"When it leaves the field it destroys the monsters it summoned, read through its activation effect's label object; that effect can already be reset by the same leave-field event, so the label object is nil and the operation indexes it.","fix":"The operation does nothing when either label object is missing (one nil check more than the pinned script's).","repro":{"jobs":[5981],"test":"tests/duel-fixes.test.ts"},"upstream":"not reported (owner decision 2026-10-11)"},{"file":"c40975243.lua","code":40975243,"name":"Tri-Brigade Revolt","baseSha256":"e511d7692262d987a4aaeb3f27fb314d1b28fa23482a3e763d112a40d748f4e3","summary":"Asking whether it can be activated no longer hangs the duel when the GY holds many Beast monsters.","bug":"Its activation check enumerated every subset of 1 to 5 of the Beast, Beast-Warrior and Winged Beast monsters in the GY and banished (575,000 subsets for 38 of them) and asked for each whether a \"Tri-Brigade\" Link Monster can be Link Summoned with exactly it; with a 31-card GY the End Phase chain window never returned (QA sweep job 41862 at 052856c).","fix":"The check asks each \"Tri-Brigade\" Link Monster in the Extra Deck once whether it can be Link Summoned from that group with 1 to 5 of them: the same question with the quantifiers swapped, answered by the Link procedure's own search. The activation itself (the selection) is unchanged. With Bucephalus II's fix the End Phase step that never returned takes 8 ms.","repro":{"jobs":[41862],"test":"tests/duel-fixes.test.ts"},"upstream":"not reported (owner decision 2026-10-11)"},{"file":"c10019086.lua","code":10019086,"name":"Tri-Brigade Arms Bucephalus II","baseSha256":"c8071082c9fdd9284b9defaa1f3c6b8d6f121bd3d895896831313ce259088219","summary":"Checking whether it can be Link Summoned no longer tries every 5-card set of a large material pool when the GY lacks the 3 \"Tri-Brigade\" Spells/Traps it needs.","bug":"Its Link Summon needs 3 \"Tri-Brigade\" Spells/Traps in the GY, stated as a check on each candidate set of materials (the Link procedure's gf), so when the GY lacks them every 5-card subset of the candidates fails one by one: 501,000 subsets and 15 million card reads for 38 candidates (Tri-Brigade Revolt asking at the End Phase whether it can be summoned from the GY, QA sweep job 41862 at 052856c; with Revolt's fix alone that step still took 9.5 s, with this one alone 49 s, with both 8 ms).","fix":"The same GY requirement is also part of the material filter, so with no 3 such cards in the GY there are no candidate materials and no subsets to try; with them nothing changes. Same answer for every input.","repro":{"jobs":[41862],"test":"tests/duel-fixes.test.ts"},"upstream":"not reported (owner decision 2026-10-11)"},{"file":"c94739788.lua","code":94739788,"name":"Remove Brainwashing","baseSha256":"88a36ffd7f65e102c6f7ac5035de19f35bf7a52f6eb4182f93b08cdb808e7f4e","summary":"With it face-up, a monster Special Summoned to the opponent's field (a Kaiju) no longer hangs the duel and crashes the engine.","bug":"The core's adjust loop, with Remove Brainwashing in play, collects every monster on a side that is not its owner and asks to move it home. A monster Special Summoned to the opponent's field carries no control-change effect for the core to undo, so nothing moves and the loop repeats until the WASM aborts out of memory, about 200 s later; the table shows the crash screen (QA sweep job 31791 at 052856c: Gameciel on the opponent's field, Solemn Strike chained under Remove Brainwashing).","fix":"Its continuous effect applies to the monsters that carry a control-change effect (EFFECT_SET_CONTROL), which is every monster the pinned core returns to its owner today (a control change creates one; a Kaiju's summon does not). A monster the core could not return keeps its controller instead of hanging the duel. Every sweep job holding the card replays identically; the one that hung now completes.","repro":{"jobs":[31791],"test":"tests/duel-fixes.test.ts"},"upstream":"not reported (owner decision 2026-10-11)","status":"deviation","deviation":"The real rule returns the Kaiju to its owner under Remove Brainwashing. The pinned core cannot: it loops in its adjust step until the WASM aborts, about 200 s later, and the table shows the crash screen. This override keeps the Kaiju where it is in that one case, until a core fix: the real fix is the core pin bump (docs/playtest.md, F18)."}]},"files":{"goat":{"c8131171.lua":"-- Deckhand period-text override, Goat (2005-08-20). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c8131171.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: goatformat.com/rulings7.html, Sinister Serpent, Card Errata.\n-- Then: during your Standby Phase, if it is in your GY, you can return it to your hand; no limit and no banish.\n-- Today: once per turn by name, and a Sinister Serpent is banished in the opponent's next End Phase.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--キラー・スネーク\nfunction c8131171.initial_effect(c)\n\t--to hand\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(aux.Stringid(8131171,0))\n\te1:SetType(EFFECT_TYPE_TRIGGER_O+EFFECT_TYPE_FIELD)\n\te1:SetCategory(CATEGORY_TOHAND)\n\te1:SetCode(EVENT_PHASE+PHASE_STANDBY)\n\te1:SetRange(LOCATION_GRAVE)\n\te1:SetCondition(c8131171.condition)\n\te1:SetTarget(c8131171.target)\n\te1:SetOperation(c8131171.operation)\n\tc:RegisterEffect(e1)\nend\nfunction c8131171.condition(e,tp,eg,ep,ev,re,r,rp)\n\treturn Duel.GetTurnPlayer()==tp\nend\nfunction c8131171.target(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return e:GetHandler():IsAbleToHand() end\n\tDuel.SetOperationInfo(0,CATEGORY_TOHAND,e:GetHandler(),1,0,0)\nend\nfunction c8131171.operation(e,tp,eg,ep,ev,re,r,rp)\n\tif e:GetHandler():IsRelateToEffect(e) then\n\t\tDuel.SendtoHand(e:GetHandler(),nil,REASON_EFFECT)\n\tend\nend\n","c14878871.lua":"-- Deckhand period-text override, Goat (2005-08-20). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c14878871.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: goatformat.com/rulings6.html, Rescue Cat, Card Errata.\n-- Then: the two Beasts keep their effects, and there is no once-per-turn limit.\n-- Today: their effects are negated, and the effect is once per turn by name.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--レスキューキャット\nfunction c14878871.initial_effect(c)\n\t--special summon\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(aux.Stringid(14878871,0))\n\te1:SetCategory(CATEGORY_SPECIAL_SUMMON)\n\te1:SetType(EFFECT_TYPE_IGNITION)\n\te1:SetRange(LOCATION_MZONE)\n\te1:SetCost(c14878871.spcost)\n\te1:SetTarget(c14878871.sptg)\n\te1:SetOperation(c14878871.spop)\n\tc:RegisterEffect(e1)\nend\nfunction c14878871.spcost(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return e:GetHandler():IsAbleToGraveAsCost() end\n\tDuel.SendtoGrave(e:GetHandler(),REASON_COST)\nend\nfunction c14878871.filter(c,e,tp)\n\treturn c:IsLevelBelow(3) and c:IsRace(RACE_BEAST) and c:IsCanBeSpecialSummoned(e,0,tp,false,false)\nend\nfunction c14878871.sptg(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return not Duel.IsPlayerAffectedByEffect(tp,59822133)\n\t\tand Duel.GetLocationCount(tp,LOCATION_MZONE)>0\n\t\tand Duel.IsExistingMatchingCard(c14878871.filter,tp,LOCATION_DECK,0,2,nil,e,tp) end\n\tDuel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,2,tp,LOCATION_DECK)\nend\nfunction c14878871.spop(e,tp,eg,ep,ev,re,r,rp)\n\tif Duel.IsPlayerAffectedByEffect(tp,59822133) then return end\n\tif Duel.GetLocationCount(tp,LOCATION_MZONE)<2 then return end\n\tlocal c=e:GetHandler()\n\tlocal g=Duel.GetMatchingGroup(c14878871.filter,tp,LOCATION_DECK,0,nil,e,tp)\n\tif g:GetCount()>=2 then\n\t\tlocal fid=e:GetHandler():GetFieldID()\n\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\t\tlocal sg=g:Select(tp,2,2,nil)\n\t\tlocal tc=sg:GetFirst()\n\t\twhile tc do\n\t\t\tDuel.SpecialSummonStep(tc,0,tp,tp,false,false,POS_FACEUP)\n\t\t\ttc:RegisterFlagEffect(14878871,RESET_EVENT+RESETS_STANDARD,0,1,fid)\n\t\t\ttc=sg:GetNext()\n\t\tend\n\t\tDuel.SpecialSummonComplete()\n\t\tsg:KeepAlive()\n\t\tlocal e3=Effect.CreateEffect(c)\n\t\te3:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)\n\t\te3:SetCode(EVENT_PHASE+PHASE_END)\n\t\te3:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)\n\t\te3:SetCountLimit(1)\n\t\te3:SetLabel(fid)\n\t\te3:SetLabelObject(sg)\n\t\te3:SetCondition(c14878871.descon)\n\t\te3:SetOperation(c14878871.desop)\n\t\tDuel.RegisterEffect(e3,tp)\n\tend\nend\nfunction c14878871.desfilter(c,fid)\n\treturn c:GetFlagEffectLabel(14878871)==fid\nend\nfunction c14878871.descon(e,tp,eg,ep,ev,re,r,rp)\n\tlocal g=e:GetLabelObject()\n\tif not g:IsExists(c14878871.desfilter,1,nil,e:GetLabel()) then\n\t\tg:DeleteGroup()\n\t\te:Reset()\n\t\treturn false\n\telse return true end\nend\nfunction c14878871.desop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal g=e:GetLabelObject()\n\tlocal tg=g:Filter(c14878871.desfilter,nil,e:GetLabel())\n\tDuel.Destroy(tg,REASON_EFFECT)\nend\n","c16226786.lua":"-- Deckhand period-text override, Goat (2005-08-20). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c16226786.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: goatformat.com/rulings5.html, Night Assailant, Card Errata.\n-- Then: discarded from the hand, return any Flip Effect Monster from your GY to your hand, another\n-- Night Assailant included (only this card itself is excluded). Today: not one named Night Assailant.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--深淵の暗殺者\nfunction c16226786.initial_effect(c)\n\t--flip\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(aux.Stringid(16226786,0))\n\te1:SetCategory(CATEGORY_DESTROY)\n\te1:SetProperty(EFFECT_FLAG_CARD_TARGET)\n\te1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_FLIP)\n\te1:SetTarget(c16226786.target)\n\te1:SetOperation(c16226786.operation)\n\tc:RegisterEffect(e1)\n\t--salvage\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetDescription(aux.Stringid(16226786,1))\n\te2:SetCategory(CATEGORY_TOHAND)\n\te2:SetProperty(EFFECT_FLAG_CARD_TARGET)\n\te2:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_F)\n\te2:SetCode(EVENT_TO_GRAVE)\n\te2:SetCondition(c16226786.thcon)\n\te2:SetTarget(c16226786.thtg)\n\te2:SetOperation(c16226786.thop)\n\tc:RegisterEffect(e2)\nend\nfunction c16226786.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\tif chkc then return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1-tp) end\n\tif chk==0 then return true end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_DESTROY)\n\tlocal g=Duel.SelectTarget(tp,aux.TRUE,tp,0,LOCATION_MZONE,1,1,nil)\n\tDuel.SetOperationInfo(0,CATEGORY_DESTROY,g,g:GetCount(),0,0)\nend\nfunction c16226786.operation(e,tp,eg,ep,ev,re,r,rp)\n\tlocal tc=Duel.GetFirstTarget()\n\tif tc and tc:IsRelateToEffect(e) and tc:IsControler(1-tp) then\n\t\tDuel.Destroy(tc,REASON_EFFECT)\n\tend\nend\nfunction c16226786.thcon(e,tp,eg,ep,ev,re,r,rp)\n\treturn e:GetHandler():IsPreviousLocation(LOCATION_HAND)\nend\nfunction c16226786.thfilter(c,ec)\n\treturn c:IsType(TYPE_FLIP) and c:IsAbleToHand() and c~=ec\nend\nfunction c16226786.thtg(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\tif chkc then return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and c16226786.thfilter(chkc,e:GetHandler()) end\n\tif chk==0 then return true end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND)\n\tlocal g=Duel.SelectTarget(tp,c16226786.thfilter,tp,LOCATION_GRAVE,0,1,1,nil,e:GetHandler())\n\tDuel.SetOperationInfo(0,CATEGORY_TOHAND,g,g:GetCount(),0,0)\nend\nfunction c16226786.thop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal tc=Duel.GetFirstTarget()\n\tif tc and tc:IsRelateToEffect(e) then\n\t\tDuel.SendtoHand(tc,nil,REASON_EFFECT)\n\tend\nend\n","c26202165.lua":"-- Deckhand period-text override, Goat (2005-08-20). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c26202165.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: goatformat.com/rulings7.html, Sangan, Card Errata.\n-- Then: searches every time it goes from the field to the GY, and the searched card can be used that turn.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--クリッター\nfunction c26202165.initial_effect(c)\n\t--search\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(aux.Stringid(26202165,0))\n\te1:SetCategory(CATEGORY_TOHAND+CATEGORY_SEARCH)\n\te1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_F)\n\te1:SetCode(EVENT_TO_GRAVE)\n\te1:SetCondition(c26202165.condition)\n\te1:SetTarget(c26202165.target)\n\te1:SetOperation(c26202165.operation)\n\tc:RegisterEffect(e1)\nend\nfunction c26202165.condition(e,tp,eg,ep,ev,re,r,rp)\n\treturn e:GetHandler():IsPreviousLocation(LOCATION_ONFIELD)\nend\nfunction c26202165.target(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return true end\n\tDuel.SetOperationInfo(0,CATEGORY_TOHAND,nil,1,tp,LOCATION_DECK)\nend\nfunction c26202165.filter(c)\n\treturn c:IsAttackBelow(1500) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()\nend\nfunction c26202165.operation(e,tp,eg,ep,ev,re,r,rp)\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND)\n\tlocal g=Duel.SelectMatchingCard(tp,c26202165.filter,tp,LOCATION_DECK,0,1,1,nil)\n\tif g:GetCount()>0 then\n\t\tDuel.SendtoHand(g,nil,REASON_EFFECT)\n\t\tDuel.ConfirmCards(1-tp,g)\n\tend\nend\n","c40737112.lua":"-- Deckhand period-text override, Goat (2005-08-20). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c40737112.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: goatformat.com/rulings2.html, Dark Magician of Chaos, Card Errata (and its missing-the-timing FAQ).\n-- Then: when this card is Normal or Special Summoned, you can add 1 Spell from your GY to your hand, at once and\n-- with no once-per-turn limit (a \"When … you can\" trigger, so it can miss the timing).\n-- Today: only during the End Phase of the turn it was Summoned, once per turn by name.\n-- The battle banish and the leave-the-field banish are unchanged.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--混沌の黒魔術師\nfunction c40737112.initial_effect(c)\n\t--summon success\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(aux.Stringid(40737112,0))\n\te1:SetCategory(CATEGORY_TOHAND)\n\te1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O)\n\te1:SetProperty(EFFECT_FLAG_CARD_TARGET)\n\te1:SetCode(EVENT_SUMMON_SUCCESS)\n\te1:SetTarget(c40737112.thtg)\n\te1:SetOperation(c40737112.thop)\n\tc:RegisterEffect(e1)\n\tlocal e3=e1:Clone()\n\te3:SetCode(EVENT_SPSUMMON_SUCCESS)\n\tc:RegisterEffect(e3)\n\t--remove\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetDescription(aux.Stringid(40737112,1))\n\te2:SetCategory(CATEGORY_REMOVE)\n\te2:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_F)\n\te2:SetCode(EVENT_BATTLED)\n\te2:SetCondition(c40737112.rmcon)\n\te2:SetTarget(c40737112.rmtg)\n\te2:SetOperation(c40737112.rmop)\n\tc:RegisterEffect(e2)\n\t--redirect\n\taux.AddBanishRedirect(c)\nend\nfunction c40737112.thfilter(c)\n\treturn c:IsType(TYPE_SPELL) and c:IsAbleToHand()\nend\nfunction c40737112.thtg(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\tif chkc then return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and c40737112.thfilter(chkc) end\n\tif chk==0 then return Duel.IsExistingTarget(c40737112.thfilter,tp,LOCATION_GRAVE,0,1,nil) end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND)\n\tlocal g=Duel.SelectTarget(tp,c40737112.thfilter,tp,LOCATION_GRAVE,0,1,1,nil)\n\tDuel.SetOperationInfo(0,CATEGORY_TOHAND,g,1,0,0)\nend\nfunction c40737112.thop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal tc=Duel.GetFirstTarget()\n\tif tc:IsRelateToEffect(e) then\n\t\tDuel.SendtoHand(tc,nil,REASON_EFFECT)\n\tend\nend\nfunction c40737112.rmcon(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tlocal bc=c:GetBattleTarget()\n\te:SetLabelObject(bc)\n\treturn bc and bc:IsStatus(STATUS_BATTLE_DESTROYED) and c:IsStatus(STATUS_OPPO_BATTLE)\nend\nfunction c40737112.rmtg(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return true end\n\tDuel.SetOperationInfo(0,CATEGORY_REMOVE,e:GetLabelObject(),1,0,0)\nend\nfunction c40737112.rmop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal bc=e:GetLabelObject()\n\tif bc:IsRelateToBattle() and bc:IsAbleToRemove() then\n\t\tDuel.Remove(bc,POS_FACEUP,REASON_EFFECT)\n\tend\nend\n","c47355498.lua":"-- Deckhand period-text override, Goat (2005-08-20). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c47355498.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: goatformat.com/rulings5.html, Necrovalley, Card Errata and Individual Card FAQs.\n-- Then: negate the effects of Spell, Trap and Monster Cards that affect a card in the GY; neither player can\n-- remove cards in the GYs from play; \"Gravekeeper's\" monsters gain 500 ATK and DEF. As ruled: effects that\n-- target a card in the GY are negated and cannot be activated; effects that activate in the GY, that are\n-- triggered by being sent there, that count the GY, or that return or summon the card itself, are not.\n-- Two non-targeting cards are reached by name: Skilled Dark Magician and Skilled White Magician summon from\n-- the hand or Deck only (netrep, 2003-12-30, \"Hand or Deck only in this situation\"). goatformat names other\n-- non-targeting cards it negates (Question, Fiber Jar, Penguin Knight, Agido, Big Burn, Gilasaurus's summon\n-- for the opponent); none is in a Goat deck we hold, so this script does not negate them\n-- (vendor/duel/errata/manifest.json says so).\n-- Today: cards in the GY cannot be affected by any card effect except their own, and any effect that would\n-- move one is negated, targeting or not.\n-- How: EFFECT_NECRO_VALLEY is what today's scripts test through aux.NecroValleyFilter. This script gives it\n-- to cards in a GY only while a chain link of Skilled Dark Magician or Skilled White Magician (by the link's\n-- code) is resolving, so their own filter keeps to the hand and Deck; every other card plays its own text,\n-- and only the rule below applies. A card\n-- in a GY cannot be chosen as the target of another card's effect, so a card that must target one cannot\n-- be activated, and an effect that already has such a target when this card is on the field is negated\n-- at resolution. Gravekeeper's Chief (its controller's GY) and the cards immune to Necrovalley (Rite of\n-- Spirit and others) keep today's exemptions.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--王家の眠る谷－ネクロバレー\nfunction c47355498.initial_effect(c)\n\t--Activate\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_ACTIVATE)\n\te1:SetCode(EVENT_FREE_CHAIN)\n\tc:RegisterEffect(e1)\n\t--Atk&Def\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetType(EFFECT_TYPE_FIELD)\n\te2:SetCode(EFFECT_UPDATE_ATTACK)\n\te2:SetRange(LOCATION_FZONE)\n\te2:SetTargetRange(LOCATION_MZONE,LOCATION_MZONE)\n\te2:SetTarget(aux.TargetBoolFunction(Card.IsSetCard,0x2e))\n\te2:SetValue(500)\n\tc:RegisterEffect(e2)\n\tlocal e3=e2:Clone()\n\te3:SetCode(EFFECT_UPDATE_DEFENSE)\n\tc:RegisterEffect(e3)\n\t--cannot remove\n\tlocal e4=Effect.CreateEffect(c)\n\te4:SetType(EFFECT_TYPE_FIELD)\n\te4:SetCode(EFFECT_CANNOT_REMOVE)\n\te4:SetRange(LOCATION_FZONE)\n\te4:SetTargetRange(LOCATION_GRAVE,0)\n\te4:SetCondition(c47355498.contp)\n\tc:RegisterEffect(e4)\n\tlocal e5=e4:Clone()\n\te5:SetTargetRange(0,LOCATION_GRAVE)\n\te5:SetCondition(c47355498.conntp)\n\tc:RegisterEffect(e5)\n\t--cards in the GY cannot be targeted\n\tlocal e6=Effect.CreateEffect(c)\n\te6:SetType(EFFECT_TYPE_FIELD)\n\te6:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)\n\te6:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)\n\te6:SetRange(LOCATION_FZONE)\n\te6:SetTargetRange(LOCATION_GRAVE,0)\n\te6:SetCondition(c47355498.contp)\n\te6:SetValue(c47355498.tgval)\n\tc:RegisterEffect(e6)\n\tlocal e7=e6:Clone()\n\te7:SetTargetRange(0,LOCATION_GRAVE)\n\te7:SetCondition(c47355498.conntp)\n\tc:RegisterEffect(e7)\n\t--negate an effect that targets a card in the GY\n\tlocal e8=Effect.CreateEffect(c)\n\te8:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)\n\te8:SetCode(EVENT_CHAIN_SOLVING)\n\te8:SetRange(LOCATION_FZONE)\n\te8:SetOperation(c47355498.disop)\n\tc:RegisterEffect(e8)\n\t--Skilled Dark Magician / Skilled White Magician: from the hand or Deck only\n\tlocal e9=Effect.CreateEffect(c)\n\te9:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)\n\te9:SetCode(EVENT_CHAIN_SOLVING)\n\te9:SetRange(LOCATION_FZONE)\n\te9:SetOperation(c47355498.skilledon)\n\tc:RegisterEffect(e9)\n\tlocal e10=Effect.CreateEffect(c)\n\te10:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)\n\te10:SetCode(EVENT_CHAIN_SOLVED)\n\te10:SetRange(LOCATION_FZONE)\n\te10:SetLabelObject(e9)\n\te10:SetOperation(c47355498.skilledoff)\n\tc:RegisterEffect(e10)\n\tlocal e11=Effect.CreateEffect(c)\n\te11:SetType(EFFECT_TYPE_FIELD)\n\te11:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)\n\te11:SetCode(EFFECT_NECRO_VALLEY)\n\te11:SetRange(LOCATION_FZONE)\n\te11:SetTargetRange(LOCATION_GRAVE,0)\n\te11:SetLabelObject(e9)\n\te11:SetCondition(c47355498.skilledtp)\n\tc:RegisterEffect(e11)\n\tlocal e12=e11:Clone()\n\te12:SetTargetRange(0,LOCATION_GRAVE)\n\te12:SetLabelObject(e9)\n\te12:SetCondition(c47355498.skilledntp)\n\tc:RegisterEffect(e12)\nend\nc47355498.skilled={[73752131]=true,[46363422]=true}\nfunction c47355498.skilledon(e,tp,eg,ep,ev,re,r,rp)\n\te:SetLabel(c47355498.skilled[Duel.GetChainInfo(ev,CHAININFO_TRIGGERING_CODE)] and ev or 0)\nend\nfunction c47355498.skilledoff(e,tp,eg,ep,ev,re,r,rp)\n\te:GetLabelObject():SetLabel(0)\nend\nfunction c47355498.skilledtp(e)\n\treturn e:GetLabelObject():GetLabel()~=0 and c47355498.contp(e)\nend\nfunction c47355498.skilledntp(e)\n\treturn e:GetLabelObject():GetLabel()~=0 and c47355498.conntp(e)\nend\nfunction c47355498.contp(e)\n\treturn not Duel.IsPlayerAffectedByEffect(e:GetHandler():GetControler(),EFFECT_NECRO_VALLEY_IM)\nend\nfunction c47355498.conntp(e)\n\treturn not Duel.IsPlayerAffectedByEffect(1-e:GetHandler():GetControler(),EFFECT_NECRO_VALLEY_IM)\nend\nfunction c47355498.tgval(e,re,rp)\n\treturn not re:GetHandler():IsHasEffect(EFFECT_NECRO_VALLEY_IM)\nend\nfunction c47355498.disfilter(c,re)\n\treturn c:IsLocation(LOCATION_GRAVE) and c:IsRelateToEffect(re) and c~=re:GetHandler()\n\t\tand not Duel.IsPlayerAffectedByEffect(c:GetControler(),EFFECT_NECRO_VALLEY_IM)\nend\nfunction c47355498.disop(e,tp,eg,ep,ev,re,r,rp)\n\tif not Duel.IsChainDisablable(ev) or not re:IsHasProperty(EFFECT_FLAG_CARD_TARGET)\n\t\tor re:GetHandler():IsHasEffect(EFFECT_NECRO_VALLEY_IM) then return end\n\tlocal tg=Duel.GetChainInfo(ev,CHAININFO_TARGET_CARDS)\n\tif tg and tg:IsExists(c47355498.disfilter,1,nil,re) then Duel.NegateEffect(ev,true) end\nend\n","c83555666.lua":"-- Deckhand period-text override, Goat (2005-08-20). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c83555666.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: goatformat.com/rulings6.html, Ring of Destruction, Card Errata (and: not in the Damage Step).\n-- Then: a Normal Trap with no timing condition. Destroy 1 face-up monster (either side) and inflict damage\n-- equal to its ATK to both players at the same time, so it can end the duel in a draw.\n-- Today: only during the opponent's turn, only their monster whose ATK is at most their LP, you take the\n-- damage first and they take the same, and only 1 activation per turn.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--破壊輪\nfunction c83555666.initial_effect(c)\n\t--Activate\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetCategory(CATEGORY_DESTROY+CATEGORY_DAMAGE)\n\te1:SetType(EFFECT_TYPE_ACTIVATE)\n\te1:SetProperty(EFFECT_FLAG_CARD_TARGET)\n\te1:SetCode(EVENT_FREE_CHAIN)\n\te1:SetHintTiming(0,TIMINGS_CHECK_MONSTER+TIMING_END_PHASE)\n\te1:SetTarget(c83555666.target)\n\te1:SetOperation(c83555666.activate)\n\tc:RegisterEffect(e1)\nend\nfunction c83555666.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\tif chkc then return chkc:IsLocation(LOCATION_MZONE) and chkc:IsFaceup() end\n\tif chk==0 then return Duel.IsExistingTarget(Card.IsFaceup,tp,LOCATION_MZONE,LOCATION_MZONE,1,nil) end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_DESTROY)\n\tlocal g=Duel.SelectTarget(tp,Card.IsFaceup,tp,LOCATION_MZONE,LOCATION_MZONE,1,1,nil)\n\tDuel.SetOperationInfo(0,CATEGORY_DESTROY,g,1,0,0)\n\tDuel.SetOperationInfo(0,CATEGORY_DAMAGE,nil,0,PLAYER_ALL,0)\nend\nfunction c83555666.activate(e,tp,eg,ep,ev,re,r,rp)\n\tlocal tc=Duel.GetFirstTarget()\n\tif tc:IsRelateToEffect(e) and tc:IsFaceup() then\n\t\tlocal atk=tc:GetAttack()\n\t\tif Duel.Destroy(tc,REASON_EFFECT)~=0 then\n\t\t\tif atk<0 then atk=0 end\n\t\t\tDuel.Damage(tp,atk,REASON_EFFECT,true)\n\t\t\tDuel.Damage(1-tp,atk,REASON_EFFECT,true)\n\t\t\tDuel.RDComplete()\n\t\tend\n\tend\nend\n","c85602018.lua":"-- Deckhand period-text override, Goat (2005-08-20). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c85602018.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: goatformat.com/rulings5.html, Last Will, Card Errata and Individual Card FAQs.\n-- Then: activating it creates a state for the rest of the turn: the next time a monster goes from your field\n-- to your Graveyard, you can Special Summon 1 monster with 1500 or less ATK from your Deck, at that time, and\n-- the state ends (SYE-031). A monster sent before activation does not count; two Last Wills give two Summons\n-- on one send.\n-- Today: if a monster already went from your field to your GY this turn, it Special Summons on resolution;\n-- otherwise it waits for one.\n-- How: activating registers a mandatory delayed trigger on the next send from your field to your GY that\n-- turn (once: its count limit); it asks whether to Summon. Today's \"already sent this turn\" check is gone.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--遺言状\nfunction c85602018.initial_effect(c)\n\t--Activate\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_ACTIVATE)\n\te1:SetCode(EVENT_FREE_CHAIN)\n\te1:SetOperation(c85602018.activate)\n\tc:RegisterEffect(e1)\nend\nfunction c85602018.activate(e,tp,eg,ep,ev,re,r,rp)\n\t--the state: the next time this turn a monster goes from your field to your GY\n\tlocal e1=Effect.CreateEffect(e:GetHandler())\n\te1:SetDescription(aux.Stringid(85602018,0))\n\te1:SetCategory(CATEGORY_SPECIAL_SUMMON)\n\te1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_F)\n\te1:SetProperty(EFFECT_FLAG_DELAY)\n\te1:SetCode(EVENT_TO_GRAVE)\n\te1:SetCountLimit(1)\n\te1:SetCondition(c85602018.spcon)\n\te1:SetOperation(c85602018.spop)\n\te1:SetReset(RESET_PHASE+PHASE_END)\n\tDuel.RegisterEffect(e1,tp)\nend\nfunction c85602018.cfilter(c,tp)\n\treturn c:IsControler(tp) and c:IsPreviousControler(tp) and c:IsPreviousLocation(LOCATION_MZONE)\nend\nfunction c85602018.spcon(e,tp,eg,ep,ev,re,r,rp)\n\treturn eg:IsExists(c85602018.cfilter,1,nil,tp)\nend\nfunction c85602018.spfilter(c,e,tp)\n\treturn c:IsAttackBelow(1500) and c:IsCanBeSpecialSummoned(e,0,tp,false,false)\nend\nfunction c85602018.spop(e,tp,eg,ep,ev,re,r,rp)\n\tif Duel.GetLocationCount(tp,LOCATION_MZONE)>0\n\t\tand Duel.IsExistingMatchingCard(c85602018.spfilter,tp,LOCATION_DECK,0,1,nil,e,tp)\n\t\tand Duel.SelectYesNo(tp,aux.Stringid(85602018,0)) then\n\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\t\tlocal g=Duel.SelectMatchingCard(tp,c85602018.spfilter,tp,LOCATION_DECK,0,1,1,nil,e,tp)\n\t\tDuel.SpecialSummon(g,0,tp,tp,false,false,POS_FACEUP)\n\t\tDuel.ShuffleDeck(tp)\n\tend\nend\n","c87910978.lua":"-- Deckhand period-text override, Goat (2005-08-20). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c87910978.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: goatformat.com/rulings1.html, Brain Control, Card Errata.\n-- Then: any face-up monster the opponent controls, not only one that can be Normal Summoned/Set.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--洗脳－ブレインコントロール\nfunction c87910978.initial_effect(c)\n\t--Activate\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetCategory(CATEGORY_CONTROL)\n\te1:SetType(EFFECT_TYPE_ACTIVATE)\n\te1:SetProperty(EFFECT_FLAG_CARD_TARGET)\n\te1:SetCode(EVENT_FREE_CHAIN)\n\te1:SetCost(c87910978.cost)\n\te1:SetTarget(c87910978.target)\n\te1:SetOperation(c87910978.activate)\n\tc:RegisterEffect(e1)\nend\nfunction c87910978.cost(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return Duel.CheckLPCost(tp,800) end\n\tDuel.PayLPCost(tp,800)\nend\nfunction c87910978.filter(c)\n\treturn c:IsControlerCanBeChanged() and c:IsFaceup()\nend\nfunction c87910978.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\tif chkc then return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1-tp) and c87910978.filter(chkc) end\n\tif chk==0 then return Duel.IsExistingTarget(c87910978.filter,tp,0,LOCATION_MZONE,1,nil) end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_CONTROL)\n\tlocal g=Duel.SelectTarget(tp,c87910978.filter,tp,0,LOCATION_MZONE,1,1,nil)\n\tDuel.SetOperationInfo(0,CATEGORY_CONTROL,g,1,0,0)\nend\nfunction c87910978.activate(e,tp,eg,ep,ev,re,r,rp)\n\tlocal tc=Duel.GetFirstTarget()\n\tif tc:IsRelateToEffect(e) and tc:IsFaceup() then\n\t\tDuel.GetControl(tc,tp,PHASE_END,1)\n\tend\nend\n"},"edison":{"c7391448.lua":"-- Deckhand period-text override, Edison (2010-04-24). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c7391448.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: edisonformat.com/functional-errata.html (the period behaviour as Edison plays it).\n-- Then: 1 Tuner (any Attribute) + 1 or more non-Tuner monsters. Only the Synchro procedure changes.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--ゴヨウ・ガーディアン\nfunction c7391448.initial_effect(c)\n\t--synchro summon\n\taux.AddSynchroProcedure(c,nil,aux.NonTuner(nil),1)\n\tc:EnableReviveLimit()\n\t--special summon\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(aux.Stringid(7391448,0))\n\te1:SetCategory(CATEGORY_SPECIAL_SUMMON)\n\te1:SetCode(EVENT_BATTLE_DESTROYING)\n\te1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O)\n\te1:SetCondition(aux.bdogcon)\n\te1:SetTarget(c7391448.sptg)\n\te1:SetOperation(c7391448.spop)\n\tc:RegisterEffect(e1)\nend\nfunction c7391448.sptg(e,tp,eg,ep,ev,re,r,rp,chk)\n\tlocal bc=e:GetHandler():GetBattleTarget()\n\tif chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0\n\t\tand bc:IsCanBeSpecialSummoned(e,0,tp,false,false,POS_FACEUP_DEFENSE) end\n\tDuel.SetTargetCard(bc)\n\tDuel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,bc,1,0,0)\nend\nfunction c7391448.spop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal tc=Duel.GetFirstTarget()\n\tif tc:IsRelateToEffect(e) then\n\t\tDuel.SpecialSummon(tc,0,tp,tp,false,false,POS_FACEUP_DEFENSE)\n\tend\nend\n","c9126351.lua":"-- Deckhand period-text override, Edison (2010-04-24). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c9126351.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: edisonformat.com/functional-errata.html, Swap Frog (\"[Ignition] can be used once by each Swap Frog. Only 1 additional Normal Summon can be gained\").\n-- Then: each Swap Frog can use its Ignition effect once per turn, even after the extra Normal Summon was\n-- gained; resolving it again grants no second one. The printing (SOVR-EN034) also excludes Frog the Jam from\n-- the extra Summon; that card is not in our card table, so the exclusion is not modelled.\n-- Today: once the extra Normal Summon was gained, no Swap Frog can activate the effect again that turn.\n-- How: the once-per-turn check leaves the cost; the engine itself grants one extra Normal Summon a turn.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--鬼ガエル\nfunction c9126351.initial_effect(c)\n\t--special summon\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_FIELD)\n\te1:SetCode(EFFECT_SPSUMMON_PROC)\n\te1:SetProperty(EFFECT_FLAG_UNCOPYABLE)\n\te1:SetRange(LOCATION_HAND)\n\te1:SetCondition(c9126351.spcon)\n\te1:SetTarget(c9126351.sptg)\n\te1:SetOperation(c9126351.spop)\n\tc:RegisterEffect(e1)\n\t--send to grave\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetCategory(CATEGORY_TOGRAVE)\n\te2:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O)\n\te2:SetProperty(EFFECT_FLAG_DAMAGE_STEP)\n\te2:SetCode(EVENT_SUMMON_SUCCESS)\n\te2:SetTarget(c9126351.target)\n\te2:SetOperation(c9126351.operation)\n\tc:RegisterEffect(e2)\n\tlocal e3=e2:Clone()\n\te3:SetCode(EVENT_FLIP_SUMMON_SUCCESS)\n\tc:RegisterEffect(e3)\n\tlocal e4=e2:Clone()\n\te4:SetCode(EVENT_SPSUMMON_SUCCESS)\n\tc:RegisterEffect(e4)\n\t--extra summon\n\tlocal e5=Effect.CreateEffect(c)\n\te5:SetType(EFFECT_TYPE_IGNITION)\n\te5:SetRange(LOCATION_MZONE)\n\te5:SetCountLimit(1)\n\te5:SetCost(c9126351.excost)\n\te5:SetTarget(c9126351.extg)\n\te5:SetOperation(c9126351.exop)\n\tc:RegisterEffect(e5)\nend\nfunction c9126351.spfilter(c)\n\treturn c:IsType(TYPE_MONSTER) and c:IsAttribute(ATTRIBUTE_WATER)\nend\nfunction c9126351.spcon(e,c)\n\tif c==nil then return true end\n\tlocal tp=c:GetControler()\n\treturn Duel.GetLocationCount(tp,LOCATION_MZONE)>0\n\t\tand Duel.IsExistingMatchingCard(c9126351.spfilter,tp,LOCATION_HAND,0,1,c)\nend\nfunction c9126351.sptg(e,tp,eg,ep,ev,re,r,rp,chk,c)\n\tlocal g=Duel.GetMatchingGroup(c9126351.spfilter,tp,LOCATION_HAND,0,c)\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_DISCARD)\n\tlocal tc=g:SelectUnselect(nil,tp,false,true,1,1)\n\tif tc then\n\t\te:SetLabelObject(tc)\n\t\treturn true\n\telse return false end\nend\nfunction c9126351.spop(e,tp,eg,ep,ev,re,r,rp,c)\n\tlocal g=e:GetLabelObject()\n\tDuel.SendtoGrave(g,REASON_SPSUMMON+REASON_DISCARD)\nend\nfunction c9126351.tgfilter(c)\n\treturn c:IsLevelBelow(2) and c:IsAttribute(ATTRIBUTE_WATER) and c:IsRace(RACE_AQUA)\n\t\tand (c:IsLocation(LOCATION_DECK) or c:IsFaceup()) and c:IsAbleToGrave()\nend\nfunction c9126351.target(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return Duel.IsExistingMatchingCard(c9126351.tgfilter,tp,LOCATION_DECK+LOCATION_MZONE,0,1,nil) end\n\tDuel.SetOperationInfo(0,CATEGORY_TOGRAVE,nil,1,tp,LOCATION_DECK+LOCATION_MZONE)\nend\nfunction c9126351.operation(e,tp,eg,ep,ev,re,r,rp)\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_TOGRAVE)\n\tlocal g=Duel.SelectMatchingCard(tp,c9126351.tgfilter,tp,LOCATION_DECK+LOCATION_MZONE,0,1,1,nil)\n\tif g:GetCount()>0 then\n\t\tDuel.SendtoGrave(g,REASON_EFFECT)\n\tend\nend\nfunction c9126351.excost(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return Duel.IsExistingMatchingCard(Card.IsAbleToHandAsCost,tp,LOCATION_MZONE,0,1,nil) end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_RTOHAND)\n\tlocal g=Duel.SelectMatchingCard(tp,Card.IsAbleToHandAsCost,tp,LOCATION_MZONE,0,1,1,nil)\n\tDuel.SendtoHand(g,nil,REASON_COST)\nend\nfunction c9126351.extg(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return Duel.IsPlayerCanSummon(tp) and Duel.IsPlayerCanAdditionalSummon(tp) end\nend\nfunction c9126351.exop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal e1=Effect.CreateEffect(e:GetHandler())\n\te1:SetDescription(aux.Stringid(9126351,0))\n\te1:SetType(EFFECT_TYPE_FIELD)\n\te1:SetTargetRange(LOCATION_HAND+LOCATION_MZONE,0)\n\te1:SetCode(EFFECT_EXTRA_SUMMON_COUNT)\n\te1:SetTarget(c9126351.estg)\n\te1:SetReset(RESET_PHASE+PHASE_END)\n\tDuel.RegisterEffect(e1,tp)\n\tDuel.RegisterFlagEffect(tp,9126352,RESET_PHASE+PHASE_END,0,1)\nend\nfunction c9126351.estg(e,c)\n\treturn c:IsSetCard(0x12) and not c:IsCode(9126351)\nend\n","c14878871.lua":"-- Deckhand period-text override, Edison (2010-04-24). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c14878871.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: edisonformat.com/functional-errata.html (the period behaviour as Edison plays it).\n-- Then: the two Beasts keep their effects, and there is no once-per-turn limit.\n-- Today: their effects are negated, and the effect is once per turn by name.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--レスキューキャット\nfunction c14878871.initial_effect(c)\n\t--special summon\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(aux.Stringid(14878871,0))\n\te1:SetCategory(CATEGORY_SPECIAL_SUMMON)\n\te1:SetType(EFFECT_TYPE_IGNITION)\n\te1:SetRange(LOCATION_MZONE)\n\te1:SetCost(c14878871.spcost)\n\te1:SetTarget(c14878871.sptg)\n\te1:SetOperation(c14878871.spop)\n\tc:RegisterEffect(e1)\nend\nfunction c14878871.spcost(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return e:GetHandler():IsAbleToGraveAsCost() end\n\tDuel.SendtoGrave(e:GetHandler(),REASON_COST)\nend\nfunction c14878871.filter(c,e,tp)\n\treturn c:IsLevelBelow(3) and c:IsRace(RACE_BEAST) and c:IsCanBeSpecialSummoned(e,0,tp,false,false)\nend\nfunction c14878871.sptg(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return not Duel.IsPlayerAffectedByEffect(tp,59822133)\n\t\tand Duel.GetLocationCount(tp,LOCATION_MZONE)>0\n\t\tand Duel.IsExistingMatchingCard(c14878871.filter,tp,LOCATION_DECK,0,2,nil,e,tp) end\n\tDuel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,2,tp,LOCATION_DECK)\nend\nfunction c14878871.spop(e,tp,eg,ep,ev,re,r,rp)\n\tif Duel.IsPlayerAffectedByEffect(tp,59822133) then return end\n\tif Duel.GetLocationCount(tp,LOCATION_MZONE)<2 then return end\n\tlocal c=e:GetHandler()\n\tlocal g=Duel.GetMatchingGroup(c14878871.filter,tp,LOCATION_DECK,0,nil,e,tp)\n\tif g:GetCount()>=2 then\n\t\tlocal fid=e:GetHandler():GetFieldID()\n\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\t\tlocal sg=g:Select(tp,2,2,nil)\n\t\tlocal tc=sg:GetFirst()\n\t\twhile tc do\n\t\t\tDuel.SpecialSummonStep(tc,0,tp,tp,false,false,POS_FACEUP)\n\t\t\ttc:RegisterFlagEffect(14878871,RESET_EVENT+RESETS_STANDARD,0,1,fid)\n\t\t\ttc=sg:GetNext()\n\t\tend\n\t\tDuel.SpecialSummonComplete()\n\t\tsg:KeepAlive()\n\t\tlocal e3=Effect.CreateEffect(c)\n\t\te3:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)\n\t\te3:SetCode(EVENT_PHASE+PHASE_END)\n\t\te3:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)\n\t\te3:SetCountLimit(1)\n\t\te3:SetLabel(fid)\n\t\te3:SetLabelObject(sg)\n\t\te3:SetCondition(c14878871.descon)\n\t\te3:SetOperation(c14878871.desop)\n\t\tDuel.RegisterEffect(e3,tp)\n\tend\nend\nfunction c14878871.desfilter(c,fid)\n\treturn c:GetFlagEffectLabel(14878871)==fid\nend\nfunction c14878871.descon(e,tp,eg,ep,ev,re,r,rp)\n\tlocal g=e:GetLabelObject()\n\tif not g:IsExists(c14878871.desfilter,1,nil,e:GetLabel()) then\n\t\tg:DeleteGroup()\n\t\te:Reset()\n\t\treturn false\n\telse return true end\nend\nfunction c14878871.desop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal g=e:GetLabelObject()\n\tlocal tg=g:Filter(c14878871.desfilter,nil,e:GetLabel())\n\tDuel.Destroy(tg,REASON_EFFECT)\nend\n","c16226786.lua":"-- Deckhand period-text override, Edison (2010-04-24). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c16226786.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: not on edisonformat.com/functional-errata.html; the Edison text is the Ancient Sanctuary print (Yugipedia).\n-- Then: discarded from the hand, return any Flip Effect Monster from your GY to your hand, another\n-- Night Assailant included (only this card itself is excluded). Today: not one named Night Assailant.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--深淵の暗殺者\nfunction c16226786.initial_effect(c)\n\t--flip\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(aux.Stringid(16226786,0))\n\te1:SetCategory(CATEGORY_DESTROY)\n\te1:SetProperty(EFFECT_FLAG_CARD_TARGET)\n\te1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_FLIP)\n\te1:SetTarget(c16226786.target)\n\te1:SetOperation(c16226786.operation)\n\tc:RegisterEffect(e1)\n\t--salvage\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetDescription(aux.Stringid(16226786,1))\n\te2:SetCategory(CATEGORY_TOHAND)\n\te2:SetProperty(EFFECT_FLAG_CARD_TARGET)\n\te2:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_F)\n\te2:SetCode(EVENT_TO_GRAVE)\n\te2:SetCondition(c16226786.thcon)\n\te2:SetTarget(c16226786.thtg)\n\te2:SetOperation(c16226786.thop)\n\tc:RegisterEffect(e2)\nend\nfunction c16226786.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\tif chkc then return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1-tp) end\n\tif chk==0 then return true end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_DESTROY)\n\tlocal g=Duel.SelectTarget(tp,aux.TRUE,tp,0,LOCATION_MZONE,1,1,nil)\n\tDuel.SetOperationInfo(0,CATEGORY_DESTROY,g,g:GetCount(),0,0)\nend\nfunction c16226786.operation(e,tp,eg,ep,ev,re,r,rp)\n\tlocal tc=Duel.GetFirstTarget()\n\tif tc and tc:IsRelateToEffect(e) and tc:IsControler(1-tp) then\n\t\tDuel.Destroy(tc,REASON_EFFECT)\n\tend\nend\nfunction c16226786.thcon(e,tp,eg,ep,ev,re,r,rp)\n\treturn e:GetHandler():IsPreviousLocation(LOCATION_HAND)\nend\nfunction c16226786.thfilter(c,ec)\n\treturn c:IsType(TYPE_FLIP) and c:IsAbleToHand() and c~=ec\nend\nfunction c16226786.thtg(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\tif chkc then return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and c16226786.thfilter(chkc,e:GetHandler()) end\n\tif chk==0 then return true end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND)\n\tlocal g=Duel.SelectTarget(tp,c16226786.thfilter,tp,LOCATION_GRAVE,0,1,1,nil,e:GetHandler())\n\tDuel.SetOperationInfo(0,CATEGORY_TOHAND,g,g:GetCount(),0,0)\nend\nfunction c16226786.thop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal tc=Duel.GetFirstTarget()\n\tif tc and tc:IsRelateToEffect(e) then\n\t\tDuel.SendtoHand(tc,nil,REASON_EFFECT)\n\tend\nend\n","c20932152.lua":"-- Deckhand period-text override, Edison (2010-04-24). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c20932152.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: edisonformat.com/functional-errata.html, Quickdraw Synchron (\"[Ignition] performs a Special Summon.\n-- Send (not discard) the card to the Graveyard when the effect resolves, this is not a cost.\"), and\n-- edisonformat.com/home/rules-update-quickdraws-summon-is-an-activated-effect (ruled to activate at SJC Edison 2010).\n-- Then: an Ignition effect from the hand that starts a Chain: as it resolves, send 1 monster from your hand to the\n-- Graveyard and Special Summon this card. The printing (SOVR-EN004) reads \"You can send 1 monster from your hand to\n-- the Graveyard and Special Summon this card from your hand.\" Its basis is a reported head-judge ruling at\n-- SJC Edison 2010, not a written UDE or Konami FAQ (manifest.json: status community-ruling).\n-- Today: a summoning procedure with no Chain; the monster is sent as part of the Summon.\n-- How: EFFECT_SPSUMMON_PROC becomes an EFFECT_TYPE_IGNITION in the hand; the send and the Summon move to the operation.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--クイック・シンクロン\nfunction c20932152.initial_effect(c)\n\t--special summon\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetCategory(CATEGORY_TOGRAVE+CATEGORY_SPECIAL_SUMMON)\n\te1:SetType(EFFECT_TYPE_IGNITION)\n\te1:SetRange(LOCATION_HAND)\n\te1:SetTarget(c20932152.sptg)\n\te1:SetOperation(c20932152.spop)\n\tc:RegisterEffect(e1)\n\t--\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetType(EFFECT_TYPE_SINGLE)\n\te2:SetCode(EFFECT_CANNOT_BE_SYNCHRO_MATERIAL)\n\te2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)\n\te2:SetValue(c20932152.synlimit)\n\tc:RegisterEffect(e2)\n\t--\n\tlocal e3=Effect.CreateEffect(c)\n\te3:SetType(EFFECT_TYPE_SINGLE)\n\te3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)\n\te3:SetCode(20932152)\n\tc:RegisterEffect(e3)\nend\nfunction c20932152.synlimit(e,c)\n\tif not c then return false end\n\treturn not aux.IsMaterialListSetCard(c,0x1017)\nend\nfunction c20932152.spfilter(c)\n\treturn c:IsType(TYPE_MONSTER) and c:IsAbleToGrave()\nend\nfunction c20932152.sptg(e,tp,eg,ep,ev,re,r,rp,chk)\n\tlocal c=e:GetHandler()\n\tif chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0\n\t\tand c:IsCanBeSpecialSummoned(e,0,tp,false,false)\n\t\tand Duel.IsExistingMatchingCard(c20932152.spfilter,tp,LOCATION_HAND,0,1,c) end\n\tDuel.SetOperationInfo(0,CATEGORY_TOGRAVE,nil,1,tp,LOCATION_HAND)\n\tDuel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,c,1,0,0)\nend\nfunction c20932152.spop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tif not c:IsRelateToEffect(e) or Duel.GetLocationCount(tp,LOCATION_MZONE)<=0 then return end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_TOGRAVE)\n\tlocal g=Duel.SelectMatchingCard(tp,c20932152.spfilter,tp,LOCATION_HAND,0,1,1,c)\n\t-- edisonformat: under Macro Cosmos the sent card is banished and the Summon still happens, so the\n\t-- Summon needs the card moved, not the card in the Graveyard.\n\tif g:GetCount()>0 and Duel.SendtoGrave(g,REASON_EFFECT)>0 then\n\t\tDuel.SpecialSummon(c,0,tp,tp,false,false,POS_FACEUP)\n\tend\nend\n","c21502796.lua":"-- Deckhand period-text override, Edison (2010-04-24). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c21502796.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: edisonformat.com/functional-errata.html, Ryko, Lightsworn Hunter (\"targets 1 card on the field (OPTIONAL)\").\n-- Then: FLIP: you may target 1 card on the field as it activates; on resolution destroy that target (if it is\n-- still there), then send the top 3 cards of your Deck to the Graveyard. The printing (LODT-EN022) does not\n-- say target; the targeting is edisonformat's ruling.\n-- Today: no target: the card to destroy is chosen as the effect resolves.\n-- How: the target is chosen (or declined) in the effect's target function.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--ライトロード・ハンター ライコウ\nfunction c21502796.initial_effect(c)\n\t--flip\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(aux.Stringid(21502796,0))\n\te1:SetCategory(CATEGORY_DECKDES+CATEGORY_DESTROY)\n\te1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_FLIP)\n\te1:SetTarget(c21502796.target)\n\te1:SetOperation(c21502796.operation)\n\tc:RegisterEffect(e1)\nend\nfunction c21502796.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\tif chkc then return chkc:IsOnField() end\n\tif chk==0 then return true end\n\te:SetProperty(0)\n\te:SetLabel(0)\n\tif Duel.IsExistingTarget(nil,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,1,nil)\n\t\tand Duel.SelectYesNo(tp,aux.Stringid(21502796,1)) then\n\t\te:SetProperty(EFFECT_FLAG_CARD_TARGET)\n\t\te:SetLabel(1)\n\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_DESTROY)\n\t\tlocal g=Duel.SelectTarget(tp,nil,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,1,1,nil)\n\t\tDuel.SetOperationInfo(0,CATEGORY_DESTROY,g,1,0,0)\n\tend\n\tDuel.SetOperationInfo(0,CATEGORY_DECKDES,nil,0,tp,3)\nend\nfunction c21502796.operation(e,tp,eg,ep,ev,re,r,rp)\n\tif e:GetLabel()==1 then\n\t\tlocal tc=Duel.GetFirstTarget()\n\t\tif tc and tc:IsRelateToEffect(e) then Duel.Destroy(tc,REASON_EFFECT) end\n\tend\n\tDuel.DiscardDeck(tp,3,REASON_EFFECT)\nend\n","c25862681.lua":"-- Deckhand period-text override, Edison (2010-04-24). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c25862681.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: edisonformat.com/functional-errata.html (the period behaviour as Edison plays it).\n-- Then: two once-per-turn effects (per copy, not by name); the first in either Main Phase; the second destroys\n-- one Field Spell Card and, if it does, gains 1000 LP, then may add any Field Spell, same name included.\n-- Today: each effect once per turn by name, the first in Main Phase 1 only, every Field Zone card destroyed,\n-- and the searched Field Spell must have a different name.\n-- The 2009 text names no target (\"destroy a Field Spell Card\"), so the card is chosen as the effect resolves.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--エンシェント・フェアリー・ドラゴン\nfunction c25862681.initial_effect(c)\n\t--synchro summon\n\taux.AddSynchroProcedure(c,nil,aux.NonTuner(nil),1)\n\tc:EnableReviveLimit()\n\t--special summon\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(aux.Stringid(25862681,0))\n\te1:SetCategory(CATEGORY_SPECIAL_SUMMON)\n\te1:SetType(EFFECT_TYPE_IGNITION)\n\te1:SetRange(LOCATION_MZONE)\n\te1:SetCountLimit(1)\n\te1:SetCost(c25862681.cost)\n\te1:SetTarget(c25862681.sumtg)\n\te1:SetOperation(c25862681.sumop)\n\tc:RegisterEffect(e1)\n\t--destroy\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetDescription(aux.Stringid(25862681,1))\n\te2:SetCategory(CATEGORY_DESTROY+CATEGORY_RECOVER+CATEGORY_SEARCH)\n\te2:SetType(EFFECT_TYPE_IGNITION)\n\te2:SetRange(LOCATION_MZONE)\n\te2:SetCountLimit(1)\n\te2:SetCost(c25862681.cost)\n\te2:SetTarget(c25862681.destg)\n\te2:SetOperation(c25862681.desop)\n\tc:RegisterEffect(e2)\nend\nfunction c25862681.cost(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return true end\n\tDuel.Hint(HINT_OPSELECTED,1-tp,e:GetDescription())\nend\nfunction c25862681.sumfilter(c,e,tp)\n\treturn c:IsLevelBelow(4) and c:IsCanBeSpecialSummoned(e,0,tp,false,false)\nend\nfunction c25862681.sumtg(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0\n\t\tand Duel.IsExistingMatchingCard(c25862681.sumfilter,tp,LOCATION_HAND,0,1,nil,e,tp) end\n\tDuel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,0,LOCATION_HAND)\n\tlocal e1=Effect.CreateEffect(e:GetHandler())\n\te1:SetType(EFFECT_TYPE_FIELD)\n\te1:SetCode(EFFECT_CANNOT_BP)\n\te1:SetProperty(EFFECT_FLAG_PLAYER_TARGET+EFFECT_FLAG_OATH)\n\te1:SetTargetRange(1,0)\n\te1:SetReset(RESET_PHASE+PHASE_END)\n\tDuel.RegisterEffect(e1,tp)\nend\nfunction c25862681.sumop(e,tp,eg,ep,ev,re,r,rp)\n\tif Duel.GetLocationCount(tp,LOCATION_MZONE)<=0 then return end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\tlocal g=Duel.SelectMatchingCard(tp,c25862681.sumfilter,tp,LOCATION_HAND,0,1,1,nil,e,tp)\n\tif g:GetCount()>0 then\n\t\tDuel.SpecialSummon(g,0,tp,tp,false,false,POS_FACEUP)\n\tend\nend\nfunction c25862681.destg(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return Duel.IsExistingMatchingCard(nil,tp,LOCATION_FZONE,LOCATION_FZONE,1,nil) end\n\tDuel.SetOperationInfo(0,CATEGORY_DESTROY,nil,1,PLAYER_ALL,LOCATION_FZONE)\n\tDuel.SetOperationInfo(0,CATEGORY_RECOVER,nil,0,tp,1000)\nend\nfunction c25862681.ffilter(c)\n\treturn c:IsType(TYPE_FIELD) and c:IsAbleToHand()\nend\nfunction c25862681.desop(e,tp,eg,ep,ev,re,r,rp)\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_DESTROY)\n\tlocal g=Duel.SelectMatchingCard(tp,nil,tp,LOCATION_FZONE,LOCATION_FZONE,1,1,nil)\n\tif g:GetCount()>0 and Duel.Destroy(g,REASON_EFFECT)>0 then\n\t\tDuel.Recover(tp,1000,REASON_EFFECT)\n\t\tlocal fg=Duel.GetMatchingGroup(c25862681.ffilter,tp,LOCATION_DECK,0,nil)\n\t\tif fg:GetCount()>0 and Duel.SelectYesNo(tp,aux.Stringid(25862681,2)) then\n\t\t\tDuel.BreakEffect()\n\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND)\n\t\t\tlocal sg=fg:Select(tp,1,1,nil)\n\t\t\tDuel.SendtoHand(sg,nil,REASON_EFFECT)\n\t\t\tDuel.ConfirmCards(1-tp,sg)\n\t\tend\n\tend\nend\n","c26202165.lua":"-- Deckhand period-text override, Edison (2010-04-24). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c26202165.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: edisonformat.com/functional-errata.html (the period behaviour as Edison plays it).\n-- Then: searches every time it goes from the field to the GY, and the searched card can be used that turn.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--クリッター\nfunction c26202165.initial_effect(c)\n\t--search\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(aux.Stringid(26202165,0))\n\te1:SetCategory(CATEGORY_TOHAND+CATEGORY_SEARCH)\n\te1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_F)\n\te1:SetCode(EVENT_TO_GRAVE)\n\te1:SetCondition(c26202165.condition)\n\te1:SetTarget(c26202165.target)\n\te1:SetOperation(c26202165.operation)\n\tc:RegisterEffect(e1)\nend\nfunction c26202165.condition(e,tp,eg,ep,ev,re,r,rp)\n\treturn e:GetHandler():IsPreviousLocation(LOCATION_ONFIELD)\nend\nfunction c26202165.target(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return true end\n\tDuel.SetOperationInfo(0,CATEGORY_TOHAND,nil,1,tp,LOCATION_DECK)\nend\nfunction c26202165.filter(c)\n\treturn c:IsAttackBelow(1500) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()\nend\nfunction c26202165.operation(e,tp,eg,ep,ev,re,r,rp)\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND)\n\tlocal g=Duel.SelectMatchingCard(tp,c26202165.filter,tp,LOCATION_DECK,0,1,1,nil)\n\tif g:GetCount()>0 then\n\t\tDuel.SendtoHand(g,nil,REASON_EFFECT)\n\t\tDuel.ConfirmCards(1-tp,g)\n\tend\nend\n","c29071332.lua":"-- Deckhand period-text override, Edison (2010-04-24). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c29071332.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: edisonformat.com/functional-errata.html, Armory Arm.\n-- Then: the damage equals the ATK the destroyed monster had on the field, modifiers included, and is\n-- inflicted even if that monster leaves the Graveyard before the effect resolves.\n-- Today: the ATK of the destroyed monster in the GY, and only while it is still there.\n-- How: the trigger records the monster's ATK as it left the field when it activates, and inflicts that.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--アームズ・エイド\nfunction c29071332.initial_effect(c)\n\t--synchro summon\n\taux.AddSynchroProcedure(c,nil,aux.NonTuner(nil),1)\n\tc:EnableReviveLimit()\n\t--equip\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(aux.Stringid(29071332,0))\n\te1:SetProperty(EFFECT_FLAG_CARD_TARGET)\n\te1:SetCategory(CATEGORY_EQUIP)\n\te1:SetType(EFFECT_TYPE_IGNITION)\n\te1:SetRange(LOCATION_MZONE)\n\te1:SetTarget(c29071332.eqtg)\n\te1:SetOperation(c29071332.eqop)\n\tc:RegisterEffect(e1)\nend\nfunction c29071332.eqtg(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\tif chkc then return chkc:IsLocation(LOCATION_MZONE) and chkc:IsFaceup() and chkc~=e:GetHandler() end\n\tif chk==0 then return e:GetHandler():GetFlagEffect(29071332)==0 and Duel.GetLocationCount(tp,LOCATION_SZONE)>0\n\t\tand Duel.IsExistingTarget(Card.IsFaceup,tp,LOCATION_MZONE,LOCATION_MZONE,1,e:GetHandler()) end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_EQUIP)\n\tlocal g=Duel.SelectTarget(tp,Card.IsFaceup,tp,LOCATION_MZONE,LOCATION_MZONE,1,1,e:GetHandler())\n\tDuel.SetOperationInfo(0,CATEGORY_EQUIP,g,1,0,0)\n\te:GetHandler():RegisterFlagEffect(29071332,RESET_EVENT+0x7e0000+RESET_PHASE+PHASE_END,0,1)\nend\nfunction c29071332.eqop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tlocal tc=Duel.GetFirstTarget()\n\tif not c:IsRelateToEffect(e) or c:IsFacedown() then return end\n\tif not tc:IsRelateToEffect(e) or tc:IsFacedown() then\n\t\tDuel.SendtoGrave(c,REASON_EFFECT)\n\t\treturn\n\tend\n\tif not Duel.Equip(tp,c,tc,false) then return end\n\t--unequip\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(aux.Stringid(29071332,1))\n\te1:SetCategory(CATEGORY_SPECIAL_SUMMON)\n\te1:SetType(EFFECT_TYPE_IGNITION)\n\te1:SetRange(LOCATION_SZONE)\n\te1:SetTarget(c29071332.sptg)\n\te1:SetOperation(c29071332.spop)\n\te1:SetReset(RESET_EVENT+RESETS_STANDARD)\n\tc:RegisterEffect(e1)\n\t--Atk up\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetType(EFFECT_TYPE_EQUIP)\n\te2:SetCode(EFFECT_UPDATE_ATTACK)\n\te2:SetValue(1000)\n\te2:SetReset(RESET_EVENT+RESETS_STANDARD)\n\tc:RegisterEffect(e2)\n\t--damage\n\tlocal e3=Effect.CreateEffect(c)\n\te3:SetDescription(aux.Stringid(29071332,2))\n\te3:SetCategory(CATEGORY_DAMAGE)\n\te3:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_F)\n\te3:SetCode(EVENT_BATTLE_DESTROYED)\n\te3:SetProperty(EFFECT_FLAG_PLAYER_TARGET)\n\te3:SetRange(LOCATION_SZONE)\n\te3:SetCondition(c29071332.damcon)\n\te3:SetTarget(c29071332.damtg)\n\te3:SetOperation(c29071332.damop)\n\te3:SetReset(RESET_EVENT+RESETS_STANDARD)\n\tc:RegisterEffect(e3)\n\t--eqlimit\n\tlocal e4=Effect.CreateEffect(c)\n\te4:SetType(EFFECT_TYPE_SINGLE)\n\te4:SetCode(EFFECT_EQUIP_LIMIT)\n\te4:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)\n\te4:SetValue(c29071332.eqlimit)\n\te4:SetReset(RESET_EVENT+RESETS_STANDARD)\n\te4:SetLabelObject(tc)\n\tc:RegisterEffect(e4)\nend\nfunction c29071332.eqlimit(e,c)\n\treturn c==e:GetLabelObject()\nend\nfunction c29071332.sptg(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return e:GetHandler():GetFlagEffect(29071332)==0 and Duel.GetLocationCount(tp,LOCATION_MZONE)>0\n\t\tand e:GetHandler():IsCanBeSpecialSummoned(e,0,tp,true,false,POS_FACEUP_ATTACK) end\n\tDuel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,e:GetHandler(),1,0,0)\n\te:GetHandler():RegisterFlagEffect(29071332,RESET_EVENT+0x7e0000+RESET_PHASE+PHASE_END,0,1)\nend\nfunction c29071332.spop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tif not c:IsRelateToEffect(e) then return end\n\tDuel.SpecialSummon(c,0,tp,tp,true,false,POS_FACEUP_ATTACK)\nend\nfunction c29071332.damcon(e,tp,eg,ep,ev,re,r,rp)\n\tlocal eqc=e:GetHandler():GetEquipTarget()\n\tlocal des=eg:GetFirst()\n\treturn des:IsLocation(LOCATION_GRAVE) and des:GetReasonCard()==eqc and des:IsType(TYPE_MONSTER)\nend\nfunction c29071332.damtg(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return true end\n\tlocal atk=eg:GetFirst():GetPreviousAttackOnField()\n\tif atk<0 then atk=0 end\n\te:SetLabel(atk)\n\tDuel.SetTargetPlayer(1-tp)\n\tDuel.SetOperationInfo(0,CATEGORY_DAMAGE,nil,0,1-tp,atk)\nend\nfunction c29071332.damop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal p=Duel.GetChainInfo(0,CHAININFO_TARGET_PLAYER)\n\tDuel.Damage(p,e:GetLabel(),REASON_EFFECT)\nend\n","c45247637.lua":"-- Deckhand period-text override, Edison (2010-04-24). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c45247637.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: edisonformat.com/functional-errata.html, Mark of the Rose (\"There are 2 [Trigger] effects, both start a Chain.\").\n-- Then: control returns to the opponent by a trigger in your End Phase, and you take it back by a second\n-- trigger in your Standby Phase; both start a Chain.\n-- Today: the End Phase trigger hands control back until your next Standby Phase, when it returns without a\n-- Chain.\n-- How: the End Phase flag no longer expires at the Standby Phase; a Standby Phase trigger clears it.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--薔薇の刻印\nfunction c45247637.initial_effect(c)\n\t--Activate\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetCategory(CATEGORY_CONTROL+CATEGORY_EQUIP)\n\te1:SetType(EFFECT_TYPE_ACTIVATE)\n\te1:SetCode(EVENT_FREE_CHAIN)\n\te1:SetProperty(EFFECT_FLAG_CARD_TARGET+EFFECT_FLAG_CONTINUOUS_TARGET)\n\te1:SetCost(c45247637.cost)\n\te1:SetTarget(c45247637.target)\n\te1:SetOperation(c45247637.operation)\n\tc:RegisterEffect(e1)\n\t--control\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetDescription(aux.Stringid(45247637,0))\n\te2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_F)\n\te2:SetCode(EVENT_PHASE+PHASE_END)\n\te2:SetRange(LOCATION_SZONE)\n\te2:SetCountLimit(1)\n\te2:SetCondition(c45247637.retcon)\n\te2:SetOperation(c45247637.retop)\n\tc:RegisterEffect(e2)\n\t--take control back (a trigger in the Standby Phase)\n\tlocal e3=Effect.CreateEffect(c)\n\te3:SetDescription(aux.Stringid(45247637,0))\n\te3:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_F)\n\te3:SetCode(EVENT_PHASE+PHASE_STANDBY)\n\te3:SetRange(LOCATION_SZONE)\n\te3:SetCountLimit(1)\n\te3:SetCondition(c45247637.gaincon)\n\te3:SetOperation(c45247637.gainop)\n\tc:RegisterEffect(e3)\n\tlocal e4=Effect.CreateEffect(c)\n\te4:SetType(EFFECT_TYPE_EQUIP)\n\te4:SetCode(EFFECT_SET_CONTROL)\n\te4:SetCondition(c45247637.ctcon)\n\te4:SetValue(c45247637.ctval)\n\tc:RegisterEffect(e4)\n\t--Equip limit\n\tlocal e5=Effect.CreateEffect(c)\n\te5:SetType(EFFECT_TYPE_SINGLE)\n\te5:SetCode(EFFECT_EQUIP_LIMIT)\n\te5:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)\n\te5:SetValue(c45247637.eqlimit)\n\tc:RegisterEffect(e5)\nend\nfunction c45247637.costfilter(c)\n\treturn c:IsRace(RACE_PLANT) and c:IsAbleToRemove()\nend\nfunction c45247637.cost(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return Duel.IsExistingMatchingCard(c45247637.costfilter,tp,LOCATION_GRAVE,0,1,nil) end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_REMOVE)\n\tlocal g=Duel.SelectMatchingCard(tp,c45247637.costfilter,tp,LOCATION_GRAVE,0,1,1,nil)\n\tDuel.Remove(g,POS_FACEUP,REASON_COST)\nend\nfunction c45247637.filter(c)\n\treturn c:IsFaceup()\nend\nfunction c45247637.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\tif chkc then return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1-tp) and c45247637.filter(chkc) end\n\tif chk==0 then return Duel.IsExistingTarget(c45247637.filter,tp,0,LOCATION_MZONE,1,nil) end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_CONTROL)\n\tlocal g=Duel.SelectTarget(tp,c45247637.filter,tp,0,LOCATION_MZONE,1,1,nil)\n\tDuel.SetOperationInfo(0,CATEGORY_CONTROL,g,1,0,0)\n\tDuel.SetOperationInfo(0,CATEGORY_EQUIP,e:GetHandler(),1,0,0)\nend\nfunction c45247637.eqlimit(e,c)\n\treturn e:GetHandlerPlayer()~=c:GetControler() or e:GetHandler():GetEquipTarget()==c\nend\nfunction c45247637.operation(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tlocal tc=Duel.GetFirstTarget()\n\tif c:IsRelateToEffect(e) and tc:IsFaceup() and tc:IsRelateToEffect(e) then\n\t\tDuel.Equip(tp,c,tc)\n\tend\nend\nfunction c45247637.retcon(e,tp,eg,ep,ev,re,r,rp)\n\treturn tp==Duel.GetTurnPlayer()\nend\nfunction c45247637.retop(e,tp,eg,ep,ev,re,r,rp)\n\te:GetHandler():RegisterFlagEffect(45247637,RESET_EVENT+RESETS_STANDARD,0,1)\nend\nfunction c45247637.gaincon(e,tp,eg,ep,ev,re,r,rp)\n\treturn tp==Duel.GetTurnPlayer() and e:GetHandler():GetFlagEffect(45247637)~=0\nend\nfunction c45247637.gainop(e,tp,eg,ep,ev,re,r,rp)\n\te:GetHandler():ResetFlagEffect(45247637)\nend\nfunction c45247637.ctcon(e,tp,eg,ep,ev,re,r,rp)\n\treturn e:GetHandler():GetFlagEffect(45247637)==0\nend\nfunction c45247637.ctval(e,c)\n\treturn e:GetHandlerPlayer()\nend\n","c47297616.lua":"-- Deckhand period-text override, Edison (2010-04-24). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c47297616.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: edisonformat.com/functional-errata.html (the period behaviour as Edison plays it).\n-- Then: every Spell/Trap activation and every Effect Monster effect activation is negated, each one costing it\n-- 500 ATK/DEF, links of the same chain included (edisonformat.com/functional-errata.html). Its own effects\n-- are not negated by itself. Today: once per Chain.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--光と闇の竜\nfunction c47297616.initial_effect(c)\n\t--cannot special summon\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_SINGLE)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)\n\te1:SetCode(EFFECT_SPSUMMON_CONDITION)\n\te1:SetValue(aux.FALSE)\n\tc:RegisterEffect(e1)\n\t--Attribute Dark\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetType(EFFECT_TYPE_SINGLE)\n\te2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)\n\te2:SetCode(EFFECT_ADD_ATTRIBUTE)\n\te2:SetRange(LOCATION_MZONE)\n\te2:SetValue(ATTRIBUTE_DARK)\n\tc:RegisterEffect(e2)\n\t--Negate\n\tlocal e3=Effect.CreateEffect(c)\n\te3:SetDescription(aux.Stringid(47297616,2))\n\te3:SetCategory(CATEGORY_NEGATE)\n\te3:SetType(EFFECT_TYPE_QUICK_F)\n\te3:SetCode(EVENT_CHAINING)\n\te3:SetProperty(EFFECT_FLAG_DAMAGE_STEP+EFFECT_FLAG_DAMAGE_CAL)\n\te3:SetRange(LOCATION_MZONE)\n\te3:SetCondition(c47297616.codisable)\n\te3:SetTarget(c47297616.tgdisable)\n\te3:SetOperation(c47297616.opdisable)\n\tc:RegisterEffect(e3)\n\t--Special summon\n\tlocal e4=Effect.CreateEffect(c)\n\te4:SetDescription(aux.Stringid(47297616,4))\n\te4:SetCategory(CATEGORY_SPECIAL_SUMMON+CATEGORY_DESTROY)\n\te4:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_F)\n\te4:SetCode(EVENT_TO_GRAVE)\n\te4:SetProperty(EFFECT_FLAG_CARD_TARGET)\n\te4:SetCondition(c47297616.cdspsum)\n\te4:SetTarget(c47297616.tgspsum)\n\te4:SetOperation(c47297616.opspsum)\n\tc:RegisterEffect(e4)\nend\nfunction c47297616.codisable(e,tp,eg,ep,ev,re,r,rp)\n\treturn (re:IsHasType(EFFECT_TYPE_ACTIVATE) or re:IsActiveType(TYPE_MONSTER))\n\t\tand re:GetHandler()~=e:GetHandler()\nend\nfunction c47297616.tgdisable(e,tp,eg,ep,ev,re,r,rp,chk)\n\tlocal c=e:GetHandler()\n\tif chk==0 then return c:GetFlagEffect(47297616)==0 end\n\tif c:IsHasEffect(EFFECT_REVERSE_UPDATE) then\n\t\tc:RegisterFlagEffect(47297616,RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END,0,1)\n\tend\n\tDuel.SetOperationInfo(0,CATEGORY_NEGATE,eg,1,0,0)\nend\nfunction c47297616.opdisable(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tif c:IsFacedown() or c:GetDefense()<500 or c:GetAttack()<500 or not c:IsRelateToEffect(e)\n\t\tor Duel.GetCurrentChain()~=ev+1 or c:IsStatus(STATUS_BATTLE_DESTROYED) then\n\t\treturn\n\tend\n\tif Duel.NegateActivation(ev) then\n\t\tlocal e1=Effect.CreateEffect(c)\n\t\te1:SetType(EFFECT_TYPE_SINGLE)\n\t\te1:SetReset(RESET_EVENT+RESETS_STANDARD+RESET_DISABLE)\n\t\te1:SetCode(EFFECT_UPDATE_ATTACK)\n\t\te1:SetValue(-500)\n\t\tc:RegisterEffect(e1)\n\t\tlocal e2=Effect.CreateEffect(c)\n\t\te2:SetType(EFFECT_TYPE_SINGLE)\n\t\te2:SetReset(RESET_EVENT+RESETS_STANDARD+RESET_DISABLE)\n\t\te2:SetCode(EFFECT_UPDATE_DEFENSE)\n\t\te2:SetValue(-500)\n\t\tc:RegisterEffect(e2)\n\tend\nend\nfunction c47297616.cdspsum(e)\n\treturn e:GetHandler():IsReason(REASON_DESTROY)\nend\nfunction c47297616.tgspsum(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\tif chkc then return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp)\n\t\tand chkc:IsCanBeSpecialSummoned(e,0,tp,false,false,POS_FACEUP,tp) end\n\tif chk==0 then return true end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\tlocal g=Duel.SelectTarget(tp,Card.IsCanBeSpecialSummoned,tp,LOCATION_GRAVE,0,1,1,nil,e,0,tp,false,false,POS_FACEUP,tp)\n\tDuel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,g,1,0,0)\n\tlocal dg=Duel.GetMatchingGroup(aux.TRUE,tp,LOCATION_ONFIELD,0,nil)\n\tDuel.SetOperationInfo(0,CATEGORY_DESTROY,dg,dg:GetCount(),0,0)\nend\nfunction c47297616.opspsum(e,tp,eg,ep,ev,re,r,rp)\n\tlocal dg=Duel.GetMatchingGroup(nil,tp,LOCATION_ONFIELD,0,nil)\n\tDuel.Destroy(dg,REASON_EFFECT)\n\tlocal tc=Duel.GetFirstTarget()\n\tif tc and tc:IsRelateToEffect(e) then\n\t\tDuel.BreakEffect()\n\t\tDuel.SpecialSummon(tc,0,tp,tp,false,false,POS_FACEUP)\n\tend\nend\n","c47355498.lua":"-- Deckhand period-text override, Edison (2010-04-24). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c47355498.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: edisonformat.com/functional-errata.html, Necrovalley (\"only negates effects that target\").\n-- Then: negate the effects of Spells, Traps and Effect Monsters that target a card in either GY; cards in\n-- either GY cannot be removed from play; \"Gravekeeper's\" monsters gain 500 ATK and DEF. Effects that do not\n-- target (Rekindling, Treeborn Frog, Red-Eyes Darkness Metal Dragon) are not negated.\n-- Today: cards in the GY cannot be affected by any card effect except their own, and any effect that would\n-- move one is negated, targeting or not.\n-- How: this script never registers EFFECT_NECRO_VALLEY. That flag is what today's scripts test through\n-- aux.NecroValleyFilter, so without it they play their own text, and only the rule below applies. A card\n-- in a GY cannot be chosen as the target of another card's effect, so a card that must target one cannot\n-- be activated, and an effect that already has such a target when this card is on the field is negated\n-- at resolution. Gravekeeper's Chief (its controller's GY) and the cards immune to Necrovalley (Rite of\n-- Spirit, Gravekeeper's Stele and others) keep today's exemptions.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--王家の眠る谷－ネクロバレー\nfunction c47355498.initial_effect(c)\n\t--Activate\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_ACTIVATE)\n\te1:SetCode(EVENT_FREE_CHAIN)\n\tc:RegisterEffect(e1)\n\t--Atk&Def\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetType(EFFECT_TYPE_FIELD)\n\te2:SetCode(EFFECT_UPDATE_ATTACK)\n\te2:SetRange(LOCATION_FZONE)\n\te2:SetTargetRange(LOCATION_MZONE,LOCATION_MZONE)\n\te2:SetTarget(aux.TargetBoolFunction(Card.IsSetCard,0x2e))\n\te2:SetValue(500)\n\tc:RegisterEffect(e2)\n\tlocal e3=e2:Clone()\n\te3:SetCode(EFFECT_UPDATE_DEFENSE)\n\tc:RegisterEffect(e3)\n\t--cannot remove\n\tlocal e4=Effect.CreateEffect(c)\n\te4:SetType(EFFECT_TYPE_FIELD)\n\te4:SetCode(EFFECT_CANNOT_REMOVE)\n\te4:SetRange(LOCATION_FZONE)\n\te4:SetTargetRange(LOCATION_GRAVE,0)\n\te4:SetCondition(c47355498.contp)\n\tc:RegisterEffect(e4)\n\tlocal e5=e4:Clone()\n\te5:SetTargetRange(0,LOCATION_GRAVE)\n\te5:SetCondition(c47355498.conntp)\n\tc:RegisterEffect(e5)\n\t--cards in the GY cannot be targeted\n\tlocal e6=Effect.CreateEffect(c)\n\te6:SetType(EFFECT_TYPE_FIELD)\n\te6:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)\n\te6:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)\n\te6:SetRange(LOCATION_FZONE)\n\te6:SetTargetRange(LOCATION_GRAVE,0)\n\te6:SetCondition(c47355498.contp)\n\te6:SetValue(c47355498.tgval)\n\tc:RegisterEffect(e6)\n\tlocal e7=e6:Clone()\n\te7:SetTargetRange(0,LOCATION_GRAVE)\n\te7:SetCondition(c47355498.conntp)\n\tc:RegisterEffect(e7)\n\t--negate an effect that targets a card in the GY\n\tlocal e8=Effect.CreateEffect(c)\n\te8:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)\n\te8:SetCode(EVENT_CHAIN_SOLVING)\n\te8:SetRange(LOCATION_FZONE)\n\te8:SetOperation(c47355498.disop)\n\tc:RegisterEffect(e8)\nend\nfunction c47355498.contp(e)\n\treturn not Duel.IsPlayerAffectedByEffect(e:GetHandler():GetControler(),EFFECT_NECRO_VALLEY_IM)\nend\nfunction c47355498.conntp(e)\n\treturn not Duel.IsPlayerAffectedByEffect(1-e:GetHandler():GetControler(),EFFECT_NECRO_VALLEY_IM)\nend\nfunction c47355498.tgval(e,re,rp)\n\treturn not re:GetHandler():IsHasEffect(EFFECT_NECRO_VALLEY_IM)\nend\nfunction c47355498.disfilter(c,re)\n\treturn c:IsLocation(LOCATION_GRAVE) and c:IsRelateToEffect(re) and c~=re:GetHandler()\n\t\tand not Duel.IsPlayerAffectedByEffect(c:GetControler(),EFFECT_NECRO_VALLEY_IM)\nend\nfunction c47355498.disop(e,tp,eg,ep,ev,re,r,rp)\n\tif not Duel.IsChainDisablable(ev) or not re:IsHasProperty(EFFECT_FLAG_CARD_TARGET)\n\t\tor re:GetHandler():IsHasEffect(EFFECT_NECRO_VALLEY_IM) then return end\n\tlocal tg=Duel.GetChainInfo(ev,CHAININFO_TARGET_CARDS)\n\tif tg and tg:IsExists(c47355498.disfilter,1,nil,re) then Duel.NegateEffect(ev,true) end\nend\n","c50321796.lua":"-- Deckhand period-text override, Edison (2010-04-24). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c50321796.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: edisonformat.com/functional-errata.html (the period behaviour as Edison plays it).\n-- Then: discard any number to return that many cards from the field (either side, itself included), with no\n-- once-per-turn limit. Today: only cards the opponent controls, once per turn.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--氷結界の龍 ブリューナク\nfunction c50321796.initial_effect(c)\n\t--synchro summon\n\taux.AddSynchroProcedure(c,nil,aux.NonTuner(nil),1)\n\tc:EnableReviveLimit()\n\t--to hand\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(aux.Stringid(50321796,0))\n\te1:SetCategory(CATEGORY_TOHAND)\n\te1:SetType(EFFECT_TYPE_IGNITION)\n\te1:SetProperty(EFFECT_FLAG_CARD_TARGET)\n\te1:SetRange(LOCATION_MZONE)\n\te1:SetCost(c50321796.cost)\n\te1:SetTarget(c50321796.target)\n\te1:SetOperation(c50321796.operation)\n\tc:RegisterEffect(e1)\nend\nfunction c50321796.costfilter(c,e,tp)\n\tif c:IsLocation(LOCATION_HAND) then\n\t\treturn c:IsDiscardable() and c:IsAbleToGraveAsCost()\n\telse\n\t\treturn e:GetHandler():IsSetCard(0x2f) and c:IsAbleToRemove() and c:IsHasEffect(18319762,tp)\n\tend\nend\nfunction c50321796.fselect(g)\n\treturn g:FilterCount(Card.IsLocation,nil,LOCATION_GRAVE)<=1\nend\nfunction c50321796.cost(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return Duel.IsExistingMatchingCard(c50321796.costfilter,tp,LOCATION_HAND+LOCATION_GRAVE,0,1,nil,e,tp) end\n\tlocal rt=Duel.GetTargetCount(Card.IsAbleToHand,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,nil)\n\tlocal g=Duel.GetMatchingGroup(c50321796.costfilter,tp,LOCATION_HAND+LOCATION_GRAVE,0,nil,e,tp)\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_DISCARD)\n\tlocal cg=g:SelectSubGroup(tp,c50321796.fselect,false,1,rt)\n\te:SetLabel(cg:GetCount())\n\tlocal tc=cg:Filter(Card.IsLocation,nil,LOCATION_GRAVE):GetFirst()\n\tif tc then\n\t\tlocal te=tc:IsHasEffect(18319762,tp)\n\t\tte:UseCountLimit(tp)\n\t\tDuel.Remove(tc,POS_FACEUP,REASON_EFFECT+REASON_REPLACE)\n\t\tcg:RemoveCard(tc)\n\tend\n\tDuel.SendtoGrave(cg,REASON_COST+REASON_DISCARD)\nend\nfunction c50321796.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\tif chkc then return chkc:IsOnField() and chkc:IsAbleToHand() end\n\tif chk==0 then return Duel.IsExistingTarget(Card.IsAbleToHand,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,1,nil) end\n\tlocal ct=e:GetLabel()\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_RTOHAND)\n\tlocal tg=Duel.SelectTarget(tp,Card.IsAbleToHand,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,ct,ct,nil)\n\tDuel.SetOperationInfo(0,CATEGORY_TOHAND,tg,ct,0,0)\nend\nfunction c50321796.operation(e,tp,eg,ep,ev,re,r,rp)\n\tlocal tg=Duel.GetChainInfo(0,CHAININFO_TARGET_CARDS)\n\tlocal rg=tg:Filter(Card.IsRelateToEffect,nil,e)\n\tif rg:GetCount()>0 then\n\t\tDuel.SendtoHand(rg,nil,REASON_EFFECT)\n\tend\nend\n","c68005187.lua":"-- Deckhand period-text override, Edison (2010-04-24). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c68005187.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: edisonformat.com/functional-errata.html, Soul Exchange (\"Tributing the opponent's monster is optional.\").\n-- Then: this turn you can Tribute the selected monster as if you controlled it (DTP1-EN010). Tributing it is\n-- optional: a Tribute Summon with your own monsters stays available.\n-- Today: if you Tribute a monster this turn, you must Tribute that target.\n-- How: EFFECT_EXTRA_RELEASE (a Tribute that must be used) becomes EFFECT_EXTRA_RELEASE_SUM and\n-- EFFECT_EXTRA_RELEASE_NONSUM, which may be used for a Tribute Summon or a Tribute for a cost.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--クロス・ソウル\nfunction c68005187.initial_effect(c)\n\t--Activate\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_ACTIVATE)\n\te1:SetProperty(EFFECT_FLAG_CARD_TARGET)\n\te1:SetCode(EVENT_FREE_CHAIN)\n\te1:SetCost(c68005187.cost)\n\te1:SetTarget(c68005187.target)\n\te1:SetOperation(c68005187.activate)\n\tc:RegisterEffect(e1)\nend\nfunction c68005187.filter(c)\n\treturn not (c:IsHasEffect(EFFECT_UNRELEASABLE_SUM) and c:IsHasEffect(EFFECT_UNRELEASABLE_NONSUM))\nend\nfunction c68005187.cost(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return Duel.GetCurrentPhase()~=PHASE_MAIN2 end\n\tlocal e1=Effect.CreateEffect(e:GetHandler())\n\te1:SetType(EFFECT_TYPE_FIELD)\n\te1:SetCode(EFFECT_CANNOT_BP)\n\te1:SetProperty(EFFECT_FLAG_PLAYER_TARGET+EFFECT_FLAG_OATH)\n\te1:SetTargetRange(1,0)\n\te1:SetReset(RESET_PHASE+PHASE_END)\n\tDuel.RegisterEffect(e1,tp)\nend\nfunction c68005187.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\tif chkc then return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1-tp) and c68005187.filter(chkc) end\n\tif chk==0 then return Duel.IsExistingTarget(c68005187.filter,tp,0,LOCATION_MZONE,1,nil) end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_TARGET)\n\tDuel.SelectTarget(tp,c68005187.filter,tp,0,LOCATION_MZONE,1,1,nil)\nend\nfunction c68005187.activate(e,tp,eg,ep,ev,re,r,rp)\n\tlocal tc=Duel.GetFirstTarget()\n\tif tc and tc:IsRelateToEffect(e) then\n\t\tlocal e1=Effect.CreateEffect(e:GetHandler())\n\t\te1:SetType(EFFECT_TYPE_SINGLE)\n\t\te1:SetCode(EFFECT_EXTRA_RELEASE_SUM)\n\t\te1:SetReset(RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END)\n\t\ttc:RegisterEffect(e1)\n\t\tlocal e2=e1:Clone()\n\t\te2:SetCode(EFFECT_EXTRA_RELEASE_NONSUM)\n\t\te2:SetValue(aux.TRUE)\n\t\ttc:RegisterEffect(e2)\n\tend\nend\n","c69279219.lua":"-- Deckhand period-text override, Edison (2010-04-24). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c69279219.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: edisonformat.com/functional-errata.html, My Body as a Shield (\"Can chain to a card / effect (ex: face-up 'Royal Oppression')\").\n-- Then: negate the activation of a card or effect your opponent activates that would destroy a monster on the\n-- field, including an effect of a face-up Spell or Trap Card (TU02-EN007 text, as edisonformat plays it).\n-- Today: only a Spell/Trap Card's activation or a monster effect.\n-- How: the condition no longer requires a monster effect or a card activation.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--我が身を盾に\nfunction c69279219.initial_effect(c)\n\t--Negate\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetCategory(CATEGORY_NEGATE+CATEGORY_DESTROY)\n\te1:SetType(EFFECT_TYPE_ACTIVATE)\n\te1:SetProperty(EFFECT_FLAG_DAMAGE_STEP+EFFECT_FLAG_DAMAGE_CAL)\n\te1:SetCode(EVENT_CHAINING)\n\te1:SetCondition(c69279219.condition)\n\te1:SetCost(c69279219.cost)\n\te1:SetTarget(c69279219.target)\n\te1:SetOperation(c69279219.operation)\n\tc:RegisterEffect(e1)\nend\nfunction c69279219.cfilter(c)\n\treturn c:IsOnField() and c:IsType(TYPE_MONSTER)\nend\nfunction c69279219.condition(e,tp,eg,ep,ev,re,r,rp)\n\tif tp==ep or not Duel.IsChainNegatable(ev) then return false end\n\tlocal ex,tg,tc=Duel.GetOperationInfo(ev,CATEGORY_DESTROY)\n\treturn ex and tg~=nil and tc+tg:FilterCount(c69279219.cfilter,nil)-tg:GetCount()>0\nend\nfunction c69279219.cost(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return Duel.CheckLPCost(tp,1500) end\n\tDuel.PayLPCost(tp,1500)\nend\nfunction c69279219.target(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return true end\n\tDuel.SetOperationInfo(0,CATEGORY_NEGATE,eg,1,0,0)\n\tif re:GetHandler():IsDestructable() and re:GetHandler():IsRelateToEffect(re) then\n\t\tDuel.SetOperationInfo(0,CATEGORY_DESTROY,eg,1,0,0)\n\tend\nend\nfunction c69279219.operation(e,tp,eg,ep,ev,re,r,rp)\n\tif Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then\n\t\tDuel.Destroy(eg,REASON_EFFECT)\n\tend\nend\n","c71645242.lua":"-- Deckhand period-text override, Edison (2010-04-24). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c71645242.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: edisonformat.com/functional-errata.html, Black Garden.\n-- Then: destroy this card and all face-up Plant-Type monsters, and Special Summon from your Graveyard 1\n-- monster with ATK equal to the total ATK of those monsters (CSOC-EN048). It does not target: the monster is\n-- chosen as the effect resolves, by the total of what was destroyed. edisonformat also says the Rose Token\n-- trigger activates for a face-down Special Summon; that is not modelled here.\n-- Today: it targets the monster in the GY as it activates, then summons it only if every Plant was destroyed.\n-- How: the ignition loses EFFECT_FLAG_CARD_TARGET; the operation sums the ATK the destroyed Plants had on the\n-- field and selects then.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--ブラック・ガーデン\nfunction c71645242.initial_effect(c)\n\taux.AddCodeList(c,71645242)\n\t--Activate\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_ACTIVATE)\n\te1:SetCode(EVENT_FREE_CHAIN)\n\tc:RegisterEffect(e1)\n\t--token\n\tlocal e4=Effect.CreateEffect(c)\n\te4:SetDescription(aux.Stringid(71645242,0))\n\te4:SetCategory(CATEGORY_SPECIAL_SUMMON+CATEGORY_TOKEN)\n\te4:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_F)\n\te4:SetRange(LOCATION_FZONE)\n\te4:SetCode(EVENT_CUSTOM+71645242)\n\te4:SetTarget(c71645242.sptg)\n\te4:SetOperation(c71645242.spop)\n\tc:RegisterEffect(e4)\n\t--special summon\n\tlocal e5=Effect.CreateEffect(c)\n\te5:SetDescription(aux.Stringid(71645242,1))\n\te5:SetCategory(CATEGORY_DESTROY+CATEGORY_SPECIAL_SUMMON)\n\te5:SetType(EFFECT_TYPE_IGNITION)\n\te5:SetRange(LOCATION_FZONE)\n\te5:SetTarget(c71645242.sptg2)\n\te5:SetOperation(c71645242.spop2)\n\tc:RegisterEffect(e5)\n\tif not c71645242.global_check then\n\t\tc71645242.global_check=true\n\t\tlocal ge1=Effect.CreateEffect(c)\n\t\tge1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)\n\t\tge1:SetCode(EVENT_SUMMON_SUCCESS)\n\t\tge1:SetCondition(c71645242.regcon)\n\t\tge1:SetOperation(c71645242.regop)\n\t\tDuel.RegisterEffect(ge1,0)\n\t\tlocal ge2=ge1:Clone()\n\t\tge2:SetCode(EVENT_SPSUMMON_SUCCESS)\n\t\tDuel.RegisterEffect(ge2,0)\n\tend\nend\nfunction c71645242.cfilter(c,tp)\n\tlocal code,code2=c:GetSpecialSummonInfo(SUMMON_INFO_CODE,SUMMON_INFO_CODE2)\n\treturn c:IsFaceup() and c:IsControler(tp) and code~=71645242 and code2~=71645242\nend\nfunction c71645242.regcon(e,tp,eg,ep,ev,re,r,rp)\n\tlocal sf=0\n\tif eg:IsExists(c71645242.cfilter,1,nil,0) then\n\t\tsf=sf+1\n\tend\n\tif eg:IsExists(c71645242.cfilter,1,nil,1) then\n\t\tsf=sf+2\n\tend\n\te:SetLabel(sf)\n\treturn sf~=0\nend\nfunction c71645242.regop(e,tp,eg,ep,ev,re,r,rp)\n\tDuel.RaiseEvent(eg,EVENT_CUSTOM+71645242,e,r,rp,ep,e:GetLabel())\nend\nfunction c71645242.sptg(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return true end\n\tDuel.SetTargetCard(eg)\n\tDuel.SetOperationInfo(0,CATEGORY_TOKEN,nil,1,0,0)\n\tDuel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,0,0)\nend\nfunction c71645242.opfilter(c,e)\n\treturn c:IsLocation(LOCATION_MZONE) and c:IsRelateToEffect(e) and not c:IsImmuneToEffect(e)\nend\nfunction c71645242.spop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal g=eg:Filter(c71645242.opfilter,nil,e)\n\tif g:GetCount()==0 then return end\n\tlocal tc=g:GetFirst()\n\twhile tc do\n\t\tif tc:IsFaceup() then\n\t\t\tlocal e1=Effect.CreateEffect(e:GetHandler())\n\t\t\te1:SetType(EFFECT_TYPE_SINGLE)\n\t\t\te1:SetCode(EFFECT_SET_ATTACK_FINAL)\n\t\t\te1:SetValue(math.ceil(tc:GetAttack()/2))\n\t\t\te1:SetReset(RESET_EVENT+RESETS_STANDARD)\n\t\t\ttc:RegisterEffect(e1)\n\t\tend\n\t\ttc=g:GetNext()\n\tend\n\tDuel.BreakEffect()\n\tif bit.extract(ev,tp)~=0 and Duel.GetLocationCount(1-tp,LOCATION_MZONE,tp)>0\n\t\tand Duel.IsPlayerCanSpecialSummonMonster(tp,71645243,0,TYPES_TOKEN_MONSTER,800,800,2,RACE_PLANT,ATTRIBUTE_DARK,POS_FACEUP_ATTACK,1-tp) then\n\t\tlocal token=Duel.CreateToken(tp,71645243)\n\t\tDuel.SpecialSummonStep(token,0,tp,1-tp,false,false,POS_FACEUP_ATTACK)\n\tend\n\tif bit.extract(ev,1-tp)~=0 and Duel.GetLocationCount(tp,LOCATION_MZONE,1-tp)>0\n\t\tand Duel.IsPlayerCanSpecialSummonMonster(1-tp,71645243,0,TYPES_TOKEN_MONSTER,800,800,2,RACE_PLANT,ATTRIBUTE_DARK,POS_FACEUP_ATTACK) then\n\t\tlocal token=Duel.CreateToken(1-tp,71645243)\n\t\tDuel.SpecialSummonStep(token,0,1-tp,tp,false,false,POS_FACEUP_ATTACK)\n\tend\n\tDuel.SpecialSummonComplete()\nend\nfunction c71645242.desfilter(c)\n\treturn c:IsFaceup() and c:IsRace(RACE_PLANT)\nend\nfunction c71645242.filter2(c,atk,e,tp)\n\treturn c:IsAttack(atk) and c:IsCanBeSpecialSummoned(e,0,tp,false,false)\nend\nfunction c71645242.sptg2(e,tp,eg,ep,ev,re,r,rp,chk)\n\tlocal g=Duel.GetMatchingGroup(c71645242.desfilter,tp,LOCATION_MZONE,LOCATION_MZONE,nil)\n\tlocal atk=g:GetSum(Card.GetAttack)\n\tlocal sc=g:FilterCount(Card.IsControler,nil,tp)\n\tif chk==0 then return g:GetCount()>0\n\t\tand Duel.GetLocationCount(tp,LOCATION_MZONE)>-sc\n\t\tand Duel.IsExistingMatchingCard(c71645242.filter2,tp,LOCATION_GRAVE,0,1,nil,atk,e,tp) end\n\tDuel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_GRAVE)\n\tg:AddCard(e:GetHandler())\n\tDuel.SetOperationInfo(0,CATEGORY_DESTROY,g,g:GetCount(),0,0)\nend\nfunction c71645242.atkfilter(c)\n\treturn c:IsPreviousLocation(LOCATION_MZONE) and c:IsPreviousPosition(POS_FACEUP)\nend\nfunction c71645242.spop2(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tlocal dg=Duel.GetMatchingGroup(c71645242.desfilter,tp,LOCATION_MZONE,LOCATION_MZONE,nil)\n\tdg:AddCard(c)\n\tif Duel.Destroy(dg,REASON_EFFECT)==0 then return end\n\tlocal atk=Duel.GetOperatedGroup():Filter(c71645242.atkfilter,nil):GetSum(Card.GetPreviousAttackOnField)\n\tif Duel.GetLocationCount(tp,LOCATION_MZONE)<=0 then return end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\tlocal sg=Duel.SelectMatchingCard(tp,aux.NecroValleyFilter(c71645242.filter2),tp,LOCATION_GRAVE,0,1,1,nil,atk,e,tp)\n\tif sg:GetCount()>0 then\n\t\tDuel.SpecialSummon(sg,0,tp,tp,false,false,POS_FACEUP)\n\tend\nend\n","c77565204.lua":"-- Deckhand period-text override, Edison (2010-04-24). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c77565204.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: edisonformat.com/functional-errata.html (the period behaviour as Edison plays it).\n-- Then: as the card resolves, show a Fusion Monster and send its listed materials from the Deck to the GY;\n-- during your 2nd Standby Phase after activation, Special Summon a Fusion Monster of that name (treated as a\n-- Fusion Summon). It cannot be activated unless it could send materials (edisonformat.com functional errata).\n-- Today: nothing is sent until your 1st Standby Phase after activation.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--未来融合－フューチャー・フュージョン\nfunction c77565204.initial_effect(c)\n\t--Activate: send the materials now\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetCategory(CATEGORY_DECKDES)\n\te1:SetType(EFFECT_TYPE_ACTIVATE)\n\te1:SetCode(EVENT_FREE_CHAIN)\n\te1:SetCost(c77565204.reg)\n\te1:SetTarget(c77565204.target)\n\te1:SetOperation(c77565204.activate)\n\tc:RegisterEffect(e1)\n\t--2nd Standby Phase: summon\n\tlocal e3=Effect.CreateEffect(c)\n\te3:SetCategory(CATEGORY_SPECIAL_SUMMON+CATEGORY_FUSION_SUMMON)\n\te3:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_F)\n\te3:SetRange(LOCATION_SZONE)\n\te3:SetCode(EVENT_PHASE+PHASE_STANDBY)\n\te3:SetCountLimit(1)\n\te3:SetCondition(c77565204.proccon)\n\te3:SetOperation(c77565204.procop)\n\te3:SetLabelObject(e1)\n\tc:RegisterEffect(e3)\n\t--Destroy\n\tlocal e4=Effect.CreateEffect(c)\n\te4:SetType(EFFECT_TYPE_CONTINUOUS+EFFECT_TYPE_SINGLE)\n\te4:SetCode(EVENT_LEAVE_FIELD)\n\te4:SetOperation(c77565204.desop)\n\tc:RegisterEffect(e4)\n\t--Destroy2\n\tlocal e5=Effect.CreateEffect(c)\n\te5:SetType(EFFECT_TYPE_CONTINUOUS+EFFECT_TYPE_FIELD)\n\te5:SetRange(LOCATION_SZONE)\n\te5:SetCode(EVENT_LEAVE_FIELD)\n\te5:SetCondition(c77565204.descon2)\n\te5:SetOperation(c77565204.desop2)\n\tc:RegisterEffect(e5)\nend\nfunction c77565204.reg(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return true end\n\tlocal c=e:GetHandler()\n\tc:SetTurnCounter(0)\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)\n\te1:SetCode(EVENT_PHASE_START+PHASE_STANDBY)\n\te1:SetCountLimit(1)\n\te1:SetOperation(c77565204.ctop)\n\tDuel.RegisterEffect(e1,tp)\n\tc:CreateEffectRelation(e1)\nend\nfunction c77565204.ctop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tlocal ct=c:GetTurnCounter()\n\tif not c:IsRelateToEffect(e) or ct>=2 then\n\t\tc:SetTurnCounter(0)\n\t\te:Reset()\n\t\treturn\n\tend\n\tif Duel.GetTurnPlayer()~=tp then return end\n\tct=ct+1\n\tc:SetTurnCounter(ct)\nend\nfunction c77565204.filter1(c,e)\n\treturn c:IsType(TYPE_MONSTER) and c:IsAbleToGrave() and not c:IsImmuneToEffect(e)\nend\nfunction c77565204.filter2(c,m)\n\treturn c:IsFusionSummonableCard() and c:CheckFusionMaterial(m)\nend\nfunction c77565204.target(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then\n\t\tlocal mg=Duel.GetMatchingGroup(c77565204.filter1,tp,LOCATION_DECK,0,nil,e)\n\t\treturn Duel.IsExistingMatchingCard(c77565204.filter2,tp,LOCATION_EXTRA,0,1,nil,mg)\n\tend\n\tDuel.SetOperationInfo(0,CATEGORY_TOGRAVE,nil,1,tp,LOCATION_DECK)\nend\nfunction c77565204.activate(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tif not c:IsRelateToEffect(e) then return end\n\tlocal mg=Duel.GetMatchingGroup(c77565204.filter1,tp,LOCATION_DECK,0,nil,e)\n\tlocal sg=Duel.GetMatchingGroup(c77565204.filter2,tp,LOCATION_EXTRA,0,nil,mg)\n\tif sg:GetCount()==0 then return end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_CONFIRM)\n\tlocal tc=sg:Select(tp,1,1,nil):GetFirst()\n\tDuel.ConfirmCards(1-tp,tc)\n\tlocal mat=Duel.SelectFusionMaterial(tp,tc,mg)\n\tmat:KeepAlive()\n\tDuel.SendtoGrave(mat,REASON_EFFECT)\n\tfor mc in aux.Next(mat) do\n\t\tmc:RegisterFlagEffect(77565204,RESET_EVENT+RESETS_STANDARD,0,1)\n\tend\n\te:SetLabel(tc:GetCode())\n\te:SetLabelObject(mat)\n\tDuel.ShuffleExtra(tp)\nend\nfunction c77565204.proccon(e,tp,eg,ep,ev,re,r,rp)\n\treturn Duel.GetTurnPlayer()==tp and e:GetHandler():GetTurnCounter()==2\n\t\tand e:GetLabelObject():GetLabel()~=0\nend\nfunction c77565204.procfilter(c,code,e,tp)\n\treturn c:IsCode(code) and c:IsCanBeSpecialSummoned(e,SUMMON_TYPE_FUSION,tp,false,false) and Duel.GetLocationCountFromEx(tp,tp,nil,c)>0\nend\nfunction c77565204.procop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tif not aux.MustMaterialCheck(nil,tp,EFFECT_MUST_BE_FMATERIAL) then return end\n\tlocal code=e:GetLabelObject():GetLabel()\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\tlocal g=Duel.SelectMatchingCard(tp,c77565204.procfilter,tp,LOCATION_EXTRA,0,1,1,nil,code,e,tp)\n\tlocal tc=g:GetFirst()\n\tif not tc then return end\n\tlocal mat=e:GetLabelObject():GetLabelObject()\n\tif mat then\n\t\tfor mc in aux.Next(mat) do\n\t\t\tif mc:GetFlagEffect(77565204)>0 then\n\t\t\t\tmc:SetReason(REASON_EFFECT+REASON_FUSION+REASON_MATERIAL)\n\t\t\tend\n\t\tend\n\t\ttc:SetMaterial(mat)\n\tend\n\tDuel.SpecialSummon(tc,SUMMON_VALUE_FUTURE_FUSION,tp,tp,false,false,POS_FACEUP)\n\ttc:CompleteProcedure()\n\tc:SetCardTarget(tc)\nend\nfunction c77565204.desop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal tc=e:GetHandler():GetFirstCardTarget()\n\tif tc and tc:IsLocation(LOCATION_MZONE) then\n\t\tDuel.Destroy(tc,REASON_EFFECT)\n\tend\nend\nfunction c77565204.descon2(e,tp,eg,ep,ev,re,r,rp)\n\tlocal tc=e:GetHandler():GetFirstCardTarget()\n\treturn tc and eg:IsContains(tc) and tc:IsReason(REASON_DESTROY)\nend\nfunction c77565204.desop2(e,tp,eg,ep,ev,re,r,rp)\n\tDuel.Destroy(e:GetHandler(),REASON_EFFECT)\nend\n","c87910978.lua":"-- Deckhand period-text override, Edison (2010-04-24). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c87910978.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: edisonformat.com/functional-errata.html (the period behaviour as Edison plays it).\n-- Then: any face-up monster the opponent controls, not only one that can be Normal Summoned/Set.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--洗脳－ブレインコントロール\nfunction c87910978.initial_effect(c)\n\t--Activate\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetCategory(CATEGORY_CONTROL)\n\te1:SetType(EFFECT_TYPE_ACTIVATE)\n\te1:SetProperty(EFFECT_FLAG_CARD_TARGET)\n\te1:SetCode(EVENT_FREE_CHAIN)\n\te1:SetCost(c87910978.cost)\n\te1:SetTarget(c87910978.target)\n\te1:SetOperation(c87910978.activate)\n\tc:RegisterEffect(e1)\nend\nfunction c87910978.cost(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return Duel.CheckLPCost(tp,800) end\n\tDuel.PayLPCost(tp,800)\nend\nfunction c87910978.filter(c)\n\treturn c:IsControlerCanBeChanged() and c:IsFaceup()\nend\nfunction c87910978.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\tif chkc then return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1-tp) and c87910978.filter(chkc) end\n\tif chk==0 then return Duel.IsExistingTarget(c87910978.filter,tp,0,LOCATION_MZONE,1,nil) end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_CONTROL)\n\tlocal g=Duel.SelectTarget(tp,c87910978.filter,tp,0,LOCATION_MZONE,1,1,nil)\n\tDuel.SetOperationInfo(0,CATEGORY_CONTROL,g,1,0,0)\nend\nfunction c87910978.activate(e,tp,eg,ep,ev,re,r,rp)\n\tlocal tc=Duel.GetFirstTarget()\n\tif tc:IsRelateToEffect(e) and tc:IsFaceup() then\n\t\tDuel.GetControl(tc,tp,PHASE_END,1)\n\tend\nend\n","c88264978.lua":"-- Deckhand period-text override, Edison (2010-04-24). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c88264978.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: edisonformat.com/functional-errata.html (the period behaviour as Edison plays it).\n-- Then: Special Summon itself by removing a face-up Dragon you control from play, any number of times a turn;\n-- once per turn per copy, Special Summon a Dragon from hand or GY. Neither effect is once per turn by name\n-- (edisonformat.com/functional-errata.html). Today: both are once per turn by name.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--レッドアイズ・ダークネスメタルドラゴン\nfunction c88264978.initial_effect(c)\n\t--spsummon proc\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_FIELD)\n\te1:SetCode(EFFECT_SPSUMMON_PROC)\n\te1:SetProperty(EFFECT_FLAG_UNCOPYABLE)\n\te1:SetRange(LOCATION_HAND)\n\te1:SetCondition(c88264978.hspcon)\n\te1:SetTarget(c88264978.hsptg)\n\te1:SetOperation(c88264978.hspop)\n\tc:RegisterEffect(e1)\n\t--spsummon\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetDescription(aux.Stringid(88264978,0))\n\te2:SetCategory(CATEGORY_SPECIAL_SUMMON)\n\te2:SetType(EFFECT_TYPE_IGNITION)\n\te2:SetCountLimit(1)\n\te2:SetRange(LOCATION_MZONE)\n\te2:SetTarget(c88264978.sptg)\n\te2:SetOperation(c88264978.spop)\n\tc:RegisterEffect(e2)\nend\nfunction c88264978.spfilter(c,tp)\n\treturn c:IsFaceup() and c:IsRace(RACE_DRAGON) and c:IsAbleToRemoveAsCost()\n\t\tand Duel.GetMZoneCount(tp,c)>0\nend\nfunction c88264978.hspcon(e,c)\n\tif c==nil then return true end\n\tlocal tp=c:GetControler()\n\treturn Duel.IsExistingMatchingCard(c88264978.spfilter,tp,LOCATION_MZONE,0,1,nil,tp)\nend\nfunction c88264978.hsptg(e,tp,eg,ep,ev,re,r,rp,chk,c)\n\tlocal g=Duel.GetMatchingGroup(c88264978.spfilter,tp,LOCATION_MZONE,0,nil,tp)\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_REMOVE)\n\tlocal tc=g:SelectUnselect(nil,tp,false,true,1,1)\n\tif tc then\n\t\te:SetLabelObject(tc)\n\t\treturn true\n\telse return false end\nend\nfunction c88264978.hspop(e,tp,eg,ep,ev,re,r,rp,c)\n\tlocal g=e:GetLabelObject()\n\tDuel.Remove(g,POS_FACEUP,REASON_SPSUMMON)\nend\nfunction c88264978.filter(c,e,tp)\n\treturn c:IsRace(RACE_DRAGON) and not c:IsCode(88264978) and c:IsCanBeSpecialSummoned(e,0,tp,false,false)\nend\nfunction c88264978.sptg(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0\n\t\tand Duel.IsExistingMatchingCard(c88264978.filter,tp,LOCATION_GRAVE+LOCATION_HAND,0,1,nil,e,tp) end\n\tDuel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_GRAVE+LOCATION_HAND)\nend\nfunction c88264978.spop(e,tp,eg,ep,ev,re,r,rp)\n\tif Duel.GetLocationCount(tp,LOCATION_MZONE)<=0 then return end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\tlocal g=Duel.SelectMatchingCard(tp,aux.NecroValleyFilter(c88264978.filter),tp,LOCATION_GRAVE+LOCATION_HAND,0,1,1,nil,e,tp)\n\tif g:GetCount()>0 then\n\t\tDuel.SpecialSummon(g,0,tp,tp,false,false,POS_FACEUP)\n\tend\nend\n","c89312388.lua":"-- Deckhand period-text override, Edison (2010-04-24). GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c89312388.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Community: edisonformat.com/functional-errata.html, Elemental Hero Prisma (\"This is not a cost.\").\n-- Then: the Fusion Monster is revealed and the listed Material sent from the Deck to the Graveyard as the\n-- effect resolves, not as a cost; if Prisma is not face-up then, nothing is sent.\n-- Today: revealing and sending are the cost of activating.\n-- How: the cost becomes a check, and the reveal and send move into the operation.\n-- Evidence and today's text: vendor/duel/errata/manifest.json.\n--E・HERO プリズマー\nfunction c89312388.initial_effect(c)\n\t--cos\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(aux.Stringid(89312388,0))\n\te1:SetType(EFFECT_TYPE_IGNITION)\n\te1:SetCountLimit(1)\n\te1:SetRange(LOCATION_MZONE)\n\te1:SetTarget(c89312388.costarget)\n\te1:SetOperation(c89312388.cosoperation)\n\tc:RegisterEffect(e1)\nend\nfunction c89312388.filter2(c,fc)\n\treturn aux.IsMaterialListCode(fc,c:GetCode()) and c:IsAbleToGrave()\nend\nfunction c89312388.filter1(c,tp)\n\treturn c:IsType(TYPE_FUSION) and Duel.IsExistingMatchingCard(c89312388.filter2,tp,LOCATION_DECK,0,1,nil,c)\nend\nfunction c89312388.costarget(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return Duel.IsExistingMatchingCard(c89312388.filter1,tp,LOCATION_EXTRA,0,1,nil,tp) end\n\tDuel.SetOperationInfo(0,CATEGORY_TOGRAVE,nil,1,tp,LOCATION_DECK)\nend\nfunction c89312388.cosoperation(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tif not c:IsRelateToEffect(e) or c:IsFacedown() then return end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_CONFIRM)\n\tlocal g=Duel.SelectMatchingCard(tp,c89312388.filter1,tp,LOCATION_EXTRA,0,1,1,nil,tp)\n\tif g:GetCount()==0 then return end\n\tDuel.ConfirmCards(1-tp,g)\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_TOGRAVE)\n\tlocal cg=Duel.SelectMatchingCard(tp,c89312388.filter2,tp,LOCATION_DECK,0,1,1,nil,g:GetFirst())\n\tlocal sc=cg:GetFirst()\n\tif not sc or Duel.SendtoGrave(sc,REASON_EFFECT)==0 or not sc:IsLocation(LOCATION_GRAVE) then return end\n\te:SetLabel(sc:GetCode())\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_SINGLE)\n\te1:SetCode(EFFECT_CHANGE_CODE)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)\n\te1:SetReset(RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END)\n\te1:SetValue(e:GetLabel())\n\tc:RegisterEffect(e1)\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetDescription(aux.Stringid(89312388,1))\n\te2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)\n\te2:SetCode(EVENT_PHASE+PHASE_END)\n\te2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)\n\te2:SetCountLimit(1)\n\te2:SetRange(LOCATION_MZONE)\n\te2:SetReset(RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END)\n\te2:SetLabelObject(e1)\n\te2:SetOperation(c89312388.rstop)\n\tc:RegisterEffect(e2)\nend\nfunction c89312388.rstop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tlocal e1=e:GetLabelObject()\n\te1:Reset()\n\tDuel.HintSelection(Group.FromCards(c))\n\tDuel.Hint(HINT_OPSELECTED,1-tp,e:GetDescription())\nend\n"},"fixes":{"c10019086.lua":"-- Deckhand bug fix, every format. GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c10019086.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Bug (F15, performance): its Link Summon needs 3 \"Tri-Brigade\" Spells/Traps in the GY, stated as a check on each candidate set of materials (the Link procedure's gf), so when the GY lacks them every 5-card subset of the candidates fails one by one: 501,000 subsets and 15 million card reads for 38 candidates (QA sweep job 41862 at 052856c, Tri-Brigade Revolt asking at the End Phase whether it can be summoned from the GY).\n-- Fix: the same GY requirement is also part of the material filter, so with no 3 such cards in the GY there are no candidate materials and no subsets to try; with them, nothing changes. Same answer for every input. Upstream: not reported (owner decision 2026-10-11).\n--鉄獣式強襲機動兵装改“BucephalusⅡ”\nlocal s,id,o=GetID()\nfunction s.initial_effect(c)\n\tc:EnableReviveLimit()\n\t--material\n\taux.AddLinkProcedure(c,function(mc) return mc:IsLinkRace(RACE_BEAST+RACE_BEASTWARRIOR+RACE_WINDBEAST) and s.spchk(nil,c,c:GetControler()) end,3,99,s.spchk)\n\t--splimit\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_SINGLE)\n\te1:SetCode(EFFECT_SPSUMMON_CONDITION)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)\n\te1:SetValue(s.splimit)\n\tc:RegisterEffect(e1)\n\t--actlimit\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)\n\te2:SetCode(EVENT_SPSUMMON_SUCCESS)\n\te2:SetRange(LOCATION_MZONE)\n\te2:SetCondition(s.limcon)\n\te2:SetOperation(s.limop)\n\tc:RegisterEffect(e2)\n\tlocal e3=Effect.CreateEffect(c)\n\te3:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)\n\te3:SetRange(LOCATION_MZONE)\n\te3:SetCode(EVENT_CHAIN_END)\n\te3:SetOperation(s.limop2)\n\tc:RegisterEffect(e3)\n\t--remove\n\tlocal e4=Effect.CreateEffect(c)\n\te4:SetCategory(CATEGORY_REMOVE)\n\te4:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_O)\n\te4:SetCode(EVENT_ATTACK_ANNOUNCE)\n\te4:SetRange(LOCATION_MZONE)\n\te4:SetTarget(s.rmtg)\n\te4:SetOperation(s.rmop)\n\tc:RegisterEffect(e4)\n\t--send to GY\n\tlocal e5=Effect.CreateEffect(c)\n\te5:SetCategory(CATEGORY_TOGRAVE)\n\te5:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O)\n\te5:SetCode(EVENT_TO_GRAVE)\n\te5:SetCountLimit(1,id)\n\te5:SetProperty(EFFECT_FLAG_DELAY)\n\te5:SetTarget(s.tgtg)\n\te5:SetOperation(s.tgop)\n\tc:RegisterEffect(e5)\nend\nfunction s.cfilter(c)\n\treturn c:IsType(TYPE_SPELL+TYPE_TRAP) and c:IsSetCard(0x14d)\nend\nfunction s.spchk(g,lc,tp)\n\treturn Duel.IsExistingMatchingCard(s.cfilter,tp,LOCATION_GRAVE,0,3,nil)\nend\nfunction s.splimit(e,se,sp,st,pos,tp)\n\treturn not e:GetHandler():IsLocation(LOCATION_EXTRA)\n\t\tor Duel.IsExistingMatchingCard(s.cfilter,sp,LOCATION_GRAVE,0,3,nil)\nend\nfunction s.limcon(e,tp,eg,ep,ev,re,r,rp)\n\treturn eg:IsExists(Card.IsSummonPlayer,1,e:GetHandler(),tp)\nend\nfunction s.limop(e,tp,eg,ep,ev,re,r,rp)\n\tif Duel.GetCurrentChain()==0 then\n\t\tDuel.SetChainLimitTillChainEnd(s.chainlm)\n\telseif Duel.GetCurrentChain()==1 then\n\t\te:GetHandler():RegisterFlagEffect(id,RESET_EVENT+RESETS_STANDARD,0,1)\n\t\tlocal e1=Effect.CreateEffect(e:GetHandler())\n\t\te1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)\n\t\te1:SetCode(EVENT_CHAINING)\n\t\te1:SetOperation(s.resetop)\n\t\tDuel.RegisterEffect(e1,tp)\n\t\tlocal e2=e1:Clone()\n\t\te2:SetCode(EVENT_BREAK_EFFECT)\n\t\te2:SetReset(RESET_CHAIN)\n\t\tDuel.RegisterEffect(e2,tp)\n\tend\nend\nfunction s.resetop(e,tp,eg,ep,ev,re,r,rp)\n\te:GetHandler():ResetFlagEffect(id)\n\te:Reset()\nend\nfunction s.limop2(e,tp,eg,ep,ev,re,r,rp)\n\tif e:GetHandler():GetFlagEffect(id)~=0 then\n\t\tDuel.SetChainLimitTillChainEnd(s.chainlm)\n\tend\n\te:GetHandler():ResetFlagEffect(id)\nend\nfunction s.chainlm(e,rp,tp)\n\treturn tp==rp\nend\nfunction s.rmtg(e,tp,eg,ep,ev,re,r,rp,chk)\n\tlocal c=e:GetHandler()\n\tif chk==0 then return c:IsAbleToRemove()\n\t\tand Duel.IsExistingMatchingCard(Card.IsAbleToRemove,tp,0,LOCATION_ONFIELD,1,nil) end\n\tlocal g=Duel.GetFieldGroup(tp,0,LOCATION_ONFIELD)+c\n\tDuel.SetOperationInfo(0,CATEGORY_REMOVE,g,#g,0,0)\nend\nfunction s.rmop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tlocal g=Duel.GetFieldGroup(tp,0,LOCATION_ONFIELD)\n\tif c:IsRelateToEffect(e) then g:AddCard(c) end\n\tDuel.Remove(g,POS_FACEUP,REASON_EFFECT)\nend\nfunction s.filter(c)\n\treturn c:IsRace(RACE_BEAST+RACE_BEASTWARRIOR+RACE_WINDBEAST) and c:IsAbleToGrave()\nend\nfunction s.tgtg(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return Duel.IsExistingMatchingCard(s.filter,tp,LOCATION_EXTRA,0,1,nil) end\n\tDuel.SetOperationInfo(0,CATEGORY_TOGRAVE,nil,1,tp,LOCATION_EXTRA)\nend\nfunction s.tgop(e,tp,eg,ep,ev,re,r,rp)\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_TOGRAVE)\n\tlocal g=Duel.SelectMatchingCard(tp,s.filter,tp,LOCATION_EXTRA,0,1,1,nil)\n\tDuel.SendtoGrave(g,REASON_EFFECT)\nend\n","c32756828.lua":"-- Deckhand bug fix, every format. GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c32756828.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Bug (F10): the activation check counts a target the cost can remove (a Tributed monster's equip card leaves with it), so the effect can resolve with no target and index a nil 'tc'. Repro: QA sweep job 39723.\n-- Fix: the operation does nothing when there is no target (one nil check). Upstream: not reported (owner decision 2026-10-11).\n--烙印の獣\nlocal s,id,o=GetID()\nfunction s.initial_effect(c)\n\t--activate\n\tlocal e0=Effect.CreateEffect(c)\n\te0:SetType(EFFECT_TYPE_ACTIVATE)\n\te0:SetCode(EVENT_FREE_CHAIN)\n\tc:RegisterEffect(e0)\n\t--destroy\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(aux.Stringid(id,0))\n\te1:SetCategory(CATEGORY_DESTROY)\n\te1:SetType(EFFECT_TYPE_QUICK_O)\n\te1:SetCode(EVENT_FREE_CHAIN)\n\te1:SetRange(LOCATION_SZONE)\n\te1:SetCountLimit(1)\n\te1:SetProperty(EFFECT_FLAG_CARD_TARGET)\n\te1:SetHintTiming(0,TIMINGS_CHECK_MONSTER+TIMING_MAIN_END)\n\te1:SetLabel(0)\n\te1:SetCondition(s.descon)\n\te1:SetCost(s.descost)\n\te1:SetTarget(s.destg)\n\te1:SetOperation(s.desop)\n\tc:RegisterEffect(e1)\n\t--recycle\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetDescription(aux.Stringid(id,1))\n\te2:SetType(EFFECT_TYPE_QUICK_O)\n\te2:SetCode(EVENT_FREE_CHAIN)\n\te2:SetRange(LOCATION_SZONE)\n\te2:SetCountLimit(1,id)\n\te2:SetProperty(EFFECT_FLAG_CARD_TARGET)\n\te2:SetHintTiming(TIMING_END_PHASE)\n\te2:SetCondition(s.condition)\n\te2:SetTarget(s.target)\n\te2:SetOperation(s.operation)\n\tc:RegisterEffect(e2)\nend\nfunction s.descon(e,tp,eg,ep,ev,re,r,rp)\n\tlocal ph=Duel.GetCurrentPhase()\n\treturn (ph==PHASE_MAIN1 or ph==PHASE_MAIN2)\n\t\tand Duel.IsExistingMatchingCard(aux.AND(Card.IsFaceup,Card.IsSetCard),tp,LOCATION_MZONE,0,1,nil,0x188)\nend\nfunction s.cfilter(c,tp)\n\treturn c:IsRace(RACE_DRAGON) and (c:IsControler(tp) or c:IsFaceup())\n\t\tand Duel.IsExistingTarget(nil,tp,0,LOCATION_ONFIELD,1,c)\nend\nfunction s.descost(e,tp,eg,ep,ev,re,r,rp,chk)\n\te:SetLabel(1)\n\treturn true\nend\nfunction s.destg(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\tif chkc then return chkc:IsOnField() and chkc:IsControler(1-tp) end\n\tlocal l=e:GetLabel()==1\n\tif chk==0 then\n\t\te:SetLabel(0)\n\t\treturn l and Duel.CheckReleaseGroup(tp,s.cfilter,1,nil,tp)\n\tend\n\tif l then\n\t\te:SetLabel(0)\n\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_RELEASE)\n\t\tlocal sg=Duel.SelectReleaseGroup(tp,s.cfilter,1,1,nil,tp)\n\t\tDuel.Release(sg,REASON_COST)\n\tend\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_DESTROY)\n\tlocal g=Duel.SelectTarget(tp,nil,tp,0,LOCATION_ONFIELD,1,1,nil)\n\tDuel.SetOperationInfo(0,CATEGORY_DESTROY,g,1,0,0)\nend\nfunction s.desop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal tc=Duel.GetFirstTarget()\n\tif tc and tc:IsRelateToEffect(e) then Duel.Destroy(tc,REASON_EFFECT) end\nend\nfunction s.condition(e,tp,eg,ep,ev,re,r,rp)\n\treturn Duel.GetCurrentPhase()==PHASE_END\nend\nfunction s.filter(c,tp)\n\treturn c:IsSetCard(0x15d) and c:IsType(TYPE_CONTINUOUS)\n\t\tand not c:IsForbidden() and c:CheckUniqueOnField(tp)\nend\nfunction s.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\tif chkc then return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc,tp) end\n\tif chk==0 then return Duel.GetLocationCount(tp,LOCATION_SZONE)>0\n\t\tand Duel.IsExistingTarget(s.filter,tp,LOCATION_GRAVE,0,1,nil,tp) end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_TOFIELD)\n\tlocal g=Duel.SelectTarget(tp,s.filter,tp,LOCATION_GRAVE,0,1,1,nil,tp)\n\tDuel.SetOperationInfo(0,CATEGORY_LEAVE_GRAVE,g,1,0,0)\nend\nfunction s.operation(e,tp,eg,ep,ev,re,r,rp)\n\tlocal tc=Duel.GetFirstTarget()\n\tif tc:IsRelateToEffect(e) then Duel.MoveToField(tc,tp,tp,LOCATION_SZONE,POS_FACEUP,true) end\nend\n","c40975243.lua":"-- Deckhand bug fix, every format. GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c40975243.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Bug (F15, performance): its activation check enumerated every subset of 1 to 5 of the Beast monsters in the GY and banished (C(n,5) for n of them, 575,000 subsets for 38) and asked for each whether a \"Tri-Brigade\" Link Monster can be Link Summoned with exactly it; a long game never returned from the End Phase chain window (QA sweep job 41862 at 052856c, a 31-card GY).\n-- Fix: the check asks each \"Tri-Brigade\" Link Monster in the Extra Deck once whether it can be Link Summoned from that group with 1 to 5 of them (the same question with the quantifiers swapped; the Link procedure's own search answers it). The activation itself is unchanged. Upstream: not reported (owner decision 2026-10-11).\n--鉄獣の抗戦\nfunction c40975243.initial_effect(c)\n\t--Activate\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetCategory(CATEGORY_SPECIAL_SUMMON)\n\te1:SetType(EFFECT_TYPE_ACTIVATE)\n\te1:SetCode(EVENT_FREE_CHAIN)\n\te1:SetCountLimit(1,40975243+EFFECT_COUNT_CODE_OATH)\n\te1:SetHintTiming(0,TIMING_END_PHASE)\n\te1:SetTarget(c40975243.target)\n\te1:SetOperation(c40975243.activate)\n\tc:RegisterEffect(e1)\nend\nfunction c40975243.spfilter(c,e,tp)\n\treturn c:IsRace(RACE_BEAST+RACE_BEASTWARRIOR+RACE_WINDBEAST) and c:IsCanBeSpecialSummoned(e,0,tp,false,false)\n\t\tand (c:IsLocation(LOCATION_GRAVE) or c:IsFaceup())\nend\nfunction c40975243.fselect(g,tp)\n\treturn Duel.IsExistingMatchingCard(c40975243.lkfilter,tp,LOCATION_EXTRA,0,1,nil,g)\nend\nfunction c40975243.lkfilter(c,g)\n\treturn c:IsSetCard(0x14d) and c:IsLinkSummonable(g,nil,g:GetCount(),g:GetCount())\nend\nfunction c40975243.lkfilter2(c,g,maxlink)\n\treturn c:IsSetCard(0x14d) and c:IsLinkSummonable(g,nil,1,maxlink)\nend\nfunction c40975243.chkfilter(c,tp)\n\treturn c:IsType(TYPE_LINK) and c:IsSetCard(0x14d) and Duel.GetLocationCountFromEx(tp,tp,nil,c)>0\nend\nfunction c40975243.target(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then\n\t\tif not Duel.IsPlayerCanSpecialSummonCount(tp,2) then return false end\n\t\tlocal ft=Duel.GetLocationCount(tp,LOCATION_MZONE)\n\t\tif ft<=0 then return false end\n\t\tif Duel.IsPlayerAffectedByEffect(tp,59822133) then ft=1 end\n\t\tlocal cg=Duel.GetMatchingGroup(c40975243.chkfilter,tp,LOCATION_EXTRA,0,nil,tp)\n\t\tif #cg==0 then return false end\n\t\tlocal _,maxlink=cg:GetMaxGroup(Card.GetLink)\n\t\tif maxlink>ft then maxlink=ft end\n\t\tlocal g=Duel.GetMatchingGroup(c40975243.spfilter,tp,LOCATION_GRAVE+LOCATION_REMOVED,0,nil,e,tp)\n\t\treturn Duel.IsExistingMatchingCard(c40975243.lkfilter2,tp,LOCATION_EXTRA,0,1,nil,g,maxlink)\n\tend\n\tDuel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_GRAVE+LOCATION_REMOVED)\nend\nfunction c40975243.activate(e,tp,eg,ep,ev,re,r,rp)\n\tif not Duel.IsPlayerCanSpecialSummonCount(tp,2) then return end\n\tlocal ft=Duel.GetLocationCount(tp,LOCATION_MZONE)\n\tif ft>1 and Duel.IsPlayerAffectedByEffect(tp,59822133) then ft=1 end\n\tlocal g=Duel.GetMatchingGroup(aux.NecroValleyFilter(c40975243.spfilter),tp,LOCATION_GRAVE+LOCATION_REMOVED,0,nil,e,tp)\n\tlocal cg=Duel.GetMatchingGroup(c40975243.chkfilter,tp,LOCATION_EXTRA,0,nil,tp)\n\tlocal _,maxlink=cg:GetMaxGroup(Card.GetLink)\n\tif ft>0 and maxlink then\n\t\tif maxlink>ft then maxlink=ft end\n\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\t\tlocal sg=g:SelectSubGroup(tp,c40975243.fselect,false,1,maxlink,tp)\n\t\tif not sg then return end\n\t\tlocal tc=sg:GetFirst()\n\t\twhile tc do\n\t\t\tDuel.SpecialSummonStep(tc,0,tp,tp,false,false,POS_FACEUP)\n\t\t\tlocal e1=Effect.CreateEffect(e:GetHandler())\n\t\t\te1:SetType(EFFECT_TYPE_SINGLE)\n\t\t\te1:SetCode(EFFECT_DISABLE)\n\t\t\te1:SetReset(RESET_EVENT+RESETS_STANDARD)\n\t\t\ttc:RegisterEffect(e1)\n\t\t\tlocal e2=e1:Clone()\n\t\t\te2:SetCode(EFFECT_DISABLE_EFFECT)\n\t\t\te2:SetValue(RESET_TURN_SET)\n\t\t\ttc:RegisterEffect(e2)\n\t\t\ttc=sg:GetNext()\n\t\tend\n\t\tDuel.SpecialSummonComplete()\n\t\tlocal og=Duel.GetOperatedGroup()\n\t\tDuel.AdjustAll()\n\t\tif og:FilterCount(Card.IsLocation,nil,LOCATION_MZONE)<sg:GetCount() then return end\n\t\tlocal tg=Duel.GetMatchingGroup(c40975243.lkfilter,tp,LOCATION_EXTRA,0,nil,og)\n\t\tif og:GetCount()==sg:GetCount() and tg:GetCount()>0 then\n\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\t\t\tlocal rg=tg:Select(tp,1,1,nil)\n\t\t\tDuel.LinkSummon(tp,rg:GetFirst(),og,nil,#og,#og)\n\t\tend\n\tend\nend\n","c56562619.lua":"-- Deckhand bug fix, every format. GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c56562619.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Bug (F9): the activation check counts a target the cost can remove (sending Ninjitsu Art of Dancing Leaves takes its monster with it), so the effect can resolve with no target and index a nil 'tc'. Repro: QA sweep job 16686.\n-- Fix: the operation does nothing when there is no target (one nil check). Upstream: not reported (owner decision 2026-10-11).\n--黒竜の忍者\nfunction c56562619.initial_effect(c)\n\t--spsummon condition\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_SINGLE)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)\n\te1:SetCode(EFFECT_SPSUMMON_CONDITION)\n\te1:SetValue(c56562619.splimit)\n\tc:RegisterEffect(e1)\n\t--remove\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetDescription(aux.Stringid(56562619,0))\n\te2:SetCategory(CATEGORY_REMOVE)\n\te2:SetType(EFFECT_TYPE_QUICK_O)\n\te2:SetCode(EVENT_FREE_CHAIN)\n\te2:SetRange(LOCATION_MZONE)\n\te2:SetProperty(EFFECT_FLAG_CARD_TARGET)\n\te2:SetHintTiming(0,TIMINGS_CHECK_MONSTER+TIMING_END_PHASE)\n\te2:SetCountLimit(1)\n\te2:SetCost(c56562619.rmcost)\n\te2:SetTarget(c56562619.rmtg)\n\te2:SetOperation(c56562619.rmop)\n\tc:RegisterEffect(e2)\n\t--special summon\n\tlocal e3=Effect.CreateEffect(c)\n\te3:SetDescription(aux.Stringid(56562619,1))\n\te3:SetCategory(CATEGORY_SPECIAL_SUMMON)\n\te3:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_F)\n\te3:SetCode(EVENT_LEAVE_FIELD)\n\te3:SetCondition(c56562619.spcon)\n\te3:SetTarget(c56562619.sptg)\n\te3:SetOperation(c56562619.spop)\n\tc:RegisterEffect(e3)\n\t--clear\n\tlocal e4=Effect.CreateEffect(c)\n\te4:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_CONTINUOUS)\n\te4:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)\n\te4:SetCode(EVENT_SUMMON_SUCCESS)\n\te4:SetOperation(c56562619.clearop)\n\tc:RegisterEffect(e4)\n\tlocal e5=e4:Clone()\n\te5:SetCode(EVENT_SPSUMMON_SUCCESS)\n\tc:RegisterEffect(e5)\n\tlocal ng=Group.CreateGroup()\n\tng:KeepAlive()\n\te2:SetLabelObject(ng)\n\te3:SetLabelObject(ng)\n\te4:SetLabelObject(ng)\n\te5:SetLabelObject(ng)\nend\nfunction c56562619.splimit(e,se,sp,st)\n\treturn (se:IsActiveType(TYPE_MONSTER) and se:GetHandler():IsSetCard(0x2b)) or se:GetHandler():IsSetCard(0x61)\nend\nfunction c56562619.cfilter1(c,tp)\n\treturn (c:IsLocation(LOCATION_HAND) or c:IsFaceup()) and c:IsType(TYPE_MONSTER) and c:IsSetCard(0x2b) and c:IsAbleToGraveAsCost()\n\t\tand Duel.IsExistingMatchingCard(c56562619.cfilter2,tp,LOCATION_HAND+LOCATION_ONFIELD,0,1,c,c)\nend\nfunction c56562619.cfilter2(c,cc)\n\treturn (c:IsLocation(LOCATION_HAND) or c:IsFaceup()) and c:IsSetCard(0x61) and c:IsAbleToGraveAsCost()\n\t\tand Duel.IsExistingTarget(c56562619.rmfilter,0,LOCATION_MZONE,LOCATION_MZONE,1,c,cc)\nend\nfunction c56562619.rmfilter(c,cc)\n\treturn c~=cc and c:IsAbleToRemove()\nend\nfunction c56562619.rmcost(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return Duel.IsExistingMatchingCard(c56562619.cfilter1,tp,LOCATION_HAND+LOCATION_MZONE,0,1,nil,tp) end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_TOGRAVE)\n\tlocal g1=Duel.SelectMatchingCard(tp,c56562619.cfilter1,tp,LOCATION_HAND+LOCATION_MZONE,0,1,1,nil,tp)\n\tlocal cc=g1:GetFirst()\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_TOGRAVE)\n\tlocal g2=Duel.SelectMatchingCard(tp,c56562619.cfilter2,tp,LOCATION_HAND+LOCATION_ONFIELD,0,1,1,cc,cc)\n\tg1:Merge(g2)\n\tDuel.SendtoGrave(g1,REASON_COST)\nend\nfunction c56562619.rmtg(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\tif chkc then return chkc:IsLocation(LOCATION_MZONE) and chkc:IsAbleToRemove() end\n\tif chk==0 then return true end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_REMOVE)\n\tlocal g=Duel.SelectTarget(tp,Card.IsAbleToRemove,tp,LOCATION_MZONE,LOCATION_MZONE,1,1,nil)\n\tDuel.SetOperationInfo(0,CATEGORY_REMOVE,g,1,0,0)\nend\nfunction c56562619.rmop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal tc=Duel.GetFirstTarget()\n\tif tc and tc:IsRelateToEffect(e) and Duel.Remove(tc,POS_FACEUP,REASON_EFFECT)~=0 and tc:IsLocation(LOCATION_REMOVED) then\n\t\ttc:RegisterFlagEffect(56562619,RESET_EVENT+RESETS_STANDARD,0,0)\n\t\te:GetLabelObject():AddCard(tc)\n\tend\nend\nfunction c56562619.spcon(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\treturn c:IsPreviousPosition(POS_FACEUP)\nend\nfunction c56562619.spfilter(c,e,tp)\n\treturn c:GetFlagEffect(56562619)~=0\n\t\tand (c:IsCanBeSpecialSummoned(e,0,tp,false,false) or c:IsCanBeSpecialSummoned(e,0,tp,false,false,POS_FACEUP,1-tp))\nend\nfunction c56562619.spfilter1(c,e,tp)\n\treturn c:GetFlagEffect(56562619)~=0 and c:IsCanBeSpecialSummoned(e,0,tp,false,false) and c:GetOwner()==tp\nend\nfunction c56562619.spfilter2(c,e,tp)\n\treturn c:GetFlagEffect(56562619)~=0 and c:IsCanBeSpecialSummoned(e,0,tp,false,false,POS_FACEUP,1-tp) and c:GetOwner()==1-tp\nend\nfunction c56562619.sptg(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return true end\n\tlocal g=e:GetLabelObject():Filter(c56562619.spfilter,nil,e,tp)\n\tDuel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,g,g:GetCount(),0,0)\nend\nfunction c56562619.spop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal ft1=Duel.GetLocationCount(tp,LOCATION_MZONE)\n\tlocal ft2=Duel.GetLocationCount(1-tp,LOCATION_MZONE,tp)\n\tlocal rg=e:GetLabelObject()\n\tif (ft1<=0 and ft2<=0) or rg:GetCount()<=0 then return end\n\tlocal sg=nil\n\tlocal sg1=rg:Filter(c56562619.spfilter1,nil,e,tp)\n\tlocal sg2=rg:Filter(c56562619.spfilter2,nil,e,tp)\n\tlocal gc1=sg1:GetCount()\n\tlocal gc2=sg2:GetCount()\n\tif Duel.IsPlayerAffectedByEffect(tp,59822133) then\n\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\t\tif ft1<=0 and gc2>0 then\n\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\t\t\tsg=sg2:Select(tp,1,1,nil)\n\t\telseif ft2<=0 and gc1>0 then\n\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\t\t\tsg=sg1:Select(tp,1,1,nil)\n\t\telseif (gc1>0 and ft1>0) or (gc2>0 and ft2>0) then\n\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\t\t\tsg=rg:FilterSelect(tp,c56562619.spfilter,1,1,nil,e,tp)\n\t\tend\n\t\tif sg~=nil then\n\t\t\tDuel.SpecialSummon(sg,0,tp,sg:GetFirst():GetOwner(),false,false,POS_FACEUP)\n\t\tend\n\t\trg:Clear()\n\t\treturn\n\tend\n\tif gc1>0 and ft1>0 then\n\t\tif sg1:GetCount()>ft1 then\n\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\t\t\tsg1=sg1:Select(tp,ft1,ft1,nil)\n\t\tend\n\t\tlocal sc=sg1:GetFirst()\n\t\twhile sc do\n\t\t\tDuel.SpecialSummonStep(sc,0,tp,tp,false,false,POS_FACEUP)\n\t\t\tsc=sg1:GetNext()\n\t\tend\n\tend\n\tif gc2>0 and ft2>0 then\n\t\tif sg2:GetCount()>ft2 then\n\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\t\t\tsg2=sg2:Select(tp,ft2,ft2,nil)\n\t\tend\n\t\tlocal sc=sg2:GetFirst()\n\t\twhile sc do\n\t\t\tDuel.SpecialSummonStep(sc,0,tp,1-tp,false,false,POS_FACEUP)\n\t\t\tsc=sg2:GetNext()\n\t\tend\n\tend\n\tDuel.SpecialSummonComplete()\n\trg:Clear()\nend\nfunction c56562619.clearop(e,tp,eg,ep,ev,re,r,rp)\n\te:GetLabelObject():Clear()\nend\n","c61840587.lua":"-- Deckhand bug fix, every format. GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c61840587.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Bug (F17): when it leaves the field it destroys the monsters it summoned, read through its activation effect's label object; that effect can already be reset by the same leave-field event, so the label object is nil and the operation indexes it. Repro: QA sweep job 5981 (HEAD 052856c), before answer 439.\n-- Fix: the operation does nothing when either label object is missing (one nil check more than the pinned script's). Upstream: not reported (owner decision 2026-10-11).\n--携帯型バッテリー\nfunction c61840587.initial_effect(c)\n\t--Activate\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetCategory(CATEGORY_SPECIAL_SUMMON)\n\te1:SetType(EFFECT_TYPE_ACTIVATE)\n\te1:SetCode(EVENT_FREE_CHAIN)\n\te1:SetHintTiming(0,TIMING_END_PHASE)\n\te1:SetProperty(EFFECT_FLAG_CARD_TARGET)\n\te1:SetTarget(c61840587.target)\n\te1:SetOperation(c61840587.operation)\n\tc:RegisterEffect(e1)\n\t--Destroy\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetType(EFFECT_TYPE_CONTINUOUS+EFFECT_TYPE_SINGLE)\n\te2:SetCode(EVENT_LEAVE_FIELD)\n\te2:SetOperation(c61840587.desop)\n\te2:SetLabelObject(e1)\n\tc:RegisterEffect(e2)\n\t--Destroy2\n\tlocal e3=Effect.CreateEffect(c)\n\te3:SetType(EFFECT_TYPE_CONTINUOUS+EFFECT_TYPE_FIELD)\n\te3:SetRange(LOCATION_SZONE)\n\te3:SetCode(EVENT_LEAVE_FIELD)\n\te3:SetCondition(c61840587.descon2)\n\te3:SetOperation(c61840587.desop2)\n\te3:SetLabelObject(e1)\n\tc:RegisterEffect(e3)\nend\nfunction c61840587.filter(c,e,tp)\n\treturn c:IsSetCard(0x28) and c:IsCanBeSpecialSummoned(e,0,tp,false,false,POS_FACEUP_ATTACK)\nend\nfunction c61840587.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\tif chkc then return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and c61840587.filter(chkc,e,tp) end\n\tif chk==0 then return not Duel.IsPlayerAffectedByEffect(tp,59822133)\n\t\tand Duel.GetLocationCount(tp,LOCATION_MZONE)>1\n\t\tand Duel.IsExistingTarget(c61840587.filter,tp,LOCATION_GRAVE,0,2,nil,e,tp) end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\tlocal g=Duel.SelectTarget(tp,c61840587.filter,tp,LOCATION_GRAVE,0,2,2,nil,e,tp)\n\tDuel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,g,2,0,0)\n\tif e:GetLabelObject() then e:GetLabelObject():DeleteGroup() end\n\te:SetLabelObject(nil)\nend\nfunction c61840587.sfilter(c,e,tp)\n\treturn c:IsRelateToEffect(e) and c:IsCanBeSpecialSummoned(e,0,tp,false,false,POS_FACEUP_ATTACK)\nend\nfunction c61840587.operation(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tlocal g=Duel.GetChainInfo(0,CHAININFO_TARGET_CARDS)\n\tlocal sg=g:Filter(c61840587.sfilter,nil,e,tp)\n\tlocal sct=sg:GetCount()\n\tlocal ft=Duel.GetLocationCount(tp,LOCATION_MZONE)\n\tif sct==0 or ft<=0 or (sct>1 and Duel.IsPlayerAffectedByEffect(tp,59822133)) then return end\n\tif sct>ft then\n\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\t\tsg=sg:Select(tp,ft,ft,nil)\n\t\tsct=ft\n\tend\n\tlocal tc=sg:GetFirst()\n\twhile tc and Duel.SpecialSummonStep(tc,0,tp,tp,false,false,POS_FACEUP_ATTACK) do\n\t\tc:SetCardTarget(tc)\n\t\ttc:CreateRelation(c,RESET_EVENT+0x1020000)\n\t\ttc=sg:GetNext()\n\tend\n\te:SetLabelObject(sg)\n\tsg:KeepAlive()\n\tDuel.SpecialSummonComplete()\nend\nfunction c61840587.desfilter1(c,rc)\n\treturn c:IsRelateToCard(rc) and c:IsLocation(LOCATION_MZONE) and not c:IsStatus(STATUS_DESTROY_CONFIRMED+STATUS_BATTLE_DESTROYED)\nend\nfunction c61840587.desop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tlocal lo=e:GetLabelObject()\n\tlocal sg=lo and lo:GetLabelObject()\n\tif not sg then return end\n\tDuel.Destroy(sg:Filter(c61840587.desfilter1,nil,c),REASON_EFFECT)\n\tsg:DeleteGroup()\n\te:SetLabelObject(nil)\nend\nfunction c61840587.descon2(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tlocal sg=e:GetLabelObject():GetLabelObject()\n\tif not sg or c:IsStatus(STATUS_DESTROY_CONFIRMED) then return false end\n\tlocal rg=eg:Filter(Card.IsRelateToCard,nil,c)\n\tlocal tc=rg:GetFirst()\n\twhile tc do sg:RemoveCard(tc) tc=rg:GetNext() end\n\treturn sg:GetCount()==0\nend\nfunction c61840587.desop2(e,tp,eg,ep,ev,re,r,rp)\n\tDuel.Destroy(e:GetHandler(),REASON_EFFECT)\nend\n","c76666602.lua":"-- Deckhand bug fix, every format. GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c76666602.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Bug (F7): its condition checks every monster on the field and in the GYs for the Dogmatika archetype, itself included. With an equip that adds an archetype (Ninjitsu Art Tool - Iron Digger), deciding whether that equip applies asks whether this card is immune, which asks the condition again: Lua \"C stack overflow\", about 80 errors per engine step. Repro: QA sweep job 39878.\n-- Fix: the condition no longer counts this card itself (one argument). Upstream: not reported (owner decision 2026-10-11).\n--聖痕喰らいし竜\nlocal s,id,o=GetID()\nfunction s.initial_effect(c)\n\taux.AddMaterialCodeList(c,68468459)\n\t--fusion procedure\n\tc:EnableReviveLimit()\n\taux.AddFusionProcMix(c,true,true,68468459,s.matfilter1,s.matfilter2,nil)\n\t--to deck\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(aux.Stringid(id,0))\n\te1:SetCategory(CATEGORY_TODECK)\n\te1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O)\n\te1:SetCode(EVENT_SPSUMMON_SUCCESS)\n\te1:SetProperty(EFFECT_FLAG_DELAY)\n\te1:SetCountLimit(1,id)\n\te1:SetTarget(s.tdtg)\n\te1:SetOperation(s.tdop)\n\tc:RegisterEffect(e1)\n\t--atk\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetType(EFFECT_TYPE_SINGLE)\n\te2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)\n\te2:SetRange(LOCATION_MZONE)\n\te2:SetCode(EFFECT_UPDATE_ATTACK)\n\te2:SetCondition(s.efcon)\n\te2:SetValue(500)\n\tc:RegisterEffect(e2)\n\t--immune\n\tlocal e3=Effect.CreateEffect(c)\n\te3:SetType(EFFECT_TYPE_SINGLE)\n\te3:SetCode(EFFECT_IMMUNE_EFFECT)\n\te3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)\n\te3:SetRange(LOCATION_MZONE)\n\te3:SetCondition(s.efcon)\n\te3:SetValue(s.efilter)\n\tc:RegisterEffect(e3)\n\t--to grave\n\tlocal e4=Effect.CreateEffect(c)\n\te4:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_CONTINUOUS)\n\te4:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)\n\te4:SetCode(EVENT_TO_GRAVE)\n\te4:SetOperation(s.regop)\n\tc:RegisterEffect(e4)\n\t--to hand\n\tlocal e5=Effect.CreateEffect(c)\n\te5:SetDescription(aux.Stringid(id,1))\n\te5:SetCategory(CATEGORY_SEARCH+CATEGORY_TOHAND)\n\te5:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_O)\n\te5:SetCode(EVENT_PHASE+PHASE_END)\n\te5:SetRange(LOCATION_GRAVE)\n\te5:SetCountLimit(1,id+o)\n\te5:SetCondition(s.thcon)\n\te5:SetTarget(s.thtg)\n\te5:SetOperation(s.thop)\n\tc:RegisterEffect(e5)\nend\nfunction s.matfilter1(c)\n\treturn c:IsFusionAttribute(ATTRIBUTE_LIGHT+ATTRIBUTE_DARK)\nend\nfunction s.matfilter2(c)\n\treturn c:IsFusionType(TYPE_EFFECT)\nend\nfunction s.tdfilter(c)\n\treturn c:IsAbleToDeck()\nend\nfunction s.tdtg(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return Duel.IsExistingMatchingCard(s.tdfilter,tp,LOCATION_GRAVE+LOCATION_REMOVED,LOCATION_GRAVE+LOCATION_REMOVED,1,nil) end\n\tDuel.SetOperationInfo(0,CATEGORY_TODECK,nil,1,PLAYER_ALL,LOCATION_GRAVE+LOCATION_REMOVED)\nend\nfunction s.tdop(e,tp,eg,ep,ev,re,r,rp)\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_TODECK)\n\tlocal g=Duel.SelectMatchingCard(tp,aux.NecroValleyFilter(s.tdfilter),tp,LOCATION_GRAVE+LOCATION_REMOVED,LOCATION_GRAVE+LOCATION_REMOVED,1,2,nil)\n\tif g:GetCount()>0 then\n\t\tDuel.HintSelection(g)\n\t\tDuel.SendtoDeck(g,nil,SEQ_DECKSHUFFLE,REASON_EFFECT)\n\tend\nend\nfunction s.effilter(c)\n\treturn c:IsFaceupEx() and c:IsSetCard(0x1d7) and c:IsType(TYPE_MONSTER)\nend\nfunction s.efcon(e)\n\treturn Duel.IsExistingMatchingCard(s.effilter,e:GetHandlerPlayer(),LOCATION_MZONE+LOCATION_GRAVE,LOCATION_MZONE+LOCATION_GRAVE,1,e:GetHandler())\nend\nfunction s.efilter(e,te)\n\treturn te:GetOwner()~=e:GetOwner()\nend\nfunction s.regop(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tc:RegisterFlagEffect(id,RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END,0,1)\nend\nfunction s.thcon(e,tp,eg,ep,ev,re,r,rp)\n\treturn e:GetHandler():GetFlagEffect(id)>0\nend\nfunction s.thfilter(c)\n\treturn c:IsSetCard(0x145,0x14d) and c:IsAbleToHand()\nend\nfunction s.thtg(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return Duel.IsExistingMatchingCard(s.thfilter,tp,LOCATION_DECK,0,1,nil) end\n\tDuel.SetOperationInfo(0,CATEGORY_TOHAND,nil,1,tp,LOCATION_DECK)\nend\nfunction s.thop(e,tp,eg,ep,ev,re,r,rp)\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND)\n\tlocal g=Duel.SelectMatchingCard(tp,s.thfilter,tp,LOCATION_DECK,0,1,1,nil)\n\tlocal tc=g:GetFirst()\n\tif tc then\n\t\tDuel.SendtoHand(tc,nil,REASON_EFFECT)\n\t\tDuel.ConfirmCards(1-tp,tc)\n\tend\nend\n","c83121692.lua":"-- Deckhand bug fix, every format. GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c83121692.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Bug (F16): its cost sends a card you control to the GY and can take away the only monster its target filter accepts, so the target selection is empty and the operation indexes a nil 'tc'. Repro: QA sweep job 1685 (HEAD 052856c), before answer 211.\n-- Fix: the operation does nothing when there is no target (one nil check, as F9 and F10). Upstream: not reported (owner decision 2026-10-11).\n--E・HERO テンペスター\nfunction c83121692.initial_effect(c)\n\t--fusion material\n\tc:EnableReviveLimit()\n\taux.AddFusionProcCode3(c,21844576,20721928,79979666,true,true)\n\t--spsummon condition\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_SINGLE)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)\n\te1:SetCode(EFFECT_SPSUMMON_CONDITION)\n\te1:SetValue(aux.fuslimit)\n\tc:RegisterEffect(e1)\n\t--set target\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(aux.Stringid(83121692,0))\n\te1:SetType(EFFECT_TYPE_IGNITION)\n\te1:SetRange(LOCATION_MZONE)\n\te1:SetProperty(EFFECT_FLAG_CARD_TARGET)\n\te1:SetCost(c83121692.cost)\n\te1:SetTarget(c83121692.target)\n\te1:SetOperation(c83121692.operation)\n\tc:RegisterEffect(e1)\nend\nc83121692.material_setcode=0x8\nfunction c83121692.cost(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return Duel.IsExistingMatchingCard(Card.IsAbleToGraveAsCost,tp,LOCATION_ONFIELD,0,1,e:GetHandler()) end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_TOGRAVE)\n\tlocal g=Duel.SelectMatchingCard(tp,Card.IsAbleToGraveAsCost,tp,LOCATION_ONFIELD,0,1,1,e:GetHandler())\n\tDuel.SendtoGrave(g,REASON_COST)\nend\nfunction c83121692.tgfilter(c,ec)\n\treturn c:GetFlagEffect(83121692)==0 and not ec:IsHasCardTarget(c)\nend\nfunction c83121692.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\tlocal c=e:GetHandler()\n\tif chkc then return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and c83121692.tgfilter(chkc,c) end\n\tif chk==0 then return Duel.IsExistingTarget(c83121692.tgfilter,tp,LOCATION_MZONE,0,1,nil,c) end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_TARGET)\n\tDuel.SelectTarget(tp,c83121692.tgfilter,tp,LOCATION_MZONE,0,1,1,nil,c)\nend\nfunction c83121692.operation(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tlocal tc=Duel.GetFirstTarget()\n\tif c:IsFacedown() or not c:IsRelateToEffect(e) then return end\n\tif not tc or not tc:IsRelateToEffect(e) then return end\n\tif c==tc then\n\t\ttc:RegisterFlagEffect(83121692,RESET_EVENT+RESETS_STANDARD,0,0)\n\telse\n\t\tc:SetCardTarget(tc)\n\tend\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_SINGLE)\n\te1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)\n\te1:SetCondition(c83121692.indcon)\n\te1:SetValue(1)\n\te1:SetReset(RESET_EVENT+RESETS_STANDARD)\n\ttc:RegisterEffect(e1)\nend\nfunction c83121692.indcon(e)\n\tlocal c=e:GetHandler()\n\tlocal rc=e:GetOwner()\n\tif c==rc then\n\t\treturn c:GetFlagEffect(83121692)~=0\n\telse\n\t\treturn rc:IsHasCardTarget(c)\n\tend\nend\n","c94739788.lua":"-- Deckhand bug fix, every format. GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts c94739788.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Bug (F18): with it face-up, the core's adjust loop collects every monster on a side that is not its owner and asks to move it home; a monster Special Summoned to the opponent's field (a Kaiju) carries no control-change effect for the core to undo, so nothing moves, the loop repeats, and the WASM aborts out of memory after about 200 s (QA sweep job 31791 at 052856c: Gameciel on the opponent's field, Solemn Strike chained).\n-- Fix: its continuous effect applies to the monsters that carry a control-change effect (EFFECT_SET_CONTROL), which is every monster the pinned core returns to its owner today; a monster whose control the core could not return keeps its controller instead of hanging the duel. Upstream: not reported (owner decision 2026-10-11).\n--洗脳解除\nfunction c94739788.brainwashed(e,c)\n\treturn c:IsHasEffect(EFFECT_SET_CONTROL)\nend\nfunction c94739788.initial_effect(c)\n\tDuel.EnableGlobalFlag(GLOBALFLAG_BRAINWASHING_CHECK)\n\t--Activate\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_ACTIVATE)\n\te1:SetCode(EVENT_FREE_CHAIN)\n\tc:RegisterEffect(e1)\n\t--\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetType(EFFECT_TYPE_FIELD)\n\te2:SetCode(EFFECT_REMOVE_BRAINWASHING)\n\te2:SetProperty(EFFECT_FLAG_SET_AVAILABLE)\n\te2:SetRange(LOCATION_SZONE)\n\te2:SetTargetRange(LOCATION_MZONE,LOCATION_MZONE)\n\te2:SetTarget(c94739788.brainwashed)\n\tc:RegisterEffect(e2)\nend\n","procedure.lua":"-- Deckhand bug fix, every format. GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts procedure.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Bug (F13, performance): Auxiliary.SynMixCheck walks every ORDERING of the candidate Synchro Materials (n! paths for n candidates) instead of every subset, and with five or fewer candidates it turns its level pruning off, so one \"is this summonable?\" check for a Tuner + 1..99 Tuners monster (Kewl Tune Loudness War) ran the material goal check 60,000 times; an Elf Tune board with three Kewl Tune monsters and hand Tuners cost about 700 ms per engine answer. Repro: QA Elf Tune position (docs/playtest.md, M7.5 clarification), dev seed 7, turn 4. Bug (F14, performance): the Fusion-repeat material check (AddFusionProcMixRep, \"A + 1 or more B\") assigned roles to the selected materials in every order (k!) and picked the repeat-role materials as sequences (n!/(n-k)!), so a selection that cannot complete ran the whole space: Frightfur Fusion with 12 materials picked from a 28-card graveyard never returned (QA sweep job 25800 at 052856c).\n-- Fix: the pinned file unchanged, plus one block at its end (\"Deckhand fix (F13)\") that redefines SynMixCheck (the condition's search, entered from SynMixFilter4) and SynMixCheckRecursive (also the material selection's filter at SynMixTarget, procedure.lua:290) to visit each subset once, in ascending minimum Synchro Level so the pruning cuts exactly what it cut before. Same answer for every input; see the proof in the QA report. Upstream: not reported (owner decision 2026-10-11). Plus one block (\"Deckhand fix (F14)\") that redefines FCheckMixRepSelectedCond, FCheckSelectMixRep and FSelectMixRep: the selected materials take their roles in a fixed order and the repeat-role picks are combinations in candidate order; the goal checks read the chosen cards as a set, so the same answer for every input.\n--Fusion check functions\nAuxiliary.FCheckAdditional=nil\nAuxiliary.FGoalCheckAdditional=nil\n\n--Ritual check functions\nAuxiliary.RCheckAdditional=nil\nAuxiliary.RGCheckAdditional=nil\n\n--Gemini Summon\nfunction Auxiliary.IsDualState(effect)\n\tlocal c=effect:GetHandler()\n\treturn not c:IsDisabled() and c:IsDualState()\nend\nfunction Auxiliary.IsNotDualState(effect)\n\tlocal c=effect:GetHandler()\n\treturn c:IsDisabled() or not c:IsDualState()\nend\nfunction Auxiliary.DualNormalCondition(effect)\n\tlocal c=effect:GetHandler()\n\treturn c:IsFaceup() and not c:IsDualState()\nend\nfunction Auxiliary.EnableDualAttribute(c)\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_SINGLE)\n\te1:SetCode(EFFECT_DUAL_SUMMONABLE)\n\tc:RegisterEffect(e1)\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetType(EFFECT_TYPE_SINGLE)\n\te2:SetCode(EFFECT_ADD_TYPE)\n\te2:SetProperty(EFFECT_FLAG_SINGLE_RANGE+EFFECT_FLAG_IGNORE_IMMUNE)\n\te2:SetRange(LOCATION_MZONE+LOCATION_GRAVE)\n\te2:SetCondition(Auxiliary.DualNormalCondition)\n\te2:SetValue(TYPE_NORMAL)\n\tc:RegisterEffect(e2)\n\tlocal e3=e2:Clone()\n\te3:SetCode(EFFECT_REMOVE_TYPE)\n\te3:SetValue(TYPE_EFFECT)\n\tc:RegisterEffect(e3)\nend\n\n--Synchro Summon\nfunction Auxiliary.Tuner(f,...)\n\tlocal ext_params=table.pack(...)\n\treturn\tfunction(target,syncard)\n\t\t\t\treturn target:IsTuner(syncard) and (not f or f(target,table.unpack(ext_params,1,ext_params.n)))\n\t\t\tend\nend\nfunction Auxiliary.NonTuner(f,...)\n\tlocal ext_params=table.pack(...)\n\treturn\tfunction(target,syncard)\n\t\t\t\treturn target:IsNotTuner(syncard) and (not f or f(target,table.unpack(ext_params,1,ext_params.n)))\n\t\t\tend\nend\n---Synchro monster, 1 tuner + min to max monsters\n---@param c Card\n---@param f1 function|nil\n---@param f2 function|nil\n---@param minc integer\n---@param maxc? integer\nfunction Auxiliary.AddSynchroProcedure(c,f1,f2,minc,maxc)\n\tif maxc==nil then maxc=c:GetLevel()-1 end\n\tlocal maxct=math.min(maxc,c:GetLevel()-1)\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(1164)\n\te1:SetType(EFFECT_TYPE_FIELD)\n\te1:SetCode(EFFECT_SPSUMMON_PROC)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)\n\te1:SetRange(LOCATION_EXTRA)\n\te1:SetCondition(Auxiliary.SynCondition(f1,f2,minc,maxct))\n\te1:SetTarget(Auxiliary.SynTarget(f1,f2,minc,maxct))\n\te1:SetOperation(Auxiliary.SynOperation(f1,f2,minc,maxct))\n\te1:SetValue(SUMMON_TYPE_SYNCHRO)\n\tc:RegisterEffect(e1)\nend\nfunction Auxiliary.SynCondition(f1,f2,minct,maxct)\n\treturn\tfunction(e,c,smat,mg,min,max)\n\t\t\t\tif c==nil then return true end\n\t\t\t\tif c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end\n\t\t\t\tlocal minc=minct\n\t\t\t\tlocal maxc=maxct\n\t\t\t\tif min then\n\t\t\t\t\tif min>minc then minc=min end\n\t\t\t\t\tif max<maxc then maxc=max end\n\t\t\t\t\tif minc>maxc then return false end\n\t\t\t\tend\n\t\t\t\tif smat and smat:IsTuner(c) and (not f1 or f1(smat)) then\n\t\t\t\t\treturn Duel.CheckTunerMaterial(c,smat,f1,f2,minc,maxc,mg) end\n\t\t\t\treturn Duel.CheckSynchroMaterial(c,f1,f2,minc,maxc,smat,mg)\n\t\t\tend\nend\nfunction Auxiliary.SynTarget(f1,f2,minct,maxct)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp,chk,c,smat,mg,min,max)\n\t\t\t\tlocal minc=minct\n\t\t\t\tlocal maxc=maxct\n\t\t\t\tif min then\n\t\t\t\t\tif min>minc then minc=min end\n\t\t\t\t\tif max<maxc then maxc=max end\n\t\t\t\t\tif minc>maxc then return false end\n\t\t\t\tend\n\t\t\t\tlocal g=nil\n\t\t\t\tif smat and smat:IsTuner(c) and (not f1 or f1(smat)) then\n\t\t\t\t\tg=Duel.SelectTunerMaterial(c:GetControler(),c,smat,f1,f2,minc,maxc,mg)\n\t\t\t\telse\n\t\t\t\t\tg=Duel.SelectSynchroMaterial(c:GetControler(),c,f1,f2,minc,maxc,smat,mg)\n\t\t\t\tend\n\t\t\t\tif g then\n\t\t\t\t\tg:KeepAlive()\n\t\t\t\t\te:SetLabelObject(g)\n\t\t\t\t\treturn true\n\t\t\t\telse return false end\n\t\t\tend\nend\nfunction Auxiliary.SynOperation(f1,f2,minct,maxct)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp,c,smat,mg,min,max)\n\t\t\t\tlocal g=e:GetLabelObject()\n\t\t\t\tc:SetMaterial(g)\n\t\t\t\tDuel.SendtoGrave(g,REASON_MATERIAL+REASON_SYNCHRO)\n\t\t\t\tg:DeleteGroup()\n\t\t\tend\nend\n--Synchro monster, 1 tuner + 1 monster\n--backward compatibility\nfunction Auxiliary.AddSynchroProcedure2(c,f1,f2)\n\tAuxiliary.AddSynchroProcedure(c,f1,f2,1,1)\nend\n---Synchro monster, f1~f3 each 1 MONSTER + f4 min to max monsters\n---@param c Card\n---@param f1 function|nil\n---@param f2 function|nil\n---@param f3 function|nil\n---@param f4 function|nil\n---@param minc integer\n---@param maxc integer\n---@param gc? function\nfunction Auxiliary.AddSynchroMixProcedure(c,f1,f2,f3,f4,minc,maxc,gc)\n\tlocal maxct=maxc\n\tif maxct>c:GetLevel() then\n\t\tmaxct=c:GetLevel()\n\t\tif f1 then maxct=maxct-1 end\n\t\tif f2 then maxct=maxct-1 end\n\t\tif f3 then maxct=maxct-1 end\n\tend\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(1164)\n\te1:SetType(EFFECT_TYPE_FIELD)\n\te1:SetCode(EFFECT_SPSUMMON_PROC)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)\n\te1:SetRange(LOCATION_EXTRA)\n\te1:SetCondition(Auxiliary.SynMixCondition(f1,f2,f3,f4,minc,maxct,gc))\n\te1:SetTarget(Auxiliary.SynMixTarget(f1,f2,f3,f4,minc,maxct,gc))\n\te1:SetOperation(Auxiliary.SynMixOperation(f1,f2,f3,f4,minc,maxct,gc))\n\te1:SetValue(SUMMON_TYPE_SYNCHRO)\n\tc:RegisterEffect(e1)\nend\nfunction Auxiliary.SynMaterialFilter(c,syncard)\n\treturn c:IsFaceupEx() and c:IsCanBeSynchroMaterial(syncard)\nend\nfunction Auxiliary.SynLimitFilter(c,f,e,syncard)\n\treturn f and not f(e,c,syncard)\nend\nfunction Auxiliary.GetSynchroLevelFlowerCardian(c)\n\treturn 2\nend\nfunction Auxiliary.GetMinSynchroLevel(c,syncard)\n\tlocal lv=c:GetSynchroLevel(syncard)\n\tlocal minlv=c:GetLevel()\n\twhile lv&MAX_PARAMETER>0 do\n\t\tminlv=math.min(minlv,lv&MAX_PARAMETER)\n\t\tlv=lv>>16\n\tend\n\treturn minlv\nend\nfunction Auxiliary.GetSynMaterials(tp,syncard)\n\tlocal mg=Duel.GetSynchroMaterial(tp):Filter(Auxiliary.SynMaterialFilter,nil,syncard)\n\tif mg:IsExists(Card.GetHandSynchro,1,nil) then\n\t\tlocal mg2=Duel.GetMatchingGroup(Card.IsCanBeSynchroMaterial,tp,LOCATION_HAND,0,nil,syncard)\n\t\tif mg2:GetCount()>0 then mg:Merge(mg2) end\n\tend\n\treturn mg\nend\nfunction Auxiliary.SynMixCondition(f1,f2,f3,f4,minct,maxct,gc)\n\treturn\tfunction(e,c,smat,mg1,min,max)\n\t\t\t\tif c==nil then return true end\n\t\t\t\tif c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end\n\t\t\t\tlocal minc=minct\n\t\t\t\tlocal maxc=maxct\n\t\t\t\tif min then\n\t\t\t\t\tlocal exct=0\n\t\t\t\t\tif f2 then exct=exct+1 end\n\t\t\t\t\tif f3 then exct=exct+1 end\n\t\t\t\t\tif min-exct>minc then minc=min-exct end\n\t\t\t\t\tif max-exct<maxc then maxc=max-exct end\n\t\t\t\t\tif minc>maxc then return false end\n\t\t\t\tend\n\t\t\t\tlocal tp=c:GetControler()\n\t\t\t\tif Duel.IsPlayerAffectedByEffect(tp,8173184) then\n\t\t\t\t\tDuel.RegisterFlagEffect(tp,8173184+1,0,0,1)\n\t\t\t\tend\n\t\t\t\tif smat and not smat:IsCanBeSynchroMaterial(c) then\n\t\t\t\t\tDuel.ResetFlagEffect(tp,8173184+1)\n\t\t\t\t\treturn false\n\t\t\t\tend\n\t\t\t\tlocal mg\n\t\t\t\tlocal mgchk=false\n\t\t\t\tlocal goalchk=false\n\t\t\t\tif mg1 then\n\t\t\t\t\tmg=mg1:Filter(Card.IsCanBeSynchroMaterial,nil,c)\n\t\t\t\t\tmgchk=true\n\t\t\t\t\tif min and min==max and #mg==#mg1 and #mg==min+1 then\n\t\t\t\t\t\tgoalchk=Auxiliary.SynMixCheckGoal(tp,mg,0,0,c,Group.CreateGroup(),smat,gc,mgchk,goalchk)\n\t\t\t\t\t\tif not goalchk then\n\t\t\t\t\t\t\tDuel.ResetFlagEffect(tp,8173184+1)\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\tend\n\t\t\t\t\tend\n\t\t\t\telse\n\t\t\t\t\tmg=Auxiliary.GetSynMaterials(tp,c)\n\t\t\t\tend\n\t\t\t\tif smat~=nil then mg:AddCard(smat) end\n\t\t\t\tlocal res=mg:IsExists(Auxiliary.SynMixFilter1,1,nil,f1,f2,f3,f4,minc,maxc,c,mg,smat,gc,mgchk,goalchk)\n\t\t\t\tDuel.ResetFlagEffect(tp,8173184+1)\n\t\t\t\treturn res\n\t\t\tend\nend\nfunction Auxiliary.SynMixTarget(f1,f2,f3,f4,minct,maxct,gc)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp,chk,c,smat,mg1,min,max)\n\t\t\t\tlocal minc=minct\n\t\t\t\tlocal maxc=maxct\n\t\t\t\tif min then\n\t\t\t\t\tlocal exct=0\n\t\t\t\t\tif f2 then exct=exct+1 end\n\t\t\t\t\tif f3 then exct=exct+1 end\n\t\t\t\t\tif min-exct>minc then minc=min-exct end\n\t\t\t\t\tif max-exct<maxc then maxc=max-exct end\n\t\t\t\t\tif minc>maxc then return false end\n\t\t\t\tend\n\t\t\t\t::SynMixTargetSelectStart::\n\t\t\t\tif Duel.IsPlayerAffectedByEffect(tp,8173184) then\n\t\t\t\t\tDuel.RegisterFlagEffect(tp,8173184+1,0,0,1)\n\t\t\t\tend\n\t\t\t\tlocal cancel=Duel.IsSummonCancelable()\n\t\t\t\tlocal g=Group.CreateGroup()\n\t\t\t\tlocal mg\n\t\t\t\tlocal mgchk=false\n\t\t\t\tlocal goalchk=false\n\t\t\t\tif mg1 then\n\t\t\t\t\tmg=mg1:Filter(Card.IsCanBeSynchroMaterial,nil,c)\n\t\t\t\t\tmgchk=true\n\t\t\t\t\tif min and min==max and #mg==#mg1 and #mg==min+1 and not cancel then\n\t\t\t\t\t\tg:Merge(mg)\n\t\t\t\t\t\tg:KeepAlive()\n\t\t\t\t\t\te:SetLabelObject(g)\n\t\t\t\t\t\tDuel.ResetFlagEffect(tp,8173184+1)\n\t\t\t\t\t\treturn true\n\t\t\t\t\tend\n\t\t\t\telse\n\t\t\t\t\tmg=Auxiliary.GetSynMaterials(tp,c)\n\t\t\t\tend\n\t\t\t\tif smat~=nil then mg:AddCard(smat) end\n\t\t\t\tlocal c1\n\t\t\t\tlocal c2\n\t\t\t\tlocal c3\n\t\t\t\tlocal g4=Group.CreateGroup()\n\t\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SMATERIAL)\n\t\t\t\tc1=mg:Filter(Auxiliary.SynMixFilter1,nil,f1,f2,f3,f4,minc,maxc,c,mg,smat,gc,mgchk,goalchk):SelectUnselect(g,tp,false,cancel,1,1)\n\t\t\t\tif not c1 then goto SynMixTargetSelectCancel end\n\t\t\t\tg:AddCard(c1)\n\t\t\t\tif f2 then\n\t\t\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SMATERIAL)\n\t\t\t\t\tc2=mg:Filter(Auxiliary.SynMixFilter2,g,f2,f3,f4,minc,maxc,c,mg,smat,c1,gc,mgchk,goalchk):SelectUnselect(g,tp,false,cancel,1,1)\n\t\t\t\t\tif not c2 then goto SynMixTargetSelectCancel end\n\t\t\t\t\tif g:IsContains(c2) then goto SynMixTargetSelectStart end\n\t\t\t\t\tg:AddCard(c2)\n\t\t\t\t\tif f3 then\n\t\t\t\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SMATERIAL)\n\t\t\t\t\t\tc3=mg:Filter(Auxiliary.SynMixFilter3,g,f3,f4,minc,maxc,c,mg,smat,c1,c2,gc,mgchk,goalchk):SelectUnselect(g,tp,false,cancel,1,1)\n\t\t\t\t\t\tif not c3 then goto SynMixTargetSelectCancel end\n\t\t\t\t\t\tif g:IsContains(c3) then goto SynMixTargetSelectStart end\n\t\t\t\t\t\tg:AddCard(c3)\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\t\tfor i=0,maxc-1 do\n\t\t\t\t\tlocal mg2=mg:Clone()\n\t\t\t\t\tif f4 then\n\t\t\t\t\t\tmg2=mg2:Filter(f4,g,c,c1,c2,c3)\n\t\t\t\t\telse\n\t\t\t\t\t\tmg2:Sub(g)\n\t\t\t\t\tend\n\t\t\t\t\tlocal fulltraversal=mg:IsExists(Card.IsHasEffect,1,nil,89818984)\n\t\t\t\t\tlocal cg=mg2:Filter(Auxiliary.SynMixCheckRecursive,g4,tp,g4,mg2,i,minc,maxc,c,g,smat,gc,mgchk,goalchk,fulltraversal)\n\t\t\t\t\tif cg:GetCount()==0 then break end\n\t\t\t\t\tlocal finish=Auxiliary.SynMixCheckGoal(tp,g4,minc,i,c,g,smat,gc,mgchk,goalchk)\n\t\t\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SMATERIAL)\n\t\t\t\t\tlocal c4=cg:SelectUnselect(g+g4,tp,finish,cancel,minc,maxc)\n\t\t\t\t\tif not c4 then\n\t\t\t\t\t\tif finish then break\n\t\t\t\t\t\telse goto SynMixTargetSelectCancel end\n\t\t\t\t\tend\n\t\t\t\t\tif g:IsContains(c4) or g4:IsContains(c4) then goto SynMixTargetSelectStart end\n\t\t\t\t\tg4:AddCard(c4)\n\t\t\t\tend\n\t\t\t\tg:Merge(g4)\n\t\t\t\tif g:GetCount()>0 then\n\t\t\t\t\tg:KeepAlive()\n\t\t\t\t\te:SetLabelObject(g)\n\t\t\t\t\tDuel.ResetFlagEffect(tp,8173184+1)\n\t\t\t\t\treturn true\n\t\t\t\tend\n\t\t\t\t::SynMixTargetSelectCancel::\n\t\t\t\tDuel.ResetFlagEffect(tp,8173184+1)\n\t\t\t\treturn false\n\t\t\tend\nend\nfunction Auxiliary.SynMixOperation(f1,f2,f3,f4,minct,maxct,gc)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp,c,smat,mg,min,max)\n\t\t\t\tlocal g=e:GetLabelObject()\n\t\t\t\tc:SetMaterial(g)\n\t\t\t\tDuel.SendtoGrave(g,REASON_MATERIAL+REASON_SYNCHRO)\n\t\t\t\tg:DeleteGroup()\n\t\t\tend\nend\nfunction Auxiliary.SynMixFilter1(c,f1,f2,f3,f4,minc,maxc,syncard,mg,smat,gc,mgchk,goalchk)\n\treturn (not f1 or f1(c,syncard)) and mg:IsExists(Auxiliary.SynMixFilter2,1,c,f2,f3,f4,minc,maxc,syncard,mg,smat,c,gc,mgchk,goalchk)\nend\nfunction Auxiliary.SynMixFilter2(c,f2,f3,f4,minc,maxc,syncard,mg,smat,c1,gc,mgchk,goalchk)\n\tif f2 then\n\t\treturn f2(c,syncard,c1)\n\t\t\tand (mg:IsExists(Auxiliary.SynMixFilter3,1,Group.FromCards(c1,c),f3,f4,minc,maxc,syncard,mg,smat,c1,c,gc,mgchk,goalchk)\n\t\t\t\tor minc==0 and Auxiliary.SynMixFilter4(c,nil,1,1,syncard,mg,smat,c1,nil,nil,gc,mgchk,goalchk))\n\telse\n\t\treturn mg:IsExists(Auxiliary.SynMixFilter4,1,c1,f4,minc,maxc,syncard,mg,smat,c1,nil,nil,gc,mgchk,goalchk)\n\tend\nend\nfunction Auxiliary.SynMixFilter3(c,f3,f4,minc,maxc,syncard,mg,smat,c1,c2,gc,mgchk,goalchk)\n\tif f3 then\n\t\treturn f3(c,syncard,c1,c2)\n\t\t\tand (mg:IsExists(Auxiliary.SynMixFilter4,1,Group.FromCards(c1,c2,c),f4,minc,maxc,syncard,mg,smat,c1,c2,c,gc,mgchk,goalchk)\n\t\t\t\tor minc==0 and Auxiliary.SynMixFilter4(c,nil,1,1,syncard,mg,smat,c1,c2,nil,gc,mgchk,goalchk))\n\telse\n\t\treturn mg:IsExists(Auxiliary.SynMixFilter4,1,Group.FromCards(c1,c2),f4,minc,maxc,syncard,mg,smat,c1,c2,nil,gc,mgchk,goalchk)\n\tend\nend\nfunction Auxiliary.SynMixFilter4(c,f4,minc,maxc,syncard,mg1,smat,c1,c2,c3,gc,mgchk,goalchk)\n\tif f4 and not f4(c,syncard,c1,c2,c3) then return false end\n\tlocal sg=Group.FromCards(c1,c)\n\tif c2 then sg:AddCard(c2) end\n\tif c3 then sg:AddCard(c3) end\n\tlocal mg=mg1:Clone()\n\tif f4 then\n\t\tmg=mg:Filter(f4,sg,syncard,c1,c2,c3)\n\telse\n\t\tmg:Sub(sg)\n\tend\n\treturn Auxiliary.SynMixCheck(mg,sg,minc-1,maxc-1,syncard,mg1,smat,gc,mgchk,goalchk)\nend\nfunction Auxiliary.SynMixCheck(mg,sg1,minc,maxc,syncard,mg1,smat,gc,mgchk,goalchk)\n\tlocal tp=syncard:GetControler()\n\tlocal sg=Group.CreateGroup()\n\tif minc<=0 and Auxiliary.SynMixCheckGoal(tp,sg1,0,0,syncard,sg,smat,gc,mgchk,goalchk) then return true end\n\tif maxc==0 then return false end\n\tlocal fulltraversal=#mg<=5 or mg1:IsExists(Card.IsHasEffect,1,nil,89818984)\n\treturn mg:IsExists(Auxiliary.SynMixCheckRecursive,1,nil,tp,sg,mg,0,minc,maxc,syncard,sg1,smat,gc,mgchk,goalchk,fulltraversal)\nend\nfunction Auxiliary.SynMixCheckRecursive(c,tp,sg,mg,ct,minc,maxc,syncard,sg1,smat,gc,mgchk,goalchk,fulltraversal)\n\tsg:AddCard(c)\n\tct=ct+1\n\tlocal res=Auxiliary.SynMixCheckGoal(tp,sg,minc,ct,syncard,sg1,smat,gc,mgchk,goalchk)\n\tif not res and ct<maxc\n\t\tand (fulltraversal or not Auxiliary.SynMixCheckPrune(sg,sg1,syncard)) then\n\t\tres=mg:IsExists(Auxiliary.SynMixCheckRecursive,1,sg,tp,sg,mg,ct,minc,maxc,syncard,sg1,smat,gc,mgchk,goalchk,fulltraversal)\n\tend\n\tsg:RemoveCard(c)\n\tct=ct-1\n\treturn res\nend\nfunction Auxiliary.SynMixCheckPrune(sg,sg1,syncard)\n\tlocal g=sg+sg1\n\tlocal sumlv=g:GetSum(Auxiliary.GetMinSynchroLevel,syncard)\n\treturn sumlv>=syncard:GetLevel()\nend\n-- the material is in hand and don't has extra synchro material effect itself\n-- that mean some other tuner added it as material\nfunction Auxiliary.SynMixHandFilter(c,tp,syncard)\n\tif not c:IsLocation(LOCATION_HAND) then return false end\n\tlocal le={c:IsHasEffect(EFFECT_EXTRA_SYNCHRO_MATERIAL,tp)}\n\tfor _,te in pairs(le) do\n\t\tlocal tf=te:GetValue()\n\t\tif Auxiliary.GetValueType(tf)==\"function\" then\n\t\t\tif tf(te,syncard) then return false end\n\t\telse\n\t\t\tif tf~=0 then return false end\n\t\tend\n\tend\n\treturn true\nend\nfunction Auxiliary.SynMixHandCheck(g,tp,syncard)\n\tlocal hg=g:Filter(Auxiliary.SynMixHandFilter,nil,tp,syncard)\n\tlocal hct=hg:GetCount()\n\tif hct>0 then\n\t\tlocal found=false\n\t\tfor c in Auxiliary.Next(g) do\n\t\t\tlocal he,hf,hmin,hmax=c:GetHandSynchro()\n\t\t\tif he then\n\t\t\t\tfound=true\n\t\t\t\tif hf and hg:IsExists(Auxiliary.SynLimitFilter,1,c,hf,he,syncard) then return false end\n\t\t\t\tif (hmin and hct<hmin) or (hmax and hct>hmax) then return false end\n\t\t\tend\n\t\tend\n\t\tif not found then return false end\n\tend\n\treturn true\nend\nfunction Auxiliary.SynMixCheckGoal(tp,sg,minc,ct,syncard,sg1,smat,gc,mgchk,goalchk)\n\tif goalchk then return true end\n\tif ct<minc then return false end\n\tlocal g=sg+sg1\n\tif Duel.GetLocationCountFromEx(tp,tp,g,syncard)<=0 then return false end\n\tif gc and not gc(g,syncard,tp) then return false end\n\tif smat and not g:IsContains(smat) then return false end\n\tif not Auxiliary.MustMaterialCheck(g,tp,EFFECT_MUST_BE_SMATERIAL) then return false end\n\tif Duel.IsPlayerAffectedByEffect(tp,8173184)\n\t\tand not g:IsExists(Auxiliary.Tuner(Card.IsSetCard,0x2),1,nil,syncard) then return false end\n\tif not g:CheckWithSumEqual(Card.GetSynchroLevel,syncard:GetLevel(),g:GetCount(),g:GetCount(),syncard)\n\t\tand (not g:IsExists(Card.IsHasEffect,1,nil,89818984)\n\t\tor not g:CheckWithSumEqual(Auxiliary.GetSynchroLevelFlowerCardian,syncard:GetLevel(),g:GetCount(),g:GetCount(),syncard))\n\t\tthen return false end\n\tif not (mgchk or Auxiliary.SynMixHandCheck(g,tp,syncard)) then return false end\n\tfor c in Auxiliary.Next(g) do\n\t\tlocal le,lf,lloc,lmin,lmax=c:GetTunerLimit()\n\t\tif le then\n\t\t\tlocal lct=g:GetCount()-1\n\t\t\tif lloc then\n\t\t\t\tlocal llct=g:FilterCount(Card.IsLocation,c,lloc)\n\t\t\t\tif llct~=lct then return false end\n\t\t\tend\n\t\t\tif lf and g:IsExists(Auxiliary.SynLimitFilter,1,c,lf,le,syncard) then return false end\n\t\t\tif (lmin and lct<lmin) or (lmax and lct>lmax) then return false end\n\t\tend\n\tend\n\treturn true\nend\n--Checking Tune Magician\nfunction Auxiliary.TuneMagicianFilter(c,e)\n\tlocal f=e:GetValue()\n\treturn f(e,c)\nend\nfunction Auxiliary.TuneMagicianCheckX(c,sg,ecode)\n\tlocal eset={c:IsHasEffect(ecode)}\n\tfor _,te in pairs(eset) do\n\t\tif sg:IsExists(Auxiliary.TuneMagicianFilter,1,c,te) then return true end\n\tend\n\treturn false\nend\nfunction Auxiliary.TuneMagicianCheckAdditionalXyz(g)\n\treturn not g:IsExists(Auxiliary.TuneMagicianCheckX,1,nil,g,EFFECT_TUNE_MAGICIAN_X)\nend\n--deprecated, use plain function instead of this factory\nfunction Auxiliary.TuneMagicianCheckAdditionalX(ecode)\n\treturn\tfunction(g)\n\t\t\t\treturn not g:IsExists(Auxiliary.TuneMagicianCheckX,1,nil,g,ecode)\n\t\t\tend\nend\nfunction Auxiliary.SynGroupCheckLevelAddition(syncard)\n\treturn\tfunction(g)\n\t\t\t\tlocal sumlv=g:GetSum(Auxiliary.GetMinSynchroLevel,syncard)\n\t\t\t\treturn sumlv<=syncard:GetLevel()\n\t\t\tend\nend\n\n--Xyz Summon\nfunction Auxiliary.XyzAlterFilter(c,alterf,xyzc,e,tp,alterop)\n\treturn alterf(c,e,tp,xyzc) and c:IsCanBeXyzMaterial(xyzc) and Duel.GetLocationCountFromEx(tp,tp,c,xyzc)>0\n\t\tand not c:IsHasEffect(EFFECT_XYZ_MIN_COUNT)\n\t\tand Auxiliary.MustMaterialCheck(c,tp,EFFECT_MUST_BE_XMATERIAL) and (not alterop or alterop(e,tp,0,c))\nend\n---Xyz monster, lv k*n\n---@param c Card\n---@param f function|nil\n---@param lv integer\n---@param ct integer\n---@param alterf? function\n---@param alterdesc? string\n---@param maxct? integer\n---@param alterop? function\nfunction Auxiliary.AddXyzProcedure(c,f,lv,ct,alterf,alterdesc,maxct,alterop)\n\tif not maxct then maxct=ct end\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(1165)\n\te1:SetType(EFFECT_TYPE_FIELD)\n\te1:SetCode(EFFECT_SPSUMMON_PROC)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)\n\te1:SetRange(LOCATION_EXTRA)\n\te1:SetCondition(Auxiliary.XyzCondition(f,lv,ct,maxct,alterf,alterdesc,alterop))\n\te1:SetTarget(Auxiliary.XyzTarget(f,lv,ct,maxct,alterf,alterdesc,alterop))\n\te1:SetOperation(Auxiliary.XyzOperation(f,lv,ct,maxct,alterf,alterdesc,alterop))\n\te1:SetValue(SUMMON_TYPE_XYZ)\n\tc:RegisterEffect(e1)\nend\nfunction Auxiliary.XyzCondition(f,lv,minct,maxct,alterf,alterdesc,alterop)\n\treturn\tfunction(e,c,og,min,max)\n\t\t\t\tif c==nil then return true end\n\t\t\t\tif c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end\n\t\t\t\tlocal tp=c:GetControler()\n\t\t\t\tlocal mg=nil\n\t\t\t\tif og then\n\t\t\t\t\tmg=og\n\t\t\t\telse\n\t\t\t\t\tmg=Duel.GetFieldGroup(tp,LOCATION_MZONE,0)\n\t\t\t\tend\n\t\t\t\tif alterf and (not min or min<=1) then\n\t\t\t\t\tif mg:IsExists(Auxiliary.XyzAlterFilter,1,nil,alterf,c,e,tp,alterop) then\n\t\t\t\t\t\treturn true\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\t\tlocal minc=minct\n\t\t\t\tlocal maxc=maxct\n\t\t\t\tif min then\n\t\t\t\t\tif min>minc then minc=min end\n\t\t\t\t\tif max<maxc then maxc=max end\n\t\t\t\tend\n\t\t\t\tif minct>=3 and mg:IsExists(Auxiliary.Xyz2XMaterialEffectFilter,1,nil,c,lv,f,tp) then\n\t\t\t\t\treturn Auxiliary.CheckXyz2XMaterial(c,f,lv,minc,maxc,mg)\n\t\t\t\telse\n\t\t\t\t\tif minc>maxc then return false end\n\t\t\t\t\treturn Duel.CheckXyzMaterial(c,f,lv,minc,maxc,og)\n\t\t\t\tend\n\t\t\tend\nend\nfunction Auxiliary.Xyz2XMaterialFilter(c,xyzc,lv,f)\n\treturn c:IsFaceupEx() and c:IsCanBeXyzMaterial(xyzc) and c:IsXyzLevel(xyzc,lv) and (not f or f(c,xyzc))\nend\nfunction Auxiliary.Xyz2XMaterialEffectFilter(c,xyzc,lv,f,tp,checked)\n\tif not checked and not Auxiliary.Xyz2XMaterialFilter(c,xyzc,lv,f) then return false end\n\tlocal e=c:IsHasEffect(EFFECT_DOUBLE_XMATERIAL,tp)\n\tif not e then return false end\n\tlocal tg=e:GetTarget()\n\tif tg and not tg(e,xyzc,tp) then return false end\n\treturn true\nend\nfunction Auxiliary.Xyz2XMaterialGoal(g,tp,xyzc,minc)\n\tif Duel.GetLocationCountFromEx(tp,tp,g,xyzc)<=0 then return false end\n\tlocal lg=g:Filter(Card.IsHasEffect,nil,EFFECT_XYZ_MIN_COUNT,tp)\n\tfor c in Auxiliary.Next(lg) do\n\t\tlocal le=c:IsHasEffect(EFFECT_XYZ_MIN_COUNT)\n\t\tlocal ct=le:GetValue()\n\t\tif #g<ct then return false end\n\tend\n\tlocal ct2=0\n\tlocal limit_table={}\n\tfor c in Auxiliary.Next(g) do\n\t\tlocal le=c:IsHasEffect(EFFECT_DOUBLE_XMATERIAL,tp)\n\t\tif le then\n\t\t\tlocal tg=le:GetTarget()\n\t\t\tlocal limit_value=le:GetValue() -- not fully implemented: assuming Hard once per turn effects\n\t\t\tif (not tg or tg(le,xyzc,tp)) and (not limit_value or not limit_table[limit_value]) then\n\t\t\t\tct2=ct2+1\n\t\t\t\tif limit_value then\n\t\t\t\t\tlimit_table[limit_value]=true\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\tend\n\treturn #g+ct2>=minc\nend\nfunction Auxiliary.CheckXyz2XMaterial(c,f,lv,minc,maxc,mg)\n\tlocal tp=c:GetControler()\n\tmg=mg:Filter(Auxiliary.Xyz2XMaterialFilter,nil,c,lv,f)\n\tlocal sg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_XMATERIAL)\n\tif sg:IsExists(Auxiliary.MustMaterialCounterFilter,1,nil,mg) then return false end\n\tDuel.SetSelectedCard(sg)\n\tAuxiliary.GCheckAdditional=Auxiliary.TuneMagicianCheckAdditionalXyz\n\tlocal res=mg:CheckSubGroup(Auxiliary.Xyz2XMaterialGoal,2,maxc,tp,c,minc)\n\tAuxiliary.GCheckAdditional=nil\n\treturn res\nend\nfunction Auxiliary.XyzTarget(f,lv,minct,maxct,alterf,alterdesc,alterop)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp,chk,c,og,min,max)\n\t\t\t\tif og and not min then\n\t\t\t\t\treturn true\n\t\t\t\tend\n\t\t\t\tlocal minc=minct\n\t\t\t\tlocal maxc=maxct\n\t\t\t\tif min then\n\t\t\t\t\tif min>minc then minc=min end\n\t\t\t\t\tif max<maxc then maxc=max end\n\t\t\t\tend\n\t\t\t\tlocal b1=true\n\t\t\t\tlocal b2=false\n\t\t\t\tlocal altg=nil\n\t\t\t\tlocal mg=nil\n\t\t\t\tif og then\n\t\t\t\t\tmg=og\n\t\t\t\telse\n\t\t\t\t\tmg=Duel.GetFieldGroup(tp,LOCATION_MZONE,0)\n\t\t\t\tend\n\t\t\t\tif alterf and (not min or min<=1) then\n\t\t\t\t\taltg=mg:Filter(Auxiliary.XyzAlterFilter,nil,alterf,c,e,tp,alterop)\n\t\t\t\t\tif minct>=3 and mg:IsExists(Auxiliary.Xyz2XMaterialEffectFilter,1,nil,c,lv,f,tp) then\n\t\t\t\t\t\tb1=Auxiliary.CheckXyz2XMaterial(c,f,lv,minc,maxc,mg)\n\t\t\t\t\telse\n\t\t\t\t\t\tb1=Duel.CheckXyzMaterial(c,f,lv,minc,maxc,og)\n\t\t\t\t\tend\n\t\t\t\t\tb2=#altg>0\n\t\t\t\tend\n\t\t\t\tlocal g=nil\n\t\t\t\tif b2 and (not b1 or Duel.SelectYesNo(tp,alterdesc)) then\n\t\t\t\t\te:SetLabel(1)\n\t\t\t\t\tlocal cancel=Duel.IsSummonCancelable()\n\t\t\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_XMATERIAL)\n\t\t\t\t\tlocal tc=altg:SelectUnselect(nil,tp,false,cancel,1,1)\n\t\t\t\t\tif tc then\n\t\t\t\t\t\tg=Group.FromCards(tc)\n\t\t\t\t\t\tif alterop then alterop(e,tp,1,tc) end\n\t\t\t\t\tend\n\t\t\t\telse\n\t\t\t\t\te:SetLabel(0)\n\t\t\t\t\tif minct>=3 and mg:IsExists(Auxiliary.Xyz2XMaterialEffectFilter,1,nil,c,lv,f,tp) then\n\t\t\t\t\t\tmg=mg:Filter(Auxiliary.Xyz2XMaterialFilter,nil,c,lv,f)\n\t\t\t\t\t\tlocal cancel=Duel.IsSummonCancelable()\n\t\t\t\t\t\tlocal sg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_XMATERIAL)\n\t\t\t\t\t\tDuel.SetSelectedCard(sg)\n\t\t\t\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_XMATERIAL)\n\t\t\t\t\t\tAuxiliary.GCheckAdditional=Auxiliary.TuneMagicianCheckAdditionalXyz\n\t\t\t\t\t\tg=mg:SelectSubGroup(tp,Auxiliary.Xyz2XMaterialGoal,cancel,2,maxc,tp,c,minc)\n\t\t\t\t\t\tAuxiliary.GCheckAdditional=nil\n\t\t\t\t\telse\n\t\t\t\t\t\tg=Duel.SelectXyzMaterial(tp,c,f,lv,minc,maxc,og)\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\t\tif g then\n\t\t\t\t\tg:KeepAlive()\n\t\t\t\t\te:SetLabelObject(g)\n\t\t\t\t\treturn true\n\t\t\t\telse return false end\n\t\t\tend\nend\nfunction Auxiliary.XyzOperation(f,lv,minct,maxct,alterf,alterdesc,alterop)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp,c,og,min,max)\n\t\t\t\tif og and not min then\n\t\t\t\t\tAuxiliary.Xyz2XMaterialOperation(tp,og,c,minct,maxct)\n\t\t\t\t\tlocal sg=Group.CreateGroup()\n\t\t\t\t\tlocal tc=og:GetFirst()\n\t\t\t\t\twhile tc do\n\t\t\t\t\t\tlocal sg1=tc:GetOverlayGroup()\n\t\t\t\t\t\tsg:Merge(sg1)\n\t\t\t\t\t\ttc=og:GetNext()\n\t\t\t\t\tend\n\t\t\t\t\tDuel.SendtoGrave(sg,REASON_RULE)\n\t\t\t\t\tc:SetMaterial(og)\n\t\t\t\t\tDuel.Overlay(c,og)\n\t\t\t\telse\n\t\t\t\t\tlocal mg=e:GetLabelObject()\n\t\t\t\t\tif e:GetLabel()==1 then\n\t\t\t\t\t\tlocal mg2=mg:GetFirst():GetOverlayGroup()\n\t\t\t\t\t\tif mg2:GetCount()~=0 then\n\t\t\t\t\t\t\tDuel.Overlay(c,mg2)\n\t\t\t\t\t\tend\n\t\t\t\t\telse\n\t\t\t\t\t\tAuxiliary.Xyz2XMaterialOperation(tp,mg,c,minct,maxct)\n\t\t\t\t\t\tlocal sg=Group.CreateGroup()\n\t\t\t\t\t\tlocal tc=mg:GetFirst()\n\t\t\t\t\t\twhile tc do\n\t\t\t\t\t\t\tlocal sg1=tc:GetOverlayGroup()\n\t\t\t\t\t\t\tsg:Merge(sg1)\n\t\t\t\t\t\t\ttc=mg:GetNext()\n\t\t\t\t\t\tend\n\t\t\t\t\t\tDuel.SendtoGrave(sg,REASON_RULE)\n\t\t\t\t\tend\n\t\t\t\t\tc:SetMaterial(mg)\n\t\t\t\t\tDuel.Overlay(c,mg)\n\t\t\t\t\tmg:DeleteGroup()\n\t\t\t\tend\n\t\t\tend\nend\nfunction Auxiliary.Xyz2XMaterialOperation(tp,mg,xyzc,minct,maxct)\n\tlocal sg=mg:Clone()\n\twhile #sg<minct do\n\t\tlocal g=sg:Filter(Auxiliary.Xyz2XMaterialEffectFilter,nil,xyzc,nil,nil,tp,true)\n\t\tif #g>1 then\n\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_RESOLVECARD)\n\t\t\tg=g:Select(tp,1,1,nil)\n\t\tend\n\t\tlocal tc=g:GetFirst()\n\t\tlocal te=tc:IsHasEffect(EFFECT_DOUBLE_XMATERIAL,tp)\n\t\tDuel.Hint(HINT_CARD,0,tc:GetCode())\n\t\tte:UseCountLimit(tp)\n\t\tsg:RemoveCard(tc)\n\t\tminct=minct-2\n\tend\nend\n---Xyz monster, any condition(level free)\n---@param c Card\n---@param f function|nil\n---@param gf function|nil\n---@param minc integer\n---@param maxc integer\n---@param alterf? function\n---@param alterdesc? string\n---@param alterop? function\nfunction Auxiliary.AddXyzProcedureLevelFree(c,f,gf,minc,maxc,alterf,alterdesc,alterop)\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(1165)\n\te1:SetType(EFFECT_TYPE_FIELD)\n\te1:SetCode(EFFECT_SPSUMMON_PROC)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)\n\te1:SetRange(LOCATION_EXTRA)\n\te1:SetCondition(Auxiliary.XyzLevelFreeCondition(f,gf,minc,maxc,alterf,alterdesc,alterop))\n\te1:SetTarget(Auxiliary.XyzLevelFreeTarget(f,gf,minc,maxc,alterf,alterdesc,alterop))\n\te1:SetOperation(Auxiliary.XyzLevelFreeOperation(f,gf,minc,maxc,alterf,alterdesc,alterop))\n\te1:SetValue(SUMMON_TYPE_XYZ)\n\tc:RegisterEffect(e1)\nend\n-- not fully implemented: EFFECT_DOUBLE_XMATERIAL is not supported\nfunction Auxiliary.XyzLevelFreeFilter(c,xyzc,f)\n\treturn (not c:IsOnField() or c:IsFaceup()) and c:IsCanBeXyzMaterial(xyzc) and (not f or f(c,xyzc))\nend\nfunction Auxiliary.XyzLevelFreeGoal(g,tp,xyzc,gf)\n\tif Duel.GetLocationCountFromEx(tp,tp,g,xyzc)<=0 then return false end\n\tif gf and not gf(g,xyzc,tp) then return false end\n\tlocal lg=g:Filter(Card.IsHasEffect,nil,EFFECT_XYZ_MIN_COUNT)\n\tfor c in Auxiliary.Next(lg) do\n\t\tlocal le=c:IsHasEffect(EFFECT_XYZ_MIN_COUNT)\n\t\tlocal ct=le:GetValue()\n\t\tif #g<ct then return false end\n\tend\n\treturn true\nend\nfunction Auxiliary.XyzLevelFreeCondition(f,gf,minct,maxct,alterf,alterdesc,alterop)\n\treturn\tfunction(e,c,og,min,max)\n\t\t\t\tif c==nil then return true end\n\t\t\t\tif c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end\n\t\t\t\tlocal tp=c:GetControler()\n\t\t\t\tlocal minc=minct\n\t\t\t\tlocal maxc=maxct\n\t\t\t\tif min then\n\t\t\t\t\tif min>minc then minc=min end\n\t\t\t\t\tif max<maxc then maxc=max end\n\t\t\t\tend\n\t\t\t\tif maxc<minc then return false end\n\t\t\t\tlocal mg=nil\n\t\t\t\tif og then\n\t\t\t\t\tmg=og\n\t\t\t\telse\n\t\t\t\t\tmg=Duel.GetFieldGroup(tp,LOCATION_MZONE,0)\n\t\t\t\tend\n\t\t\t\tif alterf and (not min or min<=1) then\n\t\t\t\t\tif mg:IsExists(Auxiliary.XyzAlterFilter,1,nil,alterf,c,e,tp,alterop) then\n\t\t\t\t\t\treturn true\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\t\tmg=mg:Filter(Auxiliary.XyzLevelFreeFilter,nil,c,f)\n\t\t\t\tlocal sg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_XMATERIAL)\n\t\t\t\tif sg:IsExists(Auxiliary.MustMaterialCounterFilter,1,nil,mg) then return false end\n\t\t\t\tDuel.SetSelectedCard(sg)\n\t\t\t\tAuxiliary.GCheckAdditional=Auxiliary.TuneMagicianCheckAdditionalXyz\n\t\t\t\tlocal res=mg:CheckSubGroup(Auxiliary.XyzLevelFreeGoal,minc,maxc,tp,c,gf)\n\t\t\t\tAuxiliary.GCheckAdditional=nil\n\t\t\t\treturn res\n\t\t\tend\nend\nfunction Auxiliary.XyzLevelFreeTarget(f,gf,minct,maxct,alterf,alterdesc,alterop)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp,chk,c,og,min,max)\n\t\t\t\tif og and not min then\n\t\t\t\t\treturn true\n\t\t\t\tend\n\t\t\t\tlocal minc=minct\n\t\t\t\tlocal maxc=maxct\n\t\t\t\tif min then\n\t\t\t\t\tif min>minc then minc=min end\n\t\t\t\t\tif max<maxc then maxc=max end\n\t\t\t\tend\n\t\t\t\tlocal mg=nil\n\t\t\t\tif og then\n\t\t\t\t\tmg=og\n\t\t\t\telse\n\t\t\t\t\tmg=Duel.GetFieldGroup(tp,LOCATION_MZONE,0)\n\t\t\t\tend\n\t\t\t\tlocal b1=true\n\t\t\t\tlocal b2=false\n\t\t\t\tlocal altg=nil\n\t\t\t\tlocal sg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_XMATERIAL)\n\t\t\t\tif alterf and (not min or min<=1) then\n\t\t\t\t\taltg=mg:Filter(Auxiliary.XyzAlterFilter,nil,alterf,c,e,tp,alterop)\n\t\t\t\t\tmg=mg:Filter(Auxiliary.XyzLevelFreeFilter,nil,c,f)\n\t\t\t\t\tDuel.SetSelectedCard(sg)\n\t\t\t\t\tAuxiliary.GCheckAdditional=Auxiliary.TuneMagicianCheckAdditionalXyz\n\t\t\t\t\tb1=mg:CheckSubGroup(Auxiliary.XyzLevelFreeGoal,minc,maxc,tp,c,gf)\n\t\t\t\t\tAuxiliary.GCheckAdditional=nil\n\t\t\t\t\tb2=#altg>0\n\t\t\t\telse\n\t\t\t\t\tmg=mg:Filter(Auxiliary.XyzLevelFreeFilter,nil,c,f)\n\t\t\t\tend\n\t\t\t\tlocal g=nil\n\t\t\t\tlocal cancel=Duel.IsSummonCancelable()\n\t\t\t\tif b2 and (not b1 or Duel.SelectYesNo(tp,alterdesc)) then\n\t\t\t\t\te:SetLabel(1)\n\t\t\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_XMATERIAL)\n\t\t\t\t\tlocal tc=altg:SelectUnselect(nil,tp,false,cancel,1,1)\n\t\t\t\t\tif tc then\n\t\t\t\t\t\tg=Group.FromCards(tc)\n\t\t\t\t\t\tif alterop then alterop(e,tp,1,tc) end\n\t\t\t\t\tend\n\t\t\t\telse\n\t\t\t\t\te:SetLabel(0)\n\t\t\t\t\tDuel.SetSelectedCard(sg)\n\t\t\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_XMATERIAL)\n\t\t\t\t\tAuxiliary.GCheckAdditional=Auxiliary.TuneMagicianCheckAdditionalXyz\n\t\t\t\t\tg=mg:SelectSubGroup(tp,Auxiliary.XyzLevelFreeGoal,cancel,minc,maxc,tp,c,gf)\n\t\t\t\t\tAuxiliary.GCheckAdditional=nil\n\t\t\t\tend\n\t\t\t\tif g and g:GetCount()>0 then\n\t\t\t\t\tg:KeepAlive()\n\t\t\t\t\te:SetLabelObject(g)\n\t\t\t\t\treturn true\n\t\t\t\telse return false end\n\t\t\tend\nend\nfunction Auxiliary.XyzLevelFreeOperation(f,gf,minct,maxct,alterf,alterdesc,alterop)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp,c,og,min,max)\n\t\t\t\tif og and not min then\n\t\t\t\t\tlocal sg=Group.CreateGroup()\n\t\t\t\t\tlocal tc=og:GetFirst()\n\t\t\t\t\twhile tc do\n\t\t\t\t\t\tlocal sg1=tc:GetOverlayGroup()\n\t\t\t\t\t\tsg:Merge(sg1)\n\t\t\t\t\t\ttc=og:GetNext()\n\t\t\t\t\tend\n\t\t\t\t\tDuel.SendtoGrave(sg,REASON_RULE)\n\t\t\t\t\tc:SetMaterial(og)\n\t\t\t\t\tDuel.Overlay(c,og)\n\t\t\t\telse\n\t\t\t\t\tlocal mg=e:GetLabelObject()\n\t\t\t\t\tif e:GetLabel()==1 then\n\t\t\t\t\t\tlocal mg2=mg:GetFirst():GetOverlayGroup()\n\t\t\t\t\t\tif mg2:GetCount()~=0 then\n\t\t\t\t\t\t\tDuel.Overlay(c,mg2)\n\t\t\t\t\t\tend\n\t\t\t\t\telse\n\t\t\t\t\t\tlocal sg=Group.CreateGroup()\n\t\t\t\t\t\tlocal tc=mg:GetFirst()\n\t\t\t\t\t\twhile tc do\n\t\t\t\t\t\t\tlocal sg1=tc:GetOverlayGroup()\n\t\t\t\t\t\t\tsg:Merge(sg1)\n\t\t\t\t\t\t\ttc=mg:GetNext()\n\t\t\t\t\t\tend\n\t\t\t\t\t\tDuel.SendtoGrave(sg,REASON_RULE)\n\t\t\t\t\tend\n\t\t\t\t\tc:SetMaterial(mg)\n\t\t\t\t\tDuel.Overlay(c,mg)\n\t\t\t\t\tmg:DeleteGroup()\n\t\t\t\tend\n\t\t\tend\nend\n\n--Fusion Summon\n\n---Fusion monster, mixed materials (fixed count)\n---@param fcard Card\n---@param sub boolean Can be fusion summoned with substitute material\n---@param insf boolean Can be fusion summoned with no material (Instant Fusion)\n---@param ... number|function|table\nfunction Auxiliary.AddFusionProcMix(fcard,sub,insf,...)\n\tif fcard:IsStatus(STATUS_COPYING_EFFECT) then return end\n\tlocal val={...}\n\tlocal fun={}\n\tlocal mat={}\n\tfor i=1,#val do\n\t\tif type(val[i])=='function' then\n\t\t\tfun[i]=function(c,fc,subm,mg,sg) return val[i](c,fc,subm,mg,sg) and not c:IsHasEffect(6205579) end\n\t\telseif type(val[i])=='table' then\n\t\t\tfun[i]=function(c,fc,subm,mg,sg)\n\t\t\t\t\tfor _,fcode in ipairs(val[i]) do\n\t\t\t\t\t\tif type(fcode)=='function' then\n\t\t\t\t\t\t\tif fcode(c,fc,subm,mg,sg) and not c:IsHasEffect(6205579) then return true end\n\t\t\t\t\t\telseif type(fcode)=='number' then\n\t\t\t\t\t\t\tif c:IsFusionCode(fcode) or (subm and c:CheckFusionSubstitute(fc)) then return true end\n\t\t\t\t\t\tend\n\t\t\t\t\tend\n\t\t\t\t\treturn false\n\t\t\tend\n\t\t\tfor _,fcode in ipairs(val[i]) do\n\t\t\t\tif type(fcode)=='number' then mat[fcode]=true end\n\t\t\tend\n\t\telseif type(val[i])=='number' then\n\t\t\tfun[i]=function(c,fc,subm) return c:IsFusionCode(val[i]) or (subm and c:CheckFusionSubstitute(fc)) end\n\t\t\tmat[val[i]]=true\n\t\tend\n\tend\n\tlocal mt=getmetatable(fcard)\n\tif mt.material==nil then\n\t\tmt.material=mat\n\tend\n\tif mt.material_count==nil then\n\t\tmt.material_count={#fun,#fun}\n\tend\n\tfor index,_ in pairs(mat) do\n\t\tAuxiliary.AddCodeList(fcard,index)\n\tend\n\tlocal e1=Effect.CreateEffect(fcard)\n\te1:SetType(EFFECT_TYPE_SINGLE)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)\n\te1:SetCode(EFFECT_FUSION_MATERIAL)\n\te1:SetCondition(Auxiliary.FConditionMix(insf,sub,table.unpack(fun)))\n\te1:SetOperation(Auxiliary.FOperationMix(insf,sub,table.unpack(fun)))\n\tfcard:RegisterEffect(e1)\nend\nfunction Auxiliary.FConditionMix(insf,sub,...)\n\t--g:Material group(nil for Instant Fusion)\n\t--gc:Material already used\n\t--chkf: check field, default:PLAYER_NONE\n\t--chkf&0x100: Not fusion summon, can use substitute (Hex-Sealed Fusion)\n\t--chkf&0x200: Not fusion summon, can't use substitute (\"Contact Fusion\", Neos Fusion)\n\tlocal funs={...}\n\treturn\tfunction(e,g,gc,chkfnf)\n\t\t\t\tif g==nil then return insf and Auxiliary.MustMaterialCheck(nil,e:GetHandlerPlayer(),EFFECT_MUST_BE_FMATERIAL) end\n\t\t\t\tlocal c=e:GetHandler()\n\t\t\t\tlocal tp=c:GetControler()\n\t\t\t\tlocal hexsealed=chkfnf&0x100>0\n\t\t\t\tlocal notfusion=chkfnf&0x200>0\n\t\t\t\tlocal sub2=(sub or hexsealed) and not notfusion\n\t\t\t\tlocal mg=g:Filter(Auxiliary.FConditionFilterMix,c,c,sub2,notfusion,table.unpack(funs))\n\t\t\t\tif gc then\n\t\t\t\t\tif not mg:IsContains(gc) then return false end\n\t\t\t\t\tDuel.SetSelectedCard(gc)\n\t\t\t\tend\n\t\t\t\treturn mg:CheckSubGroup(Auxiliary.FCheckMixGoal,#funs,#funs,tp,c,sub2,chkfnf,table.unpack(funs))\n\t\t\tend\nend\nfunction Auxiliary.FOperationMix(insf,sub,...)\n\tlocal funs={...}\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp,gc,chkfnf)\n\t\t\t\tlocal c=e:GetHandler()\n\t\t\t\tlocal hexsealed=chkfnf&0x100>0\n\t\t\t\tlocal notfusion=chkfnf&0x200>0\n\t\t\t\tlocal sub2=(sub or hexsealed) and not notfusion\n\t\t\t\tlocal cancel=notfusion and Duel.GetCurrentChain()==0\n\t\t\t\tlocal mg=eg:Filter(Auxiliary.FConditionFilterMix,c,c,sub2,notfusion,table.unpack(funs))\n\t\t\t\tif gc then Duel.SetSelectedCard(gc) end\n\t\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_FMATERIAL)\n\t\t\t\tlocal sg=mg:SelectSubGroup(tp,Auxiliary.FCheckMixGoal,cancel,#funs,#funs,tp,c,sub2,chkfnf,table.unpack(funs))\n\t\t\t\tif sg then\n\t\t\t\t\tDuel.SetFusionMaterial(sg)\n\t\t\t\telse\n\t\t\t\t\tDuel.SetFusionMaterial(Group.CreateGroup())\n\t\t\t\tend\n\t\t\tend\nend\nfunction Auxiliary.FConditionFilterMix(c,fc,sub,notfusion,...)\n\tlocal check_type=notfusion and SUMMON_TYPE_SPECIAL or SUMMON_TYPE_FUSION\n\tif not c:IsCanBeFusionMaterial(fc,check_type) then return false end\n\tfor i,f in ipairs({...}) do\n\t\tif f(c,fc,sub) then return true end\n\tend\n\treturn false\nend\nfunction Auxiliary.FCheckMix(c,mg,sg,fc,sub,fun1,fun2,...)\n\tif fun2 then\n\t\tsg:AddCard(c)\n\t\tlocal res=false\n\t\tif fun1(c,fc,false,mg,sg) then\n\t\t\tres=mg:IsExists(Auxiliary.FCheckMix,1,sg,mg,sg,fc,sub,fun2,...)\n\t\telseif sub and fun1(c,fc,true,mg,sg) then\n\t\t\tres=mg:IsExists(Auxiliary.FCheckMix,1,sg,mg,sg,fc,false,fun2,...)\n\t\tend\n\t\tsg:RemoveCard(c)\n\t\treturn res\n\telse\n\t\treturn fun1(c,fc,sub,mg,sg)\n\tend\nend\n--if sg1 is subset of sg2 then not Auxiliary.FCheckAdditional(tp,sg1,fc) -> not Auxiliary.FCheckAdditional(tp,sg2,fc)\nfunction Auxiliary.FCheckMixGoal(sg,tp,fc,sub,chkfnf,...)\n\tlocal chkf=chkfnf&0xff\n\tlocal not_fusion=chkfnf&(0x100|0x200)>0\n\tif not not_fusion and sg:IsExists(Auxiliary.TuneMagicianCheckX,1,nil,sg,EFFECT_TUNE_MAGICIAN_F) then return false end\n\tif not Auxiliary.MustMaterialCheck(sg,tp,EFFECT_MUST_BE_FMATERIAL) then return false end\n\tlocal g=Group.CreateGroup()\n\treturn sg:IsExists(Auxiliary.FCheckMix,1,nil,sg,g,fc,sub,...) and (chkf==PLAYER_NONE or Duel.GetLocationCountFromEx(tp,tp,sg,fc)>0)\n\t\tand (not Auxiliary.FCheckAdditional or Auxiliary.FCheckAdditional(tp,sg,fc))\n\t\tand (not Auxiliary.FGoalCheckAdditional or Auxiliary.FGoalCheckAdditional(tp,sg,fc))\nend\n\n---Fusion monster, mixed material * minc to maxc + material + ...\n---@param fcard Card\n---@param sub boolean Can be fusion summoned with substitute material\n---@param insf boolean Can be fusion summoned with no material (Instant Fusion)\n---@param fun1 number|function|table\n---@param minc integer\n---@param maxc integer\n---@param ... number|function|table\nfunction Auxiliary.AddFusionProcMixRep(fcard,sub,insf,fun1,minc,maxc,...)\n\tif fcard:IsStatus(STATUS_COPYING_EFFECT) then return end\n\tlocal val={fun1,...}\n\tlocal fun={}\n\tlocal mat={}\n\tfor i=1,#val do\n\t\tif type(val[i])=='function' then\n\t\t\tfun[i]=function(c,fc,subm) return val[i](c,fc,subm) and not c:IsHasEffect(6205579) end\n\t\telseif type(val[i])=='table' then\n\t\t\tfun[i]=function(c,fc,subm)\n\t\t\t\t\tfor _,fcode in ipairs(val[i]) do\n\t\t\t\t\t\tif type(fcode)=='function' then\n\t\t\t\t\t\t\tif fcode(c,fc,subm) and not c:IsHasEffect(6205579) then return true end\n\t\t\t\t\t\telseif type(fcode)=='number' then\n\t\t\t\t\t\t\tif c:IsFusionCode(fcode) or (subm and c:CheckFusionSubstitute(fc)) then return true end\n\t\t\t\t\t\tend\n\t\t\t\t\tend\n\t\t\t\t\treturn false\n\t\t\tend\n\t\t\tfor _,fcode in ipairs(val[i]) do\n\t\t\t\tif type(fcode)=='number' then mat[fcode]=true end\n\t\t\tend\n\t\telseif type(val[i])=='number' then\n\t\t\tfun[i]=function(c,fc,subm) return c:IsFusionCode(val[i]) or (subm and c:CheckFusionSubstitute(fc)) end\n\t\t\tmat[val[i]]=true\n\t\tend\n\tend\n\tlocal mt=getmetatable(fcard)\n\tif mt.material==nil then\n\t\tmt.material=mat\n\tend\n\tif mt.material_count==nil then\n\t\tmt.material_count={#fun+minc-1,#fun+maxc-1}\n\tend\n\tfor index,_ in pairs(mat) do\n\t\tAuxiliary.AddCodeList(fcard,index)\n\tend\n\tlocal e1=Effect.CreateEffect(fcard)\n\te1:SetType(EFFECT_TYPE_SINGLE)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)\n\te1:SetCode(EFFECT_FUSION_MATERIAL)\n\te1:SetCondition(Auxiliary.FConditionMixRep(insf,sub,fun[1],minc,maxc,table.unpack(fun,2)))\n\te1:SetOperation(Auxiliary.FOperationMixRep(insf,sub,fun[1],minc,maxc,table.unpack(fun,2)))\n\tfcard:RegisterEffect(e1)\nend\nfunction Auxiliary.FConditionMixRep(insf,sub,fun1,minc,maxc,...)\n\tlocal funs={...}\n\treturn\tfunction(e,g,gc,chkfnf)\n\t\t\t\tif g==nil then return insf and Auxiliary.MustMaterialCheck(nil,e:GetHandlerPlayer(),EFFECT_MUST_BE_FMATERIAL) end\n\t\t\t\tlocal c=e:GetHandler()\n\t\t\t\tlocal tp=c:GetControler()\n\t\t\t\tlocal hexsealed=chkfnf&0x100>0\n\t\t\t\tlocal notfusion=chkfnf&0x200>0\n\t\t\t\tlocal sub2=(sub or hexsealed) and not notfusion\n\t\t\t\tlocal mg=g:Filter(Auxiliary.FConditionFilterMix,c,c,sub2,notfusion,fun1,table.unpack(funs))\n\t\t\t\tif gc then\n\t\t\t\t\tif not mg:IsContains(gc) then return false end\n\t\t\t\t\tlocal sg=Group.CreateGroup()\n\t\t\t\t\treturn Auxiliary.FSelectMixRep(gc,tp,mg,sg,c,sub2,chkfnf,fun1,minc,maxc,table.unpack(funs))\n\t\t\t\tend\n\t\t\t\tlocal sg=Group.CreateGroup()\n\t\t\t\treturn mg:IsExists(Auxiliary.FSelectMixRep,1,nil,tp,mg,sg,c,sub2,chkfnf,fun1,minc,maxc,table.unpack(funs))\n\t\t\tend\nend\nfunction Auxiliary.FOperationMixRep(insf,sub,fun1,minc,maxc,...)\n\tlocal funs={...}\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp,gc,chkfnf)\n\t\t\t\tlocal c=e:GetHandler()\n\t\t\t\tlocal tp=c:GetControler()\n\t\t\t\tlocal hexsealed=chkfnf&0x100>0\n\t\t\t\tlocal notfusion=chkfnf&0x200>0\n\t\t\t\tlocal sub2=(sub or hexsealed) and not notfusion\n\t\t\t\tlocal cancel=notfusion and Duel.GetCurrentChain()==0\n\t\t\t\tlocal mg=eg:Filter(Auxiliary.FConditionFilterMix,c,c,sub2,notfusion,fun1,table.unpack(funs))\n\t\t\t\tlocal sg=Group.CreateGroup()\n\t\t\t\tif gc then sg:AddCard(gc) end\n\t\t\t\twhile sg:GetCount()<maxc+#funs do\n\t\t\t\t\tlocal cg=mg:Filter(Auxiliary.FSelectMixRep,sg,tp,mg,sg,c,sub2,chkfnf,fun1,minc,maxc,table.unpack(funs))\n\t\t\t\t\tif cg:GetCount()==0 then break end\n\t\t\t\t\tlocal finish=Auxiliary.FCheckMixRepGoal(tp,sg,c,sub2,chkfnf,fun1,minc,maxc,table.unpack(funs))\n\t\t\t\t\tlocal cancel_group=sg:Clone()\n\t\t\t\t\tif gc then cancel_group:RemoveCard(gc) end\n\t\t\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_FMATERIAL)\n\t\t\t\t\tlocal tc=cg:SelectUnselect(cancel_group,tp,finish,cancel,minc+#funs,maxc+#funs)\n\t\t\t\t\tif not tc then\n\t\t\t\t\t\tif not finish then sg:Clear() end\n\t\t\t\t\t\tbreak\n\t\t\t\t\tend\n\t\t\t\t\tif sg:IsContains(tc) then\n\t\t\t\t\t\tsg:RemoveCard(tc)\n\t\t\t\t\telse\n\t\t\t\t\t\tsg:AddCard(tc)\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\t\tDuel.SetFusionMaterial(sg)\n\t\t\tend\nend\nfunction Auxiliary.FCheckMixRep(sg,g,fc,sub,chkf,fun1,minc,maxc,fun2,...)\n\tif fun2 then\n\t\treturn sg:IsExists(Auxiliary.FCheckMixRepFilter,1,g,sg,g,fc,sub,chkf,fun1,minc,maxc,fun2,...)\n\telse\n\t\tlocal ct1=sg:FilterCount(fun1,g,fc,sub)\n\t\tlocal ct2=sg:FilterCount(fun1,g,fc,false)\n\t\treturn ct1==sg:GetCount()-g:GetCount() and ct1-ct2<=1\n\tend\nend\nfunction Auxiliary.FCheckMixRepFilter(c,sg,g,fc,sub,chkf,fun1,minc,maxc,fun2,...)\n\tif fun2(c,fc,sub) then\n\t\tg:AddCard(c)\n\t\tsub=sub and fun2(c,fc,false)\n\t\tlocal res=Auxiliary.FCheckMixRep(sg,g,fc,sub,chkf,fun1,minc,maxc,...)\n\t\tg:RemoveCard(c)\n\t\treturn res\n\tend\n\treturn false\nend\nfunction Auxiliary.FCheckMixRepGoalCheck(tp,sg,fc,chkfnf)\n\tlocal not_fusion=chkfnf&(0x100|0x200)>0\n\tif not not_fusion and sg:IsExists(Auxiliary.TuneMagicianCheckX,1,nil,sg,EFFECT_TUNE_MAGICIAN_F) then return false end\n\tif not Auxiliary.MustMaterialCheck(sg,tp,EFFECT_MUST_BE_FMATERIAL) then return false end\n\tif Auxiliary.FGoalCheckAdditional and not Auxiliary.FGoalCheckAdditional(tp,sg,fc) then return false end\n\treturn true\nend\nfunction Auxiliary.FCheckMixRepGoal(tp,sg,fc,sub,chkfnf,fun1,minc,maxc,...)\n\tlocal chkf=chkfnf&0xff\n\tif sg:GetCount()<minc+#{...} or sg:GetCount()>maxc+#{...} then return false end\n\tif not (chkf==PLAYER_NONE or Duel.GetLocationCountFromEx(tp,tp,sg,fc)>0) then return false end\n\tif Auxiliary.FCheckAdditional and not Auxiliary.FCheckAdditional(tp,sg,fc) then return false end\n\tif not Auxiliary.FCheckMixRepGoalCheck(tp,sg,fc,chkfnf) then return false end\n\tlocal g=Group.CreateGroup()\n\treturn Auxiliary.FCheckMixRep(sg,g,fc,sub,chkf,fun1,minc,maxc,...)\nend\nfunction Auxiliary.FCheckMixRepTemplate(c,cond,tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,...)\n\tfor i,f in ipairs({...}) do\n\t\tif f(c,fc,sub) then\n\t\t\tg:AddCard(c)\n\t\t\tlocal subf=sub and f(c,fc,false)\n\t\t\tlocal t={...}\n\t\t\ttable.remove(t,i)\n\t\t\tlocal res=cond(tp,mg,sg,g,fc,subf,chkfnf,fun1,minc,maxc,table.unpack(t))\n\t\t\tg:RemoveCard(c)\n\t\t\tif res then return true end\n\t\tend\n\tend\n\tif maxc>0 then\n\t\tif fun1(c,fc,sub) then\n\t\t\tg:AddCard(c)\n\t\t\tlocal subf1=sub and fun1(c,fc,false)\n\t\t\tlocal res=cond(tp,mg,sg,g,fc,subf1,chkfnf,fun1,minc-1,maxc-1,...)\n\t\t\tg:RemoveCard(c)\n\t\t\tif res then return true end\n\t\tend\n\tend\n\treturn false\nend\nfunction Auxiliary.FCheckMixRepSelectedCond(tp,mg,sg,g,...)\n\tif g:GetCount()<sg:GetCount() then\n\t\treturn sg:IsExists(Auxiliary.FCheckMixRepSelected,1,g,tp,mg,sg,g,...)\n\telse\n\t\treturn Auxiliary.FCheckSelectMixRep(tp,mg,sg,g,...)\n\tend\nend\nfunction Auxiliary.FCheckMixRepSelected(c,...)\n\treturn Auxiliary.FCheckMixRepTemplate(c,Auxiliary.FCheckMixRepSelectedCond,...)\nend\nfunction Auxiliary.FCheckSelectMixRep(tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,...)\n\tlocal chkf=chkfnf&0xff\n\tif Auxiliary.FCheckAdditional and not Auxiliary.FCheckAdditional(tp,g,fc) then return false end\n\tif chkf==PLAYER_NONE or Duel.GetLocationCountFromEx(tp,tp,g,fc)>0 then\n\t\tif minc<=0 and #{...}==0 and Auxiliary.FCheckMixRepGoalCheck(tp,g,fc,chkfnf) then return true end\n\t\treturn mg:IsExists(Auxiliary.FCheckSelectMixRepAll,1,g,tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,...)\n\telse\n\t\treturn mg:IsExists(Auxiliary.FCheckSelectMixRepM,1,g,tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,...)\n\tend\nend\nfunction Auxiliary.FCheckSelectMixRepAll(c,tp,mg,sg,g,fc,sub,chkf,fun1,minc,maxc,fun2,...)\n\tif fun2 then\n\t\tif fun2(c,fc,sub) then\n\t\t\tg:AddCard(c)\n\t\t\tlocal subf2=sub and fun2(c,fc,false)\n\t\t\tlocal res=Auxiliary.FCheckSelectMixRep(tp,mg,sg,g,fc,subf2,chkf,fun1,minc,maxc,...)\n\t\t\tg:RemoveCard(c)\n\t\t\treturn res\n\t\tend\n\telseif maxc>0 and fun1(c,fc,sub) then\n\t\tg:AddCard(c)\n\t\tlocal subf1=sub and fun1(c,fc,false)\n\t\tlocal res=Auxiliary.FCheckSelectMixRep(tp,mg,sg,g,fc,subf1,chkf,fun1,minc-1,maxc-1)\n\t\tg:RemoveCard(c)\n\t\treturn res\n\tend\n\treturn false\nend\nfunction Auxiliary.FCheckSelectMixRepM(c,tp,...)\n\treturn c:IsControler(tp) and c:IsLocation(LOCATION_MZONE)\n\t\tand Auxiliary.FCheckMixRepTemplate(c,Auxiliary.FCheckSelectMixRep,tp,...)\nend\nfunction Auxiliary.FSelectMixRep(c,tp,mg,sg,fc,sub,chkfnf,...)\n\tsg:AddCard(c)\n\tlocal res=false\n\tif Auxiliary.FCheckAdditional and not Auxiliary.FCheckAdditional(tp,sg,fc) then\n\t\tres=false\n\telseif Auxiliary.FCheckMixRepGoal(tp,sg,fc,sub,chkfnf,...) then\n\t\tres=true\n\telse\n\t\tlocal g=Group.CreateGroup()\n\t\tres=sg:IsExists(Auxiliary.FCheckMixRepSelected,1,nil,tp,mg,sg,g,fc,sub,chkfnf,...)\n\tend\n\tsg:RemoveCard(c)\n\treturn res\nend\n\n---Fusion monster, name + name\n---@param c Card\n---@param code1 integer\n---@param code2 integer\n---@param sub boolean\n---@param insf boolean\nfunction Auxiliary.AddFusionProcCode2(c,code1,code2,sub,insf)\n\tAuxiliary.AddFusionProcMix(c,sub,insf,code1,code2)\nend\n---Fusion monster, name + name + name\n---@param c Card\n---@param code1 integer\n---@param code2 integer\n---@param code3 integer\n---@param sub boolean\n---@param insf boolean\nfunction Auxiliary.AddFusionProcCode3(c,code1,code2,code3,sub,insf)\n\tAuxiliary.AddFusionProcMix(c,sub,insf,code1,code2,code3)\nend\n---Fusion monster, name + name + name + name\n---@param c Card\n---@param code1 integer\n---@param code2 integer\n---@param code3 integer\n---@param code4 integer\n---@param sub boolean\n---@param insf boolean\nfunction Auxiliary.AddFusionProcCode4(c,code1,code2,code3,code4,sub,insf)\n\tAuxiliary.AddFusionProcMix(c,sub,insf,code1,code2,code3,code4)\nend\n---Fusion monster, name * n\n---@param c Card\n---@param code1 integer\n---@param cc integer\n---@param sub boolean\n---@param insf boolean\nfunction Auxiliary.AddFusionProcCodeRep(c,code1,cc,sub,insf)\n\tlocal code={}\n\tfor i=1,cc do\n\t\tcode[i]=code1\n\tend\n\tAuxiliary.AddFusionProcMix(c,sub,insf,table.unpack(code))\nend\n---Fusion monster, name * minc to maxc\n---@param c Card\n---@param code1 integer|table\n---@param minc integer\n---@param maxc integer\n---@param sub boolean\n---@param insf boolean\nfunction Auxiliary.AddFusionProcCodeRep2(c,code1,minc,maxc,sub,insf)\n\tAuxiliary.AddFusionProcMixRep(c,sub,insf,code1,minc,maxc)\nend\n---Fusion monster, name + condition * n\n---@param c Card\n---@param code1 integer|table\n---@param f function|table\n---@param cc integer\n---@param sub boolean\n---@param insf boolean\nfunction Auxiliary.AddFusionProcCodeFun(c,code1,f,cc,sub,insf)\n\tlocal fun={}\n\tfor i=1,cc do\n\t\tfun[i]=f\n\tend\n\tAuxiliary.AddFusionProcMix(c,sub,insf,code1,table.unpack(fun))\nend\n---Fusion monster, condition + condition\n---@param c Card\n---@param f1 function|table\n---@param f2 function|table\n---@param insf boolean\nfunction Auxiliary.AddFusionProcFun2(c,f1,f2,insf)\n\tAuxiliary.AddFusionProcMix(c,false,insf,f1,f2)\nend\n---Fusion monster, condition * n\n---@param c Card\n---@param f function|table\n---@param cc integer\n---@param insf boolean\nfunction Auxiliary.AddFusionProcFunRep(c,f,cc,insf)\n\tlocal fun={}\n\tfor i=1,cc do\n\t\tfun[i]=f\n\tend\n\tAuxiliary.AddFusionProcMix(c,false,insf,table.unpack(fun))\nend\n---Fusion monster, condition * minc to maxc\n---@param c Card\n---@param f function|table\n---@param minc integer\n---@param maxc integer\n---@param insf boolean\nfunction Auxiliary.AddFusionProcFunRep2(c,f,minc,maxc,insf)\n\tAuxiliary.AddFusionProcMixRep(c,false,insf,f,minc,maxc)\nend\n---Fusion monster, condition1 + condition2 * n\n---@param c Card\n---@param f1 function|table\n---@param f2 function|table\n---@param cc integer\n---@param insf boolean\nfunction Auxiliary.AddFusionProcFunFun(c,f1,f2,cc,insf)\n\tlocal fun={}\n\tfor i=1,cc do\n\t\tfun[i]=f2\n\tend\n\tAuxiliary.AddFusionProcMix(c,false,insf,f1,table.unpack(fun))\nend\n--Fusion monster, condition1 + condition2 * minc to maxc\nfunction Auxiliary.AddFusionProcFunFunRep(c,f1,f2,minc,maxc,insf)\n\tAuxiliary.AddFusionProcMixRep(c,false,insf,f2,minc,maxc,f1)\nend\n---Fusion monster, name + condition * minc to maxc\n---@param c Card\n---@param code1 integer|table\n---@param f function|table\n---@param minc integer\n---@param maxc integer\n---@param sub boolean\n---@param insf boolean\nfunction Auxiliary.AddFusionProcCodeFunRep(c,code1,f,minc,maxc,sub,insf)\n\tAuxiliary.AddFusionProcMixRep(c,sub,insf,f,minc,maxc,code1)\nend\n---Fusion monster, name + name + condition * minc to maxc\n---@param c Card\n---@param code1 integer|table\n---@param code2 integer|table\n---@param f function|table\n---@param minc integer\n---@param maxc integer\n---@param sub boolean\n---@param insf boolean\nfunction Auxiliary.AddFusionProcCode2FunRep(c,code1,code2,f,minc,maxc,sub,insf)\n\tAuxiliary.AddFusionProcMixRep(c,sub,insf,f,minc,maxc,code1,code2)\nend\n---Fusion monster, Shaddoll materials\n---@param c Card\n---@param attr integer\nfunction Auxiliary.AddFusionProcShaddoll(c,attr)\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_SINGLE)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)\n\te1:SetCode(EFFECT_FUSION_MATERIAL)\n\te1:SetCondition(Auxiliary.FShaddollCondition(attr))\n\te1:SetOperation(Auxiliary.FShaddollOperation(attr))\n\tc:RegisterEffect(e1)\nend\nfunction Auxiliary.FShaddollFilter(c,fc,attr)\n\treturn (Auxiliary.FShaddollFilter1(c) or Auxiliary.FShaddollFilter2(c,attr)) and c:IsCanBeFusionMaterial(fc) and not c:IsHasEffect(6205579)\nend\nfunction Auxiliary.FShaddollExFilter(c,fc,attr,fe)\n\treturn c:IsFaceup() and not c:IsImmuneToEffect(fe) and Auxiliary.FShaddollFilter(c,fc,attr)\nend\nfunction Auxiliary.FShaddollFilter1(c)\n\treturn c:IsFusionSetCard(0x9d)\nend\nfunction Auxiliary.FShaddollFilter2(c,attr)\n\treturn c:IsFusionAttribute(attr) or c:IsHasEffect(4904633)\nend\nfunction Auxiliary.FShaddollSpFilter1(c,fc,tp,mg,exg,attr,chkf)\n\treturn mg:IsExists(Auxiliary.FShaddollSpFilter2,1,c,fc,tp,c,attr,chkf)\n\t\tor (exg and exg:IsExists(Auxiliary.FShaddollSpFilter2,1,c,fc,tp,c,attr,chkf))\nend\nfunction Auxiliary.FShaddollSpFilter2(c,fc,tp,mc,attr,chkf)\n\tlocal sg=Group.FromCards(c,mc)\n\tif sg:IsExists(Auxiliary.TuneMagicianCheckX,1,nil,sg,EFFECT_TUNE_MAGICIAN_F) then return false end\n\tif not Auxiliary.MustMaterialCheck(sg,tp,EFFECT_MUST_BE_FMATERIAL) then return false end\n\tif Auxiliary.FCheckAdditional and not Auxiliary.FCheckAdditional(tp,sg,fc)\n\t\tor Auxiliary.FGoalCheckAdditional and not Auxiliary.FGoalCheckAdditional(tp,sg,fc) then return false end\n\treturn ((Auxiliary.FShaddollFilter1(c) and Auxiliary.FShaddollFilter2(mc,attr))\n\t\tor (Auxiliary.FShaddollFilter2(c,attr) and Auxiliary.FShaddollFilter1(mc)))\n\t\tand (chkf==PLAYER_NONE or Duel.GetLocationCountFromEx(tp,tp,sg,fc)>0)\nend\nfunction Auxiliary.FShaddollCondition(attr)\n\treturn \tfunction(e,g,gc,chkf)\n\t\t\t\tif g==nil then return Auxiliary.MustMaterialCheck(nil,e:GetHandlerPlayer(),EFFECT_MUST_BE_FMATERIAL) end\n\t\t\t\tlocal c=e:GetHandler()\n\t\t\t\tlocal mg=g:Filter(Auxiliary.FShaddollFilter,nil,c,attr)\n\t\t\t\tlocal tp=e:GetHandlerPlayer()\n\t\t\t\tlocal fc=Duel.GetFieldCard(tp,LOCATION_FZONE,0)\n\t\t\t\tlocal exg=nil\n\t\t\t\tif fc and fc:IsHasEffect(81788994) and fc:IsCanRemoveCounter(tp,0x16,3,REASON_EFFECT) then\n\t\t\t\t\tlocal fe=fc:IsHasEffect(81788994)\n\t\t\t\t\texg=Duel.GetMatchingGroup(Auxiliary.FShaddollExFilter,tp,0,LOCATION_MZONE,mg,c,attr,fe)\n\t\t\t\tend\n\t\t\t\tif gc then\n\t\t\t\t\tif not mg:IsContains(gc) then return false end\n\t\t\t\t\treturn Auxiliary.FShaddollSpFilter1(gc,c,tp,mg,exg,attr,chkf)\n\t\t\t\tend\n\t\t\t\treturn mg:IsExists(Auxiliary.FShaddollSpFilter1,1,nil,c,tp,mg,exg,attr,chkf)\n\t\t\tend\nend\nfunction Auxiliary.FShaddollOperation(attr)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp,gc,chkf)\n\t\t\t\tlocal c=e:GetHandler()\n\t\t\t\tlocal mg=eg:Filter(Auxiliary.FShaddollFilter,nil,c,attr)\n\t\t\t\tlocal fc=Duel.GetFieldCard(tp,LOCATION_FZONE,0)\n\t\t\t\tlocal exg=nil\n\t\t\t\tif fc and fc:IsHasEffect(81788994) and fc:IsCanRemoveCounter(tp,0x16,3,REASON_EFFECT) then\n\t\t\t\t\tlocal fe=fc:IsHasEffect(81788994)\n\t\t\t\t\texg=Duel.GetMatchingGroup(Auxiliary.FShaddollExFilter,tp,0,LOCATION_MZONE,mg,c,attr,fe)\n\t\t\t\tend\n\t\t\t\tlocal g=nil\n\t\t\t\tif gc then\n\t\t\t\t\tg=Group.FromCards(gc)\n\t\t\t\t\tmg:RemoveCard(gc)\n\t\t\t\telse\n\t\t\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_FMATERIAL)\n\t\t\t\t\tg=mg:FilterSelect(tp,Auxiliary.FShaddollSpFilter1,1,1,nil,c,tp,mg,exg,attr,chkf)\n\t\t\t\t\tmg:Sub(g)\n\t\t\t\tend\n\t\t\t\tif exg and exg:IsExists(Auxiliary.FShaddollSpFilter2,1,nil,c,tp,g:GetFirst(),attr,chkf)\n\t\t\t\t\tand (mg:GetCount()==0 or (exg:GetCount()>0 and Duel.SelectYesNo(tp,Auxiliary.Stringid(81788994,0)))) then\n\t\t\t\t\tfc:RemoveCounter(tp,0x16,3,REASON_EFFECT)\n\t\t\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_FMATERIAL)\n\t\t\t\t\tlocal sg=exg:FilterSelect(tp,Auxiliary.FShaddollSpFilter2,1,1,nil,c,tp,g:GetFirst(),attr,chkf)\n\t\t\t\t\tg:Merge(sg)\n\t\t\t\telse\n\t\t\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_FMATERIAL)\n\t\t\t\t\tlocal sg=mg:FilterSelect(tp,Auxiliary.FShaddollSpFilter2,1,1,nil,c,tp,g:GetFirst(),attr,chkf)\n\t\t\t\t\tg:Merge(sg)\n\t\t\t\tend\n\t\t\t\tDuel.SetFusionMaterial(g)\n\t\t\tend\nend\n\n--Fusion Summon Effect\nfunction Auxiliary.FMaterialFilter(c,e,tp)\n\treturn c:IsCanBeFusionMaterial()\nend\nfunction Auxiliary.FMaterialRemoveFilter(c,e,tp)\n\treturn c:IsAbleToRemove()\nend\nfunction Auxiliary.FMaterialToGraveFilter(c,e,tp)\n\treturn c:IsAbleToGrave()\nend\nfunction Auxiliary.FMaterialToGrave(mat)\n\tDuel.SendtoGrave(mat,REASON_EFFECT+REASON_MATERIAL+REASON_FUSION)\nend\nfunction Auxiliary.FMaterialRemove(mat)\n\tDuel.Remove(mat,POS_FACEUP,REASON_EFFECT+REASON_MATERIAL+REASON_FUSION)\nend\nfunction Auxiliary.FMaterialToDeck(mat)\n\tDuel.SendtoDeck(mat,nil,2,REASON_EFFECT+REASON_MATERIAL+REASON_FUSION)\nend\n---Add Fusion Summon with table `params`.\n---@param c Card\n---@param params table\n---@return Effect\nfunction Auxiliary.AddFusionEffectProcUltimate(c,params)\n\t--filter,mat_location,mat_filter,mat_operation,gc,reg,get_extra_mat,include_this_card\n\t--grave_filter,grave_operation,removed_filter,removed_operation,deck_filter,deck_operation,extra_filter,extra_operation\n\t--get_fcheck,get_gcheck,get_fgoalcheck,foperation,fcheck,gcheck,fgoalcheck,spsummon_nocheck\n\t--category,opinfo,mat_operation2,foperation2\n\tif params.mat_location==nil then params.mat_location=LOCATION_HAND+LOCATION_MZONE end\n\tif params.mat_filter==nil then params.mat_filter=Auxiliary.FMaterialFilter end\n\tif params.mat_operation==nil then params.mat_operation=Auxiliary.FMaterialToGrave end\n\tif params.grave_filter==nil then params.grave_filter=Auxiliary.FMaterialRemoveFilter end\n\tif params.grave_operation==nil then params.grave_operation=Auxiliary.FMaterialRemove end\n\tif params.removed_operation==nil then params.removed_operation=params.mat_operation end\n\tif params.deck_filter==nil then params.deck_filter=Auxiliary.FMaterialToGraveFilter end\n\tif params.deck_operation==nil then params.deck_operation=params.mat_operation end\n\tif params.extra_filter==nil then params.extra_filter=Auxiliary.FMaterialToGraveFilter end\n\tif params.extra_operation==nil then params.extra_operation=params.mat_operation end\n\tif params.spsummon_nocheck==nil then params.spsummon_nocheck=false end\n\tif params.category==nil then params.category=0 end\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetCategory(CATEGORY_SPECIAL_SUMMON|CATEGORY_FUSION_SUMMON|params.category)\n\te1:SetTarget(Auxiliary.FusionEffectUltimateTarget(params))\n\te1:SetOperation(Auxiliary.FusionEffectUltimateOperation(params))\n\tif params.reg~=false then\n\t\te1:SetType(EFFECT_TYPE_ACTIVATE)\n\t\te1:SetCode(EVENT_FREE_CHAIN)\n\t\tc:RegisterEffect(e1)\n\tend\n\treturn e1\nend\nAuxiliary.FMaterialBase=nil\nfunction Auxiliary.FusionEffectUltimateFilter(c,e,tp,mg,chkf,params)\n\t--mg,gc,f1,f2,get_fcheck,spsummon_nocheck\n\tif not c:IsType(TYPE_FUSION) then return false end\n\tif not c:IsCanBeSpecialSummoned(e,SUMMON_TYPE_FUSION,tp,params.spsummon_nocheck,false) then return false end\n\tif params.filter1 and not params.filter1(c) then return false end\n\tif params.filter2 and not params.filter2(c) then return false end\n\tif params.get_fcheck then Auxiliary.FCheckAdditional=params.get_fcheck(c,e,tp) end\n\tlocal res=c:CheckFusionMaterial(mg,params.gc,chkf)\n\tif params.get_fcheck then Auxiliary.FCheckAdditional=nil end\n\treturn res\nend\nfunction Auxiliary.FusionEffectUltimateMatFilter(c,e,tp,f)\n\treturn not c:IsImmuneToEffect(e) and (not f or f(c,e,tp))\nend\nfunction Auxiliary.FusionEffectUltimateMatLocFilter(c,e,tp,loc,f)\n\treturn not c:IsLocation(loc) or (not f or f(c,e,tp))\nend\nfunction Auxiliary.FusionEffectUltimateTarget(params)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp,chk)\n\t\t\t\tif chk==0 then\n\t\t\t\t\tlocal chkf=tp\n\t\t\t\t\tlocal gc\n\t\t\t\t\tif params.include_this_card then\n\t\t\t\t\t\tgc=e:GetHandler()\n\t\t\t\t\tend\n\t\t\t\t\tlocal mgall,mgbase=Duel.GetFusionMaterial(tp,params.mat_location)\n\t\t\t\t\tlocal mgex=Group.CreateGroup()\n\t\t\t\t\tif params.get_extra_mat then mgex=params.get_extra_mat(e,tp,eg,ep,ev,re,r,rp) end\n\t\t\t\t\tmgall:Merge(mgex)\n\t\t\t\t\tmgbase:Merge(mgex)\n\t\t\t\t\tlocal mg1=mgall:Filter(Auxiliary.FusionEffectUltimateMatFilter,nil,e,tp,params.mat_filter)\n\t\t\t\t\t\t:Filter(Auxiliary.FusionEffectUltimateMatLocFilter,nil,e,tp,LOCATION_GRAVE,params.grave_filter)\n\t\t\t\t\t\t:Filter(Auxiliary.FusionEffectUltimateMatLocFilter,nil,e,tp,LOCATION_REMOVED,params.removed_filter)\n\t\t\t\t\t\t:Filter(Auxiliary.FusionEffectUltimateMatLocFilter,nil,e,tp,LOCATION_DECK,params.deck_filter)\n\t\t\t\t\t\t:Filter(Auxiliary.FusionEffectUltimateMatLocFilter,nil,e,tp,LOCATION_EXTRA,params.extra_filter)\n\t\t\t\t\tif gc then mg1:AddCard(gc) end\n\t\t\t\t\tAuxiliary.FMaterialBase=mgbase:Filter(Auxiliary.IsInGroup,nil,mg1)\n\t\t\t\t\tAuxiliary.FCheckAdditional=params.fcheck\n\t\t\t\t\tAuxiliary.GCheckAdditional=params.gcheck\n\t\t\t\t\tif params.get_gcheck then\n\t\t\t\t\t\tAuxiliary.GCheckAdditional=params.get_gcheck(e,tp,nil)\n\t\t\t\t\tend\n\t\t\t\t\tAuxiliary.FGoalCheckAdditional=params.fgoalcheck\n\t\t\t\t\tlocal res=Duel.IsExistingMatchingCard(Auxiliary.FusionEffectUltimateFilter,tp,LOCATION_EXTRA,0,1,nil,e,tp,mg1,chkf,{\n\t\t\t\t\t\tfilter1=params.filter,\n\t\t\t\t\t\tgc=gc,\n\t\t\t\t\t\tget_fcheck=params.get_fcheck,\n\t\t\t\t\t\tspsummon_nocheck=params.spsummon_nocheck\n\t\t\t\t\t})\n\t\t\t\t\tAuxiliary.FCheckAdditional=nil\n\t\t\t\t\tAuxiliary.GCheckAdditional=nil\n\t\t\t\t\tif not res then\n\t\t\t\t\t\tlocal ce=Duel.GetChainMaterial(tp)\n\t\t\t\t\t\tif ce~=nil then\n\t\t\t\t\t\t\tlocal fgroup=ce:GetTarget()\n\t\t\t\t\t\t\tlocal mg2=fgroup(ce,e,tp):Filter(Auxiliary.FusionEffectUltimateMatFilter,nil,e,tp,params.mat_filter)\n\t\t\t\t\t\t\tlocal mf=ce:GetValue()\n\t\t\t\t\t\t\tres=Duel.IsExistingMatchingCard(Auxiliary.FusionEffectUltimateFilter,tp,LOCATION_EXTRA,0,1,nil,e,tp,mg2,chkf,{\n\t\t\t\t\t\t\t\tfilter1=params.filter,\n\t\t\t\t\t\t\t\tfilter2=mf,\n\t\t\t\t\t\t\t\tgc=gc,\n\t\t\t\t\t\t\t\tget_fcheck=params.get_fcheck\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\tend\n\t\t\t\t\tend\n\t\t\t\t\tAuxiliary.FMaterialBase=nil\n\t\t\t\t\tAuxiliary.FGoalCheckAdditional=nil\n\t\t\t\t\treturn res\n\t\t\t\tend\n\t\t\t\tDuel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_EXTRA)\n\t\t\t\tif params.mat_operation==Auxiliary.FMaterialRemove\n\t\t\t\t\tor params.grave_operation==Auxiliary.FMaterialRemove\n\t\t\t\t\tor params.deck_operation==Auxiliary.FMaterialRemove then\n\t\t\t\t\tDuel.SetOperationInfo(0,CATEGORY_REMOVE,nil,1,tp,params.mat_location)\n\t\t\t\t\te:SetCategory(e:GetCategory()|CATEGORY_REMOVE)\n\t\t\t\tend\n\t\t\t\tif params.mat_operation==Auxiliary.FMaterialToDeck\n\t\t\t\t\tor params.grave_operation==Auxiliary.FMaterialToDeck\n\t\t\t\t\tor params.deck_operation==Auxiliary.FMaterialToDeck then\n\t\t\t\t\tDuel.SetOperationInfo(0,CATEGORY_TODECK,nil,1,tp,params.mat_location)\n\t\t\t\t\te:SetCategory(e:GetCategory()|CATEGORY_TODECK)\n\t\t\t\tend\n\t\t\t\tif params.mat_location&LOCATION_DECK>0 then\n\t\t\t\t\te:SetCategory(e:GetCategory()|CATEGORY_DECKDES)\n\t\t\t\tend\n\t\t\t\tif params.opinfo then\n\t\t\t\t\tparams.opinfo(e,tp)\n\t\t\t\tend\n\t\t\tend\nend\n---\n---@param params table\n---@return function\nfunction Auxiliary.FusionEffectUltimateOperation(params)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp)\n\t\t\t\tlocal chkf=tp\n\t\t\t\tlocal gc\n\t\t\t\tif params.include_this_card then\n\t\t\t\t\tgc=e:GetHandler()\n\t\t\t\t\tif gc:IsOnField() and gc:IsFacedown() or not gc:IsRelateToEffect(e) or gc:IsImmuneToEffect(e) then return end\n\t\t\t\tend\n\t\t\t\tlocal mgall,mgbase=Duel.GetFusionMaterial(tp,params.mat_location)\n\t\t\t\tlocal mgex=Group.CreateGroup()\n\t\t\t\tif params.get_extra_mat then mgex=params.get_extra_mat(e,tp,eg,ep,ev,re,r,rp) end\n\t\t\t\tmgall:Merge(mgex)\n\t\t\t\tmgbase:Merge(mgex)\n\t\t\t\tlocal mg1=mgall:Filter(Auxiliary.FusionEffectUltimateMatFilter,nil,e,tp,params.mat_filter)\n\t\t\t\t\t:Filter(Auxiliary.FusionEffectUltimateMatLocFilter,nil,e,tp,LOCATION_GRAVE,params.grave_filter)\n\t\t\t\t\t:Filter(Auxiliary.FusionEffectUltimateMatLocFilter,nil,e,tp,LOCATION_REMOVED,params.removed_filter)\n\t\t\t\t\t:Filter(Auxiliary.FusionEffectUltimateMatLocFilter,nil,e,tp,LOCATION_DECK,params.deck_filter)\n\t\t\t\t\t:Filter(Auxiliary.FusionEffectUltimateMatLocFilter,nil,e,tp,LOCATION_EXTRA,params.extra_filter)\n\t\t\t\tif gc then mg1:AddCard(gc) end\n\t\t\t\tAuxiliary.FMaterialBase=mgbase:Filter(Auxiliary.IsInGroup,nil,mg1)\n\t\t\t\tAuxiliary.FCheckAdditional=params.fcheck\n\t\t\t\tAuxiliary.GCheckAdditional=params.gcheck\n\t\t\t\tif params.get_gcheck then\n\t\t\t\t\tAuxiliary.GCheckAdditional=params.get_gcheck(e,tp,nil)\n\t\t\t\tend\n\t\t\t\tAuxiliary.FGoalCheckAdditional=params.fgoalcheck\n\t\t\t\tlocal sg1=Duel.GetMatchingGroup(Auxiliary.FusionEffectUltimateFilter,tp,LOCATION_EXTRA,0,nil,e,tp,mg1,chkf,{\n\t\t\t\t\tfilter1=params.filter,\n\t\t\t\t\tgc=gc,\n\t\t\t\t\tget_fcheck=params.get_fcheck,\n\t\t\t\t\tspsummon_nocheck=params.spsummon_nocheck\n\t\t\t\t})\n\t\t\t\tAuxiliary.FCheckAdditional=nil\n\t\t\t\tAuxiliary.GCheckAdditional=nil\n\t\t\t\tlocal mg2=nil\n\t\t\t\tlocal sg2=nil\n\t\t\t\tlocal ce=Duel.GetChainMaterial(tp)\n\t\t\t\tif ce then\n\t\t\t\t\tlocal fgroup=ce:GetTarget()\n\t\t\t\t\tmg2=fgroup(ce,e,tp):Filter(Auxiliary.FusionEffectUltimateMatFilter,nil,e,tp,params.mat_filter)\n\t\t\t\t\tlocal mf=ce:GetValue()\n\t\t\t\t\tsg2=Duel.GetMatchingGroup(Auxiliary.FusionEffectUltimateFilter,tp,LOCATION_EXTRA,0,nil,e,tp,mg2,chkf,{\n\t\t\t\t\t\tfilter1=params.filter,\n\t\t\t\t\t\tfilter2=mf,\n\t\t\t\t\t\tgc=gc,\n\t\t\t\t\t\tget_fcheck=params.get_fcheck\n\t\t\t\t\t})\n\t\t\t\tend\n\t\t\t\tif sg1:GetCount()>0 or (sg2~=nil and sg2:GetCount()>0) then\n\t\t\t\t\tlocal sg=sg1:Clone()\n\t\t\t\t\tif sg2 then sg:Merge(sg2) end\n\t\t\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\t\t\t\t\tlocal tg=sg:Select(tp,1,1,nil)\n\t\t\t\t\tlocal tc=tg:GetFirst()\n\t\t\t\t\tAuxiliary.FCheckAdditional=params.fcheck\n\t\t\t\t\tAuxiliary.GCheckAdditional=params.gcheck\n\t\t\t\t\tif params.get_gcheck then\n\t\t\t\t\t\tAuxiliary.GCheckAdditional=params.get_gcheck(e,tp,tc)\n\t\t\t\t\tend\n\t\t\t\t\tif params.get_fcheck then Auxiliary.FCheckAdditional=params.get_fcheck(tc,e,tp) end\n\t\t\t\t\tif sg1:IsContains(tc) and (sg2==nil or not sg2:IsContains(tc) or ce and not Duel.SelectYesNo(tp,ce:GetDescription())) then\n\t\t\t\t\t\tlocal mat1=Duel.SelectFusionMaterial(tp,tc,mg1,gc,chkf)\n\t\t\t\t\t\ttc:SetMaterial(mat1)\n\t\t\t\t\t\tif params.mat_operation2 then params.mat_operation2(e,tp,mat1) end\n\t\t\t\t\t\tif params.grave_operation~=params.mat_operation then\n\t\t\t\t\t\t\tlocal mat=mat1:Filter(Card.IsLocation,nil,LOCATION_GRAVE)\n\t\t\t\t\t\t\tmat1:Sub(mat)\n\t\t\t\t\t\t\tparams.grave_operation(mat)\n\t\t\t\t\t\tend\n\t\t\t\t\t\tif params.removed_operation~=params.mat_operation then\n\t\t\t\t\t\t\tlocal mat=mat1:Filter(Card.IsLocation,nil,LOCATION_REMOVED)\n\t\t\t\t\t\t\tmat1:Sub(mat)\n\t\t\t\t\t\t\tparams.removed_operation(mat)\n\t\t\t\t\t\tend\n\t\t\t\t\t\tif params.deck_operation~=params.mat_operation then\n\t\t\t\t\t\t\tlocal mat=mat1:Filter(Card.IsLocation,nil,LOCATION_DECK)\n\t\t\t\t\t\t\tmat1:Sub(mat)\n\t\t\t\t\t\t\tparams.deck_operation(mat)\n\t\t\t\t\t\tend\n\t\t\t\t\t\tif params.extra_operation~=params.mat_operation then\n\t\t\t\t\t\t\tlocal mat=mat1:Filter(Card.IsLocation,nil,LOCATION_EXTRA)\n\t\t\t\t\t\t\tmat1:Sub(mat)\n\t\t\t\t\t\t\tparams.extra_operation(mat)\n\t\t\t\t\t\tend\n\t\t\t\t\t\tparams.mat_operation(mat1)\n\t\t\t\t\t\tDuel.BreakEffect()\n\t\t\t\t\t\tDuel.SpecialSummon(tc,SUMMON_TYPE_FUSION,tp,tp,params.spsummon_nocheck,false,POS_FACEUP)\n\t\t\t\t\telseif ce and mg2 then\n\t\t\t\t\t\tlocal mat2=Duel.SelectFusionMaterial(tp,tc,mg2,gc,chkf)\n\t\t\t\t\t\tlocal fop=ce:GetOperation()\n\t\t\t\t\t\tfop(ce,e,tp,tc,mat2)\n\t\t\t\t\tend\n\t\t\t\t\ttc:CompleteProcedure()\n\t\t\t\t\tif params.foperation then params.foperation(e,tp,tc) end\n\t\t\t\tend\n\t\t\t\tAuxiliary.FCheckAdditional=nil\n\t\t\t\tAuxiliary.GCheckAdditional=nil\n\t\t\t\tAuxiliary.FGoalCheckAdditional=nil\n\t\t\t\tAuxiliary.FMaterialBase=nil\n\t\t\t\tif params.foperation2 then params.foperation2(e,tp,eg,ep,ev,re,r,rp) end\n\t\t\tend\nend\nfunction Auxiliary.AddFusionEffectProc(c,filter,mat_location,mat_filter,mat_operation,params)\n\tif params==nil then params={} end\n\tparams.filter=filter\n\tparams.mat_location=mat_location\n\tparams.mat_filter=mat_filter\n\tparams.mat_operation=mat_operation\n\treturn Auxiliary.AddFusionEffectProcUltimate(c,params)\nend\n\n--Contact Fusion\nfunction Auxiliary.AddContactFusionProcedure(c,filter,self_location,opponent_location,mat_operation,...)\n\tself_location=self_location or 0\n\topponent_location=opponent_location or 0\n\tlocal operation_params={...}\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetType(EFFECT_TYPE_FIELD)\n\te2:SetCode(EFFECT_SPSUMMON_PROC)\n\te2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)\n\te2:SetRange(LOCATION_EXTRA)\n\te2:SetCondition(Auxiliary.ContactFusionCondition(filter,self_location,opponent_location))\n\te2:SetTarget(Auxiliary.ContactFusionTarget(filter,self_location,opponent_location))\n\te2:SetOperation(Auxiliary.ContactFusionOperation(mat_operation,operation_params))\n\tc:RegisterEffect(e2)\n\treturn e2\nend\nfunction Auxiliary.ContactFusionMaterialFilter(c,fc,filter)\n\treturn c:IsCanBeFusionMaterial(fc,SUMMON_TYPE_SPECIAL) and (not filter or filter(c,fc))\nend\nfunction Auxiliary.ContactFusionCondition(filter,self_location,opponent_location)\n\treturn\tfunction(e,c)\n\t\t\t\tif c==nil then return true end\n\t\t\t\tif c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end\n\t\t\t\tlocal tp=c:GetControler()\n\t\t\t\tlocal mg=Duel.GetMatchingGroup(Auxiliary.ContactFusionMaterialFilter,tp,self_location,opponent_location,c,c,filter)\n\t\t\t\treturn c:CheckFusionMaterial(mg,nil,tp|0x200)\n\t\t\tend\nend\nfunction Auxiliary.ContactFusionTarget(filter,self_location,opponent_location)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp,chk,c)\n\t\t\t\tlocal mg=Duel.GetMatchingGroup(Auxiliary.ContactFusionMaterialFilter,tp,self_location,opponent_location,c,c,filter)\n\t\t\t\tlocal g=Duel.SelectFusionMaterial(tp,c,mg,nil,tp|0x200)\n\t\t\t\tif #g>0 then\n\t\t\t\t\tg:KeepAlive()\n\t\t\t\t\te:SetLabelObject(g)\n\t\t\t\t\treturn true\n\t\t\t\telse return false end\n\t\t\tend\nend\nfunction Auxiliary.ContactFusionOperation(mat_operation,operation_params)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp,c)\n\t\t\t\tlocal g=e:GetLabelObject()\n\t\t\t\tc:SetMaterial(g)\n\t\t\t\tmat_operation(g,table.unpack(operation_params))\n\t\t\t\tg:DeleteGroup()\n\t\t\tend\nend\n--send to deck of contact fusion\nfunction Auxiliary.ContactFusionSendToDeck(c)\n\treturn\tfunction(g)\n\t\t\t\tlocal cg=g:Filter(Card.IsFacedown,nil)\n\t\t\t\tif cg:GetCount()>0 then\n\t\t\t\t\tDuel.ConfirmCards(1-c:GetControler(),cg)\n\t\t\t\tend\n\t\t\t\tlocal hg=g:Filter(Card.IsLocation,nil,LOCATION_GRAVE+LOCATION_REMOVED)\n\t\t\t\tif hg:GetCount()>0 then\n\t\t\t\t\tDuel.HintSelection(hg)\n\t\t\t\tend\n\t\t\t\tDuel.SendtoDeck(g,nil,SEQ_DECKSHUFFLE,REASON_COST)\n\t\t\tend\nend\nAuxiliary.tdcfop=Auxiliary.ContactFusionSendToDeck\n\n--Ritual Summon\nfunction Auxiliary.AddRitualProcUltimate(c,filter,level_function,greater_or_equal,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\n\tsummon_location=summon_location or LOCATION_HAND\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetCategory(CATEGORY_SPECIAL_SUMMON)\n\te1:SetType(EFFECT_TYPE_ACTIVATE)\n\te1:SetCode(EVENT_FREE_CHAIN)\n\te1:SetTarget(Auxiliary.RitualUltimateTarget(filter,level_function,greater_or_equal,summon_location,grave_filter,mat_filter,extra_target))\n\te1:SetOperation(Auxiliary.RitualUltimateOperation(filter,level_function,greater_or_equal,summon_location,grave_filter,mat_filter,extra_operation))\n\tif not pause then\n\t\tc:RegisterEffect(e1)\n\tend\n\treturn e1\nend\n---@param g Group\n---@param c Card\n---@param lv integer\n---@return boolean\nfunction Auxiliary.RitualCheckGreater(g,c,lv)\n\tDuel.SetSelectedCard(g)\n\treturn g:CheckWithSumGreater(Card.GetRitualLevel,lv,c)\nend\n---@param g Group\n---@param c Card\n---@param lv integer\n---@return boolean\nfunction Auxiliary.RitualCheckEqual(g,c,lv)\n\treturn g:CheckWithSumEqual(Card.GetRitualLevel,lv,#g,#g,c)\nend\n---@param g Group\n---@param tp integer\n---@param c Card\n---@param lv integer\n---@param greater_or_equal string\n---|\"'Greater'\"\n---|\"'Equal'\"\n---@return boolean\nfunction Auxiliary.RitualCheck(g,tp,c,lv,greater_or_equal)\n\t-- Check if there's space to summon\n\tif c:IsLocation(LOCATION_EXTRA) then\n\t\tif Duel.GetLocationCountFromEx(tp,tp,g,c)<=0 then\n\t\t\treturn false\n\t\tend\n\telse\n\t\tif Duel.GetMZoneCount(tp,g,tp)<=0 then\n\t\t\treturn false\n\t\tend\n\tend\n\treturn Auxiliary[\"RitualCheck\"..greater_or_equal](g,c,lv) and (not c.mat_group_check or c.mat_group_check(g,tp))\n\t\tand (not Auxiliary.RCheckAdditional or Auxiliary.RCheckAdditional(tp,g,c))\nend\nfunction Auxiliary.RitualCheckAdditionalLevel(c,rc)\n\tlocal raw_level=c:GetRitualLevel(rc)\n\tlocal lv1=raw_level&0xffff\n\tlocal lv2=raw_level>>16\n\tif lv2>0 then\n\t\treturn math.min(lv1,lv2)\n\telse\n\t\treturn lv1\n\tend\nend\nfunction Auxiliary.RitualCheckAdditional(c,lv,greater_or_equal)\n\tif greater_or_equal==\"Equal\" then\n\t\treturn\tfunction(g)\n\t\t\t\t\treturn (not Auxiliary.RGCheckAdditional or Auxiliary.RGCheckAdditional(g)) and g:GetSum(Auxiliary.RitualCheckAdditionalLevel,c)<=lv\n\t\t\t\tend\n\telse\n\t\treturn\tfunction(g,ec)\n\t\t\t\t\tif ec then\n\t\t\t\t\t\treturn (not Auxiliary.RGCheckAdditional or Auxiliary.RGCheckAdditional(g,ec)) and g:GetSum(Auxiliary.RitualCheckAdditionalLevel,c)-Auxiliary.RitualCheckAdditionalLevel(ec,c)<=lv\n\t\t\t\t\telse\n\t\t\t\t\t\treturn not Auxiliary.RGCheckAdditional or Auxiliary.RGCheckAdditional(g)\n\t\t\t\t\tend\n\t\t\t\tend\n\tend\nend\nfunction Auxiliary.RitualUltimateFilter(c,filter,e,tp,m1,m2,level_function,greater_or_equal,chk)\n\tif 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\n\tlocal mg=m1:Filter(Card.IsCanBeRitualMaterial,c,c)\n\tif m2 then\n\t\tmg:Merge(m2)\n\tend\n\tif c.mat_filter then\n\t\tmg=mg:Filter(c.mat_filter,c,tp)\n\telse\n\t\tmg:RemoveCard(c)\n\tend\n\tlocal lv=level_function(c)\n\tAuxiliary.GCheckAdditional=Auxiliary.RitualCheckAdditional(c,lv,greater_or_equal)\n\tlocal res=mg:CheckSubGroup(Auxiliary.RitualCheck,1,lv,tp,c,lv,greater_or_equal)\n\tAuxiliary.GCheckAdditional=nil\n\treturn res\nend\nfunction Auxiliary.RitualExtraFilter(c,f)\n\treturn c:GetLevel()>0 and f(c) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemove()\nend\nfunction Auxiliary.RitualUltimateTarget(filter,level_function,greater_or_equal,summon_location,grave_filter,mat_filter,extra_target)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp,chk)\n\t\t\t\tif chk==0 then\n\t\t\t\t\tlocal mg=Duel.GetRitualMaterial(tp)\n\t\t\t\t\tif mat_filter then mg=mg:Filter(mat_filter,nil,e,tp,true) end\n\t\t\t\t\tlocal exg=nil\n\t\t\t\t\tif grave_filter then\n\t\t\t\t\t\texg=Duel.GetMatchingGroup(Auxiliary.RitualExtraFilter,tp,LOCATION_GRAVE,0,nil,grave_filter)\n\t\t\t\t\tend\n\t\t\t\t\treturn Duel.IsExistingMatchingCard(Auxiliary.RitualUltimateFilter,tp,summon_location,0,1,nil,filter,e,tp,mg,exg,level_function,greater_or_equal,true)\n\t\t\t\tend\n\t\t\t\tDuel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,summon_location)\n\t\t\t\tif grave_filter then\n\t\t\t\t\tDuel.SetOperationInfo(0,CATEGORY_REMOVE,nil,0,tp,LOCATION_GRAVE)\n\t\t\t\tend\n\t\t\t\tif extra_target then\n\t\t\t\t\textra_target(e,tp,eg,ep,ev,re,r,rp)\n\t\t\t\tend\n\t\t\tend\nend\nfunction Auxiliary.RitualUltimateOperation(filter,level_function,greater_or_equal,summon_location,grave_filter,mat_filter,extra_operation)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp)\n\t\t\t\t::RitualUltimateSelectStart::\n\t\t\t\tlocal mg=Duel.GetRitualMaterial(tp)\n\t\t\t\tif mat_filter then mg=mg:Filter(mat_filter,nil,e,tp) end\n\t\t\t\tlocal exg=nil\n\t\t\t\tif grave_filter then\n\t\t\t\t\texg=Duel.GetMatchingGroup(Auxiliary.RitualExtraFilter,tp,LOCATION_GRAVE,0,nil,grave_filter)\n\t\t\t\tend\n\t\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\t\t\t\tlocal 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)\n\t\t\t\tlocal tc=tg:GetFirst()\n\t\t\t\tlocal mat\n\t\t\t\tif tc then\n\t\t\t\t\tmg=mg:Filter(Card.IsCanBeRitualMaterial,tc,tc)\n\t\t\t\t\tif exg then\n\t\t\t\t\t\tmg:Merge(exg)\n\t\t\t\t\tend\n\t\t\t\t\tif tc.mat_filter then\n\t\t\t\t\t\tmg=mg:Filter(tc.mat_filter,tc,tp)\n\t\t\t\t\telse\n\t\t\t\t\t\tmg:RemoveCard(tc)\n\t\t\t\t\tend\n\t\t\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_RELEASE)\n\t\t\t\t\tlocal lv=level_function(tc)\n\t\t\t\t\tAuxiliary.GCheckAdditional=Auxiliary.RitualCheckAdditional(tc,lv,greater_or_equal)\n\t\t\t\t\tmat=mg:SelectSubGroup(tp,Auxiliary.RitualCheck,true,1,lv,tp,tc,lv,greater_or_equal)\n\t\t\t\t\tAuxiliary.GCheckAdditional=nil\n\t\t\t\t\tif not mat then goto RitualUltimateSelectStart end\n\t\t\t\t\ttc:SetMaterial(mat)\n\t\t\t\t\tDuel.ReleaseRitualMaterial(mat)\n\t\t\t\t\tDuel.BreakEffect()\n\t\t\t\t\tDuel.SpecialSummon(tc,SUMMON_TYPE_RITUAL,tp,tp,false,true,POS_FACEUP)\n\t\t\t\t\ttc:CompleteProcedure()\n\t\t\t\tend\n\t\t\t\tif extra_operation then\n\t\t\t\t\textra_operation(e,tp,eg,ep,ev,re,r,rp,tc,mat)\n\t\t\t\tend\n\t\t\tend\nend\n--Ritual Summon, geq fixed lv\nfunction Auxiliary.AddRitualProcGreater(c,filter,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\n\treturn Auxiliary.AddRitualProcUltimate(c,filter,Card.GetOriginalLevel,\"Greater\",summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\nend\nfunction Auxiliary.AddRitualProcGreaterCode(c,code1,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\n\tAuxiliary.AddCodeList(c,code1)\n\treturn Auxiliary.AddRitualProcGreater(c,Auxiliary.FilterBoolFunction(Card.IsCode,code1),summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\nend\n--Ritual Summon, equal to fixed lv\nfunction Auxiliary.AddRitualProcEqual(c,filter,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\n\treturn Auxiliary.AddRitualProcUltimate(c,filter,Card.GetOriginalLevel,\"Equal\",summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\nend\nfunction Auxiliary.AddRitualProcEqualCode(c,code1,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\n\tAuxiliary.AddCodeList(c,code1)\n\treturn Auxiliary.AddRitualProcEqual(c,Auxiliary.FilterBoolFunction(Card.IsCode,code1),summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\nend\n--Ritual Summon, equal to monster lv\nfunction Auxiliary.AddRitualProcEqual2(c,filter,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\n\treturn Auxiliary.AddRitualProcUltimate(c,filter,Card.GetLevel,\"Equal\",summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\nend\nfunction Auxiliary.AddRitualProcEqual2Code(c,code1,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\n\tAuxiliary.AddCodeList(c,code1)\n\treturn Auxiliary.AddRitualProcEqual2(c,Auxiliary.FilterBoolFunction(Card.IsCode,code1),summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\nend\nfunction Auxiliary.AddRitualProcEqual2Code2(c,code1,code2,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\n\tAuxiliary.AddCodeList(c,code1,code2)\n\treturn Auxiliary.AddRitualProcEqual2(c,Auxiliary.FilterBoolFunction(Card.IsCode,code1,code2),summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\nend\n--Ritual Summon, geq monster lv\nfunction Auxiliary.AddRitualProcGreater2(c,filter,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\n\treturn Auxiliary.AddRitualProcUltimate(c,filter,Card.GetLevel,\"Greater\",summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\nend\nfunction Auxiliary.AddRitualProcGreater2Code(c,code1,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\n\tAuxiliary.AddCodeList(c,code1)\n\treturn Auxiliary.AddRitualProcGreater2(c,Auxiliary.FilterBoolFunction(Card.IsCode,code1),summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\nend\nfunction Auxiliary.AddRitualProcGreater2Code2(c,code1,code2,summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\n\tAuxiliary.AddCodeList(c,code1,code2)\n\treturn Auxiliary.AddRitualProcGreater2(c,Auxiliary.FilterBoolFunction(Card.IsCode,code1,code2),summon_location,grave_filter,mat_filter,pause,extra_operation,extra_target)\nend\n\n--Pendulum Summon\n--add procedure to Pendulum monster, also allows registeration of activation effect\nfunction Auxiliary.EnablePendulumAttribute(c,reg)\n\tif not Auxiliary.PendulumChecklist then\n\t\tAuxiliary.PendulumChecklist=0\n\t\tlocal ge1=Effect.CreateEffect(c)\n\t\tge1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)\n\t\tge1:SetCode(EVENT_PHASE_START+PHASE_DRAW)\n\t\tge1:SetOperation(Auxiliary.PendulumReset)\n\t\tDuel.RegisterEffect(ge1,0)\n\tend\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(1163)\n\te1:SetType(EFFECT_TYPE_FIELD)\n\te1:SetCode(EFFECT_SPSUMMON_PROC_G)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)\n\te1:SetRange(LOCATION_PZONE)\n\te1:SetCondition(Auxiliary.PendCondition)\n\te1:SetOperation(Auxiliary.PendOperation)\n\te1:SetValue(SUMMON_TYPE_PENDULUM)\n\tc:RegisterEffect(e1)\n\t--register by default\n\tif reg==nil or reg then\n\t\tlocal e2=Effect.CreateEffect(c)\n\t\te2:SetDescription(1160)\n\t\te2:SetType(EFFECT_TYPE_ACTIVATE)\n\t\te2:SetCode(EVENT_FREE_CHAIN)\n\t\te2:SetRange(LOCATION_HAND)\n\t\tc:RegisterEffect(e2)\n\tend\nend\nfunction Auxiliary.PendulumReset(e,tp,eg,ep,ev,re,r,rp)\n\tAuxiliary.PendulumChecklist=0\nend\nfunction Auxiliary.PConditionExtraFilterSpecific(c,e,tp,lscale,rscale,te)\n\tif not te then return true end\n\tlocal f=te:GetValue()\n\treturn not f or f(te,c,e,tp,lscale,rscale)\nend\nfunction Auxiliary.PConditionExtraFilter(c,e,tp,lscale,rscale,eset)\n\tfor _,te in ipairs(eset) do\n\t\tif Auxiliary.PConditionExtraFilterSpecific(c,e,tp,lscale,rscale,te) then return true end\n\tend\n\treturn false\nend\nfunction Auxiliary.PConditionFilter(c,e,tp,lscale,rscale,eset)\n\tlocal lv=0\n\tif c.pendulum_level then\n\t\tlv=c.pendulum_level\n\telse\n\t\tlv=c:GetLevel()\n\tend\n\tlocal bool=Auxiliary.PendulumSummonableBool(c)\n\treturn (c:IsLocation(LOCATION_HAND) or (c:IsFaceup() and c:IsType(TYPE_PENDULUM)))\n\t\tand lv>lscale and lv<rscale and c:IsCanBeSpecialSummoned(e,SUMMON_TYPE_PENDULUM,tp,bool,bool)\n\t\tand not c:IsForbidden()\n\t\tand (Auxiliary.PendulumChecklist&(0x1<<tp)==0 or Auxiliary.PConditionExtraFilter(c,e,tp,lscale,rscale,eset))\nend\nfunction Auxiliary.PendCondition(e,c,og)\n\tif c==nil then return true end\n\tlocal tp=c:GetControler()\n\tlocal eset={Duel.IsPlayerAffectedByEffect(tp,EFFECT_EXTRA_PENDULUM_SUMMON)}\n\tif Auxiliary.PendulumChecklist&(0x1<<tp)~=0 and #eset==0 then return false end\n\tlocal rpz=Duel.GetFieldCard(tp,LOCATION_PZONE,1)\n\tif rpz==nil or c==rpz then return false end\n\tlocal lscale=c:GetLeftScale()\n\tlocal rscale=rpz:GetRightScale()\n\tif lscale>rscale then lscale,rscale=rscale,lscale end\n\tlocal loc=0\n\tif Duel.GetLocationCount(tp,LOCATION_MZONE)>0 then loc=loc+LOCATION_HAND end\n\tif Duel.GetLocationCountFromEx(tp,tp,nil,TYPE_PENDULUM)>0 then loc=loc+LOCATION_EXTRA end\n\tif loc==0 then return false end\n\tlocal g=nil\n\tif og then\n\t\tg=og:Filter(Card.IsLocation,nil,loc)\n\telse\n\t\tg=Duel.GetFieldGroup(tp,loc,0)\n\tend\n\treturn g:IsExists(Auxiliary.PConditionFilter,1,nil,e,tp,lscale,rscale,eset)\nend\nfunction Auxiliary.PendOperationCheck(ft1,ft2,ft)\n\treturn\tfunction(g)\n\t\t\t\tlocal exg=g:Filter(Card.IsLocation,nil,LOCATION_EXTRA)\n\t\t\t\tlocal mg=g-exg\n\t\t\t\treturn #g<=ft and #exg<=ft2 and #mg<=ft1\n\t\t\tend\nend\nfunction Auxiliary.PendOperation(e,tp,eg,ep,ev,re,r,rp,c,sg,og)\n\tlocal rpz=Duel.GetFieldCard(tp,LOCATION_PZONE,1)\n\tlocal lscale=c:GetLeftScale()\n\tlocal rscale=rpz:GetRightScale()\n\tif lscale>rscale then lscale,rscale=rscale,lscale end\n\tlocal eset={Duel.IsPlayerAffectedByEffect(tp,EFFECT_EXTRA_PENDULUM_SUMMON)}\n\tlocal tg=nil\n\tlocal loc=0\n\tlocal ft1=Duel.GetLocationCount(tp,LOCATION_MZONE)\n\tlocal ft2=Duel.GetLocationCountFromEx(tp,tp,nil,TYPE_PENDULUM)\n\tlocal ft=Duel.GetUsableMZoneCount(tp)\n\tlocal ect=c29724053 and Duel.IsPlayerAffectedByEffect(tp,29724053) and c29724053[tp]\n\tif ect and ect<ft2 then ft2=ect end\n\tif Duel.IsPlayerAffectedByEffect(tp,59822133) then\n\t\tif ft1>0 then ft1=1 end\n\t\tif ft2>0 then ft2=1 end\n\t\tft=1\n\tend\n\tif ft1>0 then loc=loc|LOCATION_HAND end\n\tif ft2>0 then loc=loc|LOCATION_EXTRA end\n\tif og then\n\t\ttg=og:Filter(Card.IsLocation,nil,loc):Filter(Auxiliary.PConditionFilter,nil,e,tp,lscale,rscale,eset)\n\telse\n\t\ttg=Duel.GetMatchingGroup(Auxiliary.PConditionFilter,tp,loc,0,nil,e,tp,lscale,rscale,eset)\n\tend\n\tlocal ce=nil\n\tlocal b1=Auxiliary.PendulumChecklist&(0x1<<tp)==0\n\tlocal b2=#eset>0\n\tif b1 and b2 then\n\t\tlocal options={1163}\n\t\tfor _,te in ipairs(eset) do\n\t\t\ttable.insert(options,te:GetDescription())\n\t\tend\n\t\tlocal op=Duel.SelectOption(tp,table.unpack(options))\n\t\tif op>0 then\n\t\t\tce=eset[op]\n\t\tend\n\telseif b2 and not b1 then\n\t\tlocal options={}\n\t\tfor _,te in ipairs(eset) do\n\t\t\ttable.insert(options,te:GetDescription())\n\t\tend\n\t\tlocal op=Duel.SelectOption(tp,table.unpack(options))\n\t\tce=eset[op+1]\n\tend\n\tif ce then\n\t\ttg=tg:Filter(Auxiliary.PConditionExtraFilterSpecific,nil,e,tp,lscale,rscale,ce)\n\tend\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)\n\tAuxiliary.GCheckAdditional=Auxiliary.PendOperationCheck(ft1,ft2,ft)\n\tlocal g=tg:SelectSubGroup(tp,Auxiliary.TRUE,true,1,math.min(#tg,ft))\n\tAuxiliary.GCheckAdditional=nil\n\tif not g then return end\n\tif ce then\n\t\tDuel.Hint(HINT_CARD,0,ce:GetOwner():GetOriginalCode())\n\t\tce:UseCountLimit(tp)\n\telse\n\t\tAuxiliary.PendulumChecklist=Auxiliary.PendulumChecklist|(0x1<<tp)\n\tend\n\tsg:Merge(g)\n\tDuel.HintSelection(Group.FromCards(c))\n\tDuel.HintSelection(Group.FromCards(rpz))\nend\n--enable revive limit for monsters that are also pendulum sumonable from certain locations (Odd-Eyes Revolution Dragon)\nfunction Auxiliary.EnableReviveLimitPendulumSummonable(c, loc)\n\tif c:IsStatus(STATUS_COPYING_EFFECT) then return end\n\tc:EnableReviveLimit()\n\tlocal mt=getmetatable(c)\n\tif loc==nil then loc=0xff end\n\tmt.psummonable_location=loc\n\t--complete procedure on pendulum summon success\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)\n\te1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_CONTINUOUS)\n\te1:SetCode(EVENT_SPSUMMON_SUCCESS)\n\te1:SetOperation(Auxiliary.PSSCompleteProcedure)\n\tc:RegisterEffect(e1)\nend\nfunction Auxiliary.PendulumSummonableBool(c)\n\treturn c.psummonable_location~=nil and c:GetLocation()&c.psummonable_location>0\nend\nfunction Auxiliary.PSSCompleteProcedure(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tif c:IsSummonType(SUMMON_TYPE_PENDULUM) then\n\t\tc:CompleteProcedure()\n\tend\nend\n\n---Link Summon\n---@param c Card\n---@param f function|nil\n---@param min integer\n---@param max? integer\n---@param gf? function\n---@return Effect\nfunction Auxiliary.AddLinkProcedure(c,f,min,max,gf)\n\tif max==nil then max=c:GetLink() end\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(1166)\n\te1:SetType(EFFECT_TYPE_FIELD)\n\te1:SetCode(EFFECT_SPSUMMON_PROC)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)\n\te1:SetRange(LOCATION_EXTRA)\n\te1:SetCondition(Auxiliary.LinkCondition(f,min,max,gf))\n\te1:SetTarget(Auxiliary.LinkTarget(f,min,max,gf))\n\te1:SetOperation(Auxiliary.LinkOperation(f,min,max,gf))\n\te1:SetValue(SUMMON_TYPE_LINK)\n\tc:RegisterEffect(e1)\n\treturn e1\nend\nfunction Auxiliary.LConditionFilter(c,f,lc,e)\n\treturn (c:IsFaceup() or not c:IsOnField() or e:IsHasProperty(EFFECT_FLAG_SET_AVAILABLE))\n\t\tand c:IsCanBeLinkMaterial(lc) and (not f or f(c))\nend\nfunction Auxiliary.LExtraFilter(c,f,lc,tp)\n\tif c:IsOnField() and c:IsFacedown() then return false end\n\tif not c:IsCanBeLinkMaterial(lc) or f and not f(c) then return false end\n\tlocal le={c:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)}\n\tfor _,te in pairs(le) do\n\t\tlocal tf=te:GetValue()\n\t\tlocal related,valid=tf(te,lc,nil,c,tp)\n\t\tif related then return true end\n\tend\n\treturn false\nend\nfunction Auxiliary.GetLinkCount(c)\n\tif c:IsLinkType(TYPE_LINK) and c:GetLink()>1 then\n\t\treturn 1+0x10000*c:GetLink()\n\telse return 1 end\nend\nfunction Auxiliary.GetLinkMaterials(tp,f,lc,e)\n\tlocal mg=Duel.GetMatchingGroup(Auxiliary.LConditionFilter,tp,LOCATION_MZONE,0,nil,f,lc,e)\n\tlocal mg2=Duel.GetMatchingGroup(Auxiliary.LExtraFilter,tp,LOCATION_HAND+LOCATION_SZONE,LOCATION_ONFIELD,nil,f,lc,tp)\n\tif mg2:GetCount()>0 then mg:Merge(mg2) end\n\treturn mg\nend\nfunction Auxiliary.LCheckOtherMaterial(c,mg,lc,tp)\n\tlocal le={c:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)}\n\tlocal res1=false\n\tlocal res2=true\n\tfor _,te in pairs(le) do\n\t\tlocal f=te:GetValue()\n\t\tlocal related,valid=f(te,lc,mg,c,tp)\n\t\tif related then res2=false end\n\t\tif related and valid then res1=true end\n\tend\n\treturn res1 or res2\nend\nfunction Auxiliary.LUncompatibilityFilter(c,sg,lc,tp)\n\tlocal mg=sg:Filter(Auxiliary.TRUE,c)\n\treturn not Auxiliary.LCheckOtherMaterial(c,mg,lc,tp)\nend\nfunction Auxiliary.LCheckGoal(sg,tp,lc,gf,lmat)\n\treturn sg:CheckWithSumEqual(Auxiliary.GetLinkCount,lc:GetLink(),#sg,#sg)\n\t\tand Duel.GetLocationCountFromEx(tp,tp,sg,lc)>0 and (not gf or gf(sg,lc,tp))\n\t\tand not sg:IsExists(Auxiliary.LUncompatibilityFilter,1,nil,sg,lc,tp)\n\t\tand (not lmat or sg:IsContains(lmat))\nend\nfunction Auxiliary.LExtraMaterialCount(mg,lc,tp)\n\tfor tc in Auxiliary.Next(mg) do\n\t\tlocal le={tc:IsHasEffect(EFFECT_EXTRA_LINK_MATERIAL,tp)}\n\t\tfor _,te in pairs(le) do\n\t\t\tlocal sg=mg:Filter(Auxiliary.TRUE,tc)\n\t\t\tlocal f=te:GetValue()\n\t\t\tlocal related,valid=f(te,lc,sg,tc,tp)\n\t\t\tif related and valid then\n\t\t\t\tte:UseCountLimit(tp)\n\t\t\tend\n\t\tend\n\tend\nend\nfunction Auxiliary.LinkCondition(f,minct,maxct,gf)\n\treturn\tfunction(e,c,og,lmat,min,max)\n\t\t\t\tif c==nil then return true end\n\t\t\t\tif c:IsType(TYPE_PENDULUM) and c:IsFaceup() then return false end\n\t\t\t\tlocal minc=minct\n\t\t\t\tlocal maxc=maxct\n\t\t\t\tif min then\n\t\t\t\t\tif min>minc then minc=min end\n\t\t\t\t\tif max<maxc then maxc=max end\n\t\t\t\t\tif minc>maxc then return false end\n\t\t\t\tend\n\t\t\t\tlocal tp=c:GetControler()\n\t\t\t\tlocal mg=nil\n\t\t\t\tif og then\n\t\t\t\t\tmg=og:Filter(Auxiliary.LConditionFilter,nil,f,c,e)\n\t\t\t\telse\n\t\t\t\t\tmg=Auxiliary.GetLinkMaterials(tp,f,c,e)\n\t\t\t\tend\n\t\t\t\tif lmat~=nil then\n\t\t\t\t\tif not Auxiliary.LConditionFilter(lmat,f,c,e) then return false end\n\t\t\t\t\tmg:AddCard(lmat)\n\t\t\t\tend\n\t\t\t\tlocal fg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_LMATERIAL)\n\t\t\t\tif fg:IsExists(Auxiliary.MustMaterialCounterFilter,1,nil,mg) then return false end\n\t\t\t\tDuel.SetSelectedCard(fg)\n\t\t\t\treturn mg:CheckSubGroup(Auxiliary.LCheckGoal,minc,maxc,tp,c,gf,lmat)\n\t\t\tend\nend\nfunction Auxiliary.LinkTarget(f,minct,maxct,gf)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp,chk,c,og,lmat,min,max)\n\t\t\t\tlocal minc=minct\n\t\t\t\tlocal maxc=maxct\n\t\t\t\tif min then\n\t\t\t\t\tif min>minc then minc=min end\n\t\t\t\t\tif max<maxc then maxc=max end\n\t\t\t\t\tif minc>maxc then return false end\n\t\t\t\tend\n\t\t\t\tlocal mg=nil\n\t\t\t\tif og then\n\t\t\t\t\tmg=og:Filter(Auxiliary.LConditionFilter,nil,f,c,e)\n\t\t\t\telse\n\t\t\t\t\tmg=Auxiliary.GetLinkMaterials(tp,f,c,e)\n\t\t\t\tend\n\t\t\t\tif lmat~=nil then\n\t\t\t\t\tif not Auxiliary.LConditionFilter(lmat,f,c,e) then return false end\n\t\t\t\t\tmg:AddCard(lmat)\n\t\t\t\tend\n\t\t\t\tlocal fg=Duel.GetMustMaterial(tp,EFFECT_MUST_BE_LMATERIAL)\n\t\t\t\tDuel.SetSelectedCard(fg)\n\t\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_LMATERIAL)\n\t\t\t\tlocal cancel=Duel.IsSummonCancelable()\n\t\t\t\tlocal sg=mg:SelectSubGroup(tp,Auxiliary.LCheckGoal,cancel,minc,maxc,tp,c,gf,lmat)\n\t\t\t\tif sg then\n\t\t\t\t\tsg:KeepAlive()\n\t\t\t\t\te:SetLabelObject(sg)\n\t\t\t\t\treturn true\n\t\t\t\telse return false end\n\t\t\tend\nend\nfunction Auxiliary.LinkOperation(f,minct,maxct,gf)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp,c,og,lmat,min,max)\n\t\t\t\tlocal g=e:GetLabelObject()\n\t\t\t\tc:SetMaterial(g)\n\t\t\t\tAuxiliary.LExtraMaterialCount(g,c,tp)\n\t\t\t\tDuel.SendtoGrave(g,REASON_MATERIAL+REASON_LINK)\n\t\t\t\tg:DeleteGroup()\n\t\t\tend\nend\n\n--Must use X as material\nfunction Auxiliary.MustMaterialCheck(v,tp,code)\n\tlocal g=Duel.GetMustMaterial(tp,code)\n\tif not v then\n\t\tif code==EFFECT_MUST_BE_XMATERIAL and Duel.IsPlayerAffectedByEffect(tp,67120578) then return false end\n\t\tif code==EFFECT_MUST_BE_SMATERIAL and Duel.IsPlayerAffectedByEffect(tp,8173184) then return false end\n\t\treturn #g==0\n\tend\n\treturn Duel.CheckMustMaterial(tp,v,code)\nend\nfunction Auxiliary.MustMaterialCounterFilter(c,g)\n\treturn not g:IsContains(c)\nend\n\n--Summon Condition\n--sp_summon condition for fusion monster\nfunction Auxiliary.fuslimit(e,se,sp,st)\n\treturn st&SUMMON_TYPE_FUSION==SUMMON_TYPE_FUSION\nend\n--sp_summon condition for ritual monster\nfunction Auxiliary.ritlimit(e,se,sp,st)\n\treturn st&SUMMON_TYPE_RITUAL==SUMMON_TYPE_RITUAL\nend\n--sp_summon condition for synchro monster\nfunction Auxiliary.synlimit(e,se,sp,st)\n\treturn st&SUMMON_TYPE_SYNCHRO==SUMMON_TYPE_SYNCHRO\nend\n--sp_summon condition for xyz monster\nfunction Auxiliary.xyzlimit(e,se,sp,st)\n\treturn st&SUMMON_TYPE_XYZ==SUMMON_TYPE_XYZ\nend\n--sp_summon condition for pendulum monster\nfunction Auxiliary.penlimit(e,se,sp,st)\n\treturn st&SUMMON_TYPE_PENDULUM==SUMMON_TYPE_PENDULUM\nend\n--sp_summon condition for link monster\nfunction Auxiliary.linklimit(e,se,sp,st)\n\treturn st&SUMMON_TYPE_LINK==SUMMON_TYPE_LINK\nend\n--sp_summon condition for /Assault Mode\nfunction Auxiliary.AssaultModeLimit(e,se,sp,st)\n\treturn st==SUMMON_TYPE_SPECIAL+SUMMON_VALUE_ASSAULT_MODE or se:GetHandler():IsCode(80280737)\nend\n--sp_summon condition for Masked HERO\nfunction Auxiliary.MaskChangeLimit(e,se,sp,st)\n\treturn st==SUMMON_TYPE_SPECIAL+SUMMON_VALUE_MASK_CHANGE or se:GetHandler():IsCode(21143940)\nend\n--sp_summon condition for Evil HERO\nfunction Auxiliary.DarkFusionLimit(e,se,sp,st)\n\treturn se:GetHandler():IsCode(94820406)\n\t\tor st==SUMMON_VALUE_DARK_FUSION\n\t\tor (Duel.IsPlayerAffectedByEffect(sp,72043279) and st&SUMMON_TYPE_FUSION==SUMMON_TYPE_FUSION)\nend\n--sp_summon condition for Fossil\nfunction Auxiliary.FossilFusionLimit(e,se,sp,st)\n\treturn st==SUMMON_VALUE_FOSSIL_FUSION or se:GetHandler():IsCode(59419719)\n\t\tor not e:GetHandler():IsLocation(LOCATION_EXTRA)\nend\n\n-- Deckhand fix (F13): the two functions below replace the pinned ones of the same name above. They are\n-- reached from three places, all in this file: SynMixCheck from SynMixFilter4 (the condition's search and\n-- the selection's filters), and SynMixCheckRecursive directly from SynMixTarget's material selection\n-- (mg2:Filter at the \"for i=0,maxc-1\" loop). Both keep their signatures and candidate sets.\n-- SynMixCheckGoal and SynMixCheckPrune read the chosen cards as a set, so every ordering of one\n-- subset gives the same answer; the pinned search still tried them all. This visits each subset\n-- once. The candidates are taken in ascending minimum Synchro Level, the ordering whose prefix\n-- sums are smallest, so a subset survives SynMixCheckPrune here exactly when some ordering of it\n-- survived before: the set of subsets examined, and so the result, is unchanged.\nfunction Auxiliary.SynMixCandidates(mg,sg,syncard)\n\tlocal rest={}\n\tlocal lv={}\n\tfor c in Auxiliary.Next(mg) do\n\t\tif not sg:IsContains(c) then\n\t\t\trest[#rest+1]=c\n\t\t\tlv[c]=Auxiliary.GetMinSynchroLevel(c,syncard)\n\t\tend\n\tend\n\tlocal pos={}\n\tfor i,c in ipairs(rest) do pos[c]=i end\n\ttable.sort(rest,function(a,b)\n\t\tif lv[a]~=lv[b] then return lv[a]<lv[b] end\n\t\treturn pos[a]<pos[b]\n\tend)\n\treturn rest\nend\nfunction Auxiliary.SynMixCheckCombos(rest,from,tp,sg,ct,minc,maxc,syncard,sg1,smat,gc,mgchk,goalchk,fulltraversal)\n\tfor i=from,#rest do\n\t\tlocal c=rest[i]\n\t\tsg:AddCard(c)\n\t\tlocal res=Auxiliary.SynMixCheckGoal(tp,sg,minc,ct+1,syncard,sg1,smat,gc,mgchk,goalchk)\n\t\tif not res and ct+1<maxc\n\t\t\tand (fulltraversal or not Auxiliary.SynMixCheckPrune(sg,sg1,syncard)) then\n\t\t\tres=Auxiliary.SynMixCheckCombos(rest,i+1,tp,sg,ct+1,minc,maxc,syncard,sg1,smat,gc,mgchk,goalchk,fulltraversal)\n\t\tend\n\t\tsg:RemoveCard(c)\n\t\tif res then return true end\n\tend\n\treturn false\nend\nfunction Auxiliary.SynMixCheck(mg,sg1,minc,maxc,syncard,mg1,smat,gc,mgchk,goalchk)\n\tlocal tp=syncard:GetControler()\n\tlocal sg=Group.CreateGroup()\n\tif minc<=0 and Auxiliary.SynMixCheckGoal(tp,sg1,0,0,syncard,sg,smat,gc,mgchk,goalchk) then return true end\n\tif maxc==0 then return false end\n\tlocal fulltraversal=#mg<=5 or mg1:IsExists(Card.IsHasEffect,1,nil,89818984)\n\treturn Auxiliary.SynMixCheckCombos(Auxiliary.SynMixCandidates(mg,sg,syncard),1,tp,sg,0,minc,maxc,syncard,sg1,smat,gc,mgchk,goalchk,fulltraversal)\nend\nfunction Auxiliary.SynMixCheckRecursive(c,tp,sg,mg,ct,minc,maxc,syncard,sg1,smat,gc,mgchk,goalchk,fulltraversal)\n\tsg:AddCard(c)\n\tct=ct+1\n\tlocal res=Auxiliary.SynMixCheckGoal(tp,sg,minc,ct,syncard,sg1,smat,gc,mgchk,goalchk)\n\tif not res and ct<maxc\n\t\tand (fulltraversal or not Auxiliary.SynMixCheckPrune(sg,sg1,syncard)) then\n\t\tres=Auxiliary.SynMixCheckCombos(Auxiliary.SynMixCandidates(mg,sg,syncard),1,tp,sg,ct,minc,maxc,syncard,sg1,smat,gc,mgchk,goalchk,fulltraversal)\n\tend\n\tsg:RemoveCard(c)\n\tct=ct-1\n\treturn res\nend\n\n-- Deckhand fix (F14): the Fusion-repeat material check (AddFusionProcMixRep and the CodeRep, FunRep,\n-- FunFunRep, CodeFunRep and Code2FunRep procedures built on it: \"A + 1 or more B\"). Two searches walked\n-- every ORDERING where the answer depends only on the set: FCheckMixRepSelectedCond assigned roles to the\n-- already-selected materials by trying them in every order (k! for k selected), and FCheckSelectMixRep\n-- picked the repeat-role materials from the candidates as sequences (n!/(n-k)! for n candidates). A\n-- selection that cannot complete (a second copy of the fixed-role card, say) ran the whole space: Frightfur\n-- Fusion with 12 materials picked from a 28-card graveyard never returned (QA sweep job 25800). The goal\n-- checks (FCheckMixRepGoalCheck, FCheckAdditional, GetLocationCountFromEx) read the chosen cards as a set,\n-- and the substitute flag counts substitutes, so one ordering per assignment suffices. Here the selected\n-- materials take their roles in a fixed order (each must take one), and once the fixed roles are filled the\n-- repeat-role picks are combinations in candidate order. The fixed-role picks and the no-free-zone branch\n-- (FCheckSelectMixRepM) are as pinned. FCheckMixRepSelected and FCheckSelectMixRepAll stay defined.\nfunction Auxiliary.FMixRepListOf(group,g)\n\tlocal t={}\n\tfor c in Auxiliary.Next(group) do\n\t\tif not g:IsContains(c) then t[#t+1]=c end\n\tend\n\treturn t\nend\nfunction Auxiliary.FCheckMixRepAssign(list,i,tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,...)\n\tif i>#list then\n\t\treturn Auxiliary.FCheckSelectMixRep(tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,...)\n\tend\n\tlocal cond=function(tp,mg,sg,g,...)\n\t\treturn Auxiliary.FCheckMixRepAssign(list,i+1,tp,mg,sg,g,...)\n\tend\n\treturn Auxiliary.FCheckMixRepTemplate(list[i],cond,tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,...)\nend\nfunction Auxiliary.FCheckMixRepSelectedCond(tp,mg,sg,g,...)\n\tif g:GetCount()<sg:GetCount() then\n\t\treturn Auxiliary.FCheckMixRepAssign(Auxiliary.FMixRepListOf(sg,g),1,tp,mg,sg,g,...)\n\telse\n\t\treturn Auxiliary.FCheckSelectMixRep(tp,mg,sg,g,...)\n\tend\nend\nfunction Auxiliary.FCheckSelectMixRep(tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,...)\n\treturn Auxiliary.FCheckSelectMixRepFrom(nil,1,tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,...)\nend\nfunction Auxiliary.FCheckSelectMixRepFrom(rest,from,tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,...)\n\tlocal chkf=chkfnf&0xff\n\tif Auxiliary.FCheckAdditional and not Auxiliary.FCheckAdditional(tp,g,fc) then return false end\n\tif chkf==PLAYER_NONE or Duel.GetLocationCountFromEx(tp,tp,g,fc)>0 then\n\t\tif minc<=0 and #{...}==0 and Auxiliary.FCheckMixRepGoalCheck(tp,g,fc,chkfnf) then return true end\n\t\tlocal fun2=...\n\t\tif fun2 then\n\t\t\tfor c in Auxiliary.Next(mg) do\n\t\t\t\tif not g:IsContains(c) and fun2(c,fc,sub) then\n\t\t\t\t\tg:AddCard(c)\n\t\t\t\t\tlocal subf2=sub and fun2(c,fc,false)\n\t\t\t\t\tlocal res=Auxiliary.FCheckSelectMixRepFrom(nil,1,tp,mg,sg,g,fc,subf2,chkfnf,fun1,minc,maxc,select(2,...))\n\t\t\t\t\tg:RemoveCard(c)\n\t\t\t\t\tif res then return true end\n\t\t\t\tend\n\t\t\tend\n\t\t\treturn false\n\t\tend\n\t\tif maxc<=0 then return false end\n\t\tif not rest then\n\t\t\trest=Auxiliary.FMixRepListOf(mg,g)\n\t\t\tfrom=1\n\t\tend\n\t\tfor i=from,#rest do\n\t\t\tlocal c=rest[i]\n\t\t\tif not g:IsContains(c) and fun1(c,fc,sub) then\n\t\t\t\tg:AddCard(c)\n\t\t\t\tlocal subf1=sub and fun1(c,fc,false)\n\t\t\t\tlocal res=Auxiliary.FCheckSelectMixRepFrom(rest,i+1,tp,mg,sg,g,fc,subf1,chkfnf,fun1,minc-1,maxc-1)\n\t\t\t\tg:RemoveCard(c)\n\t\t\t\tif res then return true end\n\t\t\tend\n\t\tend\n\t\treturn false\n\telse\n\t\treturn mg:IsExists(Auxiliary.FCheckSelectMixRepM,1,g,tp,mg,sg,g,fc,sub,chkfnf,fun1,minc,maxc,...)\n\tend\nend\nfunction Auxiliary.FSelectMixRep(c,tp,mg,sg,fc,sub,chkfnf,...)\n\tsg:AddCard(c)\n\tlocal res=false\n\tif Auxiliary.FCheckAdditional and not Auxiliary.FCheckAdditional(tp,sg,fc) then\n\t\tres=false\n\telseif Auxiliary.FCheckMixRepGoal(tp,sg,fc,sub,chkfnf,...) then\n\t\tres=true\n\telse\n\t\tlocal g=Group.CreateGroup()\n\t\tres=Auxiliary.FCheckMixRepAssign(Auxiliary.FMixRepListOf(sg,g),1,tp,mg,sg,g,fc,sub,chkfnf,...)\n\tend\n\tsg:RemoveCard(c)\n\treturn res\nend\n","utility.lua":"-- Deckhand bug fix, every format. GPL-2.0, like the script it modifies:\n-- mycard/ygopro-scripts utility.lua at b83db1cc3f512d3bec2faafb9ecf199143332be1.\n-- Bug (F6): the core traps (WASM \"memory access out of bounds\") when Card.GetAttackableTarget is asked of a card whose controller is PLAYER_NONE, as an Xyz Material's is. Repro: QA sweep jobs 47379 and 47378.\n-- Fix: the pinned file unchanged, plus one wrapper at its end (\"Deckhand fix (F6)\"). Upstream: not reported (owner decision 2026-10-11).\nAuxiliary={}\naux=Auxiliary\nPOS_FACEUP_DEFENCE=POS_FACEUP_DEFENSE\nPOS_FACEDOWN_DEFENCE=POS_FACEDOWN_DEFENSE\nRACE_CYBERS=RACE_CYBERSE\nNULL_VALUE=-10\n\nfunction GetID()\n\tlocal offset=self_code<100000000 and 1 or 100\n\treturn self_table,self_code,offset\nend\n\n--the lua version of the bit32 lib, which is deprecated in lua 5.3\nbit={}\nfunction bit.band(a,b)\n\treturn a&b\nend\nfunction bit.bor(a,b)\n\treturn a|b\nend\nfunction bit.bxor(a,b)\n\treturn a~b\nend\nfunction bit.lshift(a,b)\n\treturn a<<b\nend\nfunction bit.rshift(a,b)\n\treturn a>>b\nend\nfunction bit.bnot(a)\n\treturn ~a\nend\nlocal function fieldargs(f,width)\n\tlocal w=width or 1\n\tassert(f>=0,\"field cannot be negative\")\n\tassert(w>0,\"width must be positive\")\n\tassert(f+w<=32,\"trying to access non-existent bits\")\n\treturn f,~(-1<<w)\nend\nfunction bit.extract(r,field,width)\n\twidth=width or 1\n\tlocal f,m=fieldargs(field,width)\n\treturn (r>>f)&m\nend\nfunction bit.replace(r,v,field,width)\n\twidth=width or 1\n\tlocal f,m=fieldargs(field,width)\n\treturn (r&~(m<<f))|((v&m)<< f)\nend\n\n---Subgroup check function\n---@param sg Group\n---@param c Card|nil\n---@param g Group\n---@return boolean\nAuxiliary.GCheckAdditional=function(sg,c,g) return true end\n\n--the table of xyz number\nAuxiliary.xyz_number={}\nfunction Auxiliary.GetXyzNumber(v)\n\tlocal id\n\tif Auxiliary.GetValueType(v)==\"Card\" then id=v:GetCode() end\n\tif Auxiliary.GetValueType(v)==\"number\" then id=v end\n\treturn Auxiliary.xyz_number[id]\nend\n\n--iterator for getting playerid of current turn player and the other player\nfunction Auxiliary.TurnPlayers()\n\tlocal i=0\n\treturn\tfunction()\n\t\t\t\ti=i+1\n\t\t\t\tif i==1 then return Duel.GetTurnPlayer() end\n\t\t\t\tif i==2 then return 1-Duel.GetTurnPlayer() end\n\t\t\tend\nend\n\nAuxiliary.idx_table=table.pack(1,2,3,4,5,6,7,8)\n\nfunction Auxiliary.Stringid(code,id)\n\treturn code*16+id\nend\nfunction Auxiliary.Next(g)\n\tlocal first=true\n\treturn\tfunction()\n\t\t\t\tif first then first=false return g:GetFirst()\n\t\t\t\telse return g:GetNext() end\n\t\t\tend\nend\nfunction Auxiliary.NULL()\nend\nfunction Auxiliary.TRUE()\n\treturn true\nend\nfunction Auxiliary.FALSE()\n\treturn false\nend\nfunction Auxiliary.AND(...)\n\tlocal function_list={...}\n\treturn\tfunction(...)\n\t\t\t\tlocal res=false\n\t\t\t\tfor i,f in ipairs(function_list) do\n\t\t\t\t\tres=f(...)\n\t\t\t\t\tif not res then return res end\n\t\t\t\tend\n\t\t\t\treturn res\n\t\t\tend\nend\nfunction Auxiliary.OR(...)\n\tlocal function_list={...}\n\treturn\tfunction(...)\n\t\t\t\tlocal res=false\n\t\t\t\tfor i,f in ipairs(function_list) do\n\t\t\t\t\tres=f(...)\n\t\t\t\t\tif res then return res end\n\t\t\t\tend\n\t\t\t\treturn res\n\t\t\tend\nend\nfunction Auxiliary.NOT(f)\n\treturn\tfunction(...)\n\t\t\t\treturn not f(...)\n\t\t\tend\nend\nfunction Auxiliary.BeginPuzzle(effect)\n\tlocal e1=Effect.GlobalEffect()\n\te1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)\n\te1:SetCode(EVENT_TURN_END)\n\te1:SetCountLimit(1)\n\te1:SetOperation(Auxiliary.PuzzleOp)\n\tDuel.RegisterEffect(e1,0)\n\tlocal e2=Effect.GlobalEffect()\n\te2:SetType(EFFECT_TYPE_FIELD)\n\te2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)\n\te2:SetCode(EFFECT_SKIP_DP)\n\te2:SetTargetRange(1,0)\n\tDuel.RegisterEffect(e2,0)\n\tlocal e3=Effect.GlobalEffect()\n\te3:SetType(EFFECT_TYPE_FIELD)\n\te3:SetProperty(EFFECT_FLAG_PLAYER_TARGET)\n\te3:SetCode(EFFECT_SKIP_SP)\n\te3:SetTargetRange(1,0)\n\tDuel.RegisterEffect(e3,0)\nend\nfunction Auxiliary.PuzzleOp(e,tp)\n\tDuel.SetLP(0,0)\nend\n---Duel.SelectOption with option condition\n---Return value starts from 1, different from Duel.SelectOption\n---@param tp integer\n---@param ... table {condition, option[, value]}\n---@return integer\nfunction Auxiliary.SelectFromOptions(tp,...)\n\tlocal options={...}\n\tlocal ops={}\n\tlocal opvals={}\n\tfor i=1,#options do\n\t\tif options[i][1] then\n\t\t\ttable.insert(ops,options[i][2])\n\t\t\ttable.insert(opvals,options[i][3] or i)\n\t\tend\n\tend\n\tif #ops==0 then return nil end\n\tlocal select=Duel.SelectOption(tp,table.unpack(ops))\n\treturn opvals[select+1]\nend\n--register effect of return to hand for Spirit monsters\nfunction Auxiliary.EnableSpiritReturn(c,event1,...)\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_CONTINUOUS)\n\te1:SetCode(event1)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)\n\te1:SetOperation(Auxiliary.SpiritReturnReg)\n\tc:RegisterEffect(e1)\n\tfor i,event in ipairs{...} do\n\t\tlocal e2=e1:Clone()\n\t\te2:SetCode(event)\n\t\tc:RegisterEffect(e2)\n\tend\nend\nfunction Auxiliary.SpiritReturnReg(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_F)\n\te1:SetDescription(1104)\n\te1:SetCategory(CATEGORY_TOHAND)\n\te1:SetCode(EVENT_PHASE+PHASE_END)\n\te1:SetRange(LOCATION_MZONE)\n\te1:SetCountLimit(1)\n\te1:SetReset(RESET_EVENT+0xd7e0000+RESET_PHASE+PHASE_END)\n\te1:SetCondition(Auxiliary.SpiritReturnConditionForced)\n\te1:SetTarget(Auxiliary.SpiritReturnTargetForced)\n\te1:SetOperation(Auxiliary.SpiritReturnOperation)\n\tc:RegisterEffect(e1)\n\tlocal e2=e1:Clone()\n\te2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_O)\n\te2:SetCondition(Auxiliary.SpiritReturnConditionOptional)\n\te2:SetTarget(Auxiliary.SpiritReturnTargetOptional)\n\tc:RegisterEffect(e2)\nend\nfunction Auxiliary.SpiritReturnConditionForced(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\treturn not c:IsHasEffect(EFFECT_SPIRIT_DONOT_RETURN) and not c:IsHasEffect(EFFECT_SPIRIT_MAYNOT_RETURN)\nend\nfunction Auxiliary.SpiritReturnTargetForced(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return true end\n\tDuel.SetOperationInfo(0,CATEGORY_TOHAND,e:GetHandler(),1,0,0)\nend\nfunction Auxiliary.SpiritReturnConditionOptional(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\treturn not c:IsHasEffect(EFFECT_SPIRIT_DONOT_RETURN) and c:IsHasEffect(EFFECT_SPIRIT_MAYNOT_RETURN)\nend\nfunction Auxiliary.SpiritReturnTargetOptional(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return e:GetHandler():IsAbleToHand() end\n\tDuel.SetOperationInfo(0,CATEGORY_TOHAND,e:GetHandler(),1,0,0)\nend\nfunction Auxiliary.SpiritReturnOperation(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tif c:IsRelateToEffect(e) then\n\t\tDuel.SendtoHand(c,nil,REASON_EFFECT)\n\tend\nend\nfunction Auxiliary.EnableNeosReturn(c,operation,set_category)\n\t--return\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(1193)\n\te1:SetCategory(CATEGORY_TODECK)\n\te1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_F)\n\te1:SetCode(EVENT_PHASE+PHASE_END)\n\te1:SetRange(LOCATION_MZONE)\n\te1:SetCountLimit(1)\n\te1:SetCondition(Auxiliary.NeosReturnConditionForced)\n\te1:SetTarget(Auxiliary.NeosReturnTargetForced(set_category))\n\te1:SetOperation(operation)\n\tc:RegisterEffect(e1)\n\tlocal e2=e1:Clone()\n\te2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_O)\n\te2:SetCondition(Auxiliary.NeosReturnConditionOptional)\n\te2:SetTarget(Auxiliary.NeosReturnTargetOptional(set_category))\n\tc:RegisterEffect(e2)\n\treturn e1,e2\nend\nfunction Auxiliary.NeosReturnConditionForced(e,tp,eg,ep,ev,re,r,rp)\n\treturn not e:GetHandler():IsHasEffect(42015635)\nend\nfunction Auxiliary.NeosReturnTargetForced(set_category)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp,chk)\n\t\t\t\tif chk==0 then return true end\n\t\t\t\tDuel.SetOperationInfo(0,CATEGORY_TODECK,e:GetHandler(),1,0,0)\n\t\t\t\tif set_category then set_category(e,tp,eg,ep,ev,re,r,rp) end\n\t\t\tend\nend\nfunction Auxiliary.NeosReturnConditionOptional(e,tp,eg,ep,ev,re,r,rp)\n\treturn e:GetHandler():IsHasEffect(42015635)\nend\nfunction Auxiliary.NeosReturnTargetOptional(set_category)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp,chk)\n\t\t\t\tif chk==0 then return e:GetHandler():IsAbleToExtra() end\n\t\t\t\tDuel.SetOperationInfo(0,CATEGORY_TODECK,e:GetHandler(),1,0,0)\n\t\t\t\tif set_category then set_category(e,tp,eg,ep,ev,re,r,rp) end\n\t\t\tend\nend\n---add \"Toss a coin and get the following effects\" effect to Arcana Force monsters\n---@param c Card\n---@param event1 integer\n---@param ... integer\nfunction Auxiliary.EnableArcanaCoin(c,event1,...)\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(1623)\n\te1:SetCategory(CATEGORY_COIN)\n\te1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_F)\n\te1:SetCode(event1)\n\te1:SetTarget(Auxiliary.ArcanaCoinTarget)\n\te1:SetOperation(Auxiliary.ArcanaCoinOperation)\n\tc:RegisterEffect(e1)\n\tfor _,event in ipairs{...} do\n\t\tlocal e2=e1:Clone()\n\t\te2:SetCode(event)\n\t\tc:RegisterEffect(e2)\n\tend\nend\nfunction Auxiliary.ArcanaCoinTarget(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return true end\n\tDuel.SetOperationInfo(0,CATEGORY_COIN,nil,0,tp,1)\nend\nfunction Auxiliary.ArcanaCoinOperation(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tlocal res=0\n\tlocal toss=false\n\tif Duel.IsPlayerAffectedByEffect(tp,73206827) then\n\t\tres=1-Duel.SelectOption(tp,60,61)\n\telse\n\t\tres=Duel.TossCoin(tp,1)\n\t\ttoss=true\n\tend\n\tif not c:IsRelateToEffect(e) or c:IsFacedown() then return end\n\tif toss then\n\t\tc:RegisterFlagEffect(FLAG_ID_REVERSAL_OF_FATE,RESET_EVENT+RESETS_STANDARD,0,1)\n\tend\n\tc:RegisterFlagEffect(FLAG_ID_ARCANA_COIN,RESET_EVENT+RESETS_STANDARD,EFFECT_FLAG_CLIENT_HINT,1,res,63-res)\nend\n---condition of Arcana Force monster effect from coin toss\n---@param e Effect\n---@return boolean\nfunction Auxiliary.ArcanaCondition(e)\n\treturn e:GetHandler():GetFlagEffect(FLAG_ID_ARCANA_COIN)>0\nend\nfunction Auxiliary.IsUnionState(effect)\n\tlocal c=effect:GetHandler()\n\treturn c:IsHasEffect(EFFECT_UNION_STATUS) and c:GetEquipTarget()\nend\n--set EFFECT_EQUIP_LIMIT after equipping\nfunction Auxiliary.SetUnionState(c)\n\tlocal eset={c:IsHasEffect(EFFECT_UNION_LIMIT)}\n\tif #eset==0 then return end\n\tlocal e0=Effect.CreateEffect(c)\n\te0:SetType(EFFECT_TYPE_SINGLE)\n\te0:SetCode(EFFECT_EQUIP_LIMIT)\n\te0:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)\n\te0:SetValue(eset[1]:GetValue())\n\te0:SetReset(RESET_EVENT+RESETS_STANDARD)\n\tc:RegisterEffect(e0)\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_SINGLE)\n\te1:SetCode(EFFECT_UNION_STATUS)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)\n\te1:SetReset(RESET_EVENT+RESETS_STANDARD)\n\tc:RegisterEffect(e1)\n\tif c.old_union then\n\t\tlocal e2=e1:Clone()\n\t\te2:SetCode(EFFECT_OLDUNION_STATUS)\n\t\tc:RegisterEffect(e2)\n\tend\nend\n--uc: the union monster to be equipped, tc: the target monster\nfunction Auxiliary.CheckUnionEquip(uc,tc,exclude_modern_count)\n\tlocal modern_count,old_count=tc:GetUnionCount()\n\tif exclude_modern_count then modern_count=modern_count-exclude_modern_count end\n\tif uc.old_union then return modern_count==0\n\telse return old_count==0 end\nend\n--EFFECT_DESTROY_SUBSTITUTE filter for modern union monsters\nfunction Auxiliary.UnionReplaceFilter(e,re,r,rp)\n\treturn r&(REASON_BATTLE+REASON_EFFECT)~=0\nend\n---add effect to modern union monsters\n---@param c Card\n---@param filter function\nfunction Auxiliary.EnableUnionAttribute(c,filter)\n\tlocal equip_limit=Auxiliary.UnionEquipLimit(filter)\n\t--destroy sub\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_EQUIP)\n\te1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)\n\te1:SetCode(EFFECT_DESTROY_SUBSTITUTE)\n\te1:SetValue(Auxiliary.UnionReplaceFilter)\n\tc:RegisterEffect(e1)\n\t--limit\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetType(EFFECT_TYPE_SINGLE)\n\te2:SetCode(EFFECT_UNION_LIMIT)\n\te2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)\n\te2:SetValue(equip_limit)\n\tc:RegisterEffect(e2)\n\t--equip\n\tlocal equip_filter=Auxiliary.UnionEquipFilter(filter)\n\tlocal e3=Effect.CreateEffect(c)\n\te3:SetDescription(1068)\n\te3:SetProperty(EFFECT_FLAG_CARD_TARGET)\n\te3:SetCategory(CATEGORY_EQUIP)\n\te3:SetType(EFFECT_TYPE_IGNITION)\n\te3:SetRange(LOCATION_MZONE)\n\te3:SetTarget(Auxiliary.UnionEquipTarget(equip_filter))\n\te3:SetOperation(Auxiliary.UnionEquipOperation(equip_filter))\n\tc:RegisterEffect(e3)\n\t--unequip\n\tlocal e4=Effect.CreateEffect(c)\n\te4:SetDescription(1152)\n\te4:SetCategory(CATEGORY_SPECIAL_SUMMON)\n\te4:SetType(EFFECT_TYPE_IGNITION)\n\te4:SetRange(LOCATION_SZONE)\n\te4:SetTarget(Auxiliary.UnionUnequipTarget)\n\te4:SetOperation(Auxiliary.UnionUnequipOperation)\n\tc:RegisterEffect(e4)\nend\nfunction Auxiliary.UnionEquipFilter(filter)\n\treturn\tfunction(c,tp)\n\t\t\t\tlocal ct1,ct2=c:GetUnionCount()\n\t\t\t\treturn c:IsFaceup() and ct2==0 and c:IsControler(tp) and filter(c)\n\t\t\tend\nend\nfunction Auxiliary.UnionEquipLimit(filter)\n\treturn\tfunction(e,c)\n\t\t\t\treturn (c:IsControler(e:GetHandlerPlayer()) and filter(c)) or e:GetHandler():GetEquipTarget()==c\n\t\t\tend\nend\nfunction Auxiliary.UnionEquipTarget(equip_filter)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\t\t\t\tlocal c=e:GetHandler()\n\t\t\t\tif chkc then return chkc:IsLocation(LOCATION_MZONE) and equip_filter(chkc,tp) end\n\t\t\t\tif chk==0 then return c:GetFlagEffect(FLAG_ID_UNION)==0 and Duel.GetLocationCount(tp,LOCATION_SZONE)>0\n\t\t\t\t\tand Duel.IsExistingTarget(equip_filter,tp,LOCATION_MZONE,0,1,c,tp) end\n\t\t\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_EQUIP)\n\t\t\t\tlocal g=Duel.SelectTarget(tp,equip_filter,tp,LOCATION_MZONE,0,1,1,c,tp)\n\t\t\t\tDuel.SetOperationInfo(0,CATEGORY_EQUIP,g,1,0,0)\n\t\t\t\tc:RegisterFlagEffect(FLAG_ID_UNION,RESET_EVENT+0x7e0000+RESET_PHASE+PHASE_END,0,1)\n\t\t\tend\nend\nfunction Auxiliary.UnionEquipOperation(equip_filter)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp)\n\t\t\t\tlocal c=e:GetHandler()\n\t\t\t\tlocal tc=Duel.GetFirstTarget()\n\t\t\t\tif not c:IsRelateToEffect(e) or c:IsFacedown() then return end\n\t\t\t\tif not tc:IsRelateToEffect(e) or not equip_filter(tc,tp) then\n\t\t\t\t\tDuel.SendtoGrave(c,REASON_RULE)\n\t\t\t\t\treturn\n\t\t\t\tend\n\t\t\t\tif not Duel.Equip(tp,c,tc,false) then return end\n\t\t\t\tAuxiliary.SetUnionState(c)\n\t\t\tend\nend\nfunction Auxiliary.UnionUnequipTarget(e,tp,eg,ep,ev,re,r,rp,chk)\n\tlocal c=e:GetHandler()\n\tif chk==0 then return c:GetFlagEffect(FLAG_ID_UNION)==0 and Duel.GetLocationCount(tp,LOCATION_MZONE)>0\n\t\tand c:GetEquipTarget() and c:IsCanBeSpecialSummoned(e,0,tp,true,false) end\n\tDuel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,c,1,0,0)\n\tc:RegisterFlagEffect(FLAG_ID_UNION,RESET_EVENT+0x7e0000+RESET_PHASE+PHASE_END,0,1)\nend\nfunction Auxiliary.UnionUnequipOperation(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tif not c:IsRelateToEffect(e) then return end\n\tDuel.SpecialSummon(c,0,tp,tp,true,false,POS_FACEUP)\nend\nfunction Auxiliary.EnableChangeCode(c,code,location,condition)\n\tAuxiliary.AddCodeList(c,code)\n\tlocal loc=c:GetOriginalType()&TYPE_MONSTER~=0 and LOCATION_MZONE or LOCATION_SZONE\n\tloc=location or loc\n\tif condition==nil then condition=Auxiliary.TRUE end\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_SINGLE)\n\te1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)\n\te1:SetCode(EFFECT_CHANGE_CODE)\n\te1:SetRange(loc)\n\te1:SetCondition(condition)\n\te1:SetValue(code)\n\tc:RegisterEffect(e1)\n\treturn e1\nend\nfunction Auxiliary.TargetEqualFunction(f,value,...)\n\tlocal ext_params=table.pack(...)\n\treturn\tfunction(effect,target)\n\t\t\t\treturn f(target,table.unpack(ext_params,1,ext_params.n))==value\n\t\t\tend\nend\nfunction Auxiliary.TargetBoolFunction(f,...)\n\tlocal ext_params=table.pack(...)\n\treturn\tfunction(effect,target)\n\t\t\t\treturn f(target,table.unpack(ext_params,1,ext_params.n))\n\t\t\tend\nend\nfunction Auxiliary.FilterEqualFunction(f,value,...)\n\tlocal ext_params=table.pack(...)\n\treturn\tfunction(target)\n\t\t\t\treturn f(target,table.unpack(ext_params,1,ext_params.n))==value\n\t\t\tend\nend\nfunction Auxiliary.FilterBoolFunction(f,...)\n\tlocal ext_params=table.pack(...)\n\treturn\tfunction(target)\n\t\t\t\treturn f(target,table.unpack(ext_params,1,ext_params.n))\n\t\t\tend\nend\nfunction Auxiliary.GetValueType(v)\n\tlocal t=type(v)\n\tif t==\"userdata\" then\n\t\tlocal mt=getmetatable(v)\n\t\tif mt==Group then return \"Group\"\n\t\telseif mt==Effect then return \"Effect\"\n\t\telse return \"Card\" end\n\telse return t end\nend\n--Extra Deck summon count\nfunction Auxiliary.EnableExtraDeckSummonCountLimit()\n\tif Auxiliary.ExtraDeckSummonCountLimit~=nil then return end\n\tAuxiliary.ExtraDeckSummonCountLimit={}\n\tAuxiliary.ExtraDeckSummonCountLimit[0]=1\n\tAuxiliary.ExtraDeckSummonCountLimit[1]=1\n\tlocal ge1=Effect.GlobalEffect()\n\tge1:SetType(EFFECT_TYPE_CONTINUOUS+EFFECT_TYPE_FIELD)\n\tge1:SetCode(EVENT_PHASE_START+PHASE_DRAW)\n\tge1:SetOperation(Auxiliary.ExtraDeckSummonCountLimitReset)\n\tDuel.RegisterEffect(ge1,0)\nend\nfunction Auxiliary.ExtraDeckSummonCountLimitReset()\n\tAuxiliary.ExtraDeckSummonCountLimit[0]=1\n\tAuxiliary.ExtraDeckSummonCountLimit[1]=1\nend\n--Fusion Monster is unnecessary to use this\nfunction Auxiliary.AddMaterialCodeList(c,...)\n\tif c:IsStatus(STATUS_COPYING_EFFECT) then return end\n\tlocal mat={}\n\tfor _,code in ipairs{...} do\n\t\tmat[code]=true\n\tend\n\tif c.material==nil then\n\t\tlocal mt=getmetatable(c)\n\t\tmt.material=mat\n\tend\n\tfor index,_ in pairs(mat) do\n\t\tAuxiliary.AddCodeList(c,index)\n\tend\nend\nfunction Auxiliary.IsMaterialListCode(c,code)\n\treturn c.material and c.material[code]\nend\nfunction Auxiliary.IsMaterialListSetCard(c,setcode)\n\tif not c.material_setcode then return false end\n\tif type(c.material_setcode)==\"table\" then\n\t\tfor i,scode in ipairs(c.material_setcode) do\n\t\t\tif setcode&0xfff==scode&0xfff and setcode&scode==setcode then return true end\n\t\tend\n\telse\n\t\treturn setcode&0xfff==c.material_setcode&0xfff and setcode&c.material_setcode==setcode\n\tend\n\treturn false\nend\nfunction Auxiliary.IsMaterialListType(c,type)\n\treturn c.material_type and type&c.material_type==type\nend\nfunction Auxiliary.GetMaterialListCount(c)\n\tif not c.material_count then return 0,0 end\n\treturn c.material_count[1],c.material_count[2]\nend\nfunction Auxiliary.AddCodeList(c,...)\n\tif c:IsStatus(STATUS_COPYING_EFFECT) then return end\n\tif c.card_code_list==nil then\n\t\tlocal mt=getmetatable(c)\n\t\tmt.card_code_list={}\n\t\tfor _,code in ipairs{...} do\n\t\t\tmt.card_code_list[code]=true\n\t\tend\n\telse\n\t\tfor _,code in ipairs{...} do\n\t\t\tc.card_code_list[code]=true\n\t\tend\n\tend\nend\nfunction Auxiliary.IsCodeListed(c,code)\n\treturn c.card_code_list and c.card_code_list[code]\nend\nfunction Auxiliary.IsCodeOrListed(c,code)\n\treturn c:IsCode(code) or Auxiliary.IsCodeListed(c,code)\nend\nfunction Auxiliary.AddSetNameMonsterList(c,...)\n\tif c:IsStatus(STATUS_COPYING_EFFECT) then return end\n\tif c.setcode_monster_list==nil then\n\t\tlocal mt=getmetatable(c)\n\t\tmt.setcode_monster_list={}\n\t\tfor i,scode in ipairs{...} do\n\t\t\tmt.setcode_monster_list[i]=scode\n\t\tend\n\telse\n\t\tfor i,scode in ipairs{...} do\n\t\t\tc.setcode_monster_list[i]=scode\n\t\tend\n\tend\nend\nfunction Auxiliary.IsSetNameMonsterListed(c,setcode)\n\tif not c.setcode_monster_list then return false end\n\tfor i,scode in ipairs(c.setcode_monster_list) do\n\t\tif setcode&0xfff==scode&0xfff and setcode&scode==setcode then return true end\n\tend\n\treturn false\nend\nfunction Auxiliary.IsCounterAdded(c,counter)\n\tif not c.counter_add_list then return false end\n\tfor i,ccounter in ipairs(c.counter_add_list) do\n\t\tif counter==ccounter then return true end\n\tend\n\treturn false\nend\nfunction Auxiliary.HasMentionedCounter(c,counter)\n\treturn c.mentioned_counter and c.mentioned_counter[counter] or false\nend\nfunction Auxiliary.IsTypeInText(c,type)\n\treturn c.has_text_type and type&c.has_text_type==type\nend\nfunction Auxiliary.GetAttributeCount(g)\n\tif #g==0 then return 0 end\n\tlocal att=0\n\tfor tc in Auxiliary.Next(g) do\n\t\tatt=att|tc:GetAttribute()\n\tend\n\tlocal ct=0\n\twhile att~=0 do\n\t\tif att&0x1~=0 then ct=ct+1 end\n\t\tatt=att>>1\n\tend\n\treturn ct\nend\nfunction Auxiliary.IsInGroup(c,g)\n\treturn g:IsContains(c)\nend\n--Get the row index (from the viewpoint of controller)\nfunction Auxiliary.GetLocalRow(location,sequence)\n\tif location==LOCATION_SZONE then\n\t\tif 0<=sequence and sequence<=4 then\n\t\t\treturn 0\n\t\telse\n\t\t\treturn NULL_VALUE\n\t\tend\n\telseif location==LOCATION_MZONE then\n\t\tif 0<=sequence and sequence<=4 then\n\t\t\treturn 1\n\t\telseif 5<=sequence and sequence<=6 then\n\t\t\treturn 2\n\t\telse\n\t\t\treturn NULL_VALUE\n\t\tend\n\telse\n\t\treturn NULL_VALUE\n\tend\nend\n--Get the global row index (from the viewpoint of 0)\nfunction Auxiliary.GetGlobalRow(p,location,sequence)\n\tlocal row=Auxiliary.GetLocalRow(location,sequence)\n\tif row<0 then\n\t\treturn NULL_VALUE\n\tend\n\tif p==0 then\n\t\treturn row\n\telse\n\t\treturn 4-row\n\tend\nend\n--Get the column index (from the viewpoint of controller)\nfunction Auxiliary.GetLocalColumn(location,sequence)\n\tif location==LOCATION_SZONE then\n\t\tif 0<=sequence and sequence<=4 then\n\t\t\treturn sequence\n\t\telse\n\t\t\treturn NULL_VALUE\n\t\tend\n\telseif location==LOCATION_MZONE then\n\t\tif 0<=sequence and sequence<=4 then\n\t\t\treturn sequence\n\t\telseif sequence==5 then\n\t\t\treturn 1\n\t\telseif sequence==6 then\n\t\t\treturn 3\n\t\telse\n\t\t\treturn NULL_VALUE\n\t\tend\n\telse\n\t\treturn NULL_VALUE\n\tend\nend\n--Get the global column index (from the viewpoint of 0)\nfunction Auxiliary.GetGlobalColumn(p,location,sequence)\n\tlocal column=Auxiliary.GetLocalColumn(location,sequence)\n\tif column<0 then\n\t\treturn NULL_VALUE\n\tend\n\tif p==0 then\n\t\treturn column\n\telse\n\t\treturn 4-column\n\tend\nend\n---Get the global row and column index of c\n---@param c Card\n---@return integer\n---@return integer\nfunction Auxiliary.GetFieldIndex(c)\n\tlocal cp=c:GetControler()\n\tlocal loc=c:GetLocation()\n\tlocal seq=c:GetSequence()\n\treturn Auxiliary.GetGlobalRow(cp,loc,seq),Auxiliary.GetGlobalColumn(cp,loc,seq)\nend\n---Check if c is adjacent to (i,j)\n---@param c Card\n---@param i integer\n---@param j integer\n---@return boolean\nfunction Auxiliary.AdjacentFilter(c,i,j)\n\tlocal row,column=Auxiliary.GetFieldIndex(c)\n\tif row<0 or column<0 then\n\t\treturn false\n\tend\n\treturn (row==i and math.abs(column-j)==1) or (math.abs(row-i)==1 and column==j)\nend\n---Get the card group adjacent to (i,j)\n---@param tp integer\n---@param location1 integer\n---@param location2 integer\n---@param i integer\n---@param j integer\n---@return Group\nfunction Auxiliary.GetAdjacentGroup(tp,location1,location2,i,j)\n\treturn Duel.GetMatchingGroup(Auxiliary.AdjacentFilter,tp,location1,location2,nil,i,j)\nend\n---Get the column index of card c (from the viewpoint of p)\n---@param c Card\n---@param p? integer default: 0\n---@return integer\nfunction Auxiliary.GetColumn(c,p)\n\tp=p or 0\n\tlocal cp=c:GetControler()\n\tlocal loc=c:GetLocation()\n\tlocal seq=c:GetSequence()\n\tlocal column=Auxiliary.GetGlobalColumn(cp,loc,seq)\n\tif column<0 then\n\t\treturn NULL_VALUE\n\tend\n\tif p==0 then\n\t\treturn column\n\telse\n\t\treturn 4-column\n\tend\nend\n--return the column of monster zone seq (from the viewpoint of controller)\nfunction Auxiliary.MZoneSequence(seq)\n\treturn Auxiliary.GetLocalColumn(LOCATION_MZONE,seq)\nend\n--return the column of spell/trap zone seq (from the viewpoint of controller)\nfunction Auxiliary.SZoneSequence(seq)\n\treturn Auxiliary.GetLocalColumn(LOCATION_SZONE,seq)\nend\n--generate the value function of EFFECT_CHANGE_BATTLE_DAMAGE on monsters\nfunction Auxiliary.ChangeBattleDamage(player,value)\n\treturn\tfunction(e,damp)\n\t\t\t\tif player==0 then\n\t\t\t\t\tif e:GetOwnerPlayer()==damp then\n\t\t\t\t\t\treturn value\n\t\t\t\t\telse\n\t\t\t\t\t\treturn -1\n\t\t\t\t\tend\n\t\t\t\telseif player==1 then\n\t\t\t\t\tif e:GetOwnerPlayer()==1-damp then\n\t\t\t\t\t\treturn value\n\t\t\t\t\telse\n\t\t\t\t\t\treturn -1\n\t\t\t\t\tend\n\t\t\t\tend\n\t\t\tend\nend\n--filter for \"negate the effects of a face-up monster\" (無限泡影/Infinite Impermanence)\nfunction Auxiliary.NegateMonsterFilter(c)\n\treturn c:IsFaceup() and not c:IsDisabled() and (c:IsType(TYPE_EFFECT) or c:GetOriginalType()&TYPE_EFFECT~=0)\nend\n--filter for \"negate the effects of an Effect Monster\" (エフェクト・ヴェーラー/Effect Veiler)\nfunction Auxiliary.NegateEffectMonsterFilter(c)\n\treturn c:IsFaceup() and not c:IsDisabled() and c:IsType(TYPE_EFFECT)\nend\n--filter for \"negate the effects of a face-up card\"\nfunction Auxiliary.NegateAnyFilter(c)\n\tif c:IsType(TYPE_TRAPMONSTER) then\n\t\treturn c:IsFaceup()\n\telseif c:IsType(TYPE_SPELL+TYPE_TRAP) then\n\t\treturn c:IsFaceup() and not c:IsDisabled()\n\telse\n\t\treturn Auxiliary.NegateMonsterFilter(c)\n\tend\nend\n--alias for compatibility\nAuxiliary.disfilter1=Auxiliary.NegateAnyFilter\n--condition of EVENT_BATTLE_DESTROYING\nfunction Auxiliary.bdcon(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\treturn c:IsRelateToBattle()\nend\n--condition of EVENT_BATTLE_DESTROYING + opponent monster\nfunction Auxiliary.bdocon(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\treturn c:IsRelateToBattle() and c:IsStatus(STATUS_OPPO_BATTLE)\nend\n--condition of EVENT_BATTLE_DESTROYING + to_grave\nfunction Auxiliary.bdgcon(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tlocal bc=c:GetBattleTarget()\n\treturn c:IsRelateToBattle() and bc:IsLocation(LOCATION_GRAVE) and bc:IsType(TYPE_MONSTER)\nend\n--condition of EVENT_BATTLE_DESTROYING + opponent monster + to_grave\nfunction Auxiliary.bdogcon(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tlocal bc=c:GetBattleTarget()\n\treturn c:IsRelateToBattle() and c:IsStatus(STATUS_OPPO_BATTLE) and bc:IsLocation(LOCATION_GRAVE) and bc:IsType(TYPE_MONSTER)\nend\n--condition of EVENT_DAMAGE_STEP_END + this monster is releate to battle\nfunction Auxiliary.dsercon(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\treturn c:IsRelateToBattle() or c:IsStatus(STATUS_BATTLE_DESTROYED)\nend\n--condition of EVENT_TO_GRAVE + destroyed by opponent\nfunction Auxiliary.dogcon(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\treturn c:IsPreviousControler(tp) and c:IsReason(REASON_DESTROY) and rp==1-tp\nend\n--condition of EVENT_TO_GRAVE + destroyed by opponent + from field\nfunction Auxiliary.dogfcon(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\treturn c:IsPreviousLocation(LOCATION_ONFIELD) and c:IsPreviousControler(tp)\n\t\tand c:IsReason(REASON_DESTROY) and rp==1-tp\nend\n--condition of \"except the turn this card was sent to the Graveyard\"\nfunction Auxiliary.exccon(e)\n\treturn Duel.GetTurnCount()~=e:GetHandler():GetTurnID() or e:GetHandler():IsReason(REASON_RETURN)\nend\n--condition of checking battle phase availability\nfunction Auxiliary.bpcon(e,tp,eg,ep,ev,re,r,rp)\n\treturn Duel.IsAbleToEnterBP() or (Duel.GetCurrentPhase()>=PHASE_BATTLE_START and Duel.GetCurrentPhase()<=PHASE_BATTLE)\nend\n--condition of free chain effects changing ATK/DEF\nfunction Auxiliary.dscon(e,tp,eg,ep,ev,re,r,rp)\n\treturn Duel.GetCurrentPhase()~=PHASE_DAMAGE or not Duel.IsDamageCalculated()\nend\n--flag effect for spell counter\nfunction Auxiliary.chainreg(e,tp,eg,ep,ev,re,r,rp)\n\tif e:GetHandler():GetFlagEffect(FLAG_ID_CHAINING)==0 then\n\t\te:GetHandler():RegisterFlagEffect(FLAG_ID_CHAINING,RESET_EVENT+RESETS_STANDARD-RESET_TURN_SET+RESET_CHAIN,0,1)\n\tend\nend\n--default filter for EFFECT_CANNOT_BE_BATTLE_TARGET\nfunction Auxiliary.imval1(e,c)\n\treturn not c:IsImmuneToEffect(e)\nend\n--filter for EFFECT_INDESTRUCTABLE_EFFECT + self\nfunction Auxiliary.indsval(e,re,rp)\n\treturn rp==e:GetHandlerPlayer()\nend\n--filter for EFFECT_INDESTRUCTABLE_EFFECT + opponent\nfunction Auxiliary.indoval(e,re,rp)\n\treturn rp==1-e:GetHandlerPlayer()\nend\n--filter for EFFECT_CANNOT_BE_EFFECT_TARGET + self\nfunction Auxiliary.tgsval(e,re,rp)\n\treturn rp==e:GetHandlerPlayer()\nend\n--filter for EFFECT_CANNOT_BE_EFFECT_TARGET + opponent\nfunction Auxiliary.tgoval(e,re,rp)\n\treturn rp==1-e:GetHandlerPlayer()\nend\n--filter for non-zero ATK\nfunction Auxiliary.nzatk(c)\n\treturn c:IsFaceup() and c:GetAttack()>0\nend\n--filter for non-zero DEF\nfunction Auxiliary.nzdef(c)\n\treturn c:IsFaceup() and c:GetDefense()>0\nend\n--flag effect for summon/sp_summon turn\nfunction Auxiliary.sumreg(e,tp,eg,ep,ev,re,r,rp)\n\tlocal tc=eg:GetFirst()\n\tlocal code=e:GetLabel()\n\twhile tc do\n\t\tif tc:GetOriginalCode()==code then\n\t\t\ttc:RegisterFlagEffect(code,RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END,0,1)\n\t\tend\n\t\ttc=eg:GetNext()\n\tend\nend\n--for EVENT_BE_MATERIAL effect releated to the summoned monster\nfunction Auxiliary.CreateMaterialReasonCardRelation(c,te)\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_CONTINUOUS)\n\te1:SetCode(EVENT_BE_MATERIAL)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)\n\te1:SetOperation(Auxiliary.MaterialReasonCardReg)\n\te1:SetLabelObject(te)\n\tc:RegisterEffect(e1)\nend\nfunction Auxiliary.MaterialReasonCardReg(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tlocal te=e:GetLabelObject()\n\tc:GetReasonCard():CreateEffectRelation(te)\nend\n--the player tp has token on the field\nfunction Auxiliary.tkfcon(e,tp)\n\tif tp==nil and e~=nil then tp=e:GetHandlerPlayer() end\n\treturn Duel.IsExistingMatchingCard(Card.IsType,tp,LOCATION_ONFIELD,0,1,nil,TYPE_TOKEN)\nend\n--effects inflicting damage to tp\nfunction Auxiliary.damcon1(e,tp,eg,ep,ev,re,r,rp)\n\tlocal e1=Duel.IsPlayerAffectedByEffect(tp,EFFECT_REVERSE_DAMAGE)\n\tlocal e2=Duel.IsPlayerAffectedByEffect(tp,EFFECT_REVERSE_RECOVER)\n\tlocal rd=e1 and not e2\n\tlocal rr=not e1 and e2\n\tlocal ex,cg,ct,cp,cv=Duel.GetOperationInfo(ev,CATEGORY_DAMAGE)\n\tif ex and (cp==tp or cp==PLAYER_ALL) and not rd and not Duel.IsPlayerAffectedByEffect(tp,EFFECT_NO_EFFECT_DAMAGE) then\n\t\treturn true\n\tend\n\tex,cg,ct,cp,cv=Duel.GetOperationInfo(ev,CATEGORY_RECOVER)\n\treturn ex and (cp==tp or cp==PLAYER_ALL) and rr and not Duel.IsPlayerAffectedByEffect(tp,EFFECT_NO_EFFECT_DAMAGE)\nend\n--filter for the immune effect of qli monsters\nfunction Auxiliary.qlifilter(e,te)\n\tif te:IsActiveType(TYPE_MONSTER) and te:IsActivated() then\n\t\tlocal lv=e:GetHandler():GetLevel()\n\t\tlocal ec=te:GetOwner()\n\t\tif ec:IsType(TYPE_LINK) then\n\t\t\treturn false\n\t\telseif ec:IsType(TYPE_XYZ) then\n\t\t\treturn ec:GetOriginalRank()<lv\n\t\telse\n\t\t\treturn ec:GetOriginalLevel()<lv\n\t\tend\n\telse\n\t\treturn false\n\tend\nend\n--sp_summon condition for gladiator beast monsters\nfunction Auxiliary.gbspcon(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tlocal typ=c:GetSpecialSummonInfo(SUMMON_INFO_TYPE)\n\treturn c:IsSummonType(SUMMON_VALUE_GLADIATOR) or (typ&TYPE_MONSTER~=0 and c:IsSpecialSummonSetCard(0x1019))\nend\n--sp_summon condition for evolsaur monsters\nfunction Auxiliary.evospcon(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tlocal typ=c:GetSpecialSummonInfo(SUMMON_INFO_TYPE)\n\treturn c:IsSummonType(SUMMON_VALUE_EVOLTILE) or (typ&TYPE_MONSTER~=0 and c:IsSpecialSummonSetCard(0x304e))\nend\n--filter for necro_valley test\nfunction Auxiliary.NecroValleyFilter(f)\n\treturn\tfunction(target,...)\n\t\t\t\treturn (not f or f(target,...)) and not target:IsHasEffect(EFFECT_NECRO_VALLEY)\n\t\t\tend\nend\n--Necrovalley test for effect with not certain target or not certain action\nfunction Auxiliary.NecroValleyNegateCheck(v)\n\tif not Duel.IsChainDisablable(0) then return false end\n\tlocal g=Group.CreateGroup()\n\tif Auxiliary.GetValueType(v)==\"Card\" then g:AddCard(v) end\n\tif Auxiliary.GetValueType(v)==\"Group\" then g:Merge(v) end\n\tif g:IsExists(Card.IsHasEffect,1,nil,EFFECT_NECRO_VALLEY) then\n\t\tDuel.NegateEffect(0)\n\t\treturn true\n\tend\n\treturn false\nend\n--Ursarctic common summon from hand effect\nfunction Auxiliary.AddUrsarcticSpSummonEffect(c)\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetCategory(CATEGORY_SPECIAL_SUMMON)\n\te1:SetType(EFFECT_TYPE_QUICK_O)\n\te1:SetCode(EVENT_FREE_CHAIN)\n\te1:SetRange(LOCATION_HAND)\n\te1:SetHintTiming(0,TIMINGS_CHECK_MONSTER+TIMING_MAIN_END)\n\te1:SetCondition(Auxiliary.UrsarcticSpSummonCondition)\n\te1:SetCost(Auxiliary.UrsarcticSpSummonCost)\n\te1:SetTarget(Auxiliary.UrsarcticSpSummonTarget)\n\te1:SetOperation(Auxiliary.UrsarcticSpSummonOperation)\n\tc:RegisterEffect(e1)\n\treturn e1\nend\nfunction Auxiliary.UrsarcticSpSummonCondition(e,tp,eg,ep,ev,re,r,rp)\n\treturn Duel.GetCurrentPhase()==PHASE_MAIN1 or Duel.GetCurrentPhase()==PHASE_MAIN2\nend\nfunction Auxiliary.UrsarcticReleaseFilter(c)\n\treturn c:IsLevelAbove(7) and c:IsLocation(LOCATION_HAND)\nend\nfunction Auxiliary.UrsarcticExCostFilter(c,tp)\n\treturn c:IsAbleToRemoveAsCost() and (c:IsHasEffect(16471775,tp) or c:IsHasEffect(89264428,tp))\nend\nfunction Auxiliary.UrsarcticSpSummonCost(e,tp,eg,ep,ev,re,r,rp,chk)\n\tlocal g1=Duel.GetReleaseGroup(tp,true):Filter(Auxiliary.UrsarcticReleaseFilter,e:GetHandler())\n\tlocal g2=Duel.GetMatchingGroup(Auxiliary.UrsarcticExCostFilter,tp,LOCATION_GRAVE,0,nil,tp)\n\tg1:Merge(g2)\n\tif chk==0 then return g1:GetCount()>0 end\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_RELEASE)\n\tlocal tc=g1:Select(tp,1,1,nil):GetFirst()\n\tlocal te=tc:IsHasEffect(16471775,tp) or tc:IsHasEffect(89264428,tp)\n\tif te then\n\t\tte:UseCountLimit(tp)\n\t\tDuel.Remove(tc,POS_FACEUP,REASON_EFFECT+REASON_REPLACE)\n\telse\n\t\tDuel.Release(tc,REASON_COST)\n\tend\nend\nfunction Auxiliary.UrsarcticSpSummonTarget(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0\n\t\tand e:GetHandler():IsCanBeSpecialSummoned(e,0,tp,false,false) end\n\tDuel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,e:GetHandler(),1,0,0)\nend\nfunction Auxiliary.UrsarcticSpSummonOperation(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tif c:IsRelateToEffect(e) then\n\t\tDuel.SpecialSummon(c,0,tp,tp,false,false,POS_FACEUP)\n\tend\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_FIELD)\n\te1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)\n\te1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)\n\te1:SetTargetRange(1,0)\n\te1:SetTarget(Auxiliary.UrsarcticSpSummonLimit)\n\te1:SetReset(RESET_PHASE+PHASE_END)\n\tDuel.RegisterEffect(e1,tp)\nend\nfunction Auxiliary.UrsarcticSpSummonLimit(e,c)\n\treturn c:IsLevel(0)\nend\n--Drytron common summon effect\nfunction Auxiliary.AddDrytronSpSummonEffect(c,func)\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_IGNITION)\n\te1:SetRange(LOCATION_HAND+LOCATION_GRAVE)\n\te1:SetCost(Auxiliary.DrytronSpSummonCost)\n\te1:SetTarget(Auxiliary.DrytronSpSummonTarget)\n\te1:SetOperation(Auxiliary.DrytronSpSummonOperation(func))\n\tc:RegisterEffect(e1)\n\tDuel.AddCustomActivityCounter(97148796,ACTIVITY_SPSUMMON,Auxiliary.DrytronCounterFilter)\n\treturn e1\nend\nfunction Auxiliary.DrytronCounterFilter(c)\n\treturn not c:IsSummonableCard()\nend\nfunction Auxiliary.DrytronCostFilter(c,tp)\n\treturn (c:IsSetCard(0x154) or c:IsType(TYPE_RITUAL)) and c:IsType(TYPE_MONSTER) and Duel.GetMZoneCount(tp,c)>0\n\t\tand (c:IsControler(tp) or c:IsFaceup())\nend\nfunction Auxiliary.DrytronExtraCostFilter(c,tp)\n\treturn c:IsAbleToRemove() and c:IsHasEffect(89771220,tp)\nend\nfunction Auxiliary.DrytronSpSummonCost(e,tp,eg,ep,ev,re,r,rp,chk)\n\te:SetLabel(100)\n\tlocal g1=Duel.GetReleaseGroup(tp,true):Filter(Auxiliary.DrytronCostFilter,e:GetHandler(),tp)\n\tlocal g2=Duel.GetMatchingGroup(Auxiliary.DrytronExtraCostFilter,tp,LOCATION_GRAVE,0,nil,tp)\n\tg1:Merge(g2)\n\tif chk==0 then return #g1>0 and Duel.GetCustomActivityCount(97148796,tp,ACTIVITY_SPSUMMON)==0 end\n\tlocal e1=Effect.CreateEffect(e:GetHandler())\n\te1:SetType(EFFECT_TYPE_FIELD)\n\te1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)\n\te1:SetProperty(EFFECT_FLAG_PLAYER_TARGET+EFFECT_FLAG_OATH)\n\te1:SetTargetRange(1,0)\n\te1:SetTarget(Auxiliary.DrytronSpSummonLimit)\n\te1:SetReset(RESET_PHASE+PHASE_END)\n\tDuel.RegisterEffect(e1,tp)\n\t--cant special summon summonable card check\n\tlocal e2=Effect.CreateEffect(e:GetHandler())\n\te2:SetType(EFFECT_TYPE_FIELD)\n\te2:SetCode(97148796)\n\te2:SetProperty(EFFECT_FLAG_PLAYER_TARGET+EFFECT_FLAG_OATH)\n\te2:SetTargetRange(1,0)\n\te2:SetReset(RESET_PHASE+PHASE_END)\n\tDuel.RegisterEffect(e2,tp)\n\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_RELEASE)\n\tlocal rg=g1:Select(tp,1,1,nil)\n\tlocal tc=rg:GetFirst()\n\tlocal te=tc:IsHasEffect(89771220,tp)\n\tif te then\n\t\tte:UseCountLimit(tp)\n\t\tDuel.Remove(tc,POS_FACEUP,REASON_EFFECT+REASON_REPLACE)\n\telse\n\t\tAuxiliary.UseExtraReleaseCount(rg,tp)\n\t\tDuel.Release(tc,REASON_COST)\n\tend\nend\nfunction Auxiliary.DrytronSpSummonLimit(e,c,sump,sumtype,sumpos,targetp,se)\n\treturn c:IsSummonableCard() and c:GetOriginalType()&(TYPE_SPELL|TYPE_TRAP|TYPE_TRAPMONSTER)==0\nend\nfunction Auxiliary.DrytronSpSummonTarget(e,tp,eg,ep,ev,re,r,rp,chk)\n\tlocal res=e:GetLabel()==100 or Duel.GetLocationCount(tp,LOCATION_MZONE)>0\n\tif chk==0 then\n\t\te:SetLabel(0)\n\t\treturn res and e:GetHandler():IsCanBeSpecialSummoned(e,0,tp,false,true,POS_FACEUP_DEFENSE)\n\tend\n\te:SetLabel(0)\n\tDuel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,e:GetHandler(),1,0,0)\nend\nfunction Auxiliary.DrytronSpSummonOperation(func)\n\treturn\tfunction(e,tp,eg,ep,ev,re,r,rp)\n\t\t\t\tlocal c=e:GetHandler()\n\t\t\t\tif not c:IsRelateToEffect(e) then return end\n\t\t\t\tif Duel.SpecialSummon(c,0,tp,tp,false,true,POS_FACEUP_DEFENSE)~=0 then\n\t\t\t\t\tc:CompleteProcedure()\n\t\t\t\t\tfunc(e,tp)\n\t\t\t\tend\n\t\t\tend\nend\n---The `nolimit` parameter for Special Summon effects of Drytron cards\n---@param c Card\n---@return boolean\nfunction Auxiliary.DrytronSpSummonType(c)\n\treturn c:IsType(TYPE_SPSUMMON)\nend\n---The `nolimit` parameter for Special Summon effects of Dragon, Xyz monsters where Soul Drain Dragon is available\n---(Soul Drain Dragon, Level 8/LIGHT/Dragon/4000/0)\n---@param c Card\n---@return boolean\nfunction Auxiliary.DragonXyzSpSummonType(c)\n\treturn c:GetOriginalCode()==55735315\nend\n---The `nolimit` parameter for Special Summon effects of Triamid cards\n---@param c Card\n---@return boolean\nfunction Auxiliary.TriamidSpSummonType(c)\n\treturn c:IsType(TYPE_SPSUMMON)\nend\n--additional destroy effect for the Labrynth field\nfunction Auxiliary.LabrynthDestroyOp(e,tp,res)\n\tlocal c=e:GetHandler()\n\tlocal chk=not c:IsStatus(STATUS_ACT_FROM_HAND) and c:IsSetCard(0x117e) and c:GetType()==TYPE_TRAP and e:IsHasType(EFFECT_TYPE_ACTIVATE)\n\tlocal exc=nil\n\tif c:IsStatus(STATUS_LEAVE_CONFIRMED) then exc=c end\n\tlocal te=Duel.IsPlayerAffectedByEffect(tp,33407125)\n\tif chk and te\n\t\tand Duel.IsExistingMatchingCard(nil,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,1,exc)\n\t\tand Duel.SelectYesNo(tp,Auxiliary.Stringid(33407125,0)) then\n\t\tif res>0 then Duel.BreakEffect() end\n\t\tDuel.Hint(HINT_CARD,0,33407125)\n\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_DESTROY)\n\t\tlocal dg=Duel.SelectMatchingCard(tp,nil,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,1,1,exc)\n\t\tDuel.HintSelection(dg)\n\t\tDuel.Destroy(dg,REASON_EFFECT)\n\t\tte:UseCountLimit(tp)\n\tend\nend\n--shortcut for Gizmek cards\nfunction Auxiliary.AtkEqualsDef(c)\n\tif not c:IsType(TYPE_MONSTER) or c:IsType(TYPE_LINK) then return false end\n\tif c:GetAttack()~=c:GetDefense() then return false end\n\treturn c:IsLocation(LOCATION_MZONE) or c:GetTextAttack()>=0 and c:GetTextDefense()>=0\nend\n--shortcut for self-banish costs\nfunction Auxiliary.bfgcost(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return e:GetHandler():IsAbleToRemoveAsCost() end\n\tDuel.Remove(e:GetHandler(),POS_FACEUP,REASON_COST)\nend\n--check for cards with different names\nfunction Auxiliary.dncheck(g)\n\treturn g:GetClassCount(Card.GetCode)==#g\nend\n--check for cards with different levels\nfunction Auxiliary.dlvcheck(g)\n\treturn g:GetClassCount(Card.GetLevel)==#g\nend\n--check for cards with different ranks\nfunction Auxiliary.drkcheck(g)\n\treturn g:GetClassCount(Card.GetRank)==#g\nend\n--check for cards with different links\nfunction Auxiliary.dlkcheck(g)\n\treturn g:GetClassCount(Card.GetLink)==#g\nend\n--check for cards with different attributes\nfunction Auxiliary.dabcheck(g)\n\treturn g:GetClassCount(Card.GetAttribute)==#g\nend\n--check for cards with different races\nfunction Auxiliary.drccheck(g)\n\treturn g:GetClassCount(Card.GetRace)==#g\nend\n--check for group with 2 cards, each card match f with a1/a2 as argument\nfunction Auxiliary.gfcheck(g,f,a1,a2)\n\tif #g~=2 then return false end\n\tlocal c1=g:GetFirst()\n\tlocal c2=g:GetNext()\n\treturn f(c1,a1) and f(c2,a2) or f(c2,a1) and f(c1,a2)\nend\n--check for group with 2 cards, each card match f1 with a1, f2 with a2 as argument\nfunction Auxiliary.gffcheck(g,f1,a1,f2,a2)\n\tif #g~=2 then return false end\n\tlocal c1=g:GetFirst()\n\tlocal c2=g:GetNext()\n\treturn f1(c1,a1) and f2(c2,a2) or f1(c2,a1) and f2(c1,a2)\nend\nfunction Auxiliary.mzctcheck(g,tp)\n\treturn Duel.GetMZoneCount(tp,g)>0\nend\n---Check if there is space in mzone after tp releases g by reason\n---@param g Group\n---@param tp integer\n---@param reason? integer\n---@return boolean\nfunction Auxiliary.mzctcheckrel(g,tp,reason)\n\treason=reason or REASON_COST\n\treturn Duel.GetMZoneCount(tp,g)>0 and Duel.CheckReleaseGroupEx(tp,Auxiliary.IsInGroup,#g,reason,false,nil,g)\nend\n--used for \"except this card\"\nfunction Auxiliary.ExceptThisCard(e)\n\tlocal c=e:GetHandler()\n\tif c:IsRelateToChain() then return c else return nil end\nend\n--used for multi-linked zone(zone linked by two or more link monsters)\nfunction Auxiliary.GetMultiLinkedZone(tp)\n\tlocal f=function(c)\n\t\treturn c:IsFaceup() and c:IsType(TYPE_LINK)\n\tend\n\tlocal lg=Duel.GetMatchingGroup(f,tp,LOCATION_MZONE,LOCATION_MZONE,nil)\n\tlocal multi_linked_zone=0\n\tlocal single_linked_zone=0\n\tfor tc in Auxiliary.Next(lg) do\n\t\tlocal zone=tc:GetLinkedZone(tp)&0x7f\n\t\tmulti_linked_zone=single_linked_zone&zone|multi_linked_zone\n\t\tsingle_linked_zone=single_linked_zone~zone\n\tend\n\treturn multi_linked_zone\nend\nAuxiliary.SubGroupCaptured=nil\nfunction Auxiliary.CheckGroupRecursive(c,sg,g,f,min,max,ext_params)\n\tsg:AddCard(c)\n\tif Auxiliary.GCheckAdditional and not Auxiliary.GCheckAdditional(sg,c,g) then\n\t\tsg:RemoveCard(c)\n\t\treturn false\n\tend\n\tlocal res=(#sg>=min and #sg<=max and f(sg,table.unpack(ext_params,1,ext_params.n)))\n\t\tor (#sg<max and g:IsExists(Auxiliary.CheckGroupRecursive,1,sg,sg,g,f,min,max,ext_params))\n\tsg:RemoveCard(c)\n\treturn res\nend\nfunction Auxiliary.CheckGroupRecursiveCapture(c,sg,g,f,min,max,ext_params)\n\tsg:AddCard(c)\n\tif Auxiliary.GCheckAdditional and not Auxiliary.GCheckAdditional(sg,c,g) then\n\t\tsg:RemoveCard(c)\n\t\treturn false\n\tend\n\tlocal res=#sg>=min and #sg<=max and f(sg,table.unpack(ext_params,1,ext_params.n))\n\tif res then\n\t\tAuxiliary.SubGroupCaptured:Clear()\n\t\tAuxiliary.SubGroupCaptured:Merge(sg)\n\telse\n\t\tres=#sg<max and g:IsExists(Auxiliary.CheckGroupRecursiveCapture,1,sg,sg,g,f,min,max,ext_params)\n\tend\n\tsg:RemoveCard(c)\n\treturn res\nend\n---\n---@param g Group\n---@param f function\n---@param min? integer\n---@param max? integer\n---@param ... any\n---@return boolean\nfunction Group.CheckSubGroup(g,f,min,max,...)\n\tmin=min or 1\n\tmax=max or #g\n\tif min>max then return false end\n\tlocal ext_params=table.pack(...)\n\tlocal sg=Duel.GrabSelectedCard()\n\tif #sg>max or #(g+sg)<min then return false end\n\tif #sg==max and (not f(sg,...) or Auxiliary.GCheckAdditional and not Auxiliary.GCheckAdditional(sg,nil,g)) then return false end\n\tif #sg>=min and #sg<=max and f(sg,...) and (not Auxiliary.GCheckAdditional or Auxiliary.GCheckAdditional(sg,nil,g)) then return true end\n\tlocal eg=g:Clone()\n\tfor c in Auxiliary.Next(g-sg) do\n\t\tif Auxiliary.CheckGroupRecursive(c,sg,eg,f,min,max,ext_params) then return true end\n\t\teg:RemoveCard(c)\n\tend\n\treturn false\nend\n---\n---@param g Group\n---@param tp integer\n---@param f function\n---@param cancelable boolean\n---@param min? integer\n---@param max? integer\n---@param ... any\n---@return Group\nfunction Group.SelectSubGroup(g,tp,f,cancelable,min,max,...)\n\tAuxiliary.SubGroupCaptured=Group.CreateGroup()\n\tmin=min or 1\n\tmax=max or #g\n\tlocal ext_params=table.pack(...)\n\tlocal sg=Group.CreateGroup()\n\tlocal fg=Duel.GrabSelectedCard()\n\tif #fg>max or min>max or #(g+fg)<min then return nil end\n\tfor tc in Auxiliary.Next(fg) do\n\t\tfg:SelectUnselect(sg,tp,false,false,min,max)\n\tend\n\tsg:Merge(fg)\n\tlocal finish=(#sg>=min and #sg<=max and f(sg,...))\n\twhile #sg<max do\n\t\tlocal cg=Group.CreateGroup()\n\t\tlocal eg=g:Clone()\n\t\tfor c in Auxiliary.Next(g-sg) do\n\t\t\tif not cg:IsContains(c) then\n\t\t\t\tif Auxiliary.CheckGroupRecursiveCapture(c,sg,eg,f,min,max,ext_params) then\n\t\t\t\t\tcg:Merge(Auxiliary.SubGroupCaptured)\n\t\t\t\telse\n\t\t\t\t\teg:RemoveCard(c)\n\t\t\t\tend\n\t\t\tend\n\t\tend\n\t\tcg:Sub(sg)\n\t\tfinish=(#sg>=min and #sg<=max and f(sg,...))\n\t\tif #cg==0 then break end\n\t\tlocal cancel=not finish and cancelable\n\t\tlocal tc=cg:SelectUnselect(sg,tp,finish,cancel,min,max)\n\t\tif not tc then break end\n\t\tif not fg:IsContains(tc) then\n\t\t\tif not sg:IsContains(tc) then\n\t\t\t\tsg:AddCard(tc)\n\t\t\t\tif #sg==max then finish=true end\n\t\t\telse\n\t\t\t\tsg:RemoveCard(tc)\n\t\t\tend\n\t\telseif cancelable then\n\t\t\treturn nil\n\t\tend\n\tend\n\tif finish then\n\t\treturn sg\n\telse\n\t\treturn nil\n\tend\nend\n---Create a table of filter functions\n---@param f function\n---@param list table\n---@return table\nfunction Auxiliary.CreateChecks(f,list)\n\tlocal checks={}\n\tfor i=1,#list do\n\t\tchecks[i]=function(c) return f(c,list[i]) end\n\tend\n\treturn checks\nend\nfunction Auxiliary.CheckGroupRecursiveEach(c,sg,g,f,checks,ext_params)\n\tif not checks[1+#sg](c) then\n\t\treturn false\n\tend\n\tsg:AddCard(c)\n\tif Auxiliary.GCheckAdditional and not Auxiliary.GCheckAdditional(sg,c,g) then\n\t\tsg:RemoveCard(c)\n\t\treturn false\n\tend\n\tlocal res\n\tif #sg==#checks then\n\t\tres=f(sg,table.unpack(ext_params,1,ext_params.n))\n\telse\n\t\tres=g:IsExists(Auxiliary.CheckGroupRecursiveEach,1,sg,sg,g,f,checks,ext_params)\n\tend\n\tsg:RemoveCard(c)\n\treturn res\nend\n---\n---@param g Group\n---@param checks table\n---@param f? function\n---@param ... any\n---@return boolean\nfunction Group.CheckSubGroupEach(g,checks,f,...)\n\tif f==nil then f=Auxiliary.TRUE end\n\tif #g<#checks then return false end\n\tlocal ext_params=table.pack(...)\n\tlocal sg=Group.CreateGroup()\n\treturn g:IsExists(Auxiliary.CheckGroupRecursiveEach,1,sg,sg,g,f,checks,ext_params)\nend\n---\n---@param g Group\n---@param tp integer\n---@param checks table\n---@param cancelable? boolean\n---@param f? function\n---@param ... any\n---@return Group\nfunction Group.SelectSubGroupEach(g,tp,checks,cancelable,f,...)\n\tif cancelable==nil then cancelable=false end\n\tif f==nil then f=Auxiliary.TRUE end\n\tlocal ct=#checks\n\tlocal ext_params=table.pack(...)\n\tlocal sg=Group.CreateGroup()\n\tlocal finish=false\n\twhile #sg<ct do\n\t\tlocal cg=g:Filter(Auxiliary.CheckGroupRecursiveEach,sg,sg,g,f,checks,ext_params)\n\t\tif #cg==0 then break end\n\t\tlocal tc=cg:SelectUnselect(sg,tp,false,cancelable,ct,ct)\n\t\tif not tc then break end\n\t\tif not sg:IsContains(tc) then\n\t\t\tsg:AddCard(tc)\n\t\t\tif #sg==ct then finish=true end\n\t\telse\n\t\t\tsg:Clear()\n\t\tend\n\tend\n\tif finish then\n\t\treturn sg\n\telse\n\t\treturn nil\n\tend\nend\n--for effects that player usually select card from field, avoid showing panel\nfunction Auxiliary.SelectCardFromFieldFirst(tp,f,player,s,o,min,max,ex,...)\n\tlocal g=Duel.GetMatchingGroup(f,player,s,o,ex,...)\n\tlocal fg=g:Filter(Card.IsOnField,nil)\n\tg:Sub(fg)\n\tif #fg>=min and #g>0 then\n\t\tlocal last_hint=Duel.GetLastSelectHint(tp)\n\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_FIELD_FIRST)\n\t\tlocal sg=fg:CancelableSelect(tp,min,max,nil)\n\t\tif sg then\n\t\t\treturn sg\n\t\telse\n\t\t\tDuel.Hint(HINT_SELECTMSG,tp,last_hint)\n\t\tend\n\tend\n\treturn Duel.SelectMatchingCard(tp,f,player,s,o,min,max,ex,...)\nend\nfunction Auxiliary.SelectTargetFromFieldFirst(tp,f,player,s,o,min,max,ex,...)\n\tlocal g=Duel.GetMatchingGroup(f,player,s,o,ex,...):Filter(Card.IsCanBeEffectTarget,nil)\n\tlocal fg=g:Filter(Card.IsOnField,nil)\n\tg:Sub(fg)\n\tif #fg>=min and #g>0 then\n\t\tlocal last_hint=Duel.GetLastSelectHint(tp)\n\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_FIELD_FIRST)\n\t\tlocal sg=fg:CancelableSelect(tp,min,max,nil)\n\t\tif sg then\n\t\t\tDuel.SetTargetCard(sg)\n\t\t\treturn sg\n\t\telse\n\t\t\tDuel.Hint(HINT_SELECTMSG,tp,last_hint)\n\t\tend\n\tend\n\treturn Duel.SelectTarget(tp,f,player,s,o,min,max,ex,...)\nend\n---\n---Select the same number of cards from each group.\n---@param tp integer\n---@param g1 Group\n---@param g2 Group\n---@param min? integer Cards to select from each group, minimum\n---@param max? integer Cards to select from each group, maximum\n---@param except? Card|Group\n---@return Group\nfunction Auxiliary.SelectSameCount(tp,g1,g2,min,max,except)\n\tif except then\n\t\tg1=g1-except\n\t\tg2=g2-except\n\tend\n\tmin=min or 1\n\tmax=math.min(max or 127,#g1,#g2)\n\tif min>max then return nil end\n\tlocal sg=Group.CreateGroup()\n\tlocal ct1=0\n\tlocal ct2=0\n\twhile true do\n\t\tlocal fg=Group.CreateGroup()\n\t\tif ct1<max then\n\t\t\tfg:Merge(g1)\n\t\tend\n\t\tif ct2<max then\n\t\t\tfg:Merge(g2)\n\t\tend\n\t\tfg:Sub(sg)\n\t\tlocal finish=ct1==ct2 and ct1>=min and ct1<=max\n\t\tlocal tc=fg:SelectUnselect(sg,tp,finish,false,min*2,max*2)\n\t\tif not tc then break end\n\t\tif sg:IsContains(tc) then\n\t\t\tsg:RemoveCard(tc)\n\t\t\tif g1:IsContains(tc) then\n\t\t\t\tct1=ct1-1\n\t\t\telse\n\t\t\t\tct2=ct2-1\n\t\t\tend\n\t\telse\n\t\t\tsg:AddCard(tc)\n\t\t\tif g1:IsContains(tc) then\n\t\t\t\tct1=ct1+1\n\t\t\telse\n\t\t\t\tct2=ct2+1\n\t\t\tend\n\t\tend\n\t\tif ct1==max and ct2==max then break end\n\tend\n\treturn sg\nend\n--condition of \"negate activation and banish\"\nfunction Auxiliary.nbcon(tp,re)\n\tlocal rc=re:GetHandler()\n\treturn Duel.IsPlayerCanRemove(tp)\n\t\tand (not rc:IsRelateToEffect(re) or rc:IsAbleToRemove())\nend\nfunction Auxiliary.nbtg(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return Auxiliary.nbcon(tp,re) end\n\tDuel.SetOperationInfo(0,CATEGORY_NEGATE,eg,1,0,0)\n\tif re:GetHandler():IsRelateToEffect(re) then\n\t\tDuel.SetOperationInfo(0,CATEGORY_REMOVE,eg,1,0,0)\n\tend\n\tif re:GetActivateLocation()==LOCATION_GRAVE then\n\t\te:SetCategory(e:GetCategory()|CATEGORY_GRAVE_ACTION)\n\telse\n\t\te:SetCategory(e:GetCategory()&~CATEGORY_GRAVE_ACTION)\n\tend\nend\n--condition of \"negate activation and return to deck\"\nfunction Auxiliary.ndcon(tp,re)\n\tlocal rc=re:GetHandler()\n\treturn re:IsHasType(EFFECT_TYPE_ACTIVATE) or not rc:IsRelateToEffect(re) or rc:IsAbleToDeck()\nend\n--return the global index of the zone in (p,loc,seq)\nfunction Auxiliary.SequenceToGlobal(p,loc,seq)\n\tif p~=0 and p~=1 then\n\t\treturn 0\n\tend\n\tif loc==LOCATION_MZONE then\n\t\tif seq<=6 then\n\t\t\treturn 0x0001<<(16*p+seq)\n\t\telse\n\t\t\treturn 0\n\t\tend\n\telseif loc == LOCATION_SZONE then\n\t\tif seq<=4 then\n\t\t\treturn 0x0100<<(16*p+seq)\n\t\telse\n\t\t\treturn 0\n\t\tend\n\telse\n\t\treturn 0\n\tend\nend\n--use the count limit of Lair of Darkness if the tributes are not selected by Duel.SelectReleaseGroup\nfunction Auxiliary.UseExtraReleaseCount(g,tp)\n\tlocal eg=g:Filter(Auxiliary.ExtraReleaseFilter,nil,tp)\n\tfor ec in Auxiliary.Next(eg) do\n\t\tlocal te=ec:IsHasEffect(EFFECT_EXTRA_RELEASE_NONSUM,tp)\n\t\tif te then te:UseCountLimit(tp) end\n\tend\nend\nfunction Auxiliary.ExtraReleaseFilter(c,tp)\n\treturn c:IsControler(1-tp) and c:IsHasEffect(EFFECT_EXTRA_RELEASE_NONSUM,tp)\nend\n--\nfunction Auxiliary.GetCappedLevel(c)\n\tlocal lv=c:GetLevel()\n\tif lv>MAX_PARAMETER then\n\t\treturn MAX_PARAMETER\n\telse\n\t\treturn lv\n\tend\nend\n--\nfunction Auxiliary.GetCappedXyzLevel(c)\n\tlocal lv=c:GetLevel()\n\tif lv>MAX_XYZ_LEVEL then\n\t\treturn MAX_XYZ_LEVEL\n\telse\n\t\treturn lv\n\tend\nend\n--\nfunction Auxiliary.GetCappedAttack(c)\n\tlocal x=c:GetAttack()\n\tif x>MAX_PARAMETER then\n\t\treturn MAX_PARAMETER\n\telse\n\t\treturn x\n\tend\nend\n--when this card is sent to grave, record the reason effect\n--to check whether the reason effect do something simultaneously\n--so the \"while this card is in your GY\" condition isn't met\nfunction Auxiliary.AddThisCardInGraveAlreadyCheck(c)\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_CONTINUOUS)\n\te1:SetCode(EVENT_TO_GRAVE)\n\te1:SetCondition(Auxiliary.ThisCardInGraveAlreadyCheckReg)\n\tc:RegisterEffect(e1)\n\treturn e1\nend\nfunction Auxiliary.ThisCardInGraveAlreadyCheckReg(e,tp,eg,ep,ev,re,r,rp)\n\t--condition of continous effect will be checked before other effects\n\tif re==nil then return false end\n\tif e:GetLabelObject()~=nil then return false end\n\tif (r&REASON_EFFECT)>0 then\n\t\te:SetLabelObject(re)\n\t\tlocal e1=Effect.CreateEffect(e:GetHandler())\n\t\te1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)\n\t\te1:SetCode(EVENT_CHAIN_END)\n\t\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)\n\t\te1:SetOperation(Auxiliary.ThisCardInGraveAlreadyReset1)\n\t\te1:SetLabelObject(e)\n\t\tDuel.RegisterEffect(e1,tp)\n\t\tlocal e2=e1:Clone()\n\t\te2:SetCode(EVENT_BREAK_EFFECT)\n\t\te2:SetOperation(Auxiliary.ThisCardInGraveAlreadyReset2)\n\t\te2:SetReset(RESET_CHAIN)\n\t\te2:SetLabelObject(e1)\n\t\tDuel.RegisterEffect(e2,tp)\n\telseif (r&REASON_MATERIAL)>0 or not re:IsActivated() and (r&REASON_COST)>0 then\n\t\te:SetLabelObject(re)\n\t\tlocal reset_event=EVENT_SPSUMMON\n\t\tif re:GetCode()~=EFFECT_SPSUMMON_PROC then reset_event=EVENT_SUMMON end\n\t\tlocal e1=Effect.CreateEffect(e:GetHandler())\n\t\te1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)\n\t\te1:SetCode(reset_event)\n\t\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)\n\t\te1:SetOperation(Auxiliary.ThisCardInGraveAlreadyReset1)\n\t\te1:SetLabelObject(e)\n\t\tDuel.RegisterEffect(e1,tp)\n\tend\n\treturn false\nend\nfunction Auxiliary.ThisCardInGraveAlreadyReset1(e)\n\t--this will run after EVENT_SPSUMMON_SUCCESS\n\te:GetLabelObject():SetLabelObject(nil)\n\te:Reset()\nend\nfunction Auxiliary.ThisCardInGraveAlreadyReset2(e)\n\tlocal e1=e:GetLabelObject()\n\te1:GetLabelObject():SetLabelObject(nil)\n\te1:Reset()\n\te:Reset()\nend\n--Player p place g on the top of Deck in any order\nfunction Auxiliary.PlaceCardsOnDeckTop(p,g,reason)\n\tif reason==nil then reason=REASON_EFFECT end\n\tDuel.SendtoDeck(g,nil,SEQ_DECKTOP,reason)\n\tlocal rg=Duel.GetOperatedGroup()\n\tlocal og=rg:Filter(Card.IsLocation,nil,LOCATION_DECK)\n\tlocal ct1=og:FilterCount(Card.IsControler,nil,p)\n\tlocal ct2=og:FilterCount(Card.IsControler,nil,1-p)\n\tif ct1>1 then\n\t\tDuel.SortDecktop(p,p,ct1)\n\tend\n\tif ct2>1 then\n\t\tDuel.SortDecktop(p,1-p,ct2)\n\tend\n\treturn #rg\nend\n--Player p place g on the bottom of Deck in any order\nfunction Auxiliary.PlaceCardsOnDeckBottom(p,g,reason)\n\tif reason==nil then reason=REASON_EFFECT end\n\tDuel.SendtoDeck(g,nil,SEQ_DECKTOP,reason)\n\tlocal rg=Duel.GetOperatedGroup()\n\tlocal og=rg:Filter(Card.IsLocation,nil,LOCATION_DECK)\n\tlocal ct1=og:FilterCount(Card.IsControler,nil,p)\n\tlocal ct2=og:FilterCount(Card.IsControler,nil,1-p)\n\tif ct1>0 then\n\t\tif ct1>1 then\n\t\t\tDuel.SortDecktop(p,p,ct1)\n\t\tend\n\t\tfor i=1,ct1 do\n\t\t\tlocal tc=Duel.GetDecktopGroup(p,1):GetFirst()\n\t\t\tDuel.MoveSequence(tc,SEQ_DECKBOTTOM)\n\t\tend\n\tend\n\tif ct2>0 then\n\t\tif ct2>1 then\n\t\t\tDuel.SortDecktop(p,1-p,ct2)\n\t\tend\n\t\tfor i=1,ct2 do\n\t\t\tlocal tc=Duel.GetDecktopGroup(1-p,1):GetFirst()\n\t\t\tDuel.MoveSequence(tc,SEQ_DECKBOTTOM)\n\t\tend\n\tend\n\treturn #rg\nend\n--The event is triggered multiple times in a chain\n--but only 1 event with EVENT_CUSTOM+code will be triggered at EVENT_CHAIN_END, or immediately if not in chain\n--NOTE: re,r,rp,ep,ev of that custom event ARE NOT releated to the real event that trigger this custom event\nfunction Auxiliary.RegisterMergedDelayedEvent(c,code,event,g)\n\tlocal mt=getmetatable(c)\n\tif mt[event]==true then return end\n\tmt[event]=true\n\tif not g then g=Group.CreateGroup() end\n\tg:KeepAlive()\n\tlocal ge1=Effect.CreateEffect(c)\n\tge1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)\n\tge1:SetCode(event)\n\tge1:SetLabel(code)\n\tge1:SetLabelObject(g)\n\tge1:SetOperation(Auxiliary.MergedDelayEventCheck1)\n\tDuel.RegisterEffect(ge1,0)\n\tlocal ge2=ge1:Clone()\n\tge2:SetCode(EVENT_CHAIN_END)\n\tge2:SetOperation(Auxiliary.MergedDelayEventCheck2)\n\tDuel.RegisterEffect(ge2,0)\nend\nfunction Auxiliary.MergedDelayEventCheck1(e,tp,eg,ep,ev,re,r,rp)\n\tlocal g=e:GetLabelObject()\n\tg:Merge(eg)\n\tif Duel.GetCurrentChain()==0 and not Duel.CheckEvent(EVENT_CHAIN_END) then\n\t\tlocal _eg=g:Clone()\n\t\tDuel.RaiseEvent(_eg,EVENT_CUSTOM+e:GetLabel(),re,r,rp,ep,ev)\n\t\tg:Clear()\n\tend\nend\nfunction Auxiliary.MergedDelayEventCheck2(e,tp,eg,ep,ev,re,r,rp)\n\tlocal g=e:GetLabelObject()\n\tif #g>0 then\n\t\tlocal _eg=g:Clone()\n\t\tDuel.RaiseEvent(_eg,EVENT_CUSTOM+e:GetLabel(),re,r,rp,ep,ev)\n\t\tg:Clear()\n\tend\nend\n--Once the card has been moved to the public area, it should be listened to again\nAuxiliary.merge_single_effect_codes={}\nfunction Auxiliary.RegisterMergedDelayedEvent_ToSingleCard(c,code,events)\n\tlocal g=Group.CreateGroup()\n\tg:KeepAlive()\n\tlocal mt=getmetatable(c)\n\tlocal seed=0\n\tif type(events) == \"table\" then\n\t\tfor _, event in ipairs(events) do\n\t\t\tseed = seed + event\n\t\tend\n\telse\n\t\tseed = events\n\tend\n\twhile(mt[seed]==true) do\n\t\tseed = seed + 1\n\tend\n\tmt[seed]=true\n\tlocal event_code_single = (code ~ (seed << 16)) | EVENT_CUSTOM\n\tif type(events) == \"table\" then\n\t\tfor _, event in ipairs(events) do\n\t\t\tAuxiliary.RegisterMergedDelayedEvent_ToSingleCard_AddOperation(c,g,event,event_code_single)\n\t\tend\n\telse\n\t\tAuxiliary.RegisterMergedDelayedEvent_ToSingleCard_AddOperation(c,g,events,event_code_single)\n\tend\n\t--listened to again\n\tlocal e3=Effect.CreateEffect(c)\n\te3:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_CONTINUOUS)\n\te3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_SET_AVAILABLE)\n\te3:SetCode(EVENT_MOVE)\n\te3:SetLabel(event_code_single)\n\te3:SetLabelObject(g)\n\te3:SetOperation(Auxiliary.ThisCardMovedToPublicResetCheck_ToSingleCard)\n\tc:RegisterEffect(e3)\n\tAuxiliary.merge_single_effect_codes[event_code_single]=g\n\t--use global effect to raise event for face-down cards\n\tif not Auxiliary.merge_single_global_check then\n\t\tAuxiliary.merge_single_global_check=true\n\t\tlocal ge1=Effect.CreateEffect(c)\n\t\tge1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)\n\t\tge1:SetCode(EVENT_CHAIN_END)\n\t\tge1:SetOperation(Auxiliary.RegisterMergedDelayedEvent_ToSingleCard_RaiseEvent)\n\t\tDuel.RegisterEffect(ge1,0)\n\tend\n\treturn event_code_single\nend\nfunction Auxiliary.RegisterMergedDelayedEvent_ToSingleCard_AddOperation(c,g,event,event_code_single)\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)\n\te1:SetCode(event)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_SET_AVAILABLE)\n\te1:SetLabel(event_code_single,event)\n\te1:SetLabelObject(g)\n\te1:SetOperation(Auxiliary.MergedDelayEventCheck1_ToSingleCard)\n\t-- Card-registered FIELD continuous effects fail is_activateable while the handler is Set.\n\t-- Duel.RegisterEffect is FIELD_ONLY, so Check1 still merges when this card is face-down,\n\t-- which is required for cteffect. EVENT_MOVE still clears g if this copy becomes public.\n\tDuel.RegisterEffect(e1,0)\n\tlocal e2=e1:Clone()\n\te2:SetCode(EVENT_CHAIN_END)\n\te2:SetOperation(Auxiliary.MergedDelayEventCheck2_ToSingleCard)\n\tDuel.RegisterEffect(e2,0)\nend\nfunction Auxiliary.ThisCardMovedToPublicResetCheck_ToSingleCard(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetOwner()\n\tlocal g=e:GetLabelObject()\n\tif c:IsFaceup() or c:IsPublic() then\n\t\tg:Clear()\n\tend\nend\nfunction Auxiliary.MergedDelayEventCheck1_ToSingleCard(e,tp,eg,ep,ev,re,r,rp)\n\tlocal g=e:GetLabelObject()\n\tg:Merge(eg)\n\tlocal code,event=e:GetLabel()\n\tlocal c=e:GetOwner()\n\t-- clear if the owner card is in the event group\n\tif eg:IsContains(c) then\n\t\tg:Clear()\n\tend\n\tif Duel.GetCurrentChain()==0 and #g>0 and not Duel.CheckEvent(EVENT_CHAIN_END) then\n\t\tlocal _eg=g:Clone()\n\t\tDuel.RaiseEvent(_eg,code,re,r,rp,ep,ev)\n\t\tg:Clear()\n\tend\nend\nfunction Auxiliary.MergedDelayEventCheck2_ToSingleCard(e,tp,eg,ep,ev,re,r,rp)\n\tlocal g=e:GetLabelObject()\n\tif Duel.CheckEvent(EVENT_MOVE) then\n\t\tlocal _,meg=Duel.CheckEvent(EVENT_MOVE,true)\n\t\tlocal c=e:GetOwner()\n\t\tif meg:IsContains(c) and (c:IsFaceup() or c:IsPublic()) then\n\t\t\tg:Clear()\n\t\tend\n\tend\n\tif #g>0 then\n\t\tlocal _eg=g:Clone()\n\t\tDuel.RaiseEvent(_eg,e:GetLabel(),re,r,rp,ep,ev)\n\t\tg:Clear()\n\tend\nend\nfunction Auxiliary.RegisterMergedDelayedEvent_ToSingleCard_RaiseEvent(e,tp,eg,ep,ev,re,r,rp)\n\tfor code,g in pairs(Auxiliary.merge_single_effect_codes) do\n\t\tif #g>0 then\n\t\t\tlocal _eg=g:Clone()\n\t\t\tDuel.RaiseEvent(_eg,code,re,r,rp,ep,ev)\n\t\t\tg:Clear()\n\t\tend\n\tend\nend\n--B.E.S. remove counter\nfunction Auxiliary.EnableBESRemove(c)\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetDescription(10)\n\te1:SetCategory(CATEGORY_DESTROY)\n\te1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_F)\n\te1:SetCode(EVENT_DAMAGE_STEP_END)\n\te1:SetRange(LOCATION_MZONE)\n\te1:SetCondition(Auxiliary.BESRemoveCondition)\n\te1:SetTarget(Auxiliary.BESRemoveTarget)\n\te1:SetOperation(Auxiliary.BESRemoveOperation)\n\tc:RegisterEffect(e1)\nend\nfunction Auxiliary.BESRemoveCondition(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\treturn c:IsRelateToBattle()\nend\nfunction Auxiliary.BESRemoveTarget(e,tp,eg,ep,ev,re,r,rp,chk)\n\tif chk==0 then return true end\n\tif not e:GetHandler():IsCanRemoveCounter(tp,0x1f,1,REASON_EFFECT) then\n\t\tDuel.SetOperationInfo(0,CATEGORY_DESTROY,e:GetHandler(),1,0,0)\n\tend\nend\nfunction Auxiliary.BESRemoveOperation(e,tp,eg,ep,ev,re,r,rp)\n\tlocal c=e:GetHandler()\n\tif c:IsRelateToEffect(e) then\n\t\tif c:IsCanRemoveCounter(tp,0x1f,1,REASON_EFFECT) then\n\t\t\tc:RemoveCounter(tp,0x1f,1,REASON_EFFECT)\n\t\telse\n\t\t\tDuel.Destroy(c,REASON_EFFECT)\n\t\tend\n\tend\nend\n--The operation function of \"destroy during End Phase\"\nfunction Auxiliary.EPDestroyOperation(e,tp,eg,ep,ev,re,r,rp)\n\tlocal tc=e:GetLabelObject()\n\tif Auxiliary.GetValueType(tc)==\"Card\" or Auxiliary.GetValueType(tc)==\"Group\" then\n\t\tDuel.Destroy(tc,REASON_EFFECT,LOCATION_GRAVE)\n\tend\nend\n--\nfunction Auxiliary.NegateSummonCondition()\n\treturn Duel.GetReadyChain()==0\nend\n---Check if all cards in g have the same Attribute/Race\n---@param g Group\n---@param f function Like Card.GetAttribute, must return binary value\n---@return boolean\nfunction Auxiliary.SameValueCheck(g,f)\n\tif #g<=1 then return true end\n\tif #g==2 then return f(g:GetFirst())&f(g:GetNext())~=0 end\n\tlocal tc=g:GetFirst()\n\tlocal v=f(tc)\n\ttc=g:GetNext()\n\twhile tc do\n\t\tv=v&f(tc)\n\t\tif v==0 then return false end\n\t\ttc=g:GetNext()\n\tend\n\treturn v~=0\nend\n---\n---@param tp integer\n---@return boolean\nfunction Auxiliary.IsPlayerCanNormalDraw(tp)\n\treturn Duel.GetDrawCount(tp)>0 and Duel.GetFieldGroupCount(tp,LOCATION_DECK,0)>0\n\t\tand Duel.GetFlagEffect(tp,FLAG_ID_NO_NORMAL_DRAW)==0\nend\n---\n---@param e Effect\n---@param tp integer\n---@param property? integer\nfunction Auxiliary.GiveUpNormalDraw(e,tp,property)\n\tproperty=property or 0\n\tlocal c=e:GetHandler()\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_FIELD)\n\te1:SetProperty(EFFECT_FLAG_PLAYER_TARGET|property)\n\te1:SetCode(EFFECT_DRAW_COUNT)\n\te1:SetTargetRange(1,0)\n\te1:SetReset(RESET_PHASE+PHASE_DRAW)\n\te1:SetValue(0)\n\tDuel.RegisterEffect(e1,tp)\n\tDuel.RegisterFlagEffect(tp,FLAG_ID_NO_NORMAL_DRAW,RESET_PHASE+PHASE_DRAW,property,1)\nend\n---Add EFFECT_TYPE_ACTIVATE effect to Equip Spell Cards\n---@param c Card\n---@param is_self boolean\n---@param is_opponent boolean\n---@param filter function\n---@param eqlimit function|nil\n---@param pause? boolean\n---@param skip_target? boolean\nfunction Auxiliary.AddEquipSpellEffect(c,is_self,is_opponent,filter,eqlimit,pause,skip_target)\n\tlocal value=(type(eqlimit)==\"function\") and eqlimit or 1\n\tif pause==nil then pause=false end\n\tif skip_target==nil then skip_target=false end\n\t--Activate\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetCategory(CATEGORY_EQUIP)\n\te1:SetType(EFFECT_TYPE_ACTIVATE)\n\te1:SetCode(EVENT_FREE_CHAIN)\n\te1:SetProperty(EFFECT_FLAG_CARD_TARGET+EFFECT_FLAG_CONTINUOUS_TARGET)\n\tif not skip_target then\n\t\te1:SetTarget(Auxiliary.EquipSpellTarget(is_self,is_opponent,filter,eqlimit))\n\tend\n\te1:SetOperation(Auxiliary.EquipSpellOperation(eqlimit))\n\tif not pause then\n\t\tc:RegisterEffect(e1)\n\tend\n\t--Equip limit\n\tlocal e2=Effect.CreateEffect(c)\n\te2:SetType(EFFECT_TYPE_SINGLE)\n\te2:SetCode(EFFECT_EQUIP_LIMIT)\n\te2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)\n\te2:SetValue(value)\n\tc:RegisterEffect(e2)\n\treturn e1\nend\nfunction Auxiliary.EquipSpellTarget(is_self,is_opponent,filter,eqlimit)\n\tlocal loc1=is_self and LOCATION_MZONE or 0\n\tlocal loc2=is_opponent and LOCATION_MZONE or 0\n\treturn function(e,tp,eg,ep,ev,re,r,rp,chk,chkc)\n\t\tif chkc then return chkc:IsLocation(LOCATION_MZONE) and chkc:IsFaceup() and (not eqlimit or eqlimit(e,chkc)) end\n\t\tif chk==0 then return Duel.IsExistingTarget(filter,tp,loc1,loc2,1,nil) end\n\t\tDuel.Hint(HINT_SELECTMSG,tp,HINTMSG_EQUIP)\n\t\tDuel.SelectTarget(tp,filter,tp,loc1,loc2,1,1,nil)\n\t\tDuel.SetOperationInfo(0,CATEGORY_EQUIP,e:GetHandler(),1,0,0)\n\tend\nend\nfunction Auxiliary.EquipSpellOperation(eqlimit)\n\treturn function (e,tp,eg,ep,ev,re,r,rp)\n\t\tlocal c=e:GetHandler()\n\t\tlocal tc=Duel.GetFirstTarget()\n\t\tif c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) and tc:IsFaceup() and (not eqlimit or eqlimit(e,tc)) then\n\t\t\tDuel.Equip(tp,c,tc)\n\t\tend\n\tend\nend\n---If this face-up card would leave the field, banish it instead.\n---@param c Card\n---@param condition? function\nfunction Auxiliary.AddBanishRedirect(c,condition)\n\tif type(condition)~=\"function\" then\n\t\tcondition=Auxiliary.BanishRedirectCondition\n\tend\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_SINGLE)\n\te1:SetCode(EFFECT_LEAVE_FIELD_REDIRECT)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_CAN_FORBIDDEN)\n\te1:SetCondition(condition)\n\te1:SetValue(LOCATION_REMOVED)\n\tc:RegisterEffect(e1)\nend\n---\n---@param e Effect\nfunction Auxiliary.BanishRedirectCondition(e)\n\treturn e:GetHandler():IsFaceup()\nend\n---Check if c has a equip card equipped by the effect of itself.\n---@param c Card\n---@param id integer\n---@return boolean\nfunction Auxiliary.IsSelfEquip(c,id)\n\treturn c:GetEquipGroup():IsExists(Auxiliary.SelfEquipFilter,1,nil,id)\nend\nfunction Auxiliary.SelfEquipFilter(c,id)\n\treturn c:GetFlagEffect(id)>0\nend\n---Orcustrated Babel\n---@param c Card\n---@return boolean\nfunction Auxiliary.OrcustratedBabelFilter(c)\n\treturn c:IsOriginalSetCard(0x11b) and\n\t\t(c:IsLocation(LOCATION_MZONE) and c:IsAllTypes(TYPE_LINK+TYPE_MONSTER) or c:IsLocation(LOCATION_GRAVE) and c:IsType(TYPE_MONSTER))\nend\n---Golden Allure Queen\n---@param c Card\n---@return boolean\nfunction Auxiliary.GoldenAllureQueenFilter(c)\n\treturn c:IsOriginalSetCard(0x3)\nend\n---無垢なる芸術－「黄昏の変幻」\n---@param c Card\n---@return boolean\nfunction Auxiliary.ArsMagnaFilter(c)\n\treturn c:IsOriginalSetCard(0x1e6)\nend\n--The table of all \"become quick effects\"\nAuxiliary.quick_effect_filter={}\nAuxiliary.quick_effect_filter[90351981]=Auxiliary.OrcustratedBabelFilter\nAuxiliary.quick_effect_filter[95937545]=Auxiliary.GoldenAllureQueenFilter\nAuxiliary.quick_effect_filter[37279096]=Auxiliary.ArsMagnaFilter\n---Check if the effect of c becomes a Quick Effect.\n---@param c Card\n---@param tp integer\n---@param code integer\n---@return boolean\nfunction Auxiliary.IsCanBeQuickEffect(c,tp,code)\n\tlocal filter=Auxiliary.quick_effect_filter[code]\n\treturn Duel.IsPlayerAffectedByEffect(tp,code)~=nil and filter~=nil and filter(c)\nend\n--\nfunction Auxiliary.DimensionalFissureTarget(e,c)\n\treturn c:GetOriginalType()&TYPE_MONSTER>0 and not c:IsLocation(LOCATION_OVERLAY) and not c:IsType(TYPE_SPELL+TYPE_TRAP)\nend\n--\nfunction Auxiliary.MimighoulFlipCondition(e,tp,eg,ep,ev,re,r,rp)\n\treturn Duel.IsMainPhase()\nend\n---The name of `c` becomes the original name of `tc`\n---@param c Card\n---@param tc Card\n---@param reset? integer defult: RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END\n---@return Effect\nfunction Auxiliary.BecomeOriginalCode(c,tc,reset)\n\treset=reset or (RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END)\n\tlocal code=tc:GetOriginalCodeRule()\n\tlocal e1=Effect.CreateEffect(c)\n\te1:SetType(EFFECT_TYPE_SINGLE)\n\te1:SetCode(EFFECT_CHANGE_CODE)\n\te1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)\n\te1:SetValue(code)\n\te1:SetReset(reset)\n\tc:RegisterEffect(e1)\n\treturn e1\nend\n---@param category integer\n---@return function\nfunction Auxiliary.EffectCategoryFilter(category)\n\t---@param e Effect\n\treturn function (e)\n\t\treturn e:IsHasCategory(category)\n\tend\nend\n---@param flag integer\n---@return function\nfunction Auxiliary.EffectPropertyFilter(flag)\n\t---@param e Effect\n\treturn function (e)\n\t\treturn e:IsHasProperty(flag)\n\tend\nend\n---@param flag integer\n---@return function\nfunction Auxiliary.MonsterEffectPropertyFilter(flag)\n\t---@param e Effect\n\treturn function (e)\n\t\treturn e:IsHasProperty(flag) and not e:IsHasRange(LOCATION_PZONE)\n\tend\nend\n---The `nolimit` parameter for Special Summon effects of Phantasms cards\n---@param c Card\n---@return boolean\nfunction Auxiliary.PhantasmsSpSummonType(c)\n\treturn c:IsType(TYPE_SPSUMMON)\nend\n---Count for the activation of \"Mulcharmy\" monsters\nfunction Auxiliary.EnableMulcharmyGlobalCheck()\n\tif Auxiliary.MulcharmyGlobalFlag then return end\n\tAuxiliary.MulcharmyGlobalFlag=true\n\tlocal ge1=Effect.GlobalEffect()\n\tge1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)\n\tge1:SetCode(EVENT_CHAINING)\n\tge1:SetOperation(Auxiliary.MulcharmyGlobalCheck)\n\tDuel.RegisterEffect(ge1,0)\nend\nfunction Auxiliary.MulcharmyGlobalCheck(e,tp,eg,ep,ev,re,r,rp)\n\tif re:IsActiveType(TYPE_MONSTER) and re:GetHandler():IsSetCard(0x1b2) then\n\t\tDuel.RegisterFlagEffect(ep,84192580,RESET_PHASE+PHASE_END,0,1)\n\tend\nend\n---Check whether a monster is special summoned by Tiki Peace, which should not calculate its original value after leaving the field\n---@param c Card\n---@return boolean\nfunction Auxiliary.covcheck(c)\n\tif c:GetOriginalType()&TYPE_MONSTER~=0 then return true end\n\tlocal se=c:GetSpecialSummonInfo(SUMMON_INFO_REASON_EFFECT)\n\treturn se and se:GetHandler()==c\nend\n\n--Deckhand fix (F6). field::get_attack_target in the core reads player[1 - controller]. A card that\n--left the field as Xyz Material has controller PLAYER_NONE (2), so that read is out of bounds and the\n--engine traps. An attacker that became material is still Duel.GetAttacker(), and scripts that change\n--the attack target (Apple and Chocolate Magician Girl among them) ask it for its targets. A card no\n--player controls has none. Every other call is passed through unchanged.\nlocal deckhand_get_attackable_target=Card.GetAttackableTarget\nfunction Card.GetAttackableTarget(c)\n\tlocal p=c:GetControler()\n\tif p~=0 and p~=1 then return Group.CreateGroup(),false end\n\treturn deckhand_get_attackable_target(c)\nend\n"}}}
