1
<?php
2
/**
3
 *   File functions:
4
 *   Weapons shop
5
 *
6
 *   @name                 : weapons.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.1
10
 *   @since                : 08.03.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: weapons.php 566 2006-09-13 09:31:08Z thindil $
31
32
$title = "Zbrojmistrz";
33
require_once("includes/head.php");
34
35
/**
36
* Get the localization for game
37
*/
38
require_once("languages/".$player -> lang."/weapons.php");
39
40
if ($player -> location != 'Altara' && $player -> location != 'Ardulith')
41
{
42
    error (ERROR);
43
}
44
45
if (!isset ($_GET['buy'])) 
46
{
47
    $wep = $db -> Execute("SELECT * FROM equipment WHERE type='W' AND status='S' AND owner=0 ORDER BY cost ASC");
48
    $arrname = array();
49
    $arrpower = array();
50
    $arrspeed = array();
51
    $arrdur = array();
52
    $arrlevel = array();
53
    $arrcost = array();
54
    $arrid = array();
55
    $i = 0;
56
    while (!$wep -> EOF) 
57
    {
58
        $arrname[$i] = $wep -> fields['name'];
59
        $arrpower[$i] = $wep -> fields['power'];
60
        $arrspeed[$i] = $wep -> fields['szyb'];
61
        $arrdur[$i] = $wep -> fields['maxwt'];
62
        $arrlevel[$i] = $wep -> fields['minlev'];
63
        $arrcost[$i] = $wep -> fields['cost'];
64
        $arrid[$i] = $wep -> fields['id'];
65
        $wep -> MoveNext();
66
        $i = $i + 1;        
67
    }
68
    $wep -> Close();
69
    $smarty -> assign(array("Name" => $arrname, 
70
        "Power" => $arrpower, 
71
        "Speed" => $arrspeed, 
72
        "Durability" => $arrdur, 
73
        "Level" => $arrlevel, 
74
        "Cost" => $arrcost, 
75
        "Itemid" => $arrid,
76
        "Weaponinfo" => WEAPON_INFO,
77
        "Iname" => I_NAME,
78
        "Idur" => I_DUR,
79
        "Iefect" => I_EFECT,
80
        "Ispeed" => I_SPEED,
81
        "Icost" => I_COST,
82
        "Ioption" => I_OPTION,
83
        "Abuy" => A_BUY,
84
        "Asteal" => A_STEAL,
85
        "Ilevel" => I_LEVEL));
86
}
87
88
if (isset ($_GET['buy'])) 
89
{
90
    if (!ereg("^[1-9][0-9]*$", $_GET['buy'])) 
91
    {
92
        error (ERROR);
93
    }
94
    $arm = $db -> Execute("SELECT * FROM equipment WHERE id=".$_GET['buy']);
95
    if (!$arm -> fields['id']) 
96
    {
97
        error (NO_ITEM);
98
    }
99
    if ($arm -> fields['status'] != 'S') 
100
    {
101
        error (BAD_STATUS);
102
    }
103
    if ($arm -> fields['cost'] > $player -> credits) 
104
    {
105
        error (NO_MONEY);
106
    }
107
    $newcost = ceil($arm -> fields['cost'] * .75);
108
    $test = $db -> Execute("SELECT id FROM equipment WHERE name='".$arm -> fields['name']."' AND wt=".$arm -> fields['wt']." AND type='W' AND status='U' AND owner=".$player -> id." AND power=".$arm -> fields['power']." AND zr=".$arm -> fields['zr']." AND szyb=".$arm -> fields['szyb']." AND maxwt=".$arm -> fields['maxwt']." AND poison=".$arm -> fields['poison']." AND cost=".$newcost);
109
    if (!$test -> fields['id']) 
110
    {
111
        $db -> Execute("INSERT INTO equipment (owner, name, power, type, cost, zr, wt, minlev, maxwt, amount, magic, poison, szyb, twohand, repair) VALUES(".$player -> id.",'".$arm -> fields['name']."',".$arm -> fields['power'].",'".$arm -> fields['type']."',".$newcost.",".$arm -> fields['zr'].",".$arm -> fields['wt'].",".$arm -> fields['minlev'].",".$arm -> fields['maxwt'].",1,'".$arm -> fields['magic']."',".$arm -> fields['poison'].",".$arm -> fields['szyb'].",'".$arm -> fields['twohand']."', ".$arm -> fields['repair'].")");
112
    } 
113
        else 
114
    {
115
        $db -> Execute("UPDATE equipment SET amount=amount+1 WHERE id=".$test -> fields['id']);
116
    }
117
    $test -> Close();
118
    $smarty -> assign(array("Name" => $arm -> fields['name'], 
119
        "Power" => $arm -> fields['power'], 
120
        "Cost" => $arm -> fields['cost'],
121
        "Youpay" => YOU_PAY,
122
        "Andbuy" => AND_BUY,
123
        "Topower" => TO_POWER)); 
124
    $db -> Execute("UPDATE players SET credits=credits-".$arm -> fields['cost']." WHERE id=".$player -> id);
125
    $arm -> Close();
126
}
127
128
if (isset ($_GET['steal'])) 
129
{
130
    require_once("includes/steal.php");
131
    require_once("includes/checkexp.php");
132
    steal($_GET['steal']);
133
}
134
135
if ($player -> clas != 'Złodziej') 
136
{
137
    $player -> crime = 0;
138
}
139
140
/**
141
* Initialization of variable
142
*/
143
if (!isset($_GET['buy'])) 
144
{
145
    $_GET['buy'] = '';
146
}
147
148
/**
149
* Assign variables to template and display page
150
*/
151
$smarty -> assign(array("Buy" => $_GET['buy'], 
152
    "Crime" => $player -> crime));
153
$smarty -> display('weapons.tpl');
154
155
require_once("includes/foot.php");
156
?>