SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

ALTER Procedure WZ_CreateCharacter

@AccountID varchar(10),
@Name varchar(10),
@Class tinyint
AS
BEGIN

SET NOCOUNT ON
SET XACT_ABORT ON
DECLARE @Result tinyint
DECLARE @iGUID int
SET @Result = 0x00
SELECT @iGUID = memb_guid FROM MEMB_INFO WHERE memb___id = @AccountID

IF EXISTS ( SELECT Name FROM Character WHERE Name = @Name )
BEGIN
SET @Result = 0x01
GOTO ProcEnd
END

BEGIN TRAN

IF NOT EXISTS ( SELECT Id FROM AccountCharacter WHERE Id = @AccountID )
BEGIN
INSERT INTO dbo.AccountCharacter(Id, GameID1, GameID2, GameID3, GameID4, GameID5, GameIDC)
VALUES(@AccountID, @Name, NULL, NULL, NULL, NULL, NULL)

SET @Result = @@Error
END
ELSE
BEGIN
Declare @g1 varchar(10), @g2 varchar(10), @g3 varchar(10), @g4 varchar(10), @g5 varchar(10)
SELECT @g1=GameID1, @g2=GameID2, @g3=GameID3, @g4=GameID4, @g5=GameID5 FROM dbo.AccountCharacter Where Id = @AccountID

IF( ( @g1 Is NULL) OR (Len(@g1) = 0))
BEGIN
UPDATE AccountCharacter SET GameID1 = @Name
WHERE Id = @AccountID

SET @Result = @@Error
END
ELSE IF( @g2 Is NULL OR Len(@g2) = 0)
BEGIN
UPDATE AccountCharacter SET GameID2 = @Name
WHERE Id = @AccountID

SET @Result = @@Error
END
ELSE IF( @g3 Is NULL OR Len(@g3) = 0)
BEGIN
UPDATE AccountCharacter SET GameID3 = @Name
WHERE Id = @AccountID

SET @Result = @@Error
END
ELSE IF( @g4 Is NULL OR Len(@g4) = 0)
BEGIN
UPDATE AccountCharacter SET GameID4 = @Name
WHERE Id = @AccountID

SET @Result = @@Error
END
ELSE IF( @g5 Is NULL OR Len(@g5) = 0)
BEGIN
UPDATE AccountCharacter SET GameID5 = @Name
WHERE Id = @AccountID

SET @Result = @@Error
END
ELSE
BEGIN
SET @Result = 0x03
GOTO TranProcEnd
END
END

IF( @Result <> 0 )
BEGIN
GOTO TranProcEnd
END
ELSE
BEGIN

INSERT INTO dbo.Character(AccountID, Name, cLevel, LevelUpPoint, Class, Strength, Dexterity, Vitality, Energy, Inventory,MagicList,
Life, MaxLife, Mana, MaxMana, MapNumber, MapPosX, MapPosY, MDate, LDate, Quest, DbVersion, Leadership,money )

SELECT @AccountID As AccountID, @Name As Name, 400, 12000, @Class As Class,
Strength, Dexterity, Vitality, Energy, Inventory,MagicList, Life, MaxLife, Mana, MaxMana, MapNumber, MapPosX, MapPosY,
getdate() As MDate, getdate() As LDate, Quest, DbVersion, Leadership, 10000000
FROM DefaultClassType WHERE Class = @Class

–edit by minh–
DECLARE @isBonus INT
SELECT @isBonus = isBonus FROM MEMB_INFO WHERE memb___id=@AccountID
IF @isBonus > 0
BEGIN
UPDATE MEMB_INFO SET isBonus=0
WHERE memb___id=@AccountID
UPDATE dbo.Character SET Inventory = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0B40004B3FCC000000E00000000000000B4000ADA5FD000000E0000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0B400034152E000000E00000000000000B40002DC414000000E0000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0B40000D861E000000E0000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0B400075D618000000E00000000000000B40008D2A39000000E0000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0B4000EA6A87000000E00000000000000B4000F515A6000000E0000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0B48003DA8B6000000E00000000000000B50009FFCA1000000E0000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0B4000BDF9CD000000E0000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0B400027C05F000000E0000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0B5800C6DCE0000000E00000000000000B4800438023000000E0000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0B4000B7867B000000E0000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0B40009644D1000000E0000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0B4000C7A152000000E0000000000000FFFF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FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
WHERE name=@Name
END
–edit by minh–

SET @Result = @@Error
END

TranProcEnd:
IF ( @Result <> 0 )
ROLLBACK TRAN
ELSE
COMMIT TRAN

ProcEnd:
SET NOCOUNT OFF
SET XACT_ABORT OFF

SELECT
CASE @Result
WHEN 0x00 THEN 0x01
WHEN 0x01 THEN 0x00
WHEN 0x03 THEN 0x03
ELSE 0x02
END AS Result
END

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

Advertisements