name: Karakuri
card_text: This card must attack if able. When this face-up Attack Position card is selected as an attack target, change it to Defense Position. If this card attacks, it is changed to Defense Position at the end of the Battle Phase.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--must attack
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_MUST_ATTACK)
  	c:RegisterEffect(e1)
  	--to defense
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_POSITION)
  	e3:SetType(EFFECT_TYPE_TRIGGER_F + EFFECT_TYPE_SINGLE)
  	e3:SetCode(EVENT_BE_BATTLE_TARGET)
  	e3:SetCondition(s.poscon)
  	e3:SetOperation(s.posop)
  	c:RegisterEffect(e3)
  	--to defense
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e4:SetCode(EVENT_PHASE + PHASE_BATTLE)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1)
  	e4:SetCondition(s.bpcon)
  	e4:SetOperation(s.bpop)
  	c:RegisterEffect(e4)
  end
  function s.poscon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsAttackPos()
  end
  function s.posop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsFaceup() and c:IsRelateToEffect(e) then
  		Duel.ChangePosition(c, POS_FACEUP_DEFENSE)
  	end
  end
  function s.bpcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetAttackedCount() > 0
  end
  function s.bpop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsAttackPos() then
  		Duel.ChangePosition(c, POS_FACEUP_DEFENSE)
  	end
  end
  
  
source_text: Karakuri
  This card must attack if able. When this face-up Attack Position card is selected as an attack target, change it to Defense Position. If this card attacks, it is changed to Defense Position at the end of the Battle Phase.
target_text: -- Karakuri
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--must attack
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_MUST_ATTACK)
  	c:RegisterEffect(e1)
  	--to defense
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_POSITION)
  	e3:SetType(EFFECT_TYPE_TRIGGER_F + EFFECT_TYPE_SINGLE)
  	e3:SetCode(EVENT_BE_BATTLE_TARGET)
  	e3:SetCondition(s.poscon)
  	e3:SetOperation(s.posop)
  	c:RegisterEffect(e3)
  	--to defense
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e4:SetCode(EVENT_PHASE + PHASE_BATTLE)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1)
  	e4:SetCondition(s.bpcon)
  	e4:SetOperation(s.bpop)
  	c:RegisterEffect(e4)
  end
  function s.poscon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsAttackPos()
  end
  function s.posop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsFaceup() and c:IsRelateToEffect(e) then
  		Duel.ChangePosition(c, POS_FACEUP_DEFENSE)
  	end
  end
  function s.bpcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetAttackedCount() > 0
  end
  function s.bpop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsAttackPos() then
  		Duel.ChangePosition(c, POS_FACEUP_DEFENSE)
  	end
  end
  
  