Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved CharacterPersistence #660

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions Codigo/CharacterPersistence.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -96,7 +96,22 @@ 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 <= " & MAX_USERINVENTORY_HERO_SLOTS & " AND user_id = ?;"
Case Else
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, .Id)

104 counter = 0
106 If Not RS Is Nothing Then
108 While Not RS.EOF
Expand Down Expand Up @@ -571,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
Expand All @@ -584,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)
Expand Down
3 changes: 3 additions & 0 deletions Codigo/Declares.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down