name: Transforming
card_text: Once per turn: You can target 1 face-up Defense Position monster your opponent controls; discard 1 card and equip that target to this card. (You can only equip 1 monster at a time to this card with this effect.) This card gains the ATK of the equipped monster. If this card attacks, it is changed to Defense Position at the end of the Battle Phase. During the End Phase: The monster equipped to this card by this card's effect is Special Summoned to your opponent's side of the field in face-up Defense Position.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--equip
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_HANDES + CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1)
  	e1:SetCondition(s.eqcon)
  	e1:SetTarget(s.eqtg)
  	e1:SetOperation(s.eqop)
  	c:RegisterEffect(e1)
  	--to defense
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EVENT_PHASE + PHASE_BATTLE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.poscon)
  	e2:SetOperation(s.posop)
  	c:RegisterEffect(e2)
  	--spsummon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e3:SetCode(EVENT_PHASE + PHASE_END)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.spcon)
  	e3:SetTarget(s.sptg)
  	e3:SetOperation(s.spop)
  	e3:SetLabelObject(e1)
  	c:RegisterEffect(e3)
  end
  function s.eqcon(e, tp, eg, ep, ev, re, r, rp)
  	return not e:GetHandler():IsHasEffect(id)
  end
  function s.filter(c)
  	return c:IsPosition(POS_FACEUP_DEFENSE) and c:IsAbleToChangeControler()
  end
  function s.eqtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.GetFieldGroup(tp, LOCATION_HAND, 0) ~= 0 and Duel.IsExistingTarget(s.filter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	local g = Duel.SelectTarget(tp, s.filter, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_HANDES, nil, 0, tp, 1)
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, g, 1, 0, 0)
  end
  function s.eqlimit(e, c)
  	return e:GetOwner() == c
  end
  function s.eqop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if Duel.GetFieldGroup(tp, LOCATION_HAND, 0) == 0 then
  		return
  	end
  	Duel.DiscardHand(tp, nil, 1, 1, REASON_EFFECT + REASON_DISCARD)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		local atk = tc:GetTextAttack()
  		if atk < 0 then
  			atk = 0
  		end
  		if not Duel.Equip(tp, tc, c, false) then
  			return
  		end
  		--Add Equip limit
  		e:SetLabelObject(tc)
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetProperty(EFFECT_FLAG_OWNER_RELATE)
  		e1:SetCode(EFFECT_EQUIP_LIMIT)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		e1:SetValue(s.eqlimit)
  		tc:RegisterEffect(e1)
  		if atk > 0 then
  			local e2 = Effect.CreateEffect(c)
  			e2:SetType(EFFECT_TYPE_EQUIP)
  			e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE + EFFECT_FLAG_OWNER_RELATE + EFFECT_FLAG_SET_AVAILABLE)
  			e2:SetCode(EFFECT_UPDATE_ATTACK)
  			e2:SetReset(RESET_EVENT + RESETS_STANDARD)
  			e2:SetValue(atk)
  			tc:RegisterEffect(e2)
  		end
  		local e3 = Effect.CreateEffect(c)
  		e3:SetType(EFFECT_TYPE_EQUIP)
  		e3:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE + EFFECT_FLAG_SET_AVAILABLE)
  		e3:SetCode(id)
  		e3:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e3)
  	end
  end
  function s.poscon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetAttackedCount() > 0
  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.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsHasEffect(id)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local tc = e:GetLabelObject():GetLabelObject()
  	Duel.SetTargetCard(tc)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, tc, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.IsPlayerCanSpecialSummon(tp) then
  		if Duel.SpecialSummon(tc, 0, tp, 1 - tp, false, false, POS_FACEUP_DEFENSE) == 0 then
  			Duel.SendtoGrave(tc, REASON_EFFECT)
  		end
  	end
  end
  
  
source_text: Transforming
  Once per turn: You can target 1 face-up Defense Position monster your opponent controls; discard 1 card and equip that target to this card. (You can only equip 1 monster at a time to this card with this effect.) This card gains the ATK of the equipped monster. If this card attacks, it is changed to Defense Position at the end of the Battle Phase. During the End Phase: The monster equipped to this card by this card's effect is Special Summoned to your opponent's side of the field in face-up Defense Position.
target_text: -- Transforming
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--equip
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_HANDES + CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1)
  	e1:SetCondition(s.eqcon)
  	e1:SetTarget(s.eqtg)
  	e1:SetOperation(s.eqop)
  	c:RegisterEffect(e1)
  	--to defense
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EVENT_PHASE + PHASE_BATTLE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.poscon)
  	e2:SetOperation(s.posop)
  	c:RegisterEffect(e2)
  	--spsummon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e3:SetCode(EVENT_PHASE + PHASE_END)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.spcon)
  	e3:SetTarget(s.sptg)
  	e3:SetOperation(s.spop)
  	e3:SetLabelObject(e1)
  	c:RegisterEffect(e3)
  end
  function s.eqcon(e, tp, eg, ep, ev, re, r, rp)
  	return not e:GetHandler():IsHasEffect(id)
  end
  function s.filter(c)
  	return c:IsPosition(POS_FACEUP_DEFENSE) and c:IsAbleToChangeControler()
  end
  function s.eqtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0 and Duel.GetFieldGroup(tp, LOCATION_HAND, 0) ~= 0 and Duel.IsExistingTarget(s.filter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	local g = Duel.SelectTarget(tp, s.filter, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_HANDES, nil, 0, tp, 1)
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, g, 1, 0, 0)
  end
  function s.eqlimit(e, c)
  	return e:GetOwner() == c
  end
  function s.eqop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if Duel.GetFieldGroup(tp, LOCATION_HAND, 0) == 0 then
  		return
  	end
  	Duel.DiscardHand(tp, nil, 1, 1, REASON_EFFECT + REASON_DISCARD)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		local atk = tc:GetTextAttack()
  		if atk < 0 then
  			atk = 0
  		end
  		if not Duel.Equip(tp, tc, c, false) then
  			return
  		end
  		--Add Equip limit
  		e:SetLabelObject(tc)
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetProperty(EFFECT_FLAG_OWNER_RELATE)
  		e1:SetCode(EFFECT_EQUIP_LIMIT)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		e1:SetValue(s.eqlimit)
  		tc:RegisterEffect(e1)
  		if atk > 0 then
  			local e2 = Effect.CreateEffect(c)
  			e2:SetType(EFFECT_TYPE_EQUIP)
  			e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE + EFFECT_FLAG_OWNER_RELATE + EFFECT_FLAG_SET_AVAILABLE)
  			e2:SetCode(EFFECT_UPDATE_ATTACK)
  			e2:SetReset(RESET_EVENT + RESETS_STANDARD)
  			e2:SetValue(atk)
  			tc:RegisterEffect(e2)
  		end
  		local e3 = Effect.CreateEffect(c)
  		e3:SetType(EFFECT_TYPE_EQUIP)
  		e3:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE + EFFECT_FLAG_SET_AVAILABLE)
  		e3:SetCode(id)
  		e3:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e3)
  	end
  end
  function s.poscon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetAttackedCount() > 0
  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.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsHasEffect(id)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local tc = e:GetLabelObject():GetLabelObject()
  	Duel.SetTargetCard(tc)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, tc, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.IsPlayerCanSpecialSummon(tp) then
  		if Duel.SpecialSummon(tc, 0, tp, 1 - tp, false, false, POS_FACEUP_DEFENSE) == 0 then
  			Duel.SendtoGrave(tc, REASON_EFFECT)
  		end
  	end
  end
  
  