00001 <?php
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 require_once( './general.php' );
00028 require_once( './lib/fight.php' );
00029 require_once( './conf/fightconfig.php' );
00030
00031 if( !$oUser->isAdmin( 'fight' ) )
00032 {
00033 die('Keine Admin Rechte.');
00034 }
00035
00036
00037 $oStyle->setTemplate( 'fight.html' );
00038
00039 $oFight = new Fight();
00040
00041
00042 if(isset($_POST['action'])) $action = $_POST['action'];
00043 elseif(isset($_GET['action'])) $action = $_GET['action'];
00044 else $action = '';
00045
00046
00047
00048 if( $action == 'select' )
00049 {
00050 $strUnitData = isset( $_POST['unit'] ) ? $_POST['unit'] : '';
00051 $strTownData = isset( $_POST['town'] ) ? $_POST['town'] : '';
00052 $aChose = $oFight->select( $strUnitData, $strTownData );
00053 $aDefBoni = $aChose[0];
00054 $aAttBoni = $aChose[1];
00055
00056
00057
00058 $strDefRows = '';
00059 foreach( $aChose[2] AS $key => $value )
00060 {
00061 $oStyle->addReplacements( array( 'KEY' => $key, 'BONUS' => $aDefBoni[$value]*100 ) );
00062 $strDefRows .= $oStyle->get_area( 'BonusTableRow' );
00063 }
00064 $oStyle->addReplacements( array( 'SIDE' => 'Verteidiger', 'ROWS' => $strDefRows ) );
00065 $strDefTable = $oStyle->get_area( 'BonusTable' );
00066
00067
00068
00069 $strAttRows = '';
00070 foreach( $aChose[2] AS $key => $value )
00071 {
00072 $oStyle->addReplacements( array( 'KEY' => $key, 'BONUS' => $aAttBoni[$value]*100 ) );
00073 $strAttRows .= $oStyle->get_area( 'BonusTableRow' );
00074 }
00075 $oStyle->addReplacements( array( 'SIDE' => 'Angreifer', 'ROWS' => $strAttRows ) );
00076 $strAttTable = $oStyle->get_area( 'BonusTable' );
00077
00078
00079
00080 $strBuildRows = '';
00081 foreach( $aChose[4] AS $aData )
00082 {
00083 foreach( $aData['values'][0] AS $strKey => $intValue )
00084 {
00085 $oStyle->addReplacements( array( 'BUILDING' => $aData['building'],
00086 'SIDE' => 'Verteidiger',
00087 'UNITKEY' => $strKey,
00088 'VALUE' => $intValue * 100 ) );
00089 $strBuildRows .= $oStyle->get_area( 'BuildTableRow' );
00090 }
00091 foreach( $aData['values'][1] AS $strKey => $intValue )
00092 {
00093 $oStyle->addReplacements( array( 'BUILDING' => $aData['building'],
00094 'SIDE' => 'Angreifer',
00095 'UNITKEY' => $strKey,
00096 'VALUE' => $intValue * 100 ) );
00097 $strBuildRows .= $oStyle->get_area( 'BuildTableRow' );
00098 }
00099 }
00100 $oStyle->addReplacements( array( 'ROWS' => $strBuildRows ) );
00101 $strBuildTable = $oStyle->get_area( 'BuildTable' );
00102
00103
00104 $strSelectRows = '';
00105 $intPlayer = 0;
00106 foreach( $aChose[3] as $strPlayer => $aValues )
00107 {
00108 $aReplacements = array( 'TOWNNAME' => $strPlayer,
00109 'TOWNID' => $intPlayer++,
00110 'UNITCOUNT' => $aValues[12],
00111 'ATTVALUES' => implode( ';', $aValues ) );
00112 for( $i = 0; $i < 12; $i++ )
00113 {
00114 $aReplacements['VALUE'.$i] = $aValues[$i];
00115 }
00116 $oStyle->addReplacements( $aReplacements );
00117 $strSelectRows .= $oStyle->get_area( 'SelectRow' );
00118 }
00119 $oStyle->addReplacements( array( 'ROWS' => $strSelectRows,
00120 'DEFTABLE' => $strDefTable,
00121 'ATTTABLE' => $strAttTable,
00122 'BUILDTABLE' => $strBuildTable,
00123 'DEFBONI' => implode( ';', $aDefBoni ),
00124 'ATTBONI' => implode( ';', $aAttBoni ) ) );
00125 $strTmpl_inhalt = $oStyle->get_area( 'SelectUnits' );
00126 output();
00127 }
00128 elseif( $action == 'calc' )
00129 {
00130
00131 $aTmpUnits = ( isset( $_POST['units'] ) && is_array( $_POST['units'] ) ) ? $_POST['units'] : array();
00132 $aAttackers = ( isset( $_POST['attackers'] ) && is_array( $_POST['attackers'] ) ) ? $_POST['attackers'] : array();
00133 $aTownNames = ( isset( $_POST['towns'] ) && is_array( $_POST['towns'] ) ) ? $_POST['towns'] : array();
00134 $aCalc = ( isset( $_POST['calc'] ) && is_array( $_POST['calc'] ) ) ? $_POST['calc'] : array();
00135 $aDefBoni = isset( $_POST['defBoni'] ) ? explode( ';', $_POST['defBoni'] ) : array();
00136 $aAttBoni = isset( $_POST['attBoni'] ) ? explode( ';', $_POST['attBoni'] ) : array();
00137
00138
00139 $aUnits = array();
00140 foreach( $aCalc AS $intTownId )
00141 {
00142 $aUnits[] = $aTmpUnits[$intTownId];
00143 }
00144 $aReplacements = $oFight->calc( $aUnits, $aAttackers, $aDefBoni, $aAttBoni );
00145 $oStyle->addReplacements( $aReplacements );
00146 $strTmpl_inhalt = $oStyle->get_area( 'Calc' );
00147 output();
00148 }
00149 else
00150 {
00151
00152 $strTmpl_inhalt = $oStyle->get_area( 'Eingabe' );
00153 output();
00154 }