name: Triamid
card_text: Once per turn: You can target 1 "Triamid" card in your Graveyard; shuffle it into the Deck, and if you do, all Rock-Type monsters you control gain 500 ATK and DEF. Once per turn, during your opponent's turn: You can target 1 "Triamid" Field Spell Card in your Field Zone; send it to the Graveyard, and if you do, activate 1 "Triamid" Field Spell Card from your Deck with a different name (this is a Quick Effect).
external_ids: local CARD_ID_0 = 4179255 --Ancient Pixie Dragon
  local SETCARD_ID_0 = 0xe2 --Triamid
  
lua: local CARD_ID_0 = 4179255 --Ancient Pixie Dragon
  local SETCARD_ID_0 = 0xe2 --Triamid
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--to deck
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_ATKCHANGE + CATEGORY_TODECK)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1)
  	e1:SetTarget(s.tdtg)
  	e1:SetOperation(s.tdop)
  	c:RegisterEffect(e1)
  	--field
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1)
  	e2:SetHintTiming(0, TIMING_END_PHASE)
  	e2:SetCondition(s.condition)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.operation)
  	c:RegisterEffect(e2)
  end
  function s.tdfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToDeck()
  end
  function s.atkfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_ROCK)
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.tdfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.tdfilter, tp, LOCATION_GRAVE, 0, 1, nil) and Duel.IsExistingMatchingCard(s.atkfilter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.tdfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, 1, 0, 0)
  end
  function s.tdop(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, SEQ_DECKSHUFFLE, REASON_EFFECT) ~= 0 and tc:IsLocation(LOCATION_DECK + LOCATION_EXTRA) then
  		local g = Duel.GetMatchingGroup(s.atkfilter, tp, LOCATION_MZONE, 0, nil)
  		local sc = g:GetFirst()
  		while sc do
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  			e1:SetCode(EFFECT_UPDATE_ATTACK)
  			e1:SetValue(500)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			sc:RegisterEffect(e1)
  			local e2 = e1:Clone()
  			e2:SetCode(EFFECT_UPDATE_DEFENSE)
  			sc:RegisterEffect(e2)
  			sc = g:GetNext()
  		end
  	end
  end
  function s.filter(c, tp, code)
  	return c:IsType(TYPE_FIELD) and c:IsSetCard(SETCARD_ID_0) and c:GetActivateEffect():IsActivatable(tp, true, true) and not c:IsCode(code)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() ~= tp
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local tc = Duel.GetFieldCard(tp, LOCATION_FZONE, 0)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return tc
  			and tc:IsFaceup()
  			and tc:IsSetCard(SETCARD_ID_0)
  			and tc:IsAbleToGrave()
  			and tc:IsCanBeEffectTarget(e)
  			and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil, tp, tc:GetCode())
  	end
  	Duel.SetTargetCard(tc)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, tc, 1, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SendtoGrave(tc, REASON_EFFECT) ~= 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  		local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil, tp, tc:GetCode())
  		if g:GetCount() > 0 then
  			local tc = g:GetFirst()
  			Duel.MoveToField(tc, tp, tp, LOCATION_FZONE, POS_FACEUP, true)
  			local te = tc:GetActivateEffect()
  			te:UseCountLimit(tp, 1, true)
  			local tep = tc:GetControler()
  			local cost = te:GetCost()
  			if cost then
  				cost(te, tep, eg, ep, ev, re, r, rp, 1)
  			end
  			Duel.RaiseEvent(tc, CARD_ID_0, te, 0, tp, tp, Duel.GetCurrentChain())
  		end
  	end
  end
  
  
source_text: Triamid
  Once per turn: You can target 1 "Triamid" card in your Graveyard; shuffle it into the Deck, and if you do, all Rock-Type monsters you control gain 500 ATK and DEF. Once per turn, during your opponent's turn: You can target 1 "Triamid" Field Spell Card in your Field Zone; send it to the Graveyard, and if you do, activate 1 "Triamid" Field Spell Card from your Deck with a different name (this is a Quick Effect).
target_text: -- Triamid
  local CARD_ID_0 = 4179255 --Ancient Pixie Dragon
  local SETCARD_ID_0 = 0xe2 --Triamid
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--to deck
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_ATKCHANGE + CATEGORY_TODECK)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1)
  	e1:SetTarget(s.tdtg)
  	e1:SetOperation(s.tdop)
  	c:RegisterEffect(e1)
  	--field
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1)
  	e2:SetHintTiming(0, TIMING_END_PHASE)
  	e2:SetCondition(s.condition)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.operation)
  	c:RegisterEffect(e2)
  end
  function s.tdfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToDeck()
  end
  function s.atkfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_ROCK)
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.tdfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.tdfilter, tp, LOCATION_GRAVE, 0, 1, nil) and Duel.IsExistingMatchingCard(s.atkfilter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.tdfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, 1, 0, 0)
  end
  function s.tdop(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, SEQ_DECKSHUFFLE, REASON_EFFECT) ~= 0 and tc:IsLocation(LOCATION_DECK + LOCATION_EXTRA) then
  		local g = Duel.GetMatchingGroup(s.atkfilter, tp, LOCATION_MZONE, 0, nil)
  		local sc = g:GetFirst()
  		while sc do
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  			e1:SetCode(EFFECT_UPDATE_ATTACK)
  			e1:SetValue(500)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			sc:RegisterEffect(e1)
  			local e2 = e1:Clone()
  			e2:SetCode(EFFECT_UPDATE_DEFENSE)
  			sc:RegisterEffect(e2)
  			sc = g:GetNext()
  		end
  	end
  end
  function s.filter(c, tp, code)
  	return c:IsType(TYPE_FIELD) and c:IsSetCard(SETCARD_ID_0) and c:GetActivateEffect():IsActivatable(tp, true, true) and not c:IsCode(code)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() ~= tp
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local tc = Duel.GetFieldCard(tp, LOCATION_FZONE, 0)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return tc
  			and tc:IsFaceup()
  			and tc:IsSetCard(SETCARD_ID_0)
  			and tc:IsAbleToGrave()
  			and tc:IsCanBeEffectTarget(e)
  			and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil, tp, tc:GetCode())
  	end
  	Duel.SetTargetCard(tc)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, tc, 1, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SendtoGrave(tc, REASON_EFFECT) ~= 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  		local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil, tp, tc:GetCode())
  		if g:GetCount() > 0 then
  			local tc = g:GetFirst()
  			Duel.MoveToField(tc, tp, tp, LOCATION_FZONE, POS_FACEUP, true)
  			local te = tc:GetActivateEffect()
  			te:UseCountLimit(tp, 1, true)
  			local tep = tc:GetControler()
  			local cost = te:GetCost()
  			if cost then
  				cost(te, tep, eg, ep, ev, re, r, rp, 1)
  			end
  			Duel.RaiseEvent(tc, CARD_ID_0, te, 0, tp, tp, Duel.GetCurrentChain())
  		end
  	end
  end
  
  