echo "USE [MuOnline]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create PROCEDURE [dbo].[IGC_GremoryCase_AddItem]
@szAccountID varchar(10),
@szName varchar(10),
@StorageType int,
@RewardSource int,
@ItemID int,
@ItemLevel int,
@ItemDurability int,
@ItemOp1 int,
@ItemOp2 int,
@ItemOp3 int,
@ItemExcOption int,
@ItemSetOption int,
@ItemSocket1 int,
@ItemSocket2 int,
@ItemSocket3 int,
@ItemSocket4 int,
@ItemSocket5 int,
@ItemMainAttribute int,
@ItemMuunEvoItemType int,
@ItemMuunEvoItemIndex int, @[I][B][URL="http://forum.ragezone.com/members/482628.html"]rec[/URL][/B][/I]eiveDate bigint, @[I][B][URL="http://forum.ragezone.com/members/874653.html"]Expire[/URL][/B][/I]Date bigint
AS
BEGIN
SET NOCOUNT ON;
DECLARE @ItemsInStorage int
SET @ItemsInStorage = (SELECT COUNT(*) FROM IGC_GremoryCase WHERE AccountID = @szAccountID AND ((Name = @szName AND StorageType = 2) OR StorageType = 1))
IF (@ItemsInStorage >= 50)
BEGIN
WHILE (@ItemsInStorage >= 50)
BEGIN
DELETE FROM IGC_GremoryCase WHERE AccountID = @szAccountID AND ((Name = @szName AND StorageType = 2) OR StorageType = 1) AND ReceiveDate =
(SELECT MIN(ReceiveDate) FROM IGC_GremoryCase WHERE AccountID = @szAccountID AND ((Name = @szName AND StorageType = 2) OR StorageType = 1))
SET @ItemsInStorage = @ItemsInStorage - 1
END
END
DECLARE @[I][B][URL="http://forum.ragezone.com/members/789557.html"]Free[/URL][/B][/I]ItemGUID int
SET @[I][B][URL="http://forum.ragezone.com/members/789557.html"]Free[/URL][/B][/I]ItemGUID = 0
WHILE (1 = 1)
BEGIN
IF NOT EXISTS (SELECT * FROM IGC_GremoryCase WHERE AccountID = @szAccountID AND ((Name = @szName AND StorageType = 2) OR StorageType = 1) AND ItemGUID = @[I][B][URL="http://forum.ragezone.com/members/789557.html"]Free[/URL][/B][/I]ItemGUID)
BEGIN
BREAK
END
SET @[I][B][URL="http://forum.ragezone.com/members/789557.html"]Free[/URL][/B][/I]ItemGUID = @[I][B][URL="http://forum.ragezone.com/members/789557.html"]Free[/URL][/B][/I]ItemGUID + 1
END
DECLARE @[I][B][URL="http://forum.ragezone.com/members/789557.html"]Free[/URL][/B][/I]AuthCode int
SET @[I][B][URL="http://forum.ragezone.com/members/789557.html"]Free[/URL][/B][/I]AuthCode = 0
WHILE (1 = 1)
BEGIN
SET @[I][B][URL="http://forum.ragezone.com/members/789557.html"]Free[/URL][/B][/I]AuthCode = ROUND(((2000000000 - 1 -1) * RAND() + 1), 0)
IF NOT EXISTS (SELECT * FROM IGC_GremoryCase WHERE AuthCode = @[I][B][URL="http://forum.ragezone.com/members/789557.html"]Free[/URL][/B][/I]AuthCode)
BEGIN
BREAK
END
END
INSERT INTO IGC_GremoryCase (AccountID, Name, StorageType, RewardSource, ItemGUID, AuthCode, ItemID, ItemLevel, ItemDurability, ItemOp1, ItemOp2, ItemOp3, ItemExcOption, ItemSetOption, ItemSocket1, ItemSocket2, ItemSocket3, ItemSocket4, ItemSocket5, ItemMainAttribute, ItemMuunEvoItemType, ItemMuunEvoItemIndex, ReceiveDate, ExpireDate) VALUES
(@szAccountID, @szName, @StorageType, @RewardSource, @[I][B][URL="http://forum.ragezone.com/members/789557.html"]Free[/URL][/B][/I]ItemGUID, @[I][B][URL="http://forum.ragezone.com/members/789557.html"]Free[/URL][/B][/I]AuthCode, @ItemID, @ItemLevel, @ItemDurability, @ItemOp1, @ItemOp2, @ItemOp3, @ItemExcOption, @ItemSetOption, @ItemSocket1, @ItemSocket2, @ItemSocket3, @ItemSocket4, @ItemSocket5, @ItemMainAttribute, @ItemMuunEvoItemType, @ItemMuunEvoItemIndex, @[I][B][URL="http://forum.ragezone.com/members/482628.html"]rec[/URL][/B][/I]eiveDate, @[I][B][URL="http://forum.ragezone.com/members/874653.html"]Expire[/URL][/B][/I]Date)
SELECT @[I][B][URL="http://forum.ragezone.com/members/789557.html"]Free[/URL][/B][/I]ItemGUID AS ItemGUID, @[I][B][URL="http://forum.ragezone.com/members/789557.html"]Free[/URL][/B][/I]AuthCode AS AuthCode
END;