Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class roulette {
- private $each_rad;
- private $total_rad = 360;
- private $len;
- private $diced = array();
- private $raw;
- private $conn;
- private $isrdy = false;
- private $char;
- function __construct($items,$conn,$char) {
- if(!isset($items)) return 0;
- if(!isset($conn)) return 0;
- if(!isset($char)) return 0;
- if(!$this->check($char)) return 0;
- $this->len = sizeof($items) ? sizeof($items) + 1 : 1;
- $this->each_rad = $this->total_rad / $this->len;
- $this->raw = $items;
- $this->conn = $conn;
- $this->char = $char;
- $this->isrdy = true;
- }
- function dice() {
- if(!$this->isrdy) return 0;
- $ii = 0;
- for($i = 0; $i < 360; $i+= $this->each_rad) {
- $real = floor(($this->raw[$ii]->prob * $this->raw[$ii]->prob) - (($this->raw[$ii]->prob * $this->raw[$ii]->prob) / 2));
- if(!$real) $real = 1;
- $this->raw[$ii]->degfrom = $i + 2;
- $this->raw[$ii]->degto = ($i + $this->each_rad) - 2;
- $this->raw[$ii]->deg = mt_rand($this->raw[$ii]->degfrom,$this->raw[$ii]->degto - 1);
- for($ix = 0; $ix < $real; $ix++) {
- array_push($this->diced,$this->raw[$ii]);
- }
- $ii++;
- }
- return 1;
- }
- function pick($json = false) {
- if(!$this->isrdy) return 0;
- if(!isset($this->diced)) return 0;
- if(!$this->dice()) return 0;
- $pos = mt_rand(0,sizeof($this->diced) - 1);
- $this->sendReward($this->diced[$pos]);
- return $json ? json_encode($this->diced[$pos],true) : $this->diced[$pos];
- }
- function check($char) {
- global $conn;
- $chars = fetchchars();
- $yes = false;
- foreach($chars as $c) {
- if($c["name"] == $char) {
- $yes = true;
- }
- }
- if(!$yes) return 0;
- $user = $_SESSION["usid"];
- $res = $conn->prepare("SELECT `rolls_left` FROM `users` WHERE `name` = :name AND `rolls_left` > 0");
- $res->bindParam("name",$user);
- $res->execute();
- if($res->rowCount() == 0) return 0;
- return 1;
- }
- function sendReward($reward) {
- global $conn;
- $user = $_SESSION["usid"];
- $res = $conn->prepare("UPDATE `users` SET `rolls_left` = `rolls_left` - 1, `total_rolls` = `total_rolls` + 1 WHERE `name` = :name");
- $res->bindParam("name",$user);
- $res->execute();
- $won = $reward->name;
- $date = time();
- $res = $conn->prepare("INSERT INTO `roulette` (`username`,`won`,`date`) VALUES (:name,:won,:date)");
- $res->bindParam("name",$user);
- $res->bindParam("won",$won);
- $res->bindParam("date",$date);
- $res->execute();
- if($reward->itemid != -1) {
- $binded = "binded";
- $isone = 1;
- $isnone = 0;
- $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')");
- $q->bindParam("char",$this->char);
- $q->bindParam("id",$reward->itemid);
- $q->bindParam("color",$isnone);
- $q->bindParam("indin",$binded);
- $q->bindParam("smithing",$isnone);
- $q->bindParam("level",$isnone);
- $q->bindParam("amount",$isone);
- $q->bindParam("attr",$isnone);
- $q->execute();
- }
- if($reward->pts != -1) {
- $pts = $reward->pts;
- $q = $conn->prepare("UPDATE `users` SET `gpoints` = `gpoints` + :panda WHERE `name` = :panda1");
- $q->bindParam("panda",$pts);
- $q->bindParam("panda1",$user);
- $q->execute();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement