Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.44 KB | None | 0 0
  1. <?php
  2.  
  3. class Weapons
  4. {
  5.  
  6.   function __construct()
  7.   {
  8.  
  9.   }
  10.  
  11.   public function getWeapon ($id)
  12.   {
  13.     global $go;
  14.  
  15.     $stmt = $go -> prepare('SELECT * FROM `weapons` WHERE `id` = ?');
  16.     $stmt -> execute([$id]);
  17.     $weapon = $stmt -> fetch();
  18.  
  19.     if (!isset($weapon['id'])) return false;
  20.     else
  21.     {
  22.       $out = [
  23.         'id' => $weapon['id'], // ID
  24.         'name' => $weapon['name'], // Название
  25.         'about' => $weapon['about'], // Описание
  26.         'slot' => $weapon['slot'], // Слот
  27.         'quality' => $weapon['quality'], // Качество
  28.         'how' => $weapon['how'], // Как можно получить
  29.         'price' => $weapon['price'], // Цена в магазине, если how = shop,
  30.         'amount' => $weapon['amount'],
  31.         'lvl' => $weapon['lvl'] // С какого лвл можно одеть вещь (для баланса)
  32.       ];
  33.  
  34.       $stmt = $go -> prepare('SELECT `id` FROM `weapons_stats` WHERE `id_weapon` = ?');
  35.       $stmt -> execute([$id]);
  36.       $stats['count'] = $stmt -> rowCount();
  37.  
  38.       if ($stats['count'] > 0)
  39.       {
  40.         $stmt = $go -> prepare('SELECT * FROM `weapons_stats` WHERE `id_weapon` = ?');
  41.         $stmt -> execute([$id]);
  42.         $stats['query'] = $stmt -> fetchAll();
  43.  
  44.         $i = 0;
  45.         foreach ($stats['query'] as $wp)
  46.         {
  47.           $i++;
  48.           $out['stats'][$i] = ['atrb' => $wp['atrb'], 'bonus' => $wp['bonus']];
  49.         }
  50.       }
  51.       return $out;
  52.     }
  53.   }
  54.  
  55.   public function getEquip ($id)
  56.   {
  57.     global $go;
  58.  
  59.     $stmt = $go -> prepare('SELECT `weapons_users`.`id_weapon`, `weapons`.`slot`, `weapons`.`id` FROM `weapons_users` AS `weapons_users` JOIN `weapons` AS `weapons` ON (`weapons_users`.`id_weapon` = `weapons`.`id`) WHERE `weapons_users`.`id_user` = ? and `weapons_users`.`used` = ?');
  60.     $stmt -> execute([$id, '1']);
  61.     $used = $stmt -> fetchAll();
  62.     $count = $stmt -> rowCount();
  63.  
  64.     if ($count == 0) return 0;
  65.     else
  66.     {
  67.       foreach ($used as $object)
  68.       {
  69.         $slot[] = $object['id_weapon'];
  70.       }
  71.       return $slot;
  72.     }
  73.   }
  74.  
  75.   public function ladder ($id)
  76.   {
  77.     global $go;
  78.     if (empty($id)) return 0;
  79.     else
  80.     {
  81.       $stmt = $go -> prepare('SELECT `id`, `power`, `dash`, `defense` FROM `users` WHERE `id` = ?');
  82.       $stmt -> execute([$id]);
  83.       $ladder = $stmt -> fetch();
  84.  
  85.       $array = [
  86.         'id' => $id,
  87.         'power' => $ladder['power'],
  88.         'dash' => $ladder['dash'],
  89.         'defense' => $ladder['defense']
  90.       ];
  91.       return $array;
  92.     }
  93.   }
  94.  
  95.   public function getAtrb ($id, $type)
  96.   {
  97.     global $go;
  98.  
  99.     $stmt = $go -> prepare('SELECT `id`, `power`, `dash`, `defense` FROM `users` WHERE `id` = ?');
  100.     $stmt -> execute([$id]);
  101.     $fetch = $stmt -> fetch();
  102.  
  103.     $t = ['boot' => 25, 'hand' => 20, 'head' => 40, 'knife' => 95, 'pistol' => 150, 'gun' => 330, 'power' => $fetch['power'], 'dash' => $fetch['dash'], 'defense' => $fetch['defense']];
  104.     $damage = $t[$type]; // Стандартный урон
  105.  
  106.     if (array_key_exists($type, $t) == FALSE) return 0;
  107.     else
  108.     {
  109.       // Подгружаем вещи игрока
  110.       $stmt = $go -> prepare('SELECT `weapons_stats`.`bonus` FROM `weapons_users` JOIN `weapons_stats` ON (`weapons_users`.`id_weapon` = `weapons_stats`.`id_weapon`) WHERE `weapons_users`.`id_user` = ? and `weapons_users`.`used` = ? and `weapons_stats`.`atrb` = ?');
  111.       $stmt -> execute([$id, '1', $type]);
  112.       $count = $stmt -> rowCount();
  113.       $wp = $stmt -> fetchAll();
  114.  
  115.       if ($count > 0)
  116.       {
  117.         foreach ($wp as $weapon)
  118.         {
  119.           $damage += $weapon['bonus'];
  120.         }
  121.       }
  122.       if ($type == 'dash' and $damage > 100) $damage = 100;
  123.       return $damage;
  124.     }
  125.   }
  126.  
  127.   public function getLadderDamage ($id, $enemy)
  128.   {
  129.     // Рассчет урона.
  130.     $power = $this -> getAtrb($id, 'power');
  131.     $defense = $this -> getAtrb($enemy, 'defense');
  132.     $random = mt_rand(85, 100)/100;
  133.  
  134.     $step[1] = (2 + 10) / 250;
  135.     $step[2] = $power / $defense;
  136.  
  137.     $damage['normal'] = floor(($step[1] * $step[2] * ($power * 2) + 2) * 1 * $random);
  138.     $damage['crit'] = floor(($step[1] * $step[2] * ($power * 2) + 2) * 1.5 * $random);
  139.     $damage['min'] = floor(($step[1] * $step[2] * ($power * 2) + 2) * 1 * 0.85);
  140.     $damage['max'] = floor(($step[1] * $step[2] * ($power * 2) + 2) * 1.5 * 1);
  141.     return $damage;
  142.   }
  143.  
  144.   /**
  145.   * Экипировка игрока
  146.   * @var numeric $id ID предмета
  147.   * @var numiric $user ID пользователя
  148.   */
  149.   public function equipWeapons ($id, $user)
  150.   {
  151.     global $go;
  152.  
  153.     $stmt = $go -> prepare('SELECT `weapons_users`.`id`, `weapons_users`.`used`, `weapons`.`slot`, `weapons_users`.`id_weapon`, `weapons_users`.`id_user`, `weapons`.`lvl`, `u`.`level` FROM `weapons_users` AS `weapons_users` JOIN `weapons` AS `weapons` ON (`weapons_users`.`id_weapon` = `weapons`.`id`) JOIN `users` AS `u` ON (`weapons_users`.`id_user` = `u`.`id`) WHERE `weapons_users`.`id` = ? and `weapons_users`.`id_user` = ?');
  154.     $stmt -> execute([$id, $user]);
  155.     $gun = $stmt -> fetch();
  156.  
  157.     if ($gun == FALSE) $re['error'] = 'У вас нет такого предмета в инвентаре.';
  158.     elseif ($gun['lvl'] > $gun['level']) $re['error'] = 'Минимальный уровень вещи выше вашего уровня.';
  159.     else
  160.     {
  161.       if ($gun['used'] == 1) // Если предмет одет.
  162.       {
  163.         $stmt = $go -> prepare('SELECT `weapons_users`.`id` FROM `weapons_users` AS `weapons_users` JOIN `weapons` AS `weapons` ON (`weapons_users`.`id_weapon` = `weapons`.`id`) WHERE `weapons_users`.`id_user` = ? and `weapons_users`.`used` = ? and `weapons`.`slot` = ? and `weapons_users`.`id` != ?');
  164.         $stmt -> execute([$user, '1', $gun['slot'], $gun['id']]);
  165.         $count = $stmt -> rowCount();
  166.         $used = $stmt -> fetchAll();
  167.  
  168.         if ($count > 0)
  169.         {
  170.           foreach ($used as $clear)
  171.           {
  172.             $stmt = $go -> prepare('SELECT `weapons_stats`.`atrb`, `weapons_stats`.`bonus`, `weapons_users`.`id_user` FROM `weapons_users` AS `weapons_users` JOIN `weapons_stats` AS `weapons_stats` ON (`weapons_users`.`id_weapon` = `weapons_stats`.`id_weapon`) WHERE `weapons_users`.`id` = ? and (`weapons_stats`.`atrb` = ? or `weapons_stats`.`atrb` = ?)');
  173.             $stmt -> execute([$clear['id'], 'hp', 'energy']);
  174.             $atrb = $stmt -> fetchAll();
  175.             if ($atrb != FALSE)
  176.             {
  177.               foreach ($atrb as $bn)
  178.               {
  179.                 if ($bn['atrb'] == 'energy')
  180.                 {
  181.                   $stmt = $go -> prepare('UPDATE `users` SET `max_energy` = `max_energy` - ? WHERE `id` = ?');
  182.                   $stmt -> execute([$bn['bonus'], $bn['id_user']]);
  183.                 }
  184.                 elseif ($bn['atrb'] == 'hp')
  185.                 {
  186.                   $stmt = $go -> prepare('UPDATE `users` SET `max_hp` = `max_hp` - ? WHERE `id` = ?');
  187.                   $stmt -> execute([$bn['bonus'], $bn['id_user']]);
  188.                 }
  189.               }
  190.             }
  191.             $stmt = $go -> prepare('UPDATE `weapons_users` SET `used` = ? WHERE `id` = ?');
  192.             $stmt -> execute(['0', $clear['id']]);
  193.             $re['success'] = 'Предмет успешно снят с персонажа.';
  194.           }
  195.         }
  196.         elseif ($count == 0)
  197.         {
  198.           $stmt = $go -> prepare('SELECT `weapons_stats`.`atrb`, `weapons_stats`.`bonus`, `weapons_users`.`id_user` FROM `weapons_users` AS `weapons_users` JOIN `weapons_stats` AS `weapons_stats` ON (`weapons_users`.`id_weapon` = `weapons_stats`.`id_weapon`) WHERE `weapons_users`.`id` = ? and (`weapons_stats`.`atrb` = ? or `weapons_stats`.`atrb` = ?)');
  199.           $stmt -> execute([$gun['id'], 'hp', 'energy']);
  200.           $atrb = $stmt -> fetchAll();
  201.           if ($atrb != FALSE)
  202.           {
  203.             foreach ($atrb as $bn)
  204.             {
  205.               if ($bn['atrb'] == 'energy')
  206.               {
  207.                 $stmt = $go -> prepare('UPDATE `users` SET `max_energy` = `max_energy` - ? WHERE `id` = ?');
  208.                 $stmt -> execute([$bn['bonus'], $bn['id_user']]);
  209.               }
  210.               elseif ($bn['atrb'] == 'hp')
  211.               {
  212.                 $stmt = $go -> prepare('UPDATE `users` SET `max_hp` = `max_hp` - ? WHERE `id` = ?');
  213.                 $stmt -> execute([$bn['bonus'], $bn['id_user']]);
  214.               }
  215.             }
  216.           }
  217.           $stmt = $go -> prepare('UPDATE `weapons_users` SET `used` = ? WHERE `id` = ?');
  218.           $stmt -> execute(['0', $gun['id']]);
  219.           $re['success'] = 'Предмет успешно снят с персонажа.';
  220.         }
  221.         else $re['error'] = 'Код ошибки: #2, сообщите это администратору.';
  222.       }
  223.       elseif ($gun['used'] == 0) // Если предмет не одет
  224.       {
  225.         $stmt = $go -> prepare('SELECT `weapons_users`.`id` FROM `weapons_users` AS `weapons_users` JOIN `weapons` AS `weapons` ON (`weapons_users`.`id_weapon` = `weapons`.`id`) WHERE `weapons_users`.`id_user` = ? and `weapons_users`.`used` = ? and `weapons`.`slot` = ?');
  226.         $stmt -> execute([$user, '1', $gun['slot']]);
  227.         $count = $stmt -> rowCount();
  228.         $used = $stmt -> fetchAll();
  229.  
  230.         if ($count > 0)
  231.         {
  232.           foreach ($used as $clear)
  233.           {
  234.             $stmt = $go -> prepare('SELECT `weapons_stats`.`atrb`, `weapons_stats`.`bonus`, `weapons_users`.`id_user` FROM `weapons_users` AS `weapons_users` JOIN `weapons_stats` AS `weapons_stats` ON (`weapons_users`.`id_weapon` = `weapons_stats`.`id_weapon`) WHERE `weapons_users`.`id` = ? and (`weapons_stats`.`atrb` = ? or `weapons_stats`.`atrb` = ?)');
  235.             $stmt -> execute([$clear['id'], 'hp', 'energy']);
  236.             $atrb = $stmt -> fetchAll();
  237.             if ($atrb != FALSE)
  238.             {
  239.               foreach ($atrb as $bn)
  240.               {
  241.                 if ($bn['atrb'] == 'energy')
  242.                 {
  243.                   $stmt = $go -> prepare('UPDATE `users` SET `max_energy` = `max_energy` + ? WHERE `id` = ?');
  244.                   $stmt -> execute([$bn['bonus'], $bn['id_user']]);
  245.                 }
  246.                 elseif ($bn['atrb'] == 'hp')
  247.                 {
  248.                   $stmt = $go -> prepare('UPDATE `users` SET `max_hp` = `max_hp` + ? WHERE `id` = ?');
  249.                   $stmt -> execute([$bn['bonus'], $bn['id_user']]);
  250.                 }
  251.               }
  252.             }
  253.             $stmt = $go -> prepare('UPDATE `weapons_users` SET `used` = ? WHERE `id` = ?');
  254.             $stmt -> execute(['0', $clear['id']]);
  255.             $re['success'] = 'Предмет успешно одет на персонажа.';
  256.           }
  257.           $stmt = $go -> prepare('UPDATE `weapons_users` SET `used` = ? WHERE `id` = ?');
  258.           $stmt -> execute(['1', $gun['id']]);
  259.         }
  260.         elseif ($count == 0)
  261.         {
  262.           $stmt = $go -> prepare('SELECT `weapons_stats`.`atrb`, `weapons_stats`.`bonus`, `weapons_users`.`id_user` FROM `weapons_users` AS `weapons_users` JOIN `weapons_stats` AS `weapons_stats` ON (`weapons_users`.`id_weapon` = `weapons_stats`.`id_weapon`) WHERE `weapons_users`.`id` = ? and (`weapons_stats`.`atrb` = ? or `weapons_stats`.`atrb` = ?)');
  263.           $stmt -> execute([$gun['id'], 'hp', 'energy']);
  264.           $atrb = $stmt -> fetchAll();
  265.           if ($atrb != FALSE)
  266.           {
  267.             foreach ($atrb as $bn)
  268.             {
  269.               if ($bn['atrb'] == 'energy')
  270.               {
  271.                 $stmt = $go -> prepare('UPDATE `users` SET `max_energy` = `max_energy` + ? WHERE `id` = ?');
  272.                 $stmt -> execute([$bn['bonus'], $bn['id_user']]);
  273.               }
  274.               elseif ($bn['atrb'] == 'hp')
  275.               {
  276.                 $stmt = $go -> prepare('UPDATE `users` SET `max_hp` = `max_hp` + ? WHERE `id` = ?');
  277.                 $stmt -> execute([$bn['bonus'], $bn['id_user']]);
  278.               }
  279.             }
  280.           }
  281.           $stmt = $go -> prepare('UPDATE `weapons_users` SET `used` = ? WHERE `id` = ?');
  282.           $stmt -> execute(['1', $gun['id']]);
  283.           $re['success'] = 'Предмет успешно одет на персонажа.';
  284.         }
  285.         else $re['error'] = 'Код ошибки: #3, сообщите это администратору.';
  286.       }
  287.       else $re['error'] = 'Код ошибки: #1, сообщите это администратору.';
  288.     }
  289.  
  290.     return $re;
  291.   }
  292. }
  293.  
  294. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement