name: Triple
card_text: If your opponent has activated a monster effect during your Main Phase this turn: Activate 1 of these effects;
  ● Draw 2 cards.
  ● Take control of 1 monster your opponent controls until the End Phase.
  ● Look at your opponent's hand, and choose 1 card from it to shuffle into the Deck.
  You can only activate 1 "Triple Tactics Talent" per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	c:RegisterEffect(e1)
  	Duel.AddCustomActivityCounter(id, ACTIVITY_CHAIN, s.chainfilter)
  end
  function s.chainfilter(re, tp, cid)
  	local ph = Duel.GetCurrentPhase()
  	return not (re:IsActiveType(TYPE_MONSTER) and (ph == PHASE_MAIN1 or ph == PHASE_MAIN2))
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCustomActivityCount(id, 1 - tp, ACTIVITY_CHAIN) ~= 0
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local b1 = Duel.IsPlayerCanDraw(tp, 2)
  	local b2 = Duel.IsExistingMatchingCard(Card.IsControlerCanBeChanged, tp, 0, LOCATION_MZONE, 1, nil)
  	local b3 = Duel.GetFieldGroupCount(tp, 0, LOCATION_HAND) > 0
  	if chk == 0 then
  		return b1 or b2 or b3
  	end
  	local off = 1
  	local ops = {}
  	local opval = {}
  	if b1 then
  		ops[off] = aux.Stringid(id, 0)
  		opval[off - 1] = 1
  		off = off + 1
  	end
  	if b2 then
  		ops[off] = aux.Stringid(id, 1)
  		opval[off - 1] = 2
  		off = off + 1
  	end
  	if b3 then
  		ops[off] = aux.Stringid(id, 2)
  		opval[off - 1] = 3
  		off = off + 1
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EFFECT)
  	local op = Duel.SelectOption(tp, table.unpack(ops))
  	if opval[op] == 1 then
  		e:SetCategory(CATEGORY_DRAW)
  		e:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		e:SetOperation(s.draw)
  		Duel.SetTargetPlayer(tp)
  		Duel.SetTargetParam(2)
  		Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 2)
  	elseif opval[op] == 2 then
  		e:SetCategory(CATEGORY_CONTROL)
  		e:SetProperty(0)
  		e:SetOperation(s.control)
  		local g = Duel.GetFieldGroup(tp, 0, LOCATION_MZONE):Filter(Card.IsControlerCanBeChanged, nil)
  		Duel.SetOperationInfo(0, CATEGORY_CONTROL, g, 1, 0, 0)
  	elseif opval[op] == 3 then
  		e:SetCategory(CATEGORY_TODECK)
  		e:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		e:SetOperation(s.todeck)
  		Duel.SetTargetPlayer(tp)
  		Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 0, 1 - tp, LOCATION_HAND)
  	end
  end
  function s.draw(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Draw(p, d, REASON_EFFECT)
  end
  function s.control(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONTROL)
  	local g = Duel.SelectMatchingCard(tp, Card.IsControlerCanBeChanged, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	if #g > 0 then
  		Duel.HintSelection(g)
  		Duel.GetControl(g:GetFirst(), tp, PHASE_END, 1)
  	end
  end
  function s.todeck(e, tp, eg, ep, ev, re, r, rp)
  	local p = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER)
  	local g = Duel.GetFieldGroup(p, 0, LOCATION_HAND)
  	if #g > 0 then
  		Duel.ConfirmCards(p, g)
  		Duel.Hint(HINT_SELECTMSG, p, HINTMSG_TODECK)
  		local sg = g:FilterSelect(p, Card.IsAbleToDeck, 1, 1, nil)
  		if #sg <= 0 then
  			return
  		end
  		Duel.SendtoDeck(sg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  		Duel.ShuffleHand(1 - p)
  	end
  end
  
  
source_text: Triple
  If your opponent has activated a monster effect during your Main Phase this turn: Activate 1 of these effects;
  ● Draw 2 cards.
  ● Take control of 1 monster your opponent controls until the End Phase.
  ● Look at your opponent's hand, and choose 1 card from it to shuffle into the Deck.
  You can only activate 1 "Triple Tactics Talent" per turn.
target_text: -- Triple
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	c:RegisterEffect(e1)
  	Duel.AddCustomActivityCounter(id, ACTIVITY_CHAIN, s.chainfilter)
  end
  function s.chainfilter(re, tp, cid)
  	local ph = Duel.GetCurrentPhase()
  	return not (re:IsActiveType(TYPE_MONSTER) and (ph == PHASE_MAIN1 or ph == PHASE_MAIN2))
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCustomActivityCount(id, 1 - tp, ACTIVITY_CHAIN) ~= 0
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local b1 = Duel.IsPlayerCanDraw(tp, 2)
  	local b2 = Duel.IsExistingMatchingCard(Card.IsControlerCanBeChanged, tp, 0, LOCATION_MZONE, 1, nil)
  	local b3 = Duel.GetFieldGroupCount(tp, 0, LOCATION_HAND) > 0
  	if chk == 0 then
  		return b1 or b2 or b3
  	end
  	local off = 1
  	local ops = {}
  	local opval = {}
  	if b1 then
  		ops[off] = aux.Stringid(id, 0)
  		opval[off - 1] = 1
  		off = off + 1
  	end
  	if b2 then
  		ops[off] = aux.Stringid(id, 1)
  		opval[off - 1] = 2
  		off = off + 1
  	end
  	if b3 then
  		ops[off] = aux.Stringid(id, 2)
  		opval[off - 1] = 3
  		off = off + 1
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EFFECT)
  	local op = Duel.SelectOption(tp, table.unpack(ops))
  	if opval[op] == 1 then
  		e:SetCategory(CATEGORY_DRAW)
  		e:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		e:SetOperation(s.draw)
  		Duel.SetTargetPlayer(tp)
  		Duel.SetTargetParam(2)
  		Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 2)
  	elseif opval[op] == 2 then
  		e:SetCategory(CATEGORY_CONTROL)
  		e:SetProperty(0)
  		e:SetOperation(s.control)
  		local g = Duel.GetFieldGroup(tp, 0, LOCATION_MZONE):Filter(Card.IsControlerCanBeChanged, nil)
  		Duel.SetOperationInfo(0, CATEGORY_CONTROL, g, 1, 0, 0)
  	elseif opval[op] == 3 then
  		e:SetCategory(CATEGORY_TODECK)
  		e:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		e:SetOperation(s.todeck)
  		Duel.SetTargetPlayer(tp)
  		Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 0, 1 - tp, LOCATION_HAND)
  	end
  end
  function s.draw(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Draw(p, d, REASON_EFFECT)
  end
  function s.control(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONTROL)
  	local g = Duel.SelectMatchingCard(tp, Card.IsControlerCanBeChanged, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	if #g > 0 then
  		Duel.HintSelection(g)
  		Duel.GetControl(g:GetFirst(), tp, PHASE_END, 1)
  	end
  end
  function s.todeck(e, tp, eg, ep, ev, re, r, rp)
  	local p = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER)
  	local g = Duel.GetFieldGroup(p, 0, LOCATION_HAND)
  	if #g > 0 then
  		Duel.ConfirmCards(p, g)
  		Duel.Hint(HINT_SELECTMSG, p, HINTMSG_TODECK)
  		local sg = g:FilterSelect(p, Card.IsAbleToDeck, 1, 1, nil)
  		if #sg <= 0 then
  			return
  		end
  		Duel.SendtoDeck(sg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  		Duel.ShuffleHand(1 - p)
  	end
  end
  
  