| 1 |
<?php |
| 2 |
/** |
| 3 |
* File functions: |
| 4 |
* Players farms - herbs |
| 5 |
* |
| 6 |
* @name : farm.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.2 |
| 10 |
* @since : 23.08.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: farm.php 566 2006-09-13 09:31:08Z thindil $ |
| 31 |
|
| 32 |
$title = "Farma"; |
| 33 |
require_once("includes/head.php"); |
| 34 |
|
| 35 |
/** |
| 36 |
* Get the localization for game |
| 37 |
*/ |
| 38 |
require_once("languages/".$player -> lang."/farm.php"); |
| 39 |
|
| 40 |
if ($player -> location != 'Altara' && $player -> location != 'Ardulith') |
| 41 |
{ |
| 42 |
error(ERROR); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Main menu |
| 47 |
*/ |
| 48 |
if (!isset($_GET['step'])) |
| 49 |
{ |
| 50 |
$smarty -> assign(array("Farminfo" => FARM_INFO, |
| 51 |
"Aplantation" => A_PLANTATION, |
| 52 |
"Ahouse" => A_HOUSE, |
| 53 |
"Aencyclopedia" => A_ENCYCLOPEDIA)); |
| 54 |
$_GET['step'] = ''; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Herbs info |
| 59 |
*/ |
| 60 |
if (isset($_GET['step']) && $_GET['step'] == 'herbsinfo') |
| 61 |
{ |
| 62 |
$smarty -> assign(array("Herbsinfo" => HERBS_INFO, |
| 63 |
"Ilaniinfo" => ILANI_INFO, |
| 64 |
"Illaniasinfo" => ILLANIAS_INFO, |
| 65 |
"Nutariinfo" => NUTARI_INFO, |
| 66 |
"Dynallcainfo" => DYNALLCA_INFO)); |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* House of gardener |
| 71 |
*/ |
| 72 |
if (isset($_GET['step']) && $_GET['step'] == 'house') |
| 73 |
{ |
| 74 |
$objHerbs = $db -> Execute("SELECT `illani`, `illanias`, `nutari`, `dynallca` FROM `herbs` WHERE `gracz`=".$player -> id); |
| 75 |
if (!$objHerbs -> fields['illani'] && !$objHerbs -> fields['illanias'] && !$objHerbs -> fields['nutari'] && !$objHerbs -> fields['dynallca']) |
| 76 |
{ |
| 77 |
error(NO_HERBS); |
| 78 |
} |
| 79 |
$arrHerbs = array('illani', 'illanias', 'nutari', 'dynallca'); |
| 80 |
$arrHerbsname = array(HERB1, HERB2, HERB3, HERB4); |
| 81 |
$arrHerbsaviable = array(); |
| 82 |
$arrHerbsoption = array(); |
| 83 |
$arrHerbsamount = array(); |
| 84 |
$j = 0; |
| 85 |
for ($i = 0; $i < 4; $i++) |
| 86 |
{ |
| 87 |
$strName = $arrHerbs[$i]; |
| 88 |
if ($objHerbs -> fields[$strName]) |
| 89 |
{ |
| 90 |
$arrHerbsaviable[$j] = $arrHerbsname[$i]; |
| 91 |
$arrHerbsamount[$j] = $objHerbs -> fields[$strName]; |
| 92 |
$arrHerbsoption[$j] = $strName; |
| 93 |
$j++; |
| 94 |
} |
| 95 |
} |
| 96 |
if (!isset($_GET['action'])) |
| 97 |
{ |
| 98 |
$_GET['action'] = ''; |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Dryings herbs |
| 103 |
*/ |
| 104 |
if (isset($_GET['action']) && $_GET['action'] == 'dry') |
| 105 |
{ |
| 106 |
if (!ereg("^[1-9][0-9]*$", $_POST['amount'])) |
| 107 |
{ |
| 108 |
error(ERROR); |
| 109 |
} |
| 110 |
if (!in_array($_POST['herb'], $arrHerbs)) |
| 111 |
{ |
| 112 |
error(ERROR); |
| 113 |
} |
| 114 |
$intAmountherbs = 5 * $_POST['amount']; |
| 115 |
if ($intAmountherbs > $objHerbs -> fields[$_POST['herb']]) |
| 116 |
{ |
| 117 |
error(NO_HERB); |
| 118 |
} |
| 119 |
$intAmountenergy = $_POST['amount'] / 5; |
| 120 |
if ($intAmountenergy > $player -> energy) |
| 121 |
{ |
| 122 |
error(NO_ENERGY); |
| 123 |
} |
| 124 |
if ($player -> hp < 1) |
| 125 |
{ |
| 126 |
error(YOU_DEAD); |
| 127 |
} |
| 128 |
$intKey = array_search($_POST['herb'], $arrHerbs); |
| 129 |
$intAmountseeds = 0; |
| 130 |
for ($i = 0; $i < $_POST['amount']; $i++) |
| 131 |
{ |
| 132 |
$intRoll = rand(1, 100); |
| 133 |
if ($intRoll > 5) |
| 134 |
{ |
| 135 |
$intAmountseeds++; |
| 136 |
} |
| 137 |
} |
| 138 |
$intHerbalist = $intAmountseeds / 100; |
| 139 |
$arrSeeds = array('illani_seeds', 'illanias_seeds', 'nutari_seeds', 'dynallca_seeds'); |
| 140 |
$db -> Execute("UPDATE `herbs` SET `".$arrHerbs[$intKey]."`=`".$arrHerbs[$intKey]."`-".$intAmountherbs.", `".$arrSeeds[$intKey]."`=`".$arrSeeds[$intKey]."`+".$intAmountseeds." WHERE `gracz`=".$player -> id); |
| 141 |
$db -> Execute("UPDATE `players` SET `energy`=`energy`-".$intAmountenergy.", herbalist=herbalist+".$intHerbalist." WHERE `id`=".$player -> id); |
| 142 |
$smarty -> assign("Message", YOU_MAKE.$intAmountherbs.T_HERB.$intAmountseeds.T_PACKS.$intHerbalist.T_ABILITY); |
| 143 |
} |
| 144 |
$smarty -> assign(array("Houseinfo" => HOUSE_INFO, |
| 145 |
"Adry" => A_DRY, |
| 146 |
"Tdry" => T_DRY, |
| 147 |
"Tpack" => T_PACK, |
| 148 |
"Tamount" => T_AMOUNT, |
| 149 |
"Herbsname" => $arrHerbsaviable, |
| 150 |
"Herbsamount" => $arrHerbsamount, |
| 151 |
"Herbsoption" => $arrHerbsoption, |
| 152 |
"Action" => $_GET['action'])); |
| 153 |
$objHerbs -> Close(); |
| 154 |
} |
| 155 |
|
| 156 |
/** |
| 157 |
* Plantation |
| 158 |
*/ |
| 159 |
if (isset($_GET['step']) && $_GET['step'] == 'plantation') |
| 160 |
{ |
| 161 |
$objPlantation = $db -> Execute("SELECT id, owner, lands, glasshouse, irrigation, creeper FROM farms WHERE owner=".$player -> id." AND place=".$db->Quote($player -> location)); |
| 162 |
$intMithFarmCost = 15; |
| 163 |
if (!isset($_GET['action'])) |
| 164 |
{ |
| 165 |
if (!$objPlantation -> fields['lands']) |
| 166 |
{ |
| 167 |
$smarty -> assign("Aupgrade", NO_PLANT1.CITY.NO_PLANT2.$intMithFarmCost.NO_PLANT3); |
| 168 |
$intLandsamount = ''; |
| 169 |
} |
| 170 |
else |
| 171 |
{ |
| 172 |
$smarty -> assign(array("Aupgrade" => A_UPGRADE, |
| 173 |
"Asow" => A_SOW, |
| 174 |
"Achop" => A_CHOP)); |
| 175 |
$intLandsamount = $objPlantation -> fields['lands']; |
| 176 |
} |
| 177 |
$smarty -> assign("Farminfo", FARM_INFO1.CITY.FARM_INFO2); |
| 178 |
$_GET['action'] = ''; |
| 179 |
} |
| 180 |
|
| 181 |
/** |
| 182 |
* Upgrade plantation |
| 183 |
*/ |
| 184 |
if (isset($_GET['action']) && $_GET['action'] == 'upgrade') |
| 185 |
{ |
| 186 |
if (!$objPlantation -> fields['lands']) |
| 187 |
{ |
| 188 |
$intMithcost = $intMithFarmCost; |
| 189 |
$intLandsamount = ''; |
| 190 |
$intGlassAmount = ''; |
| 191 |
$intIrrigationAmount = ''; |
| 192 |
$intCreeperAmount = ''; |
| 193 |
} |
| 194 |
else |
| 195 |
{ |
| 196 |
$smarty->assign(array('noMithril' => '')); |
| 197 |
|
| 198 |
$intLandsamount = $objPlantation -> fields['lands']; |
| 199 |
$intMithcost = $intMithFarmCost * $objPlantation -> fields['lands']; |
| 200 |
$fltDelta = $intMithcost*$intMithcost + ($intMithFarmCost / 4 + 2 * $player -> platinum - $intMithcost) * $intMithFarmCost; |
| 201 |
$intMaxLand = floor(($intMithFarmCost / 2 - $intMithcost + sqrt($fltDelta)) / $intMithFarmCost); |
| 202 |
$arrFarmLevels = array(); |
| 203 |
$intMithSum = 0; |
| 204 |
for ($i=1; $i<=$intMaxLand; $i++) |
| 205 |
{ |
| 206 |
$intMithSum += ($i + $intLandsamount - 1) * $intMithFarmCost; |
| 207 |
$arrFarmLevels[$i] = ($i + $intLandsamount).': '.$intMithSum.T_MITH; |
| 208 |
} |
| 209 |
if ($intMaxLand < 1) $smarty->assign('noMithril', NO_MITH); |
| 210 |
$intGlassAmount = $objPlantation -> fields['glasshouse']; |
| 211 |
$intIrrigationAmount = $objPlantation -> fields['irrigation']; |
| 212 |
$intCreeperAmount = $objPlantation -> fields['creeper']; |
| 213 |
$intPine = $db -> getOne("SELECT `pine` FROM `minerals` WHERE owner=".$player -> id); |
| 214 |
$intMaxGold = floor($player -> credits / 1000); |
| 215 |
$intMaxPine = floor($intPine / 10); |
| 216 |
$intMaxGold = ($intMaxGold > $intMaxPine) ? $intMaxPine : $intMaxGold; |
| 217 |
if ($intGlassAmount != $intLandsamount) |
| 218 |
{ |
| 219 |
$intMaxLevel = ($intMaxGold > $intLandsamount - $intGlassAmount) ? $intLandsamount - $intGlassAmount : $intMaxGold; |
| 220 |
for ($i=1;$i<=$intMaxLevel;$i++) |
| 221 |
{ |
| 222 |
$arrGlassLevels[$i] = ($i + $intGlassAmount).': '.(1000 * $i).T_GOLDCOINS.(10*$i).PINE_PIECES; |
| 223 |
} |
| 224 |
$smarty->assign('noGlass', 0); |
| 225 |
} |
| 226 |
else $smarty->assign('noGlass', 1); |
| 227 |
if ($intIrrigationAmount != $intLandsamount) |
| 228 |
{ |
| 229 |
$intMaxLevel = ($intMaxGold > $intLandsamount - $intIrrigationAmount) ? $intLandsamount - $intIrrigationAmount : $intMaxGold; |
| 230 |
for ($i=1;$i<=$intMaxLevel;$i++) |
| 231 |
{ |
| 232 |
$arrIrrigationLevels[$i] = ($i + $intIrrigationAmount).': '.(1000 * $i).T_GOLDCOINS.(10*$i).PINE_PIECES; |
| 233 |
} |
| 234 |
$smarty->assign('noIrrigation', 0); |
| 235 |
} |
| 236 |
else $smarty->assign('noIrrigation', 1); |
| 237 |
if ($intCreeperAmount != $intLandsamount) |
| 238 |
{ |
| 239 |
$intMaxLevel = ($intMaxGold > $intLandsamount - $intCreeperAmount) ? $intLandsamount - $intCreeperAmount : $intMaxGold; |
| 240 |
for ($i=1;$i<=$intMaxLevel;$i++) |
| 241 |
{ |
| 242 |
$arrCreeperLevels[$i] = ($i + $intCreeperAmount).': '.(1000 * $i).T_GOLDCOINS.(10*$i).PINE_PIECES; |
| 243 |
} |
| 244 |
$smarty->assign('noCreeper', 0); |
| 245 |
} |
| 246 |
else $smarty->assign('noCreeper', 1); |
| 247 |
$smarty->assign(array('noCreeperSpace' => 'Brak miejsca na kolejne konstrukcje na pnącza', |
| 248 |
'noIrrigationSpace' => 'Brak miejsca na kolejne systemy nawadniające', |
| 249 |
'noGlassSpace' => 'Brak miejsca na kolejne szklarnie')); |
| 250 |
$smarty->assign_by_ref('FarmLevels', $arrFarmLevels); |
| 251 |
$smarty->assign_by_ref('GlassLevels', $arrGlassLevels); |
| 252 |
$smarty->assign_by_ref('IrrigationLevels', $arrIrrigationLevels); |
| 253 |
$smarty->assign_by_ref('CreeperLevels', $arrCreeperLevels); |
| 254 |
$smarty -> assign(array("Buyglass" => BUY_GLASS, |
| 255 |
"Buyirrigation" => BUY_IRRIGATION, |
| 256 |
"Buycreeper" => BUY_CREEPER)); |
| 257 |
} |
| 258 |
$smarty -> assign(array("Tmith" => T_MITH, |
| 259 |
"Tgoldcoins" => T_GOLDCOINS, |
| 260 |
"Upgradeinfo" => UPGRADE_INFO, |
| 261 |
"Buyland" => BUY_LAND, |
| 262 |
"Field" => FIELD, |
| 263 |
"Glass" => GLASS, |
| 264 |
"Irrigation" => IRRIGATION, |
| 265 |
"Creeper" => CREEPER, |
| 266 |
"Buylandcost" => $intMithcost, |
| 267 |
"Message" => '')); |
| 268 |
|
| 269 |
/** |
| 270 |
* Buy land, glasshouse, irrigation etc |
| 271 |
*/ |
| 272 |
if (isset($_GET['buy'])) |
| 273 |
{ |
| 274 |
$arrBuy = array('L', 'G', 'I', 'C'); |
| 275 |
if (!in_array($_GET['buy'], $arrBuy)) |
| 276 |
{ |
| 277 |
error(ERROR); |
| 278 |
} |
| 279 |
$intAmount = 1; |
| 280 |
if (isset($_POST['amount'])) $intAmount = (int) $_POST['amount']; |
| 281 |
$intField = $intLandsamount; |
| 282 |
$intGlass = $intGlassAmount; |
| 283 |
$intIrrigation = $intIrrigationAmount; |
| 284 |
$intCreeper = $intCreeperAmount; |
| 285 |
if ($_GET['buy'] == 'L') |
| 286 |
{ |
| 287 |
(isset($_POST['amount'])) ? $intMithAmount = (2 * $intLandsamount + $intAmount - 1 ) * $intMithFarmCost * $intAmount / 2 : $intMithAmount = $intMithFarmCost; |
| 288 |
if ($player -> platinum < $intMithAmount) |
| 289 |
{ |
| 290 |
error(NO_MITH); |
| 291 |
} |
| 292 |
if (!$objPlantation -> fields['lands']) |
| 293 |
{ |
| 294 |
$db -> Execute("INSERT INTO farms(owner, lands, place) VALUES(".$player -> id.", 1, '".$player -> location."')"); |
| 295 |
} |
| 296 |
else |
| 297 |
{ |
| 298 |
$db -> Execute("UPDATE farms SET lands=lands+".$intAmount." WHERE id=".$objPlantation -> fields['id']); |
| 299 |
} |
| 300 |
$db -> Execute("UPDATE players SET platinum=platinum-".$intMithAmount." WHERE id=".$player -> id); |
| 301 |
($intAmount > 1) ? $strBuyitem = BUYING_LANDS : $strBuyitem = BUYING_LAND; |
| 302 |
$intField += $intAmount; |
| 303 |
$strMith = $intMithAmount.T_MITH.".<br>"; |
| 304 |
$strOther = ''; |
| 305 |
} |
| 306 |
else |
| 307 |
{ |
| 308 |
$arrItems = array('glasshouse', 'irrigation', 'creeper'); |
| 309 |
$intKey = array_search($_GET['buy'], $arrBuy) - 1; |
| 310 |
if (($player -> credits < $intAmount * 1000) || ($intPine < $intAmount * 10)) error(NO_MONEY); |
| 311 |
if ($objPlantation -> fields['lands'] == $objPlantation -> fields[$arrItems[$intKey]]) error(NO_LANDS); |
| 312 |
$db -> Execute("UPDATE farms SET ".$arrItems[$intKey]."=".$arrItems[$intKey]."+".$intAmount." WHERE owner=".$player -> id." AND place=".$db->Quote($player -> location)) or die($db -> ErrorMsg()); |
| 313 |
$db -> Execute("UPDATE players SET credits=credits-".($intAmount * 1000)." WHERE id=".$player -> id); |
| 314 |
$db -> Execute("UPDATE minerals SET pine=pine-".($intAmount * 10)." WHERE owner=".$player -> id); |
| 315 |
switch ($_GET['buy']) |
| 316 |
{ |
| 317 |
case 'G': |
| 318 |
$intGlass += $_POST['amount']; |
| 319 |
break; |
| 320 |
case 'I': |
| 321 |
$intIrrigation += $_POST['amount']; |
| 322 |
break; |
| 323 |
case 'C': |
| 324 |
$intCreeper += $_POST['amount']; |
| 325 |
break; |
| 326 |
} |
| 327 |
$arrText = array(BUYING_GLASS, BUYING_IRRIGATION, BUYING_CREEPER); |
| 328 |
$strBuyitem = $arrText[$intKey]; |
| 329 |
$strOther = ($intAmount * 1000).T_GOLDCOINS.($intAmount * 10).PINE_PIECES.".<br>"; |
| 330 |
$strMith = ''; |
| 331 |
} |
| 332 |
$smarty -> assign("Message", YOU_BUY.$strBuyitem."<br>".YOU_PAID.": ".$strMith.$strOther.A_LANDS.$intField."<br>".A_GLASS.$intGlass."<br>".A_IRRIGATION.$intIrrigation."<br>".A_CREEPER.$intCreeper."<br><a href=\"farm.php?step=plantation&action=upgrade\">".A_REFRESH."</a><br><br>"); |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
/** |
| 337 |
* Sow herbs |
| 338 |
*/ |
| 339 |
if (isset($_GET['action']) && $_GET['action'] == 'sow') |
| 340 |
{ |
| 341 |
if (!$objPlantation -> fields['lands']) |
| 342 |
{ |
| 343 |
error(NO_FARM); |
| 344 |
} |
| 345 |
$objUsedlands = $db -> Execute("SELECT `amount` FROM `farm` WHERE `owner`=".$player -> id." AND place=".$db->Quote($player -> location)); |
| 346 |
$intUsedlands = 0; |
| 347 |
while (!$objUsedlands -> EOF) |
| 348 |
{ |
| 349 |
$intUsedlands = $intUsedlands + $objUsedlands -> fields['amount']; |
| 350 |
$objUsedlands -> MoveNext(); |
| 351 |
} |
| 352 |
$objUsedlands -> Close(); |
| 353 |
if ($objPlantation -> fields['lands'] == $intUsedlands) |
| 354 |
{ |
| 355 |
error(NO_LAND); |
| 356 |
} |
| 357 |
$objSeeds = $db -> Execute("SELECT illani_seeds, illanias_seeds, nutari_seeds, dynallca_seeds FROM herbs WHERE gracz=".$player -> id); |
| 358 |
if (!$objSeeds -> fields['illani_seeds'] && !$objSeeds -> fields['illanias_seeds'] && !$objSeeds -> fields['nutari_seeds'] && !$objSeeds -> fields['dynallca_seeds']) |
| 359 |
{ |
| 360 |
error(NO_SEEDS); |
| 361 |
} |
| 362 |
$arrSeeds = array('illani_seeds', 'illanias_seeds', 'nutari_seeds', 'dynallca_seeds'); |
| 363 |
$arrSeedsname = array(HERB1, HERB2, HERB3, HERB4); |
| 364 |
$arrSeedsaviable = array(); |
| 365 |
$arrSeedsoption = array(); |
| 366 |
$arrSeedsamount = array(); |
| 367 |
$j = 0; |
| 368 |
for ($i = 0; $i < 4; $i++) |
| 369 |
{ |
| 370 |
$strName = $arrSeeds[$i]; |
| 371 |
if ($objSeeds -> fields[$strName]) |
| 372 |
{ |
| 373 |
$arrSeedsaviable[$j] = $arrSeedsname[$i]; |
| 374 |
$arrSeedsamount[$j] = $objSeeds -> fields[$strName]; |
| 375 |
$arrSeedsoption[$j] = $strName; |
| 376 |
$j++; |
| 377 |
} |
| 378 |
} |
| 379 |
$intLandsamount = $objPlantation -> fields['lands']; |
| 380 |
$intFreelands = $intLandsamount - $intUsedlands; |
| 381 |
$smarty -> assign(array("Sawinfo" => SAW_INFO, |
| 382 |
"FarmInfo" => FARMINFO.CITY, |
| 383 |
"Ilands" => I_LANDS, |
| 384 |
"Iglass" => I_GLASS, |
| 385 |
"Iirrigation" => I_IRRIGATION, |
| 386 |
"Icreeper" => I_CREEPER, |
| 387 |
"Asaw" => A_SAW, |
| 388 |
"Tlands" => T_LANDS.CITY, |
| 389 |
"Tamount" => T_AMOUNT, |
| 390 |
"Ifreelands" => FREE_LANDS, |
| 391 |
"Freelands" => $intFreelands, |
| 392 |
"Seedsname" => $arrSeedsaviable, |
| 393 |
"Seedsamount" => $arrSeedsamount, |
| 394 |
"Seedsoption" => $arrSeedsoption, |
| 395 |
"Glasshouse" => $objPlantation -> fields['glasshouse'], |
| 396 |
"Irrigation" => $objPlantation -> fields['irrigation'], |
| 397 |
"Creeper" => $objPlantation -> fields['creeper'], |
| 398 |
"Refresh" => '', |
| 399 |
"Message" => '')); |
| 400 |
|
| 401 |
/** |
| 402 |
* Start sow herbs |
| 403 |
*/ |
| 404 |
if (isset($_GET['step2']) && $_GET['step2'] == 'next') |
| 405 |
{ |
| 406 |
if (!in_array($_POST['seeds'], $arrSeeds)) |
| 407 |
{ |
| 408 |
error(ERROR); |
| 409 |
} |
| 410 |
if (!ereg("^[1-9][0-9]*$", $_POST['amount'])) |
| 411 |
{ |
| 412 |
error(ERROR); |
| 413 |
} |
| 414 |
if ($_POST['amount'] > $intFreelands) |
| 415 |
{ |
| 416 |
error(NO_FREE); |
| 417 |
} |
| 418 |
if ($player -> hp < 1) |
| 419 |
{ |
| 420 |
error(YOU_DEAD); |
| 421 |
} |
| 422 |
$intEnergy = $_POST['amount'] / 5 ; // also for ability increase |
| 423 |
if ($intEnergy > $player -> energy) |
| 424 |
{ |
| 425 |
error(NO_ENERGY); |
| 426 |
} |
| 427 |
$intKey = array_search($_POST['seeds'], $arrSeeds); |
| 428 |
if ($_POST['amount'] > $objSeeds -> fields[$arrSeeds[$intKey]]) |
| 429 |
{ |
| 430 |
error(NO_SEED); |
| 431 |
} |
| 432 |
$arrHerbsname = array('illani', 'illanias', 'nutari', 'dynallca'); |
| 433 |
if ($intKey) |
| 434 |
{ |
| 435 |
$arrItems = array(0, $objPlantation -> fields['glasshouse'], $objPlantation -> fields['irrigation'], $objPlantation -> fields['creeper']); |
| 436 |
$objFarm = $db -> Execute("SELECT amount, name FROM farm WHERE owner=".$player -> id." AND place=".$db->Quote($player -> location)); |
| 437 |
$arrNeeditems = array(0, 0, 0, 0); |
| 438 |
while (!$objFarm -> EOF) |
| 439 |
{ |
| 440 |
$intKey2 = array_search($objFarm -> fields['name'], $arrHerbsname); |
| 441 |
if ($intKey2 == 1) |
| 442 |
{ |
| 443 |
$arrNeeditems[1] = $arrNeeditems[1] + $objFarm -> fields['amount']; |
| 444 |
} |
| 445 |
elseif ($intKey2 == 2) |
| 446 |
{ |
| 447 |
$arrNeeditems[1] = $arrNeeditems[1] + $objFarm -> fields['amount']; |
| 448 |
$arrNeeditems[2] = $arrNeeditems[2] + $objFarm -> fields['amount']; |
| 449 |
} |
| 450 |
elseif ($intKey2 == 3) |
| 451 |
{ |
| 452 |
$arrNeeditems[1] = $arrNeeditems[1] + $objFarm -> fields['amount']; |
| 453 |
$arrNeeditems[2] = $arrNeeditems[2] + $objFarm -> fields['amount']; |
| 454 |
$arrNeeditems[3] = $arrNeeditems[3] + $objFarm -> fields['amount']; |
| 455 |
} |
| 456 |
$objFarm -> MoveNext(); |
| 457 |
} |
| 458 |
$objFarm -> Close(); |
| 459 |
for ($i = 1; $i <= $intKey; $i++) |
| 460 |
{ |
| 461 |
$arrNeeditems[$i] = $_POST['amount'] + $arrNeeditems[$i]; |
| 462 |
if (!$arrItems[$i] || $arrItems[$i] < $arrNeeditems[$i]) |
| 463 |
{ |
| 464 |
error(NO_ITEMS); |
| 465 |
} |
| 466 |
} |
| 467 |
} |
| 468 |
$db -> Execute("UPDATE herbs SET ".$arrSeeds[$intKey]."=".$arrSeeds[$intKey]."-".$_POST['amount']." WHERE gracz=".$player -> id); |
| 469 |
$farmId = $db -> GetOne("SELECT id FROM farm WHERE owner=".$player -> id." AND place='".$player -> location."' AND age=0 AND name=".$db->Quote($arrHerbsname[$intKey])); |
| 470 |
if ($farmId) |
| 471 |
{ |
| 472 |
$db -> Execute("UPDATE farm SET amount=amount+".$_POST['amount']." WHERE id=".$farmId); |
| 473 |
} |
| 474 |
else |
| 475 |
{ |
| 476 |
$db -> Execute("INSERT INTO farm (owner, amount, name, age, place) VALUES(".$player -> id.", ".$_POST['amount'].", '".$arrHerbsname[$intKey]."', 0, '$player->location')"); |
| 477 |
} |
| 478 |
$db -> Execute("UPDATE players SET energy=energy-".$intEnergy.", herbalist=herbalist+".$intEnergy." WHERE id=".$player -> id); |
| 479 |
$smarty -> assign("Refresh", A_REFRESH); |
| 480 |
$smarty -> assign("Message", YOU_SAW.$_POST['amount'].T_LANDS2.$arrHerbsname[$intKey].YOU_GAIN.$intEnergy.T_ABILITY); |
| 481 |
} |
| 482 |
} |
| 483 |
|
| 484 |
/** |
| 485 |
* Gather herbs |
| 486 |
*/ |
| 487 |
if (isset($_GET['action']) && $_GET['action'] == 'chop') |
| 488 |
{ |
| 489 |
if (!$objPlantation -> fields['lands']) |
| 490 |
{ |
| 491 |
error(NO_FARM); |
| 492 |
} |
| 493 |
$objHerbs = $db -> Execute("SELECT id, amount, name, age FROM farm WHERE owner=".$player -> id." AND place=".$db->Quote($player -> location)); |
| 494 |
if (!$objHerbs -> fields['id']) |
| 495 |
{ |
| 496 |
error(NO_HERBS); |
| 497 |
} |
| 498 |
$intLandsamount = $objPlantation -> fields['lands']; |
| 499 |
$arrHerbsname = array(); |
| 500 |
$arrHerbsid = array(); |
| 501 |
$arrHerbsamount = array(); |
| 502 |
$arrHerbsage = array(); |
| 503 |
$i = 0; |
| 504 |
while (!$objHerbs -> EOF) |
| 505 |
{ |
| 506 |
$arrHerbsname[$i] = $objHerbs -> fields['name']; |
| 507 |
$arrHerbsid[$i] = $objHerbs -> fields['id']; |
| 508 |
$arrHerbsamount[$i] = $objHerbs -> fields['amount']; |
| 509 |
$arrHerbsage[$i] = $objHerbs -> fields['age']; |
| 510 |
$i++; |
| 511 |
$objHerbs -> MoveNext(); |
| 512 |
} |
| 513 |
$objHerbs -> Close(); |
| 514 |
$smarty -> assign(array("Chopinfo" => CHOP_INFO, |
| 515 |
"Tamount" => T_AMOUNT, |
| 516 |
"Tage" => T_AGE, |
| 517 |
"FarmInfo" => FARMINFO.CITY, |
| 518 |
"Message" => '', |
| 519 |
"Herbsname" => $arrHerbsname, |
| 520 |
"Herbsid" => $arrHerbsid, |
| 521 |
"Herbsamount" => $arrHerbsamount, |
| 522 |
"Herbsage" => $arrHerbsage, |
| 523 |
"Herbid" => 0)); |
| 524 |
/** |
| 525 |
* Start gather |
| 526 |
*/ |
| 527 |
if (isset($_GET['id'])) |
| 528 |
{ |
| 529 |
if (!ereg("^[1-9][0-9]*$", $_GET['id'])) |
| 530 |
{ |
| 531 |
error(ERROR); |
| 532 |
} |
| 533 |
$objHerb = $db -> Execute("SELECT `owner`, `amount`, `name`, `age` FROM `farm` WHERE `id`=".$_GET['id']); |
| 534 |
if ($objHerb -> fields['owner'] != $player -> id) |
| 535 |
{ |
| 536 |
error(NOT_YOUR); |
| 537 |
} |
| 538 |
$smarty -> assign(array("Herbid" => $_GET['id'], |
| 539 |
"Herbname" => $objHerb -> fields['name'], |
| 540 |
"Agather" => A_GATHER, |
| 541 |
"Froma" => FROM_A, |
| 542 |
"Tlands3" => T_LANDS3)); |
| 543 |
/** |
| 544 |
* Gather some herbs |
| 545 |
*/ |
| 546 |
if (isset($_GET['step2']) && $_GET['step2'] == 'next') |
| 547 |
{ |
| 548 |
if (!ereg("^[1-9][0-9]*$", $_POST['amount'])) |
| 549 |
{ |
| 550 |
error(ERROR); |
| 551 |
} |
| 552 |
if (!$objHerb -> fields['age']) |
| 553 |
{ |
| 554 |
error(TOO_YOUNG); |
| 555 |
} |
| 556 |
if ($objHerb -> fields['amount'] < $_POST['amount']) |
| 557 |
{ |
| 558 |
error(TO_MUCH); |
| 559 |
} |
| 560 |
if ($player -> hp < 1) |
| 561 |
{ |
| 562 |
error(YOU_DEAD); |
| 563 |
} |
| 564 |
$intEnergy = $_POST['amount'] / 5; |
| 565 |
if ($intEnergy > $player -> energy) |
| 566 |
{ |
| 567 |
error(NO_ENERGY); |
| 568 |
} |
| 569 |
$arrAge = array(0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 10, 10, 10, 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1); |
| 570 |
$arrHerbname = array('illani', 'illanias', 'nutari', 'dynallca'); |
| 571 |
$arrHerbmodif = array("Altara" => array(1, 3.5, 2, 6.5), "Ardulith" => array(3, 1.5, 6, 2.5)); |
| 572 |
$intKey = array_search($objHerb -> fields['name'], $arrHerbname); |
| 573 |
$intRoll = rand(-15, 15) / 100; |
| 574 |
$intKey2 = $objHerb -> fields['age'] - 1; |
| 575 |
if ($objHerb -> fields['age'] > 3) |
| 576 |
{ |
| 577 |
$intAbility = $intEnergy; |
| 578 |
} |
| 579 |
else |
| 580 |
{ |
| 581 |
$intAbility = 0; |
| 582 |
} |
| 583 |
|
| 584 |
/** |
| 585 |
* Add bonuses to ability |
| 586 |
*/ |
| 587 |
require_once('includes/abilitybonus.php'); |
| 588 |
$player -> herbalist = abilitybonus('herbalist'); |
| 589 |
$fltSum = $player -> herbalist + ($_POST['amount'] - 1) * 0.1; |
| 590 |
$intAmount = floor(($arrAge[$intKey2] * $_POST['amount'] / $arrHerbmodif[$player -> location][$intKey]) * (1 + $fltSum / 400)); |
| 591 |
$intAmount = floor($intAmount + ($intAmount * $intRoll)); |
| 592 |
if ($intAmount < 0) |
| 593 |
{ |
| 594 |
$intAmount = 0; |
| 595 |
} |
| 596 |
if ($_POST['amount'] < $objHerb -> fields['amount']) |
| 597 |
{ |
| 598 |
$db -> Execute("UPDATE `farm` SET `amount`=`amount`-".$_POST['amount']." WHERE `id`=".$_GET['id']); |
| 599 |
} |
| 600 |
else |
| 601 |
{ |
| 602 |
$db -> Execute("DELETE FROM `farm` WHERE `id`=".$_GET['id']); |
| 603 |
} |
| 604 |
$db -> Execute("UPDATE `herbs` SET `".$arrHerbname[$intKey]."`=`".$arrHerbname[$intKey]."`+".$intAmount." WHERE `gracz`=".$player -> id); |
| 605 |
$db -> Execute("UPDATE `players` SET `energy`=`energy`-".$intEnergy.", `herbalist`=`herbalist`+".$intAbility." WHERE `id`=".$player -> id); |
| 606 |
$smarty -> assign("Message", YOU_GATHER.$intAmount.T_AMOUNT2.$arrHerbname[$intKey].T_FARM.$intAbility.T_ABILITY); |
| 607 |
} |
| 608 |
$objHerb -> Close(); |
| 609 |
} |
| 610 |
} |
| 611 |
|
| 612 |
$smarty -> assign(array("Action" => $_GET['action'], |
| 613 |
"Lands" => $intLandsamount)); |
| 614 |
if ($objPlantation -> fields['id']) |
| 615 |
{ |
| 616 |
$objPlantation -> Close(); |
| 617 |
} |
| 618 |
} |
| 619 |
|
| 620 |
/** |
| 621 |
* Assign variable to template and display page |
| 622 |
*/ |
| 623 |
$smarty -> assign(array("Step" => $_GET['step'], |
| 624 |
"Aback" => A_BACK)); |
| 625 |
$smarty -> display ('farm.tpl'); |
| 626 |
|
| 627 |
require_once("includes/foot.php"); |
| 628 |
|
| 629 |
?> |