Test Failed
Push — trunk ( 132e87...b3f953 )
by SuperNova.WS
11:54
created

flt_mission_colonize()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 45
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 27
nc 5
nop 1
dl 0
loc 45
rs 9.1768
c 0
b 0
f 0
1
<?php /** @noinspection PhpUnnecessaryCurlyVarSyntaxInspection */
2
3
use Fleet\DbFleetStatic;
4
use Fleet\FleetDispatchEvent;
5
6
/**
7
 * @param FleetDispatchEvent $fleetEvent
8
 *
9
 * @return int|mixed
10
 */
11
function flt_mission_colonize($fleetEvent) {
12
  $fleet_row    = $fleetEvent->fleet;
13
  /** @noinspection PhpDeprecationInspection */
14
  $fleetOwnerRow = db_user_by_id($fleetEvent->fleet['fleet_owner'], 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

14
  $fleetOwnerRow = /** @scrutinizer ignore-deprecated */ db_user_by_id($fleetEvent->fleet['fleet_owner'], true);
Loading history...
15
16
  global $lang;
17
18
  $targetAddress = sprintf($lang['sys_address_planet'], $fleet_row['fleet_end_galaxy'], $fleet_row['fleet_end_system'], $fleet_row['fleet_end_planet']);
19
20
  $fleet_array = sys_unit_str2arr($fleet_row['fleet_array']);
21
22
  $TheMessage = $lang['sys_colo_no_colonizer'];
23
  if ($fleet_array[SHIP_COLONIZER] >= 1) {
24
    $TheMessage = $lang['sys_colo_not_free'];
25
    if (empty($fleetEvent->dstPlanetRow)) {
26
      $iPlanetCount = get_player_current_colonies($fleetOwnerRow);
27
28
      // Can we colonize more planets?
29
      $TheMessage = $lang['sys_colo_max_colo'];
30
      if ($iPlanetCount < get_player_max_colonies($fleetOwnerRow)) {
31
        // Yes, we can colonize
32
        $TheMessage     = $lang['sys_colo_bad_pos'];
33
        $NewOwnerPlanet = uni_create_planet(
34
          $fleet_row['fleet_end_galaxy'], $fleet_row['fleet_end_system'], $fleet_row['fleet_end_planet'],
35
          $fleet_row['fleet_owner'], "{$lang['sys_colo_default_name']} {$iPlanetCount}", false,
36
          array('user_row' => $fleetOwnerRow));
37
        if ($NewOwnerPlanet) {
38
          $TheMessage = $lang['sys_colo_arrival'] . $targetAddress . $lang['sys_colo_all_is_ok'];
39
          msg_send_simple_message($fleet_row['fleet_owner'], '', $fleet_row['fleet_start_time'], MSG_TYPE_SPY, $lang['sys_colo_mess_from'], $lang['sys_colo_mess_report'], $TheMessage);
40
41
          $fleet_array[SHIP_COLONIZER]--;
42
          $fleet_row['fleet_amount']--;
43
          $fleet_row['fleet_array'] = sys_unit_arr2str($fleet_array);
44
45
          /** @noinspection PhpDeprecationInspection */
46
          return RestoreFleetToPlanet($fleet_row, false);
0 ignored issues
show
Deprecated Code introduced by
The function RestoreFleetToPlanet() 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

46
          return /** @scrutinizer ignore-deprecated */ RestoreFleetToPlanet($fleet_row, false);
Loading history...
47
        }
48
      }
49
    }
50
  }
51
52
  DbFleetStatic::fleet_send_back($fleet_row);
53
  msg_send_simple_message($fleet_row['fleet_owner'], '', $fleet_row['fleet_start_time'], MSG_TYPE_SPY, $lang['sys_colo_mess_from'], $lang['sys_colo_mess_report'], "{$lang['sys_colo_arrival']}{$targetAddress}{$TheMessage}");
54
55
  return CACHE_FLEET;
56
}
57