1
<?php
2
/**
3
 *   File functions:
4
 *   Mines in moutains
5
 *
6
 *   @name                 : kopalnia.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               : Zamareth <zamareth@users.sourceforge.net>
10
 *   @version              : 1.3
11
 *   @since                : 19.09.2007
12
 *
13
 */
14
15
//
16
//
17
//       This program is free software; you can redistribute it and/or modify
18
//   it under the terms of the GNU General Public License as published by
19
//   the Free Software Foundation; either version 2 of the License, or
20
//   (at your option) any later version.
21
//
22
//   This program is distributed in the hope that it will be useful,
23
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
24
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
//   GNU General Public License for more details.
26
//
27
//   You should have received a copy of the GNU General Public License
28
//   along with this program; if not, write to the Free Software
29
//   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
30
//
31
// $Id: kopalnia.php 760 2006-10-24 12:09:02Z thindil $
32
33
$title = 'Kopalnia';
34
require_once('includes/head.php');
35
require_once('includes/checkexp.php');
36
37
38
/**
39
* Get the localization for game
40
*/
41
require_once('languages/'.$player -> lang.'/kopalnia.php');
42
43
if ($player -> location != 'Góry')
44
{
45
    error(ERROR);
46
}
47
48
/**
49
 * Dig for minerals
50
 */
