name: Dinomorphia
card_text: 2 "Dinomorphia" monsters with different names
  Loses ATK equal to your LP. You can only use each of the following effects of "Dinomorphia Kentregina" once per turn. During the Main Phase (Quick Effect): You can pay half your LP and banish 1 "Dinomorphia" Normal Trap from your GY; this effect becomes that Trap's effect when that card is activated. If this card is destroyed by battle or card effect: You can Special Summon 1 Level 4 or lower "Dinomorphia" monster from your GY.
external_ids: local SETCARD_ID_0 = 0x173 --Dinomorphia
  
lua: local SETCARD_ID_0 = 0x173 --Dinomorphia
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	aux.AddFusionProcFunRep(c, s.ffilter, 2, true)
  	--atk down
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetValue(s.adval)
  	c:RegisterEffect(e1)
  	--copy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetHintTiming(0, TIMING_MAIN_END + TIMINGS_CHECK_MONSTER)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.cpcon)
  	e2:SetCost(s.cpcost)
  	e2:SetTarget(s.cptg)
  	e2:SetOperation(s.cpop)
  	c:RegisterEffect(e2)
  	--spsummon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_DESTROYED)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.spcon)
  	e3:SetTarget(s.sptg)
  	e3:SetOperation(s.spop)
  	c:RegisterEffect(e3)
  end
  function s.ffilter(c, fc, sub, mg, sg)
  	return c:IsFusionSetCard(SETCARD_ID_0) and (not sg or not sg:IsExists(Card.IsFusionCode, 1, c, c:GetFusionCode()))
  end
  function s.adval(e, c)
  	return -Duel.GetLP(e:GetHandlerPlayer())
  end
  function s.cpcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2
  end
  function s.cpfilter(c)
  	return c:GetType() == TYPE_TRAP and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToRemoveAsCost() and c:CheckActivateEffect(false, true, false)
  end
  function s.cpcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(1)
  	if chk == 0 then
  		return true
  	end
  end
  function s.cptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		if e:GetLabel() == 0 then
  			return false
  		end
  		e:SetLabel(0)
  		return Duel.IsExistingMatchingCard(s.cpfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.PayLPCost(tp, math.floor(Duel.GetLP(tp) / 2))
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.cpfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	local te, ceg, cep, cev, cre, cr, crp = g:GetFirst():CheckActivateEffect(false, true, true)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  	e:SetProperty(te:GetProperty())
  	local tg = te:GetTarget()
  	if tg then
  		tg(e, tp, ceg, cep, cev, cre, cr, crp, 1)
  	end
  	te:SetLabelObject(e:GetLabelObject())
  	e:SetLabelObject(te)
  	Duel.ClearOperationInfo(0)
  end
  function s.cpop(e, tp, eg, ep, ev, re, r, rp)
  	local te = e:GetLabelObject()
  	if not te then
  		return
  	end
  	e:SetLabelObject(te:GetLabelObject())
  	local op = te:GetOperation()
  	if op then
  		op(e, tp, eg, ep, ev, re, r, rp)
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return bit.band(r, REASON_EFFECT + REASON_BATTLE) ~= 0
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsLevelBelow(4) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(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.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Dinomorphia
  2 "Dinomorphia" monsters with different names
  Loses ATK equal to your LP. You can only use each of the following effects of "Dinomorphia Kentregina" once per turn. During the Main Phase (Quick Effect): You can pay half your LP and banish 1 "Dinomorphia" Normal Trap from your GY; this effect becomes that Trap's effect when that card is activated. If this card is destroyed by battle or card effect: You can Special Summon 1 Level 4 or lower "Dinomorphia" monster from your GY.
target_text: -- Dinomorphia
  local SETCARD_ID_0 = 0x173 --Dinomorphia
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	aux.AddFusionProcFunRep(c, s.ffilter, 2, true)
  	--atk down
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetValue(s.adval)
  	c:RegisterEffect(e1)
  	--copy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetHintTiming(0, TIMING_MAIN_END + TIMINGS_CHECK_MONSTER)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.cpcon)
  	e2:SetCost(s.cpcost)
  	e2:SetTarget(s.cptg)
  	e2:SetOperation(s.cpop)
  	c:RegisterEffect(e2)
  	--spsummon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_DESTROYED)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.spcon)
  	e3:SetTarget(s.sptg)
  	e3:SetOperation(s.spop)
  	c:RegisterEffect(e3)
  end
  function s.ffilter(c, fc, sub, mg, sg)
  	return c:IsFusionSetCard(SETCARD_ID_0) and (not sg or not sg:IsExists(Card.IsFusionCode, 1, c, c:GetFusionCode()))
  end
  function s.adval(e, c)
  	return -Duel.GetLP(e:GetHandlerPlayer())
  end
  function s.cpcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2
  end
  function s.cpfilter(c)
  	return c:GetType() == TYPE_TRAP and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToRemoveAsCost() and c:CheckActivateEffect(false, true, false)
  end
  function s.cpcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(1)
  	if chk == 0 then
  		return true
  	end
  end
  function s.cptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		if e:GetLabel() == 0 then
  			return false
  		end
  		e:SetLabel(0)
  		return Duel.IsExistingMatchingCard(s.cpfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.PayLPCost(tp, math.floor(Duel.GetLP(tp) / 2))
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.cpfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	local te, ceg, cep, cev, cre, cr, crp = g:GetFirst():CheckActivateEffect(false, true, true)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  	e:SetProperty(te:GetProperty())
  	local tg = te:GetTarget()
  	if tg then
  		tg(e, tp, ceg, cep, cev, cre, cr, crp, 1)
  	end
  	te:SetLabelObject(e:GetLabelObject())
  	e:SetLabelObject(te)
  	Duel.ClearOperationInfo(0)
  end
  function s.cpop(e, tp, eg, ep, ev, re, r, rp)
  	local te = e:GetLabelObject()
  	if not te then
  		return
  	end
  	e:SetLabelObject(te:GetLabelObject())
  	local op = te:GetOperation()
  	if op then
  		op(e, tp, eg, ep, ev, re, r, rp)
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return bit.band(r, REASON_EFFECT + REASON_BATTLE) ~= 0
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsLevelBelow(4) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(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.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  