name: Ace★Spades
card_text: 1 monster with 2500 or more ATK + 1 face-down Defense Position monster with 2500 or less DEF
  You can only Special Summon "Ace★Spades Speculation(s)" once per turn. You can Tribute 1 Attack Position monster and 1 face-down Defense Position monster; Special Summon this card from your GY. This card gains the following effect based on its battle position.
  ● Attack Position: Gains ATK equal to the highest original ATK among monsters your opponent controls (your choice, if tied).
  ● Defense Position: Cannot be destroyed by battle or card effects.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	c:SetSPSummonOnce(id)
  	--fusion material
  	c:EnableReviveLimit()
  	aux.AddFusionProcFun2(c, s.ffilter1, s.ffilter2, true)
  	--atkup
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetCondition(s.atkcon)
  	e1:SetValue(s.val)
  	c:RegisterEffect(e1)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetCondition(s.indcon)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	c:RegisterEffect(e3)
  	--spsummon
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetRange(LOCATION_GRAVE)
  	e4:SetCost(s.spcost)
  	e4:SetTarget(s.sptg)
  	e4:SetOperation(s.spop)
  	c:RegisterEffect(e4)
  end
  function s.ffilter1(c)
  	return c:IsAttackAbove(2500)
  end
  function s.ffilter2(c)
  	return c:IsDefenseBelow(2500) and c:IsFacedown() and c:IsDefensePos() and c:IsLocation(LOCATION_MZONE)
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsAttackPos()
  end
  function s.val(e, c)
  	local g = Duel.GetMatchingGroup(Card.IsFaceup, e:GetOwnerPlayer(), 0, LOCATION_MZONE, nil)
  	if g:GetCount() == 0 then
  		return 0
  	else
  		local tg, val = g:GetMaxGroup(Card.GetBaseAttack)
  		return val
  	end
  end
  function s.indcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsDefensePos()
  end
  function s.costfilter(c)
  	return c:IsReleasable() and ((c:IsFacedown() and c:IsDefensePos()) or (c:IsFaceup() and c:IsAttackPos()))
  end
  function s.spcheck(g, tp)
  	return Duel.GetMZoneCount(tp, g) > 0 and aux.gfcheck(g, Card.IsPosition, POS_FACEUP_ATTACK, POS_FACEDOWN_DEFENSE)
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(s.costfilter, tp, LOCATION_MZONE, 0, nil)
  	if chk == 0 then
  		return g:CheckSubGroup(s.spcheck, 2, 2, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RELEASE)
  	local sg = g:SelectSubGroup(tp, s.spcheck, false, 2, 2, tp)
  	Duel.Release(sg, REASON_COST)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, c, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Ace★Spades
  1 monster with 2500 or more ATK + 1 face-down Defense Position monster with 2500 or less DEF
  You can only Special Summon "Ace★Spades Speculation(s)" once per turn. You can Tribute 1 Attack Position monster and 1 face-down Defense Position monster; Special Summon this card from your GY. This card gains the following effect based on its battle position.
  ● Attack Position: Gains ATK equal to the highest original ATK among monsters your opponent controls (your choice, if tied).
  ● Defense Position: Cannot be destroyed by battle or card effects.
target_text: -- Ace★Spades
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:SetSPSummonOnce(id)
  	--fusion material
  	c:EnableReviveLimit()
  	aux.AddFusionProcFun2(c, s.ffilter1, s.ffilter2, true)
  	--atkup
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetCondition(s.atkcon)
  	e1:SetValue(s.val)
  	c:RegisterEffect(e1)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetCondition(s.indcon)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	c:RegisterEffect(e3)
  	--spsummon
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetRange(LOCATION_GRAVE)
  	e4:SetCost(s.spcost)
  	e4:SetTarget(s.sptg)
  	e4:SetOperation(s.spop)
  	c:RegisterEffect(e4)
  end
  function s.ffilter1(c)
  	return c:IsAttackAbove(2500)
  end
  function s.ffilter2(c)
  	return c:IsDefenseBelow(2500) and c:IsFacedown() and c:IsDefensePos() and c:IsLocation(LOCATION_MZONE)
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsAttackPos()
  end
  function s.val(e, c)
  	local g = Duel.GetMatchingGroup(Card.IsFaceup, e:GetOwnerPlayer(), 0, LOCATION_MZONE, nil)
  	if g:GetCount() == 0 then
  		return 0
  	else
  		local tg, val = g:GetMaxGroup(Card.GetBaseAttack)
  		return val
  	end
  end
  function s.indcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsDefensePos()
  end
  function s.costfilter(c)
  	return c:IsReleasable() and ((c:IsFacedown() and c:IsDefensePos()) or (c:IsFaceup() and c:IsAttackPos()))
  end
  function s.spcheck(g, tp)
  	return Duel.GetMZoneCount(tp, g) > 0 and aux.gfcheck(g, Card.IsPosition, POS_FACEUP_ATTACK, POS_FACEDOWN_DEFENSE)
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(s.costfilter, tp, LOCATION_MZONE, 0, nil)
  	if chk == 0 then
  		return g:CheckSubGroup(s.spcheck, 2, 2, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RELEASE)
  	local sg = g:SelectSubGroup(tp, s.spcheck, false, 2, 2, tp)
  	Duel.Release(sg, REASON_COST)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, c, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  