forked from H3Gi/tatar-wars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
village3.php
137 lines (101 loc) · 3.44 KB
/
village3.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
require( '.' . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'boot.php' );
require_once( MODEL_PATH . 'village3.php' );
class GPage extends VillagePage {
var $pageState = null;
var $mapItemData = null;
var $lastReport = null;
var $itemTroops = null;
var $hasMarketplace = null;
var $hasRallyPoint = null;
function GPage() {
parent::villagepage();
$this->viewFile = 'village3.phtml';
$this->contentCssClass = 'map';
$this->hasMarketplace = FALSE;
$this->hasRallyPoint = FALSE;
}
function onLoadBuildings($building) {
if (!$this->hasMarketplace) {
if ($building['item_id'] == 17) {
$this->hasMarketplace = TRUE;
}
}
if (!$this->hasRallyPoint) {
if ($building['item_id'] == 16) {
$this->hasRallyPoint = TRUE;
}
}
}
function load() {
parent::load();
$villageId = (( isset( $_GET['id'] ) && 0 < intval( $_GET['id'] ) ) ? intval( $_GET['id'] ) : 0);
if ($villageId <= 0) {
$this->redirect( 'map.php' );
return null;
}
$m = new VillageModel();
$this->mapItemData = $m->getMapItemData( $villageId );
if (!is_array( $this->mapItemData )) {
$m->dispose();
$this->redirect( 'map.php' );
return null;
}
if (0 < intval( $this->mapItemData['player_id'] )) {
$this->pageState = ($this->mapItemData['is_oasis'] ? 3 : 2);
$this->mapItemData['playerType'] = $m->getPlayType( intval( $this->mapItemData['player_id'] ) );
}
else {
$this->pageState = ($this->mapItemData['is_oasis'] ? 4 : 1);
}
$this->lastReport = NULL;
if (( $this->pageState == 2 || $this->pageState == 3 )) {
if (( $this->mapItemData['player_id'] == $this->player->playerId || ( $this->mapItemData['alliance_id'] == $this->data['alliance_id'] && 0 < intval( $this->data['alliance_id'] ) ) )) {
$this->lastReport = $m->getLatestReports( $this->mapItemData['player_id'], $this->mapItemData['id'] );
}
else {
$fromPlayersId = (0 < intval( $this->data['alliance_id'] ) ? $m->getAlliancePlayersId( intval( $this->data['alliance_id'] ) ) : $this->player->playerId);
$this->lastReport = $m->getLatestReports2( $fromPlayersId, $this->mapItemData['player_id'], $this->mapItemData['id'] );
}
if ($this->pageState == 3) {
$this->mapItemData['village_name'] = $m->getVillageName( $this->mapItemData['parent_id'] );
}
}
else {
if (( $this->pageState == 1 || $this->pageState == 4 )) {
$this->itemTroops = array();
$t = ($this->pageState == 1 ? $this->data['troops_num'] : $this->mapItemData['troops_num']);
$incFactor = ($this->pageState == 4 ? floor( $this->mapItemData['elapsedTimeInSeconds'] / 86400 ) : 0);
$t_arr = explode( '|', $t );
foreach ($t_arr as $t_str) {
$t2_arr = explode( ':', $t_str );
if (0 - 1 < $t2_arr[0]) {
continue;
}
$t2_arr = explode( ',', $t2_arr[1] );
foreach ($t2_arr as $t2_str) {
$t = explode( ' ', $t2_str );
if ($t[0] == 99) {
continue;
}
$this->itemTroops[$t[0]] = $t[1] + $incFactor;
if (( $this->pageState == 4 && 7 * intval( $t[0] ) < $this->itemTroops[$t[0]] )) {
$this->itemTroops[$t[0]] = 7 * intval( $t[0] );
continue;
}
}
}
}
}
$m->dispose();
}
function preRender() {
parent::prerender();
if (isset( $_GET['id'] )) {
$this->villagesLinkPostfix .= '&id=' . intval( $_GET['id'] );
}
}
}
$p = new GPage();
$p->run();
?>