红月私服冲千前三名自动发送奖励设置

CREATE PROCEDURE RMS_LEVEL1000MAIL 
@GameID varchar(14), 
@Time datetime 
AS 

set nocount on 
declare @MailCount int, @InsertMailError int, @InsertTickError int , 

@level int , @face int,@WindowKind int,@WindowIndex int, 
@permission int,@isFirst int,@Time2 dateTime,@itemNum int,@itemNum2 

int,@itemNum3 int,@randIndex int 
set @MailCount = 0 
set @InsertMailError = 1 
set @InsertTickError = 1 
begin transaction 
select @MailCount = count(*) from tblMail1 where Recipient = @GameID 

and Time = @Time 
while @MailCount > 0 
begin 

set @MailCount = 0 
set @Time = dateadd(second, 1, @Time) 
select @MailCount = count(*) from tblMail1 where Recipient = @GameID 

and Time = @Time 
end 


select @InsertMailError = @@ERROR 
select @Level=lvl from tblGameID1 where @GameID=GameID 
select @Time2 = CONVERT(varchar, getdate(), 120) 
begin 
select @face=face from tblGameID1 where @GameID=GameID 
select @isFirst = count(*) from tblGameID1 where lvl=1000 
if @isFirst = 1 
BEGIN 
insert tblMail1 (Time, Recipient, Sender, ReadOrNot, Title, Line, 

Content, Item) values(@Time, @GameID, '[红月私服(www.2019xz.com)]', 0, '红月冲级奖励

', 20, '您好! 
祝贺您夺得冲级奖励总排行第一名,这是您的奖励,请查收! 
感谢您对红月的支持', '') 
set @itemNum2 =0 
while @itemNum2<500 
BEGIN 
insert tblSpecialItem1 (ItemKind, ItemIndex, ItemDurability, 

Position, Map, X, Y, TileKind, GameID, WindowKind, WindowIndex, 

MiscTime, AttackGrade, StrengthGrade, SpiritGrade, DexterityGrade, 

PowerGrade) values (6, 200, 4, 2, 1, 100, 100, 1, @GameID, 100, 0, 

@Time, 0,0,0,0,0) 
set @itemNum2 = @itemNum2+1 
END 

END 
else if @isFirst = 2 
BEGIN 
insert tblMail1 (Time, Recipient, Sender, ReadOrNot, Title, Line, 

Content, Item) values(@Time, @GameID, '[红月私服(www.2019xz.com)]', 0, '红月冲级奖励

', 20, '您好! 
祝贺您夺得冲级奖励总排行第二名,这是您的奖励,请查收! 
感谢您对红月的支持', '') 
set @itemNum2 =0 
while @itemNum2<400 
BEGIN 
insert tblSpecialItem1 (ItemKind, ItemIndex, ItemDurability, 

Position, Map, X, Y, TileKind, GameID, WindowKind, WindowIndex, 

MiscTime, AttackGrade, StrengthGrade, SpiritGrade, DexterityGrade, 

PowerGrade) values (6, 200, 4, 2, 1, 100, 100, 1, @GameID, 100, 0, 

@Time, 0,0,0,0,0) 
set @itemNum2 = @itemNum2+1 
END 

END 
else if @isFirst = 3 
BEGIN 
insert tblMail1 (Time, Recipient, Sender, ReadOrNot, Title, Line, 

Content, Item) values(@Time, @GameID, '[红月私服(www.2019xz.com)]', 0, '红月冲级奖励

', 20, '您好! 
祝贺您夺得冲级奖励总排行第三名,这是您的奖励,请查收! 
感谢您对红月的支持', '') 
set @itemNum2 =0 
while @itemNum2<300 
BEGIN 
insert tblSpecialItem1 (ItemKind, ItemIndex, ItemDurability, 

Position, Map, X, Y, TileKind, GameID, WindowKind, WindowIndex, 

MiscTime, AttackGrade, StrengthGrade, SpiritGrade, DexterityGrade, 

PowerGrade) values (6, 200, 4, 2, 1, 100, 100, 1, @GameID, 100, 0, 

@Time, 0,0,0,0,0) 
set @itemNum2 = @itemNum2+1 
END 

END 
else 
BEGIN 
select @isFirst = count(*) from tblGameID1 where lvl=1000 and face= 

@face 
if @isFirst = 1 
BEGIN 
insert tblMail1 (Time, Recipient, Sender, ReadOrNot, Title, Line, 

Content, Item) values(@Time, @GameID, '[红月私服(www.2019xz.com)]', 0, '红月冲级奖励

', 20, '您好! 
祝贺您夺得冲级奖励角色第一名,这是您的奖励,请查收! 
感谢您对红月的支持', '') 
set @itemNum3 =0 
while @itemNum3<200 
BEGIN 
insert tblSpecialItem1 (ItemKind, ItemIndex, ItemDurability, 

Position, Map, X, Y, TileKind, GameID, WindowKind, WindowIndex, 

MiscTime, AttackGrade, StrengthGrade, SpiritGrade, DexterityGrade, 

PowerGrade) values (6, 200, 4, 2, 1, 100, 100, 1, @GameID, 100, 0, 

@Time, 0,0,0,0,0) 
set @itemNum3 = @itemNum3+1 
END 
END 
END 
end 
set @Time2 = dateadd(second, 2, @Time) 
insert tblMail1 (Time, Recipient, Sender, ReadOrNot, Title, Line, 

Content, Item) values(@Time2, @GameID, '[红月私服(www.2019xz.com)]', 0, '红月冲级奖

励', 20, '感谢您对红月的支持', '') 
set @itemNum =0 
while @itemNum<5 
begin 

select @randIndex = cast((100+round(RAND()*16,0)) as int) 
if @randIndex = 109 
begin 
set @randIndex = 110 
end 
insert tblSpecialItem1 (ItemKind, ItemIndex, ItemDurability, 

Position, Map, X, Y, TileKind, GameID, WindowKind, WindowIndex, 

MiscTime, AttackGrade, StrengthGrade, SpiritGrade, DexterityGrade, 

PowerGrade) values (6, @randIndex, 4, 2, 1, 100, 100, 1, @GameID, 

100,@itemNum, @Time2, 0,0,0,0,0) 
set @itemNum = @itemNum+1 
end 

select @InsertTickError = @@ERROR 

If @InsertMailError = 0 and @InsertTickError = 0 
begin 
commit transaction 
end 
else 
begin 
rollback transaction 

end 
GO