name: Crystal
card_text: If this card is used for the Xyz Summon of a "Number" monster, it can be treated as a Level 3 or 4 monster. If this card is in your hand or GY: You can target 1 WATER monster on the field; Special Summon this card (but banish this card when it leaves the field), and if you do, halve that monster's ATK, also, you cannot Special Summon monsters from the Extra Deck for the rest of this turn, except Xyz Monsters. You can only use this effect of "Crystal Shark" once per turn.
external_ids: local SETCARD_ID_0 = 0x48 --Number
  
lua: local SETCARD_ID_0 = 0x48 --Number
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND + LOCATION_GRAVE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--xyzlv
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_XYZ_LEVEL)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetValue(s.xyzlv)
  	e2:SetLabel(3)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetLabel(4)
  	c:RegisterEffect(e3)
  end
  function s.spfilter(c)
  	return c:IsAttribute(ATTRIBUTE_WATER) and c:IsFaceup()
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and s.spfilter(chkc)
  	end
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.spfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil) and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, c, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) > 0 then
  		if tc:IsRelateToEffect(e) and tc:IsFaceup() and not tc:IsImmuneToEffect(e) then
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			e1:SetValue(math.ceil(tc:GetAttack() / 2))
  			tc:RegisterEffect(e1)
  		end
  		local e2 = Effect.CreateEffect(c)
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetCode(EFFECT_LEAVE_FIELD_REDIRECT)
  		e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e2:SetReset(RESET_EVENT + RESETS_REDIRECT)
  		e2:SetValue(LOCATION_REMOVED)
  		c:RegisterEffect(e2, true)
  	end
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e3:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e3:SetTargetRange(1, 0)
  	e3:SetReset(RESET_PHASE + PHASE_END)
  	e3:SetTarget(s.splimit)
  	Duel.RegisterEffect(e3, tp)
  end
  function s.splimit(e, c)
  	return not c:IsType(TYPE_XYZ) and c:IsLocation(LOCATION_EXTRA)
  end
  function s.xyzlv(e, c, rc)
  	if rc:IsSetCard(SETCARD_ID_0) then
  		return c:GetLevel() + 0x10000 * e:GetLabel()
  	else
  		return c:GetLevel()
  	end
  end
  
  
source_text: Crystal
  If this card is used for the Xyz Summon of a "Number" monster, it can be treated as a Level 3 or 4 monster. If this card is in your hand or GY: You can target 1 WATER monster on the field; Special Summon this card (but banish this card when it leaves the field), and if you do, halve that monster's ATK, also, you cannot Special Summon monsters from the Extra Deck for the rest of this turn, except Xyz Monsters. You can only use this effect of "Crystal Shark" once per turn.
target_text: -- Crystal
  local SETCARD_ID_0 = 0x48 --Number
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_HAND + LOCATION_GRAVE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--xyzlv
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_XYZ_LEVEL)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetValue(s.xyzlv)
  	e2:SetLabel(3)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetLabel(4)
  	c:RegisterEffect(e3)
  end
  function s.spfilter(c)
  	return c:IsAttribute(ATTRIBUTE_WATER) and c:IsFaceup()
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and s.spfilter(chkc)
  	end
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.spfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil) and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, c, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) > 0 then
  		if tc:IsRelateToEffect(e) and tc:IsFaceup() and not tc:IsImmuneToEffect(e) then
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			e1:SetValue(math.ceil(tc:GetAttack() / 2))
  			tc:RegisterEffect(e1)
  		end
  		local e2 = Effect.CreateEffect(c)
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetCode(EFFECT_LEAVE_FIELD_REDIRECT)
  		e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e2:SetReset(RESET_EVENT + RESETS_REDIRECT)
  		e2:SetValue(LOCATION_REMOVED)
  		c:RegisterEffect(e2, true)
  	end
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e3:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e3:SetTargetRange(1, 0)
  	e3:SetReset(RESET_PHASE + PHASE_END)
  	e3:SetTarget(s.splimit)
  	Duel.RegisterEffect(e3, tp)
  end
  function s.splimit(e, c)
  	return not c:IsType(TYPE_XYZ) and c:IsLocation(LOCATION_EXTRA)
  end
  function s.xyzlv(e, c, rc)
  	if rc:IsSetCard(SETCARD_ID_0) then
  		return c:GetLevel() + 0x10000 * e:GetLabel()
  	else
  		return c:GetLevel()
  	end
  end
  
  