name: ドクターD
card_text: 1:自分の墓地から「D-HERO」モンスター1体を除外して発動できる。
  自分の墓地から「D-HERO」モンスター1体を選び、手札に加えるか特殊召喚する。
  2:墓地のこのカードを除外し、自分フィールドの「D-HERO」モンスター2体を対象として発動できる。
  対象のモンスター1体の攻撃力は、もう1体のモンスターの攻撃力と同じになる。
external_ids: local SETCARD_ID_0 = 0xc008 --D-HERO
  
lua: local SETCARD_ID_0 = 0xc008 --D-HERO
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SPECIAL_SUMMON + CATEGORY_GRAVE_ACTION + CATEGORY_GRAVE_SPSUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--atk
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_ATKCHANGE)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.atktg)
  	e2:SetOperation(s.atkop)
  	c:RegisterEffect(e2)
  end
  function s.costfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemoveAsCost() and Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_GRAVE, 0, 1, c, e, tp)
  end
  function s.thfilter(c, e, tp)
  	if not (c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER)) then
  		return false
  	end
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	return c:IsAbleToHand() or (ft > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false))
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(1)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.costfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local res = e:GetLabel() == 1
  		e:SetLabel(0)
  		return res or Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	e:SetLabel(0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_OPERATECARD)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.thfilter), tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	local tc = g:GetFirst()
  	if tc then
  		if tc:IsAbleToHand() and (not tc:IsCanBeSpecialSummoned(e, 0, tp, false, false) or ft <= 0 or Duel.SelectOption(tp, 1190, 1152) == 0) then
  			Duel.SendtoHand(tc, nil, REASON_EFFECT)
  		else
  			Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  		end
  	end
  end
  function s.atkfilter1(c, tp)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and Duel.IsExistingTarget(s.atkfilter2, tp, LOCATION_MZONE, 0, 1, c, c)
  end
  function s.atkfilter2(c, tc)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and not c:IsAttack(tc:GetAttack())
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.atkfilter1, tp, LOCATION_MZONE, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 2))
  	local g1 = Duel.SelectTarget(tp, s.atkfilter1, tp, LOCATION_MZONE, 0, 1, 1, nil, tp)
  	local tc = g1:GetFirst()
  	e:SetLabelObject(tc)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.atkfilter2, tp, LOCATION_MZONE, 0, 1, 1, tc, tc)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local hc = e:GetLabelObject()
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local tc = g:GetFirst()
  	if tc == hc then
  		tc = g:GetNext()
  	end
  	if hc:IsFaceup() and hc:IsRelateToEffect(e) and tc:IsFaceup() and tc:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  		e1:SetValue(tc:GetAttack())
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		hc:RegisterEffect(e1)
  	end
  end
  
  
source_text: ドクターD
  1:自分の墓地から「D-HERO」モンスター1体を除外して発動できる。
  自分の墓地から「D-HERO」モンスター1体を選び、手札に加えるか特殊召喚する。
  2:墓地のこのカードを除外し、自分フィールドの「D-HERO」モンスター2体を対象として発動できる。
  対象のモンスター1体の攻撃力は、もう1体のモンスターの攻撃力と同じになる。
target_text: -- ドクターD
  local SETCARD_ID_0 = 0xc008 --D-HERO
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SPECIAL_SUMMON + CATEGORY_GRAVE_ACTION + CATEGORY_GRAVE_SPSUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--atk
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_ATKCHANGE)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.atktg)
  	e2:SetOperation(s.atkop)
  	c:RegisterEffect(e2)
  end
  function s.costfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemoveAsCost() and Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_GRAVE, 0, 1, c, e, tp)
  end
  function s.thfilter(c, e, tp)
  	if not (c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER)) then
  		return false
  	end
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	return c:IsAbleToHand() or (ft > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false))
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(1)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.costfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local res = e:GetLabel() == 1
  		e:SetLabel(0)
  		return res or Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	e:SetLabel(0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_OPERATECARD)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.thfilter), tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	local tc = g:GetFirst()
  	if tc then
  		if tc:IsAbleToHand() and (not tc:IsCanBeSpecialSummoned(e, 0, tp, false, false) or ft <= 0 or Duel.SelectOption(tp, 1190, 1152) == 0) then
  			Duel.SendtoHand(tc, nil, REASON_EFFECT)
  		else
  			Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  		end
  	end
  end
  function s.atkfilter1(c, tp)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and Duel.IsExistingTarget(s.atkfilter2, tp, LOCATION_MZONE, 0, 1, c, c)
  end
  function s.atkfilter2(c, tc)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and not c:IsAttack(tc:GetAttack())
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.atkfilter1, tp, LOCATION_MZONE, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 2))
  	local g1 = Duel.SelectTarget(tp, s.atkfilter1, tp, LOCATION_MZONE, 0, 1, 1, nil, tp)
  	local tc = g1:GetFirst()
  	e:SetLabelObject(tc)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.atkfilter2, tp, LOCATION_MZONE, 0, 1, 1, tc, tc)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local hc = e:GetLabelObject()
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local tc = g:GetFirst()
  	if tc == hc then
  		tc = g:GetNext()
  	end
  	if hc:IsFaceup() and hc:IsRelateToEffect(e) and tc:IsFaceup() and tc:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  		e1:SetValue(tc:GetAttack())
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		hc:RegisterEffect(e1)
  	end
  end
  
  