Nitorita

cakebot

Mar 19th, 2019
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 44.57 KB | None | 0 0
  1. <?php
  2. define("CAKEDBLOC", 'cakedb.txt');
  3. ini_set('display_errors', 1);
  4.  
  5. switch ($_GET['func']) {
  6. case "getCakeCount": // #cake (count)
  7. getCakeCount($_GET['arg']);
  8. break;
  9. case "obtainCakes"; // #cake get
  10. obtainCakes($_GET['arg']);
  11. break;
  12. case "testResponse"; // For testing
  13. testResponse($_GET['arg']);
  14. break;
  15. case "adventureDS"; // Dark Souls 3 Adventure
  16. $ircName = $_GET['arg']; // There will always be a name
  17.  
  18. // Current list of available sub-functions:
  19. // #ember equip [weaponName]
  20. // #ember drop [weaponName]
  21. // #ember inventory [ircName]
  22. // #ember invade [targetName]
  23.  
  24. if (empty($_GET['argTwo'])) { // If it's just #ember
  25. adventureDS($ircName);
  26. } else {
  27. // Split the second argument into two strings; first is subfunction and second is the arg
  28. $subFunc = substr($_GET['argTwo'], 0, strpos($_GET['argTwo'], " "));
  29. $subFuncArg = trim(substr($_GET['argTwo'], strpos($_GET['argTwo'], " ")));
  30.  
  31. //echo("Function is \"".$subFunc."\" and argument is \"".$subFuncArg."\"");
  32.  
  33. if (empty($subFunc)) {
  34. $subFunc = $subFuncArg;
  35. $subFuncArg = "";
  36. echo("You need to state a target.");
  37. break; }
  38.  
  39. switch ($subFunc) {
  40. case "equip";
  41. equipDSWeapon($ircName, $subFuncArg);
  42. break;
  43. case "drop";
  44. dropDSWeapon($ircName, $subFuncArg);
  45. break;
  46. case "inventory";
  47. viewDSInventory($subFuncArg);
  48. break;
  49. case "soulless";
  50. viewDSSoulless($subFuncArg);
  51. break;
  52. case "log";
  53. viewDSLog($subFuncArg);
  54. break;
  55. case "invade";
  56. // Nothing for now
  57. break;
  58. default:
  59. echo("That command doesn't exist.");
  60. }
  61. }
  62.  
  63. break;
  64. case "listRecords"; // List all records
  65. if (empty($_GET['arg'])) {
  66. listRecords();
  67. } else {
  68. listRecords($_GET['arg']); }
  69. break;
  70. default:
  71. echo("No AJAX request received.<br><br>");
  72. }
  73.  
  74. function testResponse($ircName) { // For testing purposes
  75. //echo "%C9YOU %C7DIED %C4WAY %C11TOO<br>%C13MANY %C4TIMESSSSSS<br> %C11WAOHOASDASD";
  76. }
  77.  
  78. // -------------------------------------------------- //
  79. // Classic #cake and #cake get
  80.  
  81. function getCakeCount($ircName) { // Echos the current cake count for the user
  82. // Check if the DB exists first, and if not, create a new one and end
  83. if (file_exists(CAKEDBLOC)) {
  84. $ircUsers = file(CAKEDBLOC);
  85.  
  86. $inCakeDB = false;
  87. foreach ($ircUsers as $curUser) {
  88. $checkLine = explode('|', $curUser, -1);
  89. if ($checkLine[0] === strtolower($ircName)) {
  90. $inCakeDB = true;
  91.  
  92. if (+$checkLine[1] > 1) { // If the user has cakes
  93. echo("Hi %C9".$ircName.", you currently have ".$checkLine[1]." Cakes.");
  94. } elseif (+$checkLine[1] == 1) {
  95. echo("Hi %C9".$ircName.", you currently have 1 Cake.");
  96. } else { // If the user doesn't have cakes
  97. echo("Sorry %C9".$ircName.", you don't have any Cakes!"); }
  98. break; // We're done here
  99. }
  100. }
  101.  
  102. // The user isn't even in the database in the first place
  103. if (!$inCakeDB) {
  104. echo("Sorry %C9".$ircName.", you don't have any Cakes! I'll give you some to start off.");
  105.  
  106. file_put_contents(CAKEDBLOC, strtolower($ircName)."|100|0|\n", FILE_APPEND); // Add user to DB
  107. }
  108. } else {
  109. //echo("File does not exist.\n");
  110. echo("Sorry %C9".$ircName.", you don't have any Cakes!"); // No database, obviously zero
  111.  
  112. // Create a new empty database if it doesn't exist
  113. $cakeDBFile = fopen(CAKEDBLOC, 'a');
  114. fwrite($cakeDBFile, "suwako|1000|0|\n");
  115. fwrite($cakeDBFile, "cirno|1000|0|\n");
  116. fclose($cakeDBFile);
  117. }
  118. }
  119.  
  120. function obtainCakes($ircName) {
  121. // 1800 sec = 1/2 hr OR 7200s = 2hr
  122. $cakeDelay = 600;
  123.  
  124. if (!file_exists(CAKEDBLOC)) { // Just in case
  125. $cakeDBFile = fopen(CAKEDBLOC, 'a');
  126. fwrite($cakeDBFile, "suwako|1000|0|\n");
  127. fwrite($cakeDBFile, "cirno|1000|0|\n");
  128. fclose($cakeDBFile); }
  129.  
  130. $ircUsers = file(CAKEDBLOC);
  131. //echo "<pre>";
  132. //var_dump($ircUsers);
  133.  
  134. $inCakeDB = false;
  135. foreach ($ircUsers as $index=>$curUser) {
  136. //echo("\n\n\"".$curUser."\" --- ".gettype($curUser)."\n");
  137. $checkLine = explode('|', $curUser, -1);
  138. //echo("Name is \"".$checkLine[0]."\"\n");
  139.  
  140. if ($checkLine[0] === strtolower($ircName)) { // Make it case insensitive
  141. //echo("curUser is same as irc name.\n");
  142. $inCakeDB = true;
  143.  
  144. $cakeCount = +$checkLine[1];
  145.  
  146. //echo("Cakes Old: ".+$checkLine[1]." --- ".gettype(+$checkLine[1])."\n");
  147.  
  148. if (strtolower($ircName) === "cirno" || strtolower($ircName) === "suwako") {
  149. echo("Yes Princess. I'll give you all of my cakes.\n");
  150. //echo("Princess ".$ircName.", 500 Cakes Get!\n");
  151.  
  152. $cakeCount += 250;
  153. //echo("Cakes New: ".$cakeCount."\n");
  154. //echo("Princess, you now have ".$cakeCount." cakes!\n");
  155.  
  156. $curUser = str_replace($curUser, strtolower($checkLine[0])."|".$cakeCount."|0|\n", $curUser);
  157. //echo("Edited User:\n\"".$curUser."\"\n");
  158.  
  159. //echo("OLD ARRAY INDEX ENTRY: ".$ircUsers[$index]."\n");
  160. $ircUsers[$index] = $curUser;
  161. //echo("NEW ARRAY INDEX ENTRY: ".$ircUsers[$index]."\n");
  162.  
  163. //var_dump($ircUsers);
  164. file_put_contents(CAKEDBLOC, $ircUsers);
  165. } else {
  166. // We need to see if it's been at least two hours for this user
  167. //echo("UNIX Time: ".time()."\n");
  168. //echo("USER Time: ".+$checkLine[2]."\n");
  169. //$checkTime = time() - 7200;
  170. //echo($checkTime."\n");
  171. //echo("Differene: ".(time() - +$checkLine[2])."\n");
  172. //echo(time() - +$checkLine[2]."\n".gettype(+$checkLine[2])."\n");
  173.  
  174. // +$checkLine[2] is the time last recorded for the user
  175. // time() fetches the current time
  176. // If the difference between the two is MORE than $cakeDelay, they've waited enough
  177. if ((time() - +$checkLine[2]) > $cakeDelay) { // 1800 sec = 1/2 hr OR 7200s = 2hr
  178. //echo("The user has waited at least 2000s");
  179. echo("Okay %C9".$ircName.", I'll give you some Cake.\n");
  180.  
  181. $chanceRoll = mt_rand(1,100);
  182. $cakeReceived = 0;
  183. if ($chanceRoll > 90) {
  184. $cakeReceived = mt_rand(101,150);
  185. } else {
  186. $cakeReceived = mt_rand(1,100); }
  187.  
  188. if ($cakeReceived == 1) { // If they only get 1 cake
  189. echo("Based %C9".$ircName.". 1 Cake Get!\n");
  190. } else {
  191. echo("Based %C9".$ircName.". ".$cakeReceived." Cakes Get!\n"); }
  192.  
  193. $cakeCount += $cakeReceived;
  194.  
  195. //echo($ircName.", you now have ".$cakeCount." cakes!");
  196.  
  197. $curUser = str_replace($curUser, strtolower($checkLine[0])."|".$cakeCount."|".time()."|\n", $curUser);
  198.  
  199. //echo("OLD ARRAY INDEX ENTRY: ".$ircUsers[$index]."\n");
  200. $ircUsers[$index] = $curUser;
  201. //echo("NEW ARRAY INDEX ENTRY: ".$ircUsers[$index]."\n");
  202.  
  203. //var_dump($ircUsers);
  204. file_put_contents(CAKEDBLOC, $ircUsers);
  205. } else { // If the user hasn't waited two hours yet
  206. $delayTimeMins = floor($cakeDelay/60);
  207. echo("Don't be greedy %C9".$ircName.", you can only ask for cake once every ".$delayTimeMins." minutes!\n");
  208.  
  209. $remainingWait = floor(($cakeDelay - time() - +$checkLine[2]) / 60) / -1;
  210. // I can't figure out why the time ends up being negative, so I simply turned it back to positive
  211. echo("The next time you can ask for cake is ".$remainingWait." minutes.");
  212. }
  213. }
  214. break;
  215. }
  216. }
  217.  
  218. if (!$inCakeDB) { // If the user isn't in the database; just a fallback function
  219. echo("Okay %C9".$ircName.", I'll give you some Cake.\n");
  220.  
  221. // Gonna do a bit of RNG and make it hard (10% chance) to get over 100
  222. $chanceRoll = mt_rand(1,100);
  223. $cakeReceived = 0;
  224. if ($chanceRoll > 90) {
  225. $cakeReceived = mt_rand(101,150);
  226. } else {
  227. $cakeReceived = mt_rand(1,100); }
  228.  
  229. //echo("Cakes Received by ".$ircName." was ".$cakeReceived."\n");
  230.  
  231. if ($cakeReceived == 1) { // If they only get 1 cake
  232. echo("%C9Based %C9".$ircName.". 1 Cake Get!\n");
  233. //echo($ircName.", you now have 1 cake.");
  234. } else {
  235. echo("%C9Based %C9".$ircName.". ".$cakeReceived." Cakes Get!\n");
  236. //echo($ircName.", you now have ".$cakeReceived." cakes!");
  237. }
  238.  
  239. file_put_contents(CAKEDBLOC, strtolower($ircName)."|".$cakeReceived."|".time()."|\n", FILE_APPEND); // Add user to DB
  240. }
  241.  
  242. //echo "</pre>";
  243. }
  244.  
  245. // -------------------------------------------------- //
  246. // Bakery Raid
  247.  
  248. function raidBakery($ircName, $targetName) {
  249. // We need to make sure the user is online
  250. }
  251.  
  252. // -------------------------------------------------- //
  253.  
  254. // Confirmed working
  255. function getRecord($gameName) { // Returns the current record count of a game; only for internal functions
  256. if (!file_exists('records.txt')) {
  257. file_put_contents(dirname(__FILE__).'/records.txt', "");
  258. return 0; }
  259.  
  260. $records = file('records.txt');
  261.  
  262. // Check if the record exists first, and if not, create a new one and return zero
  263. foreach ($records as $index=>$record) {
  264. $gameData = explode('|', $record, 5);
  265. if ($gameData[0] == $gameName) {
  266. return +$gameData[2]; }
  267. }
  268.  
  269. // If we exit the foreach loop, it means there's no entry. return 0
  270. return 0;
  271. }
  272. /*
  273. echo("<br>ember record: ");
  274. echo(getRecord("ember"));
  275. echo("<br>dig record: ");
  276. echo(getRecord("dig"));
  277. */
  278.  
  279. // Confirmed working
  280. function setRecord($gameName, $itemValue, $ircName, $itemName) {
  281. $records = file('records.txt');
  282.  
  283. foreach ($records as $index=>$record) {
  284. $gameData = explode('|', $record, 5);
  285. if ($gameData[0] == $gameName) {
  286. $newRecord = $gameData[0]."|".$gameData[1]."|".$itemValue."|".$ircName."|".$itemName."\n";
  287.  
  288. $records[$index] = $newRecord;
  289. file_put_contents(dirname(__FILE__).'/records.txt', $records);
  290.  
  291. return; // We're done here
  292. }
  293. }
  294.  
  295. // If no record was found because it's the first time playing
  296. // Format: Game Name|Max Limit|Top Item Value|IRC Name|Item Name
  297. file_put_contents(dirname(__FILE__).'/records.txt', $gameName."|1000|".$itemValue."|".$ircName."|".$itemName."\n", FILE_APPEND);
  298. }
  299. //setRecord("solar","734563456","Suwako","the sky");
  300.  
  301. // Works fine since it's the same function as getRecord()
  302. function getLimit($gameName) { // Returns the max limit of a game's rolls
  303. if (!file_exists('records.txt')) {
  304. file_put_contents(dirname(__FILE__).'/records.txt', "");
  305. return 0; }
  306.  
  307. $records = file('records.txt');
  308.  
  309. // Check if the record exists first, and if not, create a new one and return zero
  310. foreach ($records as $index=>$record) {
  311. $gameData = explode('|', $record, 5);
  312. if ($gameData[0] == $gameName) {
  313. return +$gameData[1]; }
  314. }
  315.  
  316. // If we exit the foreach loop, it means there's no entry. return 0
  317. return 0;
  318. }
  319.  
  320. // Works fine since it's very similar to setRecord(); only thing to keep in mind is to NOT add new line in $newRecord
  321. function setLimit($gameName, $newLimit) { // Changes the max limit of a game's rolls
  322. $records = file('records.txt');
  323.  
  324. foreach ($records as $index=>$record) {
  325. $gameData = explode('|', $record, 5);
  326. if ($gameData[0] == $gameName) {
  327. $newRecord = $gameData[0]."|".$newLimit."|".$gameData[2]."|".$gameData[3]."|".$gameData[4];
  328.  
  329. $records[$index] = $newRecord;
  330. file_put_contents(dirname(__FILE__).'/records.txt', $records);
  331.  
  332. return; // We're done here
  333. }
  334. }
  335.  
  336. // If no record was found because it's the first time playing
  337. // Format: Game Name|Max Limit|Top Item Value|IRC Name|Item Name
  338. file_put_contents(dirname(__FILE__).'/records.txt', $gameName."|".$newLimit."|0||\n", FILE_APPEND);
  339. }
  340. //setLimit("ranch","1000");
  341.  
  342. // Confirmed working
  343. function listRecords($gameName = "all") { // Publicizes all records (no arg) or an individual one
  344. if (!file_exists('records.txt')) {
  345. //echo("records.txt does not exist.\n");
  346. file_put_contents(dirname(__FILE__).'/records.txt', ""); // Just in case
  347. echo("There are currently no records set."); // Obviously, if it's new, nothing
  348. return; // Halt it here
  349. } else if (filesize('records.txt') == 0) { // If the file is empty in the first place, do nothing
  350. echo("There are currently no records set.");
  351. return; }
  352.  
  353. $records = file('records.txt');
  354.  
  355. // Format: Game Name|Max Limit|Top Record|IRC Name|Item Name
  356. if ($gameName == "all") { // List all records
  357. foreach ($records as $index=>$record) {
  358. $gameData = explode('|', $record, 5);
  359.  
  360. switch ($gameData[0]) {
  361. case "ember":
  362. // Format: Game Name|Max Limit|Top Record|IRC Name|Item Name
  363. // It's a bit messy since I embedded the shortcodes, but it works
  364. 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.");
  365. break;
  366. case "dig":
  367. 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>");
  368. break;
  369. default:
  370. echo("%C13#failed: %C9".$gameData[3]." owns the %C11".str_replace(" ", " %C11", $gameData[4]).", the best with %C4".number_format($gameData[2])." %C4value. \\n ");
  371. }
  372. }
  373.  
  374. return; // This is here to avoid the echo at end of function for specific games
  375. } else if ($gameName == "ember") { // List records for DS3 ember
  376. // Essentially the same as above, but breaks after it's found
  377. foreach ($records as $index=>$record) {
  378. if (strpos($record, "ember|") !== false) {
  379. $gameData = explode('|', $record, 5);
  380.  
  381. 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.");
  382.  
  383. return;
  384. }
  385. }
  386. }
  387. // If there are no records for a specific game
  388. echo("There are currently no records set.");
  389. }
  390. //listRecords("ember");
  391.  
  392. // Confirmed working
  393. function gameFee($ircName, $gameCost, $gameDesc) { // Used to check a user's cakes, and then allow them to play or don't
  394. if (file_exists(CAKEDBLOC)) { // Just a check for no apparent reason
  395. $ircUsers = file(CAKEDBLOC);
  396.  
  397. $inCakeDB = false;
  398. foreach ($ircUsers as $index=>$curUser) {
  399. $checkLine = explode('|', $curUser, -1);
  400. if ($checkLine[0] === strtolower($ircName)) {
  401. $inCakeDB = true;
  402.  
  403. $cakeCount = +$checkLine[1];
  404.  
  405. if (+$checkLine[1] >= $gameCost) { // If the user has enough cakes
  406. $cakeCount -= $gameCost;
  407.  
  408. $curUser = str_replace($curUser, strtolower($checkLine[0])."|".$cakeCount."|".$checkLine[2]."|\n", $curUser);
  409.  
  410. $ircUsers[$index] = $curUser;
  411. file_put_contents(CAKEDBLOC, $ircUsers);
  412.  
  413. return 1; // Fee successfully paid; continue script
  414. } else { // If the user doesn't have cakes
  415. echo("Sorry %C9".$ircName.", it costs %C13".$gameCost." %C13Cakes to ".$gameDesc.". Please try again later!"); }
  416.  
  417. break; // We're done here
  418. }
  419. }
  420.  
  421. // The user isn't even in the database in the first place
  422. if (!$inCakeDB) {
  423. echo("Sorry %C9".$ircName.", you don't have any Cakes to play games! I'll give you some to start off. Please try again!");
  424. file_put_contents(CAKEDBLOC, strtolower($ircName)."|100|0|\n", FILE_APPEND); // Add user to DB
  425. }
  426.  
  427. return 0;
  428. }
  429. }
  430. //echo(gameFee("newbie101","50","be embered"));
  431.  
  432. function recordZeroItem($ircName, $gameName, $itemName) { // This might never be used
  433. // This functions records a zero value/weight item to a user's global profile, not just their game profile
  434. }
  435.  
  436. // TO DO LIST
  437. // for wagering, just set an order and number of players. then, with the wagers all going into one pot, when there's one loser,
  438. // if we assume there's 5 players, then just divide the pot by 4 and split that among the winners. RE: 1-100 game
  439.  
  440.  
  441. // -------------------------------------------------- //
  442. // Dark Souls 3 Adventure
  443. // -------------------------------------------------- //
  444. // Confirmed working
  445. function checkDSProfile($ircName) { // Checks if the user already has a profile, and if not, it creates one
  446. // WARNING: The darksouls folder MUST exist, along with all of the databases!
  447.  
  448. // Now, check if they have a profile, by checking if it doesn't exist
  449. // Name of file: darksouls/Suwako/Suwako_Profile.txt
  450. if (!file_exists(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt')) {
  451. // If it doesn't exist, create a new profile
  452. mkdir(dirname(__FILE__).'/darksouls/'.$ircName.'/', 0777, true); // Make the folder for the profile first
  453.  
  454. // Format: Equipped Weapon|isImbued|Inventory Count|Max Inventory Size|Highest Soul Weapon's Soul Count|Last Invasion Time|isBestowedInvasion|Remaining Bestow Time
  455. // Defaults: Bare Hands|false|0|20|0|0|0
  456. file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt', "Bare Hands|false|0|20|0|0|0|0");
  457.  
  458. // Chances are, they won't have an Inventory file either, so make it now
  459. // Format (one item for each line): Imbue Prefix + Weapon|isImbued|Soul Value
  460. file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt', "");
  461. file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Soulless.txt', ""); // For Soulless items
  462.  
  463. // Create a battle log for all successful boss kills; anybody can access another person's log by querying their name
  464. // Format: Boss Name|Equipped Weapon|Date & Time
  465. file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Log.txt', "");
  466. } // If it does exist, then everything is already set up; continue on
  467. }
  468. //checkDSProfile("dood");
  469.  
  470. function getEquipSoulVal($ircName) { // Returns the soul value of the currently equipped weapon
  471. // Return 0 if it's a new player, just in case
  472. if (!file_exists(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt') || filesize(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt') == 0) {
  473. return 0; }
  474.  
  475. $playerData = explode('|', file_get_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt'), 8);
  476. $weapons = file(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt');
  477.  
  478. // Check where the weapon is in the inventory
  479. // Format (one item for each line): Imbue Prefix + Weapon|isImbued|Soul Value
  480. foreach ($weapons as $index=>$weapon) {
  481. $weaponData = explode('|', $weapon, 3);
  482.  
  483. if (strtolower($weaponData[0]) == strtolower($playerData[0])) {
  484. // If we find the weapon
  485. return +$weaponData[2]; }
  486. }
  487. return 0; // This shouldn't ever happen, but just in case
  488. }
  489.  
  490. // Confirmed working
  491. function equipDSWeapon($ircName, $equipName) { // Equips a different weapon. Trigger: #ember equip [weapon]
  492. // If the inventory is empty in the first place, don't even bother
  493. if (!file_exists(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt') || filesize(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt') == 0) {
  494. echo("You don't have that weapon in your inventory!");
  495. return; }
  496.  
  497. // If the user is changing to their bare hands
  498. $playerData = explode('|', file_get_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt'), 8);
  499.  
  500. if (strpos(strtolower($equipName), "bare hand") !== false) {
  501. if ($playerData[0] == "Bare Hands") {
  502. echo("You're already using your bare hands!");
  503. } else {
  504. echo("You have unequipped your %C9".$playerData[0].".");
  505.  
  506. $newData = "Bare Hands|false|".$playerData[2]."|".$playerData[3]."|".$playerData[4]."|".$playerData[5]."|".$playerData[6]."|".$playerData[7];
  507. file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt', $newData); }
  508. return;
  509. }
  510.  
  511. // Otherwise, if they're equipping another weapon
  512. $weapons = file(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt');
  513.  
  514. // Check if the weapon exists in inventory
  515. // Format (one item for each line): Imbue Prefix + Weapon|isImbued|Soul Value
  516. foreach ($weapons as $index=>$weapon) {
  517. $weaponData = explode('|', $weapon, 3);
  518.  
  519. // The weapon name will be in all lowercase for the check, and just needs to contain all words specified
  520. if (strtolower($weaponData[0]) == strtolower($equipName)) { // User owns weapon; change it
  521. // We need to change $playerData[0] and [1] (Weapon Name and isImbued); rest unchanged
  522. // Defaults: Bare Hands|false|0|20|0|0|0|0
  523. //$playerData = explode('|', file_get_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt'), 8);
  524.  
  525. // If the selected weapon is the same as the already equipped weapon, do nothing
  526. if ($weaponData[0] == $playerData[0]) {
  527. echo("That weapon is already equipped!");
  528. return; }
  529.  
  530. // Check if this weapon is imbued
  531. if ($weaponData[1] === "true") {
  532. $newData = $weaponData[0]."|true|".$playerData[2]."|".$playerData[3]."|".$playerData[4]."|".$playerData[5]."|".$playerData[6]."|".$playerData[7];
  533. file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt', $newData);
  534. } else {
  535. $newData = $weaponData[0]."|false|".$playerData[2]."|".$playerData[3]."|".$playerData[4]."|".$playerData[5]."|".$playerData[6]."|".$playerData[7];
  536. file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt', $newData); }
  537.  
  538. echo("%C9".$ircName." successfully equipped the %C9".str_replace(" ", " %C9", $weaponData[0])."!");
  539. return; // We've found the weapon; end here
  540. }
  541. }
  542.  
  543. // User doesn't have the weapon
  544. echo("You don't have that weapon in your inventory!");
  545. }
  546. //equipDSWeapon("Suwako","raw pickaxe");
  547.  
  548. // Confirmed working
  549. function dropDSWeapon($ircName, $dropName) { // Used to toss a weapon somebody doesn't want. Trigger: #ember drop [weapon]
  550. // Add a confirmation; probably better to add it in the JavaScript BEFORE the AJAX request
  551.  
  552. if (!file_exists(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt') || filesize(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt') == 0) {
  553. echo("You don't own any weapons to actually drop...");
  554. return; }
  555.  
  556. $weapons = file(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt');
  557.  
  558. // Check if the weapon exists in inventory
  559. // Format (one item for each line): Imbue Prefix + Weapon|isImbued|Soul Value
  560. foreach ($weapons as $index=>$weapon) {
  561. $weaponData = explode('|', $weapon, 3);
  562.  
  563. // The weapon name will be in all lowercase for the check, and just needs to contain all words specified
  564. if (strtolower($weaponData[0]) == strtolower($dropName)) {
  565. // We need to see if the weapon is currently equipped
  566. $playerData = explode('|', file_get_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt'), 8);
  567.  
  568. // If the selected weapon is the same as the already equipped weapon, change it back to bare hands
  569. if ($weaponData[0] == $playerData[0]) {
  570. $newData = "Bare Hands|false|".$playerData[2]."|".$playerData[3]."|".$playerData[4]."|".$playerData[5]."|".$playerData[6]."|".$playerData[7];
  571. file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt', $newData);
  572. }
  573.  
  574. // Remove the item from the person's inventory
  575. array_splice($weapons, $index, 1);
  576. file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt', $weapons);
  577.  
  578. echo("You have dropped your %C9".str_replace(" ", " %C9", $weaponData[0]).".");
  579.  
  580. // Reduce the count in the player's profile
  581. $inventoryCount = +$playerData[2];
  582. $inventoryCount--;
  583.  
  584. $newProfile = $playerData[0]."|".$playerData[1]."|".$inventoryCount."|".$playerData[3]."|".$playerData[4]."|".$playerData[5]."|".$playerData[6]."|".$playerData[7];
  585. file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt', $newProfile);
  586.  
  587. return; // We've found the weapon; don't loop
  588. }
  589. }
  590.  
  591. // User doesn't have the weapon
  592. echo("You don't have that weapon in your inventory!");
  593. }
  594. //dropDSWeapon("Suwako", "raw pickaxe");
  595.  
  596. function viewDSInventory($ircName) { // Gives a link to the user's inventory.txt. Trigger: #ember inventory [name]
  597. echo("Your Inventory: %C9http://kireicake.com/cakebot/darksouls/".$ircName."/".$ircName."_Inventory.txt");
  598. }
  599.  
  600. function viewDSSoulless($ircName) {
  601. echo("Your Inventory: %C9http://kireicake.com/cakebot/darksouls/".$ircName."/".$ircName."_Soulless.txt");
  602. }
  603.  
  604. function viewDSLog($ircName) { // Gives a link to the user's log.txt. Trigger: #ember log [name]
  605. echo("Your Log: %C9http://kireicake.com/cakebot/darksouls/".$ircName."/".$ircName."_Log.txt");
  606. }
  607.  
  608. function getOwnRecord() { // Lists the user's best weapon (disregarding imbue status)
  609. // To find the item name, take the highest soul weapon's soul count,
  610. // and search the array for the matching item.
  611. }
  612.  
  613. function invadeDS($ircName, $targetName) { // It costs x cakes to invade and POTENTIALLY steal a target's weapon and record, randomly. Trigger: #ember invade [targetname]
  614. // Rule: A user can only invade once an hour, regardless of failure or if they've gotten the bare-hand bonus
  615. }
  616.  
  617. function bestowInvasion($ircName) { // If a user beats a boss bare-handed, they can invade for free for two weeks
  618.  
  619. }
  620.  
  621. // Confirmed working
  622. function allSeeingSpirit($ircName) { // Just a separate function to give an equipped weapon the All-Seeing spirit
  623. $playerData = explode('|', file_get_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt'), 8);
  624. $weapons = file(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt');
  625.  
  626. // If the weapon is Soulless, we have to update that too
  627. $isSoulless = false;
  628. if (strpos($playerData[0], 'Soulless') !== false) $isSoulless = true;
  629.  
  630. foreach ($weapons as $index=>$weapon) {
  631. $weaponData = explode('|', $weapon, 3);
  632.  
  633. if (strtolower($weaponData[0]) == strtolower($playerData[0])) { // Found equipped weapon in inventory
  634. // Format: Imbue Prefix + Weapon|isImbued|Soul Value
  635. $weapon = str_replace($weaponData[0], "All-Seeing ".$weaponData[0], $weapon);
  636.  
  637. $weapons[$index] = $weapon;
  638. file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt', $weapons);
  639.  
  640. if ($isSoulless) {
  641. // We'll have to load up the Soulless list and do the same thing
  642. $soullessWeapons = file(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Soulless.txt');
  643. foreach ($soullessWeapons as $index=>$soullessWeapon) {
  644. $weaponData = explode('|', $soullessWeapon, 3); // We'll reuse the variable
  645.  
  646. if (strtolower($weaponData[0]) == strtolower($playerData[0])) {
  647. $soullessWeapon = str_replace($weaponData[0], "All-Seeing ".$weaponData[0], $soullessWeapon);
  648.  
  649. $soullessWeapons[$index] = $soullessWeapon;
  650. file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Soulless.txt', $soullessWeapons);
  651.  
  652. break; // End this loop here
  653. }
  654. }
  655. }
  656.  
  657. return; // We've found the weapon; end here
  658. }
  659. }
  660. }
  661. //allSeeingSpirit("Suwako");
  662.  
  663. // Confirmed working
  664. function calcDSCost($ircName, $baseCost) { // Function for exponential increase of DS3 game cost
  665. // Check if the DB exists first, and if not, create a new one and return the base cost
  666. if (!file_exists(dirname(__FILE__).'/darksouls/DS3_Cost.txt')) {
  667. file_put_contents(dirname(__FILE__).'/darksouls/DS3_Cost.txt', $ircName."|".$baseCost."|".time()."|\n");
  668. return $baseCost; }
  669.  
  670. $cakeDelay = 600;
  671.  
  672. $ircUsers = file(dirname(__FILE__).'/darksouls/DS3_Cost.txt');
  673. foreach ($ircUsers as $index=>$curUser) {
  674. $checkLine = explode('|', $curUser, -1);
  675.  
  676. if (strtolower($checkLine[0]) === strtolower($ircName)) { // If user is found in database
  677. if ((time() - +$checkLine[2]) > $cakeDelay) { // If it's past the delay (10 minutes), reset the cost
  678. $curUser = str_replace($curUser, $ircName."|".$baseCost."|".time()."|\n", $curUser);
  679. } else { // If the user hasn't waited 10 minutes yet
  680. $newCost = +$checkLine[1] * 1.5;
  681. if ($newCost > 500) $newCost = 500; // Limit the cost to play to 500 cakes max
  682. $curUser = str_replace($curUser, $ircName."|".round($newCost)."|".+$checkLine[2]."|\n", $curUser);
  683. }
  684.  
  685. $ircUsers[$index] = $curUser;
  686. file_put_contents(dirname(__FILE__).'/darksouls/DS3_Cost.txt', $ircUsers);
  687.  
  688. return +$checkLine[1]; // This should still be the old price
  689. }
  690.  
  691. }
  692. // If the user isn't in the database, add them and return the basecost
  693. file_put_contents(dirname(__FILE__).'/darksouls/DS3_Cost.txt', $ircName."|".$baseCost."|".time()."|\n", FILE_APPEND);
  694. return $baseCost;
  695. }
  696. //calcDSCost("Maria",50);
  697.  
  698. // -------------------------------------------------- //
  699. function adventureDS($ircName) {
  700. // Make sure user hasn't already played within the last 30 minutes
  701. // if ((time() - +$checkLine[2]) > 3600) {
  702. // write the rest later
  703. // Might not implement if balanced properly
  704.  
  705. // Encumbered check (if player is too heavy)
  706. // If the player doesn't have anything, skip the check
  707. if (file_exists(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt')) {
  708. $weapons = file(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt');
  709.  
  710. // Check if the player's inventory is full (max 10 items)
  711. if (count($weapons) > 10) {
  712. echo("You are encumbered right now, ".$ircName.". You can't go exploring until you drop some weapons.\n");
  713. return; }
  714. }
  715.  
  716. // Pay the fee to play once; check must return TRUE to continue
  717. if (gameFee($ircName, calcDSCost($ircName, 50), "be embered")) {
  718. // If they've paid the fee, check if they're a new player, and if so, set up a new profile
  719. checkDSProfile($ircName);
  720.  
  721. // Fetch various player data
  722. $playerData = explode('|', file_get_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt'), 8);
  723. $equippedWeapon = $playerData[0];
  724. $msgWeapon = str_replace(" ", " %C11", $equippedWeapon);
  725. $isImbued = $playerData[1];
  726.  
  727. $exploreArea = ""; $enemyName = "";
  728.  
  729. // Generate a random place
  730. // WARNING: The databases MUST already exist!
  731. if (file_exists(dirname(__FILE__).'/darksouls/DS3_Location.txt')) {
  732. $DS3Locations = file(dirname(__FILE__).'/darksouls/DS3_Location.txt');
  733. // rtrim is necessary because mt_rand for whatever reason adds a space at end
  734. $exploreArea = rtrim($DS3Locations[mt_rand(0,count($DS3Locations)-1)]);
  735. $msgArea = str_replace(" ", " %C11", $exploreArea);
  736. } else {
  737. echo("Error occurred: Missing Locations List");
  738. return; }
  739.  
  740. // Initial messages
  741. echo(" %C9".$ircName." is reborn and prepared to die. %C9".$ircName." ventures into the depths of %C11".$msgArea.". \\n ");
  742. echo("..... \\n ");
  743.  
  744. // If the user's weapon has the All-Seeing spirit
  745. $isAllSeeing = false;
  746. if (strpos($equippedWeapon, 'All-Seeing') !== false) {
  747. echo(" The spirit of the %C11".$msgWeapon." detects an enemy in the vicinity! \\n ");
  748. $isAllSeeing = true;
  749. // The actual code is handled below
  750. }
  751.  
  752. // Roll to see whether the player is fighting a normal mob or a boss
  753. // A player has a 10% chance of fighting a boss
  754. $roll = mt_rand(1,100);
  755.  
  756. $isBoss = false;
  757. if ($roll > 90) { // Fight a boss
  758. $DS3Bosses = file(dirname(__FILE__).'/darksouls/DS3_Boss.txt');
  759. $enemyName = rtrim($DS3Bosses[mt_rand(0,count($DS3Bosses)-1)]);
  760. $msgEnemyName = str_replace(" ", " %C4", $enemyName);
  761. $isBoss = true;
  762.  
  763. echo("%C4Boss %C4encountered! %C9".$ircName." engages in battle with %C4".$msgEnemyName."! \\n ");
  764. echo(" %C9".$ircName." attempts to fight the %C4boss using %C11".$msgWeapon."! \\n ");
  765. } else if ($roll > 20) { // Fight an ordinary mob
  766. $DS3Enemies = file(dirname(__FILE__).'/darksouls/DS3_Enemy.txt');
  767. $enemyName = rtrim($DS3Enemies[mt_rand(0,count($DS3Enemies)-1)]);
  768. $msgEnemyName = str_replace(" ", " %C4", $enemyName);
  769.  
  770. echo("%C4Enemy %C4encountered! %C9".$ircName." engages in battle with %C4".$msgEnemyName."! \\n ");
  771. echo(" %C9".$ircName." attempts to fight the enemy using %C11".$msgWeapon."! \\n ");
  772. } else { // There's a 20% chance of not finding anything; if nothing found, just echo and end
  773. if (!$isAllSeeing) { // If they don't have the All-Seeing spirit
  774. echo(" %C9".$ircName." wasn't lucky and couldn't find any enemy!");
  775. return; // Prematurely end the function here
  776. } else { // We need to regenerate whether it's a Boss or Enemy
  777. $roll = mt_rand(1,100);
  778.  
  779. if ($roll > 90) { // Fight a boss
  780. $DS3Bosses = file(dirname(__FILE__).'/darksouls/DS3_Boss.txt');
  781. $enemyName = rtrim($DS3Bosses[mt_rand(0,count($DS3Bosses)-1)]);
  782. $msgEnemyName = str_replace(" ", " %C4", $enemyName);
  783. $isBoss = true;
  784.  
  785. echo("%C4Boss %C4encountered! %C9".$ircName." engages in battle with %C4".$msgEnemyName."! \\n ");
  786. echo(" %C9".$ircName." attempts to fight the %C4boss using %C11".$msgWeapon."! \\n ");
  787. } else { // Fight a guaranteed ordinary mob
  788. $DS3Enemies = file(dirname(__FILE__).'/darksouls/DS3_Enemy.txt');
  789. $enemyName = rtrim($DS3Enemies[mt_rand(0,count($DS3Enemies)-1)]);
  790. $msgEnemyName = str_replace(" ", " %C4", $enemyName);
  791.  
  792. echo("%C4Enemy %C4encountered! %C9".$ircName." engages in battle with %C4".$msgEnemyName."! \\n ");
  793. echo(" %C9".$ircName." attempts to fight the enemy using %C11".$msgWeapon."! \\n ");
  794. }
  795. }
  796. }
  797.  
  798. $DS3Weapons = file(dirname(__FILE__).'/darksouls/DS3_Weapon.txt');
  799.  
  800. // Determine if the enemy is wielding a weapon themselves; 30% chance
  801. $roll = mt_rand(1,100);
  802.  
  803. $enemyWeapon = "";
  804. if ($roll <= 30) {
  805. $enemyWeapon = rtrim($DS3Weapons[mt_rand(0,count($DS3Weapons)-1)]);
  806. $msgEnemyWeapon = str_replace(" ", " %C11", $enemyWeapon);
  807. echo("Not good! The enemy is using a %C11".$msgEnemyWeapon."! It'll be hard to kill! \\n "); }
  808.  
  809. // Calculate the probability of winning
  810. // If they're using their bare hands, they have a low probability of winning
  811. // Imbued weapons have an increased chance of winning
  812.  
  813. // Change: Weapon above 70%+ of soul record = increased probability
  814. // Promotes the use of newer weapons
  815. $soulBonus = false;
  816. $lowSoulCount = false; // If their weapon's soul count is really low, do reduced damage
  817. $weaponSoulVal = getEquipSoulVal($ircName);
  818. if ($weaponSoulVal > getRecord("ember")*0.60) $soulBonus = true;
  819. if ($weaponSoulVal < getRecord("ember")*0.30 && $weaponSoulVal !== 0) $lowSoulCount = true;
  820.  
  821. $isSoulless = false;
  822. if ($weaponSoulVal == 0) $isSoulless = true;
  823.  
  824. $chance = 0;
  825. if ($isBoss) {
  826. $chance = 14; // Base probability; use whole numbers for no rounding
  827. if ($isImbued === "true") $chance += 10;
  828. if ($soulBonus) $chance += 6;
  829. if ($isSoulless) $chance += 8;
  830. if ($lowSoulCount) $chance -= 8;
  831. if ($equippedWeapon == "Bare Hands") $chance = 4;
  832. if (!empty($enemyWeapon)) $chance /= 2; // Chance is halved
  833. } else {
  834. $chance = 50;
  835. if ($isImbued === "true") $chance += 14;
  836. if ($soulBonus) $chance += 20;
  837. //if ($isSoulless) $chance += 10; // This shouldn't be on for normal weps
  838. if ($lowSoulCount) $chance -= 10;
  839. if ($equippedWeapon == "Bare Hands") $chance = 30;
  840. if (!empty($enemyWeapon)) $chance /= 2; // Chance is halved
  841. }
  842.  
  843. // Check if the player won the fight
  844. $roll = mt_rand(1,100); // Reuse variable to check whether player won
  845. $isVictory = false;
  846. if ($roll <= $chance) { // This value should be less than chance, not more
  847. $isVictory = true;
  848. } else if ($isSoulless && $equippedWeapon !== "Bare Hands") { // If the person died, spoof the death message, and reroll
  849. echo("%C9".$ircName." missed the enemy, but the %C4Soulless %C4essence allows %C9".$ircName." to attack again! \\n ");
  850.  
  851. $roll = mt_rand(1,100);
  852. if ($roll <= $chance) $isVictory = true;
  853. }
  854.  
  855. if ($isVictory) { // If player won the fight
  856. echo("%C9".$ircName." defeated %C4".$msgEnemyName."! Congratulations! \\n ");
  857.  
  858. // If a player killed a boss using their bare hands, they can invade for free for two weeks
  859. // Message: You can feel the darkness within you, hungering to invade...
  860. // EDIT: UNUSED ATM
  861. /*
  862. if ($isBoss && $equippedWeapon == "Bare Hands") {
  863. echo("... \\n ");
  864. echo("%C9".$ircName." feels the darkness within, hungering to invade... \\n ");
  865. bestowInvasion($ircName); }
  866. */
  867.  
  868. $roll = mt_rand(1,1000);
  869.  
  870. if ($roll <= 10 && strpos($equippedWeapon, 'All-Seeing') == false) { // User got an All-Seeing upgrade. 1% chance of getting it
  871. // Reward: Current equipped weapon is imbued with the All-Seeing essence, guaranteeing monster finds
  872. echo(" \\n The remains of the enemy manifests into an %C11All-Seeing %C11spirit... It merges into %C9".$ircName."'s weapon, bestowing the wielder foresight... ");
  873.  
  874. // We need to update both the Inventory and the Profile
  875. allSeeingSpirit($ircName); // This must happen BEFORE the Profile change!
  876.  
  877. $newData = "All-Seeing ".$playerData[0]."|".$playerData[1]."|".$playerData[2]."|".$playerData[3]."|".$playerData[4]."|".$playerData[5]."|".$playerData[6]."|".$playerData[7];
  878. file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt', $newData);
  879. } else if ($roll <= 10 && strpos($equippedWeapon, 'All-Seeing') !== false) { // User got an All-Seeing upgrade, but already has it
  880. 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
  881. } else {
  882. // Load up the entire weapon list for determining reward
  883. $wonWeapon = rtrim($DS3Weapons[mt_rand(0,count($DS3Weapons)-1)]); // Already loaded further above
  884.  
  885. $msgWeapon = str_replace(" ", " %C11", $wonWeapon);
  886.  
  887. // Bosses always drop imbued weapons, and that's the only way to get them
  888. $wonImbue = "";
  889. if ($isBoss) {
  890. $imbueList = ["Heavy","Sharp","Refined","Raw","Crystal","Simple","Fire","Chaos","Lightning","Blessed","Deep","Dark","Blood","Poison","Hollow"];
  891.  
  892. $wonImbue = $imbueList[mt_rand(0,count($imbueList))-1]; // We need to reduce it by one since count() makes it one over
  893. $wonWeapon = $wonImbue." ".$wonWeapon;
  894.  
  895. $msgImbue = str_replace(" ", " %C11", $wonImbue); // The database shouldn't have a shortcode saved
  896. $msgWeapon = $msgImbue." %C11".$msgWeapon;
  897. }
  898.  
  899. // Check if the item is Soulless (worth 0 Souls)
  900. if ($roll <= 20) { // User got a Soulless item. There is a 1% chance of getting it
  901. echo("%C9".$ircName." scavenged its soul and found a %C11Soulless %C11".$msgWeapon."...");
  902.  
  903. // Reward: Increased inventory space by 10
  904. echo(" \\n The weapon is %C11Soulless! Its unfathomable essence empowers %C9".$ircName.", increasing %C9Vitality and %C9Endurance! ");
  905.  
  906. // Increase the max inventory size; don't increase inventory count
  907. $newInvSize = $playerData[3] + 10;
  908. $newData = $playerData[0]."|".$playerData[1]."|".$playerData[2]."|".$newInvSize."|".$playerData[4]."|".$playerData[5]."|".$playerData[6]."|".$playerData[7];
  909. file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt', $newData);
  910.  
  911. // Save the item to the user's zero value inventory AND global inventory
  912. $invString = "";
  913. if (!empty($wonImbue)) { // Check if it was a boss giving an imbue
  914. // Store this weapon to their inventory, with isImbued = true
  915. // Format (one item for each line): Imbue Prefix + Weapon|isImbued|Soul Value
  916. $invString = "Soulless ".$wonWeapon."|true|0\n";
  917. } else {
  918. $invString = "Soulless ".$wonWeapon."|false|0\n"; }
  919.  
  920. file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt', $invString, FILE_APPEND);
  921. file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Soulless.txt', $invString, FILE_APPEND);
  922.  
  923. // GLOBAL ZERO VALUE INVENTORY SAVE CODE HERE
  924. //
  925. //
  926. //
  927.  
  928. // ADD LOGGING CODE HERE
  929. } else { // If it's not Soulless, we need to do a lot of calculating
  930. echo("%C9".$ircName." scavenged its soul and found a %C11".$msgWeapon."...");
  931.  
  932. // Check if inventory is full
  933. $inventoryCount = +$playerData[2];
  934. $inventoryMax = +$playerData[3];
  935.  
  936. //echo("<br>inventoryCount = ".(string)$inventoryCount);
  937. //echo("<br>inventoryMax = ".(string)$inventoryMax);
  938.  
  939. if ($inventoryCount >= $inventoryMax) {
  940. echo(" \\n ...But %C9".$ircName." is overburdened, so it was left behind...");
  941.  
  942. // Save the history to the battle log (Note: It has to be here, sorta)
  943. // Format: Boss Name|Equipped Weapon|Date & Time
  944. $logMsg = $ircName." vanquished ".$enemyName." with a ".$equippedWeapon." at ".$exploreArea." on ".date("F j, Y, g:i a").".\n";
  945. file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Log.txt', $logMsg, FILE_APPEND);
  946. } else {
  947. $soulLimit = getLimit("ember"); // Fetch the current range limit
  948.  
  949. if ($soulLimit < 1000) // Just in case
  950. $soulLimit = 1000;
  951.  
  952. $soulValue = mt_rand(1, $soulLimit); // Generate a number from 1 to the limit
  953.  
  954. // Echo the weapon found and its forged soul count
  955. echo(" which was materialized with %C4".number_format($soulValue)." %C4Souls...");
  956.  
  957. // Increase the limit by 20% if the current player rolled a number within the top 10%
  958. if ($soulValue >= $soulLimit*0.90) {
  959. $soulLimit *= 1.2;
  960. setLimit("ember", round($soulLimit, 0, PHP_ROUND_HALF_UP)); } // Set a hard limit
  961.  
  962. // Now, check if this is a new record
  963. if ($soulValue >= getRecord("ember")) { // User set a new global record
  964. echo(" \\n The %C4Fire %C4Keeper identifies this %C11".$msgWeapon." as the darkest of them all... Treasure it well...");
  965.  
  966. // Update the global record
  967. setRecord("ember", $soulValue, $ircName, $wonWeapon);
  968.  
  969. // CODE FOR PERSONAL BEST EMBER ITEM HERE
  970. //
  971. //
  972. }
  973.  
  974. // Script is done; just some saving to do
  975. $saveInv = "";
  976. if (!empty($wonImbue)) { // If the player won against a boss and has an imbued item
  977. // Store this weapon to their inventory, with isImbued = true
  978. // Format (one item for each line): Imbue Prefix + Weapon|isImbued|Soul Value
  979. $invString = $wonWeapon."|true|".$soulValue."\n";
  980. } else { // Store this weapon to their inventory, with isImbued = false
  981. $invString = $wonWeapon."|false|".$soulValue."\n"; }
  982.  
  983. file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Inventory.txt', $invString, FILE_APPEND);
  984.  
  985. // Save the battle history
  986. $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";
  987. file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Log.txt', $logMsg, FILE_APPEND);
  988.  
  989. // Increase current inventory count
  990. // Don't worry about this conflicting with the Soulless save
  991. $inventoryCount++;
  992.  
  993. //$newInvCount = $playerData[2] + 1;
  994. $newProfile = $playerData[0]."|".$playerData[1]."|".$inventoryCount."|".$playerData[3]."|".$playerData[4]."|".$playerData[5]."|".$playerData[6]."|".$playerData[7];
  995. file_put_contents(dirname(__FILE__).'/darksouls/'.$ircName.'/'.$ircName.'_Profile.txt', $newProfile);
  996. }
  997. }
  998. }
  999. } else {
  1000. echo("%C4".strtoupper($ircName)." %C4DIED"); }
  1001. } else {
  1002. echo("Sorry ".$ircName.", you can't afford the 50 Cakes needed to be embered. Try again later!"); }
  1003. }
  1004. //adventureDS("Suwako");
  1005.  
  1006. // -------------------------------------------------- //
  1007.  
  1008.  
  1009. // To do
  1010. // upgrades +1 to +10 ONLY APPLY for NON soulless items
  1011. // Any item or sets of items can be offered to upgrade to +10, where the number of items needed increases per upgrade
  1012. // Higher tier upgrades (past +5) will need increased inventory size
  1013. // 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
  1014. // 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)
  1015.  
  1016.  
  1017. // shields + shield imbues
  1018. // temp resin or chunk upgrades
  1019. // sell old stuff for conversion to cakes with Yorshka
  1020.  
  1021.  
  1022. // Add logging for soulless and all-seeing
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033. /*
  1034. function setUserInfo($ircName,$cakes,$unixTime) {
  1035. $line = $ircName."|".$cakes."|".$unixTime;
  1036. file_put_contents($cake, $line, FILE_APPEND)
  1037.  
  1038. // Format: IRCName|Cakes|LastUnixTime
  1039.  
  1040. }
  1041.  
  1042. function transferCakes($oldIRCName,$newIRCName) { // Used to transfer cakes between users; only I can do so
  1043.  
  1044. }
  1045. */
  1046.  
  1047.  
  1048. /*
  1049.  
  1050. -----------------------------------------------------
  1051. Note: Basic Skeleton of Editing a File, not Appending
  1052. -----------------------------------------------------
  1053.  
  1054. $ircUsers = file(CAKEDBLOC);
  1055.  
  1056. $inCakeDB = false;
  1057. foreach ($ircUsers as $index=>$curUser) {
  1058. $checkLine = explode('|', $curUser, -1);
  1059.  
  1060. if ($checkLine[0] === strtolower($ircName)) { // Make it case insensitive
  1061. $inCakeDB = true;
  1062.  
  1063. $cakeCount = +$checkLine[1];
  1064. $cakeCount += 250;
  1065.  
  1066. $curUser = str_replace($curUser, strtolower($checkLine[0])."|".$cakeCount."|0|\n", $curUser);
  1067. $ircUsers[$index] = $curUser;
  1068.  
  1069. file_put_contents(CAKEDBLOC, $ircUsers);
  1070. }
  1071. break;
  1072. }
  1073.  
  1074. */
  1075. // -------------------------------------------------- //
  1076. ?>
Advertisement
Add Comment
Please, Sign In to add comment