Skip to content

Commit cb7964b

Browse files
authored
Added rudimentary "Equip Trap" handling
1 parent 32f49a7 commit cb7964b

File tree

5 files changed

+44
-26
lines changed

5 files changed

+44
-26
lines changed

official/c37390589.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function s.initial_effect(c)
1515
e1:SetOperation(s.operation)
1616
c:RegisterEffect(e1)
1717
end
18+
s.self_equip_trap=true
1819
function s.cost(e,tp,eg,ep,ev,re,r,rp,chk)
1920
if chk==0 then return true end
2021
e:SetLabel(1)

official/c43004235.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function s.initial_effect(c)
2828
e2:SetOperation(s.eqpop)
2929
c:RegisterEffect(e2)
3030
end
31+
s.self_equip_trap=true
3132
s.listed_series={SET_PLUNDER_PATROLL}
3233
function s.condition(e,tp,eg,ep,ev,re,r,rp)
3334
return Duel.IsExistingMatchingCard(aux.FaceupFilter(Card.IsSetCard,SET_PLUNDER_PATROLL),tp,LOCATION_MZONE,0,1,nil)

official/c89812483.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function s.initial_effect(c)
1616
e1:SetOperation(s.activate)
1717
c:RegisterEffect(e1)
1818
end
19+
s.self_equip_trap=true
1920
s.listed_names={CARD_MAX_METALMORPH}
2021
function s.costfilter(c,e,tp)
2122
return c:IsFaceup() and Duel.GetMZoneCount(tp,c)>0

official/c91152455.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function s.initial_effect(c)
1616
e1:SetOperation(s.activate)
1717
c:RegisterEffect(e1)
1818
end
19+
s.self_equip_trap=true
1920
s.listed_names={CARD_MAX_METALMORPH}
2021
function s.costfilter(c,tp)
2122
return c:ListsCode(CARD_MAX_METALMORPH) and c:IsFaceup() and Duel.GetMZoneCount(tp,c)>0

utility.lua

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ function Card.IsTrapMonster(c)
253253
return c:IsTrapCard() and (c:GetOriginalLevel()>0 or c:GetOriginalAttribute()>0 or c:GetOriginalRace()>0)
254254
end
255255

256+
function Card.IsEquipTrap(c)
257+
if not c:IsTrap() then return false end
258+
if c.self_equip_trap then return true end
259+
local activate_eff=c:GetActivateEffect()
260+
return activate_eff and activate_eff:HasRemainFieldCost()
261+
end
262+
256263
function Card.GetMainCardType(c)
257264
return c:GetType()&(TYPE_MONSTER|TYPE_SPELL|TYPE_TRAP)
258265
end
@@ -1650,6 +1657,36 @@ function Cost.DetachFromSelf(min,max,op)
16501657
return cost_func
16511658
end
16521659

