name: Spirit
card_text: Discard 1 card; take 2 cards from your Deck with different names from each other, that are "Charmer" monsters, "Familiar-Possessed" monsters, and/or "Possessed" Spells/Traps, add 1 of them to your hand, and Set the other. You can only activate 1 "Spirit Charmers" per turn.
external_ids: local SETCARD_ID_0 = 0xc0 --Possessed
  local SETCARD_ID_1 = 0xbf --Charmer
  local SETCARD_ID_2 = 0x10c0 --Familiar-Possessed
  
lua: local SETCARD_ID_0 = 0xc0 --Possessed
  local SETCARD_ID_1 = 0xbf --Charmer
  local SETCARD_ID_2 = 0x10c0 --Familiar-Possessed
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_SPECIAL_SUMMON + CATEGORY_DECKDES)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsDiscardable, tp, LOCATION_HAND, 0, 1, e:GetHandler())
  	end
  	Duel.DiscardHand(tp, Card.IsDiscardable, 1, 1, REASON_COST + REASON_DISCARD)
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_2) and c:IsType(TYPE_MONSTER) or c:IsSetCard(SETCARD_ID_2) and c:IsType(TYPE_MONSTER) or c:IsSetCard(SETCARD_ID_2) and c:IsType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.thfilter(c, e, tp, mft, sft)
  	return s.filter(c) and c:IsAbleToHand() and Duel.IsExistingMatchingCard(s.setfilter, tp, LOCATION_DECK, 0, 1, c, e, tp, mft, sft, c:GetCode())
  end
  function s.setfilter(c, e, tp, mft, sft, code)
  	return s.filter(c) and not c:IsCode(code) and (sft > 0 and c:IsSSetable(true) or mft > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEDOWN_DEFENSE))
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local mft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  		local sft = Duel.GetLocationCount(tp, LOCATION_SZONE)
  		if e:IsHasType(EFFECT_TYPE_ACTIVATE) and not e:GetHandler():IsLocation(LOCATION_SZONE) then
  			sft = sft - 1
  		end
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp, mft, sft)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local mft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	local sft = Duel.GetLocationCount(tp, LOCATION_SZONE)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local tc1 = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp, mft, sft):GetFirst()
  	if tc1 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  		local tc2 = Duel.SelectMatchingCard(tp, s.setfilter, tp, LOCATION_DECK, 0, 1, 1, tc1, e, tp, mft, sft, tc1:GetCode()):GetFirst()
  		Duel.SendtoHand(tc1, nil, REASON_EFFECT)
  		if tc2:IsType(TYPE_MONSTER) then
  			Duel.SpecialSummon(tc2, 0, tp, tp, false, false, POS_FACEDOWN_DEFENSE)
  		else
  			Duel.SSet(tp, tc2, tp, false)
  		end
  		Duel.ConfirmCards(1 - tp, Group.FromCards(tc1, tc2))
  	end
  end
  
  
source_text: Spirit
  Discard 1 card; take 2 cards from your Deck with different names from each other, that are "Charmer" monsters, "Familiar-Possessed" monsters, and/or "Possessed" Spells/Traps, add 1 of them to your hand, and Set the other. You can only activate 1 "Spirit Charmers" per turn.
target_text: -- Spirit
  local SETCARD_ID_0 = 0xc0 --Possessed
  local SETCARD_ID_1 = 0xbf --Charmer
  local SETCARD_ID_2 = 0x10c0 --Familiar-Possessed
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_SPECIAL_SUMMON + CATEGORY_DECKDES)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsDiscardable, tp, LOCATION_HAND, 0, 1, e:GetHandler())
  	end
  	Duel.DiscardHand(tp, Card.IsDiscardable, 1, 1, REASON_COST + REASON_DISCARD)
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_2) and c:IsType(TYPE_MONSTER) or c:IsSetCard(SETCARD_ID_2) and c:IsType(TYPE_MONSTER) or c:IsSetCard(SETCARD_ID_2) and c:IsType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.thfilter(c, e, tp, mft, sft)
  	return s.filter(c) and c:IsAbleToHand() and Duel.IsExistingMatchingCard(s.setfilter, tp, LOCATION_DECK, 0, 1, c, e, tp, mft, sft, c:GetCode())
  end
  function s.setfilter(c, e, tp, mft, sft, code)
  	return s.filter(c) and not c:IsCode(code) and (sft > 0 and c:IsSSetable(true) or mft > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEDOWN_DEFENSE))
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local mft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  		local sft = Duel.GetLocationCount(tp, LOCATION_SZONE)
  		if e:IsHasType(EFFECT_TYPE_ACTIVATE) and not e:GetHandler():IsLocation(LOCATION_SZONE) then
  			sft = sft - 1
  		end
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp, mft, sft)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local mft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	local sft = Duel.GetLocationCount(tp, LOCATION_SZONE)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local tc1 = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp, mft, sft):GetFirst()
  	if tc1 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  		local tc2 = Duel.SelectMatchingCard(tp, s.setfilter, tp, LOCATION_DECK, 0, 1, 1, tc1, e, tp, mft, sft, tc1:GetCode()):GetFirst()
  		Duel.SendtoHand(tc1, nil, REASON_EFFECT)
  		if tc2:IsType(TYPE_MONSTER) then
  			Duel.SpecialSummon(tc2, 0, tp, tp, false, false, POS_FACEDOWN_DEFENSE)
  		else
  			Duel.SSet(tp, tc2, tp, false)
  		end
  		Duel.ConfirmCards(1 - tp, Group.FromCards(tc1, tc2))
  	end
  end
  
  