name: Marincess
card_text: Banish any number of "Marincess" Link Monsters you control (until your next Standby Phase), then target 1 face-up monster on the field; it gains ATK equal to the total Link Rating of the monsters banished to activate this card x 300, until the end of this turn. If you control a Link-3 or higher "Marincess" monster, you can activate this card from your hand.
external_ids: local SETCARD_ID_0 = 0x12b --Marincess
  
lua: 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_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(TIMING_DAMAGE_STEP)
  	e1:SetCondition(aux.dscon)
  	e1:SetCost(s.cost)
  	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.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(1)
  	return true
  end
  function s.costfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_LINK) and c:IsLinkAbove(1) and c:IsAbleToRemoveAsCost()
  end
  function s.fselect(g, tp)
  	return Duel.IsExistingTarget(Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, 1, g)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local g = Duel.GetMatchingGroup(s.costfilter, tp, LOCATION_MZONE, 0, nil)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsFaceup()
  	end
  	if chk == 0 then
  		if e:GetLabel() ~= 1 then
  			return false
  		end
  		e:SetLabel(0)
  		return g:CheckSubGroup(s.fselect, 1, g:GetCount(), tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local rg = g:SelectSubGroup(tp, s.fselect, false, 1, g:GetCount(), tp)
  	local ct = rg:GetSum(Card.GetLink)
  	e:SetLabel(ct)
  	local tct = 1
  	if Duel.GetTurnPlayer() == tp and Duel.GetCurrentPhase() == PHASE_STANDBY then
  		tct = 2
  	end
  	local tc = rg:GetFirst()
  	while tc do
  		if Duel.Remove(tc, 0, REASON_COST + REASON_TEMPORARY) ~= 0 then
  			tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_STANDBY + RESET_SELF_TURN, 0, tct)
  		end
  		tc = rg:GetNext()
  	end
  	rg:KeepAlive()
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e1:SetCode(EVENT_PHASE + PHASE_STANDBY)
  	e1:SetCountLimit(1)
  	e1:SetLabelObject(rg)
  	e1:SetCondition(s.retcon)
  	e1:SetOperation(s.retop)
  	if Duel.GetTurnPlayer() == tp and Duel.GetCurrentPhase() == PHASE_STANDBY then
  		e1:SetReset(RESET_PHASE + PHASE_STANDBY + RESET_SELF_TURN, 2)
  		e1:SetValue(Duel.GetTurnCount())
  	else
  		e1:SetReset(RESET_PHASE + PHASE_STANDBY + RESET_SELF_TURN)
  		e1:SetValue(0)
  	end
  	Duel.RegisterEffect(e1, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  end
  function s.retfilter(c)
  	return c:GetFlagEffect(id) ~= 0
  end
  function s.retcon(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetTurnPlayer() ~= tp or Duel.GetTurnCount() == e:GetValue() then
  		return false
  	end
  	return e:GetLabelObject():IsExists(s.retfilter, 1, nil)
  end
  function s.retop(e, tp, eg, ep, ev, re, r, rp)
  	local g = e:GetLabelObject():Filter(s.retfilter, nil)
  	local tc = g:GetFirst()
  	while tc do
  		Duel.ReturnToField(tc)
  		tc = g:GetNext()
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	local ct = e:GetLabel()
  	if tc:IsFaceup() and tc:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetValue(ct * 300)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	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
  
  
source_text: Marincess
  Banish any number of "Marincess" Link Monsters you control (until your next Standby Phase), then target 1 face-up monster on the field; it gains ATK equal to the total Link Rating of the monsters banished to activate this card x 300, until the end of this turn. If you control a Link-3 or higher "Marincess" monster, you can activate this card from your hand.
target_text: -- 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_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(TIMING_DAMAGE_STEP)
  	e1:SetCondition(aux.dscon)
  	e1:SetCost(s.cost)
  	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.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(1)
  	return true
  end
  function s.costfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_LINK) and c:IsLinkAbove(1) and c:IsAbleToRemoveAsCost()
  end
  function s.fselect(g, tp)
  	return Duel.IsExistingTarget(Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, 1, g)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local g = Duel.GetMatchingGroup(s.costfilter, tp, LOCATION_MZONE, 0, nil)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsFaceup()
  	end
  	if chk == 0 then
  		if e:GetLabel() ~= 1 then
  			return false
  		end
  		e:SetLabel(0)
  		return g:CheckSubGroup(s.fselect, 1, g:GetCount(), tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local rg = g:SelectSubGroup(tp, s.fselect, false, 1, g:GetCount(), tp)
  	local ct = rg:GetSum(Card.GetLink)
  	e:SetLabel(ct)
  	local tct = 1
  	if Duel.GetTurnPlayer() == tp and Duel.GetCurrentPhase() == PHASE_STANDBY then
  		tct = 2
  	end
  	local tc = rg:GetFirst()
  	while tc do
  		if Duel.Remove(tc, 0, REASON_COST + REASON_TEMPORARY) ~= 0 then
  			tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_STANDBY + RESET_SELF_TURN, 0, tct)
  		end
  		tc = rg:GetNext()
  	end
  	rg:KeepAlive()
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e1:SetCode(EVENT_PHASE + PHASE_STANDBY)
  	e1:SetCountLimit(1)
  	e1:SetLabelObject(rg)
  	e1:SetCondition(s.retcon)
  	e1:SetOperation(s.retop)
  	if Duel.GetTurnPlayer() == tp and Duel.GetCurrentPhase() == PHASE_STANDBY then
  		e1:SetReset(RESET_PHASE + PHASE_STANDBY + RESET_SELF_TURN, 2)
  		e1:SetValue(Duel.GetTurnCount())
  	else
  		e1:SetReset(RESET_PHASE + PHASE_STANDBY + RESET_SELF_TURN)
  		e1:SetValue(0)
  	end
  	Duel.RegisterEffect(e1, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  end
  function s.retfilter(c)
  	return c:GetFlagEffect(id) ~= 0
  end
  function s.retcon(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetTurnPlayer() ~= tp or Duel.GetTurnCount() == e:GetValue() then
  		return false
  	end
  	return e:GetLabelObject():IsExists(s.retfilter, 1, nil)
  end
  function s.retop(e, tp, eg, ep, ev, re, r, rp)
  	local g = e:GetLabelObject():Filter(s.retfilter, nil)
  	local tc = g:GetFirst()
  	while tc do
  		Duel.ReturnToField(tc)
  		tc = g:GetNext()
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	local ct = e:GetLabel()
  	if tc:IsFaceup() and tc:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetValue(ct * 300)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	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
  
  