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)
Duel.AdjustAll()
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 off=1
local ops={}
local opval={}
if b1 then
ops[off]=aux.Stringid(197042,0)
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
local op=aux.SelectFromOptions(tp,
{b1,aux.Stringid(197042,0)},
{b2,aux.Stringid(197042,1)},
{true,aux.Stringid(197042,2)})
if op==1 then
Duel.BreakEffect()
Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)
local g=Duel.SelectMatchingCard(tp,c197042.xyzfilter,tp,LOCATION_EXTRA,0,1,1,nil)
Duel.XyzSummon(tp,g:GetFirst(),nil)
elseif opval[op]==2 then
elseif op==2 then
Duel.BreakEffect()
Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_REMOVE)
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)
if not aux.NecroValleyFilter()(c) then return end
local b1=c:IsAbleToHand()
local b2=Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and c:IsCanBeSpecialSummoned(e,0,tp,false,false)
local op=0
if b1 and not b2 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
local op=aux.SelectFromOptions(tp,{b1,1190},{b2,1152})
if op==1 then
Duel.SendtoHand(c,nil,REASON_EFFECT)
end
if op==1 then
if op==2 then
Duel.SpecialSummon(c,0,tp,tp,false,false,POS_FACEUP)
end
end
......@@ -21,32 +21,16 @@ function c95113856.cost(e,tp,eg,ep,ev,re,r,rp,chk)
end
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
local off=1
local ops={}
local opval={}
if Duel.IsExistingMatchingCard(Card.IsAbleToRemove,tp,0,LOCATION_ONFIELD,1,nil) then
ops[off]=aux.Stringid(95113856,1)
opval[off-1]=1
off=off+1
end
if Duel.IsExistingMatchingCard(Card.IsAbleToRemove,tp,0,LOCATION_HAND,1,nil) then
ops[off]=aux.Stringid(95113856,2)
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])
local b1=Duel.IsExistingMatchingCard(Card.IsAbleToRemove,tp,0,LOCATION_ONFIELD,1,nil)
local b2=Duel.IsExistingMatchingCard(Card.IsAbleToRemove,tp,0,LOCATION_HAND,1,nil)
local b3=Duel.IsExistingMatchingCard(Card.IsAbleToRemove,tp,0,LOCATION_GRAVE,1,nil)
local b4=Duel.IsExistingMatchingCard(Card.IsAbleToRemove,tp,0,LOCATION_DECK,1,nil)
local op=aux.SelectFromOptions(tp,
{b1,aux.Stringid(95113856,1)},
{b2,aux.Stringid(95113856,2)},
{b3,aux.Stringid(95113856,3)},
{b4,aux.Stringid(95113856,4)})
e:SetLabel(op)
end
function c95113856.operation(e,tp,eg,ep,ev,re,r,rp)
local op=e:GetLabel()
......
......@@ -125,6 +125,22 @@ end
function Auxiliary.PuzzleOp(e,tp)
Duel.SetLP(0,0)
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)
local c=effect:GetHandler()
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