You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.5 KiB
PHP
88 lines
2.5 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
/**
|
|
* https://www.sitepoint.com/php-random-number-generator/
|
|
*/
|
|
class Random {
|
|
|
|
// random seed
|
|
private static $RSeed = 0;
|
|
|
|
// set seed
|
|
public static function seed($s = 0) {
|
|
self::$RSeed = abs(intval($s)) % 9999999 + 1;
|
|
self::num();
|
|
}
|
|
|
|
// generate random number
|
|
public static function num($min = 0, $max = 9999999) {
|
|
if (self::$RSeed == 0) {
|
|
self::seed(mt_rand());
|
|
}
|
|
self::$RSeed = (self::$RSeed * 125) % 2796203;
|
|
return self::$RSeed % ($max - $min + 1) + $min;
|
|
}
|
|
|
|
}
|
|
|
|
$returndata = [
|
|
"status" => "OK",
|
|
"item" => "",
|
|
"munzee" => "",
|
|
"messages" => []
|
|
];
|
|
|
|
try {
|
|
if (strpos($VARS["code"], "munzee") > 1) {
|
|
if (!empty($VARS["latitude"]) && !empty($VARS["longitude"]) && !empty($VARS["accuracy"])) {
|
|
include 'capturemunzee.php';
|
|
}
|
|
}
|
|
} catch (Exception $ex) {
|
|
//file_put_contents("munzee.log", "Error with Munzee code: $ex\n", FILE_APPEND);
|
|
}
|
|
|
|
if ($database->has('claimedcodes', ["AND" => ['code' => $VARS["code"], 'accountid' => getRequestUser()->getUID()]])) {
|
|
$returndata['messages'][] = $Strings->get("You've already discovered that.", false);
|
|
} else {
|
|
$codearray = str_split($VARS["code"]);
|
|
|
|
$codeint = 0;
|
|
foreach ($codearray as $chr) {
|
|
$codeint += ord($chr);
|
|
}
|
|
Random::seed($codeint);
|
|
|
|
// Get all items, except ones that have no rarity, which can't be found normally
|
|
$items = $database->select("items", ["itemid", "weight"], ["weight[>]" => 0]);
|
|
$weighted = [];
|
|
|
|
foreach ($items as $item) {
|
|
for ($i = 0; $i < $item["weight"]; $i++) {
|
|
$weighted[] = $item["itemid"];
|
|
}
|
|
}
|
|
$itemid = $weighted[Random::num(0, count($weighted))];
|
|
|
|
$database->insert('inventory', ['accountid' => getRequestUser()->getUID(), 'itemid' => $itemid]);
|
|
$database->insert('claimedcodes', ['code' => $VARS["code"], 'accountid' => getRequestUser()->getUID()]);
|
|
|
|
$player = new Player(getRequestUser());
|
|
$player->stats->updateStat(PlayerStats::SCANS, 1);
|
|
$player->save();
|
|
|
|
$itemname = $database->get('items', 'itemname', ['itemid' => $itemid]);
|
|
|
|
$returndata["item"] = $itemname;
|
|
|
|
$returndata['messages'][] = $Strings->build("You found one {item}", ["item" => $itemname], false);
|
|
}
|
|
|
|
exitWithJson($returndata);
|