Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.31 KB | None | 0 0
  1. class roulette {
  2.     private $each_rad;
  3.     private $total_rad = 360;
  4.     private $len;
  5.     private $diced = array();
  6.     private $raw;
  7.     private $conn;
  8.     private $isrdy = false;
  9.     private $char;
  10.    
  11.     function __construct($items,$conn,$char) {
  12.         if(!isset($items)) return 0;
  13.         if(!isset($conn)) return 0;
  14.         if(!isset($char)) return 0;
  15.         if(!$this->check($char)) return 0;
  16.  
  17.        
  18.         $this->len = sizeof($items) ? sizeof($items) + 1 : 1;
  19.         $this->each_rad = $this->total_rad / $this->len;
  20.         $this->raw = $items;
  21.         $this->conn = $conn;
  22.         $this->char = $char;
  23.         $this->isrdy = true;
  24.        
  25.     }
  26.    
  27.     function dice() {
  28.         if(!$this->isrdy) return 0;
  29.         $ii = 0;
  30.         for($i = 0; $i < 360; $i+= $this->each_rad) {
  31.             $real = floor(($this->raw[$ii]->prob * $this->raw[$ii]->prob) - (($this->raw[$ii]->prob * $this->raw[$ii]->prob) / 2));
  32.             if(!$real) $real = 1;
  33.            
  34.             $this->raw[$ii]->degfrom = $i + 2;
  35.             $this->raw[$ii]->degto = ($i + $this->each_rad) - 2;
  36.             $this->raw[$ii]->deg = mt_rand($this->raw[$ii]->degfrom,$this->raw[$ii]->degto - 1);
  37.            
  38.             for($ix = 0; $ix < $real; $ix++) {
  39.                 array_push($this->diced,$this->raw[$ii]);
  40.             }
  41.             $ii++;
  42.         }
  43.         return 1;
  44.     }
  45.    
  46.     function pick($json = false) {
  47.         if(!$this->isrdy) return 0;
  48.         if(!isset($this->diced)) return 0;
  49.         if(!$this->dice()) return 0;
  50.        
  51.         $pos = mt_rand(0,sizeof($this->diced) - 1);
  52.        
  53.         $this->sendReward($this->diced[$pos]);
  54.        
  55.        
  56.         return $json ? json_encode($this->diced[$pos],true) : $this->diced[$pos];
  57.     }
  58.     function check($char) {
  59.         global $conn;
  60.         $chars = fetchchars();
  61.        
  62.        
  63.         $yes = false;
  64.         foreach($chars as $c) {
  65.             if($c["name"] == $char) {
  66.                 $yes = true;
  67.             }
  68.         }
  69.         if(!$yes) return 0;
  70.        
  71.         $user = $_SESSION["usid"];
  72.         $res = $conn->prepare("SELECT `rolls_left` FROM `users` WHERE `name` = :name AND `rolls_left` > 0");
  73.         $res->bindParam("name",$user);
  74.         $res->execute();
  75.        
  76.         if($res->rowCount() == 0) return 0;
  77.        
  78.         return 1;
  79.        
  80.     }
  81.     function sendReward($reward) {
  82.         global $conn;
  83.         $user = $_SESSION["usid"];
  84.         $res = $conn->prepare("UPDATE `users` SET `rolls_left` = `rolls_left` - 1, `total_rolls` = `total_rolls` + 1 WHERE `name` = :name");
  85.         $res->bindParam("name",$user);
  86.         $res->execute();
  87.        
  88.         $won = $reward->name;
  89.         $date = time();
  90.         $res = $conn->prepare("INSERT INTO `roulette` (`username`,`won`,`date`) VALUES (:name,:won,:date)");
  91.         $res->bindParam("name",$user);
  92.         $res->bindParam("won",$won);
  93.         $res->bindParam("date",$date);
  94.         $res->execute();
  95.        
  96.         if($reward->itemid != -1) {
  97.             $binded = "binded";
  98.             $isone = 1;
  99.             $isnone = 0;
  100.            
  101.             $q = $conn->prepare("INSERT INTO `t_donate_itens`(`userName`, `itemID`, `color`, `binding`, `smithing`, `level`, `amount`, `attr`, `isSended`) VALUES (:char,:id,:color,:indin,:smithing,:level,:amount,:attr,'0')");
  102.             $q->bindParam("char",$this->char);
  103.             $q->bindParam("id",$reward->itemid);
  104.             $q->bindParam("color",$isnone);
  105.             $q->bindParam("indin",$binded);
  106.             $q->bindParam("smithing",$isnone);
  107.             $q->bindParam("level",$isnone);
  108.             $q->bindParam("amount",$isone);
  109.             $q->bindParam("attr",$isnone);
  110.             $q->execute();
  111.         }
  112.         if($reward->pts != -1) {
  113.             $pts = $reward->pts;
  114.             $q = $conn->prepare("UPDATE `users` SET `gpoints` = `gpoints` + :panda WHERE `name` = :panda1");
  115.             $q->bindParam("panda",$pts);
  116.             $q->bindParam("panda1",$user);
  117.             $q->execute();
  118.         }
  119.     }
  120.    
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement