红月论坛

 找回密码
 立即注册
查看: 10260|回复: 1

[技术解析] RMS_SENDSPECIALITEMMAILX 一信多特

  [复制链接]
发表于 2020-3-4 19:45:09 | 显示全部楼层 |阅读模式
存储过程RMS_SENDSPECIALITEMAIL每次只能发一种特殊物品。
根据语法规则写了一个可发多个的。
使用方法:

EXEC RMS_SENDSPECIALITEMMAILX '发信人','收信人',‘标题’,'内容',种类数,物品1编号,物品1数量,物品2编号,物品2数量,物品3编号,物品3数量,物品4编号,物品4数量,物品5编号,物品5数量

根据种类数,发几种就写几组 编号,数量 即可。


代码如下:
  1. USE [RedMoon]
  2. GO

  3. /****** Object:  StoredProcedure [dbo].[RMS_SENDSPECIALITEMMAILX]    Script Date: 03/04/2020 19:39:46 ******/
  4. IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RMS_SENDSPECIALITEMMAILX]') AND type in (N'P', N'PC'))
  5. DROP PROCEDURE [dbo].[RMS_SENDSPECIALITEMMAILX]
  6. GO

  7. USE [RedMoon]
  8. GO

  9. /****** Object:  StoredProcedure [dbo].[RMS_SENDSPECIALITEMMAILX]    Script Date: 03/04/2020 19:39:46 ******/
  10. SET ANSI_NULLS ON
  11. GO

  12. SET QUOTED_IDENTIFIER ON
  13. GO


  14. CREATE  PROCEDURE [dbo].[RMS_SENDSPECIALITEMMAILX]
  15.         @Sender        varchar(14),
  16.         @Recipient        varchar(14),
  17.         @Title                varchar(80),
  18.         @Content        varchar(1000),
  19.         @Count        int,
  20.         @ItemIndex1        int = 0,
  21.         @ItemCount1        int = 0,
  22.         @ItemIndex2        int = 0,
  23.         @ItemCount2        int = 0,
  24.         @ItemIndex3        int = 0,
  25.         @ItemCount3        int = 0,
  26.         @ItemIndex4        int = 0,
  27.         @ItemCount4        int = 0,
  28.         @ItemIndex5        int = 0,
  29.         @ItemCount5        int = 0
  30. AS

  31. set nocount on
  32. declare @ItemIndex int, @ItemCount int
  33. declare @MailCount int
  34. declare @Time datetime
  35. set @MailCount = 0
  36. set @Time=cast(convert(varchar, GetDate(), 120) as datetime)

  37. If @Count>5 OR @Count<0 OR @Count=1        return

  38. begin transaction sendmorespcitem

  39. select @MailCount = count(*) from tblMail1 where Recipient =@Recipient and Time = @Time
  40. while @MailCount > 0
  41. begin
  42.         set @MailCount = 0
  43.         set @Time = dateadd(second, 1, @Time)
  44.         select @MailCount = count(*) from tblMail1 where Recipient = @Recipient and Time = @Time
  45. end

  46. if @Count > 1
  47. begin
  48.         set @ItemIndex = @ItemIndex1
  49.         set @ItemCount = @ItemCount1
  50.         while @ItemCount>0
  51.         begin
  52.                 insert tblSpecialItem1 (ItemKind, ItemIndex, ItemDurability, Position, Map, X, Y, TileKind, GameID, WindowKind, WindowIndex, MiscTime) values (6, @ItemIndex, 5, 2, 1, 100, 100, 1, @Recipient, 100, 0, @Time)
  53.                 set @ItemCount=@ItemCount -1
  54.         end
  55.         set @ItemIndex = @ItemIndex2
  56.         set @ItemCount = @ItemCount2
  57.         while @ItemCount>0
  58.         begin
  59.                 insert tblSpecialItem1 (ItemKind, ItemIndex, ItemDurability, Position, Map, X, Y, TileKind, GameID, WindowKind, WindowIndex, MiscTime) values (6, @ItemIndex, 5, 2, 1, 100, 100, 1, @Recipient, 100, 1, @Time)
  60.                 set @ItemCount=@ItemCount -1
  61.         end
  62. end
  63. if @Count > 2 and @ItemIndex3 != 0 and @ItemCount3 != 0
  64. begin
  65.         set @ItemIndex = @ItemIndex3
  66.         set @ItemCount = @ItemCount3
  67.         while @ItemCount>0
  68.         begin
  69.                 insert tblSpecialItem1 (ItemKind, ItemIndex, ItemDurability, Position, Map, X, Y, TileKind, GameID, WindowKind, WindowIndex, MiscTime) values (6, @ItemIndex, 5, 2, 1, 100, 100, 1, @Recipient, 100, 2, @Time)
  70.                 set @ItemCount=@ItemCount -1
  71.         end
  72. end
  73. if @Count > 3 and @ItemIndex4 != 0 and @ItemCount4 != 0
  74. begin
  75.         set @ItemIndex = @ItemIndex4
  76.         set @ItemCount = @ItemCount4
  77.         while @ItemCount>0
  78.         begin
  79.                 insert tblSpecialItem1 (ItemKind, ItemIndex, ItemDurability, Position, Map, X, Y, TileKind, GameID, WindowKind, WindowIndex, MiscTime) values (6, @ItemIndex, 5, 2, 1, 100, 100, 1, @Recipient, 100, 3, @Time)
  80.                 set @ItemCount=@ItemCount -1
  81.         end
  82. end
  83. if @Count > 4 and @ItemIndex5 != 0 and @ItemCount5 != 0
  84. begin
  85.         set @ItemIndex = @ItemIndex5
  86.         set @ItemCount = @ItemCount5
  87.         while @ItemCount>0
  88.         begin
  89.                 insert tblSpecialItem1 (ItemKind, ItemIndex, ItemDurability, Position, Map, X, Y, TileKind, GameID, WindowKind, WindowIndex, MiscTime) values (6, @ItemIndex, 5, 2, 1, 100, 100, 1, @Recipient, 100, 4, @Time)
  90.                 set @ItemCount=@ItemCount -1
  91.         end
  92. end

  93. insert tblMail1 (Time, Recipient, Sender, ReadOrNot, Title, Line, Content, Item) values(@Time, @Recipient,@Sender, 0, @Title, 20, @Content, '')                                                                              

  94. commit transaction sendmorespcitem



  95. GO


复制代码


学习红月技术,我只来红月论坛!
回复

使用道具 举报

发表于 2021-4-20 11:56:29 | 显示全部楼层
好好学习,天天向上!
学习红月技术,我只来红月论坛!
回复

使用道具 举报

手机版|小黑屋|红月论坛

GMT+8, 2024-12-31 02:11

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表