name: Yubel
card_text: Cannot be Normal Summoned or Set. Must be Special Summoned by "Yubel". Cannot be destroyed by battle. You take no battle damage from battles involving this card. Before damage calculation, if this face-up Attack Position card is targeted for an attack: Inflict damage to your opponent equal to that attacking monster's ATK. Once per turn, during your End Phase: Destroy all other monsters on the field. When this face-up card leaves the field: You can Special Summon 1 "Yubel - The Ultimate Nightmare" from your hand, Deck, or GY.
external_ids: local CARD_ID_0 = 31764700 --Yubel - The Ultimate Nightmare
  local CARD_ID_1 = 78371393 --Yubel
  
lua: local CARD_ID_0 = 31764700 --Yubel - The Ultimate Nightmare
  local CARD_ID_1 = 78371393 --Yubel
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_1)
  	c:EnableReviveLimit()
  	--battle
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_AVOID_BATTLE_DAMAGE)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--damage
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_DAMAGE)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e3:SetCode(EVENT_BATTLE_CONFIRM)
  	e3:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e3:SetCondition(s.damcon)
  	e3:SetTarget(s.damtg)
  	e3:SetOperation(s.damop)
  	c:RegisterEffect(e3)
  	--destroy
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_RELEASE + CATEGORY_DESTROY)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1)
  	e4:SetCode(EVENT_PHASE + PHASE_END)
  	e4:SetCondition(s.descon)
  	e4:SetTarget(s.destg)
  	e4:SetOperation(s.desop)
  	c:RegisterEffect(e4)
  	--special summon
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 2))
  	e5:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e5:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e5:SetCode(EVENT_LEAVE_FIELD)
  	e5:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e5:SetCondition(s.spcon)
  	e5:SetTarget(s.sptg)
  	e5:SetOperation(s.spop)
  	c:RegisterEffect(e5)
  	--cannot special summon
  	local e6 = Effect.CreateEffect(c)
  	e6:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e6:SetType(EFFECT_TYPE_SINGLE)
  	e6:SetCode(EFFECT_SPSUMMON_CONDITION)
  	c:RegisterEffect(e6)
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler() == Duel.GetAttackTarget()
  end
  function s.damtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAttackPos()
  	end
  	Duel.SetTargetPlayer(1 - tp)
  	local atk = Duel.GetAttacker():GetAttack()
  	Duel.SetTargetParam(atk)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, atk)
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Damage(p, d, REASON_EFFECT)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local g = Duel.GetMatchingGroup(aux.TRUE, tp, LOCATION_MZONE, LOCATION_MZONE, e:GetHandler())
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(aux.TRUE, tp, LOCATION_MZONE, LOCATION_MZONE, aux.ExceptThisCard(e))
  	Duel.Destroy(g, REASON_EFFECT)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsPreviousPosition(POS_FACEUP)
  end
  function s.filter(c, e, tp)
  	return c:IsCode(CARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, true, true)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.filter, tp, 0x13, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, 0x13)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.filter), tp, 0x13, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, true, true, POS_FACEUP)
  		g:GetFirst():CompleteProcedure()
  	end
  end
  
  
source_text: Yubel
  Cannot be Normal Summoned or Set. Must be Special Summoned by "Yubel". Cannot be destroyed by battle. You take no battle damage from battles involving this card. Before damage calculation, if this face-up Attack Position card is targeted for an attack: Inflict damage to your opponent equal to that attacking monster's ATK. Once per turn, during your End Phase: Destroy all other monsters on the field. When this face-up card leaves the field: You can Special Summon 1 "Yubel - The Ultimate Nightmare" from your hand, Deck, or GY.
target_text: -- Yubel
  local CARD_ID_0 = 31764700 --Yubel - The Ultimate Nightmare
  local CARD_ID_1 = 78371393 --Yubel
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_1)
  	c:EnableReviveLimit()
  	--battle
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_AVOID_BATTLE_DAMAGE)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--damage
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_DAMAGE)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e3:SetCode(EVENT_BATTLE_CONFIRM)
  	e3:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e3:SetCondition(s.damcon)
  	e3:SetTarget(s.damtg)
  	e3:SetOperation(s.damop)
  	c:RegisterEffect(e3)
  	--destroy
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_RELEASE + CATEGORY_DESTROY)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1)
  	e4:SetCode(EVENT_PHASE + PHASE_END)
  	e4:SetCondition(s.descon)
  	e4:SetTarget(s.destg)
  	e4:SetOperation(s.desop)
  	c:RegisterEffect(e4)
  	--special summon
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 2))
  	e5:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e5:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e5:SetCode(EVENT_LEAVE_FIELD)
  	e5:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e5:SetCondition(s.spcon)
  	e5:SetTarget(s.sptg)
  	e5:SetOperation(s.spop)
  	c:RegisterEffect(e5)
  	--cannot special summon
  	local e6 = Effect.CreateEffect(c)
  	e6:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e6:SetType(EFFECT_TYPE_SINGLE)
  	e6:SetCode(EFFECT_SPSUMMON_CONDITION)
  	c:RegisterEffect(e6)
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler() == Duel.GetAttackTarget()
  end
  function s.damtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAttackPos()
  	end
  	Duel.SetTargetPlayer(1 - tp)
  	local atk = Duel.GetAttacker():GetAttack()
  	Duel.SetTargetParam(atk)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, atk)
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Damage(p, d, REASON_EFFECT)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local g = Duel.GetMatchingGroup(aux.TRUE, tp, LOCATION_MZONE, LOCATION_MZONE, e:GetHandler())
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(aux.TRUE, tp, LOCATION_MZONE, LOCATION_MZONE, aux.ExceptThisCard(e))
  	Duel.Destroy(g, REASON_EFFECT)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsPreviousPosition(POS_FACEUP)
  end
  function s.filter(c, e, tp)
  	return c:IsCode(CARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, true, true)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.filter, tp, 0x13, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, 0x13)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.filter), tp, 0x13, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, true, true, POS_FACEUP)
  		g:GetFirst():CompleteProcedure()
  	end
  end
  
  