1+ -- 霊術の指南書
2+ -- Handbook to the Spiritual Arts
3+ -- scripted by YoshiDuels
4+ local s ,id = GetID ()
5+ function s .initial_effect (c )
6+ -- Excavate and destroy
7+ local e1 = Effect .CreateEffect (c )
8+ e1 :SetDescription (aux .Stringid (id ,0 ))
9+ e1 :SetCategory (CATEGORY_DESTROY )
10+ e1 :SetType (EFFECT_TYPE_ACTIVATE )
11+ e1 :SetCode (EVENT_FREE_CHAIN )
12+ e1 :SetTarget (s .target )
13+ e1 :SetOperation (s .operation )
14+ c :RegisterEffect (e1 )
15+ end
16+ function s .target (e ,tp ,eg ,ep ,ev ,re ,r ,rp ,chk )
17+ if chk == 0 then return Duel .GetFieldGroupCount (tp ,LOCATION_DECK ,0 )>= 5 end
18+ Duel .SetPossibleOperationInfo (0 ,CATEGORY_TOHAND ,nil ,1 ,tp ,LOCATION_DECK )
19+ end
20+ function s .filter (c )
21+ return c :IsMonster () and c :IsRace (RACE_SPELLCASTER ) and c :IsAttack (500 ,1900 ) and c :IsDefense (1500 )
22+ end
23+ function s .operation (e ,tp ,eg ,ep ,ev ,re ,r ,rp )
24+ -- Effect
25+ if Duel .GetFieldGroupCount (tp ,LOCATION_DECK ,0 )< 5 then return end
26+ Duel .ConfirmDecktop (tp ,5 )
27+ local g = Duel .GetDecktopGroup (tp ,5 )
28+ Duel .DisableShuffleCheck ()
29+ local exg = g :Filter (s .filter ,nil )
30+ local dg = Duel .GetMatchingGroup (Card .IsNotMaximumModeSide ,tp ,0 ,LOCATION_ONFIELD ,nil )
31+ local ct = math.min (# exg // 2 ,# dg )
32+ if ct > 0 and Duel .SelectYesNo (tp ,aux .Stringid (id ,1 )) then
33+ Duel .Hint (HINT_SELECTMSG ,tp ,HINTMSG_DESTROY )
34+ local sg = dg :Select (tp ,1 ,ct ,nil )
35+ local sg2 = sg :AddMaximumCheck ()
36+ if # sg > 0 then
37+ Duel .HintSelection (sg2 )
38+ if Duel .Destroy (sg ,REASON_EFFECT )== 2 then
39+ local e1 = Effect .CreateEffect (e :GetHandler ())
40+ e1 :SetType (EFFECT_TYPE_FIELD )
41+ e1 :SetCode (EFFECT_CANNOT_DIRECT_ATTACK )
42+ e1 :SetProperty (EFFECT_FLAG_IGNORE_IMMUNE )
43+ e1 :SetTargetRange (LOCATION_MZONE ,0 )
44+ e1 :SetTargetRange (LOCATION_MZONE ,0 )
45+ e1 :SetCondition (s .atkcon )
46+ e1 :SetTarget (s .atktg )
47+ e1 :SetReset (RESET_PHASE |PHASE_END )
48+ Duel .RegisterEffect (e1 ,tp )
49+ local e2 = Effect .CreateEffect (e :GetHandler ())
50+ e2 :SetType (EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS )
51+ e2 :SetProperty (EFFECT_FLAG_CANNOT_DISABLE )
52+ e2 :SetCode (EVENT_ATTACK_ANNOUNCE )
53+ e2 :SetOperation (s .checkop )
54+ e2 :SetReset (RESET_PHASE |PHASE_END )
55+ e2 :SetLabelObject (e1 )
56+ Duel .RegisterEffect (e2 ,tp )
57+ end
58+ end
59+ end
60+ local ct2 =# g
61+ if ct2 > 0 then
62+ Duel .MoveToDeckBottom (ct2 ,tp )
63+ Duel .SortDeckbottom (tp ,tp ,ct2 )
64+ end
65+ end
66+ function s .atkcon (e )
67+ return e :GetLabel ()~= 0
68+ end
69+ function s .atktg (e ,c )
70+ return c :GetFieldID ()~= e :GetLabel ()
71+ end
72+ function s .checkop (e ,tp ,eg ,ep ,ev ,re ,r ,rp )
73+ local tg = Duel .GetAttackTarget ()
74+ if tg == nil then
75+ local fid = eg :GetFirst ():GetFieldID ()
76+ e :GetLabelObject ():SetLabel (fid )
77+ end
78+ end
0 commit comments