-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStat_Calculator.php
147 lines (105 loc) · 3.21 KB
/
Stat_Calculator.php
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
<?php
/**
* Get build points
* Compare build points to current points and available points for level
* Provide percent based distribution results
*/
class Stat_Calculator
{
//Set skill point progression per level
private $xenoverse_skillpoints = [
0, //1
2, //2
3, //3
3, //4
3, //5
3, //6
3, //7
3, //8
3, //9
3, //10
3, //11
3, //12
3, //13
3, //14
3, //15
3, //16
3, //17
3, //18
3, //19
4, //20
];
//Set default for character stats
private $character = [
'health' => 0,
'ki' => 0,
'stamina' => 0,
'basicattacks' => 0,
'strikesupers' => 0,
'kisupers' => 0,
];
public function __construct(){
//set build array
$this->build = $_GET['build'];
//Set character level
$this->character_level = $_GET['character']['level'];
}
public function show_level_proposition() {
$proportional_distribution = $this->distribute_points();
echo $this->formulate_result( $proportional_distribution, $this->character_level );
}
/**
* @return array[string]
*/
private function distribute_points(){
for($i = 0; $i < $this->character_level; $i++){
for( $j = 0; $j <= $this->xenoverse_skillpoints[$i]; $j++){
$character_percentages = $this->calculate_percents( $this->character );
$build_percentages = $this->calculate_percents( $this->build );
$diffs = $this->calculate_diffs( $character_percentages, $build_percentages );
$min_key = array_keys( $diffs, min( $diffs ) );
$this->character[$min_key[0]]++;
}
}
return $this->character;
}
/**
* @param array[string] $stats
* @return array[string]
*/
private function calculate_percents( $stats ) {
$stat_sum = array_sum( $stats );
foreach( $stats as $attribute => $points ) {
$stat_percents[$attribute] = $points / $stat_sum;
}
return $stat_percents;
}
/**
* @param array[string] $initial
* @param array[string] $less
* @return array[string]
*/
private function calculate_diffs( $initial, $less ){
foreach( $initial as $attribute => $points ) {
$stat_percents[$attribute] = $points - $less[$attribute];
}
return $stat_percents;
}
/**
* @param array[string] $stats
* @param array[string] $level
* @return string
*/
private function formulate_result( $stats, $level ) {
$result = "<h1>Level: " . $level . "</h1>" .
"<h3>Max Health: " . $stats[ 'health' ] . "</h3>" .
"<h3>Max Ki: " . $stats[ 'ki' ] . "</h3>" .
"<h3>Max Stamina: " . $stats[ 'stamina' ] . "</h3>" .
"<h3>Basic Attacks: " . $stats[ 'basicattacks' ] . "</h3>" .
"<h3>Strike Supers: " . $stats[ 'strikesupers' ] . "</h3>" .
"<h3>Ki Blast Supers: " . $stats[ 'kisupers' ] . "</h3>";
return $result;
}
}
$stat_tracker = new Stat_Calculator();
$stat_tracker->show_level_proposition();