Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Sub HandleLearnSpell(ByVal UserIndex)
- '##########################################
- 'Author: MAB
- 'Date: 22/11/2016
- 'Chequeo si posee el oro y los items, los descuento y le entrego el hechizo
- '##########################################
- On Error GoTo Errhandler
- With UserList(UserIndex)
- Call .incomingData.ReadByte
- Dim ID As Byte
- Dim i As Integer
- Dim Gld As Long
- Dim ObjIndex As Integer
- Dim Amount As Integer
- Dim LoopA As Integer
- Dim LoopB As Integer
- Dim LoopC As Integer
- Dim LoopD As Integer
- Dim NoTiene As Integer
- Dim TienePeroNoEs As Integer
- Dim TienePeroNoAlcanza As Integer
- Dim Tenia As Integer
- ID = .incomingData.ReadByte
- NoTiene = 0
- TienePeroNoEs = 0
- TienePeroNoAlcanza = 0
- Tenia = 0
- For i = 1 To ConfigHechiceria.Cantidad
- 'Si el index es igual al ID que enviamos desde el cliente
- If ConfigHechiceria.Hechizo(i).HechizoIndex = ID Then
- 'Asignamos el oro de este hechizo (ID) a la variable Gld
- Gld = ConfigHechiceria.Hechizo(i).Costo
- 'Si el oro del usuario es menor al que se necesita para aprender el hechizo o si directamente no posee oro
- If .Stats.Gld < Gld Or .Stats.Gld = 0 Then
- Call WriteConsoleMsg(UserIndex, "No posees la cantidad suficiente de monedas de bronce para aprender este hechizo.", FontTypeNames.FONTTYPE_INFO)
- Exit Sub
- Else
- 'Si no requiere items y con el oro alcanza, restamos el oro y le damos el hechizo
- If ConfigHechiceria.Hechizo(i).ItemsRequeridos = 0 Then
- If Not TieneHechizo(ID, UserIndex) Then
- For LoopD = 1 To MAXUSERHECHIZOS
- If .Stats.UserHechizos(LoopD) = 0 Then Exit For
- Next LoopD
- If .Stats.UserHechizos(LoopD) <> 0 Then
- Call WriteConsoleMsg(UserIndex, "No tienes espacio para más hechizos.", FontTypeNames.FONTTYPE_INFO)
- Exit Sub
- Else
- UserList(UserIndex).Stats.Gld = UserList(UserIndex).Stats.Gld - Gld
- Call Protocol.WriteUpdateGold(UserIndex)
- .Stats.UserHechizos(LoopD) = ID
- Call UpdateUserHechizos(False, UserIndex, CByte(LoopD))
- Call WriteConsoleMsg(UserIndex, "Has aprendido el hechizo: " & ConfigHechiceria.Hechizo(i).Nombre & ".", FontTypeNames.FONTTYPE_INFO)
- Exit Sub
- End If
- Else
- Call WriteConsoleMsg(UserIndex, "Ya tienes ese hechizo.", FontTypeNames.FONTTYPE_INFO)
- Exit Sub
- End If
- 'Si requiere items
- ElseIf ConfigHechiceria.Hechizo(i).ItemsRequeridos > 0 Then
- 'Redimensiono el Array para guardar los slots de los items requeridos
- ReDim ArraySlot(1 To ConfigHechiceria.Hechizo(i).ItemsRequeridos) As nhArray
- 'Loop Inventario
- For LoopA = 1 To MAX_INVENTORY_SLOTS
- 'Tiene un item en el slot?
- If .Invent.Object(LoopA).ObjIndex > 0 Then
- 'Recorramos los items requeridos
- For LoopB = 1 To ConfigHechiceria.Hechizo(i).ItemsRequeridos
- ObjIndex = ConfigHechiceria.Hechizo(i).Item(LoopB).ObjIndex
- Amount = ConfigHechiceria.Hechizo(i).Item(LoopB).Amount
- 'El item es el mismo?
- If .Invent.Object(LoopA).ObjIndex = ObjIndex Then
- 'Tiene la misma cantidad que solicitamos?
- If .Invent.Object(LoopA).Amount >= Amount Then
- 'Me guardo el slot donde esta el item y me guardo la cantidad que requiere
- ArraySlot(LoopB).Slot = LoopA
- ArraySlot(LoopB).Cantidad = Amount
- 'Le decimos que tenia
- Tenia = Tenia + 1
- Else
- 'Si tiene pero no le alcanza
- TienePeroNoAlcanza = TienePeroNoAlcanza + 1
- 'Si llegamos hasta acá es porque no le alcanza
- If TienePeroNoAlcanza = ConfigHechiceria.Hechizo(i).ItemsRequeridos Then
- Call WriteConsoleMsg(UserIndex, "La cantidad de " & ObjData(ConfigHechiceria.Hechizo(i).Item(LoopB).ObjIndex).Name & " no es suficiente.", FontTypeNames.FONTTYPE_INFO)
- Exit Sub
- End If
- End If
- Else
- 'Si no es el mismo item
- TienePeroNoEs = TienePeroNoEs + 1
- If TienePeroNoEs = (.Invent.NroItems * ConfigHechiceria.Hechizo(i).ItemsRequeridos) Then
- Call WriteConsoleMsg(UserIndex, "No posees los items necesarios.", FontTypeNames.FONTTYPE_INFO)
- Exit Sub
- End If
- End If
- Next LoopB
- Else
- 'Tiene el slot vacío
- NoTiene = NoTiene + 1
- 'Si todos los slots están vacíos
- If NoTiene = MAX_INVENTORY_SLOTS Then
- Call WriteConsoleMsg(UserIndex, "No posees ningún item en tu inventario.", FontTypeNames.FONTTYPE_INFO)
- Exit Sub
- End If
- End If
- Next LoopA
- If Tenia = ConfigHechiceria.Hechizo(i).ItemsRequeridos Then
- If Not TieneHechizo(ID, UserIndex) Then
- 'Buscamos un slot vacio
- For LoopD = 1 To MAXUSERHECHIZOS
- If .Stats.UserHechizos(LoopD) = 0 Then Exit For
- Next LoopD
- If .Stats.UserHechizos(LoopD) <> 0 Then
- Call WriteConsoleMsg(UserIndex, "No tienes espacio para más hechizos.", FontTypeNames.FONTTYPE_INFO)
- Exit Sub
- Else
- For LoopC = 1 To ConfigHechiceria.Hechizo(i).ItemsRequeridos
- 'Remuevo los items de sus slots
- Call QuitarUserInvItem(UserIndex, ArraySlot(LoopC).Slot, ArraySlot(LoopC).Cantidad)
- 'Actualizamos inventario
- Call UpdateUserInv(False, UserIndex, ArraySlot(LoopC).Slot)
- Next LoopC
- 'Si terminó de recorrer entonces descontamos el oro
- UserList(UserIndex).Stats.Gld = UserList(UserIndex).Stats.Gld - Gld
- Call Protocol.WriteUpdateGold(UserIndex)
- 'Le entregamos el hechizo
- .Stats.UserHechizos(LoopD) = ID
- Call UpdateUserHechizos(False, UserIndex, CByte(LoopD))
- Call WriteConsoleMsg(UserIndex, "Has aprendido el hechizo: " & ConfigHechiceria.Hechizo(i).Nombre & ".", FontTypeNames.FONTTYPE_INFO)
- Exit Sub
- End If
- Else
- Call WriteConsoleMsg(UserIndex, "Ya tienes ese hechizo.", FontTypeNames.FONTTYPE_INFO)
- Exit Sub
- End If
- End If
- End If
- End If
- End If
- Next i
- End With
- Exit Sub
- Errhandler:
- If Err.Number = UserList(UserIndex).outgoingData.NotEnoughSpaceErrCode Then
- Call FlushBuffer(UserIndex)
- Resume
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement