1
+ import { ItemsIds } from "../models/Enums"
2
+
3
+ export class ParseLoad {
4
+ public id : string
5
+ public hp : number
6
+ public maxHp : number
7
+ public attack : number
8
+ public defense : number
9
+ public level : number
10
+ public xp : number
11
+ public xpNeeded : number
12
+ public itemsIds : ItemsIds [ ]
13
+ public gearHead : ItemsIds | null
14
+ public gearTorso : ItemsIds | null
15
+ public gearLegs : ItemsIds | null
16
+ public gearWeapon : ItemsIds | null
17
+
18
+ constructor ( data : string ) {
19
+ const parsedData = this . parseString ( data )
20
+
21
+ this . id = parsedData [ 0 ] [ 1 ]
22
+ this . hp = + parsedData [ 0 ] [ 2 ]
23
+ this . maxHp = + parsedData [ 0 ] [ 3 ]
24
+ this . attack = + parsedData [ 0 ] [ 4 ]
25
+ this . defense = + parsedData [ 0 ] [ 5 ]
26
+ this . level = + parsedData [ 0 ] [ 6 ]
27
+ this . xp = + parsedData [ 0 ] [ 7 ]
28
+ this . xpNeeded = + parsedData [ 0 ] [ 8 ]
29
+
30
+ this . itemsIds = parsedData [ 1 ]
31
+
32
+ if ( parsedData [ 2 ] [ 0 ] != - 1 ) {
33
+ this . gearHead = parsedData [ 2 ] [ 0 ]
34
+ } else {
35
+ this . gearHead = null
36
+ }
37
+ if ( parsedData [ 2 ] [ 1 ] != - 1 ) {
38
+ this . gearTorso = parsedData [ 2 ] [ 1 ]
39
+ } else {
40
+ this . gearTorso = null
41
+ }
42
+ if ( parsedData [ 2 ] [ 2 ] != - 1 ) {
43
+ this . gearLegs = parsedData [ 2 ] [ 2 ]
44
+ } else {
45
+ this . gearLegs = null
46
+ }
47
+ if ( parsedData [ 2 ] [ 3 ] != - 1 ) {
48
+ this . gearWeapon = parsedData [ 2 ] [ 3 ]
49
+ } else {
50
+ this . gearWeapon = null
51
+ }
52
+ }
53
+
54
+ private parseString ( eventDataString : string ) : any [ ] [ ] {
55
+ const allData = eventDataString . split ( '@' )
56
+
57
+ const statsData = allData [ 0 ] . split ( ',' )
58
+
59
+ let itemsData = [ ]
60
+ if ( allData [ 1 ] ) {
61
+ const itemsDataStrings = allData [ 1 ] . split ( ',' )
62
+ for ( const itemId of itemsDataStrings ) {
63
+ if ( itemId != '' ) {
64
+ itemsData . push ( + itemId )
65
+ }
66
+ }
67
+ }
68
+
69
+ let gearData = [ ]
70
+ if ( allData [ 2 ] ) {
71
+ for ( let i = 2 ; i < 6 ; i ++ ) {
72
+ if ( allData [ i ] != 'empty' ) {
73
+ gearData . push ( + allData [ i ] )
74
+ } else {
75
+ gearData . push ( - 1 )
76
+ }
77
+ }
78
+ }
79
+
80
+ return [ statsData , itemsData , gearData ]
81
+ }
82
+ }
0 commit comments