name: 宝玉の絆
card_text: このカード名のカードは1ターンに1枚しか発動できない。
  1:デッキから「宝玉獣」モンスター1体を手札に加え、そのモンスターとはカード名が異なる「宝玉獣」モンスター1体をデッキから選び、永続魔法カード扱いで自分の魔法&罠ゾーンに表側表示で置く。
external_ids: local SETCARD_ID_0 = 0x1034 --宝玉獣
  
lua: local SETCARD_ID_0 = 0x1034 --宝玉獣
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.thfilter(c, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand() and Duel.IsExistingMatchingCard(s.plfilter, tp, LOCATION_DECK, 0, 1, nil, c:GetCode())
  end
  function s.plfilter(c, code)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and not c:IsCode(code) and not c:IsForbidden()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ft = 0
  	if e:GetHandler():IsLocation(LOCATION_HAND) then
  		ft = 1
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > ft and Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g1 = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil, tp)
  	if g1:GetCount() > 0 and Duel.SendtoHand(g1, nil, REASON_EFFECT) ~= 0 and g1:GetFirst():IsLocation(LOCATION_HAND) then
  		Duel.ConfirmCards(1 - tp, g1)
  		if Duel.GetLocationCount(tp, LOCATION_SZONE) <= 0 then
  			return
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  		local g2 = Duel.SelectMatchingCard(tp, s.plfilter, tp, LOCATION_DECK, 0, 1, 1, nil, g1:GetFirst():GetCode())
  		local tc = g2:GetFirst()
  		if tc then
  			Duel.MoveToField(tc, tp, tp, LOCATION_SZONE, POS_FACEUP, true)
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_CHANGE_TYPE)
  			e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  			e1:SetValue(TYPE_SPELL + TYPE_CONTINUOUS)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD - RESET_TURN_SET)
  			tc:RegisterEffect(e1)
  		end
  	end
  end
  
  
source_text: 宝玉の絆
  このカード名のカードは1ターンに1枚しか発動できない。
  1:デッキから「宝玉獣」モンスター1体を手札に加え、そのモンスターとはカード名が異なる「宝玉獣」モンスター1体をデッキから選び、永続魔法カード扱いで自分の魔法&罠ゾーンに表側表示で置く。
target_text: -- 宝玉の絆
  local SETCARD_ID_0 = 0x1034 --宝玉獣
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.thfilter(c, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand() and Duel.IsExistingMatchingCard(s.plfilter, tp, LOCATION_DECK, 0, 1, nil, c:GetCode())
  end
  function s.plfilter(c, code)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and not c:IsCode(code) and not c:IsForbidden()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ft = 0
  	if e:GetHandler():IsLocation(LOCATION_HAND) then
  		ft = 1
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > ft and Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g1 = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil, tp)
  	if g1:GetCount() > 0 and Duel.SendtoHand(g1, nil, REASON_EFFECT) ~= 0 and g1:GetFirst():IsLocation(LOCATION_HAND) then
  		Duel.ConfirmCards(1 - tp, g1)
  		if Duel.GetLocationCount(tp, LOCATION_SZONE) <= 0 then
  			return
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  		local g2 = Duel.SelectMatchingCard(tp, s.plfilter, tp, LOCATION_DECK, 0, 1, 1, nil, g1:GetFirst():GetCode())
  		local tc = g2:GetFirst()
  		if tc then
  			Duel.MoveToField(tc, tp, tp, LOCATION_SZONE, POS_FACEUP, true)
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_CHANGE_TYPE)
  			e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  			e1:SetValue(TYPE_SPELL + TYPE_CONTINUOUS)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD - RESET_TURN_SET)
  			tc:RegisterEffect(e1)
  		end
  	end
  end
  
  