name: Owner's
card_text: Return control of all monsters on the field to their owners.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	Duel.EnableGlobalFlag(GLOBALFLAG_BRAINWASHING_CHECK)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_CONTROL)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:GetControler() ~= c:GetOwner()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetFieldGroup(tp, LOCATION_MZONE, LOCATION_MZONE)
  	local tg = Group.CreateGroup()
  	local tc = g:GetFirst()
  	while tc do
  		if not tc:IsImmuneToEffect(e) and tc:GetFlagEffect(id) == 0 then
  			tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1)
  			tg:AddCard(tc)
  		end
  		tc = g:GetNext()
  	end
  	tg:KeepAlive()
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_REMOVE_BRAINWASHING)
  	e1:SetProperty(EFFECT_FLAG_SET_AVAILABLE)
  	e1:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e1:SetTarget(aux.TargetEqualFunction(Card.GetFlagEffect, 1, id))
  	e1:SetLabelObject(tg)
  	Duel.RegisterEffect(e1, tp)
  	--force adjust
  	local e2 = Effect.CreateEffect(e:GetHandler())
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EVENT_CHAIN_SOLVED)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetLabelObject(e1)
  	Duel.RegisterEffect(e2, tp)
  	--reset
  	local e3 = Effect.CreateEffect(e:GetHandler())
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EVENT_CHAIN_SOLVED)
  	e3:SetLabelObject(e2)
  	e3:SetLabel(Duel.GetChainInfo(0, CHAININFO_CHAIN_ID))
  	e3:SetOperation(s.reset)
  	Duel.RegisterEffect(e3, tp)
  end
  function s.reset(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetChainInfo(ev, CHAININFO_CHAIN_ID) == e:GetLabel() then
  		local e2 = e:GetLabelObject()
  		local e1 = e2:GetLabelObject()
  		local tg = e1:GetLabelObject()
  		for tc in aux.Next(tg) do
  			tc:ResetFlagEffect(id)
  		end
  		tg:DeleteGroup()
  		e1:Reset()
  		e2:Reset()
  		e:Reset()
  	end
  end
  
  
source_text: Owner's
  Return control of all monsters on the field to their owners.
target_text: -- Owner's
  local s, id, o = GetID()
  function s.initial_effect(c)
  	Duel.EnableGlobalFlag(GLOBALFLAG_BRAINWASHING_CHECK)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_CONTROL)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:GetControler() ~= c:GetOwner()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetFieldGroup(tp, LOCATION_MZONE, LOCATION_MZONE)
  	local tg = Group.CreateGroup()
  	local tc = g:GetFirst()
  	while tc do
  		if not tc:IsImmuneToEffect(e) and tc:GetFlagEffect(id) == 0 then
  			tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, 0, 1)
  			tg:AddCard(tc)
  		end
  		tc = g:GetNext()
  	end
  	tg:KeepAlive()
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_REMOVE_BRAINWASHING)
  	e1:SetProperty(EFFECT_FLAG_SET_AVAILABLE)
  	e1:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e1:SetTarget(aux.TargetEqualFunction(Card.GetFlagEffect, 1, id))
  	e1:SetLabelObject(tg)
  	Duel.RegisterEffect(e1, tp)
  	--force adjust
  	local e2 = Effect.CreateEffect(e:GetHandler())
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EVENT_CHAIN_SOLVED)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetLabelObject(e1)
  	Duel.RegisterEffect(e2, tp)
  	--reset
  	local e3 = Effect.CreateEffect(e:GetHandler())
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EVENT_CHAIN_SOLVED)
  	e3:SetLabelObject(e2)
  	e3:SetLabel(Duel.GetChainInfo(0, CHAININFO_CHAIN_ID))
  	e3:SetOperation(s.reset)
  	Duel.RegisterEffect(e3, tp)
  end
  function s.reset(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetChainInfo(ev, CHAININFO_CHAIN_ID) == e:GetLabel() then
  		local e2 = e:GetLabelObject()
  		local e1 = e2:GetLabelObject()
  		local tg = e1:GetLabelObject()
  		for tc in aux.Next(tg) do
  			tc:ResetFlagEffect(id)
  		end
  		tg:DeleteGroup()
  		e1:Reset()
  		e2:Reset()
  		e:Reset()
  	end
  end
  
  