name: Ultimate
card_text: 3 Level 5 monsters
  (This card is always treated as "Number C39: Utopia Ray".)
  Once per turn: You can detach 1 material from this card; equip 1 "ZW -" monster from your Deck or Extra Deck to this card as if it were equipped by that monster's effect. This effect's activation and effect cannot be negated. Once per turn, while this card is equipped with a "ZW -" Monster Card (Quick Effect): You can target 1 Effect Monster your opponent controls; negate its effects, and if you do, halve its ATK.
external_ids: local SETCARD_ID_0 = 0x107e --ZW
  
lua: local SETCARD_ID_0 = 0x107e --ZW
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, nil, 5, 3)
  	c:EnableReviveLimit()
  	--equip
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_INACTIVATE + EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_CAN_FORBIDDEN)
  	e1:SetCountLimit(1)
  	e1:SetCost(s.eqcost)
  	e1:SetTarget(s.eqtg)
  	e1:SetOperation(s.eqop)
  	c:RegisterEffect(e1)
  	--disable
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DISABLE)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetHintTiming(TIMING_DAMAGE_STEP, TIMING_DAMAGE_STEP + TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.discon)
  	e2:SetTarget(s.distg)
  	e2:SetOperation(s.disop)
  	c:RegisterEffect(e2)
  end
  aux.xyz_number[id] = 39
  aux.xyz_number[56840427] = 39
  function s.eqcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.eqfilter(c, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c.zw_equip_monster and not c:IsForbidden() and c:CheckUniqueOnField(tp, LOCATION_SZONE)
  end
  function s.eqtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.IsExistingMatchingCard(s.eqfilter, tp, LOCATION_EXTRA + LOCATION_DECK, 0, 1, nil, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, nil, 1, tp, LOCATION_EXTRA + LOCATION_DECK)
  end
  function s.eqop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if Duel.GetLocationCount(tp, LOCATION_SZONE) <= 0 then
  		return
  	end
  	if c:IsRelateToEffect(e) and c:IsFaceup() then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  		local g = Duel.SelectMatchingCard(tp, s.eqfilter, tp, LOCATION_EXTRA + LOCATION_DECK, 0, 1, 1, nil, tp)
  		local tc = g:GetFirst()
  		if not tc then
  			return
  		end
  		tc.zw_equip_monster(tc, tp, c)
  	end
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:GetOriginalType() & TYPE_MONSTER ~= 0
  end
  function s.discon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = c:GetEquipGroup()
  	return g:IsExists(s.cfilter, 1, nil) and aux.dscon(e, tp, eg, ep, ev, re, r, rp)
  end
  function s.distg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(1 - tp) and chkc:IsLocation(LOCATION_MZONE) and aux.NegateEffectMonsterFilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(aux.NegateEffectMonsterFilter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DISABLE)
  	local g = Duel.SelectTarget(tp, aux.NegateEffectMonsterFilter, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DISABLE, g, 1, 0, 0)
  end
  function s.disop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if tc:IsFaceup() and tc:IsRelateToEffect(e) and tc:IsCanBeDisabledByEffect(e) then
  		Duel.NegateRelatedChain(tc, RESET_TURN_SET)
  		local atk = tc:GetAttack()
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  		local e2 = Effect.CreateEffect(c)
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetCode(EFFECT_DISABLE_EFFECT)
  		e2:SetValue(RESET_TURN_SET)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e2)
  		Duel.AdjustInstantly()
  		local e3 = Effect.CreateEffect(c)
  		e3:SetType(EFFECT_TYPE_SINGLE)
  		e3:SetCode(EFFECT_SET_ATTACK_FINAL)
  		e3:SetReset(RESET_EVENT + RESETS_STANDARD)
  		e3:SetValue(math.ceil(atk / 2))
  		tc:RegisterEffect(e3)
  	end
  end
  
  
source_text: Ultimate
  3 Level 5 monsters
  (This card is always treated as "Number C39: Utopia Ray".)
  Once per turn: You can detach 1 material from this card; equip 1 "ZW -" monster from your Deck or Extra Deck to this card as if it were equipped by that monster's effect. This effect's activation and effect cannot be negated. Once per turn, while this card is equipped with a "ZW -" Monster Card (Quick Effect): You can target 1 Effect Monster your opponent controls; negate its effects, and if you do, halve its ATK.
target_text: -- Ultimate
  local SETCARD_ID_0 = 0x107e --ZW
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, nil, 5, 3)
  	c:EnableReviveLimit()
  	--equip
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_INACTIVATE + EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_CAN_FORBIDDEN)
  	e1:SetCountLimit(1)
  	e1:SetCost(s.eqcost)
  	e1:SetTarget(s.eqtg)
  	e1:SetOperation(s.eqop)
  	c:RegisterEffect(e1)
  	--disable
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DISABLE)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetHintTiming(TIMING_DAMAGE_STEP, TIMING_DAMAGE_STEP + TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.discon)
  	e2:SetTarget(s.distg)
  	e2:SetOperation(s.disop)
  	c:RegisterEffect(e2)
  end
  aux.xyz_number[id] = 39
  aux.xyz_number[56840427] = 39
  function s.eqcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.eqfilter(c, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c.zw_equip_monster and not c:IsForbidden() and c:CheckUniqueOnField(tp, LOCATION_SZONE)
  end
  function s.eqtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.IsExistingMatchingCard(s.eqfilter, tp, LOCATION_EXTRA + LOCATION_DECK, 0, 1, nil, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, nil, 1, tp, LOCATION_EXTRA + LOCATION_DECK)
  end
  function s.eqop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if Duel.GetLocationCount(tp, LOCATION_SZONE) <= 0 then
  		return
  	end
  	if c:IsRelateToEffect(e) and c:IsFaceup() then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  		local g = Duel.SelectMatchingCard(tp, s.eqfilter, tp, LOCATION_EXTRA + LOCATION_DECK, 0, 1, 1, nil, tp)
  		local tc = g:GetFirst()
  		if not tc then
  			return
  		end
  		tc.zw_equip_monster(tc, tp, c)
  	end
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:GetOriginalType() & TYPE_MONSTER ~= 0
  end
  function s.discon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = c:GetEquipGroup()
  	return g:IsExists(s.cfilter, 1, nil) and aux.dscon(e, tp, eg, ep, ev, re, r, rp)
  end
  function s.distg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(1 - tp) and chkc:IsLocation(LOCATION_MZONE) and aux.NegateEffectMonsterFilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(aux.NegateEffectMonsterFilter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DISABLE)
  	local g = Duel.SelectTarget(tp, aux.NegateEffectMonsterFilter, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DISABLE, g, 1, 0, 0)
  end
  function s.disop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if tc:IsFaceup() and tc:IsRelateToEffect(e) and tc:IsCanBeDisabledByEffect(e) then
  		Duel.NegateRelatedChain(tc, RESET_TURN_SET)
  		local atk = tc:GetAttack()
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  		local e2 = Effect.CreateEffect(c)
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetCode(EFFECT_DISABLE_EFFECT)
  		e2:SetValue(RESET_TURN_SET)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e2)
  		Duel.AdjustInstantly()
  		local e3 = Effect.CreateEffect(c)
  		e3:SetType(EFFECT_TYPE_SINGLE)
  		e3:SetCode(EFFECT_SET_ATTACK_FINAL)
  		e3:SetReset(RESET_EVENT + RESETS_STANDARD)
  		e3:SetValue(math.ceil(atk / 2))
  		tc:RegisterEffect(e3)
  	end
  end
  
  