Issues (1369)

classes/Que/QueUnitStatic.php (1 issue)

Severity
1
<?php
2
/**
3
 * Created by Gorlum 24.03.2018 19:45
4
 */
5
6
namespace Que;
7
8
use DBAL\db_mysql;
9
use Planet\DBStaticPlanet;
10
use SN;
11
12
class QueUnitStatic {
13
14
  /**
15
   * @param array $prevSqlBlock
16
   * @param int   $unit_id
17
   * @param array $user
18
   * @param array $planet
19
   * @param array $build_data
20
   * @param int   $unit_level
21
   * @param int   $unit_amount
22
   * @param int   $build_mode
23
   *
24
   * @return array
25
   */
26
  public static function que_unit_make_sql($prevSqlBlock = [], $unit_id, $user = array(), $planet = array(), $build_data, $unit_level = 0, $unit_amount = 1, $build_mode = BUILD_CREATE) {
27
    // TODO Унифицировать проверки
28
29
    // TODO que_process() тут
30
31
    db_mysql::db_transaction_check(true);
32
33
    $build_mode = $build_mode == BUILD_CREATE ? BUILD_CREATE : BUILD_DESTROY;
34
35
    // TODO: Some checks
36
    db_change_units($user, $planet, array(
37
      RES_METAL     => -$build_data[$build_mode][RES_METAL] * $unit_amount,
38
      RES_CRYSTAL   => -$build_data[$build_mode][RES_CRYSTAL] * $unit_amount,
39
      RES_DEUTERIUM => -$build_data[$build_mode][RES_DEUTERIUM] * $unit_amount,
40
    ));
41
42
    $que_type         = que_get_unit_que($unit_id);
43
    $planet_id_origin = $planet['id'] ? floatval($planet['id']) : null;
44
    $planet_id        = $que_type == QUE_RESEARCH ? null : $planet_id_origin;
45
    if (is_numeric($planet_id)) {
46
      DBStaticPlanet::db_planet_set_by_id($planet_id, "`que_processed` = UNIX_TIMESTAMP(NOW())");
47
    } elseif (is_numeric($user['id'])) {
48
      db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())');
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

48
      /** @scrutinizer ignore-deprecated */ db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())');
Loading history...
49
    }
50
51
    $resource_list = sys_unit_arr2str($build_data[$build_mode]);
52
53
    $result = [
54
      'que_player_id'         => $user['id'],
55
      'que_planet_id'         => $planet_id,
56
      'que_planet_id_origin'  => $planet_id_origin,
57
      'que_type'              => $que_type,
58
      'que_time_left'         => $build_data[RES_TIME][$build_mode],
59
      'que_unit_id'           => $unit_id,
60
      'que_unit_amount'       => $unit_amount,
61
      'que_unit_mode'         => $build_mode,
62
      'que_unit_level'        => $unit_level,
63
      'que_unit_time'         => $build_data[RES_TIME][$build_mode],
64
      'que_unit_price'        => $resource_list,
65
      'que_unit_one_time_raw' => $build_data[P_OPTIONS][P_TIME_RAW],
66
    ];
67
68
    return $result;
69
  }
70
71
}
72