name: Koa'ki
card_text: During each of your End Phases, destroy this card unless you send 1 "Iron Core of Koa'ki Meiru" from your hand to the Graveyard or reveal 1 Normal Trap Card in your hand. If this card battles a LIGHT or DARK monster, any of that monster's effects that activate or apply on the field are negated during that Battle Phase, while this card remains on the field.
external_ids: local CARD_ID_0 = 36623431 --Iron Core of Koa'ki Meiru
  
lua: local CARD_ID_0 = 36623431 --Iron Core of Koa'ki Meiru
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--cost
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EVENT_PHASE + PHASE_END)
  	e1:SetCountLimit(1)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCondition(s.mtcon)
  	e1:SetOperation(s.mtop)
  	c:RegisterEffect(e1)
  	--negate
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetOperation(s.disop)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EVENT_BE_BATTLE_TARGET)
  	c:RegisterEffect(e3)
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD)
  	e4:SetCode(EFFECT_DISABLE)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e4:SetTarget(s.distg)
  	c:RegisterEffect(e4)
  	local e5 = e4:Clone()
  	e5:SetCode(EFFECT_DISABLE_EFFECT)
  	c:RegisterEffect(e5)
  end
  function s.mtcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp
  end
  function s.cfilter1(c)
  	return c:IsCode(CARD_ID_0) and c:IsAbleToGraveAsCost()
  end
  function s.cfilter2(c)
  	return c:GetType() == TYPE_TRAP and not c:IsPublic()
  end
  function s.mtop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	Duel.HintSelection(Group.FromCards(c))
  	local g1 = Duel.GetMatchingGroup(s.cfilter1, tp, LOCATION_HAND, 0, nil)
  	local g2 = Duel.GetMatchingGroup(s.cfilter2, tp, LOCATION_HAND, 0, nil)
  	local select = 2
  	if g1:GetCount() > 0 and g2:GetCount() > 0 then
  		select = Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 1), aux.Stringid(id, 2))
  	elseif g1:GetCount() > 0 then
  		select = Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 2))
  		if select == 1 then
  			select = 2
  		end
  	elseif g2:GetCount() > 0 then
  		select = Duel.SelectOption(tp, aux.Stringid(id, 1), aux.Stringid(id, 2)) + 1
  	else
  		select = Duel.SelectOption(tp, aux.Stringid(id, 2))
  		select = 2
  	end
  	if select == 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  		local g = g1:Select(tp, 1, 1, nil)
  		Duel.SendtoGrave(g, REASON_COST)
  	elseif select == 1 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONFIRM)
  		local g = g2:Select(tp, 1, 1, nil)
  		Duel.ConfirmCards(1 - tp, g)
  		Duel.ShuffleHand(tp)
  	else
  		Duel.Destroy(c, REASON_COST)
  	end
  end
  function s.disop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = c:GetBattleTarget()
  	if tc and tc:IsAttribute(ATTRIBUTE_LIGHT + ATTRIBUTE_DARK) then
  		tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_BATTLE, 0, 1)
  	end
  end
  function s.distg(e, c)
  	return c:GetFlagEffect(id) ~= 0
  end
  
  
source_text: Koa'ki
  During each of your End Phases, destroy this card unless you send 1 "Iron Core of Koa'ki Meiru" from your hand to the Graveyard or reveal 1 Normal Trap Card in your hand. If this card battles a LIGHT or DARK monster, any of that monster's effects that activate or apply on the field are negated during that Battle Phase, while this card remains on the field.
target_text: -- Koa'ki
  local CARD_ID_0 = 36623431 --Iron Core of Koa'ki Meiru
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--cost
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EVENT_PHASE + PHASE_END)
  	e1:SetCountLimit(1)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCondition(s.mtcon)
  	e1:SetOperation(s.mtop)
  	c:RegisterEffect(e1)
  	--negate
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetOperation(s.disop)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EVENT_BE_BATTLE_TARGET)
  	c:RegisterEffect(e3)
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD)
  	e4:SetCode(EFFECT_DISABLE)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e4:SetTarget(s.distg)
  	c:RegisterEffect(e4)
  	local e5 = e4:Clone()
  	e5:SetCode(EFFECT_DISABLE_EFFECT)
  	c:RegisterEffect(e5)
  end
  function s.mtcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp
  end
  function s.cfilter1(c)
  	return c:IsCode(CARD_ID_0) and c:IsAbleToGraveAsCost()
  end
  function s.cfilter2(c)
  	return c:GetType() == TYPE_TRAP and not c:IsPublic()
  end
  function s.mtop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	Duel.HintSelection(Group.FromCards(c))
  	local g1 = Duel.GetMatchingGroup(s.cfilter1, tp, LOCATION_HAND, 0, nil)
  	local g2 = Duel.GetMatchingGroup(s.cfilter2, tp, LOCATION_HAND, 0, nil)
  	local select = 2
  	if g1:GetCount() > 0 and g2:GetCount() > 0 then
  		select = Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 1), aux.Stringid(id, 2))
  	elseif g1:GetCount() > 0 then
  		select = Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 2))
  		if select == 1 then
  			select = 2
  		end
  	elseif g2:GetCount() > 0 then
  		select = Duel.SelectOption(tp, aux.Stringid(id, 1), aux.Stringid(id, 2)) + 1
  	else
  		select = Duel.SelectOption(tp, aux.Stringid(id, 2))
  		select = 2
  	end
  	if select == 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  		local g = g1:Select(tp, 1, 1, nil)
  		Duel.SendtoGrave(g, REASON_COST)
  	elseif select == 1 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONFIRM)
  		local g = g2:Select(tp, 1, 1, nil)
  		Duel.ConfirmCards(1 - tp, g)
  		Duel.ShuffleHand(tp)
  	else
  		Duel.Destroy(c, REASON_COST)
  	end
  end
  function s.disop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = c:GetBattleTarget()
  	if tc and tc:IsAttribute(ATTRIBUTE_LIGHT + ATTRIBUTE_DARK) then
  		tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_BATTLE, 0, 1)
  	end
  end
  function s.distg(e, c)
  	return c:GetFlagEffect(id) ~= 0
  end
  
  