From 473ab96810e87620b6c8b7563e108627c6dc0797 Mon Sep 17 00:00:00 2001 From: Lucas Recoaro Date: Wed, 27 Nov 2024 16:38:08 +1300 Subject: [PATCH 1/2] Improved validation to get the correct qty in inventory --- Codigo/CharacterPersistence.bas | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Codigo/CharacterPersistence.bas b/Codigo/CharacterPersistence.bas index a34df587..37b1d6ee 100644 --- a/Codigo/CharacterPersistence.bas +++ b/Codigo/CharacterPersistence.bas @@ -60,7 +60,7 @@ GetCharacterName_Err: End Function Public Function LoadCharacterBank(ByVal UserIndex As Integer) As Boolean - On Error GoTo LoadCharacterInventory_Err + On Error GoTo LoadCharacterBank_Err 100 With UserList(UserIndex) Dim RS As ADODB.Recordset Dim counter As Long @@ -87,7 +87,7 @@ Public Function LoadCharacterBank(ByVal UserIndex As Integer) As Boolean LoadCharacterBank = True Exit Function -LoadCharacterInventory_Err: +LoadCharacterBank_Err: Call LogDatabaseError("Error en LoadCharacterFromDB LoadCharacterBank: " & UserList(UserIndex).name & ". " & Err.Number & " - " & Err.Description & ". Línea: " & Erl) End Function @@ -96,7 +96,21 @@ Public Function LoadCharacterInventory(ByVal UserIndex As Integer) As Boolean 100 With UserList(UserIndex) Dim RS As ADODB.Recordset Dim counter As Long -102 Set RS = Query("SELECT number, item_id, is_equipped, amount FROM inventory_item WHERE user_id = ?;", .id) + Dim SQLQuery As String + + ' Determine SQL query based on user type for inventory items + Select Case .Stats.tipoUsuario + Case tLeyenda + SQLQuery = "SELECT number, item_id, is_equipped, amount FROM inventory_item WHERE user_id = ?;" + Case tHeroe + SQLQuery = "SELECT number, item_id, is_equipped, amount FROM inventory_item WHERE number > 31 AND user_id = ?;" + Case Else + SQLQuery = "SELECT number, item_id, is_equipped, amount FROM inventory_item WHERE number > 25 AND user_id = ?;" + End Select + + ' Execute the query + Set RS = Query(SQLQuery, .d) + 104 counter = 0 106 If Not RS Is Nothing Then 108 While Not RS.EOF From eedbb28359bf0e4fa5377bb365017ef616b42c32 Mon Sep 17 00:00:00 2001 From: Lucas Recoaro Date: Wed, 27 Nov 2024 20:39:32 +1300 Subject: [PATCH 2/2] Improved CharacterPesistance --- Codigo/CharacterPersistence.bas | 23 ++++++++++++++++------- Codigo/Declares.bas | 3 +++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Codigo/CharacterPersistence.bas b/Codigo/CharacterPersistence.bas index 37b1d6ee..40a2f7fd 100644 --- a/Codigo/CharacterPersistence.bas +++ b/Codigo/CharacterPersistence.bas @@ -103,13 +103,14 @@ Public Function LoadCharacterInventory(ByVal UserIndex As Integer) As Boolean Case tLeyenda SQLQuery = "SELECT number, item_id, is_equipped, amount FROM inventory_item WHERE user_id = ?;" Case tHeroe - SQLQuery = "SELECT number, item_id, is_equipped, amount FROM inventory_item WHERE number > 31 AND user_id = ?;" + SQLQuery = "SELECT number, item_id, is_equipped, amount FROM inventory_item WHERE number <= " & MAX_USERINVENTORY_HERO_SLOTS & " AND user_id = ?;" Case Else - SQLQuery = "SELECT number, item_id, is_equipped, amount FROM inventory_item WHERE number > 25 AND user_id = ?;" + SQLQuery = "SELECT number, item_id, is_equipped, amount FROM inventory_item WHERE number <= " & MAX_USERINVENTORY_SLOTS & " AND user_id = ?;" End Select + ' Execute the query - Set RS = Query(SQLQuery, .d) + Set RS = Query(SQLQuery, .Id) 104 counter = 0 106 If Not RS Is Nothing Then @@ -585,10 +586,18 @@ Public Sub SaveCharacterDB(ByVal userIndex As Integer) Call Execute(QUERY_UPSERT_SPELLS, Params) ' ************************** User inventory ********************************* -366 ReDim Params(MAX_INVENTORY_SLOTS * 5 - 1) -368 ParamC = 0 +350 ' First determine Inventory Slot Limit so we do not delete items in case they remove the subscription +351 Dim InventorySlots As Long + Select Case .Stats.tipoUsuario + Case tLeyenda +354 InventorySlots = MAX_INVENTORY_SLOTS +355 Case tHeroe +356 InventorySlots = MAX_USERINVENTORY_HERO_SLOTS +357 Case Else +358 InventorySlots = MAX_USERINVENTORY_SLOTS +359 End Select -370 For LoopC = 1 To MAX_INVENTORY_SLOTS +370 For LoopC = 1 To InventorySlots 372 Params(ParamC) = .ID 374 Params(ParamC + 1) = LoopC 376 Params(ParamC + 2) = .Invent.Object(LoopC).objIndex @@ -598,7 +607,7 @@ Public Sub SaveCharacterDB(ByVal userIndex As Integer) 382 ParamC = ParamC + 5 384 Next LoopC - Call Execute(QUERY_UPSERT_INVENTORY, Params) + Call Execute(QUERY_UPSERT_INVENTORY, Params) ' ************************** User bank inventory ********************************* 402 ReDim Params(MAX_BANCOINVENTORY_SLOTS * 4 - 1) diff --git a/Codigo/Declares.bas b/Codigo/Declares.bas index 9483e157..1379f599 100644 --- a/Codigo/Declares.bas +++ b/Codigo/Declares.bas @@ -811,6 +811,9 @@ Public Const MAX_INVENTORY_SLOTS As Byte = 42 ' Cantidad de "slots" en el inventario básico Public Const MAX_USERINVENTORY_SLOTS As Byte = 24 +' Cantidad de "slots" en el inventario heroe +Public Const MAX_USERINVENTORY_HERO_SLOTS As Byte = 31 + ' Cantidad de "slots" en el inventario por fila Public Const SLOTS_PER_ROW_INVENTORY As Byte = 6