name: Amorphage
card_text: All monsters on the field, except "Amorphage" monsters, lose 100 ATK and DEF for each "Amorphage" card on the field. If a card(s) in your Pendulum Zone is destroyed (except during the Damage Step): You can place 1 "Amorphage" Pendulum Monster from your Deck in your Pendulum Zone. You can only use this effect of "Amorphage Lysis" once per turn.
external_ids: local SETCARD_ID_0 = 0xe0 --Amorphage
  
lua: local SETCARD_ID_0 = 0xe0 --Amorphage
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e0 = Effect.CreateEffect(c)
  	e0:SetDescription(aux.Stringid(id, 0))
  	e0:SetType(EFFECT_TYPE_ACTIVATE)
  	e0:SetCode(EVENT_FREE_CHAIN)
  	e0:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e0:SetHintTiming(TIMING_DAMAGE_STEP)
  	e0:SetCondition(aux.dscon)
  	c:RegisterEffect(e0)
  	--set p
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.setcon)
  	e2:SetTarget(s.settg)
  	e2:SetOperation(s.setop)
  	c:RegisterEffect(e2)
  	--atk/def down
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e3:SetCode(EFFECT_UPDATE_ATTACK)
  	e3:SetTarget(s.atktg)
  	e3:SetValue(s.atkval)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EFFECT_UPDATE_DEFENSE)
  	c:RegisterEffect(e4)
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousLocation(LOCATION_PZONE) and c:IsPreviousControler(tp)
  end
  function s.setcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_PENDULUM) and not c:IsForbidden()
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return (Duel.CheckLocation(tp, LOCATION_PZONE, 0) or Duel.CheckLocation(tp, LOCATION_PZONE, 1)) and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not (Duel.CheckLocation(tp, LOCATION_PZONE, 0) or Duel.CheckLocation(tp, LOCATION_PZONE, 1)) then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if tc then
  		Duel.MoveToField(tc, tp, tp, LOCATION_PZONE, POS_FACEUP, true)
  	end
  end
  function s.atktg(e, c)
  	return not c:IsSetCard(SETCARD_ID_0)
  end
  function s.vfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.atkval(e, c)
  	return Duel.GetMatchingGroupCount(s.vfilter, 0, LOCATION_ONFIELD, LOCATION_ONFIELD, nil) * -100
  end
  
  
source_text: Amorphage
  All monsters on the field, except "Amorphage" monsters, lose 100 ATK and DEF for each "Amorphage" card on the field. If a card(s) in your Pendulum Zone is destroyed (except during the Damage Step): You can place 1 "Amorphage" Pendulum Monster from your Deck in your Pendulum Zone. You can only use this effect of "Amorphage Lysis" once per turn.
target_text: -- Amorphage
  local SETCARD_ID_0 = 0xe0 --Amorphage
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e0 = Effect.CreateEffect(c)
  	e0:SetDescription(aux.Stringid(id, 0))
  	e0:SetType(EFFECT_TYPE_ACTIVATE)
  	e0:SetCode(EVENT_FREE_CHAIN)
  	e0:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e0:SetHintTiming(TIMING_DAMAGE_STEP)
  	e0:SetCondition(aux.dscon)
  	c:RegisterEffect(e0)
  	--set p
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.setcon)
  	e2:SetTarget(s.settg)
  	e2:SetOperation(s.setop)
  	c:RegisterEffect(e2)
  	--atk/def down
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e3:SetCode(EFFECT_UPDATE_ATTACK)
  	e3:SetTarget(s.atktg)
  	e3:SetValue(s.atkval)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EFFECT_UPDATE_DEFENSE)
  	c:RegisterEffect(e4)
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousLocation(LOCATION_PZONE) and c:IsPreviousControler(tp)
  end
  function s.setcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_PENDULUM) and not c:IsForbidden()
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return (Duel.CheckLocation(tp, LOCATION_PZONE, 0) or Duel.CheckLocation(tp, LOCATION_PZONE, 1)) and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not (Duel.CheckLocation(tp, LOCATION_PZONE, 0) or Duel.CheckLocation(tp, LOCATION_PZONE, 1)) then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if tc then
  		Duel.MoveToField(tc, tp, tp, LOCATION_PZONE, POS_FACEUP, true)
  	end
  end
  function s.atktg(e, c)
  	return not c:IsSetCard(SETCARD_ID_0)
  end
  function s.vfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.atkval(e, c)
  	return Duel.GetMatchingGroupCount(s.vfilter, 0, LOCATION_ONFIELD, LOCATION_ONFIELD, nil) * -100
  end
  
  