name: Dual
card_text: If this card is Normal or Special Summoned: You can add 1 "Dual Avatar" Trap from your Deck to your hand. During your opponent's turn, if a face-up "Dual Avatar" monster(s) you control, except "Dual Avatar Feet - Kokoku", is destroyed by battle or card effect: You can Special Summon this card from your hand, then you can apply this effect.
  ● Destroy 1 "Dual Avatar" monster you control, and if you do, Special Summon 1 "Dual Avatar" Fusion Monster from your Extra Deck.
  You can only use each effect of "Dual Avatar Feet - Kokoku" once per turn.
external_ids: local SETCARD_ID_0 = 0x14f --Dual
  
lua: local SETCARD_ID_0 = 0x14f --Dual
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_DESTROYED)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--search
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e2:SetType(EFFECT_TYPE_TRIGGER_O + EFFECT_TYPE_SINGLE)
  	e2:SetCode(EVENT_SUMMON_SUCCESS)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e3)
  end
  function s.spfilter(c, tp)
  	return c:IsReason(REASON_BATTLE + REASON_EFFECT)
  		and c:IsPreviousSetCard(SETCARD_ID_0)
  		and c:GetPreviousCodeOnField() ~= id
  		and c:IsPreviousControler(tp)
  		and c:IsPreviousLocation(LOCATION_MZONE)
  		and c:IsPreviousPosition(POS_FACEUP)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.spfilter, 1, nil, tp) and Duel.GetTurnPlayer() ~= tp
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.desfilter(c, e, tp)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and Duel.IsExistingMatchingCard(s.sffilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, c)
  end
  function s.sffilter(c, e, tp, tc)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_FUSION) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and Duel.GetLocationCountFromEx(tp, tp, tc, c) > 0
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	if
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) ~= 0
  		and Duel.IsExistingMatchingCard(s.desfilter, tp, LOCATION_MZONE, 0, 1, nil, e, tp)
  		and Duel.SelectYesNo(tp, aux.Stringid(id, 2))
  	then
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local g = Duel.SelectMatchingCard(tp, s.desfilter, tp, LOCATION_MZONE, 0, 1, 1, nil, e, tp)
  		Duel.HintSelection(g)
  		if Duel.Destroy(g, REASON_EFFECT) ~= 0 then
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  			local sg = Duel.SelectMatchingCard(tp, s.sffilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, nil)
  			if sg:GetCount() > 0 then
  				Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  			end
  		end
  	end
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_TRAP) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  
source_text: Dual
  If this card is Normal or Special Summoned: You can add 1 "Dual Avatar" Trap from your Deck to your hand. During your opponent's turn, if a face-up "Dual Avatar" monster(s) you control, except "Dual Avatar Feet - Kokoku", is destroyed by battle or card effect: You can Special Summon this card from your hand, then you can apply this effect.
  ● Destroy 1 "Dual Avatar" monster you control, and if you do, Special Summon 1 "Dual Avatar" Fusion Monster from your Extra Deck.
  You can only use each effect of "Dual Avatar Feet - Kokoku" once per turn.
target_text: -- Dual
  local SETCARD_ID_0 = 0x14f --Dual
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_DESTROYED)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--search
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e2:SetType(EFFECT_TYPE_TRIGGER_O + EFFECT_TYPE_SINGLE)
  	e2:SetCode(EVENT_SUMMON_SUCCESS)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e3)
  end
  function s.spfilter(c, tp)
  	return c:IsReason(REASON_BATTLE + REASON_EFFECT)
  		and c:IsPreviousSetCard(SETCARD_ID_0)
  		and c:GetPreviousCodeOnField() ~= id
  		and c:IsPreviousControler(tp)
  		and c:IsPreviousLocation(LOCATION_MZONE)
  		and c:IsPreviousPosition(POS_FACEUP)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.spfilter, 1, nil, tp) and Duel.GetTurnPlayer() ~= tp
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.desfilter(c, e, tp)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and Duel.IsExistingMatchingCard(s.sffilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, c)
  end
  function s.sffilter(c, e, tp, tc)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_FUSION) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and Duel.GetLocationCountFromEx(tp, tp, tc, c) > 0
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	if
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) ~= 0
  		and Duel.IsExistingMatchingCard(s.desfilter, tp, LOCATION_MZONE, 0, 1, nil, e, tp)
  		and Duel.SelectYesNo(tp, aux.Stringid(id, 2))
  	then
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local g = Duel.SelectMatchingCard(tp, s.desfilter, tp, LOCATION_MZONE, 0, 1, 1, nil, e, tp)
  		Duel.HintSelection(g)
  		if Duel.Destroy(g, REASON_EFFECT) ~= 0 then
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  			local sg = Duel.SelectMatchingCard(tp, s.sffilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, nil)
  			if sg:GetCount() > 0 then
  				Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  			end
  		end
  	end
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_TRAP) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  