name: Chain
card_text: Any time you Fusion Summon a monster this turn, you can remove from play, from your side of the field, Deck, hand or Graveyard, Fusion Material Monsters that are listed on the Fusion Monster Card, and use them as Fusion Material Monsters. You cannot attack during the turn this card is activated. If you used this effect for a Fusion Summon, the Summoned Fusion Monster(s) is destroyed during the End Phase.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetActivityCount(tp, ACTIVITY_ATTACK) == 0
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_ATTACK)
  	e1:SetProperty(EFFECT_FLAG_OATH + EFFECT_FLAG_IGNORE_IMMUNE)
  	e1:SetTargetRange(LOCATION_MZONE, 0)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:IsHasType(EFFECT_TYPE_ACTIVATE)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CHAIN_MATERIAL)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetTargetRange(1, 0)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	e1:SetTarget(s.chain_target)
  	e1:SetOperation(s.chain_operation)
  	e1:SetValue(aux.TRUE)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.filter(c, e)
  	return c:IsType(TYPE_MONSTER) and c:IsCanBeFusionMaterial() and c:IsAbleToRemove() and not c:IsImmuneToEffect(e)
  end
  function s.chain_target(e, te, tp)
  	return Duel.GetMatchingGroup(s.filter, tp, LOCATION_ONFIELD + LOCATION_GRAVE + LOCATION_HAND + LOCATION_DECK, 0, nil, te)
  end
  function s.chain_operation(e, te, tp, tc, mat, sumtype, sumpos)
  	if not sumtype then
  		sumtype = SUMMON_TYPE_FUSION
  	end
  	tc:SetMaterial(mat)
  	Duel.Remove(mat, POS_FACEUP, REASON_EFFECT + REASON_MATERIAL + REASON_FUSION)
  	Duel.BreakEffect()
  	Duel.SpecialSummonStep(tc, sumtype, tp, tp, false, false, sumpos)
  	tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD - RESET_TURN_SET, 0, 1)
  	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_END)
  	e1:SetLabelObject(tc)
  	e1:SetCondition(s.descon)
  	e1:SetOperation(s.desop)
  	e1:SetCountLimit(1)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	if tc:GetFlagEffect(id) ~= 0 then
  		return true
  	else
  		e:Reset()
  		return false
  	end
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	Duel.Destroy(tc, REASON_EFFECT)
  end
  
  
source_text: Chain
  Any time you Fusion Summon a monster this turn, you can remove from play, from your side of the field, Deck, hand or Graveyard, Fusion Material Monsters that are listed on the Fusion Monster Card, and use them as Fusion Material Monsters. You cannot attack during the turn this card is activated. If you used this effect for a Fusion Summon, the Summoned Fusion Monster(s) is destroyed during the End Phase.
target_text: -- Chain
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetActivityCount(tp, ACTIVITY_ATTACK) == 0
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_ATTACK)
  	e1:SetProperty(EFFECT_FLAG_OATH + EFFECT_FLAG_IGNORE_IMMUNE)
  	e1:SetTargetRange(LOCATION_MZONE, 0)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:IsHasType(EFFECT_TYPE_ACTIVATE)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CHAIN_MATERIAL)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetTargetRange(1, 0)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	e1:SetTarget(s.chain_target)
  	e1:SetOperation(s.chain_operation)
  	e1:SetValue(aux.TRUE)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.filter(c, e)
  	return c:IsType(TYPE_MONSTER) and c:IsCanBeFusionMaterial() and c:IsAbleToRemove() and not c:IsImmuneToEffect(e)
  end
  function s.chain_target(e, te, tp)
  	return Duel.GetMatchingGroup(s.filter, tp, LOCATION_ONFIELD + LOCATION_GRAVE + LOCATION_HAND + LOCATION_DECK, 0, nil, te)
  end
  function s.chain_operation(e, te, tp, tc, mat, sumtype, sumpos)
  	if not sumtype then
  		sumtype = SUMMON_TYPE_FUSION
  	end
  	tc:SetMaterial(mat)
  	Duel.Remove(mat, POS_FACEUP, REASON_EFFECT + REASON_MATERIAL + REASON_FUSION)
  	Duel.BreakEffect()
  	Duel.SpecialSummonStep(tc, sumtype, tp, tp, false, false, sumpos)
  	tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD - RESET_TURN_SET, 0, 1)
  	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_END)
  	e1:SetLabelObject(tc)
  	e1:SetCondition(s.descon)
  	e1:SetOperation(s.desop)
  	e1:SetCountLimit(1)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	if tc:GetFlagEffect(id) ~= 0 then
  		return true
  	else
  		e:Reset()
  		return false
  	end
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	Duel.Destroy(tc, REASON_EFFECT)
  end
  
  