name: Evil
card_text: If you control a Fiend monster: Activate 1 of these effects, based on the number of monsters in your opponent's GY;
  ● 1+: Draw 1 card.
  ● 4+: Add 1 "HERO" monster or 1 "Dark Fusion" from your Deck to your hand.
  ● 10+: Add 1 "Polymerization" Spell or 1 "Fusion" Spell from your Deck to your hand.
  You can only activate 1 "Evil Mind" per turn.
external_ids: local CARD_ID_0 = 94820406 --Dark Fusion
  local SETCARD_ID_0 = 0x46 --Polymerization/Fusion
  local SETCARD_ID_1 = 0x8 --HERO
  
lua: local CARD_ID_0 = 94820406 --Dark Fusion
  local SETCARD_ID_0 = 0x46 --Polymerization/Fusion
  local SETCARD_ID_1 = 0x8 --HERO
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--draw
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DRAW)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.drtg)
  	e1:SetOperation(s.drop)
  	c:RegisterEffect(e1)
  	--search
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e2:SetType(EFFECT_TYPE_ACTIVATE)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e2:SetCondition(s.condition)
  	e2:SetTarget(s.thtg1)
  	e2:SetOperation(s.thop1)
  	c:RegisterEffect(e2)
  	--search
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 2))
  	e3:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e3:SetType(EFFECT_TYPE_ACTIVATE)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e3:SetCondition(s.condition)
  	e3:SetTarget(s.thtg2)
  	e3:SetOperation(s.thop2)
  	c:RegisterEffect(e3)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_FIEND)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ct = Duel.GetMatchingGroupCount(Card.IsType, tp, 0, LOCATION_GRAVE, nil, TYPE_MONSTER)
  	if chk == 0 then
  		return ct > 0 and Duel.IsPlayerCanDraw(tp, 1)
  	end
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(1)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Draw(p, d, REASON_EFFECT)
  end
  function s.thfilter1(c)
  	return c:IsAbleToHand() and (c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_1) or c:IsCode(CARD_ID_0))
  end
  function s.thtg1(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ct = Duel.GetMatchingGroupCount(Card.IsType, tp, 0, LOCATION_GRAVE, nil, TYPE_MONSTER)
  	if chk == 0 then
  		return ct >= 4 and Duel.IsExistingMatchingCard(s.thfilter1, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop1(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter1, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  function s.thfilter2(c)
  	return c:IsAbleToHand() and c:IsType(TYPE_SPELL) and c:IsSetCard(SETCARD_ID_1)
  end
  function s.thtg2(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ct = Duel.GetMatchingGroupCount(Card.IsType, tp, 0, LOCATION_GRAVE, nil, TYPE_MONSTER)
  	if chk == 0 then
  		return ct >= 10 and Duel.IsExistingMatchingCard(s.thfilter2, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop2(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter2, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  
source_text: Evil
  If you control a Fiend monster: Activate 1 of these effects, based on the number of monsters in your opponent's GY;
  ● 1+: Draw 1 card.
  ● 4+: Add 1 "HERO" monster or 1 "Dark Fusion" from your Deck to your hand.
  ● 10+: Add 1 "Polymerization" Spell or 1 "Fusion" Spell from your Deck to your hand.
  You can only activate 1 "Evil Mind" per turn.
target_text: -- Evil
  local CARD_ID_0 = 94820406 --Dark Fusion
  local SETCARD_ID_0 = 0x46 --Polymerization/Fusion
  local SETCARD_ID_1 = 0x8 --HERO
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--draw
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DRAW)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.drtg)
  	e1:SetOperation(s.drop)
  	c:RegisterEffect(e1)
  	--search
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e2:SetType(EFFECT_TYPE_ACTIVATE)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e2:SetCondition(s.condition)
  	e2:SetTarget(s.thtg1)
  	e2:SetOperation(s.thop1)
  	c:RegisterEffect(e2)
  	--search
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 2))
  	e3:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e3:SetType(EFFECT_TYPE_ACTIVATE)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e3:SetCondition(s.condition)
  	e3:SetTarget(s.thtg2)
  	e3:SetOperation(s.thop2)
  	c:RegisterEffect(e3)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_FIEND)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ct = Duel.GetMatchingGroupCount(Card.IsType, tp, 0, LOCATION_GRAVE, nil, TYPE_MONSTER)
  	if chk == 0 then
  		return ct > 0 and Duel.IsPlayerCanDraw(tp, 1)
  	end
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(1)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Draw(p, d, REASON_EFFECT)
  end
  function s.thfilter1(c)
  	return c:IsAbleToHand() and (c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_1) or c:IsCode(CARD_ID_0))
  end
  function s.thtg1(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ct = Duel.GetMatchingGroupCount(Card.IsType, tp, 0, LOCATION_GRAVE, nil, TYPE_MONSTER)
  	if chk == 0 then
  		return ct >= 4 and Duel.IsExistingMatchingCard(s.thfilter1, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop1(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter1, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  function s.thfilter2(c)
  	return c:IsAbleToHand() and c:IsType(TYPE_SPELL) and c:IsSetCard(SETCARD_ID_1)
  end
  function s.thtg2(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ct = Duel.GetMatchingGroupCount(Card.IsType, tp, 0, LOCATION_GRAVE, nil, TYPE_MONSTER)
  	if chk == 0 then
  		return ct >= 10 and Duel.IsExistingMatchingCard(s.thfilter2, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop2(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter2, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  