1
<?php
2
/**
3
 *   File functions:
4
 *   Armory shop - buying armors, legs, helmets and shields
5
 *
6
 *   @name                 : armor.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: armor.php 566 2006-09-13 09:31:08Z thindil $
31
32
$title = "Płatnerz"; 
33
require_once("includes/head.php");
34
35
/**
36
* Get the localization for game
37
*/
38
require_once("languages/".$player -> lang."/armor.php");
39
40
/*if ($player -> location != 'Ardulith') 
41
{
42
    error (ERROR);
43
}
44
*/
45
if (!isset($_GET['buy'])) 
46
{
47
    if (isset($_GET['dalej'])) 
48
    {
49
        /**
50
        * Show aviable armors
51
        */
52
        if ($_GET['dalej'] != 'A' && $_GET['dalej'] != 'H' && $_GET['dalej'] != 'L' && $_GET['dalej'] != 'S') 
53
        {
54
            error (ERROR);
55
        }
56
        $arrname = array();
57
        $arrcost = array();
58
        $arrlevel = array();
59
        $arrid = array();
60
        $arrdur = array();
61
        $arrpower = array();
62
        $arragility = array();
63
        $i = 0;
64
        $arm = $db -> Execute("SELECT * FROM equipment WHERE type='".$_GET['dalej']."' AND status='S' AND owner=0 AND lang='".$player -> lang."' ORDER BY cost ASC");
65
while (!$arm -> EOF) 
66
        {
67
            $arrname[$i] = $arm -> fields['name'];
68
            $arrcost[$i] = $arm -> fields['cost'];
69
            $arrlevel[$i] = $arm -> fields['minlev'];
70
            $arrid[$i] = $arm -> fields['id'];
71
            $arrdur[$i] = $arm -> fields['wt'];
72
            $arrpower[$i] = $arm -> fields['power'];
73
            $arragility[$i] = $arm -> fields['zr'];
74
            $i = $i + 1;
75
            $arm -> MoveNext();
76
        }
77
        $arm -> Close();
78
        $smarty -> assign(array("Name" => $arrname, 
79
            "Cost" => $arrcost, 
80
            "Level" => $arrlevel, 
81
            "Id" => $arrid, 
82
            "Durability" => $arrdur, 
83
            "Power" => $arrpower, 
84
            "Agility" => $arragility,
85
            "Iname" => I_NAME,
86
            "Idur" => I_DUR,
87
            "Iefect" => I_EFECT,
88
            "Icost" => I_COST,
89
            "Ilevel" => I_LEVEL,
90
            "Iagi" => I_AGI,
91
            "Ioption" => I_OPTION,
92
            "Abuy" => A_BUY,
93
            "Asteal" => A_STEAL));
94
    }
95
}
96
97
/**
98
* Buy items
99
*/
100
if (isset($_GET['buy'])) 
101
{
102
    if (!ereg("^[1-9][0-9]*$", $_GET['buy'])) 
103
    {
104
        error (ERROR);
105
    }
106
    $arm = $db -> Execute("SELECT * FROM equipment WHERE id=".$_GET['buy']);
107
   if ($arm -> fields['id'] == 0) 
108
    {
109
        error (NO_ITEM);
110
    }
111
    if ($arm -> fields['status'] != 'S') 
112
    {
113
        error (BAD_STATUS);
114
    }
115
    if ($arm -> fields['cost'] > $player -> credits) 
116
    {
117
        error (NO_MONEY);
118
    }
119
    $newcost = ceil($arm -> fields['cost'] * .75);
120
    $test = $db -> Execute("SELECT id FROM equipment WHERE name='".$arm -> fields['name']."' AND wt=".$arm -> fields['wt']." AND type='".$arm -> fields['type']."' 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=0 AND cost=".$newcost);
121
    if ($test -> fields['id'] == 0) 
122
    {
123
        $db -> Execute("INSERT INTO equipment (owner, name, power, type, cost, zr, wt, minlev, maxwt, amount, magic, szyb, lang, 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['szyb'].",'".$player -> lang."', ".$arm -> fields['repair'].")") or error("nie mogę dodać!");
124
    } 
125
        else 
126
    {
127
        $db -> Execute("UPDATE equipment SET amount=amount+1 WHERE id=".$test -> fields['id']);
128
    }
129
    $test -> Close();
130
    $db -> Execute("UPDATE players SET credits=credits-".$arm -> fields['cost']." WHERE id=".$player -> id);
131
    $smarty -> assign (array ("Name" => $arm -> fields['name'], 
132
        "Cost" => $arm -> fields['cost'], 
133
        "Power" => $arm -> fields['power'],
134
        "Youpay" => YOU_PAY,
135
        "Andbuy" => AND_BUY,
136
        "Ipower" => I_POWER));
137
    $arm -> Close();
138
}
139
140
/**
141
* Stealing items from shop
142
*/
143
if (isset ($_GET['steal'])) 
144
{
145
    require_once("includes/steal.php");
146
    require_once("includes/checkexp.php");
147
    steal($_GET['steal']);
148
}
149
if ($player -> clas != 'Złodziej') 
150
{
151
    $player -> crime = 0;
152
}
153
154
/**
155
* Initialization of variables and assign variables to template
156
*/
157
if (!isset($_GET['buy'])) 
158
{
159
    $_GET['buy'] = '';
160
    $smarty -> assign(array("Armorinfo" => ARMOR_INFO,
161
        "Aarmors" => A_ARMORS,
162
        "Ahelmets" => A_HELMETS,
163
        "Alegs" => A_LEGS,
164
        "Ashields" => A_SHIELDS));
165
}
166
if (!isset($_GET['dalej'])) 
167
{
168
    $_GET['dalej'] = '';
169
}
170
171
/**
172
* Assign variables and display page
173
*/
174
$smarty -> assign(array("Buy" => $_GET['buy'], 
175
    "Next" => $_GET['dalej'], 
176
    "Crime" => $player -> crime));
177
$smarty -> display ('armor.tpl');
178
179
require_once("includes/foot.php");
180
?>