@@ -1405,58 +1405,67 @@ end
14051405-- Functions for commonly used costs:
14061406Cost = {}
14071407
1408+ local cost_tables = {}
1409+
14081410function Cost .SelfBanish (e ,tp ,eg ,ep ,ev ,re ,r ,rp ,chk )
14091411 local c = e :GetHandler ()
14101412 if chk == 0 then return c :IsAbleToRemoveAsCost () end
14111413 Duel .Remove (c ,POS_FACEUP ,REASON_COST )
14121414end
1415+
14131416function Cost .SelfTribute (e ,tp ,eg ,ep ,ev ,re ,r ,rp ,chk )
14141417 local c = e :GetHandler ()
14151418 if chk == 0 then return c :IsReleasable () end
14161419 Duel .Release (c ,REASON_COST )
14171420end
1418- local self_tograve_costs = {}
1421+
1422+ cost_tables .self_tograve = {}
14191423function Cost .SelfToGrave (e ,tp ,eg ,ep ,ev ,re ,r ,rp ,chk )
14201424 local c = e :GetHandler ()
14211425 if chk == 0 then return c :IsAbleToGraveAsCost () end
14221426 Duel .SendtoGrave (c ,REASON_COST )
14231427end
1424- self_tograve_costs [Cost .SelfToGrave ]= true
1428+ cost_tables .self_tograve [Cost .SelfToGrave ]= true
1429+
14251430function Cost .SelfToHand (e ,tp ,eg ,ep ,ev ,re ,r ,rp ,chk )
14261431 local c = e :GetHandler ()
14271432 if chk == 0 then return c :IsAbleToHandAsCost () end
14281433 Duel .SendtoHand (c ,nil ,REASON_COST )
14291434end
1435+
14301436function Cost .SelfToDeck (e ,tp ,eg ,ep ,ev ,re ,r ,rp ,chk )
14311437 local c = e :GetHandler ()
14321438 if chk == 0 then return c :IsAbleToDeckAsCost () end
14331439 Duel .SendtoDeck (c ,nil ,SEQ_DECKSHUFFLE ,REASON_COST )
14341440end
1441+
14351442function Cost .SelfToExtra (e ,tp ,eg ,ep ,ev ,re ,r ,rp ,chk )
14361443 local c = e :GetHandler ()
14371444 if chk == 0 then return c :IsAbleToExtraAsCost () end
14381445 Duel .SendtoDeck (c ,nil ,SEQ_DECKSHUFFLE ,REASON_COST )
14391446end
1447+
14401448function Cost .SelfReveal (e ,tp ,eg ,ep ,ev ,re ,r ,rp ,chk )
14411449 local c = e :GetHandler ()
14421450 if chk == 0 then return not c :IsPublic () end
14431451 Duel .ConfirmCards (1 - tp ,c )
14441452end
14451453
1446- local self_discard_costs = {}
1454+ cost_tables . self_discard = {}
14471455function Cost .SelfDiscard (e ,tp ,eg ,ep ,ev ,re ,r ,rp ,chk )
14481456 local c = e :GetHandler ()
14491457 if chk == 0 then return c :IsDiscardable () end
14501458 Duel .SendtoGrave (c ,REASON_DISCARD |REASON_COST )
14511459end
1452- self_discard_costs [Cost .SelfDiscard ]= true
1460+ cost_tables .self_discard [Cost .SelfDiscard ]= true
1461+
14531462function Cost .SelfDiscardToGrave (e ,tp ,eg ,ep ,ev ,re ,r ,rp ,chk )
14541463 local c = e :GetHandler ()
14551464 if chk == 0 then return c :IsDiscardable () and c :IsAbleToGraveAsCost () end
14561465 Duel .SendtoGrave (c ,REASON_DISCARD |REASON_COST )
14571466end
1458- self_tograve_costs [Cost .SelfDiscardToGrave ]= true
1459- self_discard_costs [Cost .SelfDiscardToGrave ]= true
1467+ cost_tables . self_tograve [Cost .SelfDiscardToGrave ]= true
1468+ cost_tables . self_discard [Cost .SelfDiscardToGrave ]= true
14601469
14611470-- Aliases for historical reasons:
14621471Cost .SelfRelease = Cost .SelfTribute
@@ -1477,7 +1486,7 @@ function Cost.RemoveCounterFromField(counter_type,count)
14771486 end
14781487end
14791488
1480- local self_changepos_costs = {}
1489+ cost_tables . self_changepos = {}
14811490function Cost .SelfChangePosition (position )
14821491 local function cost_func (e ,tp ,eg ,ep ,ev ,re ,r ,rp ,chk )
14831492 local c = e :GetHandler ()
@@ -1486,7 +1495,7 @@ function Cost.SelfChangePosition(position)
14861495 Duel .ChangePosition (c ,position )
14871496 if fd_chk then c :SetStatus (STATUS_EFFECT_ENABLED ,true ) end
14881497 end
1489- self_changepos_costs [cost_func ]= true
1498+ cost_tables . self_changepos [cost_func ]= true
14901499 return cost_func
14911500end
14921501
@@ -1549,7 +1558,7 @@ function Cost.Reveal(filter,other,min,max,op,location)
15491558 return cost_func
15501559end
15511560
1552- local detach_costs = {}
1561+ cost_tables . detach = {}
15531562function Cost .DetachFromSelf (min ,max ,op )
15541563 max = max or min
15551564
@@ -1579,11 +1588,10 @@ function Cost.DetachFromSelf(min,max,op)
15791588 end
15801589 end
15811590
1582- detach_costs [cost_func ]= true
1591+ cost_tables . detach [cost_func ]= true
15831592 return cost_func
15841593end
15851594
1586-
15871595-- check for cards that can stay on the field, but not always
15881596function Auxiliary .RemainFieldCost (e ,tp ,eg ,ep ,ev ,re ,r ,rp ,chk )
15891597 if chk == 0 then return true end
@@ -1603,25 +1611,26 @@ function Auxiliary.RemainFieldCost(e,tp,eg,ep,ev,re,r,rp,chk)
16031611 e2 :SetReset (RESET_CHAIN )
16041612 Duel .RegisterEffect (e2 ,tp )
16051613end
1614+
1615+ cost_tables .remain_field = {}
16061616function Auxiliary .RemainFieldDisabled (e ,tp ,eg ,ep ,ev ,re ,r ,rp )
16071617 local cid = Duel .GetChainInfo (ev ,CHAININFO_CHAIN_ID )
16081618 if cid ~= e :GetLabel () then return end
16091619 if e :GetOwner ():IsLocation (LOCATION_ONFIELD ) then
16101620 e :GetOwner ():CancelToGrave (false )
16111621 end
16121622end
1613- local remain_field_costs = {}
1614- remain_field_costs [aux .RemainFieldCost ]= true
1623+ cost_tables .remain_field [aux .RemainFieldCost ]= true
16151624
1616- local function cost_table_check (t )
1617- return function (eff ) return t [eff :GetCost ()] end
1625+ local function cost_table_check (key )
1626+ return function (eff ) return cost_tables [ key ] [eff :GetCost ()] end
16181627end
16191628
1620- Effect .HasSelfToGraveCost = cost_table_check (self_tograve_costs )
1621- Effect .HasSelfDiscardCost = cost_table_check (self_discard_costs )
1622- Effect .HasDetachCost = cost_table_check (detach_costs )
1623- Effect .HasSelfChangePositionCost = cost_table_check (self_changepos_costs )
1624- Effect .HasRemainFieldCost = cost_table_check (remain_field_costs )
1629+ Effect .HasSelfToGraveCost = cost_table_check (" self_tograve " )
1630+ Effect .HasSelfDiscardCost = cost_table_check (" self_discard " )
1631+ Effect .HasDetachCost = cost_table_check (" detach " )
1632+ Effect .HasSelfChangePositionCost = cost_table_check (" self_changepos " )
1633+ Effect .HasRemainFieldCost = cost_table_check (" remain_field " )
16251634
16261635-- Default cost for "You can pay X LP;"
16271636function Cost .PayLP (lp_value ,pay_until )
@@ -1695,12 +1704,12 @@ function Cost.AND(...)
16951704 end
16961705 end
16971706
1698- for _ ,fn in ipairs (fns ) do
1699- if detach_costs [fn ] then detach_costs [full_cost ]= true end
1700- if self_discard_costs [fn ] then self_discard_costs [full_cost ]= true end
1701- if self_tograve_costs [fn ] then self_tograve_costs [full_cost ]= true end
1702- if remain_field_costs [fn ] then remain_field_costs [full_cost ]= true end
1707+ for _ ,t in pairs (cost_tables ) do
1708+ for _ ,fn in ipairs (fns ) do
1709+ if t [fn ] then t [full_cost ]= true end
1710+ end
17031711 end
1712+
17041713 return full_cost
17051714end
17061715
@@ -1725,13 +1734,13 @@ function Cost.Choice(...)
17251734 e :SetLabel (op )
17261735 end
17271736
1728- detach_costs [ full_cost ] = true
1729- self_discard_costs [full_cost ]= true
1730- for _ ,choice in ipairs (choices ) do
1731- local fn = choice [1 ]
1732- if not detach_costs [fn ] then detach_costs [full_cost ]= false end
1733- if not self_discard_costs [ fn ] then self_discard_costs [ full_cost ] = false end
1734- end
1737+ for _ , t in pairs ( cost_tables ) do
1738+ t [full_cost ]= true
1739+ for _ ,choice in ipairs (choices ) do
1740+ local fn = choice [1 ]
1741+ if not t [fn ] then t [full_cost ]= false end
1742+ end
1743+ end
17351744
17361745 return full_cost
17371746end
0 commit comments