name: Timaeus
card_text: "Legendary Knight Timaeus" + "Legendary Knight Critias" + "Legendary Knight Hermos"
  Must be Special Summoned (from your Extra Deck) by sending the above cards you control to the GY. (You do not use "Polymerization".) Unaffected by other cards' effects. Once per battle, if this card battles, during damage calculation (Quick Effect): You can make this card's ATK/DEF become equal to the ATK of the monster on the field with the highest ATK (your choice, if tied). When this card is destroyed by battle: You can Special Summon 3 "Legendary Knight" monsters from your hand, Deck, and/or GY, ignoring their Summoning conditions.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 85800949 --Legendary Knight Critias
  local CARD_ID_2 = 84565800 --Legendary Knight Hermos
  local CARD_ID_3 = 80019195 --Legendary Knight Timaeus
  local SETCARD_ID_0 = 0xa0 --Legendary
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 85800949 --Legendary Knight Critias
  local CARD_ID_2 = 84565800 --Legendary Knight Hermos
  local CARD_ID_3 = 80019195 --Legendary Knight Timaeus
  local SETCARD_ID_0 = 0xa0 --Legendary
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--fusion material
  	c:EnableReviveLimit()
  	aux.AddFusionProcCode3(c, CARD_ID_3, CARD_ID_1, CARD_ID_2, true, true)
  	aux.AddContactFusionProcedure(c, Card.IsAbleToGraveAsCost, LOCATION_ONFIELD, 0, Duel.SendtoGrave, REASON_COST)
  	--spsummon condition
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	c:RegisterEffect(e1)
  	--immune
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetCode(EFFECT_IMMUNE_EFFECT)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetValue(s.efilter)
  	c:RegisterEffect(e3)
  	--atk & def
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_ATKCHANGE + CATEGORY_DEFCHANGE)
  	e4:SetType(EFFECT_TYPE_QUICK_O)
  	e4:SetCode(EVENT_PRE_DAMAGE_CALCULATE)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1, EFFECT_COUNT_CODE_CHAIN)
  	e4:SetCondition(s.atkcon)
  	e4:SetTarget(s.atktg)
  	e4:SetOperation(s.atkop)
  	c:RegisterEffect(e4)
  	--spsummon
  	local e5 = Effect.CreateEffect(c)
  	e5:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e5:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e5:SetCode(EVENT_BATTLE_DESTROYED)
  	e5:SetTarget(s.sptg)
  	e5:SetOperation(s.spop)
  	c:RegisterEffect(e5)
  end
  function s.efilter(e, te)
  	return te:GetOwner() ~= e:GetOwner()
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c == Duel.GetAttacker() or c == Duel.GetAttackTarget()
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		local g = Duel.GetMatchingGroup(Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, c)
  		if g:GetCount() == 0 then
  			return false
  		end
  		local g1, atk = g:GetMaxGroup(Card.GetAttack)
  		return not c:IsAttack(atk)
  	end
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetMatchingGroup(Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, c)
  	if g:GetCount() == 0 then
  		return
  	end
  	local g1, atk = g:GetMaxGroup(Card.GetAttack)
  	if c:IsRelateToEffect(e) and c:IsFaceup() and atk > 0 then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		e1:SetValue(atk)
  		c:RegisterEffect(e1)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_SET_DEFENSE_FINAL)
  		c:RegisterEffect(e2)
  	end
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, true, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) and Duel.GetLocationCount(tp, LOCATION_MZONE) >= 3 and Duel.IsExistingMatchingCard(s.spfilter, tp, 0x13, 0, 3, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 3, tp, 0x13)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		return
  	end
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) < 3 then
  		return
  	end
  	local g = Duel.GetMatchingGroup(aux.NecroValleyFilter(s.spfilter), tp, 0x13, 0, nil, e, tp)
  	if g:GetCount() > 2 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sg = g:Select(tp, 3, 3, nil)
  		Duel.SpecialSummon(sg, 0, tp, tp, true, false, POS_FACEUP)
  	end
  end
  
  
