name: 覇王龍の奇跡
card_text: 1:自分フィールドに「覇王龍ズァーク」が存在する場合、以下の効果から1つを選択して発動できる(このカード名の以下の効果はそれぞれ1ターンに1度しか選択できない)。
  ●自分フィールドの「覇王龍ズァーク」1枚を破壊し、デッキ・EXデッキから「オッドアイズ」Pモンスターまたは光属性の「覇王龍ズァーク」1体を召喚条件を無視して特殊召喚する。
  ●自分のEXデッキの表側のPモンスター1体を自分のPゾーンに置く。
  ●デッキから速攻魔法カード1枚を自分フィールドにセットする。
external_ids: local CARD_ID_0 = 13331639 --覇王龍ズァーク
  local SETCARD_ID_0 = 0x99 --オッドアイズ
  
lua: local CARD_ID_0 = 13331639 --覇王龍ズァーク
  local SETCARD_ID_0 = 0x99 --オッドアイズ
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--select effect
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c)
  	return c:IsCode(CARD_ID_0) and c:IsFaceup()
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_ONFIELD, 0, 1, nil)
  end
  function s.desfilter(c)
  	return c:IsCode(CARD_ID_0) and c:IsFaceup()
  end
  function s.spfilter(c, e, tp)
  	return ((c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_PENDULUM)) or (c:IsCode(CARD_ID_0) and c:IsAttribute(ATTRIBUTE_LIGHT)))
  		and ((c:IsLocation(LOCATION_DECK) and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0) or (c:IsLocation(LOCATION_EXTRA) and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0))
  		and c:IsCanBeSpecialSummoned(e, 0, tp, true, false)
  end
  function s.psfilter(c)
  	return c:IsType(TYPE_PENDULUM) and c:IsFaceup() and not c:IsForbidden()
  end
  function s.ssfilter(c)
  	return c:IsType(TYPE_QUICKPLAY) and c:IsSSetable()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g1 = Duel.GetMatchingGroup(s.desfilter, tp, LOCATION_ONFIELD, 0, nil)
  	local g2 = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_DECK + LOCATION_EXTRA, 0, nil, e, tp)
  	local b1 = (Duel.GetFlagEffect(tp, id + 1) == 0 or not e:IsCostChecked()) and g1:GetCount() > 0 and g2:GetCount() > 0
  	local b2 = (Duel.GetFlagEffect(tp, id + 2) == 0 or not e:IsCostChecked())
  		and (Duel.CheckLocation(tp, LOCATION_PZONE, 0) or Duel.CheckLocation(tp, LOCATION_PZONE, 1))
  		and Duel.IsExistingMatchingCard(s.psfilter, tp, LOCATION_EXTRA, 0, 1, nil)
  	local b3 = (Duel.GetFlagEffect(tp, id + 3) == 0 or not e:IsCostChecked()) and Duel.IsExistingMatchingCard(s.ssfilter, tp, LOCATION_DECK, 0, 1, nil)
  	if chk == 0 then
  		return b1 or b2 or b3
  	end
  	local op = aux.SelectFromOptions(tp, { b1, aux.Stringid(id, 1) }, { b2, aux.Stringid(id, 2) }, { b3, aux.Stringid(id, 3) })
  	if e:IsCostChecked() then
  		Duel.RegisterFlagEffect(tp, id + op, RESET_PHASE + PHASE_END, 0, 1)
  	end
  	if op == 1 then
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, g1, 1, 0, 0)
  		Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK + LOCATION_EXTRA)
  		if e:IsCostChecked() then
  			e:SetCategory(CATEGORY_DESTROY + CATEGORY_SPECIAL_SUMMON)
  		end
  		e:SetOperation(s.spop)
  	elseif op == 2 then
  		if e:IsCostChecked() then
  			e:SetCategory(0)
  		end
  		e:SetOperation(s.psop)
  	else
  		if e:IsCostChecked() then
  			e:SetCategory(0)
  		end
  		e:SetOperation(s.ssop)
  	end
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g1 = Duel.SelectMatchingCard(tp, s.desfilter, tp, LOCATION_ONFIELD, 0, 1, 1, nil)
  	local g2 = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_DECK + LOCATION_EXTRA, 0, nil, e, tp)
  	if Duel.Destroy(g1, REASON_EFFECT) > 0 and g2:GetCount() > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sc = g2:Select(tp, 1, 1, nil)
  		Duel.SpecialSummon(sc, 0, tp, tp, true, false, POS_FACEUP)
  	end
  end
  function s.psop(e, tp, eg, ep, ev, re, r, rp)
  	if not Duel.CheckLocation(tp, LOCATION_PZONE, 0) and not Duel.CheckLocation(tp, LOCATION_PZONE, 1) then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  	local g = Duel.SelectMatchingCard(tp, s.psfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if not tc then
  		return
  	end
  	if Duel.MoveToField(tc, tp, tp, LOCATION_PZONE, POS_FACEUP, false) then
  		tc:SetStatus(STATUS_EFFECT_ENABLED, true)
  	end
  end
  function s.ssop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g = Duel.SelectMatchingCard(tp, s.ssfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SSet(tp, g:GetFirst())
  	end
  end
  
  
source_text: 覇王龍の奇跡
  1:自分フィールドに「覇王龍ズァーク」が存在する場合、以下の効果から1つを選択して発動できる(このカード名の以下の効果はそれぞれ1ターンに1度しか選択できない)。
  ●自分フィールドの「覇王龍ズァーク」1枚を破壊し、デッキ・EXデッキから「オッドアイズ」Pモンスターまたは光属性の「覇王龍ズァーク」1体を召喚条件を無視して特殊召喚する。
  ●自分のEXデッキの表側のPモンスター1体を自分のPゾーンに置く。
  ●デッキから速攻魔法カード1枚を自分フィールドにセットする。
target_text: -- 覇王龍の奇跡
  local CARD_ID_0 = 13331639 --覇王龍ズァーク
  local SETCARD_ID_0 = 0x99 --オッドアイズ
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--select effect
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c)
  	return c:IsCode(CARD_ID_0) and c:IsFaceup()
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_ONFIELD, 0, 1, nil)
  end
  function s.desfilter(c)
  	return c:IsCode(CARD_ID_0) and c:IsFaceup()
  end
  function s.spfilter(c, e, tp)
  	return ((c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_PENDULUM)) or (c:IsCode(CARD_ID_0) and c:IsAttribute(ATTRIBUTE_LIGHT)))
  		and ((c:IsLocation(LOCATION_DECK) and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0) or (c:IsLocation(LOCATION_EXTRA) and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0))
  		and c:IsCanBeSpecialSummoned(e, 0, tp, true, false)
  end
  function s.psfilter(c)
  	return c:IsType(TYPE_PENDULUM) and c:IsFaceup() and not c:IsForbidden()
  end
  function s.ssfilter(c)
  	return c:IsType(TYPE_QUICKPLAY) and c:IsSSetable()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g1 = Duel.GetMatchingGroup(s.desfilter, tp, LOCATION_ONFIELD, 0, nil)
  	local g2 = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_DECK + LOCATION_EXTRA, 0, nil, e, tp)
  	local b1 = (Duel.GetFlagEffect(tp, id + 1) == 0 or not e:IsCostChecked()) and g1:GetCount() > 0 and g2:GetCount() > 0
  	local b2 = (Duel.GetFlagEffect(tp, id + 2) == 0 or not e:IsCostChecked())
  		and (Duel.CheckLocation(tp, LOCATION_PZONE, 0) or Duel.CheckLocation(tp, LOCATION_PZONE, 1))
  		and Duel.IsExistingMatchingCard(s.psfilter, tp, LOCATION_EXTRA, 0, 1, nil)
  	local b3 = (Duel.GetFlagEffect(tp, id + 3) == 0 or not e:IsCostChecked()) and Duel.IsExistingMatchingCard(s.ssfilter, tp, LOCATION_DECK, 0, 1, nil)
  	if chk == 0 then
  		return b1 or b2 or b3
  	end
  	local op = aux.SelectFromOptions(tp, { b1, aux.Stringid(id, 1) }, { b2, aux.Stringid(id, 2) }, { b3, aux.Stringid(id, 3) })
  	if e:IsCostChecked() then
  		Duel.RegisterFlagEffect(tp, id + op, RESET_PHASE + PHASE_END, 0, 1)
  	end
  	if op == 1 then
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, g1, 1, 0, 0)
  		Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK + LOCATION_EXTRA)
  		if e:IsCostChecked() then
  			e:SetCategory(CATEGORY_DESTROY + CATEGORY_SPECIAL_SUMMON)
  		end
  		e:SetOperation(s.spop)
  	elseif op == 2 then
  		if e:IsCostChecked() then
  			e:SetCategory(0)
  		end
  		e:SetOperation(s.psop)
  	else
  		if e:IsCostChecked() then
  			e:SetCategory(0)
  		end
  		e:SetOperation(s.ssop)
  	end
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g1 = Duel.SelectMatchingCard(tp, s.desfilter, tp, LOCATION_ONFIELD, 0, 1, 1, nil)
  	local g2 = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_DECK + LOCATION_EXTRA, 0, nil, e, tp)
  	if Duel.Destroy(g1, REASON_EFFECT) > 0 and g2:GetCount() > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sc = g2:Select(tp, 1, 1, nil)
  		Duel.SpecialSummon(sc, 0, tp, tp, true, false, POS_FACEUP)
  	end
  end
  function s.psop(e, tp, eg, ep, ev, re, r, rp)
  	if not Duel.CheckLocation(tp, LOCATION_PZONE, 0) and not Duel.CheckLocation(tp, LOCATION_PZONE, 1) then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  	local g = Duel.SelectMatchingCard(tp, s.psfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if not tc then
  		return
  	end
  	if Duel.MoveToField(tc, tp, tp, LOCATION_PZONE, POS_FACEUP, false) then
  		tc:SetStatus(STATUS_EFFECT_ENABLED, true)
  	end
  end
  function s.ssop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g = Duel.SelectMatchingCard(tp, s.ssfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SSet(tp, g:GetFirst())
  	end
  end
  
  