Commit a0444f9d authored by mercury233's avatar mercury233 Committed by GitHub

add Auxiliary.SelectFromOptions (#2076)

parent 52ca49bb
...@@ -66,29 +66,16 @@ function c197042.activate(e,tp,eg,ep,ev,re,r,rp) ...@@ -66,29 +66,16 @@ function c197042.activate(e,tp,eg,ep,ev,re,r,rp)
Duel.AdjustAll() Duel.AdjustAll()
local b1=Duel.IsExistingMatchingCard(c197042.xyzfilter,tp,LOCATION_EXTRA,0,1,nil) local b1=Duel.IsExistingMatchingCard(c197042.xyzfilter,tp,LOCATION_EXTRA,0,1,nil)
local b2=Duel.GetFlagEffect(tp,197042)>0 and Duel.IsExistingMatchingCard(Card.IsAbleToRemove,tp,0,LOCATION_ONFIELD,1,nil) local b2=Duel.GetFlagEffect(tp,197042)>0 and Duel.IsExistingMatchingCard(Card.IsAbleToRemove,tp,0,LOCATION_ONFIELD,1,nil)
local off=1 local op=aux.SelectFromOptions(tp,
local ops={} {b1,aux.Stringid(197042,0)},
local opval={} {b2,aux.Stringid(197042,1)},
if b1 then {true,aux.Stringid(197042,2)})
ops[off]=aux.Stringid(197042,0) if op==1 then
opval[off-1]=1
off=off+1
end
if b2 then
ops[off]=aux.Stringid(197042,1)
opval[off-1]=2
off=off+1
end
ops[off]=aux.Stringid(197042,2)
opval[off-1]=3
off=off+1
local op=Duel.SelectOption(tp,table.unpack(ops))
if opval[op]==1 then
Duel.BreakEffect() Duel.BreakEffect()
Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)
local g=Duel.SelectMatchingCard(tp,c197042.xyzfilter,tp,LOCATION_EXTRA,0,1,1,nil) local g=Duel.SelectMatchingCard(tp,c197042.xyzfilter,tp,LOCATION_EXTRA,0,1,1,nil)
Duel.XyzSummon(tp,g:GetFirst(),nil) Duel.XyzSummon(tp,g:GetFirst(),nil)
elseif opval[op]==2 then elseif op==2 then
Duel.BreakEffect() Duel.BreakEffect()
Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_REMOVE) Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_REMOVE)
local g=Duel.SelectMatchingCard(tp,Card.IsAbleToRemove,tp,0,LOCATION_ONFIELD,1,1,nil) local g=Duel.SelectMatchingCard(tp,Card.IsAbleToRemove,tp,0,LOCATION_ONFIELD,1,1,nil)
......
...@@ -68,20 +68,11 @@ function c2511.tsop(e,tp,eg,ep,ev,re,r,rp) ...@@ -68,20 +68,11 @@ function c2511.tsop(e,tp,eg,ep,ev,re,r,rp)
if not aux.NecroValleyFilter()(c) then return end if not aux.NecroValleyFilter()(c) then return end
local b1=c:IsAbleToHand() local b1=c:IsAbleToHand()
local b2=Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and c:IsCanBeSpecialSummoned(e,0,tp,false,false) local b2=Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and c:IsCanBeSpecialSummoned(e,0,tp,false,false)
local op=0 local op=aux.SelectFromOptions(tp,{b1,1190},{b2,1152})
if b1 and not b2 then if op==1 then
op=Duel.SelectOption(tp,1190)
end
if not b1 and b2 then
op=Duel.SelectOption(tp,1152)+1
end
if b1 and b2 then
op=Duel.SelectOption(tp,1190,1152)
end
if op==0 then
Duel.SendtoHand(c,nil,REASON_EFFECT) Duel.SendtoHand(c,nil,REASON_EFFECT)
end end
if op==1 then if op==2 then
Duel.SpecialSummon(c,0,tp,tp,false,false,POS_FACEUP) Duel.SpecialSummon(c,0,tp,tp,false,false,POS_FACEUP)
end end
end end
...@@ -21,32 +21,16 @@ function c95113856.cost(e,tp,eg,ep,ev,re,r,rp,chk) ...@@ -21,32 +21,16 @@ function c95113856.cost(e,tp,eg,ep,ev,re,r,rp,chk)
end end
function c95113856.target(e,tp,eg,ep,ev,re,r,rp,chk) function c95113856.target(e,tp,eg,ep,ev,re,r,rp,chk)
if chk==0 then return Duel.IsExistingMatchingCard(Card.IsAbleToRemove,tp,0,LOCATION_ONFIELD+LOCATION_HAND+LOCATION_GRAVE+LOCATION_DECK,1,nil) end if chk==0 then return Duel.IsExistingMatchingCard(Card.IsAbleToRemove,tp,0,LOCATION_ONFIELD+LOCATION_HAND+LOCATION_GRAVE+LOCATION_DECK,1,nil) end
local off=1 local b1=Duel.IsExistingMatchingCard(Card.IsAbleToRemove,tp,0,LOCATION_ONFIELD,1,nil)
local ops={} local b2=Duel.IsExistingMatchingCard(Card.IsAbleToRemove,tp,0,LOCATION_HAND,1,nil)
local opval={} local b3=Duel.IsExistingMatchingCard(Card.IsAbleToRemove,tp,0,LOCATION_GRAVE,1,nil)
if Duel.IsExistingMatchingCard(Card.IsAbleToRemove,tp,0,LOCATION_ONFIELD,1,nil) then local b4=Duel.IsExistingMatchingCard(Card.IsAbleToRemove,tp,0,LOCATION_DECK,1,nil)
ops[off]=aux.Stringid(95113856,1) local op=aux.SelectFromOptions(tp,
opval[off-1]=1 {b1,aux.Stringid(95113856,1)},
off=off+1 {b2,aux.Stringid(95113856,2)},
end {b3,aux.Stringid(95113856,3)},
if Duel.IsExistingMatchingCard(Card.IsAbleToRemove,tp,0,LOCATION_HAND,1,nil) then {b4,aux.Stringid(95113856,4)})
ops[off]=aux.Stringid(95113856,2) e:SetLabel(op)
opval[off-1]=2
off=off+1
end
if Duel.IsExistingMatchingCard(Card.IsAbleToRemove,tp,0,LOCATION_GRAVE,1,nil) then
ops[off]=aux.Stringid(95113856,3)
opval[off-1]=3
off=off+1
end
if Duel.IsExistingMatchingCard(Card.IsAbleToRemove,tp,0,LOCATION_DECK,1,nil) then
ops[off]=aux.Stringid(95113856,4)
opval[off-1]=4
off=off+1
end
if off==1 then return end
local op=Duel.SelectOption(tp,table.unpack(ops))
e:SetLabel(opval[op])
end end
function c95113856.operation(e,tp,eg,ep,ev,re,r,rp) function c95113856.operation(e,tp,eg,ep,ev,re,r,rp)
local op=e:GetLabel() local op=e:GetLabel()
......
...@@ -125,6 +125,22 @@ end ...@@ -125,6 +125,22 @@ end
function Auxiliary.PuzzleOp(e,tp) function Auxiliary.PuzzleOp(e,tp)
Duel.SetLP(0,0) Duel.SetLP(0,0)
end end
--Duel.SelectOption with option condition
--Return value starts from 1, different from Duel.SelectOption
function Auxiliary.SelectFromOptions(tp,...)
local options={...}
local ops={}
local opvals={}
for i=1,#options do
if options[i][1] then
table.insert(ops,options[i][2])
table.insert(opvals,options[i][3] or i)
end
end
if #ops==0 then return nil end
local select=Duel.SelectOption(tp,table.unpack(ops))
return opvals[select+1]
end
function Auxiliary.IsDualState(effect) function Auxiliary.IsDualState(effect)
local c=effect:GetHandler() local c=effect:GetHandler()
return not c:IsDisabled() and c:IsDualState() return not c:IsDisabled() and c:IsDualState()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment