-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
proc_equip.lua
68 lines (68 loc) · 2.26 KB
/
proc_equip.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
--add procedure to equip spells equipping by rule
function Auxiliary.AddEquipProcedure(c,p,f,eqlimit,cost,tg,op,con,prop)
--Note: p==0 is check equip spell controler, p==1 for opponent's, PLAYER_ALL for both player's monsters
local property=prop or 0
--Activate
local e1=Effect.CreateEffect(c)
e1:SetDescription(1068)
e1:SetCategory(CATEGORY_EQUIP)
e1:SetType(EFFECT_TYPE_ACTIVATE)
e1:SetCode(EVENT_FREE_CHAIN)
e1:SetProperty(EFFECT_FLAG_CARD_TARGET+EFFECT_FLAG_CONTINUOUS_TARGET+property)
if con then
e1:SetCondition(con)
end
if cost~=nil then
e1:SetCost(cost)
end
e1:SetTarget(Auxiliary.EquipTarget(tg,p,f))
e1:SetOperation(Auxiliary.EquipOperation(op))
c:RegisterEffect(e1)
--Equip limit
local e2=Effect.CreateEffect(c)
e2:SetType(EFFECT_TYPE_SINGLE)
e2:SetCode(EFFECT_EQUIP_LIMIT)
e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
if eqlimit~=nil then
e2:SetValue(eqlimit)
else
e2:SetValue(Auxiliary.EquipLimit(f))
end
c:RegisterEffect(e2)
return e1
end
function Auxiliary.EquipLimit(f)
return function(e,c)
return not f or f(c,e,e:GetHandlerPlayer())
end
end
function Auxiliary.EquipFilter(c,p,f,e,tp)
return (p==PLAYER_ALL or c:IsControler(p)) and c:IsFaceup() and (not f or f(c,e,tp))
end
function Auxiliary.EquipTarget(tg,p,f)
return function(e,tp,eg,ep,ev,re,r,rp,chk,chkc)
local player=nil
if p==0 then
player=tp
elseif p==1 then
player=1-tp
elseif p==PLAYER_ALL or p==nil then
player=PLAYER_ALL
end
if chkc then return chkc:IsLocation(LOCATION_MZONE) and chkc:IsFaceup() and Auxiliary.EquipFilter(chkc,player,f,e,tp) end
if chk==0 then return player~=nil and Duel.IsExistingTarget(Auxiliary.EquipFilter,tp,LOCATION_MZONE,LOCATION_MZONE,1,nil,player,f,e,tp) end
Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_EQUIP)
local g=Duel.SelectTarget(tp,Auxiliary.EquipFilter,tp,LOCATION_MZONE,LOCATION_MZONE,1,1,nil,player,f,e,tp)
if tg then tg(e,tp,eg,ep,ev,re,r,rp,g:GetFirst()) end
Duel.SetOperationInfo(0,CATEGORY_EQUIP,e:GetHandler(),1,0,0)
end
end
function Auxiliary.EquipOperation(op)
return function(e,tp,eg,ep,ev,re,r,rp)
local tc=Duel.GetFirstTarget()
if tc:IsRelateToEffect(e) and tc:IsFaceup() then
Duel.Equip(tp,e:GetHandler(),tc)
end
if op then op(e,tp,eg,ep,ev,re,r,rp) end
end
end