Divine
This Special Summoned card cannot be destroyed by battle. You can only use each of the following effects of "Divine Dragon Titanomakhia" once per turn. You can banish 3 "Divine Dragon Titanomakhia" from your GY and/or face-up field, including this card on the field; destroy all cards your opponent controls. During the End Phase: You can send cards from the top of your Deck to your GY, equal to the number of Dragon monsters you control.
local s, id, o = GetID()
function s.initial_effect(c)
	--indestructable
	local e1 = Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_SINGLE)
	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
	e1:SetRange(LOCATION_MZONE)
	e1:SetCondition(s.indcon)
	e1:SetValue(1)
	c:RegisterEffect(e1)
	--atkup
	local e2 = Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(id, 0))
	e2:SetCategory(CATEGORY_DESTROY)
	e2:SetType(EFFECT_TYPE_IGNITION)
	e2:SetRange(LOCATION_MZONE)
	e2:SetCountLimit(1, id)
	e2:SetCost(s.descost)
	e2:SetTarget(s.destg)
	e2:SetOperation(s.desop)
	c:RegisterEffect(e2)
	--discard deck
	local e3 = Effect.CreateEffect(c)
	e3:SetDescription(aux.Stringid(id, 1))
	e3:SetCategory(CATEGORY_DECKDES)
	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
	e3:SetRange(LOCATION_MZONE)
	e3:SetCode(EVENT_PHASE + PHASE_END)
	e3:SetCountLimit(1, id + o)
	e3:SetTarget(s.distg)
	e3:SetOperation(s.disop)
	c:RegisterEffect(e3)
end
function s.indcon(e)
	return e:GetHandler():IsSummonType(SUMMON_TYPE_SPECIAL)
end
function s.costfilter(c)
	return c:IsCode(id) and c:IsAbleToRemoveAsCost() and (c:IsLocation(LOCATION_GRAVE) or c:IsFaceup())
end
function s.descost(e, tp, eg, ep, ev, re, r, rp, chk)
	local c = e:GetHandler()
	local g = Duel.GetMatchingGroup(s.costfilter, tp, LOCATION_MZONE + LOCATION_GRAVE, 0, c)
	if chk == 0 then
		return c:IsAbleToRemoveAsCost() and g:GetCount() >= 2
	end
	local sg
	if #g == 2 then
		sg = g
	else
		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
		sg = g:Select(tp, 2, 2, nil)
	end
	sg:AddCard(c)
	Duel.Remove(sg, POS_FACEUP, REASON_COST)
end
function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return Duel.IsExistingMatchingCard(aux.TRUE, tp, 0, LOCATION_ONFIELD, 1, nil)
	end
	local g = Duel.GetMatchingGroup(aux.TRUE, tp, 0, LOCATION_ONFIELD, nil)
	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
end
function s.desop(e, tp, eg, ep, ev, re, r, rp)
	local g = Duel.GetMatchingGroup(aux.TRUE, tp, 0, LOCATION_ONFIELD, nil)
	Duel.Destroy(g, REASON_EFFECT)
end
function s.cfilter(c)
	return c:IsFaceup() and c:IsRace(RACE_DRAGON)
end
function s.distg(e, tp, eg, ep, ev, re, r, rp, chk)
	local ct = Duel.GetMatchingGroupCount(s.cfilter, tp, LOCATION_MZONE, 0, nil)
	if chk == 0 then
		return Duel.IsPlayerCanDiscardDeck(tp, ct)
	end
	Duel.SetOperationInfo(0, CATEGORY_DECKDES, nil, 0, tp, ct)
end
function s.disop(e, tp, eg, ep, ev, re, r, rp)
	local ct = Duel.GetMatchingGroupCount(s.cfilter, tp, LOCATION_MZONE, 0, nil)
	if ct > 0 then
		Duel.DiscardDeck(tp, ct, REASON_EFFECT)
	end
end


