Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- TheMasterGeneral's Mining Mod
- Mine up items, flakes, etc.
- Copyright: 2016
- License: DBAD
- Filename: mine.php
- */
- //Gotta make sure the user is legitimate and not a bot.
- $macropage=('mine');
- require('globals.php');
- /*
- Testing to see if the user already exists in the databse,
- and if not, adding them to the database.
- */
- $UIDB=$db->query("SELECT * FROM `tmg_mining` WHERE `userid` = {$userid}");
- if (!($db->num_rows($UIDB)))
- {
- $db->query("INSERT INTO `tmg_mining`
- (`userid`, `max_miningpower`, `miningpower`, `miningxp`,
- `buyable_power`, `mining_level`)
- VALUES ('{$userid}', '100', '100', '0', '1', '1');");
- }
- //Assign their information to a variable we can access later.
- $MUS=($db->fetch_row($db->query("SELECT * FROM `tmg_mining` WHERE `userid` = {$userid} LIMIT 1")));
- //Causes a person to level up, when needed. Called on each page load while mining.
- mining_levelup();
- echo "<h2>Dangerous Mines</h2><hr />";
- //Blocks access to players who are in jail/hospital.
- if ($ir['hospital'])
- {
- echo "Only the healthy folk can go mining.";
- die($h->endpage());
- }
- if ($ir['jail'])
- {
- echo "Only the innocent folk can go mining.";
- die($h->endpage());
- }
- if (!isset($_GET['action']))
- {
- $_GET['action'] = '';
- }
- switch ($_GET['action'])
- {
- case 'mine':
- mine();
- break;
- case 'buypower':
- buypower();
- break;
- default:
- home();
- break;
- }
- function home()
- {
- global $MUS,$db,$h;
- $mineen = min((int) ($MUS['miningpower'] / $MUS['max_miningpower'] * 100), 100);
- $minexp = min((int) ($MUS['miningxp'] / $MUS['xp_needed'] * 100), 100);
- $mineenp = 100 - $mineen;
- $minexpp = 100 - $minexp;
- echo "Welcome to the dangerous mines, brainless fool.
- Riches are avaliable for you, if you have the skill.
- Each mine has its own requirements, and could even have
- a special pickaxe that you need to use.<br />
- <br />
- You currently have a mining level of {$MUS['mining_level']}.<br />
- Mining Power - {$MUS['miningpower']} / {$MUS['max_miningpower']}<br />
- <img src='yellowbar.png' width='$mineen' height='15' /><img src='redbar.png' width='$mineenp' height='15' /><br />
- Mining XP - {$MUS['miningxp']} / {$MUS['xp_needed']}<br />
- <img src='yellowbar.png' width='$minexp' height='15' /><img src='redbar.png' width='$minexpp' height='15' /><br />
- <u>Avaliable Mines:</u><br />";
- $minesql=$db->query("SELECT * FROM `tmg_mines_data` ORDER BY `mine_level` ASC");
- while ($mines = $db->fetch_row($minesql))
- {
- $CityName=$db->fetch_single($db->query("SELECT `cityname` FROM `cities` WHERE `cityid` = {$mines['mine_location']}"));
- echo"[<a href='?action=mine&spot={$mines['mine_id']}'>{$CityName} - Level {$mines['mine_level']}</a>]<br />";
- }
- echo "<br /><br />
- [<a href='?action=buypower'>Buy Power</a>]";
- }
- function buypower()
- {
- global $userid,$db,$ir,$MUS,$h;
- $CostForPower = $MUS['mining_level']*75+10+$MUS['mining_level']; //Cost formula, in IQ.
- if (isset($_POST['sets']) && ($_POST['sets'] > 0))
- {
- $sets=abs((int) $_POST['sets']);
- $totalcost=$sets*$CostForPower;
- if ($sets > $MUS['buyable_power'])
- {
- echo "You are trying to buy more sets than you currently have available.";
- die($h->endpage());
- }
- elseif (($ir['IQ'] < $totalcost))
- {
- echo "You need " . number_format($totalcost) . " IQ for the amount of sets
- you wish to buy. You only have " . number_format($ir['IQ']) . ".";
- }
- else
- {
- $db->query("UPDATE `userstats` SET `IQ` = `IQ` - '{$totalcost}' WHERE
- `userid` = {$userid}");
- $db->query("UPDATE `tmg_mining` SET `buyable_power` = `buyable_power` -
- '$sets', `max_miningpower` = `max_miningpower` + ($sets*10) WHERE `userid` = {$userid}");
- echo "You have successfully traded " . number_format($totalcost) . "
- IQ for {$sets} sets of 10 mining power! Your new maximum mining power is
- " . number_format($MUS['max_miningpower'] + ($sets*10)) . "";
- }
- }
- else
- {
- echo "You can currently buy {$MUS['buyable_power']} sets of 10 Mining Power.
- Each set will cost you " . number_format($CostForPower) . " IQ each. So, how
- many sets would you like to purchase?";
- echo "<br />
- <form method='post'>
- <input type='number' min='1' max='{$MUS['buyable_power']}' name='sets' required='1'>
- <br />
- <input type='submit' value='Buy Power'>
- </form>";
- }
- }
- function mine()
- {
- global $db,$MUS,$ir,$userid;
- if (!isset($_GET['spot']) || empty($_GET['spot']))
- {
- echo "Invalid mining spot.";
- }
- else
- {
- $spot=abs((int) $_GET['spot']);
- $mineinfo=$db->query("SELECT * FROM `tmg_mines_data` WHERE `mine_id` = {$spot}");
- //Testing for if the mine itself is in the database. If not,
- //Give them a friendly error, rather than quitting out to SQL.
- if (!($db->num_rows($mineinfo)))
- {
- echo "This mine does not exist.";
- }
- else
- {
- //If the mine is found, assign its data to a variable
- //for easy access later.
- $MSI=$db->fetch_row($mineinfo);
- if ($MUS['mining_level'] < $MSI['mine_level'])
- {
- echo "You don't have a high enough mining level to mine here.
- You need a mining level of {$MSI['mine_level']}, whereas you
- only have a mining level of {$MUS['mining_level']}.";
- }
- elseif ($ir['location'] != $MSI['mine_location'])
- {
- echo "You can only go mining in this mine if you're in the same
- location.";
- }
- elseif ($ir['IQ'] < $MSI['mine_iq'])
- {
- echo "Your IQ is too low to use this mine. You need
- " . number_format($MSI['mine_iq']) . " IQ, whereas you only have
- " . number_format($ir['IQ']) . ".";
- }
- elseif ($MUS['miningpower'] < $MSI['mine_power_use'])
- {
- echo "You do not have enough mining power to mine here. You need
- {$MSI['mine_power_use']} and you only have {$MUS['miningpower']}.";
- }
- else
- {
- //Fallback in case XP gain isn't updated later on.
- if (!isset($xpgain))
- {
- $xpgain = 0;
- }
- //If the user's IQ level is between the minimum and
- //33% higher than minimum, they get the least amount of
- //Positive outputs.
- if ($ir['IQ'] <= $MSI['mine_iq']+($MSI['mine_iq']*.3))
- {
- $Rolls=mt_rand(1,5);
- }
- //If the user's IQ level is between 30% higher than minimum
- //yet less than 60%, give them an increased chance for positive
- //outputs.
- elseif ($ir['IQ'] >= $MSI['mine_iq']+($MSI['mine_iq']*.3) && ($ir['IQ'] <= $MSI['mine_iq']+($MSI['mine_iq']*.6)))
- {
- $Rolls=mt_rand(1,10);
- }
- //If the user's IQ level is above 60% of the mine's minimum IQ,
- //Give them more rolls, and a chance to get the gem item.
- else
- {
- $Rolls=mt_rand(1,15);
- }
- //Rolls 1-3 are negative.
- if ($Rolls <= 3)
- {
- $NegRolls=mt_rand(1,3);
- //Three different outputs for the negative.
- $NegTime=mt_rand(50,100)*($MUS['mining_level']*.5);
- //Hospital
- if ($NegRolls == 1)
- {
- echo "While mining, you hit a gas pocket and ignite
- an explosion. You are found later inside the rubble,
- barely breathing.";
- //$db->query("UPDATE `users` SET `hospital`=`hospital`+{$NegTime},
- //`hospreason` = 'Gas Pocket' WHERE `userid` = {$userid}");
- }
- //Jail
- elseif ($NegRolls == 2)
- {
- echo "While mining, you and another miner spot the same vein with
- a gem in it. After a few minutes of bickering of who saw it first,
- he punches you, and a brawl begins. The cops see this and arrest you
- both.";
- //$db->query("UPDATE `users` SET `jail`=`jail`+{$NegTime},
- //`jail_reason` = 'Fighting Over a Gem' WHERE `userid` = {$userid}");
- }
- //Nothing found
- else
- {
- echo "Unlucky for you. While mining you found nothing.";
- }
- }
- //All the positive rolls. 4-14
- elseif ($Rolls >= 3 && $Rolls <= 14)
- {
- $PosRolls=mt_rand(1,3);
- //Positive has 3 rolls.
- //Output #1
- if ($PosRolls == 1)
- {
- $FlakeName=$db->fetch_single($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$MSI['mine_copper_item']}"));
- $flakes=mt_rand($MSI['mine_copper_min'],$MSI['mine_copper_max']);
- echo "You struck ore! Swing your pick away! After a few minutes,
- you managed to grab yourself " . number_format($flakes) . " {$FlakeName}(s)
- from this vein.";
- item_add($userid,$MSI['mine_copper_item'],$flakes);
- $xpgain=$flakes*0.1;
- }
- //Output #2
- elseif ($PosRolls == 2)
- {
- $FlakeName=$db->fetch_single($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$MSI['mine_silver_item']}"));
- $flakes=mt_rand($MSI['mine_copper_min'],$MSI['mine_copper_max']);
- echo "You struck ore! Swing your pick away! After a few minutes,
- you managed to grab yourself " . number_format($flakes) . " {$FlakeName}(s)
- from this vein.";
- item_add($userid,$MSI['mine_silver_item'],$flakes);
- $xpgain=$flakes*0.25;
- }
- //Output #3
- else
- {
- $FlakeName=$db->fetch_single($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$MSI['mine_gold_item']}"));
- $flakes=mt_rand($MSI['mine_copper_min'],$MSI['mine_copper_max']);
- echo "You struck ore! Swing your pick away! After a few minutes,
- you managed to grab yourself " . number_format($flakes) . " {$FlakeName}(s)
- from this vein.";
- item_add($userid,$MSI['mine_gold_item'],$flakes);
- $xpgain=$flakes*0.5;
- }
- }
- //Rolled a 15 to get a gem.
- else
- {
- $GemItemName=$db->fetch_single($db->query("SELECT `itmname` FROM `items` WHERE `itmid` = {$MSI['mine_gem_item']}"));
- echo "While mining, you expertly find a {$GemItemName} and mine it out slowly. Congratulations, man!";
- item_add($userid,$MSI['mine_gem_item'],1);
- $xpgain=1;
- }
- //Displayed at the end so players don't have to refresh.
- //Also adds mining xp, and removes mining power when needed.
- echo"<hr />
- [<a href='?action=mine&spot={$spot}'>Mine Again</a>]<br />
- [<a href='mine.php'>Pack it Up</a>]";
- $db->query("UPDATE `tmg_mining` SET `miningxp`=`miningxp`+ {$xpgain}, `miningpower`=`miningpower`-'{$MSI['mine_power_use']}' WHERE `userid` = {$userid}");
- }
- }
- }
- }
- //Function for leveling up while mining.
- function mining_levelup()
- {
- global $db,$userid,$MUS;
- //Mining XP needed for a level up.
- $MUS['xp_needed'] = (int) (($MUS['mining_level'] + 1) * ($MUS['mining_level'] + 1) * ($MUS['mining_level'] + 1) * 4.4);
- //If the user's mining XP is higher than what's needed
- if ($MUS['miningxp'] >= $MUS['xp_needed'])
- {
- $expu = $MUS['miningxp'] - $MUS['xp_needed'];
- $MUS['mining_level'] += 1;
- $MUS['miningxp'] = $expu;
- $MUS['buyable_power'] += 1;
- $MUS['xp_needed'] =
- (int) (($MUS['mining_level'] + 1) * ($MUS['mining_level'] + 1)
- * ($MUS['mining_level'] + 1) * 4.4);
- $db->query("UPDATE `tmg_mining` SET `mining_level` = `mining_level` + 1, `miningxp` = {$expu},
- `buyable_power` = `buyable_power` + 1 WHERE `userid` = {$userid}");
- }
- }
- $h->endpage();
Add Comment
Please, Sign In to add comment