1
<?php
2
/**
3
 *   Funkcje pliku:
4
 *   School - train stats
5
 *
6
 *   @name                 : train.php                            
7
 *   @copyright            : (C) 2004,2005,2006,2007 Vallheru Team based on Gamers-Fusion ver 2.5
8
 *   @author               : thindil <thindil@users.sourceforge.net>
9
 *   @version              : 1.7
10
 *   @since                : 04.03.5007
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: train.php 931 2007-03-04 12:08:56Z thindil $
31
32
$title = 'Szkolenie';
33
require_once('includes/head.php');
34
35
/**
36
* Get the localization for game
37
*/
38
require_once('languages/'.$player -> lang.'/train.php');
39
40
if ($player -> location != 'Altara' && $player -> location != 'Ardulith') 
41
{
42
    error (ERROR);
43
}
44
if ($player -> hp == 0) 
45
{
46
	error (YOU_DEAD);
47
}
48
if (!$player -> race)
49
{
50
	error(NO_RACE);
51
}
52
if (!$player -> clas) 
53
{
54
	error(NO_CLASS);
55
}
56
57
$arrRaces = array('Człowiek', 'Elf', 'Krasnolud', 'Hobbit', 'Jaszczuroczłek', 'Gnom');
58
$arrRaceCost = array(array(.7, .7, .7, .7),
59
					array(.9, .5, .5, .9),
60
					array(.5, .9, .9, .5),
61
					array(.9, .5, .9, .5),
62
					array(.5, .9, .5, .9),
63
					array(.9, .7, .9, .7));
64
$arrClasses = array('Wojownik', 'Mag', 'Barbarzyńca', 'Złodziej', 'Rzemieślnik');
65
$arrClassCost = array(array(.9, .9), array(.5, .5), array(.7, .7), array(.7, .7), array(.7, .7));
66
67
$smarty -> assign_by_ref('StatsDesc', $arrStatsDesc);
68
69
$intRaceKey = array_search($player -> race, $arrRaces);
70
$intClassKey = array_search($player -> clas, $arrClasses);
71
72
$arrPlayerCost = array_merge($arrRaceCost[$intRaceKey], $arrClassCost[$intClassKey]);
73
74
if ($player -> race == 'Gnom')
75
{
76
	$arrPlayerCost[5] = .9;
77
}
78
79
unset($arrRaceCost, $arrRaces, $arrClasses, $arrClassCost, $intRaceKey, $intClassKey);
80
$smarty -> assign_by_ref('PlayerCost', $arrPlayerCost);
81
$arrStats = array('strength', 'agility', 'szyb', 'wytrz', 'inteli', 'wisdom');
82
$smarty -> assign_by_ref('StatOptions', $arrStats);
83
$smarty -> assign_by_ref('TrainedStats', $arrTrainedStats);
84
85
if (isset ($_GET['action']) && $_GET['action'] == 'train') 
86
{
87
    if (!isset($_POST['rep']))
88
    {
89
        error(HOW_MANY);
90
    }
91
    if (!ereg("^[1-9][0-9]*$", $_POST['rep'])) 
92
    {
93
        error (ERROR);
94
    }
95
    if (!in_array($_POST['train'], $arrStats)) 
96
    {
97
        error (ERROR);
98
    }
99
	$intPlayerKey = array_search($_POST['train'], $arrStats);
100
	$repeat = $_POST['rep'] * $arrPlayerCost[$intPlayerKey];
101
    $gain = $_POST['rep'] * .060;
102
    $repeat = round($repeat, 1);
103
    unset($arrPlayerCost);
104
	if ($repeat > $player -> energy) 
105
    {
106
        error (NO_ENERGY);
107
    }
108
	$smarty -> assign_by_ref('Train', $_POST['train']);
109
	$smarty -> assign_by_ref('Rep', $_POST['rep']);
110
	$smarty -> assign_by_ref('energyCost', $repeat);
111
	$smarty -> assign_by_ref('gainedStat', $gain);
112
	$smarty -> assign_by_ref('gainedStatName', $arrStatsDesc[$intPlayerKey]);
113
114
    if (isset($_GET['step']) && $_GET['step'] == 'next')
115
    {
116
		if ($_POST['train'] == 'wytrz') 
117
        {
118
            $intCondition = floor($player -> cond + $gain);
119
            if ($intCondition > $player -> cond)
120
            {
121
				$intGainedHP = $intCondition - floor($player -> cond);
122
                $db -> Execute('UPDATE `players` SET `max_hp`=`max_hp`+'.$intGainedHP.' WHERE `id`='.$player -> id);
123
            } 
124
        }
125
        $db -> Execute('UPDATE `players` SET `energy`=`energy`-'.$repeat.', '.$_POST['train'].'='.$_POST['train'].'+'.$gain.' WHERE `id`='.$player -> id);
126
        $arrTrained = $db -> GetRow('SELECT `id` FROM `trained_stats` WHERE `id`='.$player -> id);
127
        if (!isset($arrTrained['id']))
128
        {
129
            $db -> Execute('INSERT INTO `trained_stats` (`'.$_POST['train'].'`, `id`) VALUES ('.$gain.', '.$player -> id.')');
130
        }
131
        else
132
        {
133
            $db -> Execute('UPDATE `trained_stats` SET '.$_POST['train'].'='.$_POST['train'].'+'.$gain.'WHERE `id`='.$player -> id);
134
        }
135
        error (YOU_GAIN.'<b>'.$gain.'</b> '.$arrStatsDesc[$intPlayerKey].'.');
136
    }
137
}
138
unset($repeat, $gain, $intPlayerKey, $arrStats, $arrStatsDesc, $intCondition);
139
/**
140
* Initialization ov variables
141
*/
142
if (!isset($_GET['action']))
143
{
144
    $_GET['action'] = '';
145
}
146
if (!isset($_GET['step']))
147
{
148
    $_GET['step'] = '';
149
}
150
151
/**
152
* Assign variables to template and display page
153
*/
154
$smarty -> assign_by_ref('Action', $_GET['action']);
155
$smarty -> display ('train.tpl');
156
157
require_once('includes/foot.php');
158
?>