USE [lin2world]
GO
/****** Object: StoredProcedure [dbo].[lin_CreateChar] Script Date: Сб, 20.04.2024 17:16:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/**
name: lin_CreateChar
desc: create user_data, quest, user_slot
history: 2007-03-30 modified by btwinuni
*/
ALTER procedure [dbo].[lin_CreateChar]
(
@char_name nvarchar(24),
@account_name nvarchar(24),
@account_id int,
@pledge_id int,
@builder tinyint,
@gender tinyint,
@race tinyint,
@class tinyint,
@world smallint,
@xloc int,
@yloc int,
@zloc int,
@HP float,
@MP float,
@SP int,
@Exp bigint,
@Lev tinyint,
@align smallint,
@PK int,
@nickname int,
@Duel int,
@PKPardon int,
@FaceIndex int = 0,
@HairShapeIndex int = 0,
@HairColorIndex int = 0
)
as
--set @Exp=25259243744
--set @SP=50000000
--set @Lev=85
set nocount on
declare @char_id int
set @char_id = 0
set @char_name = rtrim(@char_name)
if (@gender > 1) OR (@gender<0) set @gender = 0
if (@race > 5) OR (@race<0) set @race = 0
if (@HairShapeIndex<0) set @HairShapeIndex = 0
if (@FaceIndex<0) set @HairShapeIndex = 0
if (@race = 5) begin
if (@HairShapeIndex>2) set @HairShapeIndex=0
end else begin
if (@HairShapeIndex>3) set @HairShapeIndex=0
end
if (@gender = 0) begin
if (@FaceIndex>4) set @FaceIndex=0
end else begin
if (@FaceIndex>6) set @FaceIndex=0
end
if (@HairColorIndex>2) OR (@HairColorIndex<0) set @HairColorIndex=0
if @char_name like N'%[^a-zA-Z0-9]%'
begin
raiserror ('Character name has space : name = [%s]', 16, 1, @char_name)
return -1
end
if @char_name like N'% %'
begin
raiserror ('Character name has space : name = [%s]', 16, 1, @char_name)
return -1
end
if @char_name like N'% %'
begin
raiserror ('Character name has space : name = [%s]', 16, 1, @char_name)
return -1
end
-- check user_data
if exists(select char_name from user_data (nolock) where char_name = @char_name)
begin
raiserror ('Character name is used: name = [%s]', 16, 1, @char_name)
return -1
end
-- check user_prohibit
if exists(select char_name from user_prohibit (nolock) where char_name = @char_name)
begin
raiserror ('Character name is prohibited: name = [%s]', 16, 1, @char_name)
return -1
end
declare @user_prohibit_word nvarchar(20)
select top 1 @user_prohibit_word = words from user_prohibit_word (nolock) where @char_name like '%' + words + '%'
if @user_prohibit_word is not null
begin
raiserror ('Character name has prohibited word: name = [%s], word[%s]', 16, 1, @char_name, @user_prohibit_word)
return -1
end
-- check reserved name
declare @reserved_name nvarchar(50)
declare @reserved_account_id int
select top 1 @reserved_name = char_name, @reserved_account_id = account_id from user_name_reserved (nolock) where used = 0 and char_name = @char_name
if not @reserved_name is null
begin
if not @reserved_account_id = @account_id
begin
raiserror ('Character name is reserved by other player: name = [%s]', 16, 1, @char_name)
return -1
end
end
-- insert user_data
insert into user_data (
char_name, account_name, account_id, pledge_id, builder, gender, race, class, subjob0_class,
world, xloc, yloc, zloc, HP, MP, max_hp, max_mp, SP, Exp, Lev, align, PK, nickname, PKpardon, duel,
create_date, face_index, hair_shape_index, hair_color_index
)
values (
@char_name, @account_name, @account_id, @pledge_id, @builder, @gender, @race, @class, @class,
@world, @xloc, @yloc, @zloc, @HP, @MP, @HP, @MP, @SP, @Exp, @Lev, @align, @PK, 'Title', @Duel, @PKPardon,
GETDATE(), @FaceIndex, @HairShapeIndex, @HairColorIndex
)
if (@@error = 0)
begin
set @char_id = @@identity
insert into quest (char_id) values (@char_id)
insert into user_slot (char_id) values (@char_id)
end
select @char_id
if @char_id > 0
begin
-- make user_history
exec lin_InsertUserHistory @char_name, @char_id, 1, @account_name, NULL
if not @reserved_name is null
update user_name_reserved set used = 1 where char_name = @reserved_name
end