name: Malefic
card_text: If a face-up Field Spell is on the field: You can Tribute this card; Special Summon 1 "Malefic Parallel Gear" from your Deck, then, add 1 "Malefic" monster from your Deck to your hand, except "Malefic Paradox Gear". If a "Malefic" monster would banish a monster to Special Summon itself by its own way, you can banish this card you control or in your GY instead. You can only use each effect of "Malefic Paradox Gear" once per turn.
external_ids: local CARD_ID_0 = 9433350 --Malefic Blue-Eyes White Dragon
  local CARD_ID_1 = 37115575 --Malefic Truth Dragon
  local CARD_ID_3 = 36521459 --Malefic Stardust Dragon
  local CARD_ID_4 = 74509280 --Malefic Parallel Gear
  local CARD_ID_5 = 1710476 --Malefic Cyber End Dragon
  local CARD_ID_6 = 598988 --Malefic Rainbow Dragon
  local CARD_ID_7 = 75223115 --Malefic Territory
  local CARD_ID_8 = 55343236 --Malefic Red-Eyes Black Dragon
  local SETCARD_ID_0 = 0x23 --Malefic
  
lua: local CARD_ID_0 = 9433350 --Malefic Blue-Eyes White Dragon
  local CARD_ID_1 = 37115575 --Malefic Truth Dragon
  local CARD_ID_3 = 36521459 --Malefic Stardust Dragon
  local CARD_ID_4 = 74509280 --Malefic Parallel Gear
  local CARD_ID_5 = 1710476 --Malefic Cyber End Dragon
  local CARD_ID_6 = 598988 --Malefic Rainbow Dragon
  local CARD_ID_7 = 75223115 --Malefic Territory
  local CARD_ID_8 = 55343236 --Malefic Red-Eyes Black Dragon
  local SETCARD_ID_0 = 0x23 --Malefic
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--sin territory
  	c:SetUniqueOnField(1, 1, s.uqfilter, LOCATION_MZONE)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.condition)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(id)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_MZONE + LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	c:RegisterEffect(e2)
  end
  function s.sfilter(c)
  	return c:IsOriginalCodeRule(CARD_ID_6, CARD_ID_5, CARD_ID_0, CARD_ID_3, CARD_ID_1, CARD_ID_8) and not c:IsDisabled()
  end
  function s.uqfilter(c)
  	if Duel.IsPlayerAffectedByEffect(c:GetControler(), CARD_ID_7) and Duel.IsExistingMatchingCard(s.sfilter, c:GetControler(), LOCATION_MZONE, LOCATION_MZONE, 1, nil) then
  		return c:IsCode(id)
  	else
  		return false
  	end
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(Card.IsFaceup, tp, LOCATION_FZONE, LOCATION_FZONE, 1, nil)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsReleasable()
  	end
  	Duel.Release(e:GetHandler(), REASON_COST)
  end
  function s.spfilter(c, e, tp)
  	return c:IsCode(CARD_ID_4) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, c)
  end
  function s.thfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToHand() and not c:IsCode(id)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetMZoneCount(tp, e:GetHandler()) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, 0, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, 0, LOCATION_DECK)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g1 = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g1:GetCount() > 0 then
  		Duel.SpecialSummon(g1, 0, tp, tp, false, false, POS_FACEUP)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local g2 = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  		if g2:GetCount() > 0 then
  			Duel.BreakEffect()
  			Duel.SendtoHand(g2, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, g2)
  		end
  	end
  end
  
  
source_text: Malefic
  If a face-up Field Spell is on the field: You can Tribute this card; Special Summon 1 "Malefic Parallel Gear" from your Deck, then, add 1 "Malefic" monster from your Deck to your hand, except "Malefic Paradox Gear". If a "Malefic" monster would banish a monster to Special Summon itself by its own way, you can banish this card you control or in your GY instead. You can only use each effect of "Malefic Paradox Gear" once per turn.
target_text: -- Malefic
  local CARD_ID_0 = 9433350 --Malefic Blue-Eyes White Dragon
  local CARD_ID_1 = 37115575 --Malefic Truth Dragon
  local CARD_ID_3 = 36521459 --Malefic Stardust Dragon
  local CARD_ID_4 = 74509280 --Malefic Parallel Gear
  local CARD_ID_5 = 1710476 --Malefic Cyber End Dragon
  local CARD_ID_6 = 598988 --Malefic Rainbow Dragon
  local CARD_ID_7 = 75223115 --Malefic Territory
  local CARD_ID_8 = 55343236 --Malefic Red-Eyes Black Dragon
  local SETCARD_ID_0 = 0x23 --Malefic
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--sin territory
  	c:SetUniqueOnField(1, 1, s.uqfilter, LOCATION_MZONE)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.condition)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(id)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_MZONE + LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	c:RegisterEffect(e2)
  end
  function s.sfilter(c)
  	return c:IsOriginalCodeRule(CARD_ID_6, CARD_ID_5, CARD_ID_0, CARD_ID_3, CARD_ID_1, CARD_ID_8) and not c:IsDisabled()
  end
  function s.uqfilter(c)
  	if Duel.IsPlayerAffectedByEffect(c:GetControler(), CARD_ID_7) and Duel.IsExistingMatchingCard(s.sfilter, c:GetControler(), LOCATION_MZONE, LOCATION_MZONE, 1, nil) then
  		return c:IsCode(id)
  	else
  		return false
  	end
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(Card.IsFaceup, tp, LOCATION_FZONE, LOCATION_FZONE, 1, nil)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsReleasable()
  	end
  	Duel.Release(e:GetHandler(), REASON_COST)
  end
  function s.spfilter(c, e, tp)
  	return c:IsCode(CARD_ID_4) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, c)
  end
  function s.thfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToHand() and not c:IsCode(id)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetMZoneCount(tp, e:GetHandler()) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, 0, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, 0, LOCATION_DECK)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g1 = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g1:GetCount() > 0 then
  		Duel.SpecialSummon(g1, 0, tp, tp, false, false, POS_FACEUP)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local g2 = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  		if g2:GetCount() > 0 then
  			Duel.BreakEffect()
  			Duel.SendtoHand(g2, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, g2)
  		end
  	end
  end
  
  