name: Amphibious
card_text: 2+ Effect Monsters
  Gains 200 ATK for each Link Monster in the GYs. You can only use each of the following effects of "Amphibious Swarmship Amblowhale" once per turn.
  ● If this card is destroyed: You can target 1 Link-3 or lower monster in either GY; Special Summon it.
  ● If a Link-3 or lower monster(s) on the field is destroyed by battle or card effect while this card is in your GY: You can banish this card from your GY; destroy 1 card on the field.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--same effect send this card to grave and spsummon another card check
  	local e0 = aux.AddThisCardInGraveAlreadyCheck(c)
  	--link summon
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkType, TYPE_EFFECT), 2)
  	c:EnableReviveLimit()
  	--Atk up
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetValue(s.atkval)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_TRIGGER_O + EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--destroy
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_TRIGGER_O + EFFECT_TYPE_FIELD)
  	e3:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
  	e3:SetCode(EVENT_DESTROYED)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetLabelObject(e0)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.descon)
  	e3:SetCost(aux.bfgcost)
  	e3:SetTarget(s.destg)
  	e3:SetOperation(s.desop)
  	c:RegisterEffect(e3)
  end
  function s.atkval(e, c)
  	return Duel.GetMatchingGroupCount(Card.IsType, c:GetControler(), LOCATION_GRAVE, LOCATION_GRAVE, nil, TYPE_LINK) * 200
  end
  function s.spfilter(c, e, tp)
  	return c:IsType(TYPE_LINK) and c:IsLinkBelow(3) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and s.spfilter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.cfilter(c, se)
  	return c:IsReason(REASON_BATTLE + REASON_EFFECT) and c:IsType(TYPE_LINK) and c:IsLinkBelow(3) and c:IsPreviousLocation(LOCATION_MZONE) and (se == nil or c:GetReasonEffect() ~= se)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local se = e:GetLabelObject():GetLabelObject()
  	return eg:IsExists(s.cfilter, 1, e:GetHandler(), se)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(nil, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(nil, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(nil, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  	if g:GetCount() > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local sg = g:Select(tp, 1, 1, nil)
  		Duel.HintSelection(sg)
  		Duel.Destroy(sg, REASON_EFFECT)
  	end
  end
  
  
source_text: Amphibious
  2+ Effect Monsters
  Gains 200 ATK for each Link Monster in the GYs. You can only use each of the following effects of "Amphibious Swarmship Amblowhale" once per turn.
  ● If this card is destroyed: You can target 1 Link-3 or lower monster in either GY; Special Summon it.
  ● If a Link-3 or lower monster(s) on the field is destroyed by battle or card effect while this card is in your GY: You can banish this card from your GY; destroy 1 card on the field.
target_text: -- Amphibious
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--same effect send this card to grave and spsummon another card check
  	local e0 = aux.AddThisCardInGraveAlreadyCheck(c)
  	--link summon
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkType, TYPE_EFFECT), 2)
  	c:EnableReviveLimit()
  	--Atk up
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetValue(s.atkval)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_TRIGGER_O + EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--destroy
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_TRIGGER_O + EFFECT_TYPE_FIELD)
  	e3:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
  	e3:SetCode(EVENT_DESTROYED)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetLabelObject(e0)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.descon)
  	e3:SetCost(aux.bfgcost)
  	e3:SetTarget(s.destg)
  	e3:SetOperation(s.desop)
  	c:RegisterEffect(e3)
  end
  function s.atkval(e, c)
  	return Duel.GetMatchingGroupCount(Card.IsType, c:GetControler(), LOCATION_GRAVE, LOCATION_GRAVE, nil, TYPE_LINK) * 200
  end
  function s.spfilter(c, e, tp)
  	return c:IsType(TYPE_LINK) and c:IsLinkBelow(3) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and s.spfilter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.cfilter(c, se)
  	return c:IsReason(REASON_BATTLE + REASON_EFFECT) and c:IsType(TYPE_LINK) and c:IsLinkBelow(3) and c:IsPreviousLocation(LOCATION_MZONE) and (se == nil or c:GetReasonEffect() ~= se)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local se = e:GetLabelObject():GetLabelObject()
  	return eg:IsExists(s.cfilter, 1, e:GetHandler(), se)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(nil, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(nil, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(nil, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  	if g:GetCount() > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local sg = g:Select(tp, 1, 1, nil)
  		Duel.HintSelection(sg)
  		Duel.Destroy(sg, REASON_EFFECT)
  	end
  end
  
  