name: Metamorphortress
card_text: Activate this card by targeting 1 Level 4 or higher monster you control; Special Summon this card as an Effect Monster (Rock-Type/EARTH/Level 4/ATK 1000/DEF 1000), then equip that face-up monster to this card. (This card is also still a Trap Card.) If Summoned this way, this card gains ATK and DEF equal to the ATK of the monster equipped to it by this effect, also if it attacks, change it to Defense Position at the end of the Damage Step.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--position
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EVENT_DAMAGE_STEP_END)
  	e2:SetCondition(s.poscon)
  	e2:SetOperation(s.posop)
  	c:RegisterEffect(e2)
  	--atk
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetCode(EFFECT_UPDATE_ATTACK)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCondition(s.atkcon)
  	e3:SetValue(s.atkval)
  	e3:SetLabelObject(e1)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EFFECT_UPDATE_DEFENSE)
  	c:RegisterEffect(e4)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsLevelAbove(4)
  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.filter(chkc)
  	end
  	if chk == 0 then
  		return e:IsCostChecked()
  			and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0
  			and Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, 1, nil)
  			and Duel.IsPlayerCanSpecialSummonMonster(tp, id, 0, TYPES_EFFECT_TRAP_MONSTER, 1000, 1000, 4, RACE_ROCK, ATTRIBUTE_EARTH)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, g, 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not Duel.IsPlayerCanSpecialSummonMonster(tp, id, 0, TYPES_EFFECT_TRAP_MONSTER, 1000, 1000, 4, RACE_ROCK, ATTRIBUTE_EARTH) then
  		return
  	end
  	c:AddMonsterAttribute(TYPE_EFFECT + TYPE_TRAP)
  	if Duel.SpecialSummon(c, SUMMON_VALUE_SELF, tp, tp, true, false, POS_FACEUP) == 0 then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		Duel.BreakEffect()
  		if not Duel.Equip(tp, tc, c, false) then
  			return
  		end
  		local e4 = Effect.CreateEffect(c)
  		e4:SetType(EFFECT_TYPE_SINGLE)
  		e4:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e4:SetCode(EFFECT_EQUIP_LIMIT)
  		e4:SetReset(RESET_EVENT + RESETS_STANDARD)
  		e4:SetValue(s.eqlimit)
  		tc:RegisterEffect(e4, true)
  		e:SetLabelObject(tc)
  	end
  end
  function s.poscon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:GetSummonType() == SUMMON_TYPE_SPECIAL + SUMMON_VALUE_SELF and c == Duel.GetAttacker() and c:IsRelateToBattle()
  end
  function s.posop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsAttackPos() then
  		Duel.ChangePosition(c, POS_FACEUP_DEFENSE)
  	end
  end
  function s.atkcon(e)
  	return e:GetHandler():GetSummonType() == SUMMON_TYPE_SPECIAL + SUMMON_VALUE_SELF
  end
  function s.atkval(e, c)
  	local tc = e:GetLabelObject():GetLabelObject()
  	if not tc or tc:GetEquipTarget() ~= c then
  		return 0
  	end
  	local atk = tc:GetAttack()
  	if atk < 0 then
  		atk = 0
  	end
  	return atk
  end
  function s.eqlimit(e, c)
  	return e:GetOwner() == c
  end
  
  
source_text: Metamorphortress
  Activate this card by targeting 1 Level 4 or higher monster you control; Special Summon this card as an Effect Monster (Rock-Type/EARTH/Level 4/ATK 1000/DEF 1000), then equip that face-up monster to this card. (This card is also still a Trap Card.) If Summoned this way, this card gains ATK and DEF equal to the ATK of the monster equipped to it by this effect, also if it attacks, change it to Defense Position at the end of the Damage Step.
target_text: -- Metamorphortress
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--position
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EVENT_DAMAGE_STEP_END)
  	e2:SetCondition(s.poscon)
  	e2:SetOperation(s.posop)
  	c:RegisterEffect(e2)
  	--atk
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetCode(EFFECT_UPDATE_ATTACK)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCondition(s.atkcon)
  	e3:SetValue(s.atkval)
  	e3:SetLabelObject(e1)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EFFECT_UPDATE_DEFENSE)
  	c:RegisterEffect(e4)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsLevelAbove(4)
  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.filter(chkc)
  	end
  	if chk == 0 then
  		return e:IsCostChecked()
  			and Duel.GetLocationCount(tp, LOCATION_MZONE) > 0
  			and Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, 1, nil)
  			and Duel.IsPlayerCanSpecialSummonMonster(tp, id, 0, TYPES_EFFECT_TRAP_MONSTER, 1000, 1000, 4, RACE_ROCK, ATTRIBUTE_EARTH)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, g, 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not Duel.IsPlayerCanSpecialSummonMonster(tp, id, 0, TYPES_EFFECT_TRAP_MONSTER, 1000, 1000, 4, RACE_ROCK, ATTRIBUTE_EARTH) then
  		return
  	end
  	c:AddMonsterAttribute(TYPE_EFFECT + TYPE_TRAP)
  	if Duel.SpecialSummon(c, SUMMON_VALUE_SELF, tp, tp, true, false, POS_FACEUP) == 0 then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		Duel.BreakEffect()
  		if not Duel.Equip(tp, tc, c, false) then
  			return
  		end
  		local e4 = Effect.CreateEffect(c)
  		e4:SetType(EFFECT_TYPE_SINGLE)
  		e4:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e4:SetCode(EFFECT_EQUIP_LIMIT)
  		e4:SetReset(RESET_EVENT + RESETS_STANDARD)
  		e4:SetValue(s.eqlimit)
  		tc:RegisterEffect(e4, true)
  		e:SetLabelObject(tc)
  	end
  end
  function s.poscon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:GetSummonType() == SUMMON_TYPE_SPECIAL + SUMMON_VALUE_SELF and c == Duel.GetAttacker() and c:IsRelateToBattle()
  end
  function s.posop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsAttackPos() then
  		Duel.ChangePosition(c, POS_FACEUP_DEFENSE)
  	end
  end
  function s.atkcon(e)
  	return e:GetHandler():GetSummonType() == SUMMON_TYPE_SPECIAL + SUMMON_VALUE_SELF
  end
  function s.atkval(e, c)
  	local tc = e:GetLabelObject():GetLabelObject()
  	if not tc or tc:GetEquipTarget() ~= c then
  		return 0
  	end
  	local atk = tc:GetAttack()
  	if atk < 0 then
  		atk = 0
  	end
  	return atk
  end
  function s.eqlimit(e, c)
  	return e:GetOwner() == c
  end
  
  