name: Rising
card_text: Equip only to a "Utopia" monster. It cannot be destroyed by card effects. Each time an attack is negated, place 1 Rising Sun Counter on this card. The equipped monster gains 500 ATK for each Rising Sun Counter on this card. If the equipped monster you control would detach its material to activate its effect, you can treat this card as 1 of the materials.
external_ids: local SETCARD_ID_0 = 0x107f --Utopia
  local COUNTER_ID_0 = 0x31 --Rising
  
lua: local SETCARD_ID_0 = 0x107f --Utopia
  local COUNTER_ID_0 = 0x31 --Rising
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x31)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_CONTINUOUS_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--Untargetable
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_EQUIP)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--Equip limit
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetCode(EFFECT_EQUIP_LIMIT)
  	e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e3:SetValue(s.eqlimit)
  	c:RegisterEffect(e3)
  	--counter
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_COUNTER)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e4:SetProperty(EFFECT_FLAG_DELAY)
  	e4:SetCode(EVENT_ATTACK_DISABLED)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetOperation(s.regop)
  	c:RegisterEffect(e4)
  	--atk
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_EQUIP)
  	e5:SetCode(EFFECT_UPDATE_ATTACK)
  	e5:SetValue(s.value)
  	c:RegisterEffect(e5)
  	--remove overlay replace
  	local e6 = Effect.CreateEffect(c)
  	e6:SetDescription(aux.Stringid(id, 0))
  	e6:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e6:SetCode(EFFECT_OVERLAY_REMOVE_REPLACE)
  	e6:SetRange(LOCATION_SZONE)
  	e6:SetCondition(s.rcon)
  	e6:SetOperation(s.rop)
  	c:RegisterEffect(e6)
  end
  function s.eqlimit(e, c)
  	return c:IsSetCard(SETCARD_ID_0)
  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_EQUIP)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, e:GetHandler(), 1, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		Duel.Equip(tp, c, tc)
  	end
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():AddCounter(COUNTER_ID_0, 1)
  end
  function s.value(e, c)
  	return e:GetHandler():GetCounter(COUNTER_ID_0) * 500
  end
  function s.rcon(e, tp, eg, ep, ev, re, r, rp)
  	return bit.band(r, REASON_COST) ~= 0
  		and re:GetHandler():IsType(TYPE_XYZ)
  		and ep == e:GetOwnerPlayer()
  		and e:GetHandler():GetEquipTarget() == re:GetHandler()
  		and re:GetHandler():GetOverlayCount() >= ev - 1
  end
  function s.rop(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.SendtoGrave(e:GetHandler(), REASON_COST)
  end
  
  
source_text: Rising
  Equip only to a "Utopia" monster. It cannot be destroyed by card effects. Each time an attack is negated, place 1 Rising Sun Counter on this card. The equipped monster gains 500 ATK for each Rising Sun Counter on this card. If the equipped monster you control would detach its material to activate its effect, you can treat this card as 1 of the materials.
target_text: -- Rising
  local SETCARD_ID_0 = 0x107f --Utopia
  local COUNTER_ID_0 = 0x31 --Rising
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x31)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_CONTINUOUS_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--Untargetable
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_EQUIP)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--Equip limit
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetCode(EFFECT_EQUIP_LIMIT)
  	e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e3:SetValue(s.eqlimit)
  	c:RegisterEffect(e3)
  	--counter
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_COUNTER)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e4:SetProperty(EFFECT_FLAG_DELAY)
  	e4:SetCode(EVENT_ATTACK_DISABLED)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetOperation(s.regop)
  	c:RegisterEffect(e4)
  	--atk
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_EQUIP)
  	e5:SetCode(EFFECT_UPDATE_ATTACK)
  	e5:SetValue(s.value)
  	c:RegisterEffect(e5)
  	--remove overlay replace
  	local e6 = Effect.CreateEffect(c)
  	e6:SetDescription(aux.Stringid(id, 0))
  	e6:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e6:SetCode(EFFECT_OVERLAY_REMOVE_REPLACE)
  	e6:SetRange(LOCATION_SZONE)
  	e6:SetCondition(s.rcon)
  	e6:SetOperation(s.rop)
  	c:RegisterEffect(e6)
  end
  function s.eqlimit(e, c)
  	return c:IsSetCard(SETCARD_ID_0)
  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_EQUIP)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, e:GetHandler(), 1, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		Duel.Equip(tp, c, tc)
  	end
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():AddCounter(COUNTER_ID_0, 1)
  end
  function s.value(e, c)
  	return e:GetHandler():GetCounter(COUNTER_ID_0) * 500
  end
  function s.rcon(e, tp, eg, ep, ev, re, r, rp)
  	return bit.band(r, REASON_COST) ~= 0
  		and re:GetHandler():IsType(TYPE_XYZ)
  		and ep == e:GetOwnerPlayer()
  		and e:GetHandler():GetEquipTarget() == re:GetHandler()
  		and re:GetHandler():GetOverlayCount() >= ev - 1
  end
  function s.rop(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.SendtoGrave(e:GetHandler(), REASON_COST)
  end
  
  