name: Bujintervention
card_text: Target 1 "Bujin" monster on the field; apply this effect to it for the rest of this turn. Each time it destroys a monster by battle whose current ATK is greater than or equal to the targeted monster's original ATK, and sends it to the Graveyard: Banish the destroyed monster, and if you do, banish all monsters from your opponent's hand, Main Deck, Extra Deck, and Graveyard with the same name that the destroyed monster had in the Graveyard.
external_ids: local SETCARD_ID_0 = 0x88 --Bujin
  
lua: local SETCARD_ID_0 = 0x88 --Bujin
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() and not tc:IsImmuneToEffect(e) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetDescription(aux.Stringid(id, 0))
  		e1:SetCategory(CATEGORY_REMOVE)
  		e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  		e1:SetCode(EVENT_BATTLE_DESTROYING)
  		e1:SetTarget(s.rmtg)
  		e1:SetOperation(s.rmop)
  		e1:SetReset(RESET_EVENT + 0x1620000 + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local bc = c:GetBattleTarget()
  	if chk == 0 then
  		return bc and bc:IsLocation(LOCATION_GRAVE) and bc:IsReason(REASON_BATTLE) and bc:IsType(TYPE_MONSTER) and c:GetBaseAttack() <= bc:GetAttack() and bc:IsAbleToRemove()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, bc, 1, 0, 0)
  end
  function s.rmfilter(c, code)
  	return c:IsCode(code) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemove()
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetHandler():GetBattleTarget()
  	if Duel.Remove(tc, POS_FACEUP, REASON_EFFECT) == 0 then
  		return
  	end
  	local g = Duel.GetMatchingGroup(s.rmfilter, tp, 0, LOCATION_HAND + LOCATION_DECK + LOCATION_EXTRA + LOCATION_GRAVE, nil, tc:GetCode())
  	if g:GetCount() > 0 then
  		Duel.BreakEffect()
  		Duel.Remove(g, POS_FACEUP, REASON_EFFECT)
  	end
  end
  
  
source_text: Bujintervention
  Target 1 "Bujin" monster on the field; apply this effect to it for the rest of this turn. Each time it destroys a monster by battle whose current ATK is greater than or equal to the targeted monster's original ATK, and sends it to the Graveyard: Banish the destroyed monster, and if you do, banish all monsters from your opponent's hand, Main Deck, Extra Deck, and Graveyard with the same name that the destroyed monster had in the Graveyard.
target_text: -- Bujintervention
  local SETCARD_ID_0 = 0x88 --Bujin
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() and not tc:IsImmuneToEffect(e) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetDescription(aux.Stringid(id, 0))
  		e1:SetCategory(CATEGORY_REMOVE)
  		e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  		e1:SetCode(EVENT_BATTLE_DESTROYING)
  		e1:SetTarget(s.rmtg)
  		e1:SetOperation(s.rmop)
  		e1:SetReset(RESET_EVENT + 0x1620000 + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local bc = c:GetBattleTarget()
  	if chk == 0 then
  		return bc and bc:IsLocation(LOCATION_GRAVE) and bc:IsReason(REASON_BATTLE) and bc:IsType(TYPE_MONSTER) and c:GetBaseAttack() <= bc:GetAttack() and bc:IsAbleToRemove()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, bc, 1, 0, 0)
  end
  function s.rmfilter(c, code)
  	return c:IsCode(code) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemove()
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetHandler():GetBattleTarget()
  	if Duel.Remove(tc, POS_FACEUP, REASON_EFFECT) == 0 then
  		return
  	end
  	local g = Duel.GetMatchingGroup(s.rmfilter, tp, 0, LOCATION_HAND + LOCATION_DECK + LOCATION_EXTRA + LOCATION_GRAVE, nil, tc:GetCode())
  	if g:GetCount() > 0 then
  		Duel.BreakEffect()
  		Duel.Remove(g, POS_FACEUP, REASON_EFFECT)
  	end
  end
  
  