USE [SRO_VT_LOG]
GO
/****** Object: StoredProcedure [dbo].[_SystemBox] Script Date: 17/06/2023 03:33:09 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[_SystemBox]
@CharID int,
@ItemRefID int
as
DECLARE @CharName varchar(64) = (SELECT CharName16 FROM [SRO_VT_SHARD].[dbo].[_Char] WITH (NOLOCK) WHERE CharID = @CharID);
DECLARE @ItemCodeName Varchar(max),
@ItemCount int,
@ItemPlus int
--Select Group
DECLARE @GroupID int
SELECT @GroupID =
CASE WHEN @ItemRefID = '65749' THEN '1'
WHEN @ItemRefID = '65753' THEN '2'
ELSE 0
END
DECLARE @Random float = RAND()
;WITH OddIntervals AS
(
SELECT O.*,
OddStart = CONVERT(float, SUM(O.[Ratio]) OVER (ORDER BY O.[ID]) - O.[Ratio]),
OddsEnd = CONVERT(float, SUM(O.[Ratio]) OVER (ORDER BY O.[ID]))
FROM [SRO_VT_LOG].[dbo].[_Boxes] as O
WHERE GroupID=@GroupID
)
SELECT @ItemCodeName=O.ItemCodeName,@ItemCount=O.ItemCount,@ItemPlus=O.ItemPlus
FROM OddIntervals AS O
WHERE GroupID = @GroupID AND
@Random > O.OddStart AND
@Random <= O.OddsEnd
--EXEC [SRO_VT_SHARD].[dbo].[_ADD_ITEM_EXTERN] @CharName,@ItemCodeName,@ItemCount,@ItemPlus
EXEC MaxiGuard_User.._AddBridgeCommand 53, 'Crate',@CharName,@ItemCodeName,@ItemCount
----
DECLARE @Rare INT
SELECT @Rare = Rare FROM [SRO_VT_LOG].[dbo].[_Boxes] WHERE ItemCodeName = @ItemCodeName
IF(@Rare = 1)
BEGIN
--INSERT INTO MaxiGuard_User.dbo._BridgeCommands (CommandID, Executor, Data1, Data2, Data3) VALUES (500, 'Crate', '4', 'Success : You have earned a SOM', @CharName)
EXEC MaxiGuard_User.._AddBridgeCommand 500, 'Crate', '4','Success : You have earned a SOM',@CharName
END
IF(@Rare = 0)
BEGIN
--INSERT INTO MaxiGuard_User.dbo._BridgeCommands (CommandID, Executor, Data1, Data2, Data3) VALUES (500, 'Crate', '4', 'Failed : Good luck next time', @CharName)
EXEC MaxiGuard_User.._AddBridgeCommand 500, 'Crate', '4', 'Failed : Good Luck next time',@CharName
END