name: Boss
card_text: You cannot Normal Summon or Set. During the End Phase of the turn that a "B.E.S." monster or a "Big Core" is destroyed and sent to the Graveyard, you can Special Summon 1 "B.E.S." monster or 1 "Big Core" from your Deck.
external_ids: local SETCARD_ID_0 = 0x15 --B.E.S.
  
lua: local SETCARD_ID_0 = 0x15 --B.E.S.
  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:SetCondition(s.condition)
  	c:RegisterEffect(e1)
  	--cannot normal summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(1, 0)
  	e2:SetCode(EFFECT_CANNOT_SUMMON)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_CANNOT_MSET)
  	c:RegisterEffect(e3)
  	--special summon
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetCode(EVENT_TO_GRAVE)
  	e4:SetOperation(s.checkop)
  	c:RegisterEffect(e4)
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 0))
  	e5:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e5:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e5:SetCode(EVENT_PHASE + PHASE_END)
  	e5:SetRange(LOCATION_SZONE)
  	e5:SetCountLimit(1)
  	e5:SetCondition(s.spcon)
  	e5:SetTarget(s.sptg)
  	e5:SetOperation(s.spop)
  	c:RegisterEffect(e5)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetActivityCount(tp, ACTIVITY_NORMALSUMMON) == 0
  end
  function s.chkfilter(c, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsReason(REASON_DESTROY) and c:IsPreviousControler(tp) and c:IsPreviousLocation(LOCATION_MZONE)
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	if eg:IsExists(s.chkfilter, 1, nil, tp) then
  		e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) ~= 0
  end
  function s.filter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  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, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  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, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Boss
  You cannot Normal Summon or Set. During the End Phase of the turn that a "B.E.S." monster or a "Big Core" is destroyed and sent to the Graveyard, you can Special Summon 1 "B.E.S." monster or 1 "Big Core" from your Deck.
target_text: -- Boss
  local SETCARD_ID_0 = 0x15 --B.E.S.
  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:SetCondition(s.condition)
  	c:RegisterEffect(e1)
  	--cannot normal summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(1, 0)
  	e2:SetCode(EFFECT_CANNOT_SUMMON)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_CANNOT_MSET)
  	c:RegisterEffect(e3)
  	--special summon
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetCode(EVENT_TO_GRAVE)
  	e4:SetOperation(s.checkop)
  	c:RegisterEffect(e4)
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 0))
  	e5:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e5:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e5:SetCode(EVENT_PHASE + PHASE_END)
  	e5:SetRange(LOCATION_SZONE)
  	e5:SetCountLimit(1)
  	e5:SetCondition(s.spcon)
  	e5:SetTarget(s.sptg)
  	e5:SetOperation(s.spop)
  	c:RegisterEffect(e5)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetActivityCount(tp, ACTIVITY_NORMALSUMMON) == 0
  end
  function s.chkfilter(c, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsReason(REASON_DESTROY) and c:IsPreviousControler(tp) and c:IsPreviousLocation(LOCATION_MZONE)
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	if eg:IsExists(s.chkfilter, 1, nil, tp) then
  		e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) ~= 0
  end
  function s.filter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  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, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  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, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  