Completed
Push — trunk ( 5a98ee...c2d255 )
by SuperNova.WS
04:09
created

Universe::moonMaxDebris()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 1
b 0
f 0
ccs 0
cts 2
cp 0
crap 2
1
<?php
2
/**
3
 * Created by Gorlum 13.02.2018 12:45
4
 */
5
6
class Universe {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
8
  const MOON_MIN_SIZE = 1100;
9
  const MOON_MAX_SIZE = 8999;
10
11
  const MOON_DEBRIS_MIN = 1000000;    // Minimum amount of debris to span a moon
12
  const MOON_CHANCE_MIN_PERCENT = 1;  // Minimum chance to span a moon
13
  const MOON_CHANCE_MAX_PERCENT = 30; // Maximum chance to span a moon
14
15
  /**
16
   * Calc moon chance from debris
17
   *
18
   * @param float $debrisTotal
19
   *
20
   * @return float
21
   */
22
  public static function moonCalcChanceFromDebris($debrisTotal) {
23
    $moon_chance = $debrisTotal / static::moonPercentCostInDebris();
24
25
    $moon_chance = $moon_chance < static::MOON_CHANCE_MIN_PERCENT ? 0 : $moon_chance;
26
    $moon_chance = $moon_chance > static::MOON_CHANCE_MAX_PERCENT ? static::MOON_CHANCE_MAX_PERCENT : $moon_chance;
27
28
    return $moon_chance;
29
  }
30
31
  /**
32
   * Roll moon size from rolled fracture
33
   *
34
   * @param float $rolledChance
35
   *
36
   * @return int
37
   */
38
  protected static function moonRollSizeSecondary($rolledChance) {
39
    $minSize = max(static::MOON_MIN_SIZE, $rolledChance * 100 + 1000);
40
    $maxSize = min(static::MOON_MAX_SIZE, $rolledChance * 200 + 2999);
41
42
    return mt_rand($minSize, $maxSize);
43
  }
44
45
  /**
46
   * Roll moon size from debris amount
47
   *
48
   * @param int|float $debrisTotal
49
   *
50
   * @return int
51
   */
52
  public static function moonRollSize($debrisTotal) {
53
    $roll = mt_rand(1, 100);
54
    if($roll <= static::moonCalcChanceFromDebris($debrisTotal)) {
55
      $moonSize = Universe::moonRollSizeSecondary($roll);
56
    } else {
57
      $moonSize = 0;
58
    }
59
60
    return $moonSize;
61
  }
62
63
64
  /**
65
   * Real cost of 1% moon creation size in debris
66
   *
67
   * @return float|int
68
   */
69
  public static function moonPercentCostInDebris() {
70
    return game_resource_multiplier(true) * static::MOON_DEBRIS_MIN;
71
  }
72
73
  /**
74
   * Max debris cost for max sized moon
75
   *
76
   * @return float|int
77
   */
78
  public static function moonMaxDebris() {
79
    return static::MOON_CHANCE_MAX_PERCENT * static::moonPercentCostInDebris();
80
  }
81
82
  /**
83
   * Random moon size within allowed limits
84
   *
85
   * @return int
86
   */
87
  public static function moonSizeRandom() {
88
    return mt_rand(static::MOON_MIN_SIZE, static::MOON_MAX_SIZE);
89
  }
90
91
}
92