Guest User

game

a guest
Aug 18th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 40.80 KB | None | 0 0
  1. <?php
  2.  
  3. //Game by SickWebsites
  4.  
  5. class game  {
  6.    
  7.     public static function isLoggedIn() {
  8.        
  9.         if (empty($_SESSION['login']))  {
  10.             header('Location: login.php');
  11.         }
  12.        
  13.     }
  14.    
  15.     public static function resurrect($name, $conn)  {
  16.        
  17.         mysqli_query($conn, "UPDATE users SET health = '1', isdead = '0' WHERE username = '$name'");
  18.         globalfunc::redirect("game.php?page=main");
  19.        
  20.     }
  21.    
  22.     public static function isDead($name, $conn) {
  23.        
  24.         if (self::get("r", $name, "isdead", $conn)) {
  25.             return true;
  26.         } else {
  27.             return false;
  28.         }
  29.        
  30.     }
  31.    
  32.     public static function validateUser($username)  {
  33.        
  34.         $pattern = "/^[A-Za-z0-9]+$/";
  35.        
  36.         $result = preg_match($pattern, $username);
  37.        
  38.         if (!$result)   {
  39.             return false;
  40.         }
  41.        
  42.         return true;
  43.        
  44.     }
  45.    
  46.     public static function validateEmail($email)    {
  47.        
  48.         $result = filter_var($email, FILTER_VALIDATE_EMAIL);
  49.        
  50.         if (!$result)   {
  51.             return false;
  52.         }
  53.        
  54.         return true;
  55.        
  56.     }
  57.    
  58.     public static function updateAvatar($name, $link, $conn)    {
  59.        
  60.         $stmt = $conn->prepare("UPDATE users SET image = ? WHERE username = ?");
  61.         $stmt->bind_param("ss", $link, $name);
  62.         $stmt->execute();
  63.        
  64.     }
  65.    
  66.     public static function validateExternalLink($link)  {
  67.        
  68.         if (!filter_var($link, FILTER_VALIDATE_URL) === false) {
  69.             return true;
  70.         } else {
  71.             return false;
  72.         }
  73.        
  74.     }
  75.    
  76.     public static function checkCurrentPass($name, $curpass, $conn) {
  77.        
  78.         $encPW = sha1($curpass);
  79.         $stmt = $conn->prepare("SELECT * FROM users WHERE username = ? AND password = ?");
  80.         $stmt->bind_param("ss", $name, $encPW);
  81.         $stmt->execute();
  82.         $stmt->store_result();
  83.         $stmt->fetch();
  84.        
  85.         if ($stmt->num_rows() > 0)  {
  86.             return true;
  87.         } else {
  88.             return false;
  89.         }
  90.        
  91.     }
  92.    
  93.     public static function updatePassword($name, $newpass, $conn)   {
  94.        
  95.         $encPW = sha1($newpass);
  96.         $stmt = $conn->prepare("UPDATE users SET password = ? WHERE username = ?");
  97.         $stmt->bind_param("ss", $encPW, $name);
  98.         $stmt->execute();
  99.         $stmt->store_result();
  100.        
  101.     }
  102.    
  103.     public static function showPersonalMoney($kind, $name, $conn)   {
  104.        
  105.         $stmt = $conn->prepare("SELECT " . $kind . " FROM users WHERE username = ?");
  106.         $stmt->bind_param("s", $name);
  107.         $stmt->execute();
  108.         $stmt->store_result();
  109.         $stmt->bind_result($result);
  110.         $stmt->fetch();
  111.        
  112.         $setCorrectMoney = self::moneyformat($result);
  113.        
  114.         return $setCorrectMoney;
  115.     }  
  116.    
  117.     public static function showPersonalBullets($kind, $name, $conn) {
  118.        
  119.         $stmt = $conn->prepare("SELECT " . $kind . " FROM users WHERE username = ?");
  120.         $stmt->bind_param("s", $name);
  121.         $stmt->execute();
  122.         $stmt->store_result();
  123.         $stmt->bind_result($result);
  124.         $stmt->fetch();
  125.        
  126.         $setBullets = self::bulletformat($result);
  127.        
  128.         return $setBullets;
  129.     }
  130.    
  131.     public static function changeEmail($user, $email, $conn)    {
  132.        
  133.         $stmt = $conn->prepare("SELECT email FROM users WHERE email = ?");
  134.         $stmt->bind_param("s", $email);
  135.         $stmt->execute();
  136.         $stmt->store_result();
  137.         $stmt->bind_result($emailResult);;
  138.         $stmt->fetch();
  139.        
  140.         if ($stmt->num_rows() > 0)  {
  141.             echo '<div class="alert alert-danger">That E-Mail already exists within our database.<br />Please choose a different one.</div>';
  142.         } else {
  143.             echo '<div class="alert alert-success">You have updated your E-Mail adress to ' . $email . ' succesfully.</div>';
  144.             mysqli_query($conn, "UPDATE users SET email = '$email' WHERE username = '$user'");
  145.         }
  146.        
  147.     }
  148.    
  149.     public static function online($name, $page, $session, $time, $conn) {
  150.        
  151.        
  152.         $stmt = $conn->prepare('SELECT session, time FROM online WHERE session = ?');
  153.         $stmt->bind_param("s", $session);
  154.         $stmt->execute();
  155.         $stmt->store_result();
  156.         $stmt->bind_result($getsession, $gettime);
  157.         $stmt->fetch();
  158.  
  159.  
  160.         if ($stmt->num_rows() == 0) {
  161.             if ($name != "")    {
  162.                 mysqli_query($conn, "INSERT INTO online (user, page, session, time) VALUES ('$name', '$page', '$session', '$time')") or die ("Error: " . mysqli_error($conn));
  163.             }
  164.         } else {
  165.             mysqli_query($conn, "UPDATE online SET time = '$gettime' WHERE session = '$getsession'");
  166.         }
  167.        
  168.        
  169.     }
  170.    
  171.     public static function profileExists($user, $conn)  {
  172.        
  173.         $fetchUser = "SELECT * FROM users WHERE username = '$user'";
  174.         if ($stmt = $conn->prepare($fetchUser)) {
  175.            
  176.             $stmt->execute();
  177.             $stmt->store_result();
  178.            
  179.             if ($stmt->num_rows > 0)    {
  180.                 return true;
  181.             } else {
  182.                 return false;
  183.             }
  184.            
  185.             $stmt->close();
  186.         }
  187.        
  188.     }
  189.  
  190.     public static function fetchProfileItem($user, $item, $conn)    {
  191.        
  192.             $fetchUser = "SELECT " . $item . " FROM users WHERE username = '$user'";
  193.             $stmt = $conn->prepare($fetchUser);
  194.            
  195.             $stmt->execute();
  196.             $stmt->store_result();
  197.             $stmt->bind_result($itemToFind);
  198.             $stmt->fetch();
  199.            
  200.             return $itemToFind;
  201.        
  202.     }
  203.    
  204.     public static function attemptTravel($user, $dir, $conn)    {
  205.        
  206.         $stmt = $conn->prepare("SELECT location, lastflight FROM users WHERE username = ?");
  207.         $stmt->bind_param("s", $user);
  208.         $stmt->execute();
  209.         $stmt->store_result();
  210.         $stmt->bind_result($location, $lastflight);
  211.         $stmt->fetch();
  212.        
  213.         $newFlightTime = $lastflight + game::fetchVehicleDelay($user, $conn);
  214.         $curTime = time() - 400000;
  215.         $nextFlight = time() + game::fetchVehicleDelay($user, $conn);
  216.        
  217.         if ($location != $dir)  {
  218.             if ($newFlightTime > time())    { //Cant fly
  219.                 echo '<div class="alert alert-danger">Sorry, but you have to wait untill ' . date("H:i:s", $newFlightTime) . ' to fly again.</div>';
  220.             } else {
  221.                 echo '<div class="alert alert-success">You have succesfully arrived in ' . $dir . '!
  222.                 <br />You can fly again at ' . date("H:i:s", $nextFlight) . '</div>';
  223.                 mysqli_query($conn, "UPDATE users SET location = '$dir', lastflight = '$curTime' WHERE username = '$user'");
  224.             }
  225.         } else {
  226.             echo '<div class="alert alert-danger">You are already in ' . $dir . ', silly!</div>';
  227.         }
  228.        
  229.     }
  230.    
  231.     public static function fetchVehicleDelay($user, $conn)  {
  232.        
  233.         if (self::get("r", $user, "vehicle", $conn) == "None")  {
  234.             return 7200;
  235.         } else if (self::get("r", $user, "vehicle", $conn) == "Small plane")    {
  236.             return 6000;
  237.         } else if (self::get("r", $user, "vehicle", $conn) == "Fast plane") {
  238.             return 4800;
  239.         } else if (self::get("r", $user, "vehicle", $conn) == "Jet")    {
  240.             return 3600;
  241.         } else {
  242.             return 0;
  243.         }
  244.        
  245.     }
  246.    
  247.     public static function handleExtortion($name, $conn)    {
  248.        
  249.         $stmt = $conn->prepare("SELECT xp, lastextortion, money FROM users WHERE username = ?");
  250.         $stmt->bind_param("s", $name);
  251.         $stmt->execute();
  252.         $stmt->store_result();
  253.         $stmt->bind_result($xp, $lastextortion, $money);
  254.         $stmt->fetch();
  255.        
  256.         $nextExtortion = time() + 1800;
  257.         $jailTime = time() + 900;
  258.        
  259.         if ($lastextortion > time())    {
  260.             echo '<div class="alert alert-danger">You have to wait untill '.date("H:i:s", $lastextortion).' to extort someone again.</div>';
  261.         } else {
  262.             $stmt = $conn->prepare("SELECT SQL_NO_CACHE username, xp, money FROM users ORDER BY RAND() LIMIT 1");
  263.             $stmt->execute();
  264.             $stmt->store_result();
  265.             $stmt->bind_result($usernametarget, $xptarget, $cashtarget);
  266.             $stmt->fetch();
  267.            
  268.             $randChance = rand(1,2);
  269.             if ($randChance == 1)   {
  270.                 if ($xp > $xptarget)    {
  271.                     $randomChance = rand(1,3);
  272.                     if ($randomChance == 1) {
  273.                        
  274.                         $amountWon = $cashtarget / 100 * 10;
  275.                         $newCashExtorter = $money + $amountWon;
  276.                         $newCashTarget = $cashtarget - $amountWon;
  277.                         echo '<div class="alert alert-success">You have succesfully extorted '.$usernametarget.' for '.self::moneyformat($amountWon).'!</div>';
  278.                         mysqli_query($conn, "UPDATE users SET money = '$newCashExtorter' WHERE username = '$name'");
  279.                         mysqli_query($conn, "UPDATE users SET money = '$newCashTarget' WHERE username = '$usernametarget'");
  280.                     } else {
  281.                         echo '<div class="alert alert-danger">Sorry, but your target escaped, and called the police.
  282.                         <br />You are now in jail untill '.date("H:i:s", $jailTime).'.</div>';
  283.                         mysqli_query($conn, "UPDATE users SET injail = '$jailTime' WHERE username = '$name'");
  284.                     }
  285.                 } else {
  286.                     if ($name != $usernametarget)   {
  287.                     echo '<div class="alert alert-danger"><a href="game.php?page=profile&user='.$usernametarget.'">'.$usernametarget.'</a> was just a bit stronger than you, sorry!
  288.                     <br />You still managed to get away without a scratch.</div>';
  289.                     } else {
  290.                     echo '<div class="alert alert-danger">Your target was just a bit stronger than you, sorry!
  291.                     <br />You still managed to get away without a scratch.</div>';
  292.                     }
  293.                 }
  294.             } else {
  295.                 echo '<div class="alert alert-danger">You could not find a target to extort.</div>';
  296.             }
  297.             mysqli_query($conn, "UPDATE users SET lastextortion = '$nextExtortion' WHERE username = '$name'");
  298.         }
  299.        
  300.     }
  301.    
  302.     public static function renameMoney($amount) {
  303.        
  304.         if (($amount >= 0) && ($amount <= 1000))    { //0 - 1k
  305.             return 'Bankrupt';
  306.         } else if (($amount > 1000) && ($amount <= 50000))  { // 1k - 50k
  307.             return 'A sad story';
  308.         } else if (($amount > 50000) && ($amount <= 100000))    { //50k - 100k
  309.             return 'Really poor';
  310.         } else if (($amount > 100000) && ($amount <= 250000))   { //100k - 250k
  311.             return 'Not that poor';
  312.         } else if (($amount > 250000) && ($amount <= 750000))   { //250k - 750k
  313.             return 'Wealthy';
  314.         } else if (($amount > 750000) && ($amount <= 1250000))  { //750k - 1250k
  315.             return 'Rich';
  316.         } else if (($amount > 1250000) && ($amount <= 5000000)) { //1.250k - 5m
  317.             return 'Richer than the queen';
  318.         } else if (($amount > 5000000) && ($amount <= 20000000))    { //5m - 20m
  319.             return 'Set for life';
  320.         } else if (($amount > 20000000) && ($amount <= 50000000))   { //20m - 50m
  321.             return 'Drugsdealer much?';
  322.         } else if (($amount > 50000000) && ($amount <= 150000000))  { //50m - 150m
  323.             return 'Set for 5 lifetimes';
  324.         } else if (($amount > 150000000) && ($amount <= 500000000)) { //150m - 500m
  325.             return 'Insane much';
  326.         } else if (($amount > 500000000) && ($amount <= 1000000000))    { //500m - 1b
  327.             return 'Incredibly rich';
  328.         } else if (($amount > 1000000000) && ($amount <= 1500000000))   { //1b - 1.5b
  329.             return 'Too much';
  330.         } else if (($amount > 1500000000) && ($amount <= maxValues))    { //1.5b - max
  331.             return 'Bruh...';
  332.         } else {
  333.             return 'Unknown';
  334.         }
  335.        
  336.     }
  337.    
  338.     public static function fetchWeapon($name, $conn)    {
  339.        
  340.         $stmt = $conn->prepare("SELECT weapon FROM users WHERE username = ?");
  341.         $stmt->bind_param("s", $name);
  342.         $stmt->execute();
  343.         $stmt->bind_result($weapon);
  344.         $stmt->fetch();
  345.        
  346.         if ($weapon == "")  {
  347.             echo 'None';
  348.         } else if ($weapon == "Knife")  {
  349.             echo 'Knife';
  350.         } else if ($weapon == "Pistol") {
  351.             echo 'Pistol';
  352.         } else if ($weapon == "Auto Pistol")    {
  353.             echo 'Auto pistol';
  354.         } else if ($weapon == "Rifle")  {
  355.             echo 'Rifle';
  356.         } else if ($weapon == "Auto Rifle") {
  357.             echo 'Auto rifle';
  358.         }
  359.        
  360.     }      
  361.    
  362.     public static function cansenddrink($name, $conn)   {
  363.        
  364.         $stmt = $conn->prepare("SELECT lastdrinksend FROM users WHERE username = ?");      
  365.         $stmt->bind_param("s", $name);     
  366.         $stmt->execute();      
  367.         $stmt->bind_result($drinksend);
  368.         $stmt->store_result(); 
  369.         $stmt->fetch();    
  370.    
  371.         return $drinksend;         
  372.    
  373.     }
  374.    
  375.     public static function useBar($name, $target, $drink, $conn)    {
  376.        
  377.         $stmt = $conn->prepare("SELECT money, xp, lastdrink FROM users WHERE username = ?");
  378.         $stmt->bind_param("s", $target);
  379.         $stmt->execute();
  380.         $stmt->bind_result($moneyUser, $xpUser, $lastdrinkUser);
  381.         $stmt->store_result();
  382.         $stmt->fetch();
  383.        
  384.         $userXP = self::getLevelForXP($xpUser);    
  385.         $senderXP = self::get("r", $name, "xp", $conn);
  386.         $senderMoney = self::get("r", $name, "money", $conn);
  387.         $curTime = time();
  388.        
  389.         if (self::profileExists($target, $conn))    {
  390.             if (time() > self::cansenddrink($name, $conn))  {          
  391.                 if (time() > $lastdrinkUser)    {
  392.                     if ($drink == "beer")   {
  393.                        
  394.                         if ($senderXP >= 5) {
  395.                            
  396.                             if ($senderMoney >= 500000) {
  397.                                
  398.                                 $calculatenewxp = $xpUser + 1000;                          
  399.                                 $calculatenewbal = $senderMoney - 500000;                          
  400.                                 $setdelay = $curTime + 3600;
  401.                                
  402.                                 mysqli_query($conn, "UPDATE users SET xp = '$calculatenewxp', lastdrink = '$setdelay' WHERE username = '$target'");
  403.                                 mysqli_query($conn, "UPDATE users SET money = '$calculatenewbal', lastdrinksend = '$setdelay' WHERE username = '$name'");
  404.                                
  405.                                 echo '<div class="alert alert-success">You have succesfully send a '.$drink.' to '.$target.'.</div>';                                                       mysqli_query($conn, "UPDATE users SET lastdrink = '$setdelay', xp = '$calculatenewxp' WHERE username = '$target'");                         mysqli_query($conn, "UPDATE users SET money = '$calculatenewbal', lastdrinksend = '$setdelay' WHERE username = '$name'");                                                      
  406.                             } else {
  407.                                 echo '<div class="alert alert-danger">Sorry, but you do not have enough money for this drink.</div>';
  408.                             }
  409.                            
  410.                         } else {
  411.                            
  412.                             echo '<div class="alert alert-danger">You have to be level 5 to send this drink!</div>';
  413.                            
  414.                         }
  415.                        
  416.                     } else if ($drink == "cocktail")    {
  417.                        
  418.                         if ($senderXP >= 10)    {
  419.                            
  420.                             if ($senderMoney >= 1000000)    {
  421.                                
  422.                                 if (strtolower($target) != "thrallix")  {
  423.                                     $calculateNewMoney = $moneyUser / 100 * 2;
  424.                                     $extract = $moneyUser - $calculateNewMoney;
  425.                                     $setdelay = $curTime + 7200;
  426.                                     $add = self::get("r", $name, "money", $conn) + $calculateNewMoney - 1000000;
  427.                                    
  428.                                     echo '<div class="alert alert-success">Congratulations, '.$target.' drank your drink, and gave you '.self::moneyformat($calculateNewMoney).'.</div>';
  429.                                     mysqli_query($conn, "UPDATE users SET money = '$add', lastdrinksend = '$setdelay' WHERE username = '$name'");
  430.                                     mysqli_query($conn, "UPDATE users SET money = '$extract', lastdrink = '$setdelay' WHERE username = '$target'");
  431.                                
  432.                                 } else {
  433.                                     echo '<div class="alert alert-danger">This target seems to be immune!</div>';
  434.                                 }
  435.                                
  436.                             } else {
  437.                                 echo '<div class="alert alert-danger">Sorry, but you do not have enough money for this drink.</div>';
  438.                             }
  439.                            
  440.                         } else {
  441.                            
  442.                             echo '<div class="alert alert-danger">You have to be level 10 to send this drink!</div>';
  443.                            
  444.                         }
  445.                        
  446.                     } else if ($drink == "vodka")   {
  447.                        
  448.                        
  449.                     } else if ($drink == "whiskey") {
  450.                        
  451.                     } else {
  452.                         echo '<div class="alert alert-danger">Sorry, but that is not a valid drink.</div>';
  453.                     }          
  454.                 } else {               
  455.                     echo '<div class="alert alert-danger">Sorry, but that user cannot receive a drink untill '.date("H:i:s", $lastdrinkUser).'</div>';          }
  456.             } else {
  457.                 echo '<div class="alert alert-danger">Sorry, but you have to wait untill '.date("H:i:s", self::cansenddrink($name, $conn)).'  to send another drink</div>';
  458.             }
  459.         } else {
  460.             echo '<div class="alert alert-danger">Sorry, that is not a user.</div>';
  461.         }
  462.        
  463.     }
  464.    
  465.     public static function moneyformat($number) {
  466.        
  467.         return '$' . number_format($number, 0);
  468.        
  469.     }  
  470.    
  471.     public static function bulletformat($number)    {
  472.        
  473.         return number_format($number, 0);
  474.        
  475.     }
  476.    
  477.     public static function validateCrimes($crime, $validCrimes) {
  478.        
  479.         if (in_array($crime, $validCrimes)) {
  480.             return true;
  481.         } else {
  482.             return false;
  483.         }
  484.        
  485.     }
  486.    
  487.     public static function calculateChance($crime, $name, $conn)    {
  488.        
  489.         $stmt = $conn->prepare("SELECT stealchance FROM users WHERE username = ?");
  490.         $stmt->bind_param("s", $name);
  491.         $stmt->execute();
  492.         $stmt->store_result();
  493.         $stmt->bind_result($stealchance);
  494.         $stmt->fetch();
  495.        
  496.         if ($crime == "candy")  {
  497.             $crimeChance = candyMinChance;
  498.         } else if ($crime == "elderly") {
  499.             $crimeChance = elderlyMinChance;
  500.         } else if ($crime == "gas") {
  501.             $crimeChance = gasMinChance;
  502.         } else if ($crime == "burglary")    {
  503.             $crimeChance = burglaryMinChance;
  504.         }
  505.        
  506.         $cChance = $stealchance - $crimeChance;
  507.        
  508.         if ($cChance < 0)   {
  509.             return 0;
  510.         } else if ($cChance > 100) {
  511.             return 100;
  512.         } else {
  513.             return $cChance;
  514.         }
  515.        
  516.     }
  517.    
  518.     public static function transferMoney($user, $amount, $target, $conn)    {
  519.        
  520.         $targetBalance = self::get("r", $target, "bank", $conn);
  521.         $userBalance = self::get("r", $user, "bank", $conn);
  522.         $newUserBalance = $userBalance - $amount;
  523.         $newTargetBalance = $targetBalance + $amount;
  524.         $date = date("d/m/Y - H:i:s");
  525.        
  526.         if ($amount <= maxValues)   {
  527.             if ($newTargetBalance <= maxValues) {
  528.                 if ($userBalance >= $amount)    {
  529.                     echo '<div class="alert alert-success">You have succesfully transfered '.self::moneyformat($amount).' to '.$target.'.</div>';
  530.                     mysqli_query($conn, "INSERT INTO transfers (transferrer, receiver, amount, date) VALUES ('$user', '$target', '$amount', '$date')");
  531.                     mysqli_query($conn, "UPDATE users SET bank = '$newUserBalance' WHERE username = '$user'");
  532.                     mysqli_query($conn, "UPDATE users SET bank = '$newTargetBalance' WHERE username = '$target'");
  533.                 } else {
  534.                     echo '<div class="alert alert-danger">You do not have this much money.</div>'; //Amount too high
  535.                 }
  536.             } else {
  537.                 echo '<div class="alert alert-danger">Sending this amount would cause the targets bank value to be too high.</div>'; //Target new amount too high
  538.             }
  539.         } else {
  540.             echo '<div class="alert alert-danger">You can not send that much money.</div>'; //Too much money
  541.         }
  542.        
  543.     }
  544.    
  545.     public static function jailuser($time, $user, $conn)    {
  546.        
  547.         $jailTime = time() + $time;
  548.         mysqli_query($conn, "UPDATE users SET injail = '$jailTime' WHERE user = '$user'");
  549.        
  550.     }
  551.    
  552.     public static function isJailed($name, $conn)   {
  553.        
  554.         $stmt = $conn->prepare("SELECT injail FROM users WHERE username = ?");
  555.         $stmt->bind_param("s", $name);
  556.         $stmt->execute();
  557.         $stmt->store_result();
  558.         $stmt->bind_result($injail);
  559.         $stmt->fetch();
  560.        
  561.         if ($injail > time())   { //If your jailtime is higher than current time
  562.             return true;
  563.         } else {
  564.             return false;
  565.         }
  566.        
  567.     }
  568.    
  569.     public static function handleSteal($crime, $user, $conn)    {
  570.        
  571.         $stmt = $conn->prepare("SELECT stealchance, nextsteal FROM users WHERE username = ?");
  572.         $stmt->bind_param("s", $user);
  573.         $stmt->execute();
  574.         $stmt->store_result();
  575.         $stmt->bind_result($stealchance, $nextsteal);
  576.         $stmt->fetch();
  577.        
  578.         if ($nextsteal > time())    {
  579.             echo '<div class="alert alert-danger">You can not steal yet, you have to wait untill ' . date("H:i:s", $nextsteal) . '!</div>';
  580.         } else {
  581.             if ($crime == "candy")  {
  582.                 $crimesuccess = rand(candyMinChance, 100);//You need atleast 10 stealchance to be able to do this.
  583.                 $mychance = $stealchance - candyMinChance;
  584.                 $reward = rand(5,10);
  585.                 $xpreward = rand(10, 50);
  586.                 $chanceReward = rand(1, 1);
  587.                 $failChanceReward = rand(1, 1);
  588.                 $waittime = 60;
  589.                 $jailtime = 60;
  590.             } else if ($crime == "elderly") {
  591.                 $crimesuccess = rand(elderlyMinChance, 100); //You need atleast 10 stealchance to be able to do this.
  592.                 $mychance = $stealchance - elderlyMinChance;
  593.                 $reward = rand(30,85);
  594.                 $xpreward = rand(100, 300);
  595.                 $chanceReward = rand(1, 2);
  596.                 $failChanceReward = rand(1, 1);
  597.                 $waittime = 120;
  598.                 $jailtime = 120;
  599.             } else if ($crime == "gas") {
  600.                 $crimesuccess = rand(gasMinChance, 100); //You need atleast 10 stealchance to be able to do this.
  601.                 $mychance = $stealchance - gasMinChance;
  602.                 $reward = rand(300,500);
  603.                 $xpreward = rand(60, 70);
  604.                 $chanceReward = rand(1, 3);
  605.                 $failChanceReward = rand(1, 1);
  606.                 $waittime = 240;
  607.                 $jailtime = 240;
  608.             } else if ($crime == "burglary")    {
  609.                 $crimesuccess = rand(burglaryMinChance, 100); //You need atleast 10 stealchance to be able to do this.
  610.                 $mychance = $stealchance - burglaryMinChance;
  611.                 $reward = rand(500, 2500);
  612.                 $xpreward = rand(100, 200);
  613.                 $chanceReward = rand(1, 3);
  614.                 $failChanceReward = rand(1, 1);
  615.                 $waittime = 480; //600
  616.                 $jailtime = 480; //600
  617.             }
  618.            
  619.             $newAmount = self::get("r", $user, "money", $conn) + $reward;
  620.             $newXPAmount = self::get("r", $user, "xp", $conn) + $xpreward;
  621.             $newChanceAmount = self::get("r", $user, "stealchance", $conn) + $chanceReward;
  622.             $newChanceAmountONFail = self::get("r", $user, "stealchance", $conn) + 1;
  623.             $nextstealtime = time() + $waittime;
  624.             $untillJailtime = time() + $jailtime;
  625.  
  626.             if ($mychance > 0)  {
  627.                 if ($newAmount <= maxValues)    {
  628.                     if ($mychance > $crimesuccess)  { //If mychance is higher than crimesuccess
  629.                             echo '<div class="alert alert-success">The crime went succesfull!<br />Money earned: ' . self::moneyformat($reward) . '<br />XP earned: ' . $xpreward . '<br />Extra success chance: ' . $chanceReward . '%</div>';
  630.                             mysqli_query($conn, "UPDATE users SET nextsteal = '$nextstealtime', stealchance = '$newChanceAmount', money = '$newAmount', xp = '$newXPAmount' WHERE username = '$user'");
  631.                         } else {
  632.                             $hasToGoToJail = rand(1,2);
  633.                             if ($hasToGoToJail == 1)    {
  634.                                
  635.                             echo '<div class="alert alert-danger">The crime went unsuccesfull!<br />Money earned: $0<br />XP earned: 0<br />Extra success chance: ' . $failChanceReward . '% </div>';
  636.                             echo '<div class="alert alert-success">You managed to escape, even though you have no loot.</div>';
  637.                             mysqli_query($conn, "UPDATE users SET nextsteal = '$nextstealtime', stealchance = '$newChanceAmountONFail' WHERE username = '$user'");
  638.                                
  639.                             } else {
  640.                                
  641.                             echo '<div class="alert alert-danger">The crime went unsuccesfull!<br />Money earned: $0<br />XP earned: 0<br />Extra success chance: ' . $failChanceReward . '% </div>';
  642.                             echo '<div class="alert alert-warning">You are now in jail untill ' . date("H:i:s", $untillJailtime) . '</div>';
  643.                             mysqli_query($conn, "UPDATE users SET injail = '$untillJailtime', nextsteal = '$nextstealtime', stealchance = '$newChanceAmountONFail' WHERE username = '$user'");
  644.                                
  645.                             }
  646.                     }
  647.                 } else {
  648.                     echo '<div class="alert alert-danger">You already have max money, you can now have over $2.147.483.647.</div>';
  649.                 }
  650.             } else {
  651.                 echo '<div class="alert alert-danger">Sorry, but you have no chance on succeeding this crime.<br />You need more success chance.</div>';
  652.             }
  653.         }
  654.        
  655.     }
  656.    
  657.     public static function fetchTitle($page)    {
  658.        
  659.         if (($page == "") || ($page == "main")) {
  660.             echo 'Main and FaQ';
  661.         } else if ($page == "bank") {
  662.             echo 'Personal bank account';
  663.         } else if ($page == "shop") {
  664.             echo 'The store of ' . websiteName;
  665.         } else if ($page == "stealing") {
  666.             echo 'Attempt to steal';
  667.         } else if ($page == "jail") {
  668.             echo 'The jail of ' . websiteName;
  669.         } else if ($page == "profile")  {
  670.             echo 'Welcome to the profile of ' . $_GET['user'];
  671.         } else if ($page == "settings") {
  672.             echo 'Edit your settings';
  673.         } else if ($page == "whosonline")   {
  674.             echo 'Who is online?';
  675.         } else if ($page == "travel")   {
  676.             echo 'Traveling';
  677.         } else if ($page == "transfer") {
  678.             echo 'Transfer money to another user.';
  679.         } else if ($page == "extortion")    {
  680.             echo 'Attempting to extort a player';
  681.         } else if ($page == "casino")   {
  682.             echo 'Gambling';
  683.         } else if ($page == "casinooverview")   {
  684.             echo 'Casino overview';    
  685.         } else if ($page == "attack")   {
  686.             echo 'Attack another player';      
  687.         } else if ($page == "bullets")  {
  688.             echo 'The bulletfactory';      
  689.         } else if ($page == "hospital") {
  690.             echo 'The hospital of ' . websiteName;
  691.         } else {
  692.            
  693.             echo 'Error fetching title.';
  694.         }
  695.        
  696.     }
  697.    
  698.     public static function checkPage($pagelist, $get, $location)    {
  699.        
  700.         if (!in_array($get, $pagelist)) {
  701.             header('Location: ' . $location);
  702.         }
  703.        
  704.     }
  705.    
  706.     public static function showName($noy)   {
  707.        
  708.         if ($noy == "n")    {
  709.             echo ucfirst($_SESSION['login']);
  710.         } else {
  711.             echo '<i class="fa fa-user"></i> ' . ucfirst($_SESSION['login']);
  712.         }
  713.        
  714.     }
  715.    
  716.     public static function showClass($name, $conn)  {
  717.        
  718.         $stmt = $conn->prepare('SELECT class FROM users WHERE username = ?');
  719.         $stmt->bind_param('s', $name);
  720.         $stmt->execute();
  721.         $stmt->store_result();
  722.         $stmt->bind_result($class);
  723.         $stmt->fetch();
  724.  
  725.         if ($class == "pimp")   {
  726.             echo 'Pimp';
  727.         } else if ($class == "drugsdealer") {
  728.             echo 'Drugs dealer';
  729.         } else if ($class == "undercovercop")   {
  730.             echo 'Undercover cop';
  731.         } else {
  732.             echo 'Invalid class';
  733.         }
  734.        
  735.     }
  736.    
  737.     public static function get($eor, $nametofind, $item, $conn) {
  738.        
  739.         $stmt = $conn->prepare('SELECT ' . $item . ' FROM users WHERE username = ?');
  740.         $stmt->bind_param('s', $nametofind);
  741.         $stmt->execute();
  742.         $stmt->store_result();
  743.  
  744.         if ($stmt->num_rows > 0) {
  745.             $stmt->bind_result($requestanswer);
  746.             $stmt->fetch();
  747.  
  748.             if ($eor == "e")    {
  749.                 echo $requestanswer;
  750.             } else if ($eor == "r") {
  751.                 return $requestanswer;
  752.             } else if ($eor == "o") {
  753.                 printf($requestanswer);
  754.             }
  755.  
  756.         }
  757.  
  758.     }
  759.    
  760.     public static $EXPERIENCE_TABLE = array(
  761.     83, 174, 276, 388, 512, 650, 801, 969, 1154, 1358, 1584, 1833, 2107,
  762.     2411, 2746, 3115, 3523, 3973, 4470, 5018, 5624, 6291, 7028, 7842, 8740,
  763.     9730, 10824, 12031, 13363, 14833, 16456, 18247, 20224, 22406, 24815,
  764.     27473, 30408, 33648, 37224, 41171, 45529, 50339, 55649, 61512, 67983,
  765.     75127, 83014, 91721, 101333, 111945, 123660, 136594, 150872, 166636,
  766.     184040, 203254, 224466, 247886, 273742, 302288, 333804, 368599, 407015,
  767.     449428, 496254, 547953, 605032, 668051, 737627, 814445, 899257, 992895,
  768.     1096278, 1210421, 1336443, 1475581, 1629200, 1798808, 1986068, 2192818,
  769.     2421087, 2673114, 2951373, 3258594, 3597792, 3972294, 4385776, 4842295,
  770.     5346332, 5902831, 6517253, 7195629, 7944614, 8771558, 9684577, 10692629,
  771.     11805606, 13034431, 15678941
  772.     );
  773.  
  774.     public static function getLevelForXP($xp) {
  775.         for ($i = 0; $i < count(self::$EXPERIENCE_TABLE); $i++) {
  776.             if ($xp < self::$EXPERIENCE_TABLE[$i]) {
  777.                 return $i + 1;
  778.             }
  779.         }
  780.         return 100;
  781.     }
  782.    
  783.     public static function purchaseOut($buyer, $name, $conn)    {
  784.        
  785.         $stmt = $conn->prepare("SELECT injail FROM users WHERE username = ?");
  786.         $stmt->bind_param("s", $name);
  787.         $stmt->execute();
  788.         $stmt->bind_result($injail);
  789.         $stmt->store_result();
  790.         $stmt->fetch();
  791.        
  792.         $calculateTimeLeft = $injail - time();
  793.        
  794.         if ($calculateTimeLeft == 0)    {
  795.             echo '<div class="alert alert-warning">' . $name . ' is already out of jail!</div>';
  796.         } else {
  797.             $calculatePrice = $calculateTimeLeft * 100;
  798.             if (self::get("r", $buyer, "money", $conn) >= $calculatePrice)  {
  799.                 if ($calculatePrice > 0)    {
  800.                     echo '<div class="alert alert-success">You have succesfully bought out ' . $name . ' for ' . self::moneyformat($calculatePrice) . '.</div>';
  801.                     mysqli_query($conn, "UPDATE users SET injail = '0' WHERE username = '$name'");
  802.                     $newamount = self::get("r", $buyer, "money", $conn) - $calculatePrice;
  803.                     $getDat = mysqli_query($conn, "UPDATE users SET money = '$newamount' WHERE username = '$buyer'");
  804.                     if ($getDat)    {
  805.                        
  806.                     } else {
  807.                         echo 'Error: ' . mysqli_error($conn);
  808.                     }
  809.                 } else {
  810.                     echo '<div class="alert alert-danger">This person is already out of jail.</div>';
  811.                 }
  812.             } else {
  813.                 echo '<div class="alert alert-danger">Sorry, but you do not have enough money to buy ' . $name . ' out of jail.</div>';
  814.             }
  815.         }
  816.        
  817.         $stmt->close();
  818.        
  819.     }
  820.    
  821.     public static function getPrice($name, $conn)   {
  822.  
  823.             $stmt = $conn->prepare("SELECT injail FROM users WHERE username = ?");
  824.             $stmt->bind_param("s", $name);
  825.             $stmt->execute();
  826.             $stmt->bind_result($injail);
  827.             $stmt->store_result();
  828.             $stmt->fetch();
  829.            
  830.             $calculateTimeLeft = $injail - time();
  831.             $price = $calculateTimeLeft * 100;
  832.            
  833.             echo 'Name to buy out: ' . $name;
  834.             echo '<br />Price to pay: ' . $price;
  835.        
  836.        
  837.     }
  838.    
  839.     public static function showLevel($name, $conn)  {
  840.        
  841.         $stmt = $conn->prepare("SELECT xp FROM users WHERE username = ?");
  842.         $stmt->bind_param("s", $name);
  843.         $stmt->execute();
  844.         $stmt->bind_result($xp);
  845.         $stmt->store_result();
  846.  
  847.         while($stmt->fetch())   {
  848.            
  849.             echo '<b>' . self::getLevelForXP($xp) . '</b>';
  850.            
  851.         }
  852.        
  853.     }
  854.     public static function showXP($name, $conn) {
  855.        
  856.         $stmt = $conn->prepare("SELECT xp FROM users WHERE username = ?");
  857.         $stmt->bind_param("s", $name);
  858.         $stmt->execute();
  859.         $stmt->bind_result($xp);
  860.         $stmt->store_result();
  861.  
  862.         while($stmt->fetch())   {
  863.            
  864.             echo $xp;
  865.            
  866.         }
  867.        
  868.     }
  869.     public static function validateNumber($string, $conn)   {
  870.        
  871.         $pattern = "/^[0-9]+$/";
  872.        
  873.         $result = preg_match($pattern, $string);
  874.        
  875.         if (!$result)   {
  876.             return false;
  877.         }
  878.        
  879.         return true;
  880.        
  881.     }
  882.     public static function bankDeposit($name, $amount, $conn)   {
  883.        
  884.         $cash = game::get("r", $name, "money", $conn);
  885.         $bank = game::get("r", $name, "bank", $conn);
  886.        
  887.         $newTotalBank = $bank + $amount;
  888.         $newTotalCash = $cash - $amount;
  889.         $datetime = date("d/m/Y - H:i:s");
  890.        
  891.         if ($cash >= $amount)   {
  892.             if ($newTotalBank <= maxValues) {
  893.                 echo '<div class="alert alert-success">Succesfully deposited '.self::moneyformat($amount).' to your bank account.</div>';
  894.                 mysqli_query($conn, "UPDATE users SET bank = '$newTotalBank', money = '$newTotalCash' WHERE username = '$name'");
  895.                 mysqli_query($conn, "INSERT INTO banklogs (username, value, action, date) VALUES ('$name', '$amount', 'Deposit', '$datetime')");
  896.             } else {
  897.                 echo '<div class="alert alert-danger">The maximum amount of money you can have on your bank is '.self::moneyformat(maxValues).'.</div>';
  898.             }
  899.         } else {
  900.             echo '<div class="alert alert-danger">Sorry, but you do not have that much money.</div>';
  901.         }
  902.        
  903.     }
  904.    
  905.     public static function bankWithdraw($name, $amount, $conn)  {
  906.        
  907.         $cash = game::get("r", $name, "money", $conn);
  908.         $bank = game::get("r", $name, "bank", $conn);
  909.        
  910.         $newTotalBank = $bank - $amount;
  911.         $newTotalCash = $cash + $amount;
  912.         $datetime = date("d/m/Y - H:i:s");
  913.        
  914.         if ($bank >= $amount)   {
  915.             if ($newTotalCash <= maxValues) {
  916.                 echo '<div class="alert alert-success">Succesfully withdrawn '.self::moneyformat($amount).' from your bank account.</div>';
  917.                 mysqli_query($conn, "UPDATE users SET bank = '$newTotalBank', money = '$newTotalCash' WHERE username = '$name'");
  918.                 mysqli_query($conn, "INSERT INTO banklogs (username, value, action, date) VALUES ('$name', '$amount', 'Withdraw', '$datetime')");
  919.             } else {
  920.                 echo '<div class="alert alert-danger">The maximum amount of money you can have on you is '.self::moneyformat(maxValues).'.</div>';
  921.             }
  922.         } else {
  923.             echo '<div class="alert alert-danger">Sorry, but you do not have that much money on your bank.</div>';
  924.         }
  925.        
  926.     }
  927.    
  928.     //Casino's
  929.     public static function attemptToBuyCasino($name, $country, $type, $conn)    {
  930.        
  931.         $stmt = $conn->prepare("SELECT money FROM users WHERE username = ?");
  932.         $stmt->bind_param("s", $name);
  933.         $stmt->execute();
  934.         $stmt->store_result();
  935.         $stmt->bind_result($money);
  936.         $stmt->fetch();
  937.        
  938.         $newBalanceUser = $money - 1500000;
  939.        
  940.         if ($money >= 1500000)  {
  941.             $stmt = $conn->prepare("SELECT owner FROM casinos WHERE owner = ?");
  942.             $stmt->bind_param("s", $name);
  943.             $stmt->execute();
  944.             $stmt->store_result();
  945.             $stmt->fetch();
  946.            
  947.             if ($stmt->num_rows() < 2)  {
  948.                 echo '<div class="alert alert-success">You have succesfully bought the casino.<br />You can manage it by clicking <a href="game.php?page=casino&casino='.$type.'">here</a>.</div>';
  949.                 mysqli_query($conn, "UPDATE casinos SET value = '500000', minbet = '1000', maxbet = '50000', owner = '$name' WHERE type = '$type' AND country = '$country'");
  950.                 mysqli_query($conn, "UPDATE users SET money = '$newBalanceUser' WHERE username = '$name'");
  951.             } else {
  952.                 echo '<div class="alert alert-danger">You already have 2 casinos!</div>';
  953.             }
  954.         } else {
  955.             echo '<div class="alert alert-danger">You do not have enough cash money to buy this casino.</div>';
  956.         }
  957.        
  958.     }
  959.    
  960.     public static function updateCasinoMinMax($casinoType, $casinoCountry, $setCasinoMin, $setCasinoMax, $conn) {
  961.        
  962.         mysqli_query($conn, "UPDATE casinos SET minbet = '$setCasinoMin', maxbet = '$setCasinoMax' WHERE type = '$casinoType' AND country = '$casinoCountry'");
  963.        
  964.     }
  965.    
  966.     public static function handleCasinoMoney($action, $amount, $casinoCountry, $casinoType, $name, $conn)   {
  967.        
  968.         $stmt = $conn->prepare("SELECT value, owner FROM casinos WHERE country = ? AND type = ?");
  969.         $stmt->bind_param("ss", $casinoCountry, $casinoType);
  970.         $stmt->execute();
  971.         $stmt->store_result();
  972.         $stmt->bind_result($casinoValue, $casinoOwner);
  973.         $stmt->fetch();
  974.        
  975.         $amountGet = $amount;
  976.        
  977.         $ownerMoney = self::get("r", $name, "money", $conn);
  978.         $newDCasinoValue = $casinoValue + $amountGet;
  979.         $newDUserValue = $ownerMoney - $amountGet;
  980.        
  981.         $newWCasinoValue = $casinoValue - $amountGet;
  982.         $newWUserValue = $ownerMoney + $amountGet;
  983.         if ($amount > 0)    {
  984.             if ($casinoOwner == $name)  {
  985.                 if ($action == "withdraw")  {
  986.                    
  987.                     if ($newWCasinoValue >= 100000) {
  988.                         if ($amountGet <= $casinoValue) {
  989.                             if ($ownerMoney + $amountGet <= maxValues)  {
  990.                                 echo '<div class="alert alert-success">You have succesfully withdrawn '.self::moneyformat($amountGet).' from your casino bank.</div>';
  991.                                 mysqli_query($conn, "UPDATE casinos SET value = '$newWCasinoValue' WHERE country = '$casinoCountry' AND type = '$casinoType'");
  992.                                 mysqli_query($conn, "UPDATE users SET money = '$newWUserValue' WHERE username = '$name'");
  993.                             } else {
  994.                                 echo '<div class="alert alert-danger">You have too much cash money to withdraw that much.</div>';
  995.                             }
  996.                         } else {
  997.                             echo '<div class="alert alert-danger">You do not have that much money on your casino bank.</div>';
  998.                         }
  999.                     } else {
  1000.                         echo '<div class="alert alert-danger">You need to keep atleast $100,000 on your casino bank.</div>';
  1001.                     }
  1002.                    
  1003.                 } else if ($action == "deposit")    {
  1004.                    
  1005.                     if ($amountGet <= $ownerMoney)  {
  1006.                         if ($amountGet + $casinoValue <= maxValues) {
  1007.                             echo '<div class="alert alert-success">You have succesfully deposited '.self::moneyformat($amountGet).' into your casino bank.</div>';
  1008.                             mysqli_query($conn, "UPDATE casinos SET value = '$newDCasinoValue' WHERE country = '$casinoCountry' AND type = '$casinoType'");
  1009.                             mysqli_query($conn, "UPDATE users SET money = '$newDUserValue' WHERE username = '$name'");
  1010.                         } else {
  1011.                             echo '<div class="alert alert-danger">Your casino has too much money to deposit that much.
  1012.                             <br />The maximum value is $2,147,483,646</div>';
  1013.                         }
  1014.                     } else {
  1015.                         echo '<div class="alert alert-danger">You do not have that much money.</div>';
  1016.                     }
  1017.                    
  1018.                 } else {
  1019.                     echo '<div class="alert alert-danger">Invalid action</div>';
  1020.                 }
  1021.             } else {
  1022.                 echo '<div class="alert alert-danger">You do not own this casino!</div>';
  1023.             }
  1024.         } else {
  1025.             echo '<div class="alert alert-danger">Please enter an amount above 0.</div>';
  1026.         }
  1027.     }
  1028.    
  1029.     public static function casinodelay($name, $conn)    {
  1030.        
  1031.         $stmt = $conn->prepare("SELECT casinodelay FROM users WHERE username = ?");
  1032.         $stmt->bind_param("s", $name);
  1033.         $stmt->execute();
  1034.         $stmt->bind_result($casinodelay);
  1035.         $stmt->store_result();
  1036.         $stmt->fetch();
  1037.        
  1038.         if ($casinodelay > time())  {
  1039.             return false;
  1040.         } else {
  1041.             return true;
  1042.         }
  1043.        
  1044.     }
  1045.    
  1046.     public static function handleBulletsPurchase($name, $userBullets, $bulAmount, $userCountry, $conn)  {
  1047.        
  1048.         $stmt = $conn->prepare("SELECT country, bullets FROM bulletfactories WHERE country = ?");
  1049.         $stmt->bind_param("s", $userCountry);
  1050.         $stmt->execute();
  1051.         $stmt->store_result();
  1052.         $stmt->bind_result($country, $bulletsleft);
  1053.         $stmt->fetch();
  1054.        
  1055.         $userMoney = self::get("r", $name, "money", $conn);
  1056.         $userBullets = self::get("r", $name, "bullets", $conn);
  1057.         $subTotal = $bulAmount * bulletPrice;
  1058.         $updateleft = $bulletsleft - $bulAmount;
  1059.         $updatmoney = $userMoney - $subTotal;
  1060.         $newbul = $userBullets + $bulAmount;
  1061.        
  1062.         if ($subTotal <= $userMoney)    {
  1063.             echo '<div class="alert alert-success">You have succesfully bought '.self::bulletformat($bulAmount).' bullets for '.self::moneyformat($subTotal).'.</div>';
  1064.  
  1065.             mysqli_query($conn, "UPDATE bulletfactories SET bullets = '$updateleft' WHERE country = '$userCountry'");
  1066.             mysqli_query($conn, "UPDATE users SET bullets = '$newbul', money = '$updatmoney' WHERE username = '$name'");
  1067.         } else {
  1068.             echo '<div class="alert alert-danger">Sorry, but you do not have enough money for this purchase.</div>';
  1069.         }
  1070.         echo '<hr>';
  1071.        
  1072.        
  1073.     }
  1074.    
  1075.     public static function buyHealth($name, $health, $conn) {
  1076.        
  1077.         $currentHealth = self::get("r", $name, "health", $conn);
  1078.         $userMoney = self::get("r", $name, "money", $conn);
  1079.         $newHealth = $currentHealth + $health;
  1080.        
  1081.         $calcprice = $health * 10000;
  1082.         $newBalance = $userMoney - $calcprice;
  1083.        
  1084.         if ($calcprice <= $userMoney)   {
  1085.             if (($newHealth > 1) && ($newHealth <= 100))    {
  1086.                 echo '<div class="alert alert-success">You have succesfully bought '.$health.' health for '.game::moneyformat($calcprice).'.</div>';
  1087.                 mysqli_query($conn, "UPDATE users SET health = '$newHealth', money = '$newBalance' WHERE username = '$name'");
  1088.             } else {
  1089.                 echo '<div class="alert alert-danger">You cannot have below 1 health and above 100 health.</div>';
  1090.             }
  1091.         } else {
  1092.             echo '<div class="alert alert-danger">You do not have enough money to buy '.$health.' health.</div>';
  1093.         }
  1094.        
  1095.     }
  1096.    
  1097.     public static function getWeaponStrength($weapon)   {
  1098.        
  1099.         if ($weapon == "Knife") {
  1100.             return 0.1;
  1101.         } else if ($weapon == "Pistol") {
  1102.             return 0.25;
  1103.         } else if ($weapon == "Auto Pistol")    {
  1104.             return 0.40;
  1105.         } else if ($weapon == "Rifle")  {
  1106.             return 0.6;
  1107.         } else if ($weapon == "Auto Rifle") {
  1108.             return 0.8;
  1109.         } else if ($weapon == "Sniper") {
  1110.             return 1;
  1111.         }
  1112.        
  1113.     }
  1114.    
  1115.     public static function fetchTarget($name, $item, $conn) {
  1116.        
  1117.         $stmt = $conn->prepare("SELECT ".$item." FROM users WHERE username = ?");
  1118.         $stmt->bind_param("s", $name);
  1119.         $stmt->execute();
  1120.         $stmt->store_result();
  1121.         $stmt->bind_result($itemFetch);
  1122.         $stmt->fetch();
  1123.        
  1124.         return $itemFetch;
  1125.        
  1126.     }
  1127.    
  1128.     public static function killUser($target, $conn) {
  1129.        
  1130.         $amountLost = self::fetchTarget($target, "bank", $conn) / 100 * 25;
  1131.         $newCash = self::fetchTarget($target, "bank", $conn) - $amountLost;
  1132.        
  1133.         mysqli_query($conn, "UPDATE users SET health = '0', money = '0', bank = '$newCash', isdead = '1' WHERE username = '$target'");
  1134.        
  1135.     }
  1136.    
  1137.     public static function handleKill($name, $target, $bulamount, $conn)    {
  1138.        
  1139.         $stmt = $conn->prepare("SELECT lastkill, money, location, weapon, bullets FROM users WHERE username = ?");
  1140.         $stmt->bind_param("s", $name);
  1141.         $stmt->execute();
  1142.         $stmt->store_result();
  1143.         $stmt->bind_result($lastkill, $cash, $location, $weapon, $bullets);    
  1144.         $stmt->fetch();
  1145.        
  1146.         $targetArmour = self::fetchTarget($target, "armour", $conn);
  1147.         $targetLife = self::fetchTarget($target, "health", $conn);
  1148.         $targetCash = self::fetchTarget($target, "money", $conn);
  1149.         $targetBank = self::fetchTarget($target, "bank", $conn);
  1150.         $targetLevel = self::getLevelForXP(self::fetchTarget($target, "xp", $conn));
  1151.         $targetLoc = self::fetchTarget($target, "location", $conn);
  1152.        
  1153.         $bulletdamage = self::getWeaponStrength(self::get("r", $name, "weapon", $conn)) * $bulamount / $targetArmour / $targetLevel;
  1154.         $rounddmg = round($bulletdamage);
  1155.         $newtarglife = $targetLife - $rounddmg;
  1156.         $newbullets = $bullets - $bulamount;
  1157.        
  1158.         $rewardbank = $targetBank / 100 * 25; //Target
  1159.         $reward = $targetCash + $rewardbank; //Target
  1160.        
  1161.         $newcash = $cash + $reward;
  1162.         $curtime = time() + 3600;
  1163.        
  1164.         if ($lastkill > time()) {
  1165.             echo '<div class="alert alert-danger">You have to wait untill '.date("H:i:s", $lastkill).' to attack again.</div>';
  1166.         } else {
  1167.             if ($targetLife > 0)    {
  1168.                 if ($location == $targetLoc)    {
  1169.                     if ($bulamount <= $bullets) {
  1170.                         echo '<div class="alert alert-success">You have shot '.$target.' with '.self::bulletformat($bulamount).' bullets.</div>';
  1171.                         if ($newtarglife <= 0)  {
  1172.                             echo '<div class="alert alert-success">You have killed '.$target.' and received '.self::moneyformat($reward).'!</div>';
  1173.                             mysqli_query($conn, "UPDATE casinos SET value = '0', owner = '' WHERE owner = '$target'");
  1174.                             mysqli_query($conn, "UPDATE users SET lastkill = '$curtime', bullets = '$newbullets' WHERE username = '$name'");
  1175.                             game::killUser($target, $conn);
  1176.                             if ($cash + $reward <= maxValues)   {                      
  1177.                                 mysqli_query($conn, "UPDATE users SET money = '$newcash' WHERE username = '$name'");
  1178.                             } else {
  1179.                                 $wasted = $newcash - 5000000000;
  1180.                                 mysqli_query($conn, "UPDATE users SET money = '5000000000' WHERE username = '$name'");
  1181.                                 echo '<div class="alert alert-danger">The reward + your own money was over max cash. <br />'.game::moneyformat($wasted).' has been lost!</div>';//towaste
  1182.                             }
  1183.                         } else {
  1184.                             echo '<div class="alert alert-warning">'.$target.' has survived with '.$newtarglife.' health!</div>';
  1185.                             mysqli_query($conn, "UPDATE users SET lastkill = '$curtime', bullets = '$newbullets' WHERE username = '$name'");
  1186.                             mysqli_query($conn, "UPDATE users SET health = '$newtarglife' WHERE username = '$target'");
  1187.                         }
  1188.                     } else {
  1189.                         echo '<div class="alert alert-danger">You do not have that many bullets.</div>';
  1190.                     }
  1191.                 } else  {
  1192.                     echo '<div class="alert alert-danger">Sorry, but your target could not be found in '.$location.'.</div>';
  1193.                 }
  1194.             } else {
  1195.                 echo '<div class="alert alert-danger">This user has aleady been slaughtered.</div>';
  1196.             }
  1197.         }
  1198.     }
  1199.    
  1200. }
Add Comment
Please, Sign In to add comment