USE [SRO_VT_SHARD]
GO
/****** Object: StoredProcedure [dbo].[_SMC_EDIT_ITEM] Script Date: 06/15/2012 19:51:45 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER procedure [dbo].[_SMC_EDIT_ITEM]
----------------------------------------------------- params to find target item
@TargetStorage int, /* 0 = inventory, 1 = chest, 2 = guild chest, 3 = Avatar Inventory */
@OwnerName varchar(128), /* account id or char id */
@Slot int,
@ItemIDToEdit bigint, /* just for check validity */
----------------------------------------------------- params to modify the item
@RefItemID int,
@OptLvl tinyint,
@Variance bigint,
@Data int,
@szCreater varchar(32),
@MagParamNum int,
@MagParam1 bigint,
@MagParam2 bigint,
@MagParam3 bigint,
@MagParam4 bigint,
@MagParam5 bigint,
@MagParam6 bigint,
@MagParam7 bigint,
@MagParam8 bigint,
@MagParam9 bigint,
@MagParam10 bigint,
@MagParam11 bigint,
@MagParam12 bigint
as
----------------------------------------------------
-- step 1. check validity of parameters
----------------------------------------------------
if (@TargetStorage <> 0 and @TargetStorage <> 1 and @TargetStorage <> 2 and @TargetStorage <> 3)
begin
select -1 -- invalid target storage
return
end
declare @ownerid int
declare @ItemID bigint
set @ownerid = 0
set @ItemID = 0
if (@TargetStorage = 0)
begin
select @ownerid = charid from _char where charname16 = @OwnerName
if (@@rowcount = 0 or @ownerid = 0 or @ownerid is null)
begin
select -2 -- can't find owner
return
end
select @ItemID = ItemID from _inventory where charid = @ownerid and slot = @slot
end
else if (@TargetStorage = 1)
begin
select @ownerid = JID from _AccountJID where AccountID = @ownername
if (@@rowcount = 0 or @ownerid = 0 or @ownerid is null)
begin
select -2 -- can't find owner
return
end
select @ItemID = ItemID from _chest where userjid = @ownerid and slot = @slot
end
else if (@TargetStorage = 2)
begin
select @ownerid = [id] from _guild where [name] = @ownername
if (@@rowcount = 0 or @ownerid = 0 or @ownerid is null)
begin
select -2 -- can't find owner
return
end
select @ItemID = ItemID from _guildchest where guildid = @ownerid and slot = @slot
end
else
begin
select @ownerid = charid from _char where charname16 = @OwnerName
if (@@rowcount = 0 or @ownerid = 0 or @ownerid is null)
begin
select -2 -- can't find owner
return
end
select @ItemID = ItemID from _InventoryForAvatar where charid = @ownerid and slot = @slot
end
if (@ItemID = 0 or @ItemID is null)
begin
select -3 -- can't find the item
return
end
if (@ItemID <> @ItemIDToEdit)
begin
select -4 -- it's not the one that you wanna edit
return
end
declare @tid1 int
declare @tid2 int
select @tid1 = TypeID1, @tid2 = TypeID2 from _RefObjCommon where ID = @RefItemID
if (@tid1 <> 3)
begin
select -5 -- about to assign non-item object
return
end
if (@tid2 <> 1) -- is equipment
begin
-- can't assign magic param or optlevel to non-equip item
if (@MagParamNum > 0 or @OptLvl > 0)
begin
select -6
return
end
end
----------------------------------------------------
-- step 2. correct some non-critical parameters
----------------------------------------------------
if (@OptLvl > 255)
begin
set @OptLvl = 255 -- clamp optlevel to 255
end
if (LEN(@szCreater) = 0)
set @szCreater = NULL
----------------------------------------------------
-- step 3. modify target item to desired values
----------------------------------------------------
if (@MagParamNum = 0)
begin
update _Items
set RefItemID = @RefItemID, OptLevel = @OptLvl, Variance = @Variance, Data = @Data, CreaterName = @szCreater, MagParamNum = 0
where id64 = @ItemID
end
else
begin
update _Items
set RefItemID = @RefItemID, OptLevel = @OptLvl, Variance = @Variance, Data = @Data, CreaterName = @szCreater, MagParamNum = @MagParamNum,
MagParam1 = @MagParam1, MagParam2 = @MagParam2, MagParam3 = @MagParam3, MagParam4 = @MagParam4,
MagParam5 = @MagParam5, MagParam6 = @MagParam6, MagParam7 = @MagParam7, MagParam8 = @MagParam8,
MagParam9 = @MagParam9, MagParam10 = @MagParam10, MagParam11 = @MagParam11, MagParam12 = @MagParam12
where id64 = @ItemID
end
if (@@error <> 0 or @@rowcount = 0)
begin
select -7
return
end
select 1
return