1
<?php
2
/**
3
 *   File functions:
4
 *   Mines - digging for minerals
5
 *
6
 *   @name                 : mines.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                : 04.09.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: mines.php 566 2006-09-13 09:31:08Z thindil $
31
32
$title = "Kopalnie";
33
require_once("includes/head.php");
34
require_once("includes/checkexp.php");
35
36
/**
37
* Get the localization for game
38
*/
39
require_once("languages/".$player -> lang."/mines.php");
40
41
if ($player -> location != 'Ardulith')
42
{
43
    error (ERROR);
44
}
45
46
$objMines = $db -> Execute("SELECT `owner`, `copper`, `zinc`, `tin`, `iron`, `coal` FROM `mines` WHERE `owner`=".$player -> id);
47
48
/**
49
* Main menu
50
*/
51
if (!isset($_GET['mine']))
52
{
53
    $arrMinerals = array('copper', 'zinc', 'tin', 'iron', 'coal');
54
    $arrMineralamount = array(0, 0, 0, 0, 0);
55
    for ($i = 0; $i < 5; $i++)
56
    {
57
        $strMinname = $arrMinerals[$i];
58
        if ($objMines -> fields[$strMinname])
59
        {
60
            $arrMineralamount[$i] = $objMines -> fields[$strMinname];
61
        }
62
    }
63
    /**
64
     * Did player search for minerals?
65
     */
66
    $objSearch = $db -> Execute("SELECT `mineral`, `days` FROM `mines_search` WHERE `player`=".$player -> id);
67
    if ($objSearch -> fields['mineral'])
68
    {
69
        $arrMinname = array(M_COPPER, M_ZINC, M_TIN, M_IRON, M_COAL);
70
        $intKey = array_search($objSearch -> fields['mineral'], $arrMinerals);
71
        if ($objSearch -> fields['days'] > 1)
72
        {
73
            $strDays = SEARCH_DAYS;
74
        }
75
            else
76
        {
77
            $strDays = SEARCH_DAY;
78
        }
79
        $strSearch = YOU_SEARCH.$arrMinname[$intKey].THIS_TAKE.$objSearch -> fields['days'].$strDays;
80
    }
81
    else
82
    {
83
        $strSearch = '';
84
    }
85
    $objSearch -> Close();
86
    $smarty -> assign(array("Minesinfo" => MINES_INFO,
87
                            "Acopper" => A_COPPER,
88
                            "Azinc" => A_ZINC,
89
                            "Atin" => A_TIN,
90
                            "Airon" => A_IRON,
91
                            "Acoal" => A_COAL,
92
                            "Minamount" => $arrMineralamount,
93
                            "Minessearch" => $strSearch));
94
}
95
96
/**
97
* Mine menu
98
*/
99
if (isset($_GET['mine']) && !isset($_GET['step']))
100
{
101
    $arrMines = array('copper', 'zinc', 'tin', 'iron', 'coal');
102
    if (!in_array($_GET['mine'], $arrMines))
103
    {
104
        error(ERROR);
105
    }
106
    $arrMinerals = array(M_COPPER, M_ZINC, M_TIN, M_IRON, M_COAL);
107
    $intKey = array_search($_GET['mine'], $arrMines);
108
    if ($objMines -> fields[$_GET['mine']] > 0)
109
    {
110
        $smarty -> assign("Mine2", 'N');
111
    }
112
    else
113
    {
114
        $smarty -> assign("Mine2", 'Y');
115
    }
116
    $smarty -> assign(array("Mineinfo" => MINE_INFO,
117
                            "Minename" => $arrMinerals[$intKey],
118
                            "Asearch" => A_SEARCH,
119
                            "Adig" => A_DIG,
120
                            "Mineinfo2" => MINE_INFO2));
121
}
122
123
/**
124
* Search for minerals
125
*/
126
if (isset($_GET['step']) && $_GET['step'] == 'search')
127
{
128
    $objTest = $db -> Execute("SELECT `days` FROM `mines_search` WHERE `player`=".$player -> id);
129
    if ($objTest -> fields['days'])
130
    {
131
        if ($objTest -> fields['days'] > 1)
132
        {
133
            $strDays = SEARCH_DAYS;
134
        }
135
            else
136
        {
137
            $strDays = SEARCH_DAY;
138
        }
139
        error(YOU_SEARCH.$objTest -> fields['days'].$strDays);
140
    }
141
    $objTest -> Close();
142
    $arrMines = array('coal', 'copper', 'zinc', 'tin', 'iron');
143
    if (!in_array($_GET['mine'], $arrMines))
144
    {
145
        error(ERROR);
146
    }
147
    $arrMinerals = array('coal' => 0.75,
148
                         'copper' => 1, 
149
                         'zinc' => 2, 
150
                         'tin' => 3, 
151
                         'iron' => 4);
152
    $intSmallmith = $arrMinerals[$_GET['mine']];
153
    if ($intSmallmith < 1)
154
    {
155
        $intSmallmith = 0;
156
    }
157
    $intMediummith = ceil($arrMinerals[$_GET['mine']] * 2);
158
    $intLargemith = ceil($arrMinerals[$_GET['mine']] * 3);
159
    $intSmallgold = $arrMinerals[$_GET['mine']] * 500;
160
    $intMediumgold = $arrMinerals[$_GET['mine']] * 1000;
161
    $intLargegold = $arrMinerals[$_GET['mine']] * 1500;
162
    if (!isset($_GET['type']))
163
    {
164
        $_GET['type'] = '';
165
        $smarty -> assign(array("Smallmith" => $intSmallmith,
166
                                "Mediummith" => $intMediummith,
167
                                "Largemith" => $intLargemith,
168
                                "Smallgold" => $intSmallgold,
169
                                "Mediumgold" => $intMediumgold,
170
                                "Largegold" => $intLargegold,
171
                                "Asearch" => A_SEARCH,
172
                                "Minerals" => MINERALS,
173
                                "Goldcoins" => GOLD_COINS,
174
                                "Mithrilcoins" => MITHRIL_COINS,
175
                                "Searchdays" => SEARCH_DAYS,
176
                                "Searchday" => SEARCH_DAY,
177
                                "Type" => $_GET['type']));
178
    }
179
        else
180
    {
181
        $arrType = array('small', 'medium', 'large');
182
        if (!in_array($_GET['type'], $arrType))
183
        {
184
            error(ERROR);
185
        }
186
        if ($_GET['type'] == 'small')
187
        {
188
            $intGoldcost = $intSmallgold;
189
            $intMithcost = $intSmallmith;
190
            $intDays = 1;
191
        }
192
        if ($_GET['type'] == 'medium')
193
        {
194
            $intGoldcost = $intMediumgold;
195
            $intMithcost = $intMediummith;
196
            $intDays = 2;
197
        }
198
        if ($_GET['type'] == 'large')
199
        {
200
            $intGoldcost = $intLargegold;
201
            $intMithcost = $intLargemith;
202
            $intDays = 3;
203
        }
204
        if ($intGoldcost > $player -> credits)
205
        {
206
            error(NO_MONEY);
207
        }
208
        if ($intMithcost > $player -> platinum)
209
        {
210
            error(NO_MITH);
211
        }
212
        $db -> Execute("UPDATE players SET credits=credits-".$intGoldcost.", platinum=platinum-".$intMithcost." WHERE id=".$player -> id);
213
        $db -> Execute("INSERT INTO mines_search (player, days, mineral, searchdays) VALUES(".$player -> id.", ".$intDays.", '".$_GET['mine']."', ".$intDays.")");
214
        $smarty -> assign(array("Type" => $_GET['type'],
215
            "Message" => YOU_START));
216
    }
217
}
218
219
/**
220
* Dig for minerals
221
*/
222
if (isset($_GET['step']) && $_GET['step'] == 'dig')
223
{
224
    $arrMines = array('copper', 'zinc', 'tin', 'iron', 'coal');
225
    if (!in_array($_GET['mine'], $arrMines))
226
    {
227
        error(ERROR);
228
    }
229
    if (!$objMines -> fields[$_GET['mine']])
230
    {
231
        error(NO_MINERALS);
232
    }
233
    $arrMinerals = array(M_COPPER, M_ZINC, M_TIN, M_IRON, M_COAL);
234
    $intKey = array_search($_GET['mine'], $arrMines);
235
    $smarty -> assign(array("Yousend" => YOU_SEND,
236
                            "Minname" => $arrMinerals[$intKey],
237
                            "Adig" => A_DIG,
238
                            "Menergy" => M_ENERGY,
239
                            "Message" => ''));
240
    if (isset($_GET['dig']) && $_GET['dig'] == 'Y')
241
    {
242
        if (!isset($_POST['amount']) || !ereg("^[1-9][0-9]*$", $_POST['amount']))
243
        {
244
            error(ERROR);
245
        }
246
        if ($_POST['amount'] > $player -> energy)
247
        {
248
            error(NO_ENERGY);
249
        }
250
        if ($player -> hp < 1)
251
        {
252
            error(YOU_DEAD);
253
        }
254
        $arrMinerals2 = array(1, 2, 3, 4, 1);
255
256
        /**
257
         * Add bonuses to ability
258
         */
259
        require_once('includes/abilitybonus.php');
260
        $fltAbility = abilitybonus('mining');
261
		$fltSum = $_POST['amount'] * ($fltAbility + ($_POST['amount'] - 1) * 0.05);
262
		$intAmount = ceil(((rand(1, 20) / $arrMinerals2[$intKey]) * ($_POST['amount'] + $fltSum / 20)) - $arrMinerals2[$intKey]); 
263
264
        if ($intAmount < 1)
265
        {
266
            $intAmount = 1;
267
        }
268
        $intAbility = $_POST['amount'] / 10;
269
        $gainexp = $_POST['amount']*ceil($player -> level / 3);
270
        if ($intAmount > $objMines -> fields[$_GET['mine']])
271
        {
272
            $intAmount = $objMines -> fields[$_GET['mine']];
273
        }
274
        $db -> Execute("UPDATE mines SET ".$_GET['mine']."=".$_GET['mine']."-".$intAmount." WHERE owner=".$player -> id);
275
        $db -> Execute("UPDATE players SET `energy`=`energy`-".$_POST['amount'].", bless='', `blessval`=0 WHERE `id`=".$player -> id);
276
        checkexp ($player -> exp, $gainexp, $player -> level, $player -> race, $player -> user, $player -> id, 0, 0, $player -> id, 'mining', $intAbility); 
277
        $objTest = $db -> Execute("SELECT `owner` FROM `minerals` WHERE `owner`=".$player -> id);
278
        $arrOre = array('copperore', 'zincore', 'tinore', 'ironore', 'coal');
279
        if (!$objTest -> fields['owner'])
280
        {
281
            $db -> Execute("INSERT INTO `minerals` (`owner`, `".$arrOre[$intKey]."`) VALUES(".$player -> id.", ".$intAmount.")");
282
        }
283
          else
284
        {
285
            $db -> Execute("UPDATE minerals SET ".$arrOre[$intKey]."=".$arrOre[$intKey]."+".$intAmount." WHERE owner=".$player -> id);
286
        }
287
        $objTest -> Close();
288
        $smarty -> assign("Message", YOU_DIG.$_POST['amount'].M_ENERGY.YOU_GET.$intAmount.T_AMOUNT.$arrMinerals[$intKey].T_ABILITY.$intAbility.T_ABILITY2.$gainexp.T_GAIN_EXP);
289
    }
290
}
291
292
/**
293
* Free memory
294
*/
295
if ($objMines -> fields['owner'])
296
{
297
    $objMines -> Close();
298
}
299
300
/**
301
* Initialization of variables
302
*/
303
if (!isset($_GET['mine']))
304
{
305
    $_GET['mine'] = '';
306
}
307
if (!isset($_GET['step']))
308
{
309
    $_GET['step'] = '';
310
}
311
312
/**
313
* Assign variables to template and display page
314
*/
315
$smarty -> assign(array("Mine" => $_GET['mine'],
316
    "Step" => $_GET['step'],
317
    "Aback" => A_BACK));
318
$smarty -> display ('mines.tpl');
319
320
require_once("includes/foot.php");
321
?>