1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Created by Gorlum 20.02.2016 18:04 |
5
|
|
|
*/ |
6
|
|
|
class UBEDebris { |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @var array [$resource_id] => (int)$resource_amount |
10
|
|
|
*/ |
11
|
|
|
protected $debris = array(); |
12
|
|
|
|
13
|
|
|
public function __construct() { |
14
|
|
|
// $this->_reset(); |
|
|
|
|
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function _reset() { |
18
|
|
|
$this->debris = array( |
19
|
|
|
RES_METAL => 0, |
20
|
|
|
RES_CRYSTAL => 0, |
21
|
|
|
); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param int $resource_id |
26
|
|
|
* @param float $resource_amount |
27
|
|
|
*/ |
28
|
|
|
public function debris_add_resource($resource_id, $resource_amount) { |
29
|
|
|
// В обломках может быть только металл или кристалл |
30
|
|
|
if($resource_id != RES_METAL && $resource_id != RES_CRYSTAL) { |
31
|
|
|
return; |
32
|
|
|
} |
33
|
|
|
$this->debris[$resource_id] += $resource_amount; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param array $wreckage Список ресурсов, выпавших в обломки с кораблей |
38
|
|
|
* @param bool $is_simulator |
39
|
|
|
*/ |
40
|
|
|
public function add_wrecks(array $wreckage, $is_simulator) { |
41
|
|
|
foreach($wreckage as $resource_id => $resource_amount) { |
42
|
|
|
$this->debris_add_resource($resource_id, floor($resource_amount * |
43
|
|
|
($is_simulator |
44
|
|
|
? UBE_SHIP_WRECKS_TO_DEBRIS_AVG |
45
|
|
|
: mt_rand(UBE_SHIP_WRECKS_TO_DEBRIS_MIN, UBE_SHIP_WRECKS_TO_DEBRIS_MAX) |
46
|
|
|
) |
47
|
|
|
/ 100 |
48
|
|
|
)); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param array $dropped_resources Список ресурсов, выброшенных из трюма |
54
|
|
|
* @param bool $is_simulator |
55
|
|
|
*/ |
56
|
|
|
public function add_cargo_drop(array $dropped_resources, $is_simulator) { |
57
|
|
|
foreach($dropped_resources as $resource_id => $resource_amount) { |
58
|
|
|
$this->debris_add_resource($resource_id, floor($resource_amount * |
59
|
|
|
($is_simulator |
60
|
|
|
? UBE_CARGO_DROPPED_TO_DEBRIS_AVG |
61
|
|
|
: mt_rand(UBE_CARGO_DROPPED_TO_DEBRIS_MIN, UBE_CARGO_DROPPED_TO_DEBRIS_MAX) |
62
|
|
|
) |
63
|
|
|
/ 100 |
64
|
|
|
)); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
public function get_debris() { |
73
|
|
|
return !empty($this->debris) ? $this->debris : array(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param int $resource_id |
78
|
|
|
* |
79
|
|
|
* @return float |
80
|
|
|
*/ |
81
|
|
|
public function debris_get_resource($resource_id) { |
82
|
|
|
return !empty($this->debris[$resource_id]) ? floor($this->debris[$resource_id]) : 0.0; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return float |
87
|
|
|
*/ |
88
|
|
|
public function debris_total() { |
89
|
|
|
return empty($this->debris) || !is_array($this->debris) ? 0.0 : floor(array_sum($this->debris)); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param $moon_debris_left_part |
94
|
|
|
*/ |
95
|
|
|
public function debris_adjust_proportional($moon_debris_left_part) { |
96
|
|
|
foreach($this->debris as $resource_id => &$resource_amount) { |
97
|
|
|
$resource_amount = floor($resource_amount * $moon_debris_left_part); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return int |
103
|
|
|
*/ |
104
|
|
|
public function debris_in_metal() { |
105
|
|
|
return floatval( |
106
|
|
|
($this->debris_get_resource(RES_METAL) + $this->debris_get_resource(RES_CRYSTAL) * classSupernova::$config->rpg_exchange_crystal) |
107
|
|
|
/ |
108
|
|
|
(floatval(classSupernova::$config->rpg_exchange_metal) ? floatval(classSupernova::$config->rpg_exchange_metal) : 1) |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return array |
114
|
|
|
*/ |
115
|
|
|
public function report_generate_array() { |
116
|
|
|
return array( |
117
|
|
|
'ube_report_debris_metal' => (float)$this->debris_get_resource(RES_METAL), |
118
|
|
|
'ube_report_debris_crystal' => (float)$this->debris_get_resource(RES_CRYSTAL), |
119
|
|
|
'ube_report_debris_total_in_metal' => (float)$this->debris_in_metal(), |
120
|
|
|
); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param array $report_row |
125
|
|
|
*/ |
126
|
|
|
public function load_from_report_row(array $report_row) { |
127
|
|
|
// $this->_reset(); |
|
|
|
|
128
|
|
|
$this->debris_add_resource(RES_METAL, $report_row['ube_report_debris_metal']); |
129
|
|
|
$this->debris_add_resource(RES_CRYSTAL, $report_row['ube_report_debris_crystal']); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.