Skip to content

Commit

Permalink
Merge pull request #360 from ao-org/add-hk-support
Browse files Browse the repository at this point in the history
Add hk support for testing
  • Loading branch information
RecoX authored Aug 24, 2023
2 parents 1b7e83c + 4c1b879 commit 3ac18f8
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 70 deletions.
25 changes: 19 additions & 6 deletions Codigo/Declares.bas
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ Public Enum e_SpellRequirementMask
eRequireTargetOnWater = 1024
eWorkOnDead = 2048
eIsSkill = 4096
eIsBindable = 8192
End Enum

Public Enum e_SpellEffects
Expand Down Expand Up @@ -1463,6 +1464,9 @@ Public Type t_Retos
End Type
' **************************************************

Public Enum e_ObjFlags
e_Bindable = 1
End Enum
'Tipos de objetos
Public Type t_ObjData
Pino As Byte
Expand All @@ -1475,15 +1479,10 @@ Public Type t_ObjData
ParticulaGolpe As Integer
ParticulaViaje As Integer
Jerarquia As Long

ClaseTipo As Byte

TipoRuna As Byte

Name As String 'Nombre del obj

OBJType As e_OBJType 'Tipo enum que determina cuales son las caract del obj

GrhIndex As Long ' Indice del grafico que representa el obj
GrhSecundario As Integer

Expand Down Expand Up @@ -1672,6 +1671,7 @@ Public Type t_ObjData
ObjDonador As Long
WeaponType As e_WeaponType
ProjectileType As Integer
ObjFlags As Long 'use bitmask from enum e_ObjFlags
End Type

'[Pablo ToxicWaste]
Expand Down Expand Up @@ -2257,6 +2257,19 @@ Public Type t_EffectOverTimeList
EffectCount As Integer
End Type

Public Enum e_HotkeyType
Item = 1
Spell = 2
Unknown = 3
End Enum

Public Type t_HotkeyEntry
Type As e_HotkeyType
Index As Integer
LastKnownSlot As Integer
End Type

Public Const HotKeyCount As Integer = 10
'Tipo de los Usuarios
Public Type t_User

Expand Down Expand Up @@ -2352,7 +2365,7 @@ Public Type t_User
QuestStats As t_QuestStats

Keys(1 To MAXKEYS) As Integer

HotkeyList(HotKeyCount) As t_HotkeyEntry
CraftInventory(1 To MAX_SLOTS_CRAFTEO) As Integer
CraftCatalyst As t_Obj
CraftResult As clsCrafteo
Expand Down
2 changes: 1 addition & 1 deletion Codigo/EffectsOverTime.bas
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ On Error GoTo CreateEffect_Err
End Select
Exit Sub
CreateEffect_Err:
Call TraceError(Err.Number, Err.Description, "EffectsOverTime.CreateEffect", Erl)
Call TraceError(Err.Number, Err.Description, "EffectsOverTime.CreateEffect EffectIndex:" & EffectIndex, Erl)
End Sub

Public Sub CreateTrap(ByVal SourceIndex As Integer, ByVal SourceType As e_ReferenceType, ByVal map As Integer, ByVal TileX As Integer, ByVal TileY As Integer, ByVal EffectTypeId As Integer)
Expand Down
16 changes: 16 additions & 0 deletions Codigo/FileIO.bas
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ Public Sub CargarHechizos()
If val(Leer.GetValue("Hechizo" & Hechizo, "RequireTargetOnWater")) > 0 Then Call SetMask(Hechizos(Hechizo).SpellRequirementMask, e_SpellRequirementMask.eRequireTargetOnWater)
If val(Leer.GetValue("Hechizo" & Hechizo, "WorkOnDead")) > 0 Then Call SetMask(Hechizos(Hechizo).SpellRequirementMask, e_SpellRequirementMask.eWorkOnDead)
If val(Leer.GetValue("Hechizo" & Hechizo, "IsSkill")) > 0 Then Call SetMask(Hechizos(Hechizo).SpellRequirementMask, e_SpellRequirementMask.eIsSkill)
If val(Leer.GetValue("Hechizo" & Hechizo, "IsBindable")) > 0 Then Call SetMask(Hechizos(Hechizo).SpellRequirementMask, e_SpellRequirementMask.eIsBindable)
305 Hechizos(Hechizo).RequireWeaponType = val(Leer.GetValue("Hechizo" & Hechizo, "RequireWeaponType"))
Dim SubeHP As Byte
SubeHP = val(Leer.GetValue("Hechizo" & Hechizo, "SubeHP"))
Expand Down Expand Up @@ -1287,6 +1288,7 @@ Sub LoadOBJData()
161 .ImprovedRangedHitChance = val(Leer.GetValue(ObjKey, "ImprovedRHit"))
.ImprovedMeleeHitChance = val(Leer.GetValue(ObjKey, "ImprovedMHit"))
.ApplyEffectId = val(Leer.GetValue(ObjKey, "ApplyEffectId"))
If val(Leer.GetValue(ObjKey, "Bindable")) > 0 Then Call SetMask(.ObjFlags, e_ObjFlags.e_Bindable)
Dim i As Integer

