Skip to content

Commit 930ebdd

Browse files
authored
Updated "Cost.Discard" and some cards to use it
Cost.Discard: - Can now take both a min and a max number to discard that can also be a function that returns a number. - Can now take an additional operation function if the effect needs to do something regarding the discarded cards (e.g. save how many were discarded). - Now by default also passes the effect itself and the triggering player to the discard filter. Updated "Linkslayer" and "Dragonic Warrior" to make use of these updates.
1 parent f2b2321 commit 930ebdd

3 files changed

Lines changed: 46 additions & 36 deletions

File tree

official/c35595518.lua

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,51 @@
22
--Linkslayer
33
local s,id=GetID()
44
function s.initial_effect(c)
5-
--spsummon proc
5+
--If you control no monsters, you can Special Summon this card (from your hand)
66
local e1=Effect.CreateEffect(c)
7+
e1:SetDescription(aux.Stringid(id,0))
78
e1:SetType(EFFECT_TYPE_FIELD)
8-
e1:SetCode(EFFECT_SPSUMMON_PROC)
99
e1:SetProperty(EFFECT_FLAG_UNCOPYABLE)
10+
e1:SetCode(EFFECT_SPSUMMON_PROC)
1011
e1:SetRange(LOCATION_HAND)
1112
e1:SetCondition(s.spcon)
1213
c:RegisterEffect(e1)
13-
--destroy
14+
--Destroy up to 2 Spells/Traps on the field
1415
local e2=Effect.CreateEffect(c)
15-
e2:SetDescription(aux.Stringid(id,0))
16+
e2:SetDescription(aux.Stringid(id,1))
1617
e2:SetCategory(CATEGORY_DESTROY)
1718
e2:SetType(EFFECT_TYPE_IGNITION)
18-
e2:SetCountLimit(1)
1919
e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
2020
e2:SetRange(LOCATION_MZONE)
21-
e2:SetCost(s.cost)
22-
e2:SetTarget(s.target)
23-
e2:SetOperation(s.operation)
21+
e2:SetCountLimit(1)
22+
e2:SetCost(Cost.Discard(nil,nil,1,
23+
function(e,tp)
24+
return math.min(2,Duel.GetTargetCount(Card.IsSpellTrap,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,nil))
25+
end,
26+
function(e,tp,og) e:SetLabel(#og) end
27+
)
28+
)
29+
e2:SetTarget(s.destg)
30+
e2:SetOperation(s.desop)
2431
c:RegisterEffect(e2)
2532
end
2633
function s.spcon(e,c)
2734
if c==nil then return true end
28-
return Duel.GetFieldGroupCount(c:GetControler(),LOCATION_MZONE,0,nil)==0
29-
and Duel.GetLocationCount(c:GetControler(),LOCATION_MZONE)>0
30-
end
31-
function s.cost(e,tp,eg,ep,ev,re,r,rp,chk)
32-
if chk==0 then return Duel.IsExistingMatchingCard(Card.IsDiscardable,tp,LOCATION_HAND,0,1,nil) end
33-
local rt=Duel.GetTargetCount(Card.IsSpellTrap,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,nil)
34-
if rt>2 then rt=2 end
35-
local ct=Duel.DiscardHand(tp,nil,1,rt,REASON_DISCARD|REASON_COST)
36-
e:SetLabel(ct)
35+
local tp=c:GetControler()
36+
return Duel.GetFieldGroupCount(tp,LOCATION_MZONE,0,nil)==0
37+
and Duel.GetLocationCount(tp,LOCATION_MZONE)>0
3738
end
38-
function s.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc)
39+
function s.destg(e,tp,eg,ep,ev,re,r,rp,chk,chkc)
3940
if chkc then return chkc:IsOnField() and chkc:IsSpellTrap() end
4041
if chk==0 then return Duel.IsExistingTarget(Card.IsSpellTrap,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,1,nil) end
4142
local ct=e:GetLabel()
4243
Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_DESTROY)
4344
local g=Duel.SelectTarget(tp,Card.IsSpellTrap,tp,LOCATION_ONFIELD,LOCATION_ONFIELD,ct,ct,nil)
44-
Duel.SetOperationInfo(0,CATEGORY_DESTROY,g,ct,0,0)
45+
Duel.SetOperationInfo(0,CATEGORY_DESTROY,g,ct,tp,0)
4546
end
46-
function s.operation(e,tp,eg,ep,ev,re,r,rp,chk)
47-
local tg=Duel.GetChainInfo(0,CHAININFO_TARGET_CARDS)
48-
local rg=tg:Filter(Card.IsRelateToEffect,nil,e)
49-
if #rg>0 then
50-
Duel.Destroy(rg,REASON_EFFECT)
47+
function s.desop(e,tp,eg,ep,ev,re,r,rp,chk)
48+
local tg=Duel.GetTargetCards(e)
49+
if #tg>0 then
50+
Duel.Destroy(tg,REASON_EFFECT)
5151
end
5252
end

