name: Dark
card_text: Target up to 3 cards in any GY(s); banish them, then discard 1 Fiend monster. During your Main Phase, except the turn this card was sent to the GY: You can banish this card from your GY, then target 1 of your banished Fiend monsters; add it to your hand. You can only activate 1 "Dark World Puppetry" per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--remove
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_REMOVE + CATEGORY_HANDES)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.rmtg)
  	e1:SetOperation(s.rmop)
  	c:RegisterEffect(e1)
  	--To hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCondition(aux.exccon)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.rmfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsRace(RACE_FIEND) and c:IsDiscardable(REASON_EFFECT)
  end
  function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsAbleToRemove()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsAbleToRemove, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, nil) and Duel.IsExistingMatchingCard(s.rmfilter, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectTarget(tp, Card.IsAbleToRemove, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, 3, nil)
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g, g:GetCount(), 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_HANDES, nil, 0, tp, 1)
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if #tg > 0 and Duel.Remove(tg, POS_FACEUP, REASON_EFFECT) > 0 and Duel.GetFieldGroupCount(tp, LOCATION_HAND, 0) > 0 then
  		Duel.BreakEffect()
  		Duel.DiscardHand(tp, s.rmfilter, 1, 1, REASON_EFFECT + REASON_DISCARD, nil)
  	end
  end
  function s.thfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsRace(RACE_FIEND) and c:IsAbleToHand() and c:IsFaceup()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_REMOVED) and chkc:IsControler(tp) and s.thfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.thfilter, tp, LOCATION_REMOVED, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_REMOVED, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  
  
source_text: Dark
  Target up to 3 cards in any GY(s); banish them, then discard 1 Fiend monster. During your Main Phase, except the turn this card was sent to the GY: You can banish this card from your GY, then target 1 of your banished Fiend monsters; add it to your hand. You can only activate 1 "Dark World Puppetry" per turn.
target_text: -- Dark
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--remove
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_REMOVE + CATEGORY_HANDES)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.rmtg)
  	e1:SetOperation(s.rmop)
  	c:RegisterEffect(e1)
  	--To hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCondition(aux.exccon)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.rmfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsRace(RACE_FIEND) and c:IsDiscardable(REASON_EFFECT)
  end
  function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsAbleToRemove()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsAbleToRemove, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, nil) and Duel.IsExistingMatchingCard(s.rmfilter, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectTarget(tp, Card.IsAbleToRemove, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, 3, nil)
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g, g:GetCount(), 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_HANDES, nil, 0, tp, 1)
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if #tg > 0 and Duel.Remove(tg, POS_FACEUP, REASON_EFFECT) > 0 and Duel.GetFieldGroupCount(tp, LOCATION_HAND, 0) > 0 then
  		Duel.BreakEffect()
  		Duel.DiscardHand(tp, s.rmfilter, 1, 1, REASON_EFFECT + REASON_DISCARD, nil)
  	end
  end
  function s.thfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsRace(RACE_FIEND) and c:IsAbleToHand() and c:IsFaceup()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_REMOVED) and chkc:IsControler(tp) and s.thfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.thfilter, tp, LOCATION_REMOVED, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_REMOVED, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  
  