name: Maestroke
card_text: 2 Level 4 monsters
  Once per turn: You can detach 1 Xyz Material from this card, then target 1 face-up Attack Position monster your opponent controls; change it to face-down Defense Position. If a "Djinn" Xyz Monster you control would be destroyed, you can detach 1 Xyz Material from that monster instead.
external_ids: local SETCARD_ID_0 = 0x6d --Djinn
  
lua: local SETCARD_ID_0 = 0x6d --Djinn
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, nil, 4, 2)
  	c:EnableReviveLimit()
  	--pos
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_POSITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1)
  	e1:SetCost(s.poscost)
  	e1:SetTarget(s.postg)
  	e1:SetOperation(s.posop)
  	c:RegisterEffect(e1)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTarget(s.reptg)
  	e2:SetValue(s.repval)
  	e2:SetOperation(s.repop)
  	c:RegisterEffect(e2)
  end
  function s.poscost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.posfilter(c)
  	return c:IsPosition(POS_FACEUP_ATTACK) and c:IsCanTurnSet()
  end
  function s.postg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(1 - tp) and chkc:IsLocation(LOCATION_MZONE) and s.posfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.posfilter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUPATTACK)
  	local g = Duel.SelectTarget(tp, s.posfilter, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_POSITION, g, 1, 0, 0)
  end
  function s.posop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsFaceup() and tc:IsRelateToEffect(e) then
  		Duel.ChangePosition(tc, POS_FACEDOWN_DEFENSE)
  	end
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup() and c:IsControler(tp) and c:IsLocation(LOCATION_MZONE) and c:IsSetCard(SETCARD_ID_0) and c:CheckRemoveOverlayCard(tp, 1, REASON_EFFECT)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return eg:IsExists(s.repfilter, 1, nil, tp)
  	end
  	if Duel.SelectEffectYesNo(tp, e:GetHandler(), 96) then
  		local g = eg:Filter(s.repfilter, nil, tp)
  		Duel.SetTargetCard(g)
  		return true
  	else
  		return false
  	end
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local tc = g:GetFirst()
  	while tc do
  		tc:RemoveOverlayCard(tp, 1, 1, REASON_EFFECT)
  		tc = g:GetNext()
  	end
  end
  
  
source_text: Maestroke
  2 Level 4 monsters
  Once per turn: You can detach 1 Xyz Material from this card, then target 1 face-up Attack Position monster your opponent controls; change it to face-down Defense Position. If a "Djinn" Xyz Monster you control would be destroyed, you can detach 1 Xyz Material from that monster instead.
target_text: -- Maestroke
  local SETCARD_ID_0 = 0x6d --Djinn
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, nil, 4, 2)
  	c:EnableReviveLimit()
  	--pos
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_POSITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1)
  	e1:SetCost(s.poscost)
  	e1:SetTarget(s.postg)
  	e1:SetOperation(s.posop)
  	c:RegisterEffect(e1)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTarget(s.reptg)
  	e2:SetValue(s.repval)
  	e2:SetOperation(s.repop)
  	c:RegisterEffect(e2)
  end
  function s.poscost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.posfilter(c)
  	return c:IsPosition(POS_FACEUP_ATTACK) and c:IsCanTurnSet()
  end
  function s.postg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(1 - tp) and chkc:IsLocation(LOCATION_MZONE) and s.posfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.posfilter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUPATTACK)
  	local g = Duel.SelectTarget(tp, s.posfilter, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_POSITION, g, 1, 0, 0)
  end
  function s.posop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsFaceup() and tc:IsRelateToEffect(e) then
  		Duel.ChangePosition(tc, POS_FACEDOWN_DEFENSE)
  	end
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup() and c:IsControler(tp) and c:IsLocation(LOCATION_MZONE) and c:IsSetCard(SETCARD_ID_0) and c:CheckRemoveOverlayCard(tp, 1, REASON_EFFECT)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return eg:IsExists(s.repfilter, 1, nil, tp)
  	end
  	if Duel.SelectEffectYesNo(tp, e:GetHandler(), 96) then
  		local g = eg:Filter(s.repfilter, nil, tp)
  		Duel.SetTargetCard(g)
  		return true
  	else
  		return false
  	end
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local tc = g:GetFirst()
  	while tc do
  		tc:RemoveOverlayCard(tp, 1, 1, REASON_EFFECT)
  		tc = g:GetNext()
  	end
  end
  
  