name: Realm
card_text: Each time a card(s) is sent from your Deck to the Graveyard, place 1 Shine Counter on this card. All "Lightsworn" monsters gain 100 ATK for each Shine Counter on this card. If this card would be destroyed by a card effect, remove 2 Shine Counters from this card instead.
external_ids: local SETCARD_ID_0 = 0x38 --Lightsworn
  local COUNTER_ID_0 = 0x5 --Shine
  
lua: local SETCARD_ID_0 = 0x38 --Lightsworn
  local COUNTER_ID_0 = 0x5 --Shine
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x5)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--Add counter
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetOperation(s.acop)
  	c:RegisterEffect(e2)
  	--atkup
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_UPDATE_ATTACK)
  	e3:SetRange(LOCATION_FZONE)
  	e3:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e3:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e3:SetValue(s.atkval)
  	c:RegisterEffect(e3)
  	--Destroy replace
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  	e4:SetCode(EFFECT_DESTROY_REPLACE)
  	e4:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e4:SetRange(LOCATION_FZONE)
  	e4:SetTarget(s.desreptg)
  	e4:SetOperation(s.desrepop)
  	c:RegisterEffect(e4)
  end
  function s.atkval(e, c)
  	return e:GetHandler():GetCounter(COUNTER_ID_0) * 100
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousLocation(LOCATION_DECK) and c:IsPreviousControler(tp)
  end
  function s.acop(e, tp, eg, ep, ev, re, r, rp)
  	if eg:IsExists(s.cfilter, 1, nil, tp) then
  		e:GetHandler():AddCounter(COUNTER_ID_0, 1)
  	end
  end
  function s.desreptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return not e:GetHandler():IsReason(REASON_RULE) and e:GetHandler():GetCounter(COUNTER_ID_0) >= 2
  	end
  	return true
  end
  function s.desrepop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():RemoveCounter(ep, COUNTER_ID_0, 2, REASON_EFFECT)
  end
  
  
source_text: Realm
  Each time a card(s) is sent from your Deck to the Graveyard, place 1 Shine Counter on this card. All "Lightsworn" monsters gain 100 ATK for each Shine Counter on this card. If this card would be destroyed by a card effect, remove 2 Shine Counters from this card instead.
target_text: -- Realm
  local SETCARD_ID_0 = 0x38 --Lightsworn
  local COUNTER_ID_0 = 0x5 --Shine
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x5)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--Add counter
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetOperation(s.acop)
  	c:RegisterEffect(e2)
  	--atkup
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_UPDATE_ATTACK)
  	e3:SetRange(LOCATION_FZONE)
  	e3:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e3:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e3:SetValue(s.atkval)
  	c:RegisterEffect(e3)
  	--Destroy replace
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  	e4:SetCode(EFFECT_DESTROY_REPLACE)
  	e4:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e4:SetRange(LOCATION_FZONE)
  	e4:SetTarget(s.desreptg)
  	e4:SetOperation(s.desrepop)
  	c:RegisterEffect(e4)
  end
  function s.atkval(e, c)
  	return e:GetHandler():GetCounter(COUNTER_ID_0) * 100
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousLocation(LOCATION_DECK) and c:IsPreviousControler(tp)
  end
  function s.acop(e, tp, eg, ep, ev, re, r, rp)
  	if eg:IsExists(s.cfilter, 1, nil, tp) then
  		e:GetHandler():AddCounter(COUNTER_ID_0, 1)
  	end
  end
  function s.desreptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return not e:GetHandler():IsReason(REASON_RULE) and e:GetHandler():GetCounter(COUNTER_ID_0) >= 2
  	end
  	return true
  end
  function s.desrepop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():RemoveCounter(ep, COUNTER_ID_0, 2, REASON_EFFECT)
  end
  
  