-
Notifications
You must be signed in to change notification settings - Fork 35
/
jumpgate.php
121 lines (104 loc) · 3.72 KB
/
jumpgate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
define('INSIDE', true);
$_EnginePath = './';
include($_EnginePath.'common.php');
loggedCheck();
includeLang('jumpgate');
function ShowMessage($Text)
{
global $_Lang;
message($Text, $_Lang['tech'][43], 'infos.php?gid=43', 4);
}
if(isset($_POST['dojump']) && $_POST['dojump'] != 'yes')
{
ShowMessage($_Lang['GateJump_NotDoing']);
}
if($_Planet['planet_type'] != 3)
{
ShowMessage($_Lang['GateJump_NotOnMoon']);
}
if($_Planet[$_Vars_GameElements[43]] <= 0)
{
ShowMessage($_Lang['GateJump_NoTeleportOnMoon1']);
}
$This_JumpState = GetNextJumpWaitTime($_Planet);
$This_NextJumpTime = $This_JumpState['value'];
if($This_NextJumpTime != 0)
{
ShowMessage("{$_Lang['GateJump_Moon1NotReach']} {$This_JumpState['string']}");
}
$Target_ID = (isset($_POST['jumpto']) ? round($_POST['jumpto']) : 0);
if($Target_ID <= 0)
{
ShowMessage($_Lang['GateJump_BadIDGiven']);
}
$Query_CheckTarget = "SELECT `id`, `jumpgate`, `last_jump_time` FROM {{table}} WHERE `id` = {$Target_ID} AND `id_owner` = {$_User['id']} LIMIT 1;";
$Target_Data = doquery($Query_CheckTarget, 'planets', true);
if($Target_Data['id'] != $Target_ID)
{
ShowMessage($_Lang['GateJump_Moon2NotYours']);
}
if($Target_Data[$_Vars_GameElements[43]] <= 0)
{
ShowMessage($_Lang['GateJump_NoTeleportOnMoon2']);
}
$Target_JumpState = GetNextJumpWaitTime($Target_Data);
$Target_NextJumpTime = $Target_JumpState['value'];
if($Target_NextJumpTime != 0)
{
ShowMessage("{$_Lang['GateJump_Moon2NotReach']} {$Target_JumpState['string']}");
}
foreach($_Vars_ElementCategories['fleet'] as $ShipID)
{
$ThisKey = 'ship_'.$ShipID;
if(!empty($_POST[$ThisKey]))
{
$ThisCount = round(str_replace('.', '', $_POST[$ThisKey]));
if($ThisCount > 0)
{
if($_Planet[$_Vars_GameElements[$ShipID]] > 0)
{
if($ThisCount > $_Planet[$_Vars_GameElements[$ShipID]])
{
$ThisCount = $_Planet[$_Vars_GameElements[$ShipID]];
}
$JumpData_Fleet[$ShipID] = $ThisCount;
}
}
}
}
if(empty($JumpData_Fleet))
{
ShowMessage($_Lang['GateJump_BadPOSTFound']);
}
$JumpData_Time = time();
foreach($JumpData_Fleet as $ShipID => $ShipCount)
{
$_Planet[$_Vars_GameElements[$ShipID]] -= $ShipCount;
$Query_UpdateThis_Fields[] = "`{$_Vars_GameElements[$ShipID]}` = `{$_Vars_GameElements[$ShipID]}` - {$ShipCount}";
$Query_UpdateTarget_Fields[] = "`{$_Vars_GameElements[$ShipID]}` = `{$_Vars_GameElements[$ShipID]}` + {$ShipCount}";
}
$Query_UpdateThis_Fields[] = "`last_jump_time` = {$JumpData_Time}";
$Query_UpdateTarget_Fields[] = "`last_jump_time` = {$JumpData_Time}";
$Query_UpdateThis = '';
$Query_UpdateThis .= "UPDATE {{table}} SET ";
$Query_UpdateThis .= implode(', ', $Query_UpdateThis_Fields);
$Query_UpdateThis .= " WHERE `id` = {$_Planet['id']} LIMIT 1;";
$Query_UpdateTarget = '';
$Query_UpdateTarget .= "UPDATE {{table}} SET ";
$Query_UpdateTarget .= implode(', ', $Query_UpdateTarget_Fields);
$Query_UpdateTarget .= " WHERE `id` = {$Target_ID} LIMIT 1;";
$Query_UpdateUser = '';
$Query_UpdateUser .= "UPDATE {{table}} SET `current_planet` = {$Target_ID} ";
$Query_UpdateUser .= "WHERE `id` = {$_User['id']} LIMIT 1;";
$_Planet['last_jump_time'] = $JumpData_Time;
doquery($Query_UpdateThis, 'planets');
doquery($Query_UpdateTarget, 'planets');
if(isset($_POST['changemoon']) && $_POST['changemoon'] == 'on')
{
doquery($Query_UpdateUser, 'users');
}
$UserDev_Log[] = array('PlanetID' => $_Planet['id'], 'Date' => $JumpData_Time, 'Place' => 27, 'Code' => 0, 'ElementID' => $Target_ID, 'AdditionalData' => Array2String($JumpData_Fleet));
$This_NewJumpState = GetNextJumpWaitTime($_Planet);
ShowMessage("{$_Lang['GateJump_Done']} {$This_NewJumpState['string']}");
?>