forked from H3Gi/tatar-wars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwarsm.php
115 lines (109 loc) · 4.55 KB
/
warsm.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
<?php
/*********************/
/* */
/* Version : 5.1.0 */
/* Author : RM */
/* Comment : 071223 */
/* */
/*********************/
require( ".".DIRECTORY_SEPARATOR."app".DIRECTORY_SEPARATOR."boot.php" );
require_once( MODEL_PATH."battle.php" );
require_once( MODEL_PATH.DIRECTORY_SEPARATOR."battles".DIRECTORY_SEPARATOR."war.php" );
class GPage extends securegamepage
{
public $showTroopsTable = FALSE;
public $showWarResult = FALSE;
public $errorText = "";
public $troopsMetadata = NULL;
public $warResult = NULL;
public function GPage( )
{
parent::securegamepage( );
$this->viewFile = "warsm.phtml";
$this->contentCssClass = "warsim";
}
public function load( )
{
parent::load( );
if ( $this->isPost( ) )
{
if ( !isset( $_POST['a1'] ) || intval( $_POST['a1'] ) != 1 && intval( $_POST['a1'] ) != 2 && intval( $_POST['a1'] ) != 3 && intval( $_POST['a1'] ) != 7 && intval( $_POST['a1'] ) != 6 )
{
$this->errorText = war_sim_noattack;
}
else if ( !isset( $_POST['ktyp'] ) || intval( $_POST['ktyp'] ) != 1 && intval( $_POST['ktyp'] ) != 2 )
{
$this->errorText = war_sim_nobattletype;
}
else if ( !isset( $_POST['a2'] ) || sizeof( $_POST['a2'] ) == 0 )
{
$this->errorText = war_sim_nodefense;
}
else
{
foreach ( $_POST['a2'] as $tribeId => $v )
{
if ( $tribeId != 1 && $tribeId != 2 && $tribeId != 3 && $tribeId != 4 && $tribeId != 7 && $tribeId != 6 )
{
$this->errorText = war_sim_nodefense2;
}
}
$this->troopsMetadata = $this->gameMetadata['troops'];
$this->showTroopsTable = TRUE;
$this->showWarResult = FALSE;
if ( !isset( $_POST['t1'] ) )
{
return;
}
$m = new WarBattleModel( );
if ( isset( $_POST['h_off_bonus1'] ) && 0 < intval( $_POST['h_off_bonus1'] ) )
{
$this->showWarResult = TRUE;
}
$troops = array( );
$troopsPower = array( );
foreach ( $_POST['t1'] as $tribeId => $troopArray )
{
foreach ( $troopArray as $tid => $tnum )
{
if ( 0 < $tnum )
{
$this->showWarResult = TRUE;
}
$troops[$tid] = intval( $tnum );
$troopsPower[$tid] = 0;
}
}
if ( !$this->showWarResult )
{
return;
}
$peopleCount = isset( $_POST['ew1'] ) ? intval( $_POST['ew1'] ) : 0;
$heroLevel = isset( $_POST['h_off_bonus1'] ) ? intval( $_POST['h_off_bonus1'] ) : 0;
$wringerPower = isset( $_POST['kata'] ) ? intval( $_POST['kata'] ) : 0;
$attackTroops = $m->_getTroopWithPower( $troops, $troopsPower, TRUE, $heroLevel, $peopleCount, $wringerPower, 0 );
$peopleCount = isset( $_POST['ew2'] ) ? intval( $_POST['ew2'] ) : 0;
$wallLevel = isset( $_POST['wall1'] ) ? intval( $_POST['wall1'] ) : 0;
$totalDefensePower = 0;
$defenseTroops = array( );
foreach ( $_POST['t2'] as $tribeId => $troopArray )
{
$troops = array( );
$troopsPower = array( );
foreach ( $troopArray as $tid => $tnum )
{
$troops[$tid] = intval( $tnum );
$troopsPower[$tid] = isset( $_POST['f2'], $_POST['f2'][$tribeId] ) && isset( $_POST['f2'][$tribeId][$tid] ) ? intval( $_POST['f2'][$tribeId][$tid] ) : 0;
}
$defenseTroops[$tribeId] = $m->_getTroopWithPower( $troops, $troopsPower, FALSE, 0, $peopleCount, 0, $wallLevel );
$totalDefensePower += $defenseTroops[$tribeId]['total_power'];
}
$this->warResult = $m->getWarResult( $attackTroops, $defenseTroops, $totalDefensePower, isset( $_POST['ktyp'] ) && intval( $_POST['ktyp'] ) == 2 );
$m->dispose( );
}
}
}
}
$p = new GPage( );
$p->run( );
?>