Marincess
Target 1 WATER Link Monster you control; return it to the Extra Deck, and if you do, Special Summon 1 "Marincess" Link Monster from your Extra Deck with the same Link Rating but a different name, but it cannot attack directly or be destroyed by battle this turn. (This is treated as a Link Summon.) If you control a Link-3 or higher "Marincess" monster, you can activate this card from your hand.
local SETCARD_ID_0 = 0x12b --Marincess

local SETCARD_ID_0 = 0x12b --Marincess
local s, id, o = GetID()
function s.initial_effect(c)
	--Activate
	local e1 = Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_TOEXTRA + CATEGORY_SPECIAL_SUMMON)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
	e1:SetTarget(s.target)
	e1:SetOperation(s.activate)
	c:RegisterEffect(e1)
	--act in hand
	local e2 = Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(id, 0))
	e2:SetType(EFFECT_TYPE_SINGLE)
	e2:SetCode(EFFECT_TRAP_ACT_IN_HAND)
	e2:SetCondition(s.handcon)
	c:RegisterEffect(e2)
end
function s.texfilter(c, e, tp)
	return c:IsFaceup() and c:IsType(TYPE_LINK) and c:IsAttribute(ATTRIBUTE_WATER) and c:IsAbleToExtra() and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, c)
end
function s.spfilter(c, e, tp, rc)
	return c:IsSetCard(SETCARD_ID_0)
		and c:IsType(TYPE_LINK)
		and c:IsLink(rc:GetLink())
		and not c:IsCode(rc:GetCode())
		and c:IsCanBeSpecialSummoned(e, SUMMON_TYPE_LINK, tp, false, false)
		and Duel.GetLocationCountFromEx(tp, tp, rc, c) > 0
end
function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
	if chkc then
		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.texfilter(chkc, e, tp)
	end
	if chk == 0 then
		return aux.MustMaterialCheck(nil, tp, EFFECT_MUST_BE_LMATERIAL) and Duel.IsExistingTarget(s.texfilter, tp, LOCATION_MZONE, 0, 1, nil, e, tp)
	end
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
	local g = Duel.SelectTarget(tp, s.texfilter, tp, LOCATION_MZONE, 0, 1, 1, nil, e, tp)
	Duel.SetOperationInfo(0, CATEGORY_TOEXTRA, g, 1, 0, 0)
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
end
function s.activate(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	local tc = Duel.GetFirstTarget()
	if tc:IsRelateToEffect(e) and Duel.SendtoDeck(tc, nil, 0, REASON_EFFECT) ~= 0 and tc:IsLocation(LOCATION_EXTRA) and aux.MustMaterialCheck(nil, tp, EFFECT_MUST_BE_LMATERIAL) then
		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
		local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, tc)
		local sc = g:GetFirst()
		if sc then
			sc:SetMaterial(nil)
			if Duel.SpecialSummon(sc, SUMMON_TYPE_LINK, tp, tp, false, false, POS_FACEUP) ~= 0 then
				local e1 = Effect.CreateEffect(c)
				e1:SetType(EFFECT_TYPE_SINGLE)
				e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
				e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
				e1:SetRange(LOCATION_MZONE)
				e1:SetValue(1)
				e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
				sc:RegisterEffect(e1, true)
				local e2 = Effect.CreateEffect(c)
				e2:SetType(EFFECT_TYPE_SINGLE)
				e2:SetCode(EFFECT_CANNOT_DIRECT_ATTACK)
				e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
				e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
				sc:RegisterEffect(e2, true)
				sc:CompleteProcedure()
			end
		end
	end
end
function s.hcfilter(c)
	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsLinkAbove(3)
end
function s.handcon(e)
	return Duel.IsExistingMatchingCard(s.hcfilter, e:GetHandlerPlayer(), LOCATION_MZONE, 0, 1, nil)
end


Marincess
Target 1 WATER Link Monster you control; return it to the Extra Deck, and if you do, Special Summon 1 "Marincess" Link Monster from your Extra Deck with the same Link Rating but a different name, but it cannot attack directly or be destroyed by battle this turn. (This is treated as a Link Summon.) If you control a Link-3 or higher "Marincess" monster, you can activate this card from your hand.
-- Marincess
local SETCARD_ID_0 = 0x12b --Marincess
local s, id, o = GetID()
function s.initial_effect(c)
	--Activate
	local e1 = Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_TOEXTRA + CATEGORY_SPECIAL_SUMMON)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
	e1:SetTarget(s.target)
	e1:SetOperation(s.activate)
	c:RegisterEffect(e1)
	--act in hand
	local e2 = Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(id, 0))
	e2:SetType(EFFECT_TYPE_SINGLE)
	e2:SetCode(EFFECT_TRAP_ACT_IN_HAND)
	e2:SetCondition(s.handcon)
	c:RegisterEffect(e2)
end
function s.texfilter(c, e, tp)
	return c:IsFaceup() and c:IsType(TYPE_LINK) and c:IsAttribute(ATTRIBUTE_WATER) and c:IsAbleToExtra() and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, c)
end
function s.spfilter(c, e, tp, rc)
	return c:IsSetCard(SETCARD_ID_0)
		and c:IsType(TYPE_LINK)
		and c:IsLink(rc:GetLink())
		and not c:IsCode(rc:GetCode())
		and c:IsCanBeSpecialSummoned(e, SUMMON_TYPE_LINK, tp, false, false)
		and Duel.GetLocationCountFromEx(tp, tp, rc, c) > 0
end
function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
	if chkc then
		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.texfilter(chkc, e, tp)
	end
	if chk == 0 then
		return aux.MustMaterialCheck(nil, tp, EFFECT_MUST_BE_LMATERIAL) and Duel.IsExistingTarget(s.texfilter, tp, LOCATION_MZONE, 0, 1, nil, e, tp)
	end
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
	local g = Duel.SelectTarget(tp, s.texfilter, tp, LOCATION_MZONE, 0, 1, 1, nil, e, tp)
	Duel.SetOperationInfo(0, CATEGORY_TOEXTRA, g, 1, 0, 0)
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
end
function s.activate(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	local tc = Duel.GetFirstTarget()
	if tc:IsRelateToEffect(e) and Duel.SendtoDeck(tc, nil, 0, REASON_EFFECT) ~= 0 and tc:IsLocation(LOCATION_EXTRA) and aux.MustMaterialCheck(nil, tp, EFFECT_MUST_BE_LMATERIAL) then
		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
		local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, tc)
		local sc = g:GetFirst()
		if sc then
			sc:SetMaterial(nil)
			if Duel.SpecialSummon(sc, SUMMON_TYPE_LINK, tp, tp, false, false, POS_FACEUP) ~= 0 then
				local e1 = Effect.CreateEffect(c)
				e1:SetType(EFFECT_TYPE_SINGLE)
				e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
				e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
				e1:SetRange(LOCATION_MZONE)
				e1:SetValue(1)
				e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
				sc:RegisterEffect(e1, true)
				local e2 = Effect.CreateEffect(c)
				e2:SetType(EFFECT_TYPE_SINGLE)
				e2:SetCode(EFFECT_CANNOT_DIRECT_ATTACK)
				e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
				e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
				sc:RegisterEffect(e2, true)
				sc:CompleteProcedure()
			end
		end
	end
end
function s.hcfilter(c)
	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsLinkAbove(3)
end
function s.handcon(e)
	return Duel.IsExistingMatchingCard(s.hcfilter, e:GetHandlerPlayer(), LOCATION_MZONE, 0, 1, nil)
end

