server-re/decomp/schema/RustyHearts/procs/up_ItemMove.sql

213 lines
4.2 KiB
Transact-SQL

CREATE PROCEDURE [dbo].[up_ItemMove]
@character_id [uniqueidentifier],
@item_uid [uniqueidentifier],
@item_count int,
@inven_dest_type tinyint,
@inven_dest_page tinyint,
@inven_dest_slot tinyint,
@inven_src_type tinyint,
@inven_src_page tinyint,
@inven_src_slot tinyint
as
set nocount on
declare @char_id nvarchar(50)
declare @item_id nvarchar(50)
declare @TableName_Src nvarchar(50)
declare @TableName_Dest nvarchar(50)
declare @SQL nvarchar(500)
declare @src_item_count int
declare @get_item_code int
set @get_item_code = 0
set @char_id = CONVERT(NVARCHAR(50), @character_id)
set @item_id = CONVERT(NVARCHAR(50), @item_uid)
-- 1-인벤, 2-창고, 3-장착
if(@inven_src_type = 1)
Set @TableName_Src = 'N_InventoryItem'
else if(@inven_src_type = 2)
Set @TableName_Src = 'N_StorageItem'
else if(@inven_src_type = 3)
Set @TableName_Src = 'N_EquipItem'
else
return
if(@inven_dest_type = 1)
Set @TableName_Dest = 'N_InventoryItem'
else if(@inven_dest_type = 2)
Set @TableName_Dest = 'N_StorageItem'
else if(@inven_dest_type = 3)
Set @TableName_Dest = 'N_EquipItem'
else
return
begin tran
-- Dest에 아이템이 있는지 알아본다.
set @SQL = 'select '
+@get_item_code
+' = [code] as variable'
+'from '
+@TableName_Dest
+' with (READUNCOMMITTED) where [character_id] ='
+@char_id
+' and [page_index] = '
+@inven_dest_page
+' and [slot_index] = '
+@inven_dest_slot
exec(@SQL)
-- dest에 이미 아이템이 있으면 개수를 업데이트 해준다.
if(@get_item_code > 0)
begin
set @SQL = 'update'+ ' '
+@TableName_Dest
+'set [use_cnt] = '
+'[use_cnt]'+@item_count
+' where [character_id] ='
+@char_id
+' and [page_index] = '
+@inven_dest_page
+' and [slot_index] = '
+@inven_dest_slot
exec(@SQL)
end
-- dest에 아이템이 없으면 인서트 시켜준다.
else
begin
set @SQL = 'insert'+ ' '
+@TableName_Dest+ ' '
+'[item_uid], '
+'[character_id], '
+'[auth_id], '
+'[page_index], '
+'[slot_index], '
+'[code], '
+'[use_cnt], '
+'[remain_time], '
+'[create_time], '
+'[update_time], '
+'[gcode], '
+'[durability], '
+'[enhance_level], '
+'[option_1_code], '
+'[option_1_value], '
+'[option_2_code], '
+'[option_2_value], '
+'[option_3_code], '
+'[option_3_value], '
+'[wa_grade], '
+'[identity], '
+'[socket_count], '
+'[socket_1_code], '
+'[socket_1_value], '
+'[socket_2_code], '
+'[socket_2_value], '
+'[socket_3_code], '
+'[socket_3_value], '
+'[rank], '
+'[acquireroute], '
+'[physical], '
+'[magical], '
+'[durabilitymax], '
+'[weight]) '
+'select '
+'[item_uid], '
+'[character_id], '
+'[auth_id], '
+@inven_dest_page
+','
+@inven_dest_slot
+', '
+'[code],'
+@item_count
+', '
+'[remain_time], '
+'[create_time], '
+'[update_time], '
+'[gcode], '
+'[durability], '
+'[enhance_level], '
+'[option_1_code], '
+'[option_1_value], '
+'[option_2_code], '
+'[option_2_value], '
+'[option_3_code], '
+'[option_3_value], '
+'[wa_grade], '
+'[identity], '
+'[socket_count], '
+'[socket_1_code], '
+'[socket_1_value], '
+'[socket_2_code], '
+'[socket_2_value], '
+'[socket_3_code], '
+'[socket_3_value], '
+'[rank], '
+'[acquireroute], '
+'[physical], '
+'[magical], '
+'[durabilitymax], '
+'[weight]'
+'from '
+@TableName_Src
+' where [item_uid] ='
+ @item_id
exec(@SQL)
end
--
set @SQL = 'select'+ ' '
+@src_item_count+ ' = [use_cnt]'
+'from '
+@TableName_Src
+' with (READUNCOMMITTED) where [item_uid] ='
+@item_id
exec(@SQL)
-- 모두 옮겼으면 옮긴 아이템을 삭제한다.
if @src_item_count <= @item_count
begin
set @SQL = 'delete from'+ ' '
+@TableName_Src
+' where [item_uid] ='
+@item_id
exec(@SQL)
end
-- 특정 몇개만 옮겼으면 개수를 빼준다.
else if @src_item_count > @item_count
begin
set @SQL = 'update'+ ' '
+@TableName_Src
+'set [use_cnt] = '
+@src_item_count-@item_count
+' where [item_uid] ='
+@item_id
exec(@SQL)
end
declare @ERR int
SET @ERR = @@ERROR
IF @ERR <> 0 BEGIN
RAISERROR('처리오류', 16, 10)
IF @@TRANCOUNT <> 0 ROLLBACK
RETURN (@ERR)
END
COMMIT TRAN