Divine
This Special Summoned card cannot be destroyed by battle. You can only use each of the following effects of "Divine Dragon Titanomakhia" once per turn. You can banish 3 "Divine Dragon Titanomakhia" from your GY and/or face-up field, including this card on the field; destroy all cards your opponent controls. During the End Phase: You can send cards from the top of your Deck to your GY, equal to the number of Dragon monsters you control.
-- Divine
local s, id, o = GetID()
function s.initial_effect(c)
	--indestructable
	local e1 = Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_SINGLE)
	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
	e1:SetRange(LOCATION_MZONE)
	e1:SetCondition(s.indcon)
	e1:SetValue(1)
	c:RegisterEffect(e1)
	--atkup
	local e2 = Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(id, 0))
	e2:SetCategory(CATEGORY_DESTROY)
	e2:SetType(EFFECT_TYPE_IGNITION)
	e2:SetRange(LOCATION_MZONE)
	e2:SetCountLimit(1, id)
	e2:SetCost(s.descost)
	e2:SetTarget(s.destg)
	e2:SetOperation(s.desop)
	c:RegisterEffect(e2)
	--discard deck
	local e3 = Effect.CreateEffect(c)
	e3:SetDescription(aux.Stringid(id, 1))
	e3:SetCategory(CATEGORY_DECKDES)
	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
	e3:SetRange(LOCATION_MZONE)
	e3:SetCode(EVENT_PHASE + PHASE_END)
	e3:SetCountLimit(1, id + o)
	e3:SetTarget(s.distg)
	e3:SetOperation(s.disop)
	c:RegisterEffect(e3)
end
function s.indcon(e)
	return e:GetHandler():IsSummonType(SUMMON_TYPE_SPECIAL)
end
function s.costfilter(c)
	return c:IsCode(id) and c:IsAbleToRemoveAsCost() and (c:IsLocation(LOCATION_GRAVE) or c:IsFaceup())
end
function s.descost(e, tp, eg, ep, ev, re, r, rp, chk)
	local c = e:GetHandler()
	local g = Duel.GetMatchingGroup(s.costfilter, tp, LOCATION_MZONE + LOCATION_GRAVE, 0, c)
	if chk == 0 then
		return c:IsAbleToRemoveAsCost() and g:GetCount() >= 2
	end
	local sg
	if #g == 2 then
		sg = g
	else
		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
		sg = g:Select(tp, 2, 2, nil)
	end
	sg:AddCard(c)
	Duel.Remove(sg, POS_FACEUP, REASON_COST)
end
function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return Duel.IsExistingMatchingCard(aux.TRUE, tp, 0, LOCATION_ONFIELD, 1, nil)
	end
	local g = Duel.GetMatchingGroup(aux.TRUE, tp, 0, LOCATION_ONFIELD, nil)
	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
end
function s.desop(e, tp, eg, ep, ev, re, r, rp)
	local g = Duel.GetMatchingGroup(aux.TRUE, tp, 0, LOCATION_ONFIELD, nil)
	Duel.Destroy(g, REASON_EFFECT)
end
function s.cfilter(c)
	return c:IsFaceup() and c:IsRace(RACE_DRAGON)
end
function s.distg(e, tp, eg, ep, ev, re, r, rp, chk)
	local ct = Duel.GetMatchingGroupCount(s.cfilter, tp, LOCATION_MZONE, 0, nil)
	if chk == 0 then
		return Duel.IsPlayerCanDiscardDeck(tp, ct)
	end
	Duel.SetOperationInfo(0, CATEGORY_DECKDES, nil, 0, tp, ct)
end
function s.disop(e, tp, eg, ep, ev, re, r, rp)
	local ct = Duel.GetMatchingGroupCount(s.cfilter, tp, LOCATION_MZONE, 0, nil)
	if ct > 0 then
		Duel.DiscardDeck(tp, ct, REASON_EFFECT)
	end
end

