Advertisement
Guest User

locuratotal123

a guest
Apr 28th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Sub HandleLearnSpell(ByVal UserIndex)
  2. '##########################################
  3. 'Author: MAB
  4. 'Date: 22/11/2016
  5. 'Chequeo si posee el oro y los items, los descuento y le entrego el hechizo
  6. '##########################################
  7. On Error GoTo Errhandler
  8.  
  9.     With UserList(UserIndex)
  10.    
  11.         Call .incomingData.ReadByte
  12.        
  13.         Dim ID As Byte
  14.         Dim i As Integer
  15.        
  16.         Dim Gld As Long
  17.         Dim ObjIndex As Integer
  18.         Dim Amount As Integer
  19.        
  20.         Dim LoopA As Integer
  21.         Dim LoopB As Integer
  22.         Dim LoopC As Integer
  23.         Dim LoopD As Integer
  24.        
  25.         Dim NoTiene As Integer
  26.         Dim TienePeroNoEs As Integer
  27.         Dim TienePeroNoAlcanza As Integer
  28.         Dim Tenia As Integer
  29.        
  30.         ID = .incomingData.ReadByte
  31.         NoTiene = 0
  32.         TienePeroNoEs = 0
  33.         TienePeroNoAlcanza = 0
  34.         Tenia = 0
  35.        
  36.         For i = 1 To ConfigHechiceria.Cantidad
  37.             'Si el index es igual al ID que enviamos desde el cliente
  38.            If ConfigHechiceria.Hechizo(i).HechizoIndex = ID Then
  39.                 'Asignamos el oro de este hechizo (ID) a la variable Gld
  40.                Gld = ConfigHechiceria.Hechizo(i).Costo
  41.                
  42.                 'Si el oro del usuario es menor al que se necesita para aprender el hechizo o si directamente no posee oro
  43.                If .Stats.Gld < Gld Or .Stats.Gld = 0 Then
  44.                     Call WriteConsoleMsg(UserIndex, "No posees la cantidad suficiente de monedas de bronce para aprender este hechizo.", FontTypeNames.FONTTYPE_INFO)
  45.                     Exit Sub
  46.                 Else
  47.                     'Si no requiere items y con el oro alcanza, restamos el oro y le damos el hechizo
  48.                    If ConfigHechiceria.Hechizo(i).ItemsRequeridos = 0 Then
  49.                         If Not TieneHechizo(ID, UserIndex) Then
  50.                             For LoopD = 1 To MAXUSERHECHIZOS
  51.                                 If .Stats.UserHechizos(LoopD) = 0 Then Exit For
  52.                             Next LoopD
  53.                            
  54.                             If .Stats.UserHechizos(LoopD) <> 0 Then
  55.                                 Call WriteConsoleMsg(UserIndex, "No tienes espacio para más hechizos.", FontTypeNames.FONTTYPE_INFO)
  56.                                 Exit Sub
  57.                             Else
  58.                                 UserList(UserIndex).Stats.Gld = UserList(UserIndex).Stats.Gld - Gld
  59.                                 Call Protocol.WriteUpdateGold(UserIndex)
  60.                                
  61.                                 .Stats.UserHechizos(LoopD) = ID
  62.                                 Call UpdateUserHechizos(False, UserIndex, CByte(LoopD))
  63.                                
  64.                                 Call WriteConsoleMsg(UserIndex, "Has aprendido el hechizo: " & ConfigHechiceria.Hechizo(i).Nombre & ".", FontTypeNames.FONTTYPE_INFO)
  65.                                 Exit Sub
  66.                             End If
  67.                         Else
  68.                             Call WriteConsoleMsg(UserIndex, "Ya tienes ese hechizo.", FontTypeNames.FONTTYPE_INFO)
  69.                             Exit Sub
  70.                         End If
  71.                        
  72.                     'Si requiere items
  73.                    ElseIf ConfigHechiceria.Hechizo(i).ItemsRequeridos > 0 Then
  74.                    
  75.                         'Redimensiono el Array para guardar los slots de los items requeridos
  76.                        ReDim ArraySlot(1 To ConfigHechiceria.Hechizo(i).ItemsRequeridos) As nhArray
  77.  
  78.                         'Loop Inventario
  79.                        For LoopA = 1 To MAX_INVENTORY_SLOTS
  80.                             'Tiene un item en el slot?
  81.                            If .Invent.Object(LoopA).ObjIndex > 0 Then
  82.                                 'Recorramos los items requeridos
  83.                                For LoopB = 1 To ConfigHechiceria.Hechizo(i).ItemsRequeridos
  84.                                
  85.                                     ObjIndex = ConfigHechiceria.Hechizo(i).Item(LoopB).ObjIndex
  86.                                     Amount = ConfigHechiceria.Hechizo(i).Item(LoopB).Amount
  87.                                    
  88.                                     'El item es el mismo?
  89.                                    If .Invent.Object(LoopA).ObjIndex = ObjIndex Then
  90.                                         'Tiene la misma cantidad que solicitamos?
  91.                                        If .Invent.Object(LoopA).Amount >= Amount Then
  92.                                            
  93.                                             'Me guardo el slot donde esta el item y me guardo la cantidad que requiere
  94.                                            ArraySlot(LoopB).Slot = LoopA
  95.                                             ArraySlot(LoopB).Cantidad = Amount
  96.                                            
  97.                                             'Le decimos que tenia
  98.                                            Tenia = Tenia + 1
  99.                                         Else
  100.                                             'Si tiene pero no le alcanza
  101.                                            TienePeroNoAlcanza = TienePeroNoAlcanza + 1
  102.                                             'Si llegamos hasta acá es porque no le alcanza
  103.                                            If TienePeroNoAlcanza = ConfigHechiceria.Hechizo(i).ItemsRequeridos Then
  104.                                                 Call WriteConsoleMsg(UserIndex, "La cantidad de " & ObjData(ConfigHechiceria.Hechizo(i).Item(LoopB).ObjIndex).Name & " no es suficiente.", FontTypeNames.FONTTYPE_INFO)
  105.                                                 Exit Sub
  106.                                             End If
  107.                                         End If
  108.                                     Else
  109.                                         'Si no es el mismo item
  110.                                        TienePeroNoEs = TienePeroNoEs + 1
  111.                                        
  112.                                         If TienePeroNoEs = (.Invent.NroItems * ConfigHechiceria.Hechizo(i).ItemsRequeridos) Then
  113.                                             Call WriteConsoleMsg(UserIndex, "No posees los items necesarios.", FontTypeNames.FONTTYPE_INFO)
  114.                                             Exit Sub
  115.                                         End If
  116.                                     End If
  117.                                 Next LoopB
  118.                             Else
  119.                                 'Tiene el slot vacío
  120.                                NoTiene = NoTiene + 1
  121.                                 'Si todos los slots están vacíos
  122.                                If NoTiene = MAX_INVENTORY_SLOTS Then
  123.                                     Call WriteConsoleMsg(UserIndex, "No posees ningún item en tu inventario.", FontTypeNames.FONTTYPE_INFO)
  124.                                     Exit Sub
  125.                                 End If
  126.                             End If
  127.                         Next LoopA
  128.  
  129.                         If Tenia = ConfigHechiceria.Hechizo(i).ItemsRequeridos Then
  130.                             If Not TieneHechizo(ID, UserIndex) Then
  131.                                     'Buscamos un slot vacio
  132.                                    For LoopD = 1 To MAXUSERHECHIZOS
  133.                                         If .Stats.UserHechizos(LoopD) = 0 Then Exit For
  134.                                     Next LoopD
  135.                                                
  136.                                     If .Stats.UserHechizos(LoopD) <> 0 Then
  137.                                         Call WriteConsoleMsg(UserIndex, "No tienes espacio para más hechizos.", FontTypeNames.FONTTYPE_INFO)
  138.                                         Exit Sub
  139.                                     Else
  140.                                         For LoopC = 1 To ConfigHechiceria.Hechizo(i).ItemsRequeridos
  141.                                             'Remuevo los items de sus slots
  142.                                            Call QuitarUserInvItem(UserIndex, ArraySlot(LoopC).Slot, ArraySlot(LoopC).Cantidad)
  143.                                             'Actualizamos inventario
  144.                                            Call UpdateUserInv(False, UserIndex, ArraySlot(LoopC).Slot)
  145.                                         Next LoopC
  146.                                        
  147.                                         'Si terminó de recorrer entonces descontamos el oro
  148.                                        UserList(UserIndex).Stats.Gld = UserList(UserIndex).Stats.Gld - Gld
  149.                                         Call Protocol.WriteUpdateGold(UserIndex)
  150.                                        
  151.                                         'Le entregamos el hechizo
  152.                                        .Stats.UserHechizos(LoopD) = ID
  153.                                         Call UpdateUserHechizos(False, UserIndex, CByte(LoopD))
  154.                                        
  155.                                         Call WriteConsoleMsg(UserIndex, "Has aprendido el hechizo: " & ConfigHechiceria.Hechizo(i).Nombre & ".", FontTypeNames.FONTTYPE_INFO)
  156.                                         Exit Sub
  157.                                     End If
  158.                             Else
  159.                                 Call WriteConsoleMsg(UserIndex, "Ya tienes ese hechizo.", FontTypeNames.FONTTYPE_INFO)
  160.                                 Exit Sub
  161.                             End If
  162.                         End If
  163.                     End If
  164.                 End If
  165.             End If
  166.         Next i
  167.     End With
  168.  
  169. Exit Sub
  170. Errhandler:
  171.     If Err.Number = UserList(UserIndex).outgoingData.NotEnoughSpaceErrCode Then
  172.         Call FlushBuffer(UserIndex)
  173.         Resume
  174.     End If
  175. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement