Skip to content

Commit

Permalink
add multiple lobby and instance support (#418)
Browse files Browse the repository at this point in the history
* add multiple lobby support and start working with map instance

* Add instance support for event maps

* add support for users to create lobby (#428)

* add missing increasearraysize call

* address pr comments

* add missing change from last commit
  • Loading branch information
matiascalegaris authored Oct 24, 2023
1 parent 792c345 commit cd135ca
Show file tree
Hide file tree
Showing 20 changed files with 831 additions and 476 deletions.
12 changes: 11 additions & 1 deletion Codigo/Acciones.bas
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,17 @@ Sub Accion(ByVal UserIndex As Integer, ByVal Map As Integer, ByVal X As Integer,
End If

Call WriteShopPjsInit(UserIndex)

ElseIf NpcList(TempCharIndex).npcType = e_NPCType.EventMaster Then
If UserList(UserIndex).flags.Muerto = 1 Then
Call WriteLocaleMsg(UserIndex, 77, e_FontTypeNames.FONTTYPE_INFO)
Exit Sub
End If

If Distancia(NpcList(TempCharIndex).pos, UserList(UserIndex).pos) > 4 Then
Call WriteLocaleMsg(UserIndex, 8, e_FontTypeNames.FONTTYPE_INFO)
Exit Sub
End If
Call WriteUpdateLobbyList(UserIndex)
320 ElseIf NpcList(TempCharIndex).Craftea > 0 Then
If UserList(UserIndex).flags.Muerto = 1 Then
Call WriteLocaleMsg(UserIndex, "77", e_FontTypeNames.FONTTYPE_INFOIAO)
Expand Down
81 changes: 63 additions & 18 deletions Codigo/CustomScenarios.bas
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,34 @@ End Type

Private CustomScenarioList As New Dictionary
Private ScenarioUpdateList() As IBaseScenario
Private AvailableUpdateSlots As t_IndexHeap
Private ActiveUpdateSlots As t_IndexHeap
Const InitialUpdateSize = 20

Private Sub InitializeUpdateStacks()
ReDim ScenarioUpdateList(InitialUpdateSize) As IBaseScenario
ReDim AvailableUpdateSlots.IndexInfo(InitialUpdateSize)
ReDim ActiveUpdateSlots.IndexInfo(InitialUpdateSize)
Dim i As Integer
For i = 1 To InitialUpdateSize
AvailableUpdateSlots.IndexInfo(i) = InitialUpdateSize - (i - 1)
Next i
AvailableUpdateSlots.currentIndex = InitialUpdateSize
ActiveUpdateSlots.currentIndex = 0
End Sub

Private Sub IncreaseArraySize(ByVal ExtraSlots As Integer)
Dim NewSize As Integer
NewSize = UBound(ScenarioUpdateList) + ExtraSlots
ReDim Preserve ScenarioUpdateList(NewSize) As IBaseScenario
ReDim Preserve AvailableUpdateSlots.IndexInfo(NewSize)
ReDim Preserve ActiveUpdateSlots.IndexInfo(NewSize)
Dim i As Integer
For i = 1 To ExtraSlots
AvailableUpdateSlots.IndexInfo(i) = NewSize - (i - 1)
Next i
AvailableUpdateSlots.currentIndex = ExtraSlots
End Sub
Public Function GetMap(ByVal mapIndex As Integer) As IBaseScenario
On Error GoTo GetMap_Err:
Set GetMap = Nothing
Expand All @@ -69,12 +96,16 @@ End Sub
Public Function AddUpdateScenario(ByRef scenario As IBaseScenario) As Integer
On Error GoTo AddUpdateScenario_Err:
Dim Pos As Integer
100 If IsArrayInitialized(ScenarioUpdateList) Then
102 Pos = UBound(ScenarioUpdateList)
Else
Pos = 0
100 If AvailableUpdateSlots.currentIndex = 0 And ActiveUpdateSlots.currentIndex = 0 Then
102 Call InitializeUpdateStacks
End If
If AvailableUpdateSlots.currentIndex = 0 Then
Call IncreaseArraySize(InitialUpdateSize)
End If
104 ReDim Preserve ScenarioUpdateList(Pos + 1) As IBaseScenario
pos = AvailableUpdateSlots.IndexInfo(AvailableUpdateSlots.currentIndex)
AvailableUpdateSlots.currentIndex = AvailableUpdateSlots.currentIndex - 1
ActiveUpdateSlots.IndexInfo(ActiveUpdateSlots.currentIndex) = pos
ActiveUpdateSlots.currentIndex = ActiveUpdateSlots.currentIndex + 1
106 Set ScenarioUpdateList(Pos) = scenario
AddUpdateScenario = Pos
Exit Function
Expand All @@ -85,17 +116,23 @@ End Function
Public Sub RemoveUpdateScenario(ByRef Index As Integer)
Debug.Assert Index < UBound(ScenarioUpdateList)
Set ScenarioUpdateList(Index) = Nothing
Dim i As Integer
For i = 0 To ActiveUpdateSlots.currentIndex - 1
If ActiveUpdateSlots.IndexInfo(i) = Index Then
ActiveUpdateSlots.IndexInfo(i) = ActiveUpdateSlots.IndexInfo(ActiveUpdateSlots.currentIndex - 1)
ActiveUpdateSlots.currentIndex = ActiveUpdateSlots.currentIndex - 1
AvailableUpdateSlots.currentIndex = AvailableUpdateSlots.currentIndex + 1
AvailableUpdateSlots.IndexInfo(AvailableUpdateSlots.currentIndex) = Index
End If
Next
End Sub

Public Sub UpdateAll()
On Error GoTo UpdateAll_Err:
If Not IsArrayInitialized(ScenarioUpdateList) Then
Exit Sub
End If
Dim i As Integer
For i = 0 To UBound(ScenarioUpdateList)
If Not ScenarioUpdateList(i) Is Nothing Then
Call ScenarioUpdateList(i).Update
For i = 0 To ActiveUpdateSlots.currentIndex - 1
If Not ScenarioUpdateList(ActiveUpdateSlots.IndexInfo(i)) Is Nothing Then
Call ScenarioUpdateList(ActiveUpdateSlots.IndexInfo(i)).Update
End If
Next
Exit Sub
Expand Down Expand Up @@ -257,16 +294,20 @@ UserCanDropItem_Err:
Call TraceError(Err.Number, Err.Description, "CustomScenarios.UserCanDropItem", Erl)
End Function

Public Sub PrepareNewEvent(ByVal eventType As e_EventType)
Public Sub PrepareNewEvent(ByVal eventType As e_EventType, ByVal LobbyIndex As Integer)
On Error GoTo PrepareNewEvent_Err:
Debug.Assert LobbyIndex < UBound(LobbyList)
Select Case EventType
Case e_EventType.NpcHunt
Set GenericGlobalLobby.scenario = New ScenarioHunt
Set LobbyList(LobbyIndex).Scenario = New ScenarioHunt
Case e_EventType.DeathMatch
Set GenericGlobalLobby.scenario = New ScenarioDeathMatch
Set LobbyList(LobbyIndex).Scenario = New ScenarioDeathMatch
Case e_EventType.NavalBattle
Set GenericGlobalLobby.Scenario = New NavalBoarding
Set LobbyList(LobbyIndex).Scenario = New NavalBoarding
End Select
If Not LobbyList(LobbyIndex).Scenario Is Nothing Then
LobbyList(LobbyIndex).Scenario.SetLobbyIndex (LobbyIndex)
End If
Exit Sub
PrepareNewEvent_Err:
Call TraceError(Err.Number, Err.Description, "CustomScenarios.PrepareNewEvent", Erl)
Expand Down Expand Up @@ -296,16 +337,20 @@ Public Function IsEventActive() As Boolean
If CurrentActiveEventType = CaptureTheFlag Then
IsEventActive = Not InstanciaCaptura Is Nothing
Else
IsEventActive = GenericGlobalLobby.State > e_LobbyState.UnInitilized And GenericGlobalLobby.State < Completed
If GlobalLobbyIndex >= 0 Then
IsEventActive = LobbyList(GlobalLobbyIndex).State > e_LobbyState.UnInitilized And LobbyList(GlobalLobbyIndex).State < InProgress
Else
IsEventActive = False
End If
End If
End Function

Public Sub UserDisconnected(ByVal mapNumber As Integer, ByVal userIndex As Integer)
Call RegisterDisconnectedUser(GenericGlobalLobby, userIndex)
Call RegisterDisconnectedUser(UserIndex)
End Sub

Public Sub UserConnected(ByVal userIndex)
Call RegisterReconnectedUser(GenericGlobalLobby, userIndex)
Call RegisterReconnectedUser(UserIndex)
End Sub

Public Sub GetNextWaypointForNpc(ByVal NpcIndex As Integer, ByRef PosX As Integer, ByRef PosY As Integer)
Expand Down
5 changes: 3 additions & 2 deletions Codigo/Declares.bas
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,6 @@ Public Const PinoWood As Integer = 3788 'OK
Public Const BLODIUM_MINA As Integer = 3787 'OK

Public Enum e_NPCType

Comun = 0
Revividor = 1
GuardiaReal = 2
Expand All @@ -576,7 +575,7 @@ Public Enum e_NPCType
EntregaPesca = 20
AO20Shop = 21
AO20ShopPjs = 22

EventMaster = 23
End Enum

Public Const MIN_APUÑALAR As Byte = 10
Expand Down Expand Up @@ -2753,6 +2752,7 @@ End Enum
Type t_MapInfo

map_name As String
MapResource As Integer
backup_mode As Byte
music_numberHi As Long
music_numberLow As Long
Expand Down Expand Up @@ -2861,6 +2861,7 @@ Public EnPausa As Boolean
Public EnTesting As Boolean
Public EnableTelemetry As Boolean
Public PendingConnectionTimeout As Long
Public InstanceMapCount As Integer

'*****************ARRAYS PUBLICOS*************************
Public UserList() As t_User 'USUARIOS
Expand Down
25 changes: 11 additions & 14 deletions Codigo/FileIO.bas
Original file line number Diff line number Diff line change
Expand Up @@ -1774,9 +1774,9 @@ Sub CargarBackUp()
116 frmCargando.cargar.value = 0
118 frmCargando.ToMapLbl.Visible = True

120 ReDim MapData(1 To NumMaps, XMinMapSize To XMaxMapSize, YMinMapSize To YMaxMapSize) As t_MapBlock
120 ReDim MapData(1 To (NumMaps + InstanceMapCount), XMinMapSize To XMaxMapSize, YMinMapSize To YMaxMapSize) As t_MapBlock

122 ReDim MapInfo(1 To NumMaps) As t_MapInfo
122 ReDim MapInfo(1 To (NumMaps + InstanceMapCount)) As t_MapInfo

124 For map = 1 To NumMaps
126 frmCargando.ToMapLbl = map & "/" & NumMaps
Expand Down Expand Up @@ -1823,17 +1823,14 @@ Sub LoadMapData()
End If

#End If

104 Call InitAreas

106 frmCargando.cargar.Min = 0
108 frmCargando.cargar.max = NumMaps
110 frmCargando.cargar.value = 0
112 frmCargando.ToMapLbl.Visible = True

114 ReDim MapData(1 To NumMaps, XMinMapSize To XMaxMapSize, YMinMapSize To YMaxMapSize) As t_MapBlock
114 ReDim MapData(1 To (NumMaps + InstanceMapCount), XMinMapSize To XMaxMapSize, YMinMapSize To YMaxMapSize) As t_MapBlock

116 ReDim MapInfo(1 To NumMaps) As t_MapInfo
116 ReDim MapInfo(1 To (NumMaps + InstanceMapCount)) As t_MapInfo

118 For map = 1 To NumMaps

Expand All @@ -1846,16 +1843,15 @@ Sub LoadMapData()
126 DoEvents

128 Next map

'Call generateMatrix(MATRIX_INITIAL_MAP)

130 frmCargando.ToMapLbl.Visible = False

Call InstanceManager.InitializeInstanceHeap(InstanceMapCount, NumMaps + 1)
NumMaps = NumMaps + InstanceMapCount
132 Call InitAreas
Exit Sub

man:
132 Call MsgBox("Error durante la carga de mapas, el mapa " & map & " contiene errores")
134 Call LogError(Date & " " & Err.Description & " " & Err.HelpContext & " " & Err.HelpFile & " " & Err.source)
Call MsgBox("Error durante la carga de mapas, el mapa " & Map & " contiene errores")
Call LogError(Date & " " & Err.Description & " " & Err.HelpContext & " " & Err.HelpFile & " " & Err.Source)

End Sub

Expand Down Expand Up @@ -2103,6 +2099,7 @@ Public Sub CargarMapaFormatoCSM(ByVal map As Long, ByVal MAPFl As String)
End If

340 MapInfo(map).map_name = MapDat.map_name
341 MapInfo(Map).MapResource = Map
342 MapInfo(map).ambient = MapDat.ambient
344 MapInfo(map).backup_mode = MapDat.backup_mode
346 MapInfo(map).base_light = MapDat.base_light
Expand Down Expand Up @@ -2224,7 +2221,7 @@ Sub LoadSini()
MinimumLevelMao = val(Lector.GetValue("INIT", "MinimumLevelMao"))
ServerSoloGMs = val(Lector.GetValue("init", "ServerSoloGMs"))
140 DisconnectTimeout = val(Lector.GetValue("INIT", "DisconnectTimeout"))

142 InstanceMapCount = val(Lector.GetValue("INIT", "InstanceMaps"))
144 EnTesting = val(Lector.GetValue("INIT", "Testing"))
145 EnableTelemetry = val(Lector.GetValue("INIT", "EnableTelemetry"))
146 PendingConnectionTimeout = val(Lector.GetValue("INIT", "PendingConnectionTimeout"))
Expand Down
2 changes: 1 addition & 1 deletion Codigo/General.bas
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ Sub Main()
120 frmCargando.Label1(2).Caption = "Iniciando Arrays..."

Call InitializeNpcIndexHeap

Call InitializeLobbyList
126 Call loadAdministrativeUsers

'¿?¿?¿?¿?¿?¿?¿?¿ CARGAMOS DATOS DESDE ARCHIVOS ¿??¿?¿?¿?¿?¿?¿?¿
Expand Down
3 changes: 3 additions & 0 deletions Codigo/IBaseScenario.cls
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ Attribute VB_Exposed = False
'
Option Explicit

Public Sub SetLobbyIndex(ByVal Value As Integer)
End Sub

Public Function GetScenarioName() As String
End Function
Public Sub BroadcastOpenScenario(ByVal CreatorIndex As Integer)
Expand Down
80 changes: 80 additions & 0 deletions Codigo/InstanceManager.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
Attribute VB_Name = "InstanceManager"
Option Explicit


Private AvailableInstanceMap As t_IndexHeap
Public Type t_TranslationMapping
OriginalTarget As Integer
NewTarget As Integer
End Type

Public Sub InitializeInstanceHeap(ByVal Size As Integer, ByVal MapIndexStart As Integer)
On Error GoTo ErrHandler_InitializeInstanceHeap
ReDim AvailableInstanceMap.IndexInfo(Size)
Dim i As Integer
For i = 1 To Size
AvailableInstanceMap.IndexInfo(i) = Size - (i - 1) + MapIndexStart
Next i
AvailableInstanceMap.currentIndex = Size
Exit Sub
ErrHandler_InitializeInstanceHeap:
Call TraceError(Err.Number, Err.Description, "InstanceManager.InitializeInstanceHeap", Erl)
End Sub

Public Function ReleaseInstance(ByVal InstanceMapIndex As Integer) As Boolean
On Error GoTo ErrHandler
AvailableInstanceMap.currentIndex = AvailableInstanceMap.currentIndex + 1
Debug.Assert AvailableInstanceMap.currentIndex <= UBound(AvailableInstanceMap.IndexInfo)
AvailableInstanceMap.IndexInfo(AvailableInstanceMap.currentIndex) = InstanceMapIndex
ReleaseInstance = True
MapInfo(InstanceMapIndex).MapResource = 0
Exit Function
ErrHandler:
ReleaseInstance = False
Call TraceError(Err.Number, Err.Description, "InstanceManager.ReleaseInstance", Erl)
End Function

Public Function GetAvailableInstanceCount() As Integer
GetAvailableInstanceCount = AvailableInstanceMap.currentIndex
End Function

Public Function GetNextAvailableInstance() As Integer
On Error GoTo ErrHandler
If (AvailableInstanceMap.currentIndex = 0) Then
GetNextAvailableInstance = -1
Exit Function
End If
GetNextAvailableInstance = AvailableInstanceMap.IndexInfo(AvailableInstanceMap.currentIndex)
AvailableInstanceMap.currentIndex = AvailableInstanceMap.currentIndex - 1
Exit Function
ErrHandler:
Call TraceError(Err.Number, Err.Description, "InstanceManager.GetNextAvailableInstance", Erl)
End Function

Public Sub CloneMap(ByVal SourceMapIndex As Integer, ByVal DestMapIndex As Integer)
Dim Translations(0) As t_TranslationMapping
Call CloneMapWithTranslations(SourceMapIndex, DestMapIndex, Translations)
End Sub

Public Sub CloneMapWithTranslations(ByVal SourceMapIndex As Integer, ByVal DestMapIndex As Integer, ByRef TranslationMappings() As t_TranslationMapping)
MapInfo(DestMapIndex) = MapInfo(SourceMapIndex)
MapInfo(DestMapIndex).MapResource = SourceMapIndex
Dim PosX As Integer
Dim PosY As Integer
Dim PerformanceTimer As Long
Dim i As Integer
Call PerformanceTestStart(PerformanceTimer)
For PosY = YMinMapSize To YMaxMapSize
For PosX = XMinMapSize To XMaxMapSize
MapData(DestMapIndex, PosX, PosY) = MapData(SourceMapIndex, PosX, PosY)
If (MapData(DestMapIndex, PosX, PosY).TileExit.Map > 0) Then
For i = LBound(TranslationMappings) To UBound(TranslationMappings)
If MapData(DestMapIndex, PosX, PosY).TileExit.Map = TranslationMappings(i).OriginalTarget Then
MapData(DestMapIndex, PosX, PosY).TileExit.Map = TranslationMappings(i).NewTarget
End If
Next i
End If
Next PosX
Next PosY
Call PerformTimeLimitCheck(PerformanceTimer, "CloneMapWithTranslations time", 50)
End Sub
7 changes: 6 additions & 1 deletion Codigo/LocaleDef.bas
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ Public Const MsgInventoryIsFull = 328
Public Const MsgCantJoinEventDeath = 368
Public Const MsgCantAttackYourself = 380
Public Const MSgNpcInmuneToEffect = 381
Public Const ForbiddenLevelMessage = 396
Public Const LobbyIsFullMessage = 397
Public Const ForbiddenClassMessage = 398
Public Const JoinSuccessMessage = 399
Public Const AlreadyRegisteredMessage = 405
Public Const MsgInvalidGroupCount = 406
Public Const MsgCantChangeGroupSizeNow = 407
Public Const MsgInvalidUserState = 408
Expand Down Expand Up @@ -109,7 +114,7 @@ Public Const MsgNavalBattleWinBroadcast = 485
Public Const MsgNavalBattleRewardBroadcast = 486
Public Const MsgBoardcastInscriptionPrice = 487
Public Const MsgMatchComplete = 488

Public Const MsgInvalidPassword = 489

Public Function GetRequiredWeaponLocaleId(ByVal WeaponType As e_WeaponType) As Integer
Select Case WeaponType
Expand Down
Loading

0 comments on commit cd135ca

Please sign in to comment.