1660+
1661+
--check for cards that can stay on the field, but not always
1662+
function Auxiliary.RemainFieldCost(e,tp,eg,ep,ev,re,r,rp,chk)
1663+
if chk==0 then return true end
1664+
local c=e:GetHandler()
1665+
local cid=Duel.GetChainInfo(0,CHAININFO_CHAIN_ID)
1666+
local e1=Effect.CreateEffect(c)
1667+
e1:SetType(EFFECT_TYPE_SINGLE)
1668+
e1:SetCode(EFFECT_REMAIN_FIELD)
1669+
e1:SetProperty(EFFECT_FLAG_OATH)
1670+
e1:SetReset(RESET_CHAIN)
1671+
c:RegisterEffect(e1)
1672+
local e2=Effect.CreateEffect(c)
1673+
e2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
1674+
e2:SetCode(EVENT_CHAIN_DISABLED)
1675+
e2:SetOperation(Auxiliary.RemainFieldDisabled)
1676+
e2:SetLabel(cid)
1677+
e2:SetReset(RESET_CHAIN)
1678+
Duel.RegisterEffect(e2,tp)
1679+
end
1680+
function Auxiliary.RemainFieldDisabled(e,tp,eg,ep,ev,re,r,rp)
1681+
local cid=Duel.GetChainInfo(ev,CHAININFO_CHAIN_ID)
1682+
if cid~=e:GetLabel() then return end
1683+
if e:GetOwner():IsLocation(LOCATION_ONFIELD) then
1684+
e:GetOwner():CancelToGrave(false)
1685+
end
1686+
end
1687+
local remain_field_costs={}
1688+
remain_field_costs[aux.RemainFieldCost]=true
1689+
16531690
local function cost_table_check(t)
16541691
return function(eff) return t[eff:GetCost()] end
16551692
end
@@ -1658,6 +1695,7 @@ Effect.HasSelfToGraveCost=cost_table_check(self_tograve_costs)
16581695
Effect.HasSelfDiscardCost=cost_table_check(self_discard_costs)
16591696
Effect.HasDetachCost=cost_table_check(detach_costs)
16601697
Effect.HasSelfChangePositionCost=cost_table_check(self_changepos_costs)
1698+
Effect.HasRemainFieldCost=cost_table_check(remain_field_costs)
16611699

16621700
--Default cost for "You can pay X LP;"
16631701
function Cost.PayLP(lp_value,pay_until)
@@ -1733,6 +1771,7 @@ function Cost.AND(...)
17331771
if detach_costs[fn] then detach_costs[full_cost]=true end
17341772
if self_discard_costs[fn] then self_discard_costs[full_cost]=true end
17351773
if self_tograve_costs[fn] then self_tograve_costs[full_cost]=true end
1774+
if remain_field_costs[fn] then remain_field_costs[full_cost]=true end
17361775
end
17371776
return full_cost
17381777
end
@@ -1941,32 +1980,7 @@ function Auxiliary.ChkfMMZ(sumcount)
19411980
return Duel.GetMZoneCount(tp,sg)>=sumcount
19421981
end
19431982
end
1944-
--check for cards that can stay on the field, but not always
1945-
function Auxiliary.RemainFieldCost(e,tp,eg,ep,ev,re,r,rp,chk)
1946-
if chk==0 then return true end
1947-
local c=e:GetHandler()
1948-
local cid=Duel.GetChainInfo(0,CHAININFO_CHAIN_ID)
1949-
local e1=Effect.CreateEffect(c)
1950-
e1:SetType(EFFECT_TYPE_SINGLE)
1951-
e1:SetCode(EFFECT_REMAIN_FIELD)
1952-
e1:SetProperty(EFFECT_FLAG_OATH)
1953-
e1:SetReset(RESET_CHAIN)
1954-
c:RegisterEffect(e1)
1955-
local e2=Effect.CreateEffect(c)
1956-
e2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
1957-
e2:SetCode(EVENT_CHAIN_DISABLED)
1958-
e2:SetOperation(Auxiliary.RemainFieldDisabled)
1959-
e2:SetLabel(cid)
1960-
e2:SetReset(RESET_CHAIN)
1961-
Duel.RegisterEffect(e2,tp)
1962-
end
1963-
function Auxiliary.RemainFieldDisabled(e,tp,eg,ep,ev,re,r,rp)
1964-
local cid=Duel.GetChainInfo(ev,CHAININFO_CHAIN_ID)
1965-
if cid~=e:GetLabel() then return end
1966-
if e:GetOwner():IsLocation(LOCATION_ONFIELD) then
1967-
e:GetOwner():CancelToGrave(false)
1968-
end
1969-
end
1983+
19701984
--autocheck for Summoning a Group containing Extra Deck/non-Extra Deck monsters to avoid zone issues
19711985
function Auxiliary.MainAndExtraSpSummonLoop(func,sumtype,sump,targetp,nocheck,nolimit,pos,mmz,emz)
19721986
return function(e,tp,eg,ep,ev,re,r,rp,sg)

0 commit comments

Comments
 (0)