name: Possessed
card_text: Special Summon 1 Spellcaster monster with 1500 DEF from your hand or GY in Attack Position or face-down Defense Position, then, if you control monsters with 2 or more different Attributes, you can destroy 1 face-up card on the field. You can banish this card from your GY, then target 1 "Possessed" Continuous Spell/Trap in your GY; place it face-up on your field. You can only use 1 "Possessed Partnerships" effect per turn, and only once that turn.
external_ids: local SETCARD_ID_0 = 0xc0 --Possessed
  
lua: local SETCARD_ID_0 = 0xc0 --Possessed
  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_SPECIAL_SUMMON + CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--to field
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 2))
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1, id)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.tftg)
  	e2:SetOperation(s.tfop)
  	c:RegisterEffect(e2)
  end
  function s.filter(c, e, tp)
  	return c:IsRace(RACE_SPELLCASTER) and c:IsDefense(1500) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_ATTACK + POS_FACEDOWN_DEFENSE)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_GRAVE)
  end
  function s.activate(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 g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.filter), tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	local tc = g:GetFirst()
  	if tc then
  		if Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP_ATTACK + POS_FACEDOWN_DEFENSE) ~= 0 and tc:IsFacedown() then
  			Duel.ConfirmCards(1 - tp, tc)
  		end
  	end
  	local mg = Duel.GetMatchingGroup(Card.IsFaceup, tp, LOCATION_MZONE, 0, nil)
  	local g = Duel.GetMatchingGroup(Card.IsFaceup, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, aux.ExceptThisCard(e))
  	if aux.GetAttributeCount(mg) >= 2 and g:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local g = Duel.SelectMatchingCard(tp, Card.IsFaceup, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, aux.ExceptThisCard(e))
  		if g:GetCount() > 0 then
  			Duel.HintSelection(g)
  			Duel.Destroy(g, REASON_EFFECT)
  		end
  	end
  end
  function s.tffilter(c)
  	return c:IsType(TYPE_SPELL + TYPE_TRAP) and c:IsType(TYPE_CONTINUOUS) and c:IsSetCard(SETCARD_ID_0) and not c:IsForbidden()
  end
  function s.tftg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and s.tffilter(chkc) and chkc:IsControler(tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.IsExistingTarget(s.tffilter, tp, LOCATION_GRAVE, 0, 1, e:GetHandler())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  	local g = Duel.SelectTarget(tp, s.tffilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, g, 1, 0, 0)
  end
  function s.tfop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_SZONE) <= 0 then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	if tc and tc:IsRelateToEffect(e) then
  		Duel.MoveToField(tc, tp, tp, LOCATION_SZONE, POS_FACEUP, true)
  	end
  end
  
  
source_text: Possessed
  Special Summon 1 Spellcaster monster with 1500 DEF from your hand or GY in Attack Position or face-down Defense Position, then, if you control monsters with 2 or more different Attributes, you can destroy 1 face-up card on the field. You can banish this card from your GY, then target 1 "Possessed" Continuous Spell/Trap in your GY; place it face-up on your field. You can only use 1 "Possessed Partnerships" effect per turn, and only once that turn.
target_text: -- Possessed
  local SETCARD_ID_0 = 0xc0 --Possessed
  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_SPECIAL_SUMMON + CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--to field
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 2))
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1, id)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.tftg)
  	e2:SetOperation(s.tfop)
  	c:RegisterEffect(e2)
  end
  function s.filter(c, e, tp)
  	return c:IsRace(RACE_SPELLCASTER) and c:IsDefense(1500) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_ATTACK + POS_FACEDOWN_DEFENSE)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_GRAVE)
  end
  function s.activate(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 g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.filter), tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	local tc = g:GetFirst()
  	if tc then
  		if Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP_ATTACK + POS_FACEDOWN_DEFENSE) ~= 0 and tc:IsFacedown() then
  			Duel.ConfirmCards(1 - tp, tc)
  		end
  	end
  	local mg = Duel.GetMatchingGroup(Card.IsFaceup, tp, LOCATION_MZONE, 0, nil)
  	local g = Duel.GetMatchingGroup(Card.IsFaceup, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, aux.ExceptThisCard(e))
  	if aux.GetAttributeCount(mg) >= 2 and g:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local g = Duel.SelectMatchingCard(tp, Card.IsFaceup, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, aux.ExceptThisCard(e))
  		if g:GetCount() > 0 then
  			Duel.HintSelection(g)
  			Duel.Destroy(g, REASON_EFFECT)
  		end
  	end
  end
  function s.tffilter(c)
  	return c:IsType(TYPE_SPELL + TYPE_TRAP) and c:IsType(TYPE_CONTINUOUS) and c:IsSetCard(SETCARD_ID_0) and not c:IsForbidden()
  end
  function s.tftg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and s.tffilter(chkc) and chkc:IsControler(tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.IsExistingTarget(s.tffilter, tp, LOCATION_GRAVE, 0, 1, e:GetHandler())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  	local g = Duel.SelectTarget(tp, s.tffilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, g, 1, 0, 0)
  end
  function s.tfop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_SZONE) <= 0 then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	if tc and tc:IsRelateToEffect(e) then
  		Duel.MoveToField(tc, tp, tp, LOCATION_SZONE, POS_FACEUP, true)
  	end
  end
  
  