--[决斗编年史]遗言之札
function c20049999.initial_effect(c)
	if not c20049999.reg then
		c20049999.reg = true
		local orig = Card.RegisterEffect
		Card.RegisterEffect = function(c,e,...)
			if e:GetCode()==EFFECT_UPDATE_ATTACK or e:GetCode()==EFFECT_SET_ATTACK_FINAL then
				local v=e:GetValue()
				if aux.GetValueType(v)=="function" then
					local newv = function(e,c)
						local val = v(e,c)
						if c:GetAttack()>0 and val == 0 then Duel.RaiseEvent(EVENT_CUSTOM+20049999) end
						return val
					end
					e:SetValue(newv)
					orig(c,e,...)
				elseif c:GetAttack()>0 and ((e:GetCode()==EFFECT_SET_ATTACK_FINAL and val == 0) or (e:GetCode()==EFFECT_UPDATE_ATTACK and c:GetAttack() + val == 0)) then
					Duel.RaiseEvent(EVENT_CUSTOM+20049999)
					orig(c,e,...)
				end
			end
		end
	end
	local e1=Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(20049999,1))
	e1:SetCategory(CATEGORY_DRAW)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_CUSTOM+20049999)
	e1:SetProperty(EFFECT_FLAG_DELAY)
	e1:SetTarget(c20049999.drtg)
	e1:SetOperation(c20049999.drop)
	c:RegisterEffect(e1)
end
function c20049999.drtg(e,tp,eg,ep,ev,re,r,rp,chk)
	local cnt=Duel.GetCardsInZone(tp,LOCATION_HAND):GetCount()
	if chk==0 then return cnt>=5 or not Duel.IsPlayerCanDraw(tp,5-cnt) end
	Duel.SetOperationInfo(0,CATEGORY_DRAW,nil,0,tp,5-cnt)
end
function c20049999.drop(e,tp,eg,ep,ev,re,r,rp)
	local cnt=5-Duel.GetCardsInZone(tp,LOCATION_HAND):GetCount()
	local _,_,_,p=Duel.GetOperationInfo(0,CATEGORY_DRAW)
	Duel.Draw(p,cnt,REASON_EFFECT)
end
