name: Dogmatika
card_text: Neither player can target "Dogmatika" monsters you control with effects of monsters that were Special Summoned from the Extra Deck. You can only use each of the following effects of "Dogmatika Nation" once per turn.
  ● After damage calculation, if your "Dogmatika" monster battled an opponent's monster: Destroy that opponent's monster.
  ● If this face-up card in the Field Zone is destroyed by an opponent's card effect: You can have each player send 1 monster from their Extra Deck to the GY.
external_ids: local SETCARD_ID_0 = 0x145 --Dogmatika
  
lua: local SETCARD_ID_0 = 0x145 --Dogmatika
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_ACTIVATE)
  	e0:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e0)
  	--cannot be target
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e1:SetRange(LOCATION_FZONE)
  	e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e1:SetTargetRange(LOCATION_MZONE, 0)
  	e1:SetTarget(s.eftg)
  	e1:SetValue(s.efilter)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BATTLED)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.descon)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  	--to grave
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_TOGRAVE)
  	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.tgcon)
  	e3:SetTarget(s.tgtg)
  	e3:SetOperation(s.tgop)
  	c:RegisterEffect(e3)
  end
  function s.eftg(e, c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.efilter(e, re, rp)
  	return re:IsActiveType(TYPE_MONSTER) and re:GetHandler():IsSummonLocation(LOCATION_EXTRA) and re:GetActivateLocation() == LOCATION_MZONE
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local ac = Duel.GetAttacker()
  	local bc = Duel.GetAttackTarget()
  	if not bc then
  		return false
  	end
  	if not ac:IsControler(tp) then
  		ac, bc = bc, ac
  	end
  	e:SetLabelObject(bc)
  	return ac:IsFaceup() and ac:IsControler(tp) and ac:IsSetCard(SETCARD_ID_0) and bc:IsControler(1 - tp)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local bc = e:GetLabelObject()
  	if not bc then
  		return false
  	end
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, bc, 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local bc = e:GetLabelObject()
  	if bc and bc:IsRelateToBattle() and bc:IsControler(1 - tp) then
  		Duel.Destroy(bc, REASON_EFFECT)
  	end
  end
  function s.tgcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsPreviousPosition(POS_FACEUP) and c:IsPreviousLocation(LOCATION_FZONE) and c:IsPreviousControler(tp) and c:IsReason(REASON_EFFECT) and c:GetReasonPlayer() == 1 - tp
  end
  function s.tgtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(Card.IsAbleToGrave, tp, LOCATION_EXTRA, 0, nil)
  	local g2 = Duel.GetMatchingGroup(Card.IsAbleToGrave, tp, 0, LOCATION_EXTRA, nil)
  	if chk == 0 then
  		return g:GetCount() > 0 and g2:GetCount() > 0
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 2, PLAYER_ALL, LOCATION_EXTRA)
  end
  function s.tgop(e, tp, eg, ep, ev, re, r, rp)
  	local turnp = Duel.GetTurnPlayer()
  	local g = Duel.GetMatchingGroup(Card.IsAbleToGrave, turnp, LOCATION_EXTRA, 0, nil)
  	local g2 = Duel.GetMatchingGroup(Card.IsAbleToGrave, turnp, 0, LOCATION_EXTRA, nil)
  	Duel.Hint(HINT_SELECTMSG, turnp, HINTMSG_TOGRAVE)
  	local sg = g:Select(turnp, 1, 1, nil)
  	Duel.Hint(HINT_SELECTMSG, 1 - turnp, HINTMSG_TOGRAVE)
  	local sg2 = g2:Select(1 - turnp, 1, 1, nil)
  	sg:Merge(sg2)
  	if sg:GetCount() > 0 then
  		Duel.SendtoGrave(sg, REASON_EFFECT)
  	end
  end
  
  
source_text: Dogmatika
  Neither player can target "Dogmatika" monsters you control with effects of monsters that were Special Summoned from the Extra Deck. You can only use each of the following effects of "Dogmatika Nation" once per turn.
  ● After damage calculation, if your "Dogmatika" monster battled an opponent's monster: Destroy that opponent's monster.
  ● If this face-up card in the Field Zone is destroyed by an opponent's card effect: You can have each player send 1 monster from their Extra Deck to the GY.
target_text: -- Dogmatika
  local SETCARD_ID_0 = 0x145 --Dogmatika
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_ACTIVATE)
  	e0:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e0)
  	--cannot be target
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e1:SetRange(LOCATION_FZONE)
  	e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e1:SetTargetRange(LOCATION_MZONE, 0)
  	e1:SetTarget(s.eftg)
  	e1:SetValue(s.efilter)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BATTLED)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.descon)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  	--to grave
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_TOGRAVE)
  	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.tgcon)
  	e3:SetTarget(s.tgtg)
  	e3:SetOperation(s.tgop)
  	c:RegisterEffect(e3)
  end
  function s.eftg(e, c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.efilter(e, re, rp)
  	return re:IsActiveType(TYPE_MONSTER) and re:GetHandler():IsSummonLocation(LOCATION_EXTRA) and re:GetActivateLocation() == LOCATION_MZONE
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local ac = Duel.GetAttacker()
  	local bc = Duel.GetAttackTarget()
  	if not bc then
  		return false
  	end
  	if not ac:IsControler(tp) then
  		ac, bc = bc, ac
  	end
  	e:SetLabelObject(bc)
  	return ac:IsFaceup() and ac:IsControler(tp) and ac:IsSetCard(SETCARD_ID_0) and bc:IsControler(1 - tp)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local bc = e:GetLabelObject()
  	if not bc then
  		return false
  	end
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, bc, 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local bc = e:GetLabelObject()
  	if bc and bc:IsRelateToBattle() and bc:IsControler(1 - tp) then
  		Duel.Destroy(bc, REASON_EFFECT)
  	end
  end
  function s.tgcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsPreviousPosition(POS_FACEUP) and c:IsPreviousLocation(LOCATION_FZONE) and c:IsPreviousControler(tp) and c:IsReason(REASON_EFFECT) and c:GetReasonPlayer() == 1 - tp
  end
  function s.tgtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(Card.IsAbleToGrave, tp, LOCATION_EXTRA, 0, nil)
  	local g2 = Duel.GetMatchingGroup(Card.IsAbleToGrave, tp, 0, LOCATION_EXTRA, nil)
  	if chk == 0 then
  		return g:GetCount() > 0 and g2:GetCount() > 0
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 2, PLAYER_ALL, LOCATION_EXTRA)
  end
  function s.tgop(e, tp, eg, ep, ev, re, r, rp)
  	local turnp = Duel.GetTurnPlayer()
  	local g = Duel.GetMatchingGroup(Card.IsAbleToGrave, turnp, LOCATION_EXTRA, 0, nil)
  	local g2 = Duel.GetMatchingGroup(Card.IsAbleToGrave, turnp, 0, LOCATION_EXTRA, nil)
  	Duel.Hint(HINT_SELECTMSG, turnp, HINTMSG_TOGRAVE)
  	local sg = g:Select(turnp, 1, 1, nil)
  	Duel.Hint(HINT_SELECTMSG, 1 - turnp, HINTMSG_TOGRAVE)
  	local sg2 = g2:Select(1 - turnp, 1, 1, nil)
  	sg:Merge(sg2)
  	if sg:GetCount() > 0 then
  		Duel.SendtoGrave(sg, REASON_EFFECT)
  	end
  end
  
  