pre-release/c100201001.lua

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function s.initial_effect(c)
99
e1:SetType(EFFECT_TYPE_IGNITION)
1010
e1:SetRange(LOCATION_MZONE)
1111
e1:SetCountLimit(1,id)
12-
e1:SetCost(s.spcost)
12+
e1:SetCost(Cost.Discard(s.spcostfilter))
1313
e1:SetTarget(s.sptg)
1414
e1:SetOperation(s.spop)
1515
c:RegisterEffect(e1)
@@ -21,10 +21,6 @@ end
2121
function s.spfilter(c,e,tp)
2222
return c:IsLevelBelow(4) and c:IsRace(RACE_DRAGON) and not c:IsCode(id) and c:IsCanBeSpecialSummoned(e,0,tp,false,false)
2323
end
24-
function s.spcost(e,tp,eg,ep,ev,re,r,rp,chk)
25-
if chk==0 then return Duel.IsExistingMatchingCard(s.spcostfilter,tp,LOCATION_HAND,0,1,nil,e,tp) end
26-
Duel.DiscardHand(tp,s.spcostfilter,1,1,REASON_COST|REASON_DISCARD,nil,e,tp)
27-
end
2824
function s.sptg(e,tp,eg,ep,ev,re,r,rp,chk)
2925
if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE,0)>0
3026
and Duel.IsExistingMatchingCard(s.spfilter,tp,LOCATION_HAND|LOCATION_DECK,0,1,nil,e,tp) end
@@ -39,4 +35,4 @@ function s.spop(e,tp,eg,ep,ev,re,r,rp)
3935
sc:NegateEffects(e:GetHandler())
4036
end
4137
Duel.SpecialSummonComplete()
42-
end
38+
end

utility.lua

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,14 +1513,28 @@ function Cost.HintSelectedEffect(e,tp,eg,ep,ev,re,r,rp,chk)
15131513
Duel.Hint(HINT_OPSELECTED,1-tp,e:GetDescription())
15141514
end
15151515

1516-
function Cost.Discard(filter,other,count)
1517-
count=count or 1
1518-
filter=filter and aux.AND(filter,Card.IsDiscardable) or Card.IsDiscardable
1519-
return function(e,tp,eg,ep,ev,re,r,rp,chk)
1516+
function Cost.Discard(filter,other,min,max,op)
1517+
local min_type=type(min)
1518+
local max_type=type(max)
1519+
1520+
local function filter_final(c,e,tp)
1521+
return (not filter or filter(c,e,tp)) and c:IsDiscardable()
1522+
end
1523+
1524+
local function cost_func(e,tp,eg,ep,ev,re,r,rp,chk)
1525+
local min_count=(min_type=="function" and min(e,tp))
1526+
or (min==nil and 1)
1527+
or min
1528+
local max_count=(max_type=="function" and max(e,tp))
1529+
or (max==nil and min_count)
1530+
or max
15201531
local exclude=other and e:GetHandler() or nil
1521-
if chk==0 then return Duel.IsExistingMatchingCard(filter,tp,LOCATION_HAND,0,count,exclude) end
1522-
Duel.DiscardHand(tp,filter,count,count,REASON_COST|REASON_DISCARD,exclude)
1532+
if chk==0 then return min_count>0 and max_count>=min_count
1533+
and Duel.IsExistingMatchingCard(filter_final,tp,LOCATION_HAND,0,min_count,exclude,e,tp) end
1534+
Duel.DiscardHand(tp,filter_final,min_count,max_count,REASON_COST|REASON_DISCARD,exclude,e,tp)
1535+
if op then op(e,tp,Duel.GetOperatedGroup()) end
15231536
end
1537+
return cost_func
15241538
end
15251539

15261540
local detach_costs={}

0 commit comments

Comments
 (0)