name: Chaos
card_text: Cannot be Normal Summoned/Set. Must first be Special Summoned (from your hand) by banishing 1 LIGHT and 1 DARK monster from your GY. While a Field Spell is face-up on the field, your opponent cannot target LIGHT or DARK monsters you control with card effects. You can target cards on the field, up to the number of face-up Field Spells on the field; banish them. You can only use this effect of "Chaos Daedalus" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--cannot be target
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetCondition(s.tgcon)
  	e2:SetTarget(s.target)
  	e2:SetValue(aux.tgoval)
  	c:RegisterEffect(e2)
  	--remove
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_REMOVE)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetCountLimit(1, id)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetTarget(s.rmtg)
  	e3:SetOperation(s.rmop)
  	c:RegisterEffect(e3)
  end
  function s.spcostfilter(c)
  	return c:IsAbleToRemoveAsCost() and c:IsAttribute(ATTRIBUTE_LIGHT + ATTRIBUTE_DARK)
  end
  function s.spcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	if Duel.GetMZoneCount(tp) <= 0 then
  		return false
  	end
  	local g = Duel.GetMatchingGroup(s.spcostfilter, tp, LOCATION_GRAVE, 0, nil)
  	return g:CheckSubGroup(aux.gfcheck, 2, 2, Card.IsAttribute, ATTRIBUTE_LIGHT, ATTRIBUTE_DARK)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, c)
  	local g = Duel.GetMatchingGroup(s.spcostfilter, tp, LOCATION_GRAVE, 0, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local sg = g:SelectSubGroup(tp, aux.gfcheck, true, 2, 2, Card.IsAttribute, ATTRIBUTE_LIGHT, ATTRIBUTE_DARK)
  	if sg then
  		sg:KeepAlive()
  		e:SetLabelObject(sg)
  		return true
  	else
  		return false
  	end
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp, c)
  	local sg = e:GetLabelObject()
  	Duel.Remove(sg, POS_FACEUP, REASON_SPSUMMON)
  	sg:DeleteGroup()
  end
  function s.ffilter(c)
  	return c:IsFaceup() and c:IsType(TYPE_FIELD)
  end
  function s.tgcon(e)
  	return Duel.IsExistingMatchingCard(s.ffilter, e:GetHandlerPlayer(), LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  end
  function s.target(e, c)
  	return c:IsAttribute(ATTRIBUTE_LIGHT + ATTRIBUTE_DARK)
  end
  function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local ct = Duel.GetMatchingGroupCount(s.ffilter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  	if chkc then
  		return chkc:IsOnField() and chkc:IsAbleToRemove()
  	end
  	if chk == 0 then
  		return ct > 0 and Duel.IsExistingTarget(Card.IsAbleToRemove, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectTarget(tp, Card.IsAbleToRemove, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, ct, nil)
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g, #g, 0, 0)
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if tg:GetCount() > 0 then
  		Duel.Remove(tg, POS_FACEUP, REASON_EFFECT)
  	end
  end
  
  
source_text: Chaos
  Cannot be Normal Summoned/Set. Must first be Special Summoned (from your hand) by banishing 1 LIGHT and 1 DARK monster from your GY. While a Field Spell is face-up on the field, your opponent cannot target LIGHT or DARK monsters you control with card effects. You can target cards on the field, up to the number of face-up Field Spells on the field; banish them. You can only use this effect of "Chaos Daedalus" once per turn.
target_text: -- Chaos
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--cannot be target
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetCondition(s.tgcon)
  	e2:SetTarget(s.target)
  	e2:SetValue(aux.tgoval)
  	c:RegisterEffect(e2)
  	--remove
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_REMOVE)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetCountLimit(1, id)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetTarget(s.rmtg)
  	e3:SetOperation(s.rmop)
  	c:RegisterEffect(e3)
  end
  function s.spcostfilter(c)
  	return c:IsAbleToRemoveAsCost() and c:IsAttribute(ATTRIBUTE_LIGHT + ATTRIBUTE_DARK)
  end
  function s.spcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	if Duel.GetMZoneCount(tp) <= 0 then
  		return false
  	end
  	local g = Duel.GetMatchingGroup(s.spcostfilter, tp, LOCATION_GRAVE, 0, nil)
  	return g:CheckSubGroup(aux.gfcheck, 2, 2, Card.IsAttribute, ATTRIBUTE_LIGHT, ATTRIBUTE_DARK)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, c)
  	local g = Duel.GetMatchingGroup(s.spcostfilter, tp, LOCATION_GRAVE, 0, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local sg = g:SelectSubGroup(tp, aux.gfcheck, true, 2, 2, Card.IsAttribute, ATTRIBUTE_LIGHT, ATTRIBUTE_DARK)
  	if sg then
  		sg:KeepAlive()
  		e:SetLabelObject(sg)
  		return true
  	else
  		return false
  	end
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp, c)
  	local sg = e:GetLabelObject()
  	Duel.Remove(sg, POS_FACEUP, REASON_SPSUMMON)
  	sg:DeleteGroup()
  end
  function s.ffilter(c)
  	return c:IsFaceup() and c:IsType(TYPE_FIELD)
  end
  function s.tgcon(e)
  	return Duel.IsExistingMatchingCard(s.ffilter, e:GetHandlerPlayer(), LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  end
  function s.target(e, c)
  	return c:IsAttribute(ATTRIBUTE_LIGHT + ATTRIBUTE_DARK)
  end
  function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local ct = Duel.GetMatchingGroupCount(s.ffilter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  	if chkc then
  		return chkc:IsOnField() and chkc:IsAbleToRemove()
  	end
  	if chk == 0 then
  		return ct > 0 and Duel.IsExistingTarget(Card.IsAbleToRemove, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectTarget(tp, Card.IsAbleToRemove, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, ct, nil)
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g, #g, 0, 0)
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if tg:GetCount() > 0 then
  		Duel.Remove(tg, POS_FACEUP, REASON_EFFECT)
  	end
  end
  
  