name: Megalith
card_text: You can Ritual Summon this card with a "Megalith" card. You can discard this card; Ritual Summon 1 "Megalith" Ritual Monster from your hand, by Tributing monsters from your hand or field whose total Levels equal or exceed its Level. You can only use this effect of "Megalith Phaleg" once per turn. Monsters you control gain 300 ATK/DEF for each Ritual Monster in your GY.
external_ids: local SETCARD_ID_0 = 0x138 --Megalith
  
lua: local SETCARD_ID_0 = 0x138 --Megalith
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--ritual summon
  	local e1 = aux.AddRitualProcGreater2(c, s.filter, nil, nil, s.matfilter, true)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetCode(0)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.rscost)
  	c:RegisterEffect(e1)
  	--atk/def up
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_UPDATE_ATTACK)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetValue(s.val)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_UPDATE_DEFENSE)
  	c:RegisterEffect(e3)
  end
  function s.filter(c, e, tp, chk)
  	return c:IsSetCard(SETCARD_ID_0) and (not chk or c ~= e:GetHandler())
  end
  function s.matfilter(c, e, tp, chk)
  	return not chk or c ~= e:GetHandler()
  end
  function s.rscost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsDiscardable()
  	end
  	Duel.SendtoGrave(e:GetHandler(), REASON_COST + REASON_DISCARD)
  end
  function s.cfilter(c)
  	return c:IsType(TYPE_RITUAL) and c:IsType(TYPE_MONSTER)
  end
  function s.val(e, c)
  	return Duel.GetMatchingGroupCount(s.cfilter, e:GetHandlerPlayer(), LOCATION_GRAVE, 0, nil) * 300
  end
  
  
source_text: Megalith
  You can Ritual Summon this card with a "Megalith" card. You can discard this card; Ritual Summon 1 "Megalith" Ritual Monster from your hand, by Tributing monsters from your hand or field whose total Levels equal or exceed its Level. You can only use this effect of "Megalith Phaleg" once per turn. Monsters you control gain 300 ATK/DEF for each Ritual Monster in your GY.
target_text: -- Megalith
  local SETCARD_ID_0 = 0x138 --Megalith
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--ritual summon
  	local e1 = aux.AddRitualProcGreater2(c, s.filter, nil, nil, s.matfilter, true)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetCode(0)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.rscost)
  	c:RegisterEffect(e1)
  	--atk/def up
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_UPDATE_ATTACK)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetValue(s.val)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_UPDATE_DEFENSE)
  	c:RegisterEffect(e3)
  end
  function s.filter(c, e, tp, chk)
  	return c:IsSetCard(SETCARD_ID_0) and (not chk or c ~= e:GetHandler())
  end
  function s.matfilter(c, e, tp, chk)
  	return not chk or c ~= e:GetHandler()
  end
  function s.rscost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsDiscardable()
  	end
  	Duel.SendtoGrave(e:GetHandler(), REASON_COST + REASON_DISCARD)
  end
  function s.cfilter(c)
  	return c:IsType(TYPE_RITUAL) and c:IsType(TYPE_MONSTER)
  end
  function s.val(e, c)
  	return Duel.GetMatchingGroupCount(s.cfilter, e:GetHandlerPlayer(), LOCATION_GRAVE, 0, nil) * 300
  end
  
  