name: Dark
card_text: When an opponent's monster declares an attack, or an opponent's monster effect is activated that would destroy a monster(s) on the field, while a monster that mentions "Shining Sarcophagus" is on the field: Destroy as many Attack Position monsters your opponent controls as possible, then if you control "Dark Magician", inflict 500 damage to your opponent for each monster destroyed, also for the rest of this turn after this card resolves, the first time each monster you control that mentions "Shining Sarcophagus" would be destroyed by battle or card effect, it is not destroyed.
external_ids: local CARD_ID_0 = 46986414 --Dark Magician
  local CARD_ID_1 = 79791878 --Shining Sarcophagus
  
lua: local CARD_ID_0 = 46986414 --Dark Magician
  local CARD_ID_1 = 79791878 --Shining Sarcophagus
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_1, CARD_ID_0)
  	--
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DESTROY + CATEGORY_DAMAGE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetCondition(s.condition1)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetCondition(s.condition2)
  	c:RegisterEffect(e2)
  end
  function s.cfilter1(c)
  	return aux.IsCodeListed(c, CARD_ID_1) and c:IsFaceup()
  end
  function s.condition1(e, tp, eg, ep, ev, re, r, rp)
  	return tp ~= Duel.GetTurnPlayer()
  end
  function s.filter(c)
  	return c:IsAttackPos()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, 0, LOCATION_MZONE, 1, nil) and Duel.IsExistingMatchingCard(s.cfilter1, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(s.filter, tp, 0, LOCATION_MZONE, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
  end
  function s.cfilter2(c)
  	return c:IsCode(CARD_ID_0) and c:IsFaceup()
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.filter, tp, 0, LOCATION_MZONE, nil)
  	if g:GetCount() > 0 then
  		local ct = Duel.Destroy(g, REASON_EFFECT)
  		if Duel.IsExistingMatchingCard(s.cfilter2, tp, LOCATION_ONFIELD, 0, 1, nil) then
  			Duel.BreakEffect()
  			Duel.Damage(1 - tp, ct * 500, REASON_EFFECT)
  		end
  	end
  	if e:IsHasType(EFFECT_TYPE_ACTIVATE) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_FIELD)
  		e1:SetCode(EFFECT_INDESTRUCTABLE_COUNT)
  		e1:SetTargetRange(LOCATION_MZONE, 0)
  		e1:SetTarget(s.efftg)
  		e1:SetValue(s.indct)
  		e1:SetReset(RESET_PHASE + PHASE_END)
  		Duel.RegisterEffect(e1, tp)
  	end
  end
  function s.efftg(e, c)
  	return aux.IsCodeListed(c, CARD_ID_1)
  end
  function s.indct(e, re, r, rp)
  	if bit.band(r, REASON_BATTLE + REASON_EFFECT) ~= 0 then
  		return 1
  	else
  		return 0
  	end
  end
  function s.cfilter3(c)
  	return c:IsOnField() and c:IsType(TYPE_MONSTER)
  end
  function s.condition2(e, tp, eg, ep, ev, re, r, rp)
  	if tp == ep then
  		return false
  	end
  	if not re:IsActiveType(TYPE_MONSTER) then
  		return false
  	end
  	local ex, tg, tc = Duel.GetOperationInfo(ev, CATEGORY_DESTROY)
  	return ex and tg ~= nil and tc + tg:FilterCount(s.cfilter3, nil) - tg:GetCount() > 0
  end
  
  
source_text: Dark
  When an opponent's monster declares an attack, or an opponent's monster effect is activated that would destroy a monster(s) on the field, while a monster that mentions "Shining Sarcophagus" is on the field: Destroy as many Attack Position monsters your opponent controls as possible, then if you control "Dark Magician", inflict 500 damage to your opponent for each monster destroyed, also for the rest of this turn after this card resolves, the first time each monster you control that mentions "Shining Sarcophagus" would be destroyed by battle or card effect, it is not destroyed.
target_text: -- Dark
  local CARD_ID_0 = 46986414 --Dark Magician
  local CARD_ID_1 = 79791878 --Shining Sarcophagus
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_1, CARD_ID_0)
  	--
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DESTROY + CATEGORY_DAMAGE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetCondition(s.condition1)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetCondition(s.condition2)
  	c:RegisterEffect(e2)
  end
  function s.cfilter1(c)
  	return aux.IsCodeListed(c, CARD_ID_1) and c:IsFaceup()
  end
  function s.condition1(e, tp, eg, ep, ev, re, r, rp)
  	return tp ~= Duel.GetTurnPlayer()
  end
  function s.filter(c)
  	return c:IsAttackPos()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, 0, LOCATION_MZONE, 1, nil) and Duel.IsExistingMatchingCard(s.cfilter1, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(s.filter, tp, 0, LOCATION_MZONE, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
  end
  function s.cfilter2(c)
  	return c:IsCode(CARD_ID_0) and c:IsFaceup()
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.filter, tp, 0, LOCATION_MZONE, nil)
  	if g:GetCount() > 0 then
  		local ct = Duel.Destroy(g, REASON_EFFECT)
  		if Duel.IsExistingMatchingCard(s.cfilter2, tp, LOCATION_ONFIELD, 0, 1, nil) then
  			Duel.BreakEffect()
  			Duel.Damage(1 - tp, ct * 500, REASON_EFFECT)
  		end
  	end
  	if e:IsHasType(EFFECT_TYPE_ACTIVATE) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_FIELD)
  		e1:SetCode(EFFECT_INDESTRUCTABLE_COUNT)
  		e1:SetTargetRange(LOCATION_MZONE, 0)
  		e1:SetTarget(s.efftg)
  		e1:SetValue(s.indct)
  		e1:SetReset(RESET_PHASE + PHASE_END)
  		Duel.RegisterEffect(e1, tp)
  	end
  end
  function s.efftg(e, c)
  	return aux.IsCodeListed(c, CARD_ID_1)
  end
  function s.indct(e, re, r, rp)
  	if bit.band(r, REASON_BATTLE + REASON_EFFECT) ~= 0 then
  		return 1
  	else
  		return 0
  	end
  end
  function s.cfilter3(c)
  	return c:IsOnField() and c:IsType(TYPE_MONSTER)
  end
  function s.condition2(e, tp, eg, ep, ev, re, r, rp)
  	if tp == ep then
  		return false
  	end
  	if not re:IsActiveType(TYPE_MONSTER) then
  		return false
  	end
  	local ex, tg, tc = Duel.GetOperationInfo(ev, CATEGORY_DESTROY)
  	return ex and tg ~= nil and tc + tg:FilterCount(s.cfilter3, nil) - tg:GetCount() > 0
  end
  
  