162 Select Case .OBJType
Expand Down Expand Up @@ -3508,3 +3510,17 @@ Public Sub SetFeatureToggle(ByVal Name As String, ByVal State As Boolean)
End If
Call FeatureToggles.Add(Name, State)
End Sub

Public Function GetActiveToggles(ByRef ActiveCount As Integer) As String()
Dim key As Variant
Dim ActiveKeys() As String
ReDim ActiveKeys(FeatureToggles.count) As String
ActiveCount = 0
For Each key In FeatureToggles.Keys
If FeatureToggles.Item(key) Then
ActiveKeys(ActiveCount) = key
ActiveCount = ActiveCount + 1
End If
Next key
GetActiveToggles = ActiveKeys
End Function
2 changes: 1 addition & 1 deletion Codigo/Matematicas.bas
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Public Sub SetMask(ByRef mask As Long, ByVal value As Long)
mask = mask Or value
End Sub

Public Function IsSet(ByVal mask As Long, ByVal value As Long)
Public Function IsSet(ByVal Mask As Long, ByVal Value As Long) As Boolean
IsSet = (mask And value) > 0
End Function

Expand Down
12 changes: 10 additions & 2 deletions Codigo/Modulo_UsUaRiOs.bas
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ On Error GoTo Complete_ConnectUser_Err

Dim n As Integer
Dim tStr As String
98 Call SendData(SendTarget.ToIndex, UserIndex, PrepareActiveToggles)
100 With UserList(UserIndex)

105 If .flags.Paralizado = 1 Then
Expand Down Expand Up @@ -272,7 +272,13 @@ On Error GoTo Complete_ConnectUser_Err
200 .Invent.WeaponEqpSlot = 0
End If
End If


' clear hotkey settings, the client should set this
For n = 0 To HotKeyCount - 1
.HotkeyList(n).Index = -1
.HotkeyList(n).LastKnownSlot = -1
.HotkeyList(n).Type = Unknown
Next n
'Obtiene el indice-objeto del armadura
205 If .Invent.ArmourEqpSlot > 0 Then
210 If .Invent.Object(.Invent.ArmourEqpSlot).ObjIndex > 0 Then
Expand Down Expand Up @@ -649,6 +655,8 @@ On Error GoTo Complete_ConnectUser_Err

995 Call WriteFYA(UserIndex)
1000 Call WriteBindKeys(UserIndex)



1005 If .NroMascotas > 0 And MapInfo(.pos.Map).NoMascotas = 0 And .flags.MascotasGuardadas = 0 Then
Dim i As Integer
Expand Down
136 changes: 78 additions & 58 deletions Codigo/Protocol.bas
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ Public Enum ServerPacketID
UpdateGroupInfo
RequestTelemetry
UpdateCharValue
SendClientToggles
#If PYMMO = 0 Then
AccountCharacterList
#End If
Expand Down Expand Up @@ -560,6 +561,8 @@ Public Enum ClientPacketID
FeatureToggle
ActionOnGroupFrame
SendTelemetry
SetHotkeySlot
UseHKeySlot
#If PYMMO = 0 Then
CreateAccount
LoginAccount
Expand Down Expand Up @@ -1408,6 +1411,10 @@ On Error Resume Next
Call HandleActionOnGroupFrame(UserIndex)
Case ClientPacketID.SendTelemetry
Call HandleSendTelemetry(UserIndex)
Case ClientPacketID.SetHotkeySlot
Call HandleSetHotkeySlot(UserIndex)
Case ClientPacketID.UseHKeySlot
Call HandleUseHKeySlot(UserIndex)
#If PYMMO = 0 Then
Case ClientPacketID.CreateAccount
Call HandleCreateAccount(userindex)
Expand Down Expand Up @@ -2968,67 +2975,17 @@ End Function
' Handles the "CastSpell" message.
' @param UserIndex The index of the user sending the message.
Private Sub HandleCastSpell(ByVal UserIndex As Integer)
On Error GoTo HandleCastSpell_Err
100 With UserList(UserIndex)
Dim Spell As Byte
102 Spell = Reader.ReadInt8()
Dim PacketCounter As Long
PacketCounter = Reader.ReadInt32
Dim Packet_ID As Long
Packet_ID = PacketNames.CastSpell

