Skip to content

Commit

Permalink
Merge pull request #660 from ao-org/iv
Browse files Browse the repository at this point in the history
Improved CharacterPersistence
  • Loading branch information
RecoX authored Nov 27, 2024
2 parents 45d30cf + eedbb28 commit a297e83
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
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

0 comments on commit a297e83

Please sign in to comment.