Issues (1369)

jumpgate.php (4 issues)

1
<?php
2
/** @noinspection PhpDeprecationInspection */
3
4
/**
5
 * jumpgate.php
6
 *
7
 * Jump Gate interface, I presume
8
 */
9
10
use DBAL\db_mysql;
11
use DBAL\OldDbChangeSet;
12
use Planet\DBStaticPlanet;
13
14
include('common.' . substr(strrchr(__FILE__, '.'), 1));
15
16
global $user, $planetrow, $lang;
17
18
lng_include('fleet');
19
20
/** @noinspection SpellCheckingInspection */
21
if ($TargetPlanet = sys_get_param_id('jmpto')) {
22
  db_mysql::db_transaction_start();
23
  db_user_by_id($user['id'], true);
0 ignored issues
show
Deprecated Code introduced by
The function db_user_by_id() has been deprecated. ( Ignorable by Annotation )

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

23
  /** @scrutinizer ignore-deprecated */ db_user_by_id($user['id'], true);
Loading history...
24
  $planetrow = DBStaticPlanet::db_planet_by_id($planetrow['id'], true);
25
  if (!($NextJumpTime = uni_get_time_to_jump($planetrow))) {
26
    $TargetGate = DBStaticPlanet::db_planet_by_id($TargetPlanet, true);
27
    if (mrc_get_level($user, $TargetGate, STRUC_MOON_GATE) > 0) {
28
      $NextDestTime = uni_get_time_to_jump($TargetGate);
29
      if (!$NextDestTime) {
30
        // $SubQueryOri = "";
31
        // $SubQueryDes = "";
32
        $ship_list    = sys_get_param('ships');
33
        $db_changeset = array();
34
        foreach ($ship_list as $ship_id => $ship_count) {
35
          if (!in_array($ship_id, sn_get_groups('fleet'))) {
36
            continue;
37
          }
38
39
          $ship_count = max(0, min(floor($ship_count), mrc_get_level($user, $planetrow, $ship_id)));
40
          if ($ship_count) {
41
            $db_changeset['unit'][] = OldDbChangeSet::db_changeset_prepare_unit($ship_id, -$ship_count, $user, $planetrow['id']);
42
            $db_changeset['unit'][] = OldDbChangeSet::db_changeset_prepare_unit($ship_id, $ship_count, $user, $TargetGate['id']);
43
          }
44
        }
45
46
        if (!empty($db_changeset)) {
47
          DBStaticPlanet::db_planet_set_by_id($TargetGate['id'], "`last_jump_time` = " . SN_TIME_NOW);
48
          DBStaticPlanet::db_planet_set_by_id($planetrow['id'], "`last_jump_time` = " . SN_TIME_NOW);
49
          OldDbChangeSet::db_changeset_apply($db_changeset);
50
51
          db_user_set_by_id($user['id'], "`current_planet` = '{$TargetGate['id']}'");
0 ignored issues
show
Deprecated Code introduced by
The function db_user_set_by_id() has been deprecated. ( Ignorable by Annotation )

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

51
          /** @scrutinizer ignore-deprecated */ db_user_set_by_id($user['id'], "`current_planet` = '{$TargetGate['id']}'");
Loading history...
52
53
          $planetrow['last_jump_time'] = SN_TIME_NOW;
54
          $RetMessage                  = $lang['gate_jump_done'] . " - " . pretty_time(uni_get_time_to_jump($planetrow));
55
        } else {
56
          $RetMessage = $lang['gate_wait_data'];
57
        }
58
      } else {
59
        $RetMessage = $lang['gate_wait_dest'] . " - " . pretty_time($NextDestTime);
60
      }
61
    } else {
62
      $RetMessage = $lang['gate_no_dest_g'];
63
    }
64
  } else {
65
    $RetMessage = $lang['gate_wait_star'] . " - " . pretty_time($NextJumpTime);
66
  }
67
  db_mysql::db_transaction_commit();
68
  SnTemplate::messageBox($RetMessage, $lang['tech'][STRUC_MOON_GATE], "jumpgate.php", 10);
69
} else {
70
  $template = SnTemplate::gettemplate('jumpgate', true);
0 ignored issues
show
true of type true is incompatible with the type null|template expected by parameter $template of SnTemplate::gettemplate(). ( Ignorable by Annotation )

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

70
  $template = SnTemplate::gettemplate('jumpgate', /** @scrutinizer ignore-type */ true);
Loading history...
71
  if (mrc_get_level($user, $planetrow, STRUC_MOON_GATE) > 0) {
72
    $Combo    = '';
73
    $MoonList = DBStaticPlanet::db_planet_list_moon_other($user['id'], $planetrow['id']);
74
    // while($CurMoon = db_fetch($MoonList))
75
    foreach ($MoonList as $CurMoon) {
76
      if (mrc_get_level($user, $CurMoon, STRUC_MOON_GATE) >= 1) {
77
        $NextJumpTime = uni_get_time_to_jump($CurMoon);
78
        $template->assign_block_vars('moon', array(
79
          'ID'             => $CurMoon['id'],
80
          'GALAXY'         => $CurMoon['galaxy'],
81
          'SYSTEM'         => $CurMoon['system'],
82
          'PLANET'         => $CurMoon['planet'],
83
          'NAME'           => $CurMoon['name'],
84
          'NEXT_JUMP_TIME' => $NextJumpTime ? pretty_time($NextJumpTime) : '',
85
        ));
86
      }
87
    }
88
89
    foreach (sn_get_groups('fleet') as $Ship) {
90
      if (($ship_count = mrc_get_level($user, $planetrow, $Ship)) <= 0) {
91
        continue;
92
      }
93
94
      $template->assign_block_vars('fleet', array(
95
        'SHIP_ID'         => $Ship,
96
        'SHIP_NAME'       => $lang['tech'][$Ship],
97
        'SHIP_COUNT'      => $ship_count,
98
        'SHIP_COUNT_TEXT' => HelperString::numberFloorAndFormat($ship_count),
0 ignored issues
show
It seems like $ship_count can also be of type boolean; however, parameter $number of HelperString::numberFloorAndFormat() does only seem to accept double|integer, maybe add an additional type check? ( Ignorable by Annotation )

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

98
        'SHIP_COUNT_TEXT' => HelperString::numberFloorAndFormat(/** @scrutinizer ignore-type */ $ship_count),
Loading history...
99
      ));
100
    }
101
102
    $template->assign_vars(array(
103
      'GATE_JUMP_REST_TIME' => uni_get_time_to_jump($planetrow),
104
      'gate_start_name'     => $planetrow['name'],
105
      'gate_start_link'     => uni_render_coordinates_href($planetrow, '', 3),
106
    ));
107
108
    SnTemplate::display($template, $lang['tech'][STRUC_MOON_GATE]);
109
  } else {
110
    SnTemplate::messageBox($lang['gate_no_src_ga'], $lang['tech'][STRUC_MOON_GATE], "overview.php", 10);
111
  }
112
}
113