USE [kn_online]
GO
/****** Object: StoredProcedure [dbo].[CREATE_NEW_CHAR] Script Date: 09.09.2013 22:01:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[CREATE_NEW_CHAR]
@nRet smallint OUTPUT,
@AccountID varchar(21),
@index tinyint,
@CharID varchar(21),
@Race tinyint,
@Class smallint,
@Hair int,
@Face tinyint,
@Str tinyint,
@Sta tinyint,
@Dex tinyint,
@Intel tinyint,
@Cha tinyint
AS
DECLARE @Row tinyint, @Nation tinyint, @Zone tinyint, @PosX int, @PosZ int, @PosY int
SET @Row = 0 SET @Nation = 0 SET @Zone = 21 SET @PosX = 0 SET @PosZ = 0 SET @PosY = 0
SELECT @PosX = InitX, @PosZ = InitZ, @PosY = InitY from ZONE_INFO where ZoneNo = 21
SELECT @Nation = bNation, @Row = bCharNum FROM ACCOUNT_CHAR WHERE strAccountID = @AccountID
IF @Row >= 3 SET @nRet = 1
IF @Nation = 1 AND @Race > 10 SET @nRet = 2
ELSE IF @Nation = 2 AND @Race < 10 SET @nRet = 2
ELSE IF @Nation <>1 AND @Nation <> 2 SET @nRet = 2
IF @nRet > 0
RETURN
SELECT @Row = COUNT(*) FROM USERDATA WHERE strUserId = @CharID
IF @Row > 0
BEGIN
SET @nRet = 3
RETURN
END
BEGIN TRAN
IF @index = 0
UPDATE ACCOUNT_CHAR SET strCharID1 = @CharID, bCharNum = bCharNum + 1 WHERE strAccountID = @AccountID
ELSE IF @index = 1
UPDATE ACCOUNT_CHAR SET strCharID2 = @CharID, bCharNum = bCharNum + 1 WHERE strAccountID = @AccountID
ELSE IF @index = 2
UPDATE ACCOUNT_CHAR SET strCharID3 = @CharID, bCharNum = bCharNum + 1 WHERE strAccountID = @AccountID
ELSE
BEGIN
ROLLBACK TRAN
RETURN
END
INSERT INTO USERDATA (strUserId, Nation, Race, Class, HairRGB, Face, Strong, Sta, Dex, Intel, Cha, Zone, PX, PZ)
VALUES (@CharID, @Nation, @Race, @Class, @Hair, @Face, @Str, @Sta, @Dex, @Intel, @Cha, @Zone, @PosX, @PosZ)
/* Başlangıç İtemleri */
/*DECLARE @bClass tinyint
SET @bClass = SUBSTRING(RTRIM(LTRIM(STR(@Class))),3,1)
DECLARE @bLevel int
DECLARE @bExp bigint
DECLARE @bStrong smallint
DECLARE @bDex smallint
DECLARE @bIntel smallint
DECLARE @bCha smallint
DECLARE @bSta smallint
DECLARE @bSkill varchar(10)
DECLARE @bGold int
DECLARE @bstrItem binary(584)
DECLARE @bWarehouseData binary(1536)
DECLARE @bLoyalty int
DECLARE @bPoints smallint
SELECT @bLevel = Level, @bExp = Exp,@bStrong = Strong,@bDex = Dex, @bIntel = Intel, @bCha = Cha, @bSta = Sta,@bSkill = Skill,@bGold = Gold, @bstrItem = strItem,@bWarehouseData = WarehouseData, @bLoyalty = Loyalty,@bPoints = Points FROM BEGINNER_ITEM WHERE Class = @bClass
IF @bStrong = 0 SET @bStrong = @Str
IF @bDex = 0 SET @bDex = @Dex
IF @bIntel = 0 SET @bIntel = @Intel
IF @bCha = 0 SET @bCha = @Cha
IF @bSta = 0 SET @bSta = @Sta
UPDATE USERDATA SET Level = @bLevel,Exp = @bExp,Strong = @bStrong,Dex = @bDex,Intel = @bIntel,Cha = @bCha,Sta = @bSta,strSkill = @bSkill,Gold = @bGold,strItem = @bstrItem,Loyalty = @bLoyalty,Points = @bPoints WHERE strUserId = @CharID
UPDATE WAREHOUSE SET WarehouseData = @bWarehouseData WHERE strAccountID = @AccountID
UPDATE USERDATA SET Class = Class + 5 WHERE strUserId = @CharID AND @bClass = 1
UPDATE USERDATA SET Class = Class + 6 WHERE strUserId = @CharID AND @bClass = 2
UPDATE USERDATA SET Class = Class + 7 WHERE strUserId = @CharID AND @bClass = 3
UPDATE USERDATA SET Class = Class + 8 WHERE strUserId = @CharID AND @bClass = 4
/* Başlangıç İtemleri */*/
exec GIVE_BEGINNER_ITEM @CharID
IF @@ERROR <> 0
BEGIN
ROLLBACK TRAN
SET @nRet = 4
RETURN
END
COMMIT TRAN
SET @nRet = 0