name: Dragunity
card_text: You can discard 1 "Dragunity" card; equip 1 "Dragunity" Tuner from your Deck to this card, also, you cannot Special Summon monsters from the Extra Deck for the rest of this turn, except Dragon monsters. You can only use this effect of "Dragunity Senatus" once per turn. If a "Dragunity" card(s) you control would be destroyed by battle or card effect, you can destroy 1 "Dragunity" card equipped to this card, instead.
external_ids: local SETCARD_ID_0 = 0x29 --Dragunity
  
lua: local SETCARD_ID_0 = 0x29 --Dragunity
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--equip
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.eqcost)
  	e1:SetTarget(s.eqtg)
  	e1:SetOperation(s.eqop)
  	c:RegisterEffect(e1)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTarget(s.reptg)
  	e2:SetValue(s.repval)
  	e2:SetOperation(s.repop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsDiscardable()
  end
  function s.eqcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_HAND, 0, 1, e:GetHandler())
  	end
  	Duel.DiscardHand(tp, s.cfilter, 1, 1, REASON_COST + REASON_DISCARD, e:GetHandler())
  end
  function s.eqfilter(c, ec)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_TUNER) and not c:IsForbidden()
  end
  function s.eqtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.IsExistingMatchingCard(s.eqfilter, tp, LOCATION_DECK, 0, 1, nil, e:GetHandler())
  	end
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, nil, 1, tp, LOCATION_DECK)
  end
  function s.eqop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and c:IsFaceup() and c:IsRelateToEffect(e) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  		local g = Duel.SelectMatchingCard(tp, s.eqfilter, tp, LOCATION_DECK, 0, 1, 1, nil, c)
  		if g:GetCount() > 0 then
  			Duel.Equip(tp, g:GetFirst(), c)
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetProperty(EFFECT_FLAG_OWNER_RELATE)
  			e1:SetCode(EFFECT_EQUIP_LIMIT)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			e1:SetValue(s.eqlimit)
  			e1:SetLabelObject(c)
  			g:GetFirst():RegisterEffect(e1)
  		end
  	end
  	local e2 = Effect.CreateEffect(c)
  	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.eqlimit(e, c)
  	return c == e:GetLabelObject()
  end
  function s.splimit(e, c)
  	return not c:IsRace(RACE_DRAGON) and c:IsLocation(LOCATION_EXTRA)
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup() and c:IsControler(tp) and c:IsOnField() and c:IsSetCard(SETCARD_ID_0) and (c:IsReason(REASON_BATTLE) or c:IsReason(REASON_EFFECT)) and not c:IsReason(REASON_REPLACE)
  end
  function s.desfilter(c, e)
  	return c:IsLocation(LOCATION_SZONE) and c:IsSetCard(SETCARD_ID_0) and e:GetHandler():GetEquipGroup():IsContains(c) and c:IsDestructable(e) and not c:IsStatus(STATUS_DESTROY_CONFIRMED)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return eg:IsExists(s.repfilter, 1, nil, tp) and Duel.IsExistingMatchingCard(s.desfilter, tp, LOCATION_SZONE, LOCATION_SZONE, 1, nil, e)
  	end
  	if Duel.SelectEffectYesNo(tp, e:GetHandler(), 96) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESREPLACE)
  		local g = Duel.SelectMatchingCard(tp, s.desfilter, tp, LOCATION_SZONE, LOCATION_SZONE, 1, 1, nil, e)
  		e:SetLabelObject(g:GetFirst())
  		g:GetFirst():SetStatus(STATUS_DESTROY_CONFIRMED, true)
  		return true
  	end
  	return false
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	tc:SetStatus(STATUS_DESTROY_CONFIRMED, false)
  	Duel.Destroy(tc, REASON_EFFECT + REASON_REPLACE)
  end
  
  
source_text: Dragunity
  You can discard 1 "Dragunity" card; equip 1 "Dragunity" Tuner from your Deck to this card, also, you cannot Special Summon monsters from the Extra Deck for the rest of this turn, except Dragon monsters. You can only use this effect of "Dragunity Senatus" once per turn. If a "Dragunity" card(s) you control would be destroyed by battle or card effect, you can destroy 1 "Dragunity" card equipped to this card, instead.
target_text: -- Dragunity
  local SETCARD_ID_0 = 0x29 --Dragunity
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--equip
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.eqcost)
  	e1:SetTarget(s.eqtg)
  	e1:SetOperation(s.eqop)
  	c:RegisterEffect(e1)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTarget(s.reptg)
  	e2:SetValue(s.repval)
  	e2:SetOperation(s.repop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsDiscardable()
  end
  function s.eqcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_HAND, 0, 1, e:GetHandler())
  	end
  	Duel.DiscardHand(tp, s.cfilter, 1, 1, REASON_COST + REASON_DISCARD, e:GetHandler())
  end
  function s.eqfilter(c, ec)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_TUNER) and not c:IsForbidden()
  end
  function s.eqtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.IsExistingMatchingCard(s.eqfilter, tp, LOCATION_DECK, 0, 1, nil, e:GetHandler())
  	end
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, nil, 1, tp, LOCATION_DECK)
  end
  function s.eqop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and c:IsFaceup() and c:IsRelateToEffect(e) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  		local g = Duel.SelectMatchingCard(tp, s.eqfilter, tp, LOCATION_DECK, 0, 1, 1, nil, c)
  		if g:GetCount() > 0 then
  			Duel.Equip(tp, g:GetFirst(), c)
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetProperty(EFFECT_FLAG_OWNER_RELATE)
  			e1:SetCode(EFFECT_EQUIP_LIMIT)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			e1:SetValue(s.eqlimit)
  			e1:SetLabelObject(c)
  			g:GetFirst():RegisterEffect(e1)
  		end
  	end
  	local e2 = Effect.CreateEffect(c)
  	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.eqlimit(e, c)
  	return c == e:GetLabelObject()
  end
  function s.splimit(e, c)
  	return not c:IsRace(RACE_DRAGON) and c:IsLocation(LOCATION_EXTRA)
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup() and c:IsControler(tp) and c:IsOnField() and c:IsSetCard(SETCARD_ID_0) and (c:IsReason(REASON_BATTLE) or c:IsReason(REASON_EFFECT)) and not c:IsReason(REASON_REPLACE)
  end
  function s.desfilter(c, e)
  	return c:IsLocation(LOCATION_SZONE) and c:IsSetCard(SETCARD_ID_0) and e:GetHandler():GetEquipGroup():IsContains(c) and c:IsDestructable(e) and not c:IsStatus(STATUS_DESTROY_CONFIRMED)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return eg:IsExists(s.repfilter, 1, nil, tp) and Duel.IsExistingMatchingCard(s.desfilter, tp, LOCATION_SZONE, LOCATION_SZONE, 1, nil, e)
  	end
  	if Duel.SelectEffectYesNo(tp, e:GetHandler(), 96) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESREPLACE)
  		local g = Duel.SelectMatchingCard(tp, s.desfilter, tp, LOCATION_SZONE, LOCATION_SZONE, 1, 1, nil, e)
  		e:SetLabelObject(g:GetFirst())
  		g:GetFirst():SetStatus(STATUS_DESTROY_CONFIRMED, true)
  		return true
  	end
  	return false
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	tc:SetStatus(STATUS_DESTROY_CONFIRMED, false)
  	Duel.Destroy(tc, REASON_EFFECT + REASON_REPLACE)
  end
  
  