51
if (isset($_GET['action']) && $_GET['action'] == 'dig')
52
{
53
    if (!isset($_POST['amount']) || !preg_match("/^[1-9][0-9]*$/", $_POST['amount']))
54
    {
55
        error(ERROR);
56
    }
57
    integercheck($_POST['amount']);
58
    if ($player -> hp < 1)
59
    {
60
        error(YOU_DEAD." (<a href=\"gory.php\">".BACK."</a>)");
61
    }
62
    if ($player -> energy < $_POST['amount'])
63
    {
64
        error(NO_ENERGY." (<a href=\"gory.php\">".BACK."</a>)");
65
    }
66
67
    /**
68
     * Count bonus to ability
69
     */
70
    require_once('includes/abilitybonus.php');
71
    $fltAbility = abilitybonus('mining');
72
73
    $fltGainAbility = 0;
74
    $arrMinerals = array(0, 0);
75
    $arrGold = array(0, 0);
76
    $strInfo = '';
77
    $intGainExp = 0;
78
    $intLostHPSum = 0;
79
    
80
    for ($i = 0; $i < $_POST['amount']; $i++)
81
    {
82
        $intRoll = rand(1, 10);
83
        if ($intRoll > 4 && $intRoll < 10)
84
        {
85
            $fltGainAbility += 0.1;
86
        }
87
        if ($intRoll == 5)
88
        {
89
            $intAmount = max(1, ceil((rand(1, 20) * 1 / 8) * (1 + ($fltAbility + $fltGainAbility) / 20)));
90
            $intGainExp += ceil($player -> level / 3);
91
            $arrMinerals[0] += $intAmount; // crystal
92
        }
93
        if ($intRoll == 6)
94
        {
95
            $intAmount = max(1, ceil((rand(1, 20) * 1 / 5) * (1 + ($fltAbility  + $fltGainAbility) / 20)));
96
            $intGainExp += ceil($player -> level / 3);
97
            $arrMinerals[1] += $intAmount; // adamantium
98
        }
99
        if ($intRoll == 7 || $intRoll == 8)
100
        {
101
            $intAmount = max(1, ceil((rand(1, 20) * 1 / 3) * (1 + ($fltAbility + $fltGainAbility) / 20)));
102
            $intGainExp += ceil($player -> level / 3);
103
            $arrGold[1] += $intAmount; // platinum
104
        }
105
        if ($intRoll == 9)
106
        {
107
            $intAmount = max(1, ceil(rand(50, 200) * (1 + ($fltAbility + $fltGainAbility) / 20)));
108
            $arrGold[0] += $intAmount; // gold
109
        }
110
        if ($intRoll == 10)
111
        {
112
            $intLostHP = rand(1, 100);
113
            if ($intLostHP < 51)
114
            {
115
                $intLostHPSum += $intLostHP;
116
            }
117
            if ($intLostHPSum > $player -> hp - 1)
118
            {
119
				$intLostHPSum = min($intLostHPSum, $player -> hp);
120
                $strInfo = '<br />'.DEAD_MAN.'. (<a href="gory.php">'.BACK.'</a>)';
121
                break;
122
            }
123
        }
124
        if ($intLostHPSum > 0 )
125
        {
126
        $strInfo = M_LOST_HP1.$intLostHPSum.M_LOST_HP2;
127
        }
128
    }
129
	$oldFetchMode = $db -> SetFetchMode(ADODB_FETCH_NUM);
130
	$arrBless = $db -> GetRow('SELECT `bless`, `blessval` FROM `players` WHERE `id`='.$player -> id);
131
	if (isset($arrBless) && $arrBless[0] == 'hp' && $intLostHPSum < $arrBless[1])
132
	{
133
		$intLostHPSum = $arrBless[1];
134
	}
135
    $intMinSum = array_sum($arrMinerals);
136
    $intGoldSum = array_sum($arrGold);
137
    if ($intMinSum)
138
    {
139
        $arrMinCheck = $db -> GetRow('SELECT `adamantium`, `crystal`, `owner` FROM `minerals` WHERE `owner`='.$player -> id);
140
        $db -> SetFetchMode($oldFetchMode);
141
		if (empty($arrMinCheck))
142
        {
143
            $db -> Execute('INSERT INTO `minerals` (`owner`, `crystal`, `adamantium`) VALUES('.$player -> id.', '.$arrMinerals[0].', '.$arrMinerals[1].')');
144
        }
145
        else
146
        {
147
            $db -> Execute('UPDATE `minerals` SET `crystal`=`crystal`+'.$arrMinerals[0].', `adamantium`=`adamantium`+'.$arrMinerals[1].' WHERE `owner`='.$player -> id);
148
        }
149
    }
150
    $strFind = YOU_GO.$i.T_AMOUNT2;
151
    if ($intGoldSum || $intMinSum)
152
    {
153
        $strFind = $strFind.YOU_FIND;
154
        if ($arrMinerals[0])
155
        {
156
            $strFind .= $arrMinerals[0].T_CRYSTALS;
157
        }
158
        if ($arrMinerals[1])
159
        {
160
            $strFind .= $arrMinerals[1].T_ADAMANTIUM;
161
        }
162
        if ($arrGold[1])
163
        {
164
            $strFind .= $arrGold[1].T_MITHRIL;
165
        }
166
        if ($arrGold[0])
167
        {
168
            $strFind .= T_GOLD.$arrGold[0].T_GOLD2;
169
        }
170
        $strFind .= $fltGainAbility.T_ABILITY.$intGainExp.T_GAIN_EXP;
171
    }
172
    if (!$fltGainAbility && $strInfo == '')
173
    {
174
        $strFind .= T_NOTHING;
175
    }
176
    $strFind .= $strInfo;
177
	$strBless = isset($arrBless) && $arrBless[0] == 'hp' ? ', `bless`=\'\', `blessval`=0' : '';
178
    $db -> Execute('UPDATE `players` SET `credits`=`credits`+'.$arrGold[0].', `platinum`=`platinum`+'.$arrGold[1].', `hp`=`hp`-'.$intLostHPSum.$strBless.', `energy`=`energy`-'.$i.' WHERE `id`='.$player -> id);
179
    $smarty -> assign('Youfind', $strFind);
180
    checkexp ($player -> exp, $intGainExp, $player -> level, $player -> race, $player -> user, $player -> id, 0, 0, $player -> id, 'mining', $fltGainAbility);
181
182
}
183
184
/**
185
* Initialization of variables
186
*/
187
if (!isset($_GET['action']))
188
{
189
    $_GET['action'] = '';
190
}
191
192
/**
193
* Assign variables to template and display page
194
*/
195
$smarty -> assign('Health', isset($intLostHPSum) ? $player -> hp - $intLostHPSum : $player -> hp);
196
$smarty -> display ('kopalnia.tpl');
197
198
require_once('includes/foot.php');
199
?>