1
<?php
2
/**
3
 *   File functions:
4
 *   Jeweller - make rings
5
 *
6
 *   @name                 : jeweller.php
7
 *   @copyright            : (C) 2006 Vallheru Team based on Gamers-Fusion ver 2.5
8
 *   @author               : thindil <thindil@users.sourceforge.net>
9
 *   @version              : 1.3
10
 *   @since                : 16.11.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
//
31
32
$title = 'Warsztat jubilerski';
33
require_once('includes/head.php');
34
require_once('includes/checkexp.php');
35
require_once('includes/artisan.php');
36
37
/**
38
* Get the localization for game
39
*/
40
require_once('languages/'.$player -> lang.'/jeweller.php');
41
42
if ($player -> location != 'Ardulith')
43
{
44
    error(ERROR);
45
}
46
47
/**
48
 * Main menu
49
 */
50
if (!isset($_GET['step']))
51
{
52
    $_GET['step'] = '';
53
    $smarty -> assign(array('Jewellerinfo' => JEWELLER_INFO,
54
                            'Aplans' => A_PLANS,
55
                            'Aring' => A_RING,
56
                            'Amakering' => A_MAKE_RING,
57
                            'Amakering2' => A_MAKE_RING2,
58
                            'Playerclass' => $player -> clas,
59
                            'Aastral' => A_ASTRAL));
60
}
61
    else
62
{
63
    $smarty -> assign(array('Aback' => A_BACK,
64
                            'Message' => ''));
65
}
66
67
/**
68
 * Buy plans
69
 */
70
if (isset ($_GET['step']) && $_GET['step'] == 'plans')
71
{
72
    if (!isset($_GET['buy']))
73
    {
74
        showplans ('jeweller', 0, $player -> clas);
75
    }
76
    else
77
    {
78
        buyplan('jeweller', $_GET['buy'], $player -> id, $player -> credits, $player -> clas);
79
    }
80
}
81
82
/**
83
 * Make simple rings
84
 */
85
if (isset($_GET['step']) && $_GET['step'] == 'make')
86
{
87
    $objPlan = $db -> Execute('SELECT `id` FROM `jeweller` WHERE `name`=\''.RING.'\' AND `owner`='.$player -> id);
88
    if (!$objPlan -> fields['id'])
89
    {
90
        error(NO_PLAN);
91
    }
92
    $objPlan -> Close();
93
    $smarty -> assign(array('Ringinfo' => RING_INFO,
94
                            'Amake' => A_MAKE,
95
                            'Ramount' => R_AMOUNT));
96
    if (isset($_GET['make']) && $_GET['make'] == 'Y')
97
    {
98
        if (!ereg("^[1-9][0-9]*$", $_POST['amount']))
99
        {
100
            error(ERROR);
101
        }
102
        if ($player -> hp == 0)
103
        {
104
            error(YOU_DEAD);
105
        }
106
        $objAdamantium = $db -> Execute('SELECT `adamantium` FROM `minerals` WHERE `owner`='.$player -> id);
107
        if ($objAdamantium -> fields['adamantium'] < $_POST['amount'])
108
        {
109
            error(NO_ADAMANTIUM);
110
        }
111
        $objAdamantium -> Close();
112
        if ($player -> energy < $_POST['amount'])
113
        {
114
            error(NO_ENERGY);
115
        }
116
117
        /**
118
         * Add bonuses to ability
119
         */
120
        require_once('includes/abilitybonus.php');
121
        $intJeweller = abilitybonus('jeweller');
122
123
        $intChance = $intJeweller * 100;
124
        if ($intChance > 95)
125
        {
126
            $intChance = 95;
127
        }
128
        $intAmount = 0;
129
        for ($i = 0; $i < $_POST['amount']; $i++)
130
        {
131
            $intRoll = rand(1, 100);
132
            if ($intRoll < $intChance)
133
            {
134
                $intAmount ++;
135
            }
136
        }
137
        $intAbility = ($intAmount + $_POST['amount']) * 0.005 ;
138
        $intGainexp = $intAmount;
139
        if ($player -> clas == ARTISAN)
140
        {
141
            $intAbility = $intAbility * 2;
142
            $intGainexp = $intGainexp * 2;
143
        }
144
        $intAbility = round($intAbility*100, 0)/100;
145
        $intAbility = $intAbility ? $intAbility : 0.01; 
146
        checkexp($player -> exp, $intGainexp, $player -> level, $player -> race, $player -> user, $player -> id, 0, 0, $player -> id, 'jeweller', $intAbility);
147
        if ($intAmount)
148
        {
149
            $objTest = $db -> Execute('SELECT `id` FROM `equipment` WHERE `owner`='.$player -> id.' AND `name`=\''.RING.'\' AND `status`=\'U\'');
150
            if (!$objTest -> fields['id'])
151
            {
152
                $db -> Execute('INSERT INTO `equipment` (`owner`, `name`, `power`, `type`, `cost`, `minlev`, `amount`) VALUES('.$player -> id.', \''.RING.'\', 0, \'I\', 3, 1, '.$intAmount.')');
153
            }
154
                else
155
            {
156
                $db -> Execute('UPDATE `equipment` SET `amount`=`amount`+'.$intAmount.' WHERE `id`='.$objTest -> fields['id']);
157
            }
158
            $objTest -> Close();
159
        }
160
        $db -> Execute('UPDATE `players` SET `energy`=`energy`-'.$_POST['amount'].' WHERE `id`='.$player -> id);
161
        $db -> Execute('UPDATE `minerals` SET `adamantium`=`adamantium`-'.$_POST['amount'].' WHERE `owner`='.$player -> id);
162
        $smarty -> assign('Message', YOU_MAKE.$intAmount.'</b> '.R_AMOUNT.YOU_GAIN3.$intGainexp.T_PD.$intAbility.T_ABILITY);
163
    }
164
}
165
166
/**
167
 * Make rings with bonus to stats
168
 */