source_text: Timaeus
  "Legendary Knight Timaeus" + "Legendary Knight Critias" + "Legendary Knight Hermos"
  Must be Special Summoned (from your Extra Deck) by sending the above cards you control to the GY. (You do not use "Polymerization".) Unaffected by other cards' effects. Once per battle, if this card battles, during damage calculation (Quick Effect): You can make this card's ATK/DEF become equal to the ATK of the monster on the field with the highest ATK (your choice, if tied). When this card is destroyed by battle: You can Special Summon 3 "Legendary Knight" monsters from your hand, Deck, and/or GY, ignoring their Summoning conditions.
target_text: -- Timaeus
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 85800949 --Legendary Knight Critias
  local CARD_ID_2 = 84565800 --Legendary Knight Hermos
  local CARD_ID_3 = 80019195 --Legendary Knight Timaeus
  local SETCARD_ID_0 = 0xa0 --Legendary
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--fusion material
  	c:EnableReviveLimit()
  	aux.AddFusionProcCode3(c, CARD_ID_3, CARD_ID_1, CARD_ID_2, true, true)
  	aux.AddContactFusionProcedure(c, Card.IsAbleToGraveAsCost, LOCATION_ONFIELD, 0, Duel.SendtoGrave, REASON_COST)
  	--spsummon condition
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	c:RegisterEffect(e1)
  	--immune
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetCode(EFFECT_IMMUNE_EFFECT)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetValue(s.efilter)
  	c:RegisterEffect(e3)
  	--atk & def
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_ATKCHANGE + CATEGORY_DEFCHANGE)
  	e4:SetType(EFFECT_TYPE_QUICK_O)
  	e4:SetCode(EVENT_PRE_DAMAGE_CALCULATE)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1, EFFECT_COUNT_CODE_CHAIN)
  	e4:SetCondition(s.atkcon)
  	e4:SetTarget(s.atktg)
  	e4:SetOperation(s.atkop)
  	c:RegisterEffect(e4)
  	--spsummon
  	local e5 = Effect.CreateEffect(c)
  	e5:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e5:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e5:SetCode(EVENT_BATTLE_DESTROYED)
  	e5:SetTarget(s.sptg)
  	e5:SetOperation(s.spop)
  	c:RegisterEffect(e5)
  end
  function s.efilter(e, te)
  	return te:GetOwner() ~= e:GetOwner()
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c == Duel.GetAttacker() or c == Duel.GetAttackTarget()
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		local g = Duel.GetMatchingGroup(Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, c)
  		if g:GetCount() == 0 then
  			return false
  		end
  		local g1, atk = g:GetMaxGroup(Card.GetAttack)
  		return not c:IsAttack(atk)
  	end
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetMatchingGroup(Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, c)
  	if g:GetCount() == 0 then
  		return
  	end
  	local g1, atk = g:GetMaxGroup(Card.GetAttack)
  	if c:IsRelateToEffect(e) and c:IsFaceup() and atk > 0 then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		e1:SetValue(atk)
  		c:RegisterEffect(e1)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_SET_DEFENSE_FINAL)
  		c:RegisterEffect(e2)
  	end
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, true, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) and Duel.GetLocationCount(tp, LOCATION_MZONE) >= 3 and Duel.IsExistingMatchingCard(s.spfilter, tp, 0x13, 0, 3, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 3, tp, 0x13)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		return
  	end
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) < 3 then
  		return
  	end
  	local g = Duel.GetMatchingGroup(aux.NecroValleyFilter(s.spfilter), tp, 0x13, 0, nil, e, tp)
  	if g:GetCount() > 2 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sg = g:Select(tp, 3, 3, nil)
  		Duel.SpecialSummon(sg, 0, tp, tp, true, false, POS_FACEUP)
  	end
  end
  
  