name: Dinomorphia
card_text: Pay half your LP; Special Summon up to 2 "Dinomorphia" monsters from your GY whose total Levels equal 8 or less, but you cannot declare an attack with them this turn, also you cannot Special Summon for the rest of this turn, except "Dinomorphia" monsters. When your opponent activates a card or effect, while your LP are 2000 or less: You can banish this card from your GY; you take no effect damage from your opponent's card effects this turn. You can only activate 1 "Dinomorphia Alert" per turn.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x173 --Dinomorphia
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x173 --Dinomorphia
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--change damage
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCondition(s.cdcon)
  	e2:SetCost(aux.bfgcost)
  	e2:SetOperation(s.cdop)
  	c:RegisterEffect(e2)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.PayLPCost(tp, math.floor(Duel.GetLP(tp) / 2))
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsLevelBelow(8) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  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.spfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.spcheck(g)
  	return g:GetSum(Card.GetLevel) <= 8
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local ft = math.min((Duel.GetLocationCount(tp, LOCATION_MZONE)), 2)
  	local tg = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_GRAVE, 0, nil, e, tp)
  	if ft > 0 and #tg > 0 then
  		if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  			ft = 1
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		aux.GCheckAdditional = s.spcheck
  		local g = tg:SelectSubGroup(tp, aux.TRUE, false, 1, ft)
  		aux.GCheckAdditional = nil
  		local tc = g:GetFirst()
  		while tc do
  			if Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP) then
  				local e1 = Effect.CreateEffect(e:GetHandler())
  				e1:SetType(EFFECT_TYPE_SINGLE)
  				e1:SetCode(EFFECT_CANNOT_ATTACK)
  				e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  				e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  				tc:RegisterEffect(e1)
  			end
  			tc = g:GetNext()
  		end
  		Duel.SpecialSummonComplete()
  	end
  	local e2 = Effect.CreateEffect(e:GetHandler())
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetTargetRange(1, 0)
  	e2:SetTarget(s.splimit)
  	e2:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e2, tp)
  end
  function s.splimit(e, c)
  	return not c:IsSetCard(SETCARD_ID_0)
  end
  function s.cdcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetLP(tp) <= 2000 and rp == 1 - tp
  end
  function s.cdop(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CHANGE_DAMAGE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetTargetRange(1, 0)
  	e1:SetValue(s.damval1)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_NO_EFFECT_DAMAGE)
  	e2:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e2, tp)
  end
  function s.damval1(e, re, val, r, rp, rc)
  	if bit.band(r, REASON_EFFECT) ~= 0 and rp == 1 - e:GetOwnerPlayer() then
  		return 0
  	else
  		return val
  	end
  end
  
  
source_text: Dinomorphia
  Pay half your LP; Special Summon up to 2 "Dinomorphia" monsters from your GY whose total Levels equal 8 or less, but you cannot declare an attack with them this turn, also you cannot Special Summon for the rest of this turn, except "Dinomorphia" monsters. When your opponent activates a card or effect, while your LP are 2000 or less: You can banish this card from your GY; you take no effect damage from your opponent's card effects this turn. You can only activate 1 "Dinomorphia Alert" per turn.
target_text: -- Dinomorphia
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x173 --Dinomorphia
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--change damage
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCondition(s.cdcon)
  	e2:SetCost(aux.bfgcost)
  	e2:SetOperation(s.cdop)
  	c:RegisterEffect(e2)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.PayLPCost(tp, math.floor(Duel.GetLP(tp) / 2))
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsLevelBelow(8) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  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.spfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.spcheck(g)
  	return g:GetSum(Card.GetLevel) <= 8
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local ft = math.min((Duel.GetLocationCount(tp, LOCATION_MZONE)), 2)
  	local tg = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_GRAVE, 0, nil, e, tp)
  	if ft > 0 and #tg > 0 then
  		if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  			ft = 1
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		aux.GCheckAdditional = s.spcheck
  		local g = tg:SelectSubGroup(tp, aux.TRUE, false, 1, ft)
  		aux.GCheckAdditional = nil
  		local tc = g:GetFirst()
  		while tc do
  			if Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP) then
  				local e1 = Effect.CreateEffect(e:GetHandler())
  				e1:SetType(EFFECT_TYPE_SINGLE)
  				e1:SetCode(EFFECT_CANNOT_ATTACK)
  				e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  				e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  				tc:RegisterEffect(e1)
  			end
  			tc = g:GetNext()
  		end
  		Duel.SpecialSummonComplete()
  	end
  	local e2 = Effect.CreateEffect(e:GetHandler())
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetTargetRange(1, 0)
  	e2:SetTarget(s.splimit)
  	e2:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e2, tp)
  end
  function s.splimit(e, c)
  	return not c:IsSetCard(SETCARD_ID_0)
  end
  function s.cdcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetLP(tp) <= 2000 and rp == 1 - tp
  end
  function s.cdop(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CHANGE_DAMAGE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetTargetRange(1, 0)
  	e1:SetValue(s.damval1)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_NO_EFFECT_DAMAGE)
  	e2:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e2, tp)
  end
  function s.damval1(e, re, val, r, rp, rc)
  	if bit.band(r, REASON_EFFECT) ~= 0 and rp == 1 - e:GetOwnerPlayer() then
  		return 0
  	else
  		return val
  	end
  end
  
  