Issues (1369)

classes/Universe/Universe.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Created by Gorlum 13.02.2018 12:45
4
 */
5
6
namespace Universe;
7
8
use \Fleet\RecordFleet;
0 ignored issues
show
The type \Fleet\RecordFleet was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

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