104 If .flags.Muerto = 1 Then
106 Call WriteLocaleMsg(UserIndex, "77", e_FontTypeNames.FONTTYPE_INFO)
Exit Sub

End If

108 .flags.Hechizo = Spell
If UserMod.IsStun(.flags, .Counters) Then
Call WriteLocaleMsg(UserIndex, "394", e_FontTypeNames.FONTTYPE_INFO)
Exit Sub
End If


110 If .flags.Hechizo < 1 Or .flags.Hechizo > MAXUSERHECHIZOS Then
112 .flags.Hechizo = 0
End If

114 If .flags.Hechizo <> 0 Then

116 If (.flags.Privilegios And e_PlayerType.Consejero) = 0 Then

If .Stats.UserHechizos(Spell) <> 0 Then

120 If Hechizos(.Stats.UserHechizos(Spell)).AutoLanzar = 1 Then
122 Call SetUserRef(UserList(userIndex).flags.targetUser, userIndex)
124 Call LanzarHechizo(.flags.Hechizo, UserIndex)
Else
If IsValidUserRef(.flags.GMMeSigue) Then
Call WriteNofiticarClienteCasteo(.flags.GMMeSigue.ArrayIndex, 1)
End If

If Hechizos(.Stats.UserHechizos(Spell)).AreaAfecta > 0 Then
126 Call WriteWorkRequestTarget(UserIndex, e_Skill.Magia, True, Hechizos(.Stats.UserHechizos(Spell)).AreaRadio)
Else
Call WriteWorkRequestTarget(UserIndex, e_Skill.Magia)
End If
End If

End If

End If

End If

End With

On Error GoTo HandleCastSpell_Err
Dim Spell As Byte
Spell = Reader.ReadInt8()
Dim PacketCounter As Long
PacketCounter = Reader.ReadInt32
Dim Packet_ID As Long
Packet_ID = PacketNames.CastSpell
Call UseSpellSlot(UserIndex, Spell)
Exit Sub

HandleCastSpell_Err:
128 Call TraceError(Err.Number, Err.Description, "Protocol.HandleCastSpell", Erl)
130

End Sub

''
Expand Down Expand Up @@ -11374,3 +11331,66 @@ On Error GoTo HandleSendTelemetry_Err:
HandleSendTelemetry_Err:
Call TraceError(Err.Number, Err.Description, "Protocol.HandleSendTelemetry", Erl)
End Sub

Public Sub HandleSetHotkeySlot(ByVal UserIndex As Integer)
On Error GoTo HandleSetHotkeySlot_Err:

With UserList(UserIndex)
Dim SlotIndex As Byte
Dim TargetIndex As Integer
Dim LastKnownSlot As Integer
Dim HkType As Byte
SlotIndex = Reader.ReadInt8
TargetIndex = Reader.ReadInt16
LastKnownSlot = Reader.ReadInt16
HkType = Reader.ReadInt8

.HotkeyList(SlotIndex).Index = TargetIndex
.HotkeyList(SlotIndex).LastKnownSlot = LastKnownSlot
.HotkeyList(SlotIndex).Type = HkType
End With
Exit Sub
HandleSetHotkeySlot_Err:
Call TraceError(Err.Number, Err.Description, "Protocol.HandleSetHotkeySlot", Erl)
End Sub

Public Sub HandleUseHKeySlot(ByVal UserIndex As Integer)
On Error GoTo HandleUseHKeySlot_Err:
Dim SlotIndex As Byte
SlotIndex = Reader.ReadInt8
If Not IsFeatureEnabled("hotokey-enabled") Then Exit Sub
Dim CurrentSlotIndex As Integer
Dim i As Integer
With UserList(UserIndex)
If .HotkeyList(SlotIndex).Index > 0 Then
If .HotkeyList(SlotIndex).Type = Item Then
ElseIf .HotkeyList(SlotIndex).Type = Spell Then
If .HotkeyList(SlotIndex).LastKnownSlot > 0 And .HotkeyList(SlotIndex).LastKnownSlot < UBound(.Stats.UserHechizos) Then
If .Stats.UserHechizos(.HotkeyList(SlotIndex).LastKnownSlot) = .HotkeyList(SlotIndex).Index Then
CurrentSlotIndex = .HotkeyList(SlotIndex).LastKnownSlot
End If
End If
If CurrentSlotIndex = 0 Then
For i = LBound(.Stats.UserHechizos) To UBound(.Stats.UserHechizos)
If .Stats.UserHechizos(i) = .HotkeyList(SlotIndex).Index Then
CurrentSlotIndex = i
Exit For
End If
Next i
End If
If CurrentSlotIndex > 0 Then
If .Stats.UserHechizos(CurrentSlotIndex) > 0 Then
If IsSet(Hechizos(UserList(UserIndex).Stats.UserHechizos(CurrentSlotIndex)).SpellRequirementMask, e_SpellRequirementMask.eIsBindable) Then
Call UseSpellSlot(UserIndex, CurrentSlotIndex)
End If
End If
End If
End If
End If
End With
Exit Sub
HandleUseHKeySlot_Err:
Call TraceError(Err.Number, Err.Description, "Protocol.HandleUseHKeySlot", Erl)
End Sub


26 changes: 25 additions & 1 deletion Codigo/Protocol_Writes.bas
Original file line number Diff line number Diff line change
Expand Up @@ -1967,6 +1967,11 @@ Public Sub WriteChangeInventorySlot(ByVal UserIndex As Integer, ByVal Slot As By
114 Call Writer.WriteBool(UserList(UserIndex).Invent.Object(Slot).Equipped)
116 Call Writer.WriteReal32(SalePrice(ObjIndex))
118 Call Writer.WriteInt8(PodraUsarlo)
If ObjIndex > 0 Then
119 Call Writer.WriteBool(IsSet(ObjData(ObjIndex).ObjFlags, e_ObjFlags.e_Bindable))
Else
Call Writer.WriteBool(False)
End If
120 Call modSendData.SendData(ToIndex, UserIndex)
'<EhFooter>
Exit Sub
Expand Down Expand Up @@ -2033,10 +2038,12 @@ Public Sub WriteChangeSpellSlot(ByVal UserIndex As Integer, ByVal Slot As Intege

106 If UserList(UserIndex).Stats.UserHechizos(Slot) > 0 Then
108 Call Writer.WriteInt16(UserList(UserIndex).Stats.UserHechizos(Slot))
Call Writer.WriteBool(IsSet(Hechizos(UserList(UserIndex).Stats.UserHechizos(Slot)).SpellRequirementMask, e_SpellRequirementMask.eIsBindable))
Else
110 Call Writer.WriteInt16(-1)
Call Writer.WriteBool(False)
End If

112 Call modSendData.SendData(ToIndex, UserIndex)
'<EhFooter>
Exit Sub
Expand Down Expand Up @@ -5824,3 +5831,20 @@ PrepareMessageDoAnimation_Err:
Call TraceError(Err.Number, Err.Description, "Argentum20Server.Protocol_Writes.PrepareMessageDoAnimation", Erl)
End Function

Public Function PrepareActiveToggles()
On Error GoTo PrepareActiveToggles_Err
100 Call Writer.WriteInt16(ServerPacketID.SendClientToggles)
Dim ActiveToggles() As String
Dim ActiveToggleCount As Integer
ActiveToggles = GetActiveToggles(ActiveToggleCount)
Call Writer.WriteInt16(ActiveToggleCount)
Dim i As Integer
For i = 0 To ActiveToggleCount - 1
Call Writer.WriteString8(ActiveToggles(i))
Next i
Exit Function
PrepareActiveToggles_Err:
Call Writer.Clear
Call TraceError(Err.Number, Err.Description, "Argentum20Server.Protocol_Writes.PrepareActiveToggles", Erl)
End Function

2 changes: 1 addition & 1 deletion Codigo/frmMain.frm
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ On Error GoTo Handler

If UserGuardados > NumUsers Then Exit For
'limit the amount of time we block the only thread we have here, lets save some user on the next loop
If (GetTickCount - PerformanceTimer) > IntervaloGuardarUsuarios Then Exit For
If (GetTickCount - PerformanceTimer) > 100 Then Exit For
End If

End If
Expand Down
Loading

0 comments on commit 3ac18f8

Please sign in to comment.