-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathGameLogic.bas
2387 lines (1755 loc) · 91.8 KB
/
GameLogic.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Attribute VB_Name = "Extra"
' Argentum 20 Game Server
'
' Copyright (C) 2023 Noland Studios LTD
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU Affero General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU Affero General Public License for more details.
'
' You should have received a copy of the GNU Affero General Public License
' along with this program. If not, see <https://www.gnu.org/licenses/>.
'
' This program was based on Argentum Online 0.11.6
' Copyright (C) 2002 Márquez Pablo Ignacio
'
' Argentum Online is based on Baronsoft's VB6 Online RPG
' You can contact the original creator of ORE at [email protected]
' for more information about ORE please visit http://www.baronsoft.com/
'
'
'
Option Explicit
Public m_NameIndex As New Dictionary
Public Function esCiudad(ByVal map As Integer) As Boolean
Dim i As Byte
For i = 0 To UBound(TotalMapasCiudades)
If TotalMapasCiudades(i) = map Then
esCiudad = True
Exit Function
End If
Next i
End Function
Public Sub AgregarAConsola(ByVal Text As String)
On Error GoTo AgregarAConsola_Err
frmMain.List1.AddItem (Text)
Exit Sub
AgregarAConsola_Err:
Call TraceError(Err.Number, Err.Description, "ModLadder.AgregarAConsola", Erl)
End Sub
Public Function NameIndex(ByRef username As String) As t_UserReference
Dim UserRef As t_UserReference
Dim key As String
Dim wrapper As clsUserRefWrapper
key = UCase$(Replace(username, "+", " "))
If m_NameIndex.Exists(key) Then
Set wrapper = m_NameIndex(key)
UserRef.ArrayIndex = wrapper.PlayerIndex
UserRef.VersionId = wrapper.VersionId
Else
Call SetUserRef(UserRef, 0)
End If
NameIndex = UserRef
End Function
Public Sub FindLegalPos(ByVal UserIndex As Integer, ByVal Map As Integer, ByRef X As Byte, ByRef Y As Byte)
'***************************************************
'Autor: ZaMa
'Last Modification: 26/03/2009
'Search for a Legal pos for the user who is being teleported.
'***************************************************
On Error GoTo FindLegalPos_Err
100 If MapData(Map, X, Y).UserIndex <> 0 Or MapData(Map, X, Y).NpcIndex <> 0 Then
' Se teletransporta a la misma pos a la que estaba
102 If MapData(Map, X, Y).UserIndex = UserIndex Then Exit Sub
Dim FoundPlace As Boolean
Dim tX As Long
Dim tY As Long
Dim Rango As Long
Dim OtherUserIndex As Integer
104 For Rango = 0 To 5
106 For tY = Y - Rango To Y + Rango
108 For tX = X - Rango To X + Rango
'Reviso que no haya User ni NPC
110 If MapData(Map, tX, tY).UserIndex = 0 And MapData(Map, tX, tY).NpcIndex = 0 Then
112 If InMapBounds(Map, tX, tY) Then FoundPlace = True
Exit For
End If
114 Next tX
116 If FoundPlace Then Exit For
118 Next tY
120 If FoundPlace Then Exit For
122 Next Rango
124 If FoundPlace Then 'Si encontramos un lugar, listo, nos quedamos ahi
126 X = tX
128 Y = tY
Else
'Muy poco probable, pero..
'Si no encontramos un lugar, sacamos al usuario que tenemos abajo, y si es un NPC, lo pisamos.
130 OtherUserIndex = MapData(Map, X, Y).UserIndex
132 If OtherUserIndex <> 0 Then
'Si no encontramos lugar, y abajo teniamos a un usuario, lo pisamos y cerramos su comercio seguro
134 If IsValidUserRef(UserList(OtherUserIndex).ComUsu.DestUsu) Then
'Le avisamos al que estaba comerciando que se tuvo que ir.
136 If UserList(UserList(OtherUserIndex).ComUsu.DestUsu.ArrayIndex).flags.UserLogged Then
138 Call FinComerciarUsu(UserList(OtherUserIndex).ComUsu.DestUsu.ArrayIndex)
'Msg1104= Comercio cancelado. El otro usuario se ha desconectado.
Call WriteLocaleMsg(UserList(OtherUserIndex).ComUsu.DestUsu.ArrayIndex, "1104", e_FontTypeNames.FONTTYPE_TALK)
End If
'Lo sacamos.
142 If UserList(OtherUserIndex).flags.UserLogged Then
144 Call FinComerciarUsu(OtherUserIndex)
146 Call WriteShowMessageBox(OtherUserIndex, "Alguien se ha conectado donde te encontrabas, por favor reconéctate...")
End If
End If
148 Call CloseSocket(OtherUserIndex)
End If
End If
End If
Exit Sub
FindLegalPos_Err:
150 Call TraceError(Err.Number, Err.Description, "Extra.FindLegalPos", Erl)
End Sub
Public Function EsNewbie(ByVal UserIndex As Integer) As Boolean
On Error GoTo EsNewbie_Err
100 If UserIndex > 0 Then EsNewbie = UserList(UserIndex).Stats.ELV <= LimiteNewbie
Exit Function
EsNewbie_Err:
102 Call TraceError(Err.Number, Err.Description, "Extra.EsNewbie", Erl)
End Function
Public Function esCiudadano(ByVal UserIndex As Integer) As Boolean
On Error GoTo esCiudadano_Err
100 If UserIndex > 0 Then esCiudadano = Status(UserIndex) = Ciudadano
Exit Function
esCiudadano_Err:
102 Call TraceError(Err.Number, Err.Description, "Extra.esCiudadano", Erl)
End Function
Public Function esCriminal(ByVal UserIndex As Integer) As Boolean
On Error GoTo esCriminal_Err
100 If UserIndex > 0 Then esCriminal = Status(UserIndex) = Criminal
Exit Function
esCriminal_Err:
102 Call TraceError(Err.Number, Err.Description, "Extra.esCriminal", Erl)
End Function
Public Function esArmada(ByVal UserIndex As Integer) As Boolean
On Error GoTo esArmada_Err
100 If UserIndex > 0 Then esArmada = (UserList(UserIndex).Faccion.status = e_Facciones.Armada Or UserList(UserIndex).Faccion.status = e_Facciones.consejo)
Exit Function
esArmada_Err:
102 Call TraceError(Err.Number, Err.Description, "Extra.esArmada", Erl)
End Function
Public Function esCaos(ByVal UserIndex As Integer) As Boolean
On Error GoTo esCaos_Err
100 If UserIndex > 0 Then esCaos = (UserList(UserIndex).Faccion.Status = e_Facciones.Caos Or UserList(UserIndex).Faccion.Status = e_Facciones.concilio)
Exit Function
esCaos_Err:
Call TraceError(Err.Number, Err.Description, "Extra.esCaos", Erl)
End Function
Public Function FactionCanAttackFaction(ByVal AttackerFaction As e_Facciones, ByVal TargetFaction As e_Facciones)
Select Case AttackerFaction
Case e_Facciones.Ciudadano, e_Facciones.Armada, e_Facciones.consejo
If TargetFaction = e_Facciones.Armada Or TargetFaction = e_Facciones.Ciudadano Or TargetFaction = e_Facciones.consejo Then
Exit Function
End If
Case e_Facciones.Caos, e_Facciones.concilio
If TargetFaction = e_Facciones.Caos Or TargetFaction = e_Facciones.concilio Then
Exit Function
End If
End Select
FactionCanAttackFaction = True
End Function
Public Function FactionCanHelpFaction(ByVal SourceFaction As e_Facciones, ByVal TargetFaction As e_Facciones) As e_InteractionResult
Select Case SourceFaction
Case e_Facciones.Ciudadano, e_Facciones.Armada, e_Facciones.consejo
If TargetFaction = e_Facciones.Caos Or TargetFaction = e_Facciones.concilio Then
FactionCanHelpFaction = eOposingFaction
Exit Function
ElseIf TargetFaction = e_Facciones.Criminal Then
FactionCanHelpFaction = eCantHelpCriminal
Exit Function
End If
Case e_Facciones.Caos, e_Facciones.concilio
If TargetFaction = e_Facciones.Armada Or TargetFaction = e_Facciones.consejo Or TargetFaction = e_Facciones.Ciudadano Then
FactionCanHelpFaction = eOposingFaction
Exit Function
End If
Case Else
End Select
FactionCanHelpFaction = eInteractionOk
End Function
Public Function EsGM(ByVal UserIndex As Integer) As Boolean
'***************************************************
'Autor: Pablo (ToxicWaste)
'Last Modification: 23/01/2007
'***************************************************
On Error GoTo EsGM_Err
100 If UserIndex = 0 Then
102 EsGM = False
Exit Function
End If
104 EsGM = (UserList(UserIndex).flags.Privilegios And (e_PlayerType.Admin Or e_PlayerType.Dios Or e_PlayerType.SemiDios Or e_PlayerType.Consejero)) <> 0
Exit Function
EsGM_Err:
106 Call TraceError(Err.Number, Err.Description, "Extra.EsGM", Erl)
End Function
Private Function CheckMapRestrictions(ByVal UserIndex As Integer, ByVal Map As Integer) As Boolean
100 With UserList(UserIndex)
102 If EsGM(UserIndex) Then
104 CheckMapRestrictions = True
Exit Function
End If
106 If MapInfo(Map).Newbie And Not EsNewbie(UserIndex) Then
108 If .flags.UltimoMensaje <> 101 Then
110 ' Msg771=Sólo los newbies pueden entrar a este mapa.
Call WriteLocaleMsg(UserIndex, "771", e_FontTypeNames.FONTTYPE_INFO)
112 .flags.UltimoMensaje = 101
End If
Exit Function
End If
114 If MapInfo(Map).NoPKs And (Status(UserIndex) = 0 Or Status(UserIndex) = 2) Then
116 If .flags.UltimoMensaje <> 102 Then
118 ' Msg772=Sólo los ciudadanos pueden entrar a este mapa.
Call WriteLocaleMsg(UserIndex, "772", e_FontTypeNames.FONTTYPE_INFO)
120 .flags.UltimoMensaje = 102
End If
Exit Function
End If
122 If MapInfo(Map).NoCiudadanos And (Status(UserIndex) = 1 Or Status(UserIndex) = 3) Then
124 If .flags.UltimoMensaje <> 103 Then
126 ' Msg773=Sólo los criminales pueden entrar a este mapa.
Call WriteLocaleMsg(UserIndex, "773", e_FontTypeNames.FONTTYPE_INFO)
128 .flags.UltimoMensaje = 103
End If
Exit Function
End If
130 If MapInfo(Map).SoloClanes And .GuildIndex <= 0 Then
132 If .flags.UltimoMensaje <> 104 Then
134 ' Msg774=Necesitas pertenecer a un clan para entrar a este mapa.
Call WriteLocaleMsg(UserIndex, "774", e_FontTypeNames.FONTTYPE_INFO)
136 .flags.UltimoMensaje = 104
End If
Exit Function
End If
138 If MapInfo(Map).MinLevel <> 0 And .Stats.ELV < MapInfo(Map).MinLevel Then
140 If .flags.UltimoMensaje <> 105 Then
'Msg1108= Necesitas ser al menos nivel ¬1
Call WriteLocaleMsg(UserIndex, "1108", e_FontTypeNames.FONTTYPE_INFO, MapInfo(Map).MinLevel)
144 .flags.UltimoMensaje = 105
End If
Exit Function
End If
146 If MapInfo(Map).MaxLevel <> 0 And .Stats.ELV >= MapInfo(Map).MaxLevel Then
148 If .flags.UltimoMensaje <> 106 Then
'Msg1109= Sólo los personajes inferiores a nivel ¬1
Call WriteLocaleMsg(UserIndex, "1109", e_FontTypeNames.FONTTYPE_INFO, MapInfo(Map).MaxLevel)
152 .flags.UltimoMensaje = 106
End If
Exit Function
End If
153 If MapInfo(Map).OnlyGroups And Not .Grupo.EnGrupo Then
154 If .flags.UltimoMensaje <> 107 Then
155 ' Msg775=Necesitas pertenecer a un grupo para entrar a este mapa.
Call WriteLocaleMsg(UserIndex, "775", e_FontTypeNames.FONTTYPE_INFO)
156 .flags.UltimoMensaje = 107
End If
Exit Function
End If
If MapInfo(Map).OnlyPatreon And Not (.Stats.tipoUsuario = tAventurero Or .Stats.tipoUsuario = tHeroe Or .Stats.tipoUsuario = tLeyenda) Then
157 If .flags.UltimoMensaje <> 107 Then
158 ' Msg776=Necesitas ser Patreon para entrar a este mapa.
Call WriteLocaleMsg(UserIndex, "776", e_FontTypeNames.FONTTYPE_INFO)
159 .flags.UltimoMensaje = 107
End If
Exit Function
End If
160 CheckMapRestrictions = True
End With
End Function
Public Function GetTransportNextIndex(ByVal Map As Integer, ByVal PosX As Byte, ByVal PosY As Byte) As Integer
Dim i As Integer
With MapInfo(Map)
For i = 0 To UBound(.TransportNetwork)
If .TransportNetwork(i).TileX = PosX And .TransportNetwork(i).TileY = PosY Then
GetTransportNextIndex = i
Exit Function
End If
Next i
End With
GetTransportNextIndex = -1
End Function
Public Function GetExitTransport(ByVal Map As Integer, ByVal ExcludeIndex As Integer) As Integer
Dim output As Integer
Do
output = RandomNumber(0, UBound(MapInfo(Map).TransportNetwork))
Loop While output = excludeIndex
GetExitTransport = output
End Function
Public Sub DoTileEvents(ByVal UserIndex As Integer, ByVal Map As Integer, ByVal X As Integer, ByVal Y As Integer)
'***************************************************
'Autor: Pablo (ToxicWaste) & Unknown (orginal version)
'Last Modification: 23/01/2007
'Handles the Map passage of Users. Allows the existance
'of exclusive maps for Newbies, Royal Army and Caos Legion members
'and enables GMs to enter every map without restriction.
'Uses: Mapinfo(map).Restringir = "NEWBIE" (newbies), "ARMADA", "CAOS", "FACCION" or "NO".
'***************************************************
On Error GoTo ErrHandler
Dim nPos As t_WorldPos
Dim EsTeleport As Boolean
Dim TelepRadio As Byte
Dim aN As Integer
Dim destPos As t_WorldPos
100 With UserList(UserIndex)
'Controla las salidas
102 If InMapBounds(Map, X, Y) Then
If MapData(Map, X, Y).trigger = AUTORESU Then
Call ResucitarOCurar(UserIndex)
End If
104 If MapData(Map, X, Y).ObjInfo.ObjIndex > 0 Then
106 EsTeleport = ObjData(MapData(Map, X, Y).ObjInfo.ObjIndex).OBJType = e_OBJType.otTeleport
End If
If Not MapData(map, X, y).Trap Is Nothing Then
Call ModMap.ActivateTrap(UserIndex, eUser, map, X, y)
End If
If EsTeleport Then
108 If ObjData(MapData(map, X, y).ObjInfo.objIndex).Subtipo = e_TeleportSubType.eTransportNetwork Then
110 Dim StartTransportIndex As Integer
112 Dim ExitPortal As Integer
114 StartTransportIndex = GetTransportNextIndex(map, X, y)
116 If .LastTransportNetwork.map = map And .LastTransportNetwork.ExitIndex = StartTransportIndex Then
118 ExitPortal = .LastTransportNetwork.StartIdex
Else
120 ExitPortal = GetExitTransport(map, StartTransportIndex)
End If
122 destPos = MapData(map, MapInfo(map).TransportNetwork(ExitPortal).TileX, MapInfo(map).TransportNetwork(ExitPortal).TileY).TileExit
124 If destPos.map > 0 And destPos.map <= NumMaps Then
126 .LastTransportNetwork.map = map
128 .LastTransportNetwork.StartIdex = StartTransportIndex
130 .LastTransportNetwork.ExitIndex = ExitPortal
132 Call WarpUserChar(UserIndex, destPos.map, destPos.X, destPos.y, EsTeleport)
Else
134 Call LogError("Invalid teleport at map: " & map & "(" & X & ", " & y & ")")
End If
Exit Sub
End If
End If
136 If (MapData(map, X, y).TileExit.map > 0) And (MapData(map, X, y).TileExit.map <= NumMaps) Then
' WyroX: Restricciones de mapas
138 If CheckMapRestrictions(UserIndex, MapData(map, X, y).TileExit.map) Then
140 If EsMapaInterdimensional(MapData(map, X, y).TileExit.map) And Not EsMapaInterdimensional(.pos.map) Then
142 .flags.ReturnPos = .pos
End If
144 destPos.map = MapData(map, X, y).TileExit.map
If EsTeleport Then
146 destPos.X = RandomNumber(MapData(map, X, y).TileExit.X - ObjData(MapData(map, X, y).ObjInfo.objIndex).Radio, MapData(map, X, y).TileExit.X + ObjData(MapData(map, X, y).ObjInfo.objIndex).Radio)
148 destPos.y = RandomNumber(MapData(map, X, y).TileExit.y - ObjData(MapData(map, X, y).ObjInfo.objIndex).Radio, MapData(map, X, y).TileExit.y + ObjData(MapData(map, X, y).ObjInfo.objIndex).Radio)
Else
150 destPos.X = MapData(map, X, y).TileExit.X
152 destPos.y = MapData(map, X, y).TileExit.y
End If
If .flags.Navegando Then
154 Call ClosestLegalPos(destPos, nPos, True)
Else
156 Call ClosestLegalPos(destPos, nPos)
End If
158 If nPos.X <> 0 And nPos.y <> 0 Then
160 Call WarpUserChar(UserIndex, nPos.map, nPos.X, nPos.y, EsTeleport)
End If
End If
'Te fusite del mapa. La criatura ya no es más tuya ni te reconoce como que vos la atacaste.
162 Call ClearAttackerNpc(UserIndex)
164 ElseIf MapData(map, X, y).TileExit.map < 0 Then
166 If .flags.ReturnPos.map <> 0 Then
168 If LegalPos(.flags.ReturnPos.map, .flags.ReturnPos.X, .flags.ReturnPos.y, .flags.Navegando = 1, , , False) Then
170 Call WarpUserChar(UserIndex, .flags.ReturnPos.map, .flags.ReturnPos.X, .flags.ReturnPos.y, False)
Else
172 Call ClosestLegalPos(.flags.ReturnPos, nPos)
174 If nPos.X <> 0 And nPos.y <> 0 Then
176 Call WarpUserChar(UserIndex, nPos.map, nPos.X, nPos.y, EsTeleport)
End If
End If
'Te fusite del mapa. La criatura ya no es más tuya ni te reconoce como que vos la atacaste.
178 Call ClearAttackerNpc(UserIndex)
End If
End If
End If
End With
Exit Sub
ErrHandler:
Call TraceError(Err.Number, Err.Description, ".DotileEvents", Erl)
End Sub
Public Sub ClearAttackerNpc(ByVal UserIndex As Integer)
On Error GoTo ClearAttackerNpc_err
With UserList(UserIndex)
Dim aN As Integer
If Not IsValidNpcRef(.flags.AtacadoPorNpc) Then
Call ClearNpcRef(.flags.AtacadoPorNpc)
Else
100 aN = .flags.AtacadoPorNpc.ArrayIndex
102 If aN > 0 Then
104 If IsValidUserRef(NpcList(aN).TargetUser) And NpcList(aN).TargetUser.ArrayIndex = UserIndex Then
106 Call SetMovement(aN, NpcList(aN).flags.OldMovement)
108 NpcList(aN).Hostile = NpcList(aN).flags.OldHostil
110 NpcList(aN).flags.AttackedBy = vbNullString
112 Call SetUserRef(NpcList(aN).TargetUser, 0)
114 End If
116 End If
End If
If Not IsValidNpcRef(.flags.NPCAtacado) Then
Call ClearNpcRef(.flags.NPCAtacado)
Else
118 aN = .flags.NPCAtacado.ArrayIndex
120 If aN > 0 Then
122 If NpcList(aN).flags.AttackedFirstBy = .Name Then
124 NpcList(aN).flags.AttackedFirstBy = vbNullString
126 End If
128 End If
End If
130 Call ClearNpcRef(.flags.AtacadoPorNpc)
132 Call ClearNpcRef(.flags.NPCAtacado)
End With
Exit Sub
ClearAttackerNpc_err:
Call TraceError(Err.Number, Err.Description, "Extra.ClearAttackerNpc failed to clear userindex" & userIndex & "(" & UserList(userIndex).VersionId & ")", Erl)
End Sub
Function InRangoVision(ByVal UserIndex As Integer, ByVal X As Integer, ByVal Y As Integer) As Boolean
On Error GoTo InRangoVision_Err
100 If X > UserList(UserIndex).Pos.X - MinXBorder And X < UserList(UserIndex).Pos.X + MinXBorder Then
102 If Y > UserList(UserIndex).Pos.Y - MinYBorder And Y < UserList(UserIndex).Pos.Y + MinYBorder Then
104 InRangoVision = True
Exit Function
End If
End If
106 InRangoVision = False
Exit Function
InRangoVision_Err:
108 Call TraceError(Err.Number, Err.Description, "Extra.InRangoVision", Erl)
End Function
Function InRangoVisionNPC(ByVal NpcIndex As Integer, ByVal x As Integer, ByVal y As Integer) As Boolean
On Error GoTo InRangoVisionNPC_Err
100 If X > NpcList(NpcIndex).Pos.X - MinXBorder And X < NpcList(NpcIndex).Pos.X + MinXBorder Then
102 If Y > NpcList(NpcIndex).Pos.Y - MinYBorder And Y < NpcList(NpcIndex).Pos.Y + MinYBorder Then
104 InRangoVisionNPC = True
Exit Function
End If
End If
106 InRangoVisionNPC = False
Exit Function
InRangoVisionNPC_Err:
108 Call TraceError(Err.Number, Err.Description, "Extra.InRangoVisionNPC", Erl)
End Function
Function InMapBounds(ByVal Map As Integer, ByVal X As Integer, ByVal Y As Integer) As Boolean
On Error GoTo InMapBounds_Err
100 If (Map <= 0 Or Map > NumMaps) Or X < MinXBorder Or X > MaxXBorder Or Y < MinYBorder Or Y > MaxYBorder Then
102 InMapBounds = False
Else
104 InMapBounds = True
End If
Exit Function
InMapBounds_Err:
106 Call TraceError(Err.Number, Err.Description, "Extra.InMapBounds", Erl)
End Function
Function ClosestLegalPosNPC(ByVal NpcIndex As Integer, ByVal MaxRange As Integer, Optional ByVal IgnoreUsers As Boolean, Optional ByVal IgnoreDeadUsers As Boolean) As t_WorldPos
On Error GoTo ErrHandler
Dim LoopC As Integer
Dim tX As Integer
Dim tY As Integer
100 With NpcList(NpcIndex)
Do
102 tY = .Pos.Y - LoopC
104 For tX = .Pos.X - LoopC To .Pos.X + LoopC
106 If ValidNPCSpawnPos(ClosestLegalPosNPC, .Pos.map, tX, tY, .flags.AguaValida = 1, .flags.TierraInvalida = 0, IgnoreUsers, IgnoreDeadUsers) Then
Exit Function
End If
Next
108 tX = .Pos.X - LoopC
110 For tY = .Pos.Y - LoopC + 1 To .Pos.Y + LoopC - 1
112 If ValidNPCSpawnPos(ClosestLegalPosNPC, .Pos.map, tX, tY, .flags.AguaValida = 1, .flags.TierraInvalida = 0, IgnoreUsers, IgnoreDeadUsers) Then
Exit Function
End If
Next
114 tX = .Pos.X + LoopC
116 For tY = .Pos.Y - LoopC + 1 To .Pos.Y + LoopC - 1
118 If ValidNPCSpawnPos(ClosestLegalPosNPC, .Pos.map, tX, tY, .flags.AguaValida = 1, .flags.TierraInvalida = 0, IgnoreUsers, IgnoreDeadUsers) Then
Exit Function
End If
Next
120 tY = .Pos.Y + LoopC
122 For tX = .Pos.X - LoopC To .Pos.X + LoopC
124 If ValidNPCSpawnPos(ClosestLegalPosNPC, .Pos.map, tX, tY, .flags.AguaValida = 1, .flags.TierraInvalida = 0, IgnoreUsers, IgnoreDeadUsers) Then
Exit Function
End If
Next
126 LoopC = LoopC + 1
128 Loop While LoopC <= MaxRange
End With
Exit Function
ErrHandler:
130 Call TraceError(Err.Number, Err.Description, "Extra.ClosestLegalPosNPC")
End Function
Private Function ValidNPCSpawnPos(OutPos As t_WorldPos, ByVal map As Integer, ByVal X As Integer, ByVal y As Integer, ByVal AguaValida As Boolean, ByVal TierraValida As Boolean, ByVal IgnoreUsers As Boolean, ByVal IgnoreDeadUsers As Boolean) As Boolean
100 If LegalPos(Map, X, Y, AguaValida, TierraValida, , False) Then
102 If TestSpawnTrigger(Map, X, Y) Then
104 If Not HayPCarea(map, X, y, IgnoreDeadUsers) Or IgnoreUsers Then
106 ValidNPCSpawnPos = True
108 OutPos.Map = Map
110 OutPos.X = X
112 OutPos.Y = Y
Exit Function
End If
End If
End If
End Function
Sub ClosestLegalPos(Pos As t_WorldPos, ByRef nPos As t_WorldPos, Optional ByVal PuedeAgua As Boolean = False, Optional ByVal PuedeTierra As Boolean = True)
'*****************************************************************
'Author: Unknown (original version)
'Last Modification: 24/01/2007 (ToxicWaste)
'Encuentra la posicion legal mas cercana y la guarda en nPos
'*****************************************************************
On Error GoTo ClosestLegalPos_Err
Dim Notfound As Boolean
Dim LoopC As Integer
Dim tX As Integer
Dim tY As Integer
100 nPos.Map = Pos.Map
102 Do While Not LegalPos(Pos.Map, nPos.X, nPos.Y, PuedeAgua, PuedeTierra, , False)
104 If LoopC > 12 Then
106 Notfound = True
Exit Do
End If
108 For tY = Pos.Y - LoopC To Pos.Y + LoopC
110 For tX = Pos.X - LoopC To Pos.X + LoopC
112 If LegalPos(nPos.Map, tX, tY, PuedeAgua, PuedeTierra, , False) Then
114 nPos.X = tX
116 nPos.Y = tY
Exit Sub
End If
122 Next tX
124 Next tY
126 LoopC = LoopC + 1
Loop
128 If Notfound = True Then
130 nPos.X = 0
132 nPos.Y = 0
End If
Exit Sub
ClosestLegalPos_Err:
134 Call TraceError(Err.Number, Err.Description, "Extra.ClosestLegalPos", Erl)
End Sub
Sub ClosestStablePos(Pos As t_WorldPos, ByRef nPos As t_WorldPos)
'*****************************************************************
'Encuentra la posicion legal mas cercana que no sea un portal y la guarda en nPos
'*****************************************************************
On Error GoTo ClosestStablePos_Err
Dim Notfound As Boolean
Dim LoopC As Integer
Dim tX As Integer
Dim tY As Integer
100 nPos.Map = Pos.Map
102 Do While Not LegalPos(Pos.Map, nPos.X, nPos.Y)
104 If LoopC > 12 Then
106 Notfound = True
Exit Do
End If
108 For tY = Pos.Y - LoopC To Pos.Y + LoopC
110 For tX = Pos.X - LoopC To Pos.X + LoopC
112 If LegalPos(nPos.Map, tX, tY) And MapData(nPos.Map, tX, tY).TileExit.Map = 0 Then
114 nPos.X = tX
116 nPos.Y = tY
'¿Hay objeto?
118 tX = Pos.X + LoopC
120 tY = Pos.Y + LoopC
End If
122 Next tX
124 Next tY
126 LoopC = LoopC + 1
Loop
128 If Notfound = True Then
130 nPos.X = 0
132 nPos.Y = 0
End If
Exit Sub
ClosestStablePos_Err:
134 Call TraceError(Err.Number, Err.Description, "Extra.ClosestStablePos", Erl)
End Sub
Function IP_Index(ByVal inIP As String) As Integer
On Error GoTo IP_Index_Err
Dim UserIndex As Integer
'¿Nombre valido?
100 If LenB(inIP) = 0 Then
102 IP_Index = 0
Exit Function
End If
104 UserIndex = 1
106 Do Until UserList(UserIndex).ConnectionDetails.IP = inIP
108 UserIndex = UserIndex + 1
110 If UserIndex > MaxUsers Then
112 IP_Index = 0
Exit Function
End If
Loop
114 IP_Index = UserIndex
Exit Function
Exit Function
IP_Index_Err:
116 Call TraceError(Err.Number, Err.Description, "Extra.IP_Index", Erl)
End Function
Sub HeadtoPos(ByVal Head As e_Heading, ByRef Pos As t_WorldPos)
On Error GoTo HeadtoPos_Err
'*****************************************************************
'Toma una posicion y se mueve hacia donde esta perfilado
'*****************************************************************
Dim X As Integer
Dim Y As Integer
Dim nX As Integer
Dim nY As Integer
100 X = Pos.X
102 Y = Pos.Y
104 If Head = e_Heading.NORTH Then
106 nX = X
108 nY = Y - 1
End If
110 If Head = e_Heading.SOUTH Then
112 nX = X
114 nY = Y + 1
End If
116 If Head = e_Heading.EAST Then
118 nX = X + 1
120 nY = Y
End If
122 If Head = e_Heading.WEST Then
124 nX = X - 1
126 nY = Y
End If
'Devuelve valores
128 Pos.X = nX
130 Pos.Y = nY
Exit Sub
HeadtoPos_Err:
132 Call TraceError(Err.Number, Err.Description, "Extra.HeadtoPos", Erl)
End Sub
'Returns the front left positon from current heading
Public Sub GetHeadingLeft(ByVal head As e_Heading, ByRef pos As t_WorldPos)
Dim X, Y, nX, nY As Integer
100 X = pos.X
102 Y = pos.Y
104 If head = e_Heading.NORTH Then
106 nX = X - 1
108 nY = Y - 1
End If
110 If head = e_Heading.SOUTH Then
112 nX = X + 1
114 nY = Y + 1
End If
116 If head = e_Heading.EAST Then
118 nX = X + 1
120 nY = Y - 1
End If
122 If head = e_Heading.WEST Then
124 nX = X - 1
126 nY = Y + 1
End If
'Devuelve valores
128 pos.X = nX
130 pos.Y = nY
End Sub
'Returns the front right positon from current heading
Sub GetHeadingRight(ByVal head As e_Heading, ByRef pos As t_WorldPos)
Dim X, Y, nX, nY As Integer
100 X = pos.X
102 Y = pos.Y
104 If head = e_Heading.NORTH Then
106 nX = X + 1
108 nY = Y - 1
End If
110 If head = e_Heading.SOUTH Then
112 nX = X - 1
114 nY = Y + 1
End If
116 If head = e_Heading.EAST Then
118 nX = X + 1
120 nY = Y + 1
End If
122 If head = e_Heading.WEST Then
124 nX = X - 1
126 nY = Y - 1
End If
'Devuelve valores
128 pos.X = nX
130 pos.Y = nY
End Sub
' Autor: WyroX - 20/01/2021
' Retorna el heading recibo como parámetro pero rotado, según el valor R.
' Si R es 1, rota en sentido horario. Si R es -1, en sentido antihorario.
Function Rotate_Heading(ByVal Heading As e_Heading, ByVal R As Integer) As e_Heading
100 Rotate_Heading = (Heading + R + 3) Mod 4 + 1
End Function
Function LegalPos(ByVal Map As Integer, ByVal X As Integer, ByVal Y As Integer, Optional ByVal PuedeAgua As Boolean = False, Optional ByVal PuedeTierra As Boolean = True, Optional ByVal Montado As Boolean = False, Optional ByVal PuedeTraslado As Boolean = True, Optional ByVal PuedeBloqueoParcial As Boolean = True) As Boolean
'***************************************************
'Autor: Pablo (ToxicWaste) & Unknown (orginal version)
'Last Modification: 23/01/2007
'Checks if the position is Legal.
'***************************************************
'¿Es un mapa valido?
On Error GoTo LegalPos_Err
100 If Map <= 0 Or Map > NumMaps Then Exit Function
102 If X < MinXBorder Or X > MaxXBorder Then Exit Function
104 If Y < MinYBorder Or Y > MaxYBorder Then Exit Function
106 With MapData(Map, X, Y)
108 If .NpcIndex <> 0 Then Exit Function
110 If .UserIndex <> 0 Then Exit Function
112 If Not PuedeTraslado Then
114 If .TileExit.Map > 0 Then Exit Function
End If
116 If Not PuedeAgua Then
118 If (.Blocked And FLAG_AGUA) <> 0 Then Exit Function
End If
120 If Not PuedeTierra Then
122 If (.Blocked And FLAG_AGUA) = 0 Then Exit Function
End If
If PuedeBloqueoParcial Then
124 If (.Blocked And e_Block.ALL_SIDES) = e_Block.ALL_SIDES Then Exit Function
Else
If (.Blocked And e_Block.ALL_SIDES) > 0 Then Exit Function
End If
End With
126 LegalPos = True
Exit Function
LegalPos_Err:
128 Call TraceError(Err.Number, Err.Description, "Extra.LegalPos", Erl)
End Function
Function LegalPosDestrabar(ByVal Map As Integer, ByVal X As Integer, ByVal Y As Integer, Optional ByVal PuedeAgua As Boolean = False, Optional ByVal PuedeTierra As Boolean = True, Optional ByVal Montado As Boolean = False, Optional ByVal PuedeTraslado As Boolean = True, Optional ByVal PuedeBloqueoParcial As Boolean = True) As Boolean
On Error GoTo LegalPosDestrabar_Err
100 If Map <= 0 Or Map > NumMaps Then Exit Function
102 If X < MinXBorder Or X > MaxXBorder Then Exit Function
104 If Y < MinYBorder Or Y > MaxYBorder Then Exit Function
106 With MapData(Map, X, Y)
108 If .NpcIndex <> 0 Then Exit Function
112 If Not PuedeTraslado Then
114 If .TileExit.Map > 0 Then Exit Function