Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define("CAKEDBLOC", 'cakedb.txt');
- ini_set('display_errors', 1);
- switch ($_GET['func']) {
- case "getCakeCount": // #cake (count)
- getCakeCount($_GET['arg']);
- break;
- case "obtainCakes"; // #cake get
- obtainCakes($_GET['arg']);
- break;
- case "testResponse"; // For testing
- testResponse($_GET['arg']);
- break;
- case "adventureDS"; // Dark Souls 3 Adventure
- $ircName = $_GET['arg']; // There will always be a name
- // Current list of available sub-functions:
- // #ember equip [weaponName]
- // #ember drop [weaponName]
- // #ember inventory [ircName]
- // #ember invade [targetName]
- if (empty($_GET['argTwo'])) { // If it's just #ember
- adventureDS($ircName);
- } else {
- // Split the second argument into two strings; first is subfunction and second is the arg
- $subFunc = substr($_GET['argTwo'], 0, strpos($_GET['argTwo'], " "));
- $subFuncArg = trim(substr($_GET['argTwo'], strpos($_GET['argTwo'], " ")));
- //echo("Function is \"".$subFunc."\" and argument is \"".$subFuncArg."\"");
- if (empty($subFunc)) {
- $subFunc = $subFuncArg;
- $subFuncArg = "";
- echo("You need to state a target.");
- break; }
- switch ($subFunc) {
- case "equip";
- equipDSWeapon($ircName, $subFuncArg);
- break;
- case "drop";
- dropDSWeapon($ircName, $subFuncArg);
- break;
- case "inventory";
- viewDSInventory($subFuncArg);
- break;
- case "soulless";
- viewDSSoulless($subFuncArg);
- break;
- case "log";
- viewDSLog($subFuncArg);
- break;
- case "invade";
- // Nothing for now
- break;
- default:
- echo("That command doesn't exist.");
- }
- }
- break;
- case "listRecords"; // List all records
- if (empty($_GET['arg'])) {
- listRecords();
- } else {
- listRecords($_GET['arg']); }
- break;
- default:
- echo("No AJAX request received.<br><br>");
- }
- function testResponse($ircName) { // For testing purposes
- //echo "%C9YOU %C7DIED %C4WAY %C11TOO<br>%C13MANY %C4TIMESSSSSS<br> %C11WAOHOASDASD";
- }
- // -------------------------------------------------- //
- // Classic #cake and #cake get
- function getCakeCount($ircName) { // Echos the current cake count for the user
- // Check if the DB exists first, and if not, create a new one and end
- if (file_exists(CAKEDBLOC)) {
- $ircUsers = file(CAKEDBLOC);
- $inCakeDB = false;
- foreach ($ircUsers as $curUser) {
- $checkLine = explode('|', $curUser, -1);
- if ($checkLine[0] === strtolower($ircName)) {
- $inCakeDB = true;
- if (+$checkLine[1] > 1) { // If the user has cakes
- echo("Hi %C9".$ircName.", you currently have ".$checkLine[1]." Cakes.");
- } elseif (+$checkLine[1] == 1) {
- echo("Hi %C9".$ircName.", you currently have 1 Cake.");
- } else { // If the user doesn't have cakes
- echo("Sorry %C9".$ircName.", you don't have any Cakes!"); }
- break; // We're done here
- }
- }
- // The user isn't even in the database in the first place
- if (!$inCakeDB) {
- echo("Sorry %C9".$ircName.", you don't have any Cakes! I'll give you some to start off.");
- file_put_contents(CAKEDBLOC, strtolower($ircName)."|100|0|\n", FILE_APPEND); // Add user to DB
- }
- } else {
- //echo("File does not exist.\n");
- echo("Sorry %C9".$ircName.", you don't have any Cakes!"); // No database, obviously zero
- // Create a new empty database if it doesn't exist
- $cakeDBFile = fopen(CAKEDBLOC, 'a');
- fwrite($cakeDBFile, "suwako|1000|0|\n");
- fwrite($cakeDBFile, "cirno|1000|0|\n");
- fclose($cakeDBFile);
- }
- }
- function obtainCakes($ircName) {
- // 1800 sec = 1/2 hr OR 7200s = 2hr
- $cakeDelay = 600;
- if (!file_exists(CAKEDBLOC)) { // Just in case
- $cakeDBFile = fopen(CAKEDBLOC, 'a');
- fwrite($cakeDBFile, "suwako|1000|0|\n");
- fwrite($cakeDBFile, "cirno|1000|0|\n");
- fclose($cakeDBFile); }
- $ircUsers = file(CAKEDBLOC);
- //echo "<pre>";
- //var_dump($ircUsers);
- $inCakeDB = false;
- foreach ($ircUsers as $index=>$curUser) {
- //echo("\n\n\"".$curUser."\" --- ".gettype($curUser)."\n");
- $checkLine = explode('|', $curUser, -1);
- //echo("Name is \"".$checkLine[0]."\"\n");
- if ($checkLine[0] === strtolower($ircName)) { // Make it case insensitive
- //echo("curUser is same as irc name.\n");
- $inCakeDB = true;
- $cakeCount = +$checkLine[1];
- //echo("Cakes Old: ".+$checkLine[1]." --- ".gettype(+$checkLine[1])."\n");
- if (strtolower($ircName) === "cirno" || strtolower($ircName) === "suwako") {
- echo("Yes Princess. I'll give you all of my cakes.\n");
- //echo("Princess ".$ircName.", 500 Cakes Get!\n");
- $cakeCount += 250;
- //echo("Cakes New: ".$cakeCount."\n");
- //echo("Princess, you now have ".$cakeCount." cakes!\n");
- $curUser = str_replace($curUser, strtolower($checkLine[0])."|".$cakeCount."|0|\n", $curUser);
- //echo("Edited User:\n\"".$curUser."\"\n");
- //echo("OLD ARRAY INDEX ENTRY: ".$ircUsers[$index]."\n");
- $ircUsers[$index] = $curUser;
- //echo("NEW ARRAY INDEX ENTRY: ".$ircUsers[$index]."\n");
- //var_dump($ircUsers);
- file_put_contents(CAKEDBLOC, $ircUsers);
- } else {
- // We need to see if it's been at least two hours for this user
- //echo("UNIX Time: ".time()."\n");
- //echo("USER Time: ".+$checkLine[2]."\n");
- //$checkTime = time() - 7200;
- //echo($checkTime."\n");
- //echo("Differene: ".(time() - +$checkLine[2])."\n");
- //echo(time() - +$checkLine[2]."\n".gettype(+$checkLine[2])."\n");
- // +$checkLine[2] is the time last recorded for the user
- // time() fetches the current time
- // If the difference between the two is MORE than $cakeDelay, they've waited enough
- if ((time() - +$checkLine[2]) > $cakeDelay) { // 1800 sec = 1/2 hr OR 7200s = 2hr
- //echo("The user has waited at least 2000s");
- echo("Okay %C9".$ircName.", I'll give you some Cake.\n");
- $chanceRoll = mt_rand(1,100);
- $cakeReceived = 0;
- if ($chanceRoll > 90) {
- $cakeReceived = mt_rand(101,150);
- } else {
- $cakeReceived = mt_rand(1,100); }
- if ($cakeReceived == 1) { // If they only get 1 cake
- echo("Based %C9".$ircName.". 1 Cake Get!\n");
- } else {
- echo("Based %C9".$ircName.". ".$cakeReceived." Cakes Get!\n"); }
- $cakeCount += $cakeReceived;
- //echo($ircName.", you now have ".$cakeCount." cakes!");
- $curUser = str_replace($curUser, strtolower($checkLine[0])."|".$cakeCount."|".time()."|\n", $curUser);
- //echo("OLD ARRAY INDEX ENTRY: ".$ircUsers[$index]."\n");
- $ircUsers[$index] = $curUser;
- //echo("NEW ARRAY INDEX ENTRY: ".$ircUsers[$index]."\n");
- //var_dump($ircUsers);
- file_put_contents(CAKEDBLOC, $ircUsers);
- } else { // If the user hasn't waited two hours yet
- $delayTimeMins = floor($cakeDelay/60);
- echo("Don't be greedy %C9".$ircName.", you can only ask for cake once every ".$delayTimeMins." minutes!\n");
- $remainingWait = floor(($cakeDelay - time() - +$checkLine[2]) / 60) / -1;
- // I can't figure out why the time ends up being negative, so I simply turned it back to positive
- echo("The next time you can ask for cake is ".$remainingWait." minutes.");
- }
- }
- break;
- }
- }
- if (!$inCakeDB) { // If the user isn't in the database; just a fallback function
- echo("Okay %C9".$ircName.", I'll give you some Cake.\n");
- // Gonna do a bit of RNG and make it hard (10% chance) to get over 100
- $chanceRoll = mt_rand(1,100);
- $cakeReceived = 0;
- if ($chanceRoll > 90) {
- $cakeReceived = mt_rand(101,150);
- } else {
- $cakeReceived = mt_rand(1,100); }
- //echo("Cakes Received by ".$ircName." was ".$cakeReceived."\n");
- if ($cakeReceived == 1) { // If they only get 1 cake
- echo("%C9Based %C9".$ircName.". 1 Cake Get!\n");
- //echo($ircName.", you now have 1 cake.");
- } else {
- echo("%C9Based %C9".$ircName.". ".$cakeReceived." Cakes Get!\n");
- //echo($ircName.", you now have ".$cakeReceived." cakes!");
- }
- file_put_contents(CAKEDBLOC, strtolower($ircName)."|".$cakeReceived."|".time()."|\n", FILE_APPEND); // Add user to DB
- }
- //echo "</pre>";
- }
- // -------------------------------------------------- //
- // Bakery Raid
- function raidBakery($ircName, $targetName) {
- // We need to make sure the user is online
- }
- // -------------------------------------------------- //
- // Confirmed working
- function getRecord($gameName) { // Returns the current record count of a game; only for internal functions
- if (!file_exists('records.txt')) {
- file_put_contents(dirname(__FILE__).'/records.txt', "");
- return 0; }
- $records = file('records.txt');
- // Check if the record exists first, and if not, create a new one and return zero
- foreach ($records as $index=>$record) {
- $gameData = explode('|', $record, 5);
- if ($gameData[0] == $gameName) {
- return +$gameData[2]; }
- }
- // If we exit the foreach loop, it means there's no entry. return 0
- return 0;
- }
- /*
- echo("<br>ember record: ");
- echo(getRecord("ember"));
- echo("<br>dig record: ");
- echo(getRecord("dig"));
- */
- // Confirmed working
- function setRecord($gameName, $itemValue, $ircName, $itemName) {
- $records = file('records.txt');
- foreach ($records as $index=>$record) {
- $gameData = explode('|', $record, 5);
- if ($gameData[0] == $gameName) {
- $newRecord = $gameData[0]."|".$gameData[1]."|".$itemValue."|".$ircName."|".$itemName."\n";
- $records[$index] = $newRecord;
- file_put_contents(dirname(__FILE__).'/records.txt', $records);
- return; // We're done here
- }
- }
- // If no record was found because it's the first time playing
- // Format: Game Name|Max Limit|Top Item Value|IRC Name|Item Name
- file_put_contents(dirname(__FILE__).'/records.txt', $gameName."|1000|".$itemValue."|".$ircName."|".$itemName."\n", FILE_APPEND);
- }
- //setRecord("solar","734563456","Suwako","the sky");
- // Works fine since it's the same function as getRecord()
- function getLimit($gameName) { // Returns the max limit of a game's rolls
- if (!file_exists('records.txt')) {
- file_put_contents(dirname(__FILE__).'/records.txt', "");
- return 0; }
- $records = file('records.txt');
- // Check if the record exists first, and if not, create a new one and return zero
- foreach ($records as $index=>$record) {
- $gameData = explode('|', $record, 5);
- if ($gameData[0] == $gameName) {
- return +$gameData[1]; }
- }
- // If we exit the foreach loop, it means there's no entry. return 0
- return 0;
- }
- // Works fine since it's very similar to setRecord(); only thing to keep in mind is to NOT add new line in $newRecord
- function setLimit($gameName, $newLimit) { // Changes the max limit of a game's rolls
- $records = file('records.txt');
- foreach ($records as $index=>$record) {
- $gameData = explode('|', $record, 5);
- if ($gameData[0] == $gameName) {
- $newRecord = $gameData[0]."|".$newLimit."|".$gameData[2]."|".$gameData[3]."|".$gameData[4];
- $records[$index] = $newRecord;
- file_put_contents(dirname(__FILE__).'/records.txt', $records);
- return; // We're done here
- }
- }
- // If no record was found because it's the first time playing
- // Format: Game Name|Max Limit|Top Item Value|IRC Name|Item Name
- file_put_contents(dirname(__FILE__).'/records.txt', $gameName."|".$newLimit."|0||\n", FILE_APPEND);
- }
- //setLimit("ranch","1000");
- // Confirmed working
- function listRecords($gameName = "all") { // Publicizes all records (no arg) or an individual one
- if (!file_exists('records.txt')) {
- //echo("records.txt does not exist.\n");
- file_put_contents(dirname(__FILE__).'/records.txt', ""); // Just in case
- echo("There are currently no records set."); // Obviously, if it's new, nothing
- return; // Halt it here
- } else if (filesize('records.txt') == 0) { // If the file is empty in the first place, do nothing
- echo("There are currently no records set.");
- return; }
- $records = file('records.txt');
- // Format: Game Name|Max Limit|Top Record|IRC Name|Item Name
- if ($gameName == "all") { // List all records
- foreach ($records as $index=>$record) {
- $gameData = explode('|', $record, 5);
- switch ($gameData[0]) {
- case "ember":
- // Format: Game Name|Max Limit|Top Record|IRC Name|Item Name
- // It's a bit messy since I embedded the shortcodes, but it works
- echo("%C13#ember: %C9".$gameData[3]." possesses the %C11".rtrim(str_replace(" ", " %C11", $gameData[4])).", the darkest weapon in existence materialized from %C4".number_format($gameData[2])." %C4Souls.");
- break;
- case "dig":
- echo("%C13#dig: %C9".$gameData[3]." owns the %C11".str_replace(" ", " %C11", $gameData[4]).", the darkest weapon in from %C4".number_format($gameData[2])." %C4Souls.<br>");
- break;
- default:
- echo("%C13#failed: %C9".$gameData[3]." owns the %C11".str_replace(" ", " %C11", $gameData[4]).", the best with %C4".number_format($gameData[2])." %C4value. \\n ");
- }
- }
- return; // This is here to avoid the echo at end of function for specific games
- } else if ($gameName == "ember") { // List records for DS3 ember
- // Essentially the same as above, but breaks after it's found
- foreach ($records as $index=>$record) {
- if (strpos($record, "ember|") !== false) {
- $gameData = explode('|', $record, 5);
- echo("%C13#ember: %C9".$gameData[3]." possesses the %C4".str_replace(" ", " %C4", $gameData[4]).", the darkest weapon in existence materialized from %C4".number_format($gameData[2])." %C4Souls.");
- return;
- }
- }
- }
- // If there are no records for a specific game
- echo("There are currently no records set.");
- }
- //listRecords("ember");
- // Confirmed working
- function gameFee($ircName, $gameCost, $gameDesc) { // Used to check a user's cakes, and then allow them to play or don't
- if (file_exists(CAKEDBLOC)) { // Just a check for no apparent reason
- $ircUsers = file(CAKEDBLOC);
- $inCakeDB = false;
- foreach ($ircUsers as $index=>$curUser) {
- $checkLine = explode('|', $curUser, -1);
- if ($checkLine[0] === strtolower($ircName)) {
- $inCakeDB = true;
- $cakeCount = +$checkLine[1];
- if (+$checkLine[1] >= $gameCost) { // If the user has enough cakes
- $cakeCount -= $gameCost;
- $curUser = str_replace($curUser, strtolower($checkLine[0])."|".$cakeCount."|".$checkLine[2]."|\n", $curUser);
- $ircUsers[$index] = $curUser;
- file_put_contents(CAKEDBLOC, $ircUsers);
- return 1; // Fee successfully paid; continue script
- } else { // If the user doesn't have cakes
- echo("Sorry %C9".$ircName.", it costs %C13".$gameCost." %C13Cakes to ".$gameDesc.". Please try again later!"); }
- break; // We're done here
- }
- }
- // The user isn't even in the database in the first place
- if (!$inCakeDB) {
- echo("Sorry %C9".$ircName.", you don't have any Cakes to play games! I'll give you some to start off. Please try again!");
- file_put_contents(CAKEDBLOC, strtolower($ircName)."|100|0|\n", FILE_APPEND); // Add user to DB
- }
- return 0;
- }
- }
- //echo(gameFee("newbie101","50","be embered"));
- function recordZeroItem($ircName, $gameName, $itemName) { // This might never be used
- // This functions records a zero value/weight item to a user's global profile, not just their game profile
- }
- // TO DO LIST
- // for wagering, just set an order and number of players. then, with the wagers all going into one pot, when there's one loser,
- // if we assume there's 5 players, then just divide the pot by 4 and split that among the winners. RE: 1-100 game
- // -------------------------------------------------- //
- // Dark Souls 3 Adventure
- // -------------------------------------------------- //
- // Confirmed working
- function checkDSProfile($ircName) { // Checks if the user already has a profile, and if not, it creates one
- // WARNING: The darksouls folder MUST exist, along with all of the databases!
- // Now, check if they have a profile, by checking if it doesn't exist
- // Name of file: darksouls/Suwako/Suwako_Profile.txt
- if (!file_exists(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt')) {
- // If it doesn't exist, create a new profile
- mkdir(dirname(__FILE__).'/darksouls/'.$ircName.'/', 0777, true); // Make the folder for the profile first
- // Format: Equipped Weapon|isImbued|Inventory Count|Max Inventory Size|Highest Soul Weapon's Soul Count|Last Invasion Time|isBestowedInvasion|Remaining Bestow Time
- // Defaults: Bare Hands|false|0|20|0|0|0
- file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt', "Bare Hands|false|0|20|0|0|0|0");
- // Chances are, they won't have an Inventory file either, so make it now
- // Format (one item for each line): Imbue Prefix + Weapon|isImbued|Soul Value
- file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt', "");
- file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Soulless.txt', ""); // For Soulless items
- // Create a battle log for all successful boss kills; anybody can access another person's log by querying their name
- // Format: Boss Name|Equipped Weapon|Date & Time
- file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Log.txt', "");
- } // If it does exist, then everything is already set up; continue on
- }
- //checkDSProfile("dood");
- function getEquipSoulVal($ircName) { // Returns the soul value of the currently equipped weapon
- // Return 0 if it's a new player, just in case
- if (!file_exists(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt') || filesize(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt') == 0) {
- return 0; }
- $playerData = explode('|', file_get_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt'), 8);
- $weapons = file(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt');
- // Check where the weapon is in the inventory
- // Format (one item for each line): Imbue Prefix + Weapon|isImbued|Soul Value
- foreach ($weapons as $index=>$weapon) {
- $weaponData = explode('|', $weapon, 3);
- if (strtolower($weaponData[0]) == strtolower($playerData[0])) {
- // If we find the weapon
- return +$weaponData[2]; }
- }
- return 0; // This shouldn't ever happen, but just in case
- }
- // Confirmed working
- function equipDSWeapon($ircName, $equipName) { // Equips a different weapon. Trigger: #ember equip [weapon]
- // If the inventory is empty in the first place, don't even bother
- if (!file_exists(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt') || filesize(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt') == 0) {
- echo("You don't have that weapon in your inventory!");
- return; }
- // If the user is changing to their bare hands
- $playerData = explode('|', file_get_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt'), 8);
- if (strpos(strtolower($equipName), "bare hand") !== false) {
- if ($playerData[0] == "Bare Hands") {
- echo("You're already using your bare hands!");
- } else {
- echo("You have unequipped your %C9".$playerData[0].".");
- $newData = "Bare Hands|false|".$playerData[2]."|".$playerData[3]."|".$playerData[4]."|".$playerData[5]."|".$playerData[6]."|".$playerData[7];
- file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt', $newData); }
- return;
- }
- // Otherwise, if they're equipping another weapon
- $weapons = file(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt');
- // Check if the weapon exists in inventory
- // Format (one item for each line): Imbue Prefix + Weapon|isImbued|Soul Value
- foreach ($weapons as $index=>$weapon) {
- $weaponData = explode('|', $weapon, 3);
- // The weapon name will be in all lowercase for the check, and just needs to contain all words specified
- if (strtolower($weaponData[0]) == strtolower($equipName)) { // User owns weapon; change it
- // We need to change $playerData[0] and [1] (Weapon Name and isImbued); rest unchanged
- // Defaults: Bare Hands|false|0|20|0|0|0|0
- //$playerData = explode('|', file_get_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt'), 8);
- // If the selected weapon is the same as the already equipped weapon, do nothing
- if ($weaponData[0] == $playerData[0]) {
- echo("That weapon is already equipped!");
- return; }
- // Check if this weapon is imbued
- if ($weaponData[1] === "true") {
- $newData = $weaponData[0]."|true|".$playerData[2]."|".$playerData[3]."|".$playerData[4]."|".$playerData[5]."|".$playerData[6]."|".$playerData[7];
- file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt', $newData);
- } else {
- $newData = $weaponData[0]."|false|".$playerData[2]."|".$playerData[3]."|".$playerData[4]."|".$playerData[5]."|".$playerData[6]."|".$playerData[7];
- file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt', $newData); }
- echo("%C9".$ircName." successfully equipped the %C9".str_replace(" ", " %C9", $weaponData[0])."!");
- return; // We've found the weapon; end here
- }
- }
- // User doesn't have the weapon
- echo("You don't have that weapon in your inventory!");
- }
- //equipDSWeapon("Suwako","raw pickaxe");
- // Confirmed working
- function dropDSWeapon($ircName, $dropName) { // Used to toss a weapon somebody doesn't want. Trigger: #ember drop [weapon]
- // Add a confirmation; probably better to add it in the JavaScript BEFORE the AJAX request
- if (!file_exists(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt') || filesize(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt') == 0) {
- echo("You don't own any weapons to actually drop...");
- return; }
- $weapons = file(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt');
- // Check if the weapon exists in inventory
- // Format (one item for each line): Imbue Prefix + Weapon|isImbued|Soul Value
- foreach ($weapons as $index=>$weapon) {
- $weaponData = explode('|', $weapon, 3);
- // The weapon name will be in all lowercase for the check, and just needs to contain all words specified
- if (strtolower($weaponData[0]) == strtolower($dropName)) {
- // We need to see if the weapon is currently equipped
- $playerData = explode('|', file_get_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt'), 8);
- // If the selected weapon is the same as the already equipped weapon, change it back to bare hands
- if ($weaponData[0] == $playerData[0]) {
- $newData = "Bare Hands|false|".$playerData[2]."|".$playerData[3]."|".$playerData[4]."|".$playerData[5]."|".$playerData[6]."|".$playerData[7];
- file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt', $newData);
- }
- // Remove the item from the person's inventory
- array_splice($weapons, $index, 1);
- file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt', $weapons);
- echo("You have dropped your %C9".str_replace(" ", " %C9", $weaponData[0]).".");
- // Reduce the count in the player's profile
- $inventoryCount = +$playerData[2];
- $inventoryCount--;
- $newProfile = $playerData[0]."|".$playerData[1]."|".$inventoryCount."|".$playerData[3]."|".$playerData[4]."|".$playerData[5]."|".$playerData[6]."|".$playerData[7];
- file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt', $newProfile);
- return; // We've found the weapon; don't loop
- }
- }
- // User doesn't have the weapon
- echo("You don't have that weapon in your inventory!");
- }
- //dropDSWeapon("Suwako", "raw pickaxe");
- function viewDSInventory($ircName) { // Gives a link to the user's inventory.txt. Trigger: #ember inventory [name]
- echo("Your Inventory: %C9http://kireicake.com/cakebot/darksouls/".$ircName."/".$ircName."_Inventory.txt");
- }
- function viewDSSoulless($ircName) {
- echo("Your Inventory: %C9http://kireicake.com/cakebot/darksouls/".$ircName."/".$ircName."_Soulless.txt");
- }
- function viewDSLog($ircName) { // Gives a link to the user's log.txt. Trigger: #ember log [name]
- echo("Your Log: %C9http://kireicake.com/cakebot/darksouls/".$ircName."/".$ircName."_Log.txt");
- }
- function getOwnRecord() { // Lists the user's best weapon (disregarding imbue status)
- // To find the item name, take the highest soul weapon's soul count,
- // and search the array for the matching item.
- }
- function invadeDS($ircName, $targetName) { // It costs x cakes to invade and POTENTIALLY steal a target's weapon and record, randomly. Trigger: #ember invade [targetname]
- // Rule: A user can only invade once an hour, regardless of failure or if they've gotten the bare-hand bonus
- }
- function bestowInvasion($ircName) { // If a user beats a boss bare-handed, they can invade for free for two weeks
- }
- // Confirmed working
- function allSeeingSpirit($ircName) { // Just a separate function to give an equipped weapon the All-Seeing spirit
- $playerData = explode('|', file_get_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt'), 8);
- $weapons = file(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt');
- // If the weapon is Soulless, we have to update that too
- $isSoulless = false;
- if (strpos($playerData[0], 'Soulless') !== false) $isSoulless = true;
- foreach ($weapons as $index=>$weapon) {
- $weaponData = explode('|', $weapon, 3);
- if (strtolower($weaponData[0]) == strtolower($playerData[0])) { // Found equipped weapon in inventory
- // Format: Imbue Prefix + Weapon|isImbued|Soul Value
- $weapon = str_replace($weaponData[0], "All-Seeing ".$weaponData[0], $weapon);
- $weapons[$index] = $weapon;
- file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt', $weapons);
- if ($isSoulless) {
- // We'll have to load up the Soulless list and do the same thing
- $soullessWeapons = file(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Soulless.txt');
- foreach ($soullessWeapons as $index=>$soullessWeapon) {
- $weaponData = explode('|', $soullessWeapon, 3); // We'll reuse the variable
- if (strtolower($weaponData[0]) == strtolower($playerData[0])) {
- $soullessWeapon = str_replace($weaponData[0], "All-Seeing ".$weaponData[0], $soullessWeapon);
- $soullessWeapons[$index] = $soullessWeapon;
- file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Soulless.txt', $soullessWeapons);
- break; // End this loop here
- }
- }
- }
- return; // We've found the weapon; end here
- }
- }
- }
- //allSeeingSpirit("Suwako");
- // Confirmed working
- function calcDSCost($ircName, $baseCost) { // Function for exponential increase of DS3 game cost
- // Check if the DB exists first, and if not, create a new one and return the base cost
- if (!file_exists(dirname(__FILE__).'/darksouls/DS3_Cost.txt')) {
- file_put_contents(dirname(__FILE__).'/darksouls/DS3_Cost.txt', $ircName."|".$baseCost."|".time()."|\n");
- return $baseCost; }
- $cakeDelay = 600;
- $ircUsers = file(dirname(__FILE__).'/darksouls/DS3_Cost.txt');
- foreach ($ircUsers as $index=>$curUser) {
- $checkLine = explode('|', $curUser, -1);
- if (strtolower($checkLine[0]) === strtolower($ircName)) { // If user is found in database
- if ((time() - +$checkLine[2]) > $cakeDelay) { // If it's past the delay (10 minutes), reset the cost
- $curUser = str_replace($curUser, $ircName."|".$baseCost."|".time()."|\n", $curUser);
- } else { // If the user hasn't waited 10 minutes yet
- $newCost = +$checkLine[1] * 1.5;
- if ($newCost > 500) $newCost = 500; // Limit the cost to play to 500 cakes max
- $curUser = str_replace($curUser, $ircName."|".round($newCost)."|".+$checkLine[2]."|\n", $curUser);
- }
- $ircUsers[$index] = $curUser;
- file_put_contents(dirname(__FILE__).'/darksouls/DS3_Cost.txt', $ircUsers);
- return +$checkLine[1]; // This should still be the old price
- }
- }
- // If the user isn't in the database, add them and return the basecost
- file_put_contents(dirname(__FILE__).'/darksouls/DS3_Cost.txt', $ircName."|".$baseCost."|".time()."|\n", FILE_APPEND);
- return $baseCost;
- }
- //calcDSCost("Maria",50);
- // -------------------------------------------------- //
- function adventureDS($ircName) {
- // Make sure user hasn't already played within the last 30 minutes
- // if ((time() - +$checkLine[2]) > 3600) {
- // write the rest later
- // Might not implement if balanced properly
- // Encumbered check (if player is too heavy)
- // If the player doesn't have anything, skip the check
- if (file_exists(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt')) {
- $weapons = file(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt');
- // Check if the player's inventory is full (max 10 items)
- if (count($weapons) > 10) {
- echo("You are encumbered right now, ".$ircName.". You can't go exploring until you drop some weapons.\n");
- return; }
- }
- // Pay the fee to play once; check must return TRUE to continue
- if (gameFee($ircName, calcDSCost($ircName, 50), "be embered")) {
- // If they've paid the fee, check if they're a new player, and if so, set up a new profile
- checkDSProfile($ircName);
- // Fetch various player data
- $playerData = explode('|', file_get_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt'), 8);
- $equippedWeapon = $playerData[0];
- $msgWeapon = str_replace(" ", " %C11", $equippedWeapon);
- $isImbued = $playerData[1];
- $exploreArea = ""; $enemyName = "";
- // Generate a random place
- // WARNING: The databases MUST already exist!
- if (file_exists(dirname(__FILE__).'/darksouls/DS3_Location.txt')) {
- $DS3Locations = file(dirname(__FILE__).'/darksouls/DS3_Location.txt');
- // rtrim is necessary because mt_rand for whatever reason adds a space at end
- $exploreArea = rtrim($DS3Locations[mt_rand(0,count($DS3Locations)-1)]);
- $msgArea = str_replace(" ", " %C11", $exploreArea);
- } else {
- echo("Error occurred: Missing Locations List");
- return; }
- // Initial messages
- echo(" %C9".$ircName." is reborn and prepared to die. %C9".$ircName." ventures into the depths of %C11".$msgArea.". \\n ");
- echo("..... \\n ");
- // If the user's weapon has the All-Seeing spirit
- $isAllSeeing = false;
- if (strpos($equippedWeapon, 'All-Seeing') !== false) {
- echo(" The spirit of the %C11".$msgWeapon." detects an enemy in the vicinity! \\n ");
- $isAllSeeing = true;
- // The actual code is handled below
- }
- // Roll to see whether the player is fighting a normal mob or a boss
- // A player has a 10% chance of fighting a boss
- $roll = mt_rand(1,100);
- $isBoss = false;
- if ($roll > 90) { // Fight a boss
- $DS3Bosses = file(dirname(__FILE__).'/darksouls/DS3_Boss.txt');
- $enemyName = rtrim($DS3Bosses[mt_rand(0,count($DS3Bosses)-1)]);
- $msgEnemyName = str_replace(" ", " %C4", $enemyName);
- $isBoss = true;
- echo("%C4Boss %C4encountered! %C9".$ircName." engages in battle with %C4".$msgEnemyName."! \\n ");
- echo(" %C9".$ircName." attempts to fight the %C4boss using %C11".$msgWeapon."! \\n ");
- } else if ($roll > 20) { // Fight an ordinary mob
- $DS3Enemies = file(dirname(__FILE__).'/darksouls/DS3_Enemy.txt');
- $enemyName = rtrim($DS3Enemies[mt_rand(0,count($DS3Enemies)-1)]);
- $msgEnemyName = str_replace(" ", " %C4", $enemyName);
- echo("%C4Enemy %C4encountered! %C9".$ircName." engages in battle with %C4".$msgEnemyName."! \\n ");
- echo(" %C9".$ircName." attempts to fight the enemy using %C11".$msgWeapon."! \\n ");
- } else { // There's a 20% chance of not finding anything; if nothing found, just echo and end
- if (!$isAllSeeing) { // If they don't have the All-Seeing spirit
- echo(" %C9".$ircName." wasn't lucky and couldn't find any enemy!");
- return; // Prematurely end the function here
- } else { // We need to regenerate whether it's a Boss or Enemy
- $roll = mt_rand(1,100);
- if ($roll > 90) { // Fight a boss
- $DS3Bosses = file(dirname(__FILE__).'/darksouls/DS3_Boss.txt');
- $enemyName = rtrim($DS3Bosses[mt_rand(0,count($DS3Bosses)-1)]);
- $msgEnemyName = str_replace(" ", " %C4", $enemyName);
- $isBoss = true;
- echo("%C4Boss %C4encountered! %C9".$ircName." engages in battle with %C4".$msgEnemyName."! \\n ");
- echo(" %C9".$ircName." attempts to fight the %C4boss using %C11".$msgWeapon."! \\n ");
- } else { // Fight a guaranteed ordinary mob
- $DS3Enemies = file(dirname(__FILE__).'/darksouls/DS3_Enemy.txt');
- $enemyName = rtrim($DS3Enemies[mt_rand(0,count($DS3Enemies)-1)]);
- $msgEnemyName = str_replace(" ", " %C4", $enemyName);
- echo("%C4Enemy %C4encountered! %C9".$ircName." engages in battle with %C4".$msgEnemyName."! \\n ");
- echo(" %C9".$ircName." attempts to fight the enemy using %C11".$msgWeapon."! \\n ");
- }
- }
- }
- $DS3Weapons = file(dirname(__FILE__).'/darksouls/DS3_Weapon.txt');
- // Determine if the enemy is wielding a weapon themselves; 30% chance
- $roll = mt_rand(1,100);
- $enemyWeapon = "";
- if ($roll <= 30) {
- $enemyWeapon = rtrim($DS3Weapons[mt_rand(0,count($DS3Weapons)-1)]);
- $msgEnemyWeapon = str_replace(" ", " %C11", $enemyWeapon);
- echo("Not good! The enemy is using a %C11".$msgEnemyWeapon."! It'll be hard to kill! \\n "); }
- // Calculate the probability of winning
- // If they're using their bare hands, they have a low probability of winning
- // Imbued weapons have an increased chance of winning
- // Change: Weapon above 70%+ of soul record = increased probability
- // Promotes the use of newer weapons
- $soulBonus = false;
- $lowSoulCount = false; // If their weapon's soul count is really low, do reduced damage
- $weaponSoulVal = getEquipSoulVal($ircName);
- if ($weaponSoulVal > getRecord("ember")*0.60) $soulBonus = true;
- if ($weaponSoulVal < getRecord("ember")*0.30 && $weaponSoulVal !== 0) $lowSoulCount = true;
- $isSoulless = false;
- if ($weaponSoulVal == 0) $isSoulless = true;
- $chance = 0;
- if ($isBoss) {
- $chance = 14; // Base probability; use whole numbers for no rounding
- if ($isImbued === "true") $chance += 10;
- if ($soulBonus) $chance += 6;
- if ($isSoulless) $chance += 8;
- if ($lowSoulCount) $chance -= 8;
- if ($equippedWeapon == "Bare Hands") $chance = 4;
- if (!empty($enemyWeapon)) $chance /= 2; // Chance is halved
- } else {
- $chance = 50;
- if ($isImbued === "true") $chance += 14;
- if ($soulBonus) $chance += 20;
- //if ($isSoulless) $chance += 10; // This shouldn't be on for normal weps
- if ($lowSoulCount) $chance -= 10;
- if ($equippedWeapon == "Bare Hands") $chance = 30;
- if (!empty($enemyWeapon)) $chance /= 2; // Chance is halved
- }
- // Check if the player won the fight
- $roll = mt_rand(1,100); // Reuse variable to check whether player won
- $isVictory = false;
- if ($roll <= $chance) { // This value should be less than chance, not more
- $isVictory = true;
- } else if ($isSoulless && $equippedWeapon !== "Bare Hands") { // If the person died, spoof the death message, and reroll
- echo("%C9".$ircName." missed the enemy, but the %C4Soulless %C4essence allows %C9".$ircName." to attack again! \\n ");
- $roll = mt_rand(1,100);
- if ($roll <= $chance) $isVictory = true;
- }
- if ($isVictory) { // If player won the fight
- echo("%C9".$ircName." defeated %C4".$msgEnemyName."! Congratulations! \\n ");
- // If a player killed a boss using their bare hands, they can invade for free for two weeks
- // Message: You can feel the darkness within you, hungering to invade...
- // EDIT: UNUSED ATM
- /*
- if ($isBoss && $equippedWeapon == "Bare Hands") {
- echo("... \\n ");
- echo("%C9".$ircName." feels the darkness within, hungering to invade... \\n ");
- bestowInvasion($ircName); }
- */
- $roll = mt_rand(1,1000);
- if ($roll <= 10 && strpos($equippedWeapon, 'All-Seeing') == false) { // User got an All-Seeing upgrade. 1% chance of getting it
- // Reward: Current equipped weapon is imbued with the All-Seeing essence, guaranteeing monster finds
- echo(" \\n The remains of the enemy manifests into an %C11All-Seeing %C11spirit... It merges into %C9".$ircName."'s weapon, bestowing the wielder foresight... ");
- // We need to update both the Inventory and the Profile
- allSeeingSpirit($ircName); // This must happen BEFORE the Profile change!
- $newData = "All-Seeing ".$playerData[0]."|".$playerData[1]."|".$playerData[2]."|".$playerData[3]."|".$playerData[4]."|".$playerData[5]."|".$playerData[6]."|".$playerData[7];
- file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt', $newData);
- } else if ($roll <= 10 && strpos($equippedWeapon, 'All-Seeing') !== false) { // User got an All-Seeing upgrade, but already has it
- echo(" \\n The remains of the enemy manifests into an %C11All-Seeing %C11spirit... But %C9".$ircName."'s weapon is already possessed by one... "); // Wasted reward
- } else {
- // Load up the entire weapon list for determining reward
- $wonWeapon = rtrim($DS3Weapons[mt_rand(0,count($DS3Weapons)-1)]); // Already loaded further above
- $msgWeapon = str_replace(" ", " %C11", $wonWeapon);
- // Bosses always drop imbued weapons, and that's the only way to get them
- $wonImbue = "";
- if ($isBoss) {
- $imbueList = ["Heavy","Sharp","Refined","Raw","Crystal","Simple","Fire","Chaos","Lightning","Blessed","Deep","Dark","Blood","Poison","Hollow"];
- $wonImbue = $imbueList[mt_rand(0,count($imbueList))-1]; // We need to reduce it by one since count() makes it one over
- $wonWeapon = $wonImbue." ".$wonWeapon;
- $msgImbue = str_replace(" ", " %C11", $wonImbue); // The database shouldn't have a shortcode saved
- $msgWeapon = $msgImbue." %C11".$msgWeapon;
- }
- // Check if the item is Soulless (worth 0 Souls)
- if ($roll <= 20) { // User got a Soulless item. There is a 1% chance of getting it
- echo("%C9".$ircName." scavenged its soul and found a %C11Soulless %C11".$msgWeapon."...");
- // Reward: Increased inventory space by 10
- echo(" \\n The weapon is %C11Soulless! Its unfathomable essence empowers %C9".$ircName.", increasing %C9Vitality and %C9Endurance! ");
- // Increase the max inventory size; don't increase inventory count
- $newInvSize = $playerData[3] + 10;
- $newData = $playerData[0]."|".$playerData[1]."|".$playerData[2]."|".$newInvSize."|".$playerData[4]."|".$playerData[5]."|".$playerData[6]."|".$playerData[7];
- file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt', $newData);
- // Save the item to the user's zero value inventory AND global inventory
- $invString = "";
- if (!empty($wonImbue)) { // Check if it was a boss giving an imbue
- // Store this weapon to their inventory, with isImbued = true
- // Format (one item for each line): Imbue Prefix + Weapon|isImbued|Soul Value
- $invString = "Soulless ".$wonWeapon."|true|0\n";
- } else {
- $invString = "Soulless ".$wonWeapon."|false|0\n"; }
- file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt', $invString, FILE_APPEND);
- file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Soulless.txt', $invString, FILE_APPEND);
- // GLOBAL ZERO VALUE INVENTORY SAVE CODE HERE
- //
- //
- //
- // ADD LOGGING CODE HERE
- } else { // If it's not Soulless, we need to do a lot of calculating
- echo("%C9".$ircName." scavenged its soul and found a %C11".$msgWeapon."...");
- // Check if inventory is full
- $inventoryCount = +$playerData[2];
- $inventoryMax = +$playerData[3];
- //echo("<br>inventoryCount = ".(string)$inventoryCount);
- //echo("<br>inventoryMax = ".(string)$inventoryMax);
- if ($inventoryCount >= $inventoryMax) {
- echo(" \\n ...But %C9".$ircName." is overburdened, so it was left behind...");
- // Save the history to the battle log (Note: It has to be here, sorta)
- // Format: Boss Name|Equipped Weapon|Date & Time
- $logMsg = $ircName." vanquished ".$enemyName." with a ".$equippedWeapon." at ".$exploreArea." on ".date("F j, Y, g:i a").".\n";
- file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Log.txt', $logMsg, FILE_APPEND);
- } else {
- $soulLimit = getLimit("ember"); // Fetch the current range limit
- if ($soulLimit < 1000) // Just in case
- $soulLimit = 1000;
- $soulValue = mt_rand(1, $soulLimit); // Generate a number from 1 to the limit
- // Echo the weapon found and its forged soul count
- echo(" which was materialized with %C4".number_format($soulValue)." %C4Souls...");
- // Increase the limit by 20% if the current player rolled a number within the top 10%
- if ($soulValue >= $soulLimit*0.90) {
- $soulLimit *= 1.2;
- setLimit("ember", round($soulLimit, 0, PHP_ROUND_HALF_UP)); } // Set a hard limit
- // Now, check if this is a new record
- if ($soulValue >= getRecord("ember")) { // User set a new global record
- echo(" \\n The %C4Fire %C4Keeper identifies this %C11".$msgWeapon." as the darkest of them all... Treasure it well...");
- // Update the global record
- setRecord("ember", $soulValue, $ircName, $wonWeapon);
- // CODE FOR PERSONAL BEST EMBER ITEM HERE
- //
- //
- }
- // Script is done; just some saving to do
- $saveInv = "";
- if (!empty($wonImbue)) { // If the player won against a boss and has an imbued item
- // Store this weapon to their inventory, with isImbued = true
- // Format (one item for each line): Imbue Prefix + Weapon|isImbued|Soul Value
- $invString = $wonWeapon."|true|".$soulValue."\n";
- } else { // Store this weapon to their inventory, with isImbued = false
- $invString = $wonWeapon."|false|".$soulValue."\n"; }
- file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt', $invString, FILE_APPEND);
- // Save the battle history
- $logMsg = $ircName." vanquished ".$enemyName." with a ".$equippedWeapon." at ".$exploreArea." on ".date("F j, Y, g:i a").", and found a ".$wonWeapon." from its soul.\n";
- file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Log.txt', $logMsg, FILE_APPEND);
- // Increase current inventory count
- // Don't worry about this conflicting with the Soulless save
- $inventoryCount++;
- //$newInvCount = $playerData[2] + 1;
- $newProfile = $playerData[0]."|".$playerData[1]."|".$inventoryCount."|".$playerData[3]."|".$playerData[4]."|".$playerData[5]."|".$playerData[6]."|".$playerData[7];
- file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt', $newProfile);
- }
- }
- }
- } else {
- echo("%C4".strtoupper($ircName)." %C4DIED"); }
- } else {
- echo("Sorry ".$ircName.", you can't afford the 50 Cakes needed to be embered. Try again later!"); }
- }
- //adventureDS("Suwako");
- // -------------------------------------------------- //
- // To do
- // upgrades +1 to +10 ONLY APPLY for NON soulless items
- // Any item or sets of items can be offered to upgrade to +10, where the number of items needed increases per upgrade
- // Higher tier upgrades (past +5) will need increased inventory size
- // Soulless items can be sold to upgrade a non-soulless weapon (regardless of +#) to Phantom which gives huge damage boost and is not affected by low soul debuff, but locks all future upgrades
- // To track Phantom status, add a new Name_Phantom.txt which keeps track of any Phantom items, for an additional (laggy) check (easier than trying to rewrite the current format)
- // shields + shield imbues
- // temp resin or chunk upgrades
- // sell old stuff for conversion to cakes with Yorshka
- // Add logging for soulless and all-seeing
- /*
- function setUserInfo($ircName,$cakes,$unixTime) {
- $line = $ircName."|".$cakes."|".$unixTime;
- file_put_contents($cake, $line, FILE_APPEND)
- // Format: IRCName|Cakes|LastUnixTime
- }
- function transferCakes($oldIRCName,$newIRCName) { // Used to transfer cakes between users; only I can do so
- }
- */
- /*
- -----------------------------------------------------
- Note: Basic Skeleton of Editing a File, not Appending
- -----------------------------------------------------
- $ircUsers = file(CAKEDBLOC);
- $inCakeDB = false;
- foreach ($ircUsers as $index=>$curUser) {
- $checkLine = explode('|', $curUser, -1);
- if ($checkLine[0] === strtolower($ircName)) { // Make it case insensitive
- $inCakeDB = true;
- $cakeCount = +$checkLine[1];
- $cakeCount += 250;
- $curUser = str_replace($curUser, strtolower($checkLine[0])."|".$cakeCount."|0|\n", $curUser);
- $ircUsers[$index] = $curUser;
- file_put_contents(CAKEDBLOC, $ircUsers);
- }
- break;
- }
- */
- // -------------------------------------------------- //
- ?>
Advertisement
Add Comment
Please, Sign In to add comment