1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by Gorlum 13.02.2018 12:45 |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
use \Fleet\RecordFleet; |
7
|
|
|
|
8
|
|
|
class Universe { |
|
|
|
|
9
|
|
|
|
10
|
|
|
const MOON_MIN_SIZE = 1100; |
11
|
|
|
const MOON_MAX_SIZE = 8999; |
12
|
|
|
|
13
|
|
|
const MOON_DEBRIS_MIN = 1000000; // Minimum amount of debris to span a moon |
14
|
|
|
const MOON_CHANCE_MIN_PERCENT = 1; // Minimum chance to span a moon |
15
|
|
|
const MOON_CHANCE_MAX_PERCENT = 30; // Maximum chance to span a moon |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Calc moon chance from debris |
19
|
|
|
* |
20
|
|
|
* @param float $debrisTotal |
21
|
|
|
* |
22
|
|
|
* @return float |
23
|
|
|
*/ |
24
|
|
|
public static function moonCalcChanceFromDebris($debrisTotal) { |
25
|
|
|
$moon_chance = $debrisTotal / static::moonPercentCostInDebris(); |
26
|
|
|
|
27
|
|
|
$moon_chance = $moon_chance < static::MOON_CHANCE_MIN_PERCENT ? 0 : $moon_chance; |
28
|
|
|
$moon_chance = $moon_chance > static::MOON_CHANCE_MAX_PERCENT ? static::MOON_CHANCE_MAX_PERCENT : $moon_chance; |
29
|
|
|
|
30
|
|
|
return $moon_chance; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Roll moon size from rolled fracture |
35
|
|
|
* |
36
|
|
|
* @param float $rolledChance |
37
|
|
|
* |
38
|
|
|
* @return int |
39
|
|
|
*/ |
40
|
|
|
protected static function moonRollSizeSecondary($rolledChance) { |
41
|
|
|
$minSize = max(static::MOON_MIN_SIZE, $rolledChance * 100 + 1000); |
42
|
|
|
$maxSize = min(static::MOON_MAX_SIZE, $rolledChance * 200 + 2999); |
43
|
|
|
|
44
|
|
|
return mt_rand($minSize, $maxSize); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Roll moon size from debris amount |
49
|
|
|
* |
50
|
|
|
* @param int|float $debrisTotal |
51
|
|
|
* |
52
|
|
|
* @return int |
53
|
|
|
*/ |
54
|
|
|
public static function moonRollSize($debrisTotal) { |
55
|
|
|
$roll = mt_rand(1, 100); |
56
|
|
|
if ($roll <= static::moonCalcChanceFromDebris($debrisTotal)) { |
57
|
|
|
$moonSize = Universe::moonRollSizeSecondary($roll); |
58
|
|
|
} else { |
59
|
|
|
$moonSize = 0; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $moonSize; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Real cost of 1% moon creation size in debris |
68
|
|
|
* |
69
|
|
|
* @return float|int |
70
|
|
|
*/ |
71
|
|
|
public static function moonPercentCostInDebris() { |
72
|
|
|
return game_resource_multiplier(true) * static::MOON_DEBRIS_MIN; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Max debris cost for max sized moon |
77
|
|
|
* |
78
|
|
|
* @return float|int |
79
|
|
|
*/ |
80
|
|
|
public static function moonMaxDebris() { |
81
|
|
|
return static::MOON_CHANCE_MAX_PERCENT * static::moonPercentCostInDebris(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Random moon size within allowed limits |
86
|
|
|
* |
87
|
|
|
* @return int |
88
|
|
|
*/ |
89
|
|
|
public static function moonSizeRandom() { |
90
|
|
|
return mt_rand(static::MOON_MIN_SIZE, static::MOON_MAX_SIZE); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Return fleets heading to specified location |
96
|
|
|
* |
97
|
|
|
* @param int|null $galaxy |
98
|
|
|
* @param int|null $system |
99
|
|
|
* @param int|null $planet |
100
|
|
|
* @param bool $fromHold - Should be fleets on active Hold mission returned too |
101
|
|
|
*/ |
102
|
|
|
public static function fleetsReturn($galaxy = null, $system = null, $planet = null, $type = null, $fromHold = true) { |
103
|
|
|
$filter = []; |
104
|
|
|
$galaxy ? $filter['fleet_end_galaxy'] = $galaxy : false; |
105
|
|
|
$galaxy ? $filter['fleet_end_system'] = $system : false; |
106
|
|
|
$galaxy ? $filter['fleet_end_planet'] = $planet : false; |
107
|
|
|
$galaxy ? $filter['fleet_end_type'] = $type : false; |
108
|
|
|
$fleetsResult = RecordFleet::findAll($filter); |
109
|
|
|
foreach ($fleetsResult as $fleetRecord) { |
110
|
|
|
if ($fleetRecord->fleet_mess == FLEET_STATUS_RETURNING) { |
111
|
|
|
continue; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
if($fleetRecord->fleet_mission == MT_HOLD) { |
115
|
|
|
if (!$fromHold) { |
116
|
|
|
continue; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
// Changing end time |
120
|
|
|
$fleetRecord->fleet_end_stay = SN_TIME_NOW; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
$fleetRecord->fleet_mess = FLEET_STATUS_RETURNING; |
124
|
|
|
|
125
|
|
|
$fleetRecord->update(); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
} |
130
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.