169
if (isset($_GET['step']) && $_GET['step'] == 'make2')
170
{
171
    if ($player -> clas != ARTISAN)
172
    {
173
        error(WRONG_CLASS);
174
    }
175
176
    /**
177
     * Make rings menu
178
     */
179
    if (!isset($_GET['action']))
180
    {
181
        $objMaked = $db -> Execute('SELECT `id`, `name`, `n_energy`, `u_energy` FROM `jeweller_work` WHERE `owner`='.$player -> id.' AND `type`=\'N\'');
182
        if (!$objMaked -> fields['id'])
183
        {
184
            $objPlans = $db -> Execute('SELECT `id`, `name`, `level`, `bonus` FROM `jeweller` WHERE `owner`='.$player -> id.' AND `name`!=\''.RING.'\' ORDER BY `level`');
185
            if (!$objPlans -> fields['name'])
186
            {
187
                error(NO_PLANS);
188
            }
189
            $arrId = array();
190
            $arrName = array();
191
            $arrLevel = array();
192
            $arrAdam = array();
193
            $arrCryst = array();
194
            $arrMeteor = array();
195
            $arrEnergy = array();
196
            $arrChange = array();
197
            $arrBonus = array();
198
            $i = 0;
199
            while (!$objPlans -> EOF)
200
            {
201
                $arrId[$i] = $objPlans -> fields['id'];
202
                $arrName[$i] = $objPlans -> fields['name'];
203
                $arrLevel[$i] = $objPlans -> fields['level'];
204
                $arrAdam[$i] = $objPlans -> fields['level'];
205
                $arrCryst[$i] = ceil($objPlans -> fields['level'] / 2);
206
                $arrMeteor[$i] = ceil($objPlans -> fields['level'] / 4);
207
                $arrBonus[$i] = $objPlans -> fields['bonus'];
208
                $arrEnergy[$i] = $objPlans -> fields['level'] * 2;
209
                $intChange = $objPlans -> fields['level'] * 4;
210
                if ($player -> jeweller >= $intChange)
211
                {
212
                    $arrChange[$i] = YES;
213
                }
214
                    else
215
                {
216
                    $arrChange[$i] = NO;
217
                }
218
                $i++;
219
                $objPlans -> MoveNext();
220
            }
221
            $objPlans -> Close();
222
            $smarty -> assign(array('Ringinfo' => RING_INFO,
223
                                    'Tname' => T_NAME,
224
                                    'Tlevel' => T_LEVEL,
225
                                    'Tadam' => T_ADAM,
226
                                    'Tcryst' => T_CRYST,
227
                                    'Tmeteor' => T_METEOR,
228
                                    'Tenergy' => T_ENERGY,
229
                                    'Tbonus' => T_BONUS,
230
                                    'Tchange' => T_CHANGE,
231
                                    'Rname' => $arrName,
232
                                    'Rlevel' => $arrLevel,
233
                                    'Radam' => $arrAdam,
234
                                    'Rcryst' => $arrCryst,
235
                                    'Rmeteor' => $arrMeteor,
236
                                    'Renergy' => $arrEnergy,
237
                                    'Rbonus' => $arrBonus,
238
                                    'Rid' => $arrId,
239
                                    'Rchange' => $arrChange,
240
                                    'Action' => '',
241
                                    'Make' => '',
242
                                    'Maked' => ''));
243
244
            /**
245
             * Select make ring
246
             */
247
            if (isset($_GET['make']))
248
            {
249
                if (!ereg("^[1-9][0-9]*$", $_GET['make']))
250
                {
251
                    error(ERROR);
252
                }
253
                if ($player -> hp == 0)
254
                {
255
                  error(YOU_DEAD);
256
                }
257
                if ($objMaked -> fields['id'])
258
                {
259
                    error(ERROR);
260
                }
261
                $intKey = array_search($_GET['make'], $arrId);
262
                $arrBonus = array(R_AGI, R_STR, R_INT, R_WIS, R_SPE, R_CON);
263
                if ($arrChange[$intKey] == YES)
264
                {
265
                    $strChange = 'Y';
266
                }
267
                    else
268
                {
269
                    $strChange = 'N';
270
                }
271
                $smarty -> assign(array('Make' => $_GET['make'],
272
                                        'Rname2' => $arrName[$intKey],
273
                                        'Rbonus2' => $arrBonus,
274
                                        'Pjeweller' => $player -> jeweller,
275
                                        'Change' => $strChange,
276
                                        'Youmake' => YOU_MAKE,
277
                                        'Ramount' => R_AMOUNT2,
278
                                        'Withbon' => WITH_BON,
279
                                        'Tenergy3' => R_ENERGY));
280
            }
281
        }
282
            else
283
        {
284
            $smarty -> assign(array('Ringinfo' => RING_INFO,
285
                                    'Tname' => T_NAME,
286
                                    'Tenergy' => T_ENERGY,
287
                                    'Tenergy2' => T_ENERGY2,
288
                                    'Youcontinue' => YOU_CONTINUE,
289
                                    'Tenergy3' => R_ENERGY,
290
                                    'Ramount' => R_AMOUNT2,
291
                                    'Rname' => $objMaked -> fields['name'],
292
                                    'Renergy' => $objMaked -> fields['n_energy'],
293
                                    'Renergy2' => $objMaked -> fields['u_energy'],
294
                                    'Action' => '',
295
                                    'Make' => '',
296
                                    'Maked' => $objMaked -> fields['id']));
297
        }
298
        $objMaked -> Close();
299
    }
300
301
    /**
302
     * Continue create rings
303
     */
304
    if (isset($_GET['action']) && $_GET['action'] == 'continue')
305
    {
306
        if (!ereg("^[1-9][0-9]*$", $_POST['make']) || !ereg("^[1-9][0-9]*$", $_POST['amount']))
307
        {
308
            error(ERROR);
309
        }
310
        if ($player -> hp == 0)
311
        {
312
            error(YOU_DEAD);
313
        }
314
        $objRing = $db -> Execute('SELECT `owner`, `name`, `n_energy`, `u_energy`, `bonus` FROM `jeweller_work` WHERE `id`='.$_POST['make']);
315
        if (!$objRing -> fields['owner'] || $objRing -> fields['owner'] != $player -> id)
316
        {
317
            error(NO_WORK);
318
        }
319
        $intEnergy = $_POST['amount'] + $objRing -> fields['u_energy'];
320
        if ($intEnergy > $objRing -> fields['n_energy'])
321
        {
322
            error(TOO_MUCH);
323
        }
324
325
        /**
326
         * When player assign need energy
327
         */
328
        if ($intEnergy == $objRing -> fields['n_energy'])
329
        {
330
            /**
331
             * Add bonuses to ability
332
             */
333
            require_once('includes/abilitybonus.php');
334
            $intJeweller = abilitybonus('jeweller');
335
336
            $objRing2 = $db -> Execute('SELECT `level`, `bonus`, `cost`, `type` FROM `jeweller` WHERE `owner`='.$player -> id.' AND `name`=\''.$objRing -> fields['name'].'\'');
337
338
            $intChance = ($intJeweller / $objRing2 -> fields['level']) * 50;
339
            if ($intChance > 95)
340
            {
341
                $intChance = 95;
342
            }
343
344
            $intGainexp = 0;
345
346
            $arrStats = array(R_AGI, R_STR, R_INT, R_WIS, R_SPE, R_CON);
347
            $arrStats2 = array('agility', 'strength', 'inteli', 'wisdom', 'speed', 'cond');
348
            $intKey = array_search($objRing -> fields['bonus'], $arrStats);
349
            $intStat = $player -> $arrStats2[$intKey];
350
351
            $intRoll = rand(1, 100);
352
353
            /**
354
             * Success
355
             */
356
            if ($intRoll <= $intChance)
357
            {
358
	            echo (floor($intJeweller/2))." - ".$intJeweller." ";
359
                echo $intBonus = rand(floor($intJeweller/2), $intJeweller);
360
                if ($intBonus < 1)
361
                {
362
                    $intBonus = 1;
363
                }
364
                if ($intBonus > $objRing2 -> fields['bonus'])
365
                {
366
                    $intBonus = $objRing2 -> fields['bonus'];
367
                }
368
                $intBonus += floor($intStat / 50);
369
                $strName = $objRing -> fields['name']." ".$objRing -> fields['bonus'];
370
                $intCost = ceil($objRing2 -> fields['cost'] / 200);
371
                $objTest = $db -> Execute('SELECT `id` FROM `equipment` WHERE `owner`='.$player -> id.' AND status=\'U\' AND `name`=\''.$strName.'\' AND `power`='.$intBonus.' AND `cost`='.$intCost);
372
                if (!$objTest -> fields['id'])
373
                {
374
                    $db -> Execute('INSERT INTO `equipment` (`owner`, `name`, `power`, `status`, `type`, `cost`, `minlev`, `amount`) VALUES('.$player -> id.', \''.$strName.'\', '.$intBonus.', \'U\', \''.$objRing2 -> fields['type'].'\', '.$intCost.', '.$objRing2 -> fields['level'].', 1)');
375
                }
376
                    else
377
                {
378
                    $db -> Execute('UPDATE `equipment` SET `amount`=`amount`+1 WHERE `id`='.$objTest -> fields['id']);
379
                }
380
                $objTest -> Close();
381
                $intGainexp = $objRing2 -> fields['level'] * 200;
382
                $intAbility = ($objRing -> fields['n_energy'] * 0.02);
383
                $smarty -> assign('Message', YOU_MAKE.$strName.YOU_GAIN3.$intGainexp.AND_EXP2.$intAbility.IN_JEWELLER);
384
            }
385
                else
386
            {
387
                $intAbility = ($objRing -> fields['n_energy'] * 0.01);
388
                $intGainexp = 0;
389
                $smarty -> assign('Message', YOU_TRY.$objRing -> fields['name'].BUT_FAIL.$intAbility.IN_JEWELLER);
390
            }
391
            $objRing2 -> Close();
392
            $db -> Execute('DELETE FROM `jeweller_work` WHERE `id`='.$_POST['make']);
393
            checkexp($player -> exp, $intGainexp, $player -> level, $player -> race, $player -> user, $player -> id, 0, 0, $player -> id, 'jeweller', $intAbility);
394
        }
395
            else
396
        {
397
            $db -> Execute('UPDATE `jeweller_work` SET `u_energy`='.$intEnergy.' WHERE `id`='.$_POST['make']);
398
            $smarty -> assign('Message', YOU_TRY.$objRing -> fields['name'].YOU_GAIN4);
399
        }
400
        $objRing -> Close();
401
        $db -> Execute('UPDATE `players` SET `energy`=`energy`-'.$_POST['amount'].' WHERE `id`='.$player -> id);
402
        $smarty -> assign('Action', $_GET['action']);
403
    }
404
405
    /**
406
     * Start create rings
407
     */
408
    if (isset($_GET['action']) && $_GET['action'] == 'create')
409
    {
410
        if (!ereg("^[1-9][0-9]*$", $_POST['make']) || !ereg("^[1-9][0-9]*$", $_POST['amount']))
411
        {
412
            error(ERROR);
413
        }
414
        $objRing = $db -> Execute('SELECT `owner`, `name`, `level`, `bonus`, `cost`, `type` FROM `jeweller` WHERE `id`='.$_POST['make']);
415
        if (!$objRing -> fields['owner'] || $objRing -> fields['owner'] != $player -> id)
416
        {
417
            error(NO_PLAN);
418
        }
419
        $intMake = floor($_POST['amount'] / ($objRing -> fields['level'] * 2));
420
421
        $intNeed = ($intMake < 1) ? 1 : $intMake;
422
        $intAdam = $objRing -> fields['level'] * $intNeed;
423
        $intCryst = ceil($objRing -> fields['level'] / 2) * $intNeed;
424
        $intMeteor = ceil($objRing -> fields['level'] / 4) * $intNeed;
425
        $objMinerals = $db -> Execute('SELECT `adamantium`, `crystal`, `meteor` FROM `minerals` WHERE `owner`='.$player -> id);
426
        if ($objMinerals -> fields['adamantium'] < $intAdam || $objMinerals -> fields['crystal'] < $intCryst || $objMinerals -> fields['meteor'] < $intMeteor)
427
        {
428
            error(NO_MINERALS);
429
        }
430
        $objMinerals -> Close();
431
        if ($player -> energy < $_POST['amount'])
432
        {
433
            error(NO_ENERGY);
434
        }
435
        $objRings = $db -> Execute('SELECT `id`, `amount` FROM `equipment` WHERE `owner`='.$player -> id.' AND `name`=\''.RING.'\' AND `status`=\'U\'');
436
        if ($objRings -> fields['amount'] < $intMake)
437
        {
438
            error(NO_RINGS);
439
        }
440
441
        /**
442
         * Add bonuses to ability
443
         */
444
        require_once('includes/abilitybonus.php');
445
        $intJeweller = abilitybonus('jeweller');
446
447
        $intChance = ($intJeweller / $objRing -> fields['level']) * 50;
448
        if ($intChance > 95)
449
        {
450
            $intChance = 95;
451
        }
452
453
        /**
454
         * Which stats have bonus
455
         */
456
        $intChange = $objRing -> fields['level'] * 4;
457
        $arrStats = array(R_AGI, R_STR, R_INT, R_WIS, R_SPE, R_CON);
458
        $arrStats2 = array('agility', 'strength', 'inteli', 'wisdom', 'speed', 'cond');
459
        if (isset($_POST['bonus']) && $player -> jeweller >= $intChange)
460
        {
461
            $strStat = $_POST['bonus'];
462
            $intKey = array_search($_POST['bonus'], $arrStats);
463
            $intStat = $player -> $arrStats2[$intKey];
464
        }
465
            else
466
        {
467
            $intRoll = rand(0, 5);
468
            $strStat = $arrStats[$intRoll];
469
            $intStat = $player -> $arrStats2[$intRoll];
470
        }
471
472
        /**
473
         * Start create items
474
         */
475
        $arrBonus = array();
476
        $arrAmount = array();
477
        $intAmount2 = 0;
478
        for ($i = 0; $i < $intMake; $i++)
479
        {
480
            $intRoll = rand(1, 100);
481
            if ($intRoll <= $intChance)
482
            {
483
                $intAmount2++;
484
                echo (floor($intJeweller/2))." - ".$intJeweller." ";
485
                echo $intBonus = rand(floor($intJeweller/2), $intJeweller);
486
                if ($intBonus < 1)
487
                {
488
                    $intBonus = 1;
489
                }
490
                if ($intBonus > $objRing -> fields['bonus'])
491
                {
492
                    $intBonus = $objRing -> fields['bonus'];
493
                }
494
                $intBonus += floor($intStat / 50);
495
                $intKey = array_search($intBonus, $arrBonus);
496
                if (!empty($intKey) || $intKey === 0)
497
                {
498
                    $arrAmount[$intKey]++;
499
                }
500
                    else
501
                {
502
                    $arrBonus[] = $intBonus;
503
                    $arrAmount[] = 1;
504
                }
505
            }
506
        }
507
508
        /**
509
         * Write to database and show info
510
         */
511
        $intAbility = 0;
512
        if ($intMake > 0)
513
        {
514
            $i = 0;
515
            $strName = $objRing -> fields['name']." ".$strStat;
516
            $intCost = ceil($objRing -> fields['cost'] / 200);
517
            foreach ($arrAmount as $intAmount)
518
            {
519
                $objTest = $db -> Execute('SELECT `id` FROM `equipment` WHERE `owner`='.$player -> id.' AND status=\'U\' AND `name`=\''.$strName.'\' AND `power`='.$arrBonus[$i].' AND `cost`='.$intCost);
520
                if (!$objTest -> fields['id'])
521
                {
522
                    $db -> Execute('INSERT INTO `equipment` (`owner`, `name`, `power`, `status`, `type`, `cost`, `minlev`, `amount`) VALUES('.$player -> id.', \''.$strName.'\', '.$arrBonus[$i].', \'U\', \''.$objRing -> fields['type'].'\', '.$intCost.', '.$objRing -> fields['level'].', '.$intAmount.')');
523
                }
524
                    else
525
                {
526
                    $db -> Execute('UPDATE `equipment` SET `amount`=`amount`+'.$intAmount.' WHERE `id`='.$objTest -> fields['id']);
527
                }
528
                $objTest -> Close();
529
                $i ++;
530
            }
531
            $intGainexp = $objRing -> fields['level'] * 200;
532
            $intGainexp = floor($intGainexp * $intAmount2);
533
            $intAbility = 0.02 * $objRing -> fields['level'] * ($intAmount2 + $intMake);
534
            $smarty -> assign('Message', YOU_MAKE.$intAmount2.'</b> '.R_AMOUNT.$strName.YOU_GAIN3.$intGainexp.AND_EXP2.$intAbility.IN_JEWELLER);
535
        }
536
            else
537
        {
538
            $intAdam = $objRing -> fields['level'];
539
            $intCryst = ceil($objRing -> fields['level'] / 2);
540
            $intMeteor = ceil($objRing -> fields['level'] / 4);
541
            $intGainexp = 0;
542
            $intEnergy2 = ($objRing -> fields['level'] * 2);
543
            $intAbility = 0;
544
            $intEnergy = $_POST['amount'];
545
            $intMake = 1;
546
            $db -> Execute('INSERT INTO `jeweller_work` (`owner`, `name`, `n_energy`, `u_energy`, `bonus`, `type`) VALUES('.$player -> id.', \''.$objRing -> fields['name'].'\', '.$intEnergy2.', '.$_POST['amount'].', \''.$strStat.'\', \'N\')');
547
            $smarty -> assign('Message', YOU_TRY.$objRing -> fields['name'].YOU_GAIN4);
548
        }
549
        checkexp($player -> exp, $intGainexp, $player -> level, $player -> race, $player -> user, $player -> id, 0, 0, $player -> id, 'jeweller', $intAbility);
550
        $db -> Execute('UPDATE `minerals` SET `adamantium`=`adamantium`-'.$intAdam.', `crystal`=`crystal`-'.$intCryst.', `meteor`=`meteor`-'.$intMeteor.' WHERE `owner`='.$player -> id);
551
        $db -> Execute('UPDATE `players` SET `energy`=`energy`-'.$_POST['amount'].' WHERE `id`='.$player -> id);
552
        if ($objRings -> fields['amount'] == $intMake)
553
        {
554
            $db -> Execute('DELETE FROM `equipment` WHERE `id`='.$objRings -> fields['id']);
555
        }
556
            else
557
        {
558
            $db -> Execute('UPDATE `equipment` SET `amount`=`amount`-'.$intMake.' WHERE `id`='.$objRings -> fields['id']);
559
        }
560
        $objRings -> Close();
561
        $smarty -> assign('Action', $_GET['action']);
562
    }
563
}
564
565
/**
566
 * Make special rings with bonus to stats
567
 */
