Advertisement
Luciano_fuentes

modParties

Apr 23rd, 2017
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. 'Autor: G Toyz.
  4.  
  5. Public Const MAX_PARTICIPANTES_PARTY As Byte = 10 ' No exceder este límite 10 (diez).
  6. Private Const MAX_PARTIES As Byte = 50
  7.  
  8. Private Type tUsuarios
  9.     UsuarioIndex As Integer
  10.     Porcentaje As Byte
  11.     Experiencia As Long
  12. End Type
  13.  
  14. Private Type tGeneral
  15.     Participantes(1 To MAX_PARTICIPANTES_PARTY) As tUsuarios
  16.     Solicitudes(1 To MAX_PARTICIPANTES_PARTY) As Integer
  17.     CantidadParticipantes As Byte
  18.     Activa As Boolean
  19.     Lider As Byte
  20. End Type
  21.  
  22. Public Parties(1 To MAX_PARTIES) As tGeneral
  23.  
  24. Public Sub AñadirParty(ByVal UsuarioIndex As Integer)
  25.  
  26.     Dim PartyIndex As Byte
  27.    
  28.     With UserList(UsuarioIndex)
  29.         If .Party.PartyIndex > 0 Then
  30.             Call WriteConsoleMsg(UsuarioIndex, "Primero debes " & IIf(.Party.Lider, "disolver", "abandonar") & " la party para poder fundar una.", FontTypeNames.FONTTYPE_CONSEJO)
  31.             Exit Sub
  32.         End If
  33.        
  34.         .Party.PartyIndex = PartyIndex
  35.         .Party.ParticipanteIndex = 1
  36.     End With
  37.    
  38.     PartyIndex = DamePartyIndex()
  39.     With Parties(PartyIndex)
  40.         .CantidadParticipantes = 1
  41.         .Activa = True
  42.         .Lider = 1      '       ««  El que la crea es el lider.
  43.        .Participantes(.Lider).UsuarioIndex = UsuarioIndex
  44.     End With
  45.    
  46.     Call WriteConsoleMsg(UsuarioIndex, "Has fundado una party.", FontTypeNames.FONTTYPE_CONSEJO)
  47. End Sub
  48.  
  49. Public Sub EnviarSolicitudIngreso(ByVal UsuarioIndex As Integer, ByVal LiderIndex As Integer)
  50.    
  51.     Dim SolicitudIndex As Byte
  52.    
  53.     If LiderIndex = 0 Then
  54.         Call WriteConsoleMsg(UsuarioIndex, "Clickea al lider de la party.", FontTypeNames.FONTTYPE_CONSEJO)
  55.         Exit Sub
  56.     End If
  57.    
  58.     If Not UserList(LiderIndex).Party.Lider Then
  59.         Call WriteConsoleMsg(UsuarioIndex, "El usuario no es lider de ninguna party.", FontTypeNames.FONTTYPE_CONSEJO)
  60.         Exit Sub
  61.     End If
  62.    
  63.     SolicitudIndex = DameSolicitudIndex(UserList(LiderIndex).Party.PartyIndex)
  64.    
  65.     If SolicitudIndex = 0 Then
  66.         Call WriteConsoleMsg(UsuarioIndex, "La party ya tiene muchas solicitudes de ingreso, intente más tarde", FontTypeNames.FONTTYPE_CONSEJO)
  67.         Exit Sub
  68.     End If
  69.    
  70.     Parties(UserList(LiderIndex).Party.PartyIndex).Solicitudes(SolicitudIndex) = UsuarioIndex
  71.    
  72.     Call WriteActualizarDatosParty(LiderIndex)
  73. End Sub
  74.  
  75. Public Sub AñadirParticipante(ByVal SolicitudIndex As Byte, ByVal PartyIndex As Byte)
  76.    
  77.     Dim ParticipanteIndex As Byte
  78.     Dim UsuarioIndex As Integer
  79.     UsuarioIndex = Parties(PartyIndex).Solicitudes(SolicitudIndex)
  80.     ParticipanteIndex = DameParticipanteIndex(PartyIndex)
  81.    
  82.     With UserList(UsuarioIndex)
  83.         If .Party.PartyIndex > 0 Then
  84.             Call WriteConsoleMsg(UsuarioIndex, "Primero debes " & IIf(.Party.Lider, "disolver", "abandonar") & " la party para poder entrar a una.", FontTypeNames.FONTTYPE_CONSEJO)
  85.             Exit Sub
  86.         End If
  87.        
  88.         .Party.PartyIndex = PartyIndex
  89.         .Party.ParticipanteIndex = ParticipanteIndex
  90.        
  91.         Call SendData(SendTarget.ToPartyArea, PartyIndex, PrepareMessageConsoleMsg(.Name & " ha ingresado a la party.", FontTypeNames.FONTTYPE_CONSEJO))
  92.     End With
  93.    
  94.     Parties(PartyIndex).CantidadParticipantes = Parties(PartyIndex).CantidadParticipantes + 1
  95.     With Parties(PartyIndex).Participantes(PartyIndex)
  96.         .Experiencia = 0
  97.         .UsuarioIndex = UsuarioIndex
  98.         ResetearPorcentajes PartyIndex
  99.     End With
  100.    
  101.     Parties(PartyIndex).Solicitudes(SolicitudIndex) = 0
  102.     Call WriteActualizarDatosParty(UsuarioIndex)
  103. End Sub
  104.  
  105. Public Sub QuitarParticipante(ByVal UsuarioIndex As Integer)
  106.     Call SendData(SendTarget.ToPartyArea, UserList(UsuarioIndex).Party.PartyIndex, PrepareMessageConsoleMsg(UserList(UsuarioIndex).Name & " abandona la party.", FontTypeNames.FONTTYPE_CONSEJO))
  107.     Call WriteConsoleMsg(UsuarioIndex, "Abandonas la party.", FontTypeNames.FONTTYPE_CONSEJO)
  108.     With Parties(UserList(UsuarioIndex).Party.PartyIndex)
  109.         DarExperiencia UsuarioIndex, .Participantes(UserList(UsuarioIndex).Party.ParticipanteIndex).Experiencia
  110.         .Participantes(UserList(UsuarioIndex).Party.ParticipanteIndex).Experiencia = 0
  111.         .Participantes(UserList(UsuarioIndex).Party.ParticipanteIndex).Porcentaje = 0
  112.         .Participantes(UserList(UsuarioIndex).Party.ParticipanteIndex).UsuarioIndex = 0
  113.         .CantidadParticipantes = .CantidadParticipantes - 1
  114.         ResetearPorcentajes UserList(UsuarioIndex).Party.PartyIndex
  115.     End With
  116. End Sub
  117.  
  118. Public Sub RepartirExperiencia(ByVal PartyIndex As Byte, ByVal Experiencia As Long)
  119.  
  120.     Dim LoopC As Long
  121.    
  122.     With Parties(PartyIndex)
  123.         For LoopC = 1 To MAX_PARTICIPANTES_PARTY
  124.             If .Participantes(LoopC).UsuarioIndex > 0 Then
  125.                 Experiencia = CLng(Round(Experiencia * .Participantes(LoopC).Porcentaje / 100))
  126.                 .Participantes(LoopC).Experiencia = Experiencia
  127.             End If
  128.         Next LoopC
  129.     End With
  130. End Sub
  131.  
  132. Private Sub DarExperiencia(ByVal UsuarioIndex As Integer, ByVal Experiencia As Long)
  133.     With UserList(UsuarioIndex)
  134.         .Stats.Exp = .Stats.Exp + Experiencia
  135.         If .Stats.Exp > MAXEXP Then _
  136.             .Stats.Exp = MAXEXP
  137.         Call WriteConsoleMsg(UsuarioIndex, "Has ganado " & Experiencia & " puntos de experiencia durante la party.", FontTypeNames.FONTTYPE_CONSEJO)
  138.         Call CheckUserLevel(UsuarioIndex)
  139.     End With
  140. End Sub
  141.  
  142. Private Sub ResetearPorcentajes(ByVal PartyIndex As Byte)
  143.    
  144.     Dim Porcentaje As Byte       '    «   Porcentaje para cada usuario
  145.    Dim LoopC As Long
  146.    
  147.     With Parties(PartyIndex)
  148.         Porcentaje = CByte(Round(100 / .CantidadParticipantes))
  149.        
  150.         For LoopC = 1 To .CantidadParticipantes
  151.             .Participantes(LoopC).Porcentaje = Porcentaje
  152.         Next LoopC
  153.         Call SendData(SendTarget.ToPartyArea, PartyIndex, PrepareMessageConsoleMsg("Los porcentajes han sido reseteados.", FontTypeNames.FONTTYPE_CONSEJO))
  154.     End With
  155.    
  156. End Sub
  157.  
  158. Public Sub EnviarToParty(ByRef dataTosend As String, ByVal sndIndex As Byte)
  159.  
  160.     Dim LoopC  As Long
  161.      
  162.     For LoopC = 1 To MAX_PARTICIPANTES_PARTY
  163.         With Parties(sndIndex)
  164.             If .Participantes(LoopC).UsuarioIndex > 0 Then
  165.                 Call EnviarDatosASlot(.Participantes(LoopC).UsuarioIndex, dataTosend)
  166.             End If
  167.         End With
  168.     Next LoopC
  169.  
  170. End Sub
  171.  
  172. Public Sub SetearPorcentajes(ByVal PartyIndex As Byte, ByVal ParticipanteIndex As Byte, ByVal Porcentaje As Byte)
  173.     Parties(PartyIndex).Participantes(ParticipanteIndex).Porcentaje = Porcentaje
  174.     Call SendData(SendTarget.ToPartyArea, PartyIndex, PrepareMessageConsoleMsg("El porcentaje de " & UserList(Parties(PartyIndex).Participantes(ParticipanteIndex).UsuarioIndex).Name & " ahora es de " & Porcentaje, FontTypeNames.FONTTYPE_CONSEJO))
  175. End Sub
  176.  
  177. Public Sub DisolverParty(ByVal UsuarioIndex As Byte)
  178.    
  179.     Dim LoopC As Long
  180.    
  181.     With Parties(UserList(UsuarioIndex).Party.PartyIndex)
  182.    
  183.         If Not .Lider = UserList(UsuarioIndex).Party.ParticipanteIndex Then Exit Sub
  184.        
  185.         For LoopC = 1 To MAX_PARTICIPANTES_PARTY
  186.             If .Participantes(LoopC).UsuarioIndex > 0 Then
  187.                 Call QuitarParticipante(.Participantes(LoopC).UsuarioIndex)
  188.             End If
  189.         Next LoopC
  190.        
  191.         .Activa = False
  192.         .Lider = 0
  193.         .CantidadParticipantes = 0
  194.         Erase .Participantes()
  195.         Erase .Solicitudes()
  196.     End With
  197. End Sub
  198.  
  199. Private Function DameSolicitudIndex(ByVal PartyIndex As Byte) As Byte
  200.  
  201.     Dim LoopC As Long
  202.    
  203.     With Parties(PartyIndex)
  204.         For LoopC = 1 To MAX_PARTICIPANTES_PARTY
  205.             If .Solicitudes(LoopC) = 0 Then
  206.                 DameSolicitudIndex = LoopC
  207.                 Exit Function
  208.             End If
  209.         Next LoopC
  210.     End With
  211.    
  212. End Function
  213.  
  214. Private Function DameParticipanteIndex(ByVal PartyIndex As Byte) As Byte
  215.    
  216.     Dim LoopC As Long
  217.    
  218.     With Parties(PartyIndex)
  219.         For LoopC = 1 To MAX_PARTICIPANTES_PARTY
  220.             If .Participantes(LoopC).UsuarioIndex = 0 Then
  221.                 DameParticipanteIndex = LoopC
  222.                 Exit Function
  223.             End If
  224.         Next LoopC
  225.     End With
  226.    
  227. End Function
  228.  
  229. Private Function DamePartyIndex() As Byte
  230.    
  231.     Dim LoopC As Long
  232.    
  233.     For LoopC = 1 To MAX_PARTIES
  234.         If Parties(LoopC).Activa = False Then
  235.             DamePartyIndex = LoopC
  236.             Exit Function
  237.         End If
  238.     Next LoopC
  239.    
  240. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement