| 1 |
<?php |
| 2 |
/** |
| 3 |
* File functions: |
| 4 |
* Distribution of Astral Poinst between player statistics |
| 5 |
* |
| 6 |
* @name : ap.php |
| 7 |
* @copyright : (C) 2004,2005,2006 Vallheru Team based on Gamers-Fusion ver 2.5 |
| 8 |
* @author : thindil <thindil@users.sourceforge.net> |
| 9 |
* @version : 1.1 |
| 10 |
* @since : 08.03.2006 |
| 11 |
* |
| 12 |
*/ |
| 13 |
|
| 14 |
// |
| 15 |
// |
| 16 |
// This program is free software; you can redistribute it and/or modify |
| 17 |
// it under the terms of the GNU General Public License as published by |
| 18 |
// the Free Software Foundation; either version 2 of the License, or |
| 19 |
// (at your option) any later version. |
| 20 |
// |
| 21 |
// This program is distributed in the hope that it will be useful, |
| 22 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 |
// GNU General Public License for more details. |
| 25 |
// |
| 26 |
// You should have received a copy of the GNU General Public License |
| 27 |
// along with this program; if not, write to the Free Software |
| 28 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 29 |
// |
| 30 |
// $Id$ |
| 31 |
|
| 32 |
$title = 'Dystrybucja AP'; |
| 33 |
require_once('includes/head.php'); |
| 34 |
|
| 35 |
/** |
| 36 |
* Get the localization for game |
| 37 |
*/ |
| 38 |
require_once('languages/'.$player -> lang.'/ap.php'); |
| 39 |
|
| 40 |
if (!$player -> race || !$player -> clas) |
| 41 |
{ |
| 42 |
error (NO_CLASS); |
| 43 |
} |
| 44 |
if ($player -> age > 3 && !$player -> ap) |
| 45 |
{ |
| 46 |
error(NO_AP3); |
| 47 |
} |
| 48 |
/** |
| 49 |
* Assign variables to template |
| 50 |
*/ |
| 51 |
$arrStats = array('Człowiek' => array(2.5, 2.5, 2.5, 2.5, 2.5, 2.5), |
| 52 |
'Elf' => array(2, 2.8, 2.9, 2, 2.6, 2.7), |
| 53 |
'Krasnolud' => array(3, 2.3, 2.1, 2.8, 2.3, 2.5), |
| 54 |
'Hobbit' => array(2, 2.8, 2.3, 2.5, 2.5, 3), |
| 55 |
'Jaszczuroczłek' => array(2.8, 2.6, 2.7, 2.3, 2.3, 2.3), |
| 56 |
'Gnom' => array(2.1, 2.5, 2.1, 2.5, 2.9, 2.3)); |
| 57 |
|
| 58 |
$arrClassStats = array('Wojownik' => array(0, 0, 0, 0.15, 0, -0.15), |
| 59 |
'Barbarzyńca' => array(0.15, 0, 0, 0, -0.15, 0), |
| 60 |
'Rzemieślnik' => array(0, 0, 0, 0, 0, 0), |
| 61 |
'Złodziej' => array(0, 0.15, 0, -0.15, 0, 0), |
| 62 |
'Mag' => array(-0.15, 0, 0, 0, 0.15, 0)); |
| 63 |
|
| 64 |
$arrStatsSumm = array($arrStats[$player -> race][0] + $arrClassStats[$player -> clas][0],#strength |
| 65 |
$arrStats[$player -> race][1] + $arrClassStats[$player -> clas][1],#agility |
| 66 |
$arrStats[$player -> race][2] + $arrClassStats[$player -> clas][2],#speed |
| 67 |
$arrStats[$player -> race][3] + $arrClassStats[$player -> clas][3],#endurance |
| 68 |
$arrStats[$player -> race][4] + $arrClassStats[$player -> clas][4],#inteligence |
| 69 |
$arrStats[$player -> race][5] + $arrClassStats[$player -> clas][5]);#wisdom |
| 70 |
|
| 71 |
$arrStatNames = array('strength', 'agility', 'szyb', 'wytrz', 'inteli', 'wisdom'); |
| 72 |
|
| 73 |
$smarty -> assign_by_ref('StatSumm', $arrStatsSumm); |
| 74 |
$smarty -> assign_by_ref('StatDesc', $arrStatDesc); |
| 75 |
$smarty -> assign_by_ref('StatNames', $arrStatNames); |
| 76 |
$smarty -> assign_by_ref('Age', $player -> age); |
| 77 |
|
| 78 |
unset($arrStats, $arrClassStats); |
| 79 |
|
| 80 |
/** |
| 81 |
* Distribution of Astral Points |
| 82 |
*/ |
| 83 |
if (isset ($_GET['step']) && $_GET['step'] == 'add') |
| 84 |
{ |
| 85 |
if (!isset($_POST['strength']) || !isset($_POST['agility']) || !isset($_POST['szyb']) || !isset($_POST['wytrz']) || !isset($_POST['inteli']) || !isset($_POST['wisdom'])) |
| 86 |
{ |
| 87 |
error(EMPTY_FIELDS); |
| 88 |
} |
| 89 |
|
| 90 |
$sum = 0; |
| 91 |
$arrpoints = array(0,0,0,0,0,0); |
| 92 |
$arrname = array(A_STRENGTH, A_AGILITY, A_SPEED, A_CONDITION, A_INTELIGENCE, A_WISDOM); |
| 93 |
for ($i = 0; $i < 6; $i++) |
| 94 |
{ |
| 95 |
if (!preg_match("/^\d*$/", $_POST[$arrStatNames[$i]])) |
| 96 |
{ |
| 97 |
error (ERROR); |
| 98 |
} |
| 99 |
$sum += $_POST[$arrStatNames[$i]]; |
| 100 |
$arrpoints[$i] = $_POST[$arrStatNames[$i]] * ($arrStatsSumm[$i]); |
| 101 |
} |
| 102 |
if ($sum > $player -> ap) |
| 103 |
{ |
| 104 |
error (NO_AP); |
| 105 |
} |
| 106 |
if ($sum == 0) |
| 107 |
{ |
| 108 |
error (NO_AP2); |
| 109 |
} |
| 110 |
$strBase = 'UPDATE `players` SET `ap`=`ap`-'.$sum; |
| 111 |
$strMain = ''; |
| 112 |
$strEnding = ' WHERE `id`='.$player -> id; |
| 113 |
|
| 114 |
for ($i = 0; $i < 6; $i++) |
| 115 |
{ |
| 116 |
if ($arrpoints[$i] > 0) |
| 117 |
{ |
| 118 |
$strMain .= ',`'.$arrStatNames[$i].'`=`'.$arrStatNames[$i].'`+'.$arrpoints[$i]; |
| 119 |
if ($i == 3) |
| 120 |
{ |
| 121 |
$strMain .= ',`max_hp`=`max_hp`+'.$arrpoints[$i]; |
| 122 |
} |
| 123 |
} |
| 124 |
} |
| 125 |
$db -> Execute($strBase.$strMain.$strEnding); |
| 126 |
$smarty -> assign_by_ref ('Amount', $arrpoints); |
| 127 |
$smarty -> assign_by_ref ('Name', $arrname); |
| 128 |
} |
| 129 |
|
| 130 |
if (isset($_GET['step']) && $_GET['step'] == 'reassign') |
| 131 |
{ |
| 132 |
if ($player -> age > 3) |
| 133 |
{ |
| 134 |
error(TOO_OLD); |
| 135 |
} |
| 136 |
if (isset($_POST['answer']) && $_POST['answer'] == A_YES) |
| 137 |
{ |
| 138 |
$intAP = 0; |
| 139 |
for ($i = 0; $i < $player -> level; $i++) |
| 140 |
{ |
| 141 |
$intAP += 10 + floor(.35 * $i); |
| 142 |
} |
| 143 |
if ($player -> clas == 'Rzemieślnik') |
| 144 |
{ |
| 145 |
$intAP = floor($intAP / 2) + 5; |
| 146 |
} |
| 147 |
if ($intAP == $player -> ap) |
| 148 |
{ |
| 149 |
error(MAX_AP); |
| 150 |
} |
| 151 |
$intDiff = $intAP - $player -> ap; |
| 152 |
$strDBQuery = 'UPDATE `players` SET `ap`='.$intAP; |
| 153 |
$oldFetchMode = $db -> SetFetchMode(ADODB_FETCH_NUM); |
| 154 |
$arrTrainedStats = $db -> GetRow('SELECT `strength`, `agility`, `szyb`, `wytrz`, `inteli`, `wisdom` FROM `trained_stats` WHERE `id`='.$player -> id); |
| 155 |
$db -> SetFetchMode($oldFetchMode); |
| 156 |
$arrRaces = array('Człowiek', 'Elf', 'Krasnolud', 'Hobbit', 'Jaszczuroczłek', 'Gnom'); |
| 157 |
$arrHP = array(5, 4, 6, 3, 5, 3); |
| 158 |
$intRaceKey = array_search($player -> race, $arrRaces); |
| 159 |
$intAmountHP = 15 + ($player -> level - 1) * $arrHP[$intRaceKey]; |
| 160 |
$intAmountHP += empty($arrTrainedStats) ? 0 : floor($arrTrainedStats[3]); |
| 161 |
$intCurrHP = min($player -> hp, $intAmountHP); |
| 162 |
$strDBQuery .= ', `max_hp`='.$intAmountHP.', `hp`='.$intCurrHP; |
| 163 |
if (empty($arrTrainedStats)) |
| 164 |
{ |
| 165 |
for ($i = 0; $i < 6; $i++) |
| 166 |
{ |
| 167 |
$strDBQuery .= ', `'.$arrStatNames[$i].'`=3'; |
| 168 |
} |
| 169 |
} |
| 170 |
else |
| 171 |
{ |
| 172 |
for ($i = 0; $i < 6; $i++) |
| 173 |
{ |
| 174 |
$arrCurrentStats[$i] = $arrTrainedStats[$i] + 3; |
| 175 |
$strDBQuery .= ', `'.$arrStatNames[$i].'`='.$arrCurrentStats[$i]; |
| 176 |
} |
| 177 |
} |
| 178 |
$strDBQuery .= ' WHERE `id`='.$player -> id; |
| 179 |
$db -> Execute($strDBQuery); |
| 180 |
$smarty -> assign_by_ref ('Diff', $intDiff); |
| 181 |
$smarty -> assign_by_ref ('Amount', $intAP); |
| 182 |
} |
| 183 |
} |
| 184 |
if (!isset($_GET['step'])) |
| 185 |
{ |
| 186 |
$_GET['step'] = ''; |
| 187 |
} |
| 188 |
/** |
| 189 |
* Assign variables and display page |
| 190 |
*/ |
| 191 |
$smarty -> assign_by_ref ('Ap', $player -> ap); |
| 192 |
$smarty -> display ('ap.tpl'); |
| 193 |
|
| 194 |
unset($arrpoints, $arrStatNames, $arrname); |
| 195 |
require_once('includes/foot.php'); |
| 196 |
?> |