568
if (isset($_GET['step']) && $_GET['step'] == 'make3')
569
{
570
    if ($player -> clas != ARTISAN)
571
    {
572
        error(WRONG_CLASS);
573
    }
574
575
    /**
576
     * Main menu
577
     */
578
    $objMaked = $db -> Execute('SELECT `id`, `name`, `n_energy`, `u_energy` FROM `jeweller_work` WHERE `owner`='.$player -> id.' AND `type`=\'S\'');
579
    if (!$objMaked -> fields['id'])
580
    {
581
        $objPlans = $db -> Execute('SELECT `name`, `level` FROM `jeweller` WHERE `owner`='.$player -> id.' AND `name`!=\''.RING.'\' ORDER BY `level`');
582
        if (!$objPlans -> fields['name'])
583
        {
584
            error(NO_PLANS);
585
        }
586
        $arrName = array();
587
        $arrLevel = array();
588
        $arrMeteor = array();
589
        $arrEnergy = array();
590
        $i = 0;
591
        while (!$objPlans -> EOF)
592
        {
593
            $arrName[$i] = $objPlans -> fields['name'];
594
            $arrLevel[$i] = $objPlans -> fields['level'];
595
            $arrMeteor[$i] = ceil($objPlans -> fields['level'] / 2);
596
            $arrEnergy[$i] = $objPlans -> fields['level'] * 1.5;
597
            $i++;
598
            $objPlans -> MoveNext();
599
        }
600
        $objPlans -> Close();
601
        $objRings = $db -> Execute('SELECT `id`, `name`, `amount`, `minlev`, `power`, `cost` FROM `equipment` WHERE `owner`='.$player -> id.' AND `status`=\'U\' AND `type`=\'I\' AND `name`!=\''.RING.'\' AND `name` NOT LIKE \''.R_GNOME.'%\' AND `name` NOT LIKE \''.R_ELF.'%\' AND `name` NOT LIKE \''.R_DWARF.'%\' AND `name` NOT LIKE \''.R_GOD.'%\'');
602
        $arrRid = array();
603
        $arrRname = array();
604
        $arrRamount = array();
605
        $arrRpower = array();
606
        $arrRlevel = array();
607
        $arrRcost = array();
608
        $i = 0;
609
        while (!$objRings -> EOF)
610
        {
611
            $arrRid[$i] = $objRings -> fields['id'];
612
            $arrRname[$i] = $objRings -> fields['name'];
613
            $arrRamount[$i] = $objRings -> fields['amount'];
614
            $arrRpower[$i] = $objRings -> fields['power'];
615
            $arrRlevel[$i] = $objRings -> fields['minlev'];
616
            $arrRcost[$i] = $objRings -> fields['cost'];
617
            $i++;
618
            $objRings -> MoveNext();
619
        }
620
        $objRings -> Close();
621
622
        $smarty -> assign(array('Ringinfo' => RING_INFO,
623
                                'Tname' => T_NAME,
624
                                'Tlevel' => T_LEVEL,
625
                                'Tmeteor' => T_METEOR,
626
                                'Tenergy' => T_ENERGY,
627
                                'Amake' => A_MAKE,
628
                                'Ramount' => R_AMOUNT,
629
                                'Onspecial' => ON_SPECIAL,
630
                                'Ramount3' => R_AMOUNT2,
631
                                'Ramount4' => R_AMOUNT4,
632
                                'Renergy2' => R_ENERGY,
633
                                'Maked' => '',
634
                                'Rname' => $arrName,
635
                                'Rlevel' => $arrLevel,
636
                                'Rmeteor' => $arrMeteor,
637
                                'Renergy' => $arrEnergy,
638
                                'Rid2' => $arrRid,
639
                                'Rname2' => $arrRname,
640
                                'Ramount2' => $arrRamount,
641
                                'Rpower' => $arrRpower));
642
    }
643
        else
644
    {
645
        $smarty -> assign(array('Ringinfo' => RING_INFO,
646
                                'Tname' => T_NAME,
647
                                'Tenergy' => T_ENERGY,
648
                                'Tenergy2' => T_ENERGY2,
649
                                'Youcontinue' => YOU_CONTINUE,
650
                                'Tenergy3' => R_ENERGY,
651
                                'Ramount' => R_AMOUNT2,
652
                                'Rname' => $objMaked -> fields['name'],
653
                                'Renergy' => $objMaked -> fields['n_energy'],
654
                                'Renergy2' => $objMaked -> fields['u_energy'],
655
                                'Action' => '',
656
                                'Make' => '',
657
                                'Maked' => $objMaked -> fields['id']));
658
    }
659
660
    /**
661
     * Continue create special rings
662
     */
663
    if (isset($_GET['action']) && $_GET['action'] == 'continue')
664
    {
665
        if (!ereg("^[1-9][0-9]*$", $_POST['make']) || !ereg("^[0-9][0-9\.]*$", $_POST['amount']))
666
        {
667
            error(ERROR);
668
        }
669
        if ($player -> hp == 0)
670
        {
671
            error(YOU_DEAD);
672
        }
673
        $objRing = $db -> Execute('SELECT `owner`, `name`, `n_energy`, `u_energy`, `bonus` FROM `jeweller_work` WHERE `id`='.$_POST['make']);
674
        if (!$objRing -> fields['owner'] || $objRing -> fields['owner'] != $player -> id)
675
        {
676
            error(NO_WORK);
677
        }
678
        $intEnergy = $_POST['amount'] + $objRing -> fields['u_energy'];
679
        if ($intEnergy > $objRing -> fields['n_energy'])
680
        {
681
            error(TOO_MUCH);
682
        }
683
684
        /**
685
         * When player assign need energy
686
         */
687
        if ($intEnergy == $objRing -> fields['n_energy'])
688
        {
689
            /**
690
             * Add bonuses to ability
691
             */
692
            require_once('includes/abilitybonus.php');
693
            $intJeweller = abilitybonus('jeweller');
694
695
            /**
696
             * Select ring name
697
             */
698
            $arrRings = array(R_AGI, R_SPE, R_STR, R_CON, R_INT, R_WIS);
699
            $arrPrefix = array(R_ELF, R_DWARF, R_GNOME);
700
            $strName = $objRing -> fields['name'];
701
            $arrRingtype = explode(" ", $strName);
702
            $intAmount2 = count($arrRingtype) - 1;
703
            $intKey2 = array_search($arrRingtype[$intAmount2], $arrRings);
704
            $intName = $intAmount2 - ( ($intKey2 < 5) ? 1 : 2 );
705
            $strName2 = '';
706
            for ($i = 0; $i <= $intName; $i++)
707
            {
708
                if (!empty($strName2))
709
                {
710
                  $strName2 = $strName2." ";
711
                }
712
                $strName2 = $strName2.$arrRingtype[$i];
713
            }
714
            $intKey2 = floor($intKey2 / 2);
715
            $strPrefix = $arrPrefix[$intKey2];
716
717
            $objRing2 = $db -> Execute('SELECT `level`, `cost`, `type` FROM `jeweller` WHERE `owner`='.$player -> id.' AND `name`=\''.$strName2.'\'');
718
719
            $intChance = floor(($intJeweller / 50) * 0.5) + 5;
720
            if ($intChance > 15)
721
            {
722
                $intChance = 15;
723
            }
724
725
            $intGainexp = 0;
726
727
            $intRoll = rand(1, 100);
728
729
            /**
730
             * Success
731
             */
732
            if ($intRoll <= $intChance)
733
            {
734
                $blnGod = false;
735
                $intRoll = rand(1, 100);
736
                if ($intRoll == 1)
737
                {
738
                    $intRoll2 = rand(1, 2);
739
                    if ($intRoll2 == 1)
740
                    {
741
                        $intGainexp =  $objRing -> fields['n_energy'] * 500;
742
                        $intAbility =  $objRing -> fields['n_energy'] * 0.28;
743
                        $blnGod = true;
744
                    }
745
                }
746
                if ($intRoll <= $intChance && !$blnGod)
747
                {
748
                    $intGainexp = $objRing -> fields['n_energy'] * 250;
749
                    $intAbility = $objRing -> fields['n_energy'] * 0.14;
750
                }
751
752
                $intPower = (int)$objRing -> fields['bonus'];
753
                $intCost = ceil($objRing2 -> fields['cost'] / 10);
754
                $intAbility = $objRing -> fields['n_energy'] * 0.02;
755
                if ($blnGod)
756
                {
757
                    $strName2 = R_GOD.$strName;
758
                    $intPower = $intPower * 4;
759
                    $objTest = $db -> Execute('SELECT `id` FROM `equipment` WHERE `owner`='.$player -> id.' AND `name`=\''.$strName2.'\' AND `status`=\'U\' AND `cost`='.$intCost.' AND `power`='.$intPower);
760
                    if (!$objTest -> fields['id'])
761
                    {
762
                        $db -> Execute('INSERT INTO `equipment` (`owner`, `name`, `power`, `status`, `type`, `cost`, `minlev`, `amount`) VALUES('.$player -> id.', \''.$strName2.'\', \''.$intPower.'\', \'U\', \'I\', '.$intCost.', '.$intLevel.', '.$intGod.')');
763
                    }
764
                        else
765
                    {
766
                        $db -> Execute('UPDATE `equipment` SET `amount`=`amount`+'.$intGod.' WHERE `id`='.$player -> id);
767
                    }
768
                    $objTest -> Close();
769
                }
770
                    else
771
                {
772
                    $strName2 = $strPrefix.$strName;
773
                    $intPower = $intPower * 2;
774
                    $objTest = $db -> Execute('SELECT `id` FROM `equipment` WHERE `owner`='.$player -> id.' AND `name`=\''.$strName2.'\' AND `status`=\'U\' AND `cost`='.$intCost.' AND `power`='.$intPower);
775
                    if (!$objTest -> fields['id'])
776
                    {
777
                        $db -> Execute('INSERT INTO `equipment` (`owner`, `name`, `power`, `status`, `type`, `cost`, `minlev`, `amount`) VALUES('.$player -> id.', \''.$strName2.'\', '.$intPower.', \'U\', \'I\', \''.$intCost.', '.$intLevel.', 1)');
778
                    }
779
                    else
780
                    {
781
                        $db -> Execute('UPDATE `equipment` SET `amount`=`amount`+'.$intSpecial.' WHERE `id`='.$player -> id);
782
                    }
783
                    $objTest -> Close();
784
                }
785
                $smarty -> assign('Message', YOU_MAKE.$strName.YOU_GAIN3.$intGainexp.AND_EXP2.$intAbility.IN_JEWELLER);
786
            }
787
                else
788
            {
789
                $intAbility = $objRing -> fields['n_energy'] * 0.01;
790
                $smarty -> assign('Message', YOU_TRY.$strName.BUT_FAIL.$intAbility.IN_JEWELLER);
791
            }
792
            checkexp($player -> exp, $intGainexp, $player -> level, $player -> race, $player -> user, $player -> id, 0, 0, $player -> id, 'jeweller', $intAbility);
793
            $objRing2 -> Close();
794
            $db -> Execute('DELETE FROM `jeweller_work` WHERE `id`='.$_POST['make']);
795
        }
796
            else
797
        {
798
            $db -> Execute('UPDATE `jeweller_work` SET `u_energy`='.$intEnergy.' WHERE `id`='.$_POST['make']);
799
            $smarty -> assign('Message', YOU_TRY.$objRing -> fields['name'].YOU_GAIN4);
800
        }
801
        $objRing -> Close();
802
        $db -> Execute('UPDATE `players` SET `energy`=`energy`-'.$_POST['amount'].' WHERE `id`='.$player -> id);
803
    }
804
805
    /**
806
     * Start create special rings
807
     */
808
    if (isset($_GET['action']) && $_GET['action'] == 'create')
809
    {
810
        if (!isset($_POST['rings']) || !ereg("^[1-9][0-9]*$", $_POST['rings']) || !ereg("^[0-9][0-9\.]*$", $_POST['amount']))
811
        {
812
            error(ERROR);
813
        }
814
        if ($objMaked -> fields['id'])
815
        {
816
            error(ERROR);
817
        }
818
        if ($player -> hp == 0)
819
        {
820
            error(YOU_DEAD);
821
        }
822
        $intKey = array_search($_POST['rings'], $arrRid);
823
        $intLevel = $arrRlevel[$intKey];
824
        $intMake = floor($_POST['amount'] / ($intLevel * 1.5));
825
        if (!$intMake)
826
        {
827
            $intMake = 1;
828
        }
829
        $intMeteor = ceil($intLevel / 2) * $intMake;
830
        $objMeteor = $db -> Execute('SELECT `meteor` FROM `minerals` WHERE `owner`='.$player -> id);
831
        if ($objMeteor -> fields['meteor'] < $intMeteor)
832
        {
833
            error(NO_METEOR);
834
        }
835
        $objMeteor -> Close();
836
        $intEnergys = $intLevel * 1.5;
837
        $intEnergy = $intEnergys * $intMake;
838
        if ($player -> energy < $intEnergy)
839
        {
840
            error(NO_ENERGY);
841
        }
842
        $intRamount = $arrRamount[$intKey];
843
        if ($intRamount < $intMake)
844
        {
845
            error(NO_RINGS);
846
        }
847
848
        /**
849
         * Select ring name
850
         */
851
        $arrRings = array(R_AGI, R_SPE, R_STR, R_CON, R_INT, R_WIS);
852
        $arrPrefix = array(R_ELF, R_DWARF, R_GNOME);
853
        $strName = $arrRname[$intKey];
854
        $arrRingtype = explode(" ", $strName);
855
        $intAmount2 = count($arrRingtype) - 1;
856
        $intKey2 = array_search($arrRingtype[$intAmount2], $arrRings);
857
        $intKey2 = floor($intKey2 / 2);
858
        $strPrefix = $arrPrefix[$intKey2];
859
860
        /**
861
         * Add bonuses to ability
862
         */
863
        require_once('includes/abilitybonus.php');
864
        $intJeweller = abilitybonus('jeweller');
865
866
        $intChance = floor(($intJeweller / 50) * 0.5) + 5;
867
        if ($intChance > 15)
868
        {
869
            $intChance = 15;
870
        }
871
872
        /**
873
         * Start create item
874
         */
875
        $intGod = 0;
876
        $intSpecial = 0;
877
        $intGainexp = 0;
878
        $intAbility = 0;
879
        for ($i = 0; $i < $intMake; $i++)
880
        {
881
            $intRoll = rand(1, 100);
882
            if ($intRoll == 1)
883
            {
884
                $intRoll2 = rand(1, 2);
885
                if ($intRoll2 == 1)
886
                {
887
                    $intGod ++;
888
                    $intGainexp = $intGainexp + ($intEnergys * 500);
889
                    $intAbility = $intAbility + ($intEnergys * 0.28);
890
                    continue;
891
                }
892
            }
893
            if ($intRoll <= $intChance)
894
            {
895
                $intSpecial ++;
896
                $intGainexp = $intGainexp + ($intEnergys * 250);
897
                $intAbility = $intAbility + ($intEnergys * 0.14);
898
            }
899
                else
900
            {
901
                $intAbility = $intAbility + 0.01 * $intEnergys;
902
            }
903
        }
904
		$intAbility = round($intAbility, 2);
905
        /**
906
         * Write to database and show info
907
         */
908
        if ($intMake)
909
        {
910
            $intCost = ceil($arrRcost[$intKey] / 10);
911
            $intPower = $arrRpower[$intKey];
912
            if ($intGod)
913
            {
914
                $strName2 = R_GOD.$strName;
915
                $intPower = $intPower * 4;
916
                $objTest = $db -> Execute('SELECT `id` FROM `equipment` WHERE `owner`='.$player -> id.' AND `name`=\''.$strName2.'\' AND `status`=\'U\' AND `cost`='.$intCost.' AND `power`='.$intPower);
917
                if (!$objTest -> fields['id'])
918
                {
919
                    $db -> Execute('INSERT INTO `equipment` (`owner`, `name`, `power`, `status`, `type`, `cost`, `minlev`, `amount`) VALUES('.$player -> id.', \''.$strName2.'\', '.$intPower.', \'U\', \'I\', '.$intCost.', '.$intLevel.', '.$intGod.')');
920
                }
921
                    else
922
                {
923
                    $db -> Execute('UPDATE `equipment` SET `amount`=`amount`+'.$intGod.' WHERE `id`='.$player -> id);
924
                }
925
                $objTest -> Close();
926
            }
927
            $intPower = $arrRpower[$intKey];
928
            if ($intSpecial)
929
            {
930
                $strName2 = $strPrefix.$strName;
931
                $intPower *= 2;
932
                $objTest = $db -> Execute("SELECT `id` FROM `equipment` WHERE `owner`=".$player -> id." AND `name`='".$strName2."' AND `status`='U' AND `cost`=".$intCost." AND `power`=".$intPower);
933
                if (!$objTest -> fields['id'])
934
                {
935
                    $db -> Execute("INSERT INTO `equipment` (`owner`, `name`, `power`, `status`, `type`, `cost`, `minlev`, `amount`) VALUES(".$player -> id.", '".$strName2."', '".$intPower."', 'U', 'I', '".$intCost."', '".$intLevel."', '".$intSpecial."')");
936
                }
937
                    else
938
                {
939
                  $db -> Execute("UPDATE `equipment` SET `amount`=`amount`+".$intSpecial." WHERE `id`=".$player -> id);
940
                }
941
                $objTest -> Close();
942
            }
943
            $intRings = $intGod + $intSpecial;
944
            $smarty -> assign('Message', '<br /><br />'.YOU_MAKE.$intRings.'</b> '.R_AMOUNT3.$strName.YOU_GAIN3.$intGainexp.AND_EXP2.$intAbility.IN_JEWELLER);
945
        }
946
           else
947
        {
948
            $intMeteor = ceil($intLevel / 2);
949
            $intGainexp = 0;
950
            $intEnergy2 = ($intLevel * 1.5);
951
            $intAbility = 0;
952
            $intEnergy = $_POST['amount'];
953
            $intMake = 1;
954
            $intPower = $arrRpower[$intKey];
955
            $db -> Execute('INSERT INTO `jeweller_work` (`owner`, `name`, `n_energy`, `u_energy`, `bonus`, `type`) VALUES('.$player -> id.', \''.$strName.'\', '.$intEnergy2.', '.$_POST['amount'].', '.$intPower.', \'S\')');
956
            $smarty -> assign('Message', YOU_TRY.$strName.YOU_GAIN4);
957
        }
958
        $db -> Execute('UPDATE `minerals` SET `meteor`=`meteor`-'.$intMeteor.' WHERE `owner`='.$player -> id);
959
        $db -> Execute('UPDATE `players` SET `energy`=`energy`-'.$intEnergy.' WHERE `id`='.$player -> id);
960
        checkexp($player -> exp, $intGainexp, $player -> level, $player -> race, $player -> user, $player -> id, 0, 0, $player -> id, 'jeweller', $intAbility);
961
        if ($intRamount == $intMake)
962
        {
963
            $db -> Execute('DELETE FROM `equipment` WHERE `id`='.$_POST['rings']);
964
        }
965
            else
966
        {
967
            $db -> Execute('UPDATE `equipment` SET `amount`=`amount`-'.$intMake.' WHERE `id`='.$_POST['rings']);
968
        }
969
    }
970
}
971
972
if (!isset($_GET['buy']))
973
{
974
    $_GET['buy'] = '';
975
}
976
977
/**
978
 * Make astral constructions
979
 */
980
if (isset($_GET['step']) && $_GET['step'] == 'astral')
981
{
982
    if( !isset($_GET['component'] ))
983
    {
984
        makeastral3();
985
    }
986
    else
987
    {
988
        makeastral3($_GET['component']);
989
    }
990
}
991
992
/**
993
* Assign variables to template and display page
994
*/
995
$smarty -> assign(array('Step' => $_GET['step'], 'Buy' => $_GET['buy']));
996
$smarty -> display('jeweller.tpl');
997
998
require_once('includes/foot.php');
999
?>