name: Morphtronic
card_text: ● Attack Position: Once per turn: You can target 1 "Morphtronic" monster in your GY; banish that target, and if you do, add 1 "Morphtronic" monster with the same Level as the target from your Deck to your hand.
  ● Defense Position: Once per turn: You can send 1 "Morphtronic" monster from your hand to the GY, and if you do, add 1 other "Morphtronic" monster with the same Level as that monster from your GY to your hand.
external_ids: local SETCARD_ID_0 = 0x26 --Morphtronic
  
lua: local SETCARD_ID_0 = 0x26 --Morphtronic
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--search
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_REMOVE + CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCondition(s.cona)
  	e1:SetTarget(s.tga)
  	e1:SetOperation(s.opa)
  	c:RegisterEffect(e1)
  	--salvage
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOGRAVE + CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetCountLimit(1)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCondition(s.cond)
  	e2:SetTarget(s.tgd)
  	e2:SetOperation(s.opd)
  	c:RegisterEffect(e2)
  end
  function s.filter(c, lv)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsLevel(lv) and c:IsAbleToHand()
  end
  function s.cona(e, tp, eg, ep, ev, re, r, rp)
  	return not e:GetHandler():IsDisabled() and e:GetHandler():IsAttackPos()
  end
  function s.filtera(c, tp)
  	local lv = c:GetLevel()
  	return c:IsSetCard(SETCARD_ID_0) and lv > 0 and c:IsAbleToRemove() and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil, lv)
  end
  function s.tga(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filtera(chkc, tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filtera, tp, LOCATION_GRAVE, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectTarget(tp, s.filtera, tp, LOCATION_GRAVE, 0, 1, 1, nil, tp)
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g, 1, tp, LOCATION_GRAVE)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.opa(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.Remove(tc, POS_FACEUP, REASON_EFFECT) ~= 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil, tc:GetLevel())
  		if g:GetCount() > 0 then
  			Duel.SendtoHand(g, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, g)
  		end
  	end
  end
  function s.cond(e, tp, eg, ep, ev, re, r, rp)
  	return not e:GetHandler():IsDisabled() and e:GetHandler():IsDefensePos()
  end
  function s.filterd(c, tp)
  	local lv = c:GetLevel()
  	return c:IsSetCard(SETCARD_ID_0) and lv > 0 and c:IsAbleToGrave() and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_GRAVE, 0, 1, nil, lv)
  end
  function s.tgd(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filterd, tp, LOCATION_HAND, 0, 1, nil, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_HAND)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.opd(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.filterd, tp, LOCATION_HAND, 0, 1, 1, nil, tp)
  	local tc = g:GetFirst()
  	if not tc then
  		return
  	end
  	Duel.SendtoGrave(tc, REASON_EFFECT)
  	if not tc:IsLocation(LOCATION_GRAVE) then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local sg = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, tc, tc:GetLevel())
  	if sg:GetCount() > 0 then
  		Duel.SendtoHand(sg, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, sg)
  	end
  end
  
  
source_text: Morphtronic
  ● Attack Position: Once per turn: You can target 1 "Morphtronic" monster in your GY; banish that target, and if you do, add 1 "Morphtronic" monster with the same Level as the target from your Deck to your hand.
  ● Defense Position: Once per turn: You can send 1 "Morphtronic" monster from your hand to the GY, and if you do, add 1 other "Morphtronic" monster with the same Level as that monster from your GY to your hand.
target_text: -- Morphtronic
  local SETCARD_ID_0 = 0x26 --Morphtronic
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--search
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_REMOVE + CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCondition(s.cona)
  	e1:SetTarget(s.tga)
  	e1:SetOperation(s.opa)
  	c:RegisterEffect(e1)
  	--salvage
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOGRAVE + CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetCountLimit(1)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCondition(s.cond)
  	e2:SetTarget(s.tgd)
  	e2:SetOperation(s.opd)
  	c:RegisterEffect(e2)
  end
  function s.filter(c, lv)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsLevel(lv) and c:IsAbleToHand()
  end
  function s.cona(e, tp, eg, ep, ev, re, r, rp)
  	return not e:GetHandler():IsDisabled() and e:GetHandler():IsAttackPos()
  end
  function s.filtera(c, tp)
  	local lv = c:GetLevel()
  	return c:IsSetCard(SETCARD_ID_0) and lv > 0 and c:IsAbleToRemove() and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil, lv)
  end
  function s.tga(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filtera(chkc, tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filtera, tp, LOCATION_GRAVE, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectTarget(tp, s.filtera, tp, LOCATION_GRAVE, 0, 1, 1, nil, tp)
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g, 1, tp, LOCATION_GRAVE)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.opa(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.Remove(tc, POS_FACEUP, REASON_EFFECT) ~= 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil, tc:GetLevel())
  		if g:GetCount() > 0 then
  			Duel.SendtoHand(g, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, g)
  		end
  	end
  end
  function s.cond(e, tp, eg, ep, ev, re, r, rp)
  	return not e:GetHandler():IsDisabled() and e:GetHandler():IsDefensePos()
  end
  function s.filterd(c, tp)
  	local lv = c:GetLevel()
  	return c:IsSetCard(SETCARD_ID_0) and lv > 0 and c:IsAbleToGrave() and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_GRAVE, 0, 1, nil, lv)
  end
  function s.tgd(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filterd, tp, LOCATION_HAND, 0, 1, nil, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_HAND)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.opd(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.filterd, tp, LOCATION_HAND, 0, 1, 1, nil, tp)
  	local tc = g:GetFirst()
  	if not tc then
  		return
  	end
  	Duel.SendtoGrave(tc, REASON_EFFECT)
  	if not tc:IsLocation(LOCATION_GRAVE) then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local sg = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, tc, tc:GetLevel())
  	if sg:GetCount() > 0 then
  		Duel.SendtoHand(sg, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, sg)
  	end
  end
  
  