name: 義賊の極意書
card_text: 自分フィールド上の通常モンスター1体を選択して発動できる。
  このターン選択したモンスターが相手ライフに戦闘ダメージを与えた時、相手の手札をランダムに2枚捨てる。
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsType(TYPE_NORMAL)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() and not tc:IsImmuneToEffect(e) then
  		tc:RegisterFlagEffect(id, RESET_EVENT + 0x1220000 + RESET_PHASE + PHASE_END, 0, 1)
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetDescription(aux.Stringid(id, 0))
  		e1:SetCategory(CATEGORY_HANDES)
  		e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  		e1:SetCode(EVENT_BATTLE_DAMAGE)
  		e1:SetLabelObject(tc)
  		e1:SetCondition(s.hdcon)
  		e1:SetTarget(s.hdtg)
  		e1:SetOperation(s.hdop)
  		e1:SetReset(RESET_PHASE + PHASE_END)
  		Duel.RegisterEffect(e1, tp)
  	end
  end
  function s.hdcon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	return ep ~= tp and eg:IsContains(tc) and tc:GetFlagEffect(id) ~= 0
  end
  function s.hdtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetOperationInfo(0, CATEGORY_HANDES, nil, 0, 1 - tp, 2)
  end
  function s.hdop(e, tp, eg, ep, ev, re, r, rp)
  	local p = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER)
  	local g = Duel.GetFieldGroup(p, 0, LOCATION_HAND)
  	local dg = g:RandomSelect(tp, 2)
  	Duel.SendtoGrave(dg, REASON_EFFECT + REASON_DISCARD)
  end
  
  
source_text: 義賊の極意書
  自分フィールド上の通常モンスター1体を選択して発動できる。
  このターン選択したモンスターが相手ライフに戦闘ダメージを与えた時、相手の手札をランダムに2枚捨てる。
target_text: -- 義賊の極意書
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsType(TYPE_NORMAL)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() and not tc:IsImmuneToEffect(e) then
  		tc:RegisterFlagEffect(id, RESET_EVENT + 0x1220000 + RESET_PHASE + PHASE_END, 0, 1)
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetDescription(aux.Stringid(id, 0))
  		e1:SetCategory(CATEGORY_HANDES)
  		e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  		e1:SetCode(EVENT_BATTLE_DAMAGE)
  		e1:SetLabelObject(tc)
  		e1:SetCondition(s.hdcon)
  		e1:SetTarget(s.hdtg)
  		e1:SetOperation(s.hdop)
  		e1:SetReset(RESET_PHASE + PHASE_END)
  		Duel.RegisterEffect(e1, tp)
  	end
  end
  function s.hdcon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = e:GetLabelObject()
  	return ep ~= tp and eg:IsContains(tc) and tc:GetFlagEffect(id) ~= 0
  end
  function s.hdtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetOperationInfo(0, CATEGORY_HANDES, nil, 0, 1 - tp, 2)
  end
  function s.hdop(e, tp, eg, ep, ev, re, r, rp)
  	local p = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER)
  	local g = Duel.GetFieldGroup(p, 0, LOCATION_HAND)
  	local dg = g:RandomSelect(tp, 2)
  	Duel.SendtoGrave(dg, REASON_EFFECT + REASON_DISCARD)
  end
  
  