USE [SRO_VT_SHARD]
GO
/****** Object: Trigger [dbo].[TR_AUTOEQUIP_SPARE] Script Date: 09/11/2013 00:04:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[TR_AUTOEQUIP_SPARE] ON [dbo].[_Char] AFTER UPDATE
AS
BEGIN
declare @Newlvl as tinyint = (select CurLevel from inserted)
declare @CharID as int = (select CharID from inserted)
if(@Newlvl = 15 or @Newlvl = 23 or @Newlvl = 31 or @Newlvl = 40 or @Newlvl = 47 or @Newlvl = 57 or @Newlvl = 69 or @Newlvl = 81 or @Newlvl = 95)
begin
declare @RefCharID int
declare @CharName varchar(64)
declare @CharLevel tinyint
set @RefCharID = (select RefObjID from SRO_VT_SHARD.dbo._Char where CharID = @CharID)
set @CharName = (select CharName16 from SRO_VT_SHARD.dbo._Char where CharID = @CharID)
set @CharLevel = (select CurLevel from SRO_VT_SHARD.dbo._Char where CharID = @CharID)
Declare @RefMail INT = (Select ItemID From SRO_VT_SHARD.dbo._Inventory Where CharID=(Select CharID From SRO_VT_SHARD.dbo._Char Where CharID = @CharID)
AND Slot ='1')
Declare @RefMailID INT = (Select RefItemID From SRO_VT_SHARD.dbo._Items Where ID64 = @RefMail)
Declare @RefWeapon INT
Declare @Weapon INT = (Select ItemID From SRO_VT_SHARD.dbo._Inventory Where CharID=(Select CharID From SRO_VT_SHARD.dbo._Char Where CharID = @CharID)
AND Slot ='6')
Declare @RefWeaponID INT = (Select RefItemID From SRO_VT_SHARD.dbo._Items Where ID64 = @Weapon)
Declare @WeaponType Tinyint = (Select Typeid4 from SRO_VT_SHARD.dbo._RefObjCommon where ID = @RefWeaponID)
Declare @RefShield INT
Declare @Shield INT = (Select ItemID From SRO_VT_SHARD.dbo._Inventory Where CharID=(Select CharID From SRO_VT_SHARD.dbo._Char Where CharID = @CharID)
AND Slot ='7')
Declare @RefShieldID INT = (Select RefItemID From SRO_VT_SHARD.dbo._Items Where ID64 = @Shield)
Declare @ShieldType Tinyint = (Select Typeid4 from SRO_VT_SHARD.dbo._RefObjCommon where ID = @RefShieldID)
declare @mail_codename varchar(250)
declare @chr_gender varchar(250)
declare @item_level varchar(250)
declare @itemcodename varchar(250)
select @mail_codename = CodeName128 from SRO_VT_SHARD.dbo._RefObjCommon where ID = @RefMailID
Update SRO_VT_SHARD.dbo._Inventory set ItemID = 0 where CharID = @CharID and Slot = 0
Update SRO_VT_SHARD.dbo._Inventory set ItemID = 0 where CharID = @CharID and Slot = 1
Update SRO_VT_SHARD.dbo._Inventory set ItemID = 0 where CharID = @CharID and Slot = 2
Update SRO_VT_SHARD.dbo._Inventory set ItemID = 0 where CharID = @CharID and Slot = 3
Update SRO_VT_SHARD.dbo._Inventory set ItemID = 0 where CharID = @CharID and Slot = 4
Update SRO_VT_SHARD.dbo._Inventory set ItemID = 0 where CharID = @CharID and Slot = 5
Update SRO_VT_SHARD.dbo._Inventory set ItemID = 0 where CharID = @CharID and Slot = 9
Update SRO_VT_SHARD.dbo._Inventory set ItemID = 0 where CharID = @CharID and Slot = 10
Update SRO_VT_SHARD.dbo._Inventory set ItemID = 0 where CharID = @CharID and Slot = 11
Update SRO_VT_SHARD.dbo._Inventory set ItemID = 0 where CharID = @CharID and Slot = 12
If ((Select TypeID4 from SRO_VT_SHARD.dbo._RefObjCommon where ID = (Select top 1 RefItemID from SRO_VT_SHARD.dbo._items where id64 = @Weapon))
= @WeaponType ) -- Weapon
Begin
Set @RefWeapon = (Select top 1 ID from SRO_VT_SHARD.dbo._ItemPoolAutoEquipment where
Service = 1 AND
TypeID1=3 AND --- Weapon
TypeID2=1 AND
TypeID3=6 AND
TypeID4=@WeaponType
Group by SRO_VT_SHARD.dbo._ItemPoolAutoEquipment.ID,SRO_VT_SHARD.dbo._ItemPoolAutoEquipment.reqlevel1
having (MAX(ReqLevel1)<=@Newlvl)
Order By ReqLevel1 Desc
)
Update SRO_VT_SHARD.dbo._Items set RefItemID= @RefWeapon where ID64= @Weapon
Update SRO_VT_SHARD.dbo._Items set OptLevel= 12,Variance= 34359738367,Data= 200, MagParamNum='2',MagParam1='30064771144',MagParam2= '30064771150' where ID64= @Weapon
END
If ((Select TypeID4 from SRO_VT_SHARD.dbo._RefObjCommon where ID = (Select top 1 RefItemID from SRO_VT_SHARD.dbo._items where id64 = @Shield))
= @ShieldType ) -- Shield
Begin
Set @RefShield = (Select top 1 ID from SRO_VT_SHARD.dbo._ItemPoolAutoEquipment WITH (Nolock) where
Service = 1 AND
TypeID1=3 AND --- Shield
TypeID2=1 AND
TypeID3=4 AND
TypeID4=@ShieldType
Group by SRO_VT_SHARD.dbo._ItemPoolAutoEquipment.ID,SRO_VT_SHARD.dbo._ItemPoolAutoEquipment.reqlevel1
having (MAX(ReqLevel1)<=@Newlvl)
Order By ReqLevel1 Desc
)
Update SRO_VT_SHARD.dbo._Items set RefItemID= @RefShield where ID64= @Shield
Update SRO_VT_SHARD.dbo._Items set OptLevel= 12,Variance= 34359738367,Data= 200, MagParamNum='2',MagParam1='30064771144',MagParam2= '30064771150' where ID64= @Shield
END
IF (@Newlvl = 15)
BEGIN
set @item_level = '02' --DG
end
IF (@Newlvl = 23)
BEGIN
set @item_level = '03' --DG
end
IF (@Newlvl = 31)
BEGIN
set @item_level = '04' --DG
end
IF (@Newlvl = 40)
BEGIN
set @item_level = '05' --DG
end
IF (@Newlvl = 47)
BEGIN
set @item_level = '06' --DG
end
IF (@Newlvl = 57)
BEGIN
set @item_level = '07' --DG
end
IF (@Newlvl = 69)
BEGIN
set @item_level = '08' --DG
end
IF (@Newlvl = 81)
BEGIN
set @item_level = '09' --DG
end
if(@RefCharID between 1907 and 1919 or @RefCharID between 14875 and 14887)
begin
set @chr_gender = 'M' --male
end
if(@RefCharID between 1920 and 1932 or @RefCharID between 14888 and 14900)
begin
set @chr_gender = 'W' --female
end
if(@RefCharID between 1907 and 1919 or @RefCharID between 1920 and 1932)
begin
set @itemcodename = 'ITEM_CH_RING_' + @item_level + '_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,11,@itemcodename,200
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,12,@itemcodename,200
set @itemcodename = 'ITEM_CH_EARRING_' + @item_level + '_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,9,@itemcodename,200
set @itemcodename = 'ITEM_CH_NECKLACE_' + @item_level + '_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,10,@itemcodename,200
end
if(@RefCharID between 14875 and 14887 or @RefCharID between 14888 and 14900)
begin
set @itemcodename = 'ITEM_EU_RING_' + @item_level + '_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,11,@itemcodename,200
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,12,@itemcodename,200
set @itemcodename = 'ITEM_EU_EARRING_' + @item_level + '_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,9,@itemcodename,200
set @itemcodename = 'ITEM_EU_NECKLACE_' + @item_level + '_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,10,@itemcodename,200
end
--//ARMOR\\--
if(@mail_codename like 'ITEM_CH_%_LIGHT%')
begin
set @itemcodename = 'ITEM_CH_' + @chr_gender + '_LIGHT_' + @item_level + '_HA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,0,@itemcodename,200
set @itemcodename = 'ITEM_CH_' + @chr_gender + '_LIGHT_' + @item_level + '_SA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,2,@itemcodename,200
set @itemcodename = 'ITEM_CH_' + @chr_gender + '_LIGHT_' + @item_level + '_BA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,1,@itemcodename,200
set @itemcodename = 'ITEM_CH_' + @chr_gender + '_LIGHT_' + @item_level + '_LA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,4,@itemcodename,200
set @itemcodename = 'ITEM_CH_' + @chr_gender + '_LIGHT_' + @item_level + '_AA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,3,@itemcodename,200
set @itemcodename = 'ITEM_CH_' + @chr_gender + '_LIGHT_' + @item_level + '_FA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,5,@itemcodename,200
end
else if(@mail_codename like 'ITEM_CH_%_HEAVY%')
begin
set @itemcodename = 'ITEM_CH_' + @chr_gender + '_HEAVY_' + @item_level + '_HA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,0,@itemcodename,200
set @itemcodename = 'ITEM_CH_' + @chr_gender + '_HEAVY_' + @item_level + '_SA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,2,@itemcodename,200
set @itemcodename = 'ITEM_CH_' + @chr_gender + '_HEAVY_' + @item_level + '_BA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,1,@itemcodename,200
set @itemcodename = 'ITEM_CH_' + @chr_gender + '_HEAVY_' + @item_level + '_LA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,4,@itemcodename,200
set @itemcodename = 'ITEM_CH_' + @chr_gender + '_HEAVY_' + @item_level + '_AA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,3,@itemcodename,200
set @itemcodename = 'ITEM_CH_' + @chr_gender + '_HEAVY_' + @item_level + '_FA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,5,@itemcodename,200
end
else if(@mail_codename like 'ITEM_CH_%_CLOTHES%')
begin
set @itemcodename = 'ITEM_CH_' + @chr_gender + '_CLOTHES_' + @item_level + '_HA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,0,@itemcodename,200
set @itemcodename = 'ITEM_CH_' + @chr_gender + '_CLOTHES_' + @item_level + '_SA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,2,@itemcodename,200
set @itemcodename = 'ITEM_CH_' + @chr_gender + '_CLOTHES_' + @item_level + '_BA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,1,@itemcodename,200
set @itemcodename = 'ITEM_CH_' + @chr_gender + '_CLOTHES_' + @item_level + '_LA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,4,@itemcodename,200
set @itemcodename = 'ITEM_CH_' + @chr_gender + '_CLOTHES_' + @item_level + '_AA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,3,@itemcodename,200
set @itemcodename = 'ITEM_CH_' + @chr_gender + '_CLOTHES_' + @item_level + '_FA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,5,@itemcodename,200
end
else if(@mail_codename like 'ITEM_EU_%_LIGHT%')
begin
set @itemcodename = 'ITEM_EU_' + @chr_gender + '_LIGHT_' + @item_level + '_HA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,0,@itemcodename,200
set @itemcodename = 'ITEM_EU_' + @chr_gender + '_LIGHT_' + @item_level + '_SA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,2,@itemcodename,200
set @itemcodename = 'ITEM_EU_' + @chr_gender + '_LIGHT_' + @item_level + '_BA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,1,@itemcodename,200
set @itemcodename = 'ITEM_EU_' + @chr_gender + '_LIGHT_' + @item_level + '_LA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,4,@itemcodename,200
set @itemcodename = 'ITEM_EU_' + @chr_gender + '_LIGHT_' + @item_level + '_AA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,3,@itemcodename,200
set @itemcodename = 'ITEM_EU_' + @chr_gender + '_LIGHT_' + @item_level + '_FA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,5,@itemcodename,200
end
else if(@mail_codename like 'ITEM_EU_%_HEAVY%')
begin
set @itemcodename = 'ITEM_EU_' + @chr_gender + '_HEAVY_' + @item_level + '_HA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,0,@itemcodename,200
set @itemcodename = 'ITEM_EU_' + @chr_gender + '_HEAVY_' + @item_level + '_SA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,2,@itemcodename,200
set @itemcodename = 'ITEM_EU_' + @chr_gender + '_HEAVY_' + @item_level + '_BA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,1,@itemcodename,200
set @itemcodename = 'ITEM_EU_' + @chr_gender + '_HEAVY_' + @item_level + '_LA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,4,@itemcodename,200
set @itemcodename = 'ITEM_EU_' + @chr_gender + '_HEAVY_' + @item_level + '_AA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,3,@itemcodename,200
set @itemcodename = 'ITEM_EU_' + @chr_gender + '_HEAVY_' + @item_level + '_FA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,5,@itemcodename,200
end
else if(@mail_codename like 'ITEM_EU_%_CLOTHES%')
begin
set @itemcodename = 'ITEM_EU_' + @chr_gender + '_CLOTHES_' + @item_level + '_HA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,0,@itemcodename,200
set @itemcodename = 'ITEM_EU_' + @chr_gender + '_CLOTHES_' + @item_level + '_SA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,2,@itemcodename,200
set @itemcodename = 'ITEM_EU_' + @chr_gender + '_CLOTHES_' + @item_level + '_BA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,1,@itemcodename,200
set @itemcodename = 'ITEM_EU_' + @chr_gender + '_CLOTHES_' + @item_level + '_LA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,4,@itemcodename,200
set @itemcodename = 'ITEM_EU_' + @chr_gender + '_CLOTHES_' + @item_level + '_AA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,3,@itemcodename,200
set @itemcodename = 'ITEM_EU_' + @chr_gender + '_CLOTHES_' + @item_level + '_FA_C_RARE'
EXEC SRO_VT_SHARD.dbo._FN_ADD_INITIAL_EQUIP_SPARE @CharName,5,@itemcodename,200
end
end
END