From 4c1b879b7a7360bc4eee9347e4962766db7b6687 Mon Sep 17 00:00:00 2001 From: matiascalegaris Date: Thu, 24 Aug 2023 16:26:26 -0300 Subject: [PATCH] Add hk support for testing --- Codigo/Declares.bas | 25 +++++-- Codigo/EffectsOverTime.bas | 2 +- Codigo/FileIO.bas | 16 +++++ Codigo/Matematicas.bas | 2 +- Codigo/Modulo_UsUaRiOs.bas | 12 +++- Codigo/Protocol.bas | 136 +++++++++++++++++++++---------------- Codigo/Protocol_Writes.bas | 26 ++++++- Codigo/frmMain.frm | 2 +- Codigo/modHechizos.bas | 46 +++++++++++++ 9 files changed, 197 insertions(+), 70 deletions(-) diff --git a/Codigo/Declares.bas b/Codigo/Declares.bas index 4e359e83..1bb7e600 100644 --- a/Codigo/Declares.bas +++ b/Codigo/Declares.bas @@ -967,6 +967,7 @@ Public Enum e_SpellRequirementMask eRequireTargetOnWater = 1024 eWorkOnDead = 2048 eIsSkill = 4096 + eIsBindable = 8192 End Enum Public Enum e_SpellEffects @@ -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 @@ -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 @@ -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] @@ -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 @@ -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 diff --git a/Codigo/EffectsOverTime.bas b/Codigo/EffectsOverTime.bas index ff9e47fd..df0c2420 100644 --- a/Codigo/EffectsOverTime.bas +++ b/Codigo/EffectsOverTime.bas @@ -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) diff --git a/Codigo/FileIO.bas b/Codigo/FileIO.bas index 8e1f51e1..78c6275b 100644 --- a/Codigo/FileIO.bas +++ b/Codigo/FileIO.bas @@ -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")) @@ -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 @@ -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 diff --git a/Codigo/Matematicas.bas b/Codigo/Matematicas.bas index ecb59184..8ab0e7a7 100644 --- a/Codigo/Matematicas.bas +++ b/Codigo/Matematicas.bas @@ -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 diff --git a/Codigo/Modulo_UsUaRiOs.bas b/Codigo/Modulo_UsUaRiOs.bas index 7cb84277..3889372f 100644 --- a/Codigo/Modulo_UsUaRiOs.bas +++ b/Codigo/Modulo_UsUaRiOs.bas @@ -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 @@ -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 @@ -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 diff --git a/Codigo/Protocol.bas b/Codigo/Protocol.bas index 2c5d1a64..c2c89d97 100644 --- a/Codigo/Protocol.bas +++ b/Codigo/Protocol.bas @@ -232,6 +232,7 @@ Public Enum ServerPacketID UpdateGroupInfo RequestTelemetry UpdateCharValue + SendClientToggles #If PYMMO = 0 Then AccountCharacterList #End If @@ -560,6 +561,8 @@ Public Enum ClientPacketID FeatureToggle ActionOnGroupFrame SendTelemetry + SetHotkeySlot + UseHKeySlot #If PYMMO = 0 Then CreateAccount LoginAccount @@ -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) @@ -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 '' @@ -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 + + diff --git a/Codigo/Protocol_Writes.bas b/Codigo/Protocol_Writes.bas index c6c928e9..984c8ff2 100644 --- a/Codigo/Protocol_Writes.bas +++ b/Codigo/Protocol_Writes.bas @@ -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) ' Exit Sub @@ -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) ' Exit Sub @@ -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 + diff --git a/Codigo/frmMain.frm b/Codigo/frmMain.frm index 8e3c21f5..e5b70854 100644 --- a/Codigo/frmMain.frm +++ b/Codigo/frmMain.frm @@ -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 diff --git a/Codigo/modHechizos.bas b/Codigo/modHechizos.bas index ca187ff7..a6918a0c 100644 --- a/Codigo/modHechizos.bas +++ b/Codigo/modHechizos.bas @@ -4558,3 +4558,49 @@ Private Sub AdjustNpcStatWithCasterLevel(ByVal UserIndex As Integer, ByVal NpcIn .Stats.MaxHit = .Stats.MaxHit + .Stats.MaxHit * BonusDamage End With End Sub + +Public Sub UseSpellSlot(ByVal UserIndex As Integer, ByVal SpellSlot As Integer) + On Error GoTo UseSpellSlot_Err +100 With UserList(UserIndex) + +104 If .flags.Muerto = 1 Then +106 Call WriteLocaleMsg(UserIndex, 77, e_FontTypeNames.FONTTYPE_INFO) + Exit Sub + + End If + +108 .flags.Hechizo = SpellSlot + 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(SpellSlot) <> 0 Then +120 If Hechizos(.Stats.UserHechizos(SpellSlot)).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(SpellSlot)).AreaAfecta > 0 Then +126 Call WriteWorkRequestTarget(UserIndex, e_Skill.Magia, True, Hechizos(.Stats.UserHechizos(SpellSlot)).AreaRadio) + Else + Call WriteWorkRequestTarget(UserIndex, e_Skill.Magia) + End If + End If + End If + End If + End If + End With + Exit Sub +UseSpellSlot_Err: +128 Call TraceError(Err.Number, Err.Description, "Protocol.UseSpellSlot", Erl) +End Sub