forked from H3Gi/tatar-wars
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresources.php
More file actions
93 lines (66 loc) · 2.51 KB
/
Copy pathresources.php
File metadata and controls
93 lines (66 loc) · 2.51 KB
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
<?php
require( '.' . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'boot.php' );
require_once( MODEL_PATH . 'resources.php' );
class GPage extends SecureGamePage {
var $isAdmin = null;
var $villageId = null;
var $villageName = null;
var $playerName = null;
var $resources = null;
var $msgText = null;
function GPage() {
$this->customLogoutAction = TRUE;
parent::securegamepage();
if ($this->player == NULL) {
exit( 0 );
}
$this->viewFile = 'resources.phtml';
$this->layoutViewFile = 'layout' . DIRECTORY_SEPARATOR . 'popup.phtml';
}
function load() {
parent::load();
$this->msgText = '';
$this->isAdmin = $this->data['player_type'] == PLAYERTYPE_ADMIN;
if (!$this->isAdmin) {
exit( 0 );
return null;
}
$this->villageId = (isset( $_GET['avid'] ) ? intval( $_GET['avid'] ) : 0);
if ($this->villageId <= 0) {
exit( 0 );
return null;
}
$m = new ResourcesModel();
if ($this->isPost()) {
$r1 = (( isset( $_POST['r1'] ) && 0 <= intval( $_POST['r1'] ) ) ? intval( $_POST['r1'] ) : 0 - 1);
$r2 = (( isset( $_POST['r2'] ) && 0 <= intval( $_POST['r2'] ) ) ? intval( $_POST['r2'] ) : 0 - 1);
$r3 = (( isset( $_POST['r3'] ) && 0 <= intval( $_POST['r3'] ) ) ? intval( $_POST['r3'] ) : 0 - 1);
$r4 = (( isset( $_POST['r4'] ) && 0 <= intval( $_POST['r4'] ) ) ? intval( $_POST['r4'] ) : 0 - 1);
$m->updateVillageResources( $this->villageId, array( '1' => $r1, '2' => $r2, '3' => $r3, '4' => $r4 ) );
$this->msgText = data_saved;
}
$row = $m->getVillageData( $this->villageId );
if (( ( $row == NULL || intval( $row['player_id'] ) == 0 ) || $row['is_oasis'] )) {
exit( 0 );
return null;
}
$this->villageName = $row['village_name'];
$this->playerName = $row['player_name'];
$this->resources = array();
$elapsedTimeInSeconds = $row['elapsedTimeInSeconds'];
$r_arr = explode( ',', $row['resources'] );
foreach ($r_arr as $r_str) {
$r2 = explode( ' ', $r_str );
$prate = floor( $r2[4] * ( 1 + $r2[5] / 100 ) ) - ($r2[0] == 4 ? $row['crop_consumption'] : 0);
$current_value = floor( $r2[1] + $elapsedTimeInSeconds * ( $prate / 3600 ) );
if ($r2[2] < $current_value) {
$current_value = $r2[2];
}
$this->resources[$r2[0]] = array( 'current_value' => $current_value, 'store_max_limit' => $r2[2], 'store_init_limit' => $r2[3], 'prod_rate' => $r2[4], 'prod_rate_percentage' => $r2[5], 'calc_prod_rate' => $prate );
}
$m->dispose();
}
}
$p = new GPage();
$p->run();
?>