1
<?php
2
/**
3
 *   File functions:
4
 *   Temple
5
 *
6
 *   @name                 : temple.php
7
 *   @copyright            : (C) 2004, 2005, 2006 Vallheru Team based on Gamers-Fusion ver 2.5
8
 *   @author               : thindil <thindil@users.sourceforge.net>
9
 *   @author               : eyescream <tduda@users.sourceforge.net>
10
 *   @author               : Zamareth <zamareth@users.sourceforge.net>
11
 *   @version              : 1.4
12
 *   @since                : 13.09.2007
13
 *
14
 */
15
16
//
17
//
18
//       This program is free software; you can redistribute it and/or modify
19
//   it under the terms of the GNU General Public License as published by
20
//   the Free Software Foundation; either version 2 of the License, or
21
//   (at your option) any later version.
22
//
23
//   This program is distributed in the hope that it will be useful,
24
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
25
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
//   GNU General Public License for more details.
27
//
28
//   You should have received a copy of the GNU General Public License
29
//   along with this program; if not, write to the Free Software
30
//   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
31
//
32
// $Id$
33
34
$title = 'Świątynia';
35
require_once('includes/head.php');
36
require_once('includes/security.php');
37
38
/**
39
* Get the localization for game
40
*/
41
require_once('languages/'.$player -> lang.'/temple.php');
42
43
if ($player -> location != 'Altara' && $player -> location != 'Ardulith')
44
{
45
    error (ERROR);
46
}
47
48
// Polish grammar.
49
$strGod = $player -> deity;
50
if (in_array($player -> deity, array('Tartus', 'Unrod', 'Luzubal', 'Gulgard')))
51
{
52
    $strGod .='a';
53
}
54
if ($player -> deity == 'Anea')
55
{
56
	$strGod = 'Anei';
57
}
58
if ($player -> deity == 'Yala')
59
{
60
	$strGod = 'Yali';
61
}
62
if (isset ($_GET['view']))
63
{
64
/**
65
* Check common errors.
66
*/
67
    if ($_GET['view'] == 'service' || $_GET['view'] == 'prayer')
68
    {
69
        if ($player -> deity == '')
70
        {
71
            error (NO_DEITY);
72
        }
73
        if ($player -> hp == 0)
74
        {
75
            error (YOU_DEAD);
76
        }
77
    }
78
    switch($_GET['view'])
79
    {
80
        case 'service':     /// Work in temple to gain faith points.
81
            if (isset($_POST['rep']))
82
            {
83
                $intNum = uint32($_POST['rep']);
84
                if ($player -> energy < $intNum / 2)
85
                {
86
                    error (NO_ENERGY);
87
                }
88
                $smarty -> assign ('Message', YOU_WORK.$intNum.YOU_WORK2);
89
                $db -> Execute('UPDATE `players` SET `energy`=`energy`-'.($intNum / 2).', `pw`=`pw`+'.$intNum.' WHERE `id`='.$player -> id);
90
            }
91
            break;
92
        case 'book':        /// Read the story.
93
            $intKey = isset($_GET['book']) ? $_GET['book'] : 0;
94
            if( $intKey > 2)
95
            {
96
                $intKey = 2;
97
            }
98
            $smarty -> assign(array('Booktext' => $arrText[$intKey],
99
                                    'Next' => $intKey));
100
            unset($arrText);
101
            break;
102
        case 'pantheon':    ///View game pantheon.
103
            $smarty -> assign_by_ref('Godnames', $arrNames);
104
            $smarty -> assign_by_ref('Goddesc', $arrDesc);
105
            break;
106
        case 'prayer':      ///Pray to god.
107
            if ($player -> race =='')
108
            {
109
                error(NO_RACE);
110
            }
111
			if ($player -> faith < 1)
112
			{
113
				error (NO_PW);
114
			}
115
            // All possible blessings.
116
			//TODO: dodac hutnictwo, szpiegostwo gdy pojawia sie w grze
117
            $arrBless = array('agility', 'strength', 'inteli', 'wisdom', 'szyb', 'wytrz', 'hp', 'ability', 'alchemia', 'fletcher', 'atak', 'shoot', 'unik', 'magia', 'breeding', 'mining', 'lumberjack', 'herbalist', 'jeweller', 'hutnictwo');
118
            $arrBlessNames = array(AGI, STR, INTELI, WIS, SPE, CON, HITPTS, SMI, ALC, FLE, WEA, SHO, DOD, CAS, BRE, MINI, LUMBER, HERBS, JEWEL, METAL);
119
120
            // Costs of praying in faith points for each race. See $arrBless for values matching.
121
            $arrRaces = array('Człowiek', 'Elf', 'Krasnolud', 'Hobbit', 'Jaszczuroczłek', 'Gnom');
122
            $arrFaithCosts = array(array('10', '10', '10', '10', '10', '10', '10', '10', '10', '10', '10', '10', '10', '10', '10', '10', '10', '10', '10', '10'),
123
								   array('7', '15', '10', '10', '7', '15', '15', '15', '7', '7', '15', '7', '10', '7', '7', '15', '7', '7', '10', '15'),
124
								   array('15', '7', '10', '10', '15', '7', '7', '7', '15', '10', '7', '15', '10', '15', '15', '7', '15', '15', '7', '7'),
125
								   array('7', '15', '10', '10', '7', '10', '10', '10', '15', '10', '10', '10', '10', '7', '7', '10', '10', '7', '10', '15'),
126
								   array('7', '7', '15', '15', '7', '7', '7', '10', '10', '10', '10', '10', '10', '15', '15', '15', '15', '15', '15', '10'),
127
								   array('10', '15', '10', '15', '15', '10', '10', '7', '7', '7', '15', '15', '15', '15', '7', '7', '15', '7', '7', '7'));
128
			$intRaceKey = array_search($player -> race, $arrRaces);
129
			// Note: All gods can bless stats (0-5). Heluvald and Daeraell have the same bonuses.
130
			$arrGods = array('Tartus', 'Anea', 'Meltis', 'Dintel', 'Yala', 'Unrod', 'Luzubal', 'Gulgard', 'Artis');
131
			$intGodKey = array_search($player -> deity, $arrGods);
132
			$arrPossibleBlessings = array(array(1, 2, 10, 13, 19),
133
										  array(0, 3, 12, 13),//szpiegostwo
134
										  array(1, 5, 15, 16, 17),
135
										  array(3, 6, 8, 14, 17),
136
										  array(1, 2, 7, 9, 18),
137
										  array(0, 5, 9, 11),//, Złodziejstwo),
138
										  array(2, 4, 10, 11),//wywiad
139
										  array(3, 5, 7, 15, 19),
140
										  array(0, 4, 8, 18));//Złodziejstwo
141
			foreach ($arrPossibleBlessings[$intGodKey] as $Key)
142
			{
143
				$arrBlessings[] = array($arrBlessNames[$Key], $arrFaithCosts[$intRaceKey][$Key]);
144
			}
145
			$smarty -> assign_by_ref('Blessings', $arrBlessings);
146
			$smarty -> assign_by_ref('Indices', $arrPossibleBlessings[$intGodKey]);
147
			if (isset($_POST['pray']))
148
			{
149
				$intNumber = uint32($_POST['pray']);
150
				// Check if someone tampered with form: wrong energy cost, wrong blessing number passed.
151
				if (!preg_match("/^[01246]$/", $_POST['praytype']) || !in_array($intNumber, $arrPossibleBlessings[$intGodKey]))
152
				{
153
					error(ERROR);
154
				}
155
				if ($_POST['praytype'] == 0)
156
				{
157
					$intPermCost = $intNumber < 7 ? 100 : 300;
158
					if ($player -> faith - $intPermCost < 0)
159
					{
160
						error(NO_PW);
161
					}
162
					$strQuery = 'UPDATE `players` SET `'.$arrBless[$intNumber].'`=`'.$arrBless[$intNumber].'`+1, ';
163
					if ($_POST['pray'] == 5 || $_POST['pray'] == 6)
164
					{
165
						$strQuery .= '`max_hp`=`max_hp`+1, ';
166
					}
167
					$strQuery .= '`pw`=`pw`-'.$intPermCost.' WHERE `id`='.$player -> id;
168
					$db -> Execute($strQuery);
169
					$strMessage = PERM_BONUS.$arrBlessNames[$intNumber];
170
					$smarty -> assign('Message', $strMessage);
171
					break;
172
				}
173
				if ($player -> bless !='')
174
				{
175
					error(YOU_HAVE);
176
				}
177
				if ($player -> energy < $_POST['praytype'])
178
				{
179
					error(NO_ENERGY);
180
				}
181
				if ($player -> faith < $arrFaithCosts[$intRaceKey][$intNumber])
182
				{
183
					error (NO_PW);
184
				}
185
				$strMessage = YOU_PRAY.$strGod;
186
				$strQuery = 'UPDATE `players` SET `pw`=`pw`-'.$arrFaithCosts[$intRaceKey][$intNumber].', `energy`=`energy`-'.$_POST['praytype'];
187
				switch (rand(1, 10))
188
				{
189
					case 10: // god's wrath
190
						$strMessage .= P_DEAD.$player -> deity.P_DEAD2;
191
						$strQuery .= ', `hp`=0';
192
						break;
193
					case 9: // nothing
194
						$strMessage .= BUT_FAIL;
195
						break;
196
					default:    // success
197
						$intBonus = $_POST['praytype'] * $player -> level;
198
						// Blessings to skills are reduced.
199
						if ($intNumber > 5)
200
						{
201
							$intBonus /= 10;
202
						}
203
						$strQuery .= ', `bless`=\''.$arrBless[$intNumber].'\', `blessval`='.$intBonus;
204
						$strQuery .= $intNumber == 6 ? ', `hp`=`hp`+'.$intBonus : '';
205
						$strMessage .= P_SUCCESS.$arrBlessNames[$intNumber];
206
				}
207
				$smarty -> assign('Message', $strMessage);
208
				$db -> Execute($strQuery.' WHERE `id`='.$player -> id);
209
			}
210
			break;
211
		default:
212
			error(ERROR);
213
	}
214
}
215
else
216
{
217
    $_GET['view'] = '';
218
}
219
220
/**
221
* Assign variables to template and display page
222
*/
223
$smarty -> assign(array('God' => $player -> deity,
224
						'God2' => $strGod,
225
						'Location' => $player -> location));
226
$smarty -> display('temple.tpl');
227
228
// After displaying delete arrays that aren't used anymore.
229
if (isset($arrNames))
230
{
231
    unset($arrNames,$arrDesc);
232
}
233
if (isset($arrBless))
234
{
235
    unset($arrBless, $arrBlessNames, $arrRaces, $arrFaithCosts, $arrGods, $arrPossibleBlessings, $arrBlessings);
236
}
237
require_once('includes/foot.php');
238
?>