name: Dragunity
card_text: 1 "Dragunity" Tuner + 1+ non-Tuner monsters
  When your opponent activates a monster effect (Quick Effect): You can banish 1 "Dragunity" monster from your GY; negate the activation, and if you do, banish that card. If this card destroys an opponent's monster by battle, after damage calculation: You can banish that opponent's monster. If this Synchro Summoned card in its owner's control is destroyed by an opponent's card: You can destroy all Spells and Traps your opponent controls. You can only use each effect of "Dragunity Knight - Areadbhair" once per turn.
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)
  	--synchro summon
  	aux.AddSynchroProcedure(c, aux.FilterBoolFunction(Card.IsSetCard, SETCARD_ID_0), aux.NonTuner(nil), 1)
  	c:EnableReviveLimit()
  	--negate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_NEGATE + CATEGORY_REMOVE)
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_CHAINING)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.negcon)
  	e1:SetCost(s.negcost)
  	e1:SetTarget(aux.nbtg)
  	e1:SetOperation(s.negop)
  	c:RegisterEffect(e1)
  	--remove
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCategory(CATEGORY_REMOVE)
  	e2:SetCode(EVENT_BATTLED)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.rmcon)
  	e2:SetTarget(s.rmtg)
  	e2:SetOperation(s.rmop)
  	c:RegisterEffect(e2)
  	--destroy
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCode(EVENT_DESTROYED)
  	e3:SetCountLimit(1, id + 2)
  	e3:SetCondition(s.descon)
  	e3:SetTarget(s.destg)
  	e3:SetOperation(s.desop)
  	c:RegisterEffect(e3)
  end
  function s.cfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToRemoveAsCost()
  end
  function s.negcon(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp and not e:GetHandler():IsStatus(STATUS_BATTLE_DESTROYED) and Duel.IsChainNegatable(ev) and re:IsActiveType(TYPE_MONSTER)
  end
  function s.negcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  end
  function s.negop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then
  		Duel.Remove(eg, POS_FACEUP, REASON_EFFECT)
  	end
  end
  function s.rmcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local bc = c:GetBattleTarget()
  	e:SetLabelObject(bc)
  	return bc and bc:IsStatus(STATUS_BATTLE_DESTROYED) and c:IsStatus(STATUS_OPPO_BATTLE) and bc:IsControler(1 - tp) and bc:IsRelateToBattle()
  end
  function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local bc = e:GetLabelObject()
  	if chk == 0 then
  		return bc:IsAbleToRemove()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, bc, 1, 0, 0)
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local bc = e:GetLabelObject()
  	if bc:IsRelateToBattle() and bc:IsControler(1 - tp) then
  		Duel.Remove(bc, POS_FACEUP, REASON_EFFECT)
  	end
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return rp == 1 - tp and c:IsPreviousControler(tp) and c:IsPreviousLocation(LOCATION_MZONE) and c:IsSummonType(SUMMON_TYPE_SYNCHRO)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsType, tp, 0, LOCATION_ONFIELD, 1, nil, TYPE_SPELL + TYPE_TRAP)
  	end
  	local g = Duel.GetMatchingGroup(Card.IsType, tp, 0, LOCATION_ONFIELD, nil, TYPE_SPELL + TYPE_TRAP)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, #g, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(Card.IsType, tp, 0, LOCATION_ONFIELD, nil, TYPE_SPELL + TYPE_TRAP)
  	Duel.Destroy(g, REASON_EFFECT)
  end
  
  
source_text: Dragunity
  1 "Dragunity" Tuner + 1+ non-Tuner monsters
  When your opponent activates a monster effect (Quick Effect): You can banish 1 "Dragunity" monster from your GY; negate the activation, and if you do, banish that card. If this card destroys an opponent's monster by battle, after damage calculation: You can banish that opponent's monster. If this Synchro Summoned card in its owner's control is destroyed by an opponent's card: You can destroy all Spells and Traps your opponent controls. You can only use each effect of "Dragunity Knight - Areadbhair" once per turn.
target_text: -- Dragunity
  local SETCARD_ID_0 = 0x29 --Dragunity
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, aux.FilterBoolFunction(Card.IsSetCard, SETCARD_ID_0), aux.NonTuner(nil), 1)
  	c:EnableReviveLimit()
  	--negate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_NEGATE + CATEGORY_REMOVE)
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_CHAINING)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.negcon)
  	e1:SetCost(s.negcost)
  	e1:SetTarget(aux.nbtg)
  	e1:SetOperation(s.negop)
  	c:RegisterEffect(e1)
  	--remove
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCategory(CATEGORY_REMOVE)
  	e2:SetCode(EVENT_BATTLED)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.rmcon)
  	e2:SetTarget(s.rmtg)
  	e2:SetOperation(s.rmop)
  	c:RegisterEffect(e2)
  	--destroy
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCode(EVENT_DESTROYED)
  	e3:SetCountLimit(1, id + 2)
  	e3:SetCondition(s.descon)
  	e3:SetTarget(s.destg)
  	e3:SetOperation(s.desop)
  	c:RegisterEffect(e3)
  end
  function s.cfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToRemoveAsCost()
  end
  function s.negcon(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp and not e:GetHandler():IsStatus(STATUS_BATTLE_DESTROYED) and Duel.IsChainNegatable(ev) and re:IsActiveType(TYPE_MONSTER)
  end
  function s.negcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  end
  function s.negop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then
  		Duel.Remove(eg, POS_FACEUP, REASON_EFFECT)
  	end
  end
  function s.rmcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local bc = c:GetBattleTarget()
  	e:SetLabelObject(bc)
  	return bc and bc:IsStatus(STATUS_BATTLE_DESTROYED) and c:IsStatus(STATUS_OPPO_BATTLE) and bc:IsControler(1 - tp) and bc:IsRelateToBattle()
  end
  function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local bc = e:GetLabelObject()
  	if chk == 0 then
  		return bc:IsAbleToRemove()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, bc, 1, 0, 0)
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local bc = e:GetLabelObject()
  	if bc:IsRelateToBattle() and bc:IsControler(1 - tp) then
  		Duel.Remove(bc, POS_FACEUP, REASON_EFFECT)
  	end
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return rp == 1 - tp and c:IsPreviousControler(tp) and c:IsPreviousLocation(LOCATION_MZONE) and c:IsSummonType(SUMMON_TYPE_SYNCHRO)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsType, tp, 0, LOCATION_ONFIELD, 1, nil, TYPE_SPELL + TYPE_TRAP)
  	end
  	local g = Duel.GetMatchingGroup(Card.IsType, tp, 0, LOCATION_ONFIELD, nil, TYPE_SPELL + TYPE_TRAP)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, #g, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(Card.IsType, tp, 0, LOCATION_ONFIELD, nil, TYPE_SPELL + TYPE_TRAP)
  	Duel.Destroy(g, REASON_EFFECT)
  end
  
  