Issues (1369)

includes/general/general_playerFunctions.php (4 issues)

Labels
Severity
1
<?php
2
3
use Planet\DBStaticPlanet;
4
5
/**
6
 * Created by Gorlum 04.12.2017 4:34
7
 */
8
9
// ----------------------------------------------------------------------------------------------------------------
10
function sys_user_options_pack(&$user) {
11
  global $user_option_list;
12
13
  $options = '';
14
  $option_list = array();
15
  foreach ($user_option_list as $option_group_id => $option_group) {
16
    $option_list[$option_group_id] = array();
17
    foreach ($option_group as $option_name => $option_value) {
18
      if (!isset($user[$option_name])) {
19
        $user[$option_name] = $option_value;
20
      } elseif ($user[$option_name] == '') {
21
        $user[$option_name] = 0;
22
      }
23
      $options .= "{$option_name}^{$user[$option_name]}" . USER_OPTIONS_SPLIT;
24
      $option_list[$option_group_id][$option_name] = $user[$option_name];
25
    }
26
  }
27
28
  $user['options'] = $options;
29
  $user['option_list'] = $option_list;
30
31
  return $options;
32
}
33
34
function sys_user_options_unpack(&$user) {
35
  global $user_option_list;
36
37
  $option_list = array();
38
  $option_string_list = explode(USER_OPTIONS_SPLIT, $user['options']);
39
40
  foreach ($option_string_list as $option_string) {
41
    list($option_name, $option_value) = explode('^', $option_string);
42
    $option_list[$option_name] = $option_value;
43
  }
44
45
  $final_list = array();
46
  foreach ($user_option_list as $option_group_id => $option_group) {
47
    $final_list[$option_group_id] = array();
48
    foreach ($option_group as $option_name => $option_value) {
49
      if (!isset($option_list[$option_name])) {
50
        $option_list[$option_name] = $option_value;
51
      }
52
      $user[$option_name] = $final_list[$option_group_id][$option_name] = $option_list[$option_name];
53
    }
54
  }
55
56
  $user['option_list'] = $final_list;
57
58
  return $final_list;
59
}
60
61
62
// ----------------------------------------------------------------------------------------------------------------
63
function get_player_max_expeditons(&$user, $astrotech = -1) { $result = null; return sn_function_call('get_player_max_expeditons', array(&$user, $astrotech, &$result)); }
64
65
function sn_get_player_max_expeditons(&$user, $astrotech = -1, &$result = 0) {
66
  if ($astrotech == -1) {
67
    if (!isset($user[UNIT_PLAYER_EXPEDITIONS_MAX])) {
68
      $astrotech = mrc_get_level($user, false, TECH_ASTROTECH);
0 ignored issues
show
false of type false is incompatible with the type array expected by parameter $planet of mrc_get_level(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

68
      $astrotech = mrc_get_level($user, /** @scrutinizer ignore-type */ false, TECH_ASTROTECH);
Loading history...
69
      $user[UNIT_PLAYER_EXPEDITIONS_MAX] = $astrotech >= 1 ? floor(sqrt($astrotech - 1)) : 0;
70
    }
71
72
    return $result += $user[UNIT_PLAYER_EXPEDITIONS_MAX];
73
  } else {
74
    return $result += $astrotech >= 1 ? floor(sqrt($astrotech - 1)) : 0;
75
  }
76
}
77
78
function get_player_max_expedition_duration(&$user, $astrotech = -1) {
79
  return $astrotech == -1 ? mrc_get_level($user, false, TECH_ASTROTECH) : $astrotech;
0 ignored issues
show
false of type false is incompatible with the type array expected by parameter $planet of mrc_get_level(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

79
  return $astrotech == -1 ? mrc_get_level($user, /** @scrutinizer ignore-type */ false, TECH_ASTROTECH) : $astrotech;
Loading history...
80
}
81
82
function get_player_max_colonies(&$user, $astrotech = -1) {
83
  if ($astrotech == -1) {
84
    if (!isset($user[UNIT_PLAYER_COLONIES_MAX])) {
85
86
      $expeditions = get_player_max_expeditons($user);
87
      $astrotech = mrc_get_level($user, false, TECH_ASTROTECH);
0 ignored issues
show
false of type false is incompatible with the type array expected by parameter $planet of mrc_get_level(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
      $astrotech = mrc_get_level($user, /** @scrutinizer ignore-type */ false, TECH_ASTROTECH);
Loading history...
88
      $colonies = $astrotech - $expeditions;
89
90
      $user[UNIT_PLAYER_COLONIES_MAX] = SN::$config->player_max_colonies < 0 ? $colonies : min(SN::$config->player_max_colonies, $colonies);
91
    }
92
93
    return $user[UNIT_PLAYER_COLONIES_MAX];
94
  } else {
95
    $expeditions = get_player_max_expeditons($user, $astrotech);
96
    $colonies = $astrotech - $expeditions;
97
98
    return SN::$config->player_max_colonies < 0 ? $colonies : min(SN::$config->player_max_colonies, $colonies);
99
  }
100
}
101
102
function get_player_current_colonies(&$user) {
103
  return $user[UNIT_PLAYER_COLONIES_CURRENT] = isset($user[UNIT_PLAYER_COLONIES_CURRENT]) ? $user[UNIT_PLAYER_COLONIES_CURRENT] : max(0, DBStaticPlanet::db_planet_count_by_type($user['id']) - 1);
104
}
105
106
function GetSpyLevel(&$user) {
107
  return mrc_modify_value($user, false, array(MRC_SPY, TECH_SPY), 0);
108
}
109
110
function GetMaxFleets(&$user) {
111
  return mrc_modify_value($user, false, array(MRC_COORDINATOR, TECH_COMPUTER), 1);
112
}
113
114
115
// ----------------------------------------------------------------------------------------------------------------
116
/**
117
 * @param int|string $user_id
118
 * @param int|string $capitalPlanetId
119
 *
120
 * @return mixed
121
 */
122
function sys_player_new_adjust($user_id, $capitalPlanetId) { $result = null; return sn_function_call('sys_player_new_adjust', array($user_id, $capitalPlanetId, &$result)); }
123
124
function sn_sys_player_new_adjust($user_id, $planet_id, &$result) {
125
  return $result;
126
}
127
128
129
// ----------------------------------------------------------------------------------------------------------------
130
function flt_get_missile_range($user) {
131
  return max(0, mrc_get_level($user, false, TECH_ENGINE_ION) * 5 - 1);
0 ignored issues
show
false of type false is incompatible with the type array expected by parameter $planet of mrc_get_level(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

131
  return max(0, mrc_get_level($user, /** @scrutinizer ignore-type */ false, TECH_ENGINE_ION) * 5 - 1);
Loading history...
132
}
133
134