name: Factory
card_text: Remove from play all "Morphtronic" monsters from your Graveyard. Target face-up Machine-Type monster you control gains 200 ATK for each card removed, until the End Phase.
external_ids: local SETCARD_ID_0 = 0x26 --Morphtronic
  
lua: local SETCARD_ID_0 = 0x26 --Morphtronic
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_REMOVE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter1(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemove()
  end
  function s.filter2(c)
  	return c:IsFaceup() and c:IsRace(RACE_MACHINE)
  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.filter2(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter1, tp, LOCATION_GRAVE, 0, 1, nil) and Duel.IsExistingTarget(s.filter2, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.filter2, tp, LOCATION_MZONE, 0, 1, 1, nil)
  	local rg = Duel.GetMatchingGroup(s.filter1, tp, LOCATION_GRAVE, 0, nil)
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, rg, rg:GetCount(), 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.filter1, tp, LOCATION_GRAVE, 0, nil)
  	local ct = Duel.Remove(g, POS_FACEUP, REASON_EFFECT)
  	local tc = Duel.GetFirstTarget()
  	if ct > 0 and 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 * 200)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  
  
source_text: Factory
  Remove from play all "Morphtronic" monsters from your Graveyard. Target face-up Machine-Type monster you control gains 200 ATK for each card removed, until the End Phase.
target_text: -- Factory
  local SETCARD_ID_0 = 0x26 --Morphtronic
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_REMOVE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter1(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemove()
  end
  function s.filter2(c)
  	return c:IsFaceup() and c:IsRace(RACE_MACHINE)
  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.filter2(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter1, tp, LOCATION_GRAVE, 0, 1, nil) and Duel.IsExistingTarget(s.filter2, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.filter2, tp, LOCATION_MZONE, 0, 1, 1, nil)
  	local rg = Duel.GetMatchingGroup(s.filter1, tp, LOCATION_GRAVE, 0, nil)
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, rg, rg:GetCount(), 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.filter1, tp, LOCATION_GRAVE, 0, nil)
  	local ct = Duel.Remove(g, POS_FACEUP, REASON_EFFECT)
  	local tc = Duel.GetFirstTarget()
  	if ct > 0 and 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 * 200)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  
  