Advertisement
Guest User

Untitled

a guest
May 5th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.73 KB | None | 0 0
  1. using ClipperLib;
  2. using System;
  3. using Legend;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Reflection;
  10. using UnityEngine;
  11. using X_UniTMX;
  12.  
  13.  
  14. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  15. // %%% Save Game Information %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  16. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  17.  
  18. // save game class (restored or stored from JSON)
  19. public class AdventureModSaveGame
  20. {
  21.  
  22. // current playthrough
  23. public int Playthrough;
  24.  
  25. // last level number
  26. public int LevelNumber;
  27.  
  28. // players max health
  29. public float Maxhealth;
  30.  
  31. // players current health
  32. public float Health;
  33.  
  34. // players damage output
  35. public float Damage;
  36.  
  37. // players current bomb count
  38. public int Bombs;
  39.  
  40. // players current coin count
  41. public int Coins;
  42.  
  43. // players current key count
  44. public int Keys;
  45.  
  46.  
  47.  
  48. };
  49.  
  50. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  51. // %%% Mod Class Implementation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  52. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  53.  
  54.  
  55. public class ExampleMod : IMod
  56. {
  57.  
  58. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  59. // %%% Mod Basic Information %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  60. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  61.  
  62. // set mod name
  63. public string Name { get { return "Legend of Luca Adventure Mod"; } }
  64.  
  65. // set your mod description here
  66. public string Description { get { return "Legend of Luca Adventure Mod"; } }
  67.  
  68. // set your mod author here
  69. public string Author { get { return "Some Guy"; } }
  70.  
  71. // set your mod version here
  72. public int Version { get { return 1; } }
  73.  
  74. // returns debug
  75. public int DebugMode { get { return 1; } }
  76.  
  77.  
  78. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  79. // %%% Player OnLoad Hook %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  80. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  81.  
  82. // mod playthrough (set via save)
  83. int Playthrough;
  84.  
  85. // onload
  86. public void OnLoad()
  87. {
  88.  
  89. // set initial playthrough to 1
  90. this.Playthrough = 1;
  91.  
  92. }
  93.  
  94. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  95. // %%% Player Spawn Load Hook (Called When Player Spawns %%%%%%%%
  96. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  97.  
  98.  
  99. // called when player spawns into the game (start of level, game load)
  100. public void OnPlayerSpawn(Player player)
  101. {
  102.  
  103.  
  104.  
  105. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  106. // %%% Add Custom Items To Game %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  107. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  108. /*
  109. // Create new item type
  110. ItemType itemType = new ItemType();
  111. itemType.Id = (ItemId)9000;
  112. itemType.Category = ItemCategory.Upgrade;
  113. itemType.Description = "\"Adventure Random Weapon Modifier\"";
  114. itemType.OnFound = delegate (Item item, Player player_cb)
  115. {
  116. player_cb.Damageable.MaxHealth += 1f;
  117. player_cb.Damageable.Health += 1f;
  118. };
  119. ItemBase.AddItem(itemType);
  120. */
  121.  
  122. // display adventure mod
  123. // HUD.ShowMessage("Level Load", "A new Adventure has been Loaded!", 6);
  124.  
  125.  
  126. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  127. // %%% Set Player Attributes Here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  128. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  129.  
  130. // adjust players max health
  131. player.Damageable.MaxHealth = 20;
  132.  
  133. // adjust players starting health
  134. player.Damageable.Health = 5;
  135.  
  136. // load save state
  137. this.LoadModGameState("./AdventureMod.savestate");
  138.  
  139. // set player info from save state
  140. if(this.current_save_game != null)
  141. {
  142. player.Coins = this.current_save_game.Coins;
  143. player.Bombs = this.current_save_game.Bombs;
  144. player.Keys = this.current_save_game.Keys;
  145. player.Damageable.MaxHealth = this.current_save_game.Maxhealth;
  146. player.Damageable.Health = this.current_save_game.Health;
  147. player.Damage = this.current_save_game.Damage;
  148. this.Playthrough = this.current_save_game.Playthrough;
  149. }
  150.  
  151.  
  152. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  153. // %%% Add Items To Inventory on Spawn %%%%%%%%%%%%%%%%%%%%%%%%%
  154. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  155.  
  156. // add custom item to player inventory
  157. // player.AddItem(ItemId.Map);
  158.  
  159.  
  160.  
  161. }
  162.  
  163.  
  164.  
  165. // simply logs a message to the debug file
  166. public void ModLogger(String report_level, String report_message)
  167. {
  168. // log to file
  169. Debug.Log("Legend of Luca Adventure Mod: " + report_level + ": " + report_message);
  170. }
  171.  
  172.  
  173. // load all level designs
  174. public void LoadLevelDesignByIdx(int idx)
  175. {
  176.  
  177.  
  178. // exit the method
  179. return;
  180.  
  181. }
  182.  
  183. // set on level load to the current save game available
  184. AdventureModSaveGame current_save_game;
  185.  
  186. // custom level loader
  187. public void OnGotoLevel(LevelDesign level)
  188. {
  189.  
  190. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  191. // %%% Level Generator Prologue %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  192. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  193.  
  194. // Never work on levels 0, 6, or 7. Mod only works on levels 1-5.
  195. switch(Level.Instance.LevelNumber)
  196. {
  197. case 0:
  198. case 6:
  199. case 7:
  200. return;
  201. default:
  202. break;
  203. }
  204.  
  205. // clear the level on startup
  206. Level.Instance.ClearLevel();
  207.  
  208.  
  209. // load state if it exists
  210. if(!this.LoadModGameState("./AdventureMod.savestate"))
  211. {
  212.  
  213. // attempt to create state if no state exists
  214. this.SaveModGameState("./AdventureMod.savestate", this.current_save_game);
  215.  
  216. // attempt to load from the new save (sets class member for future save data)
  217. this.LoadModGameState("./AdventureMod.savestate");
  218.  
  219. }
  220.  
  221. // go to level number if loaded level is not the same as our current level
  222. if(this.current_save_game != null)
  223. if(Level.Instance.LevelNumber != this.current_save_game.LevelNumber)
  224. {
  225.  
  226. // set the instance level number before moving levels
  227. Level.Instance.LevelNumber = this.current_save_game.LevelNumber;
  228.  
  229. // move levels
  230. Level.Instance.GotoLevel(this.current_save_game.LevelNumber);
  231.  
  232. // exit here to prevent overlap (recurses)
  233. return;
  234.  
  235. }
  236.  
  237.  
  238.  
  239.  
  240. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  241. // %%% Custom Load All Room Designs First %%%%%%%%%%%%%%%%%%%%%%%%%%%
  242. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  243.  
  244.  
  245. // Step 1) Load all room designs
  246. foreach (var design in Level.Instance.Designs)
  247. {
  248.  
  249. if (design.Rooms == null)
  250. continue;
  251.  
  252. // load room design
  253. design.LoadRoomDesigns(design.Rooms);
  254.  
  255. }
  256.  
  257.  
  258. // step 2) merge all room designs into new level
  259. Dictionary<RoomType, List<TileLayer>> merged_design = new Dictionary<RoomType, List<TileLayer>>();
  260.  
  261. // create lists for merged itemms
  262. merged_design[RoomType.Boss] = new List<TileLayer>();
  263. merged_design[RoomType.Hidden] = new List<TileLayer>();
  264. merged_design[RoomType.Normal] = new List<TileLayer>();
  265. merged_design[RoomType.Shop] = new List<TileLayer>();
  266. merged_design[RoomType.Start] = new List<TileLayer>();
  267. merged_design[RoomType.Treasure] = new List<TileLayer>();
  268. merged_design[RoomType.Weapon] = new List<TileLayer>();
  269.  
  270.  
  271. // walk the level designs
  272. foreach (var design in Level.Instance.Designs)
  273. {
  274.  
  275. // ensure room designs aren't null
  276. if (design.RoomDesigns != null)
  277. {
  278.  
  279. foreach (KeyValuePair<RoomType, List<TileLayer>> entry in design.RoomDesigns)
  280. {
  281.  
  282. // switch on RoomType and add to the correct range
  283. switch(entry.Key)
  284. {
  285.  
  286. // add to boss rooms
  287. case RoomType.Boss:
  288. merged_design[RoomType.Boss].AddRange(entry.Value);
  289. break;
  290.  
  291. // add to hidden rooms
  292. case RoomType.Hidden:
  293. merged_design[RoomType.Hidden].AddRange(entry.Value);
  294. break;
  295.  
  296. // add to normal rooms
  297. case RoomType.Normal:
  298. merged_design[RoomType.Normal].AddRange(entry.Value);
  299. break;
  300.  
  301. // add to shop rooms
  302. case RoomType.Shop:
  303. merged_design[RoomType.Shop].AddRange(entry.Value);
  304. break;
  305.  
  306. // add to start rooms
  307. case RoomType.Start:
  308. merged_design[RoomType.Start].AddRange(entry.Value);
  309. break;
  310.  
  311. // add to treasure rooms
  312. case RoomType.Treasure:
  313. merged_design[RoomType.Treasure].AddRange(entry.Value);
  314. break;
  315.  
  316. // add to weapon rooms
  317. case RoomType.Weapon:
  318. merged_design[RoomType.Weapon].AddRange(entry.Value);
  319. break;
  320.  
  321. // don't add anything/bad value
  322. default:
  323. break;
  324.  
  325. }
  326.  
  327. }
  328.  
  329. }
  330.  
  331. }
  332.  
  333. // step 3) Replace all the current room designs in our current level with the
  334. // merged version. This effectively gives us access to all levels in our single level.
  335.  
  336. if (merged_design[RoomType.Boss].Count > 0)
  337. {
  338. this.ModLogger("NOTICE", "Attempting to add merged boss rooms.");
  339. level.RoomDesigns[RoomType.Boss] = merged_design[RoomType.Boss];
  340. }
  341.  
  342. if (merged_design[RoomType.Hidden].Count > 0)
  343. {
  344. this.ModLogger("NOTICE", "Attempting to add merged weapon rooms.");
  345. level.RoomDesigns[RoomType.Hidden] = merged_design[RoomType.Hidden];
  346. }
  347.  
  348. if (merged_design[RoomType.Normal].Count > 0)
  349. {
  350. this.ModLogger("NOTICE", "Attempting to add merged normal rooms.");
  351. level.RoomDesigns[RoomType.Normal] = merged_design[RoomType.Normal];
  352. }
  353.  
  354. if (merged_design[RoomType.Shop].Count > 0)
  355. {
  356. this.ModLogger("NOTICE", "Attempting to add merged shop rooms.");
  357. level.RoomDesigns[RoomType.Shop] = merged_design[RoomType.Shop];
  358. }
  359.  
  360. if (merged_design[RoomType.Start].Count > 0)
  361. {
  362. this.ModLogger("NOTICE", "Attempting to add merged starting rooms.");
  363. level.RoomDesigns[RoomType.Start] = merged_design[RoomType.Start];
  364. }
  365.  
  366. if (merged_design[RoomType.Treasure].Count > 0)
  367. {
  368. this.ModLogger("NOTICE", "Attempting to add merged treasure rooms.");
  369. level.RoomDesigns[RoomType.Treasure] = merged_design[RoomType.Treasure];
  370. }
  371.  
  372. if (merged_design[RoomType.Weapon].Count > 0)
  373. {
  374. this.ModLogger("NOTICE", "Attempting to add merged weapon rooms.");
  375. level.RoomDesigns[RoomType.Weapon] = merged_design[RoomType.Weapon];
  376. }
  377.  
  378. // display mod startup notice
  379. this.ModLogger("NOTICE", "All level layouts have been added.");
  380.  
  381.  
  382.  
  383.  
  384. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  385. // %%% Level Generation Multipliers %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  386. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  387.  
  388. // Note: All multipliers are (current level * multiplier)
  389.  
  390. // normal room multiplier
  391. float normal_room_multiplier = 0f;
  392.  
  393. // pseudo random room multiplier
  394. float pseudo_random_room_multiplier = 0f;
  395.  
  396. // shop room multiplier
  397. float shop_room_multiplier = 0f;
  398.  
  399. // hidden room multiplier
  400. float hidden_room_multiplier = 0f;
  401.  
  402. // default treasure room multiplier
  403. float treasure_room_multiplier = 0f;
  404.  
  405. // the number of bogus boss rooms (there is only one actual boss room)
  406. float bogus_boss_room_multiplier = 0f;
  407.  
  408. // the number of weapon rooms
  409. float extra_weapon_room_multiplier = 0f;
  410.  
  411.  
  412.  
  413. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  414. // %%% Multiplier Adjustments Per Level %%%%%%%%%%%%%%%%%%%%%%%%%%%%
  415. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  416.  
  417. // setup randomizers (for adding to multiplier ranges)
  418. System.Random normal_room_randomizer = new System.Random();
  419. System.Random pseudo_random_room_randomizer = new System.Random();
  420. System.Random shop_room_randomizer = new System.Random();
  421. System.Random hidden_room_randomizer = new System.Random();
  422. System.Random treasure_room_randomizer = new System.Random();
  423. System.Random bogus_boss_room_randomizer = new System.Random();
  424. System.Random extra_weapon_room_randomizer = new System.Random();
  425.  
  426. // set the instance
  427. Level mod_level_instance = Level.Instance;
  428.  
  429. // perform arbitrary adjustments for level 1
  430. if (mod_level_instance.LevelNumber == 1)
  431. {
  432.  
  433. // create level number for display
  434. String display_msg = String.Format("Death and despair, this is what you know. With that knowledge you begin your long quest to overcome the horrors which exist within this terrible labyrinth.");
  435.  
  436. // show the load message
  437. HUD.ShowMessage("Act 1:", display_msg, 12);
  438.  
  439. // no adjustments required for level 1
  440. normal_room_multiplier = normal_room_randomizer.Next(70, 90);
  441. pseudo_random_room_multiplier = pseudo_random_room_randomizer.Next(70, 90);
  442. shop_room_multiplier = shop_room_randomizer.Next(4, 9);
  443. hidden_room_multiplier = hidden_room_randomizer.Next(4, 9);
  444. treasure_room_multiplier = treasure_room_randomizer.Next(4, 9);
  445. bogus_boss_room_multiplier = bogus_boss_room_randomizer.Next(4, 9);
  446. extra_weapon_room_multiplier = extra_weapon_room_randomizer.Next(4, 9);
  447.  
  448.  
  449. }
  450.  
  451. // perform arbitrary adjustments for level 2 (multiply all values by 2;
  452. if (mod_level_instance.LevelNumber == 2)
  453. {
  454.  
  455. // create level number for display
  456. String display_msg = String.Format("As the damned soul rises, so does the fire and as the doors of hell open a soul sinks deeper. (difficulty has been increased)");
  457.  
  458. // show the load message
  459. HUD.ShowMessage("Act 2:", display_msg, 12);
  460.  
  461. // reduce player damage by 25% (scales mob HP)
  462. Player.Instance.Damage *= 0.90f;
  463.  
  464. // no adjustments required for level 1
  465. normal_room_multiplier = normal_room_randomizer.Next(70, 100);
  466. pseudo_random_room_multiplier = pseudo_random_room_randomizer.Next(70, 100);
  467. shop_room_multiplier = shop_room_randomizer.Next(4, 11);
  468. hidden_room_multiplier = hidden_room_randomizer.Next(4, 11);
  469. treasure_room_multiplier = treasure_room_randomizer.Next(4, 11);
  470. bogus_boss_room_multiplier = bogus_boss_room_randomizer.Next(4, 11);
  471. extra_weapon_room_multiplier = extra_weapon_room_randomizer.Next(4, 11);
  472.  
  473. }
  474.  
  475. // perform arbitrary adjustments for level 3
  476. if (mod_level_instance.LevelNumber == 3)
  477. {
  478.  
  479. // create level number for display
  480. String display_msg = String.Format("The only familiar thing here are the walking malicious fates of a many long forgotten agonies. The creatures here mmanifest sorrow through mutilation, and express vanity through abomination. They will break you, or you will break them, this is hells bargain. (difficulty has been increased further)");
  481.  
  482. // show the load message
  483. HUD.ShowMessage("Act 3:", display_msg, 12);
  484.  
  485. // reduce player damage by 25% (scales mob HP further)
  486. Player.Instance.Damage *= 0.90f;
  487.  
  488. // no adjustments required for level 1
  489. normal_room_multiplier = normal_room_randomizer.Next(80, 120);
  490. pseudo_random_room_multiplier = pseudo_random_room_randomizer.Next(80, 120);
  491. shop_room_multiplier = shop_room_randomizer.Next(5, 13);
  492. hidden_room_multiplier = hidden_room_randomizer.Next(5, 13);
  493. treasure_room_multiplier = treasure_room_randomizer.Next(5, 13);
  494. bogus_boss_room_multiplier = bogus_boss_room_randomizer.Next(5, 13);
  495. extra_weapon_room_multiplier = extra_weapon_room_randomizer.Next(5, 13);
  496.  
  497. }
  498.  
  499. // perform arbitrary adjustments for level 4
  500. if (mod_level_instance.LevelNumber == 4)
  501. {
  502.  
  503. // create level number for display
  504. String display_msg = String.Format("Sulfur burns your lungs as you press on. You contemplate turning around. You ask yourself if it's worth it, and you remind yourself over the sound of yoru body beginning to shut down from wear, you remind yourself... you barely remember but you make out a memory. (difficulty has been increased further)");
  505.  
  506. // show the load message
  507. HUD.ShowMessage("Act 4:", display_msg, 12);
  508.  
  509. // reduce player damage by 25% (scales mob HP further)
  510. Player.Instance.Damage *= 0.90f;
  511.  
  512. // no adjustments required for level 1
  513. normal_room_multiplier = normal_room_randomizer.Next(90, 130);
  514. pseudo_random_room_multiplier = pseudo_random_room_randomizer.Next(30, 130);
  515. shop_room_multiplier = shop_room_randomizer.Next(6, 16);
  516. hidden_room_multiplier = hidden_room_randomizer.Next(6, 16);
  517. treasure_room_multiplier = treasure_room_randomizer.Next(6, 16);
  518. bogus_boss_room_multiplier = bogus_boss_room_randomizer.Next(6, 16);
  519. extra_weapon_room_multiplier = extra_weapon_room_randomizer.Next(6, 16);
  520.  
  521. }
  522.  
  523. // perform arbitrary adjustments for level 5
  524. if (mod_level_instance.LevelNumber == 5)
  525. {
  526.  
  527.  
  528. // create level number for display
  529. String display_msg = String.Format("As you reach the final depth of the labyrinth, you remember the people you are fighting for. You remember that this fight was not one you started. You remember all those who died, those who suffered, all those who bled out at the merciless cruelty of such basal evils. You begin your final journey to destroy them once and for all. (difficulty has been increased further)");
  530.  
  531. // show the load message
  532. HUD.ShowMessage("Act 5:", display_msg, 12);
  533.  
  534. // reduce player damage by 35% (scales mob HP further)
  535. Player.Instance.Damage *= 0.90f;
  536.  
  537.  
  538. // no adjustments required for level 1
  539. normal_room_multiplier = normal_room_randomizer.Next(120, 150);
  540. pseudo_random_room_multiplier = pseudo_random_room_randomizer.Next(120, 150);
  541. shop_room_multiplier = shop_room_randomizer.Next(8, 20);
  542. hidden_room_multiplier = hidden_room_randomizer.Next(8, 20);
  543. treasure_room_multiplier = treasure_room_randomizer.Next(8, 20);
  544. bogus_boss_room_multiplier = bogus_boss_room_randomizer.Next(8, 20);
  545. extra_weapon_room_multiplier = extra_weapon_room_randomizer.Next(8, 20);
  546.  
  547. }
  548.  
  549.  
  550.  
  551. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  552. // %%% Level Generation Loop %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  553. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  554.  
  555.  
  556. // NOTE: This try except creates a "loop". If level generation fails (and it does fail, this is normal)
  557. // the loop will attempt to create the level again. Levels will fail generation when the generation
  558. // engine "paints itself into a corner."
  559.  
  560. // attempt level generation
  561. try
  562. {
  563.  
  564. // set spawn room
  565. mod_level_instance.SpawnRoom = mod_level_instance.CreateRoom(Level.CenterRoomsX, Level.CenterRoomsY, RoomType.Start);
  566.  
  567. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  568. // %%% Step 1) Create "Normal" Rooms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  569. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  570.  
  571. // set current room
  572. var currentRoom = mod_level_instance.SpawnRoom;
  573.  
  574. // create "normal" rooms first (using random direction)
  575. for
  576. (
  577. int i = 0;
  578. i < normal_room_multiplier;
  579. i++
  580. )
  581. {
  582.  
  583. // add debug message
  584. this.ModLogger("NOTICE", "Spawning 'normal' room.");
  585.  
  586. // add normal room in random direction
  587. currentRoom = mod_level_instance.AddRoom(currentRoom, Level.RandomDirection());
  588.  
  589. }
  590.  
  591. // add debug message
  592. this.ModLogger("NOTICE", "Finished spawning 'normal' room.");
  593.  
  594.  
  595. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  596. // %%% Add Some Pseudo-Random Rooms (Adds Depth to Layouts) %%%%%%%%%
  597. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  598.  
  599. // set current room
  600. currentRoom = mod_level_instance.SpawnRoom;
  601.  
  602. // create pseudorandom layout
  603. for
  604. (
  605. int i = 0;
  606. i < pseudo_random_room_multiplier;
  607. i++
  608. )
  609. {
  610.  
  611. // add debug message
  612. this.ModLogger("NOTICE", "Spawning 'pseudo random' room.");
  613.  
  614. // add pr room
  615. currentRoom = mod_level_instance.AddRoom(currentRoom, mod_level_instance.PsudoRandomDirection(currentRoom));
  616.  
  617. }
  618.  
  619. // add debug message
  620. this.ModLogger("NOTICE", "Finished spawning 'pseudo random' rooms.");
  621.  
  622. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  623. // %%% Add Some Hidden Rooms (Adds Depth to Layouts) %%%%%%%%%%%%%%%%
  624. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  625.  
  626. // set current room
  627. currentRoom = mod_level_instance.SpawnRoom;
  628.  
  629. // create pseudorandom layout
  630. for
  631. (
  632. int i = 0;
  633. i < hidden_room_multiplier;
  634. i++
  635. )
  636. {
  637.  
  638. // add debug message
  639. this.ModLogger("NOTICE", "Spawning 'hidden' room.");
  640.  
  641. // add hidden room
  642. currentRoom = mod_level_instance.AddNewRoom(RoomType.Hidden);
  643.  
  644.  
  645. }
  646.  
  647. // add debug message
  648. this.ModLogger("NOTICE", "Finished spawning 'hidden' rooms.");
  649.  
  650.  
  651. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  652. // %%% Add Some Treasure Rooms (Adds Depth to Layouts) %%%%%%%%%%%%%%
  653. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  654.  
  655. // set current room
  656. currentRoom = mod_level_instance.SpawnRoom;
  657.  
  658. // create pseudorandom layout
  659. for
  660. (
  661. int i = 0;
  662. i < treasure_room_multiplier;
  663. i++
  664. )
  665. {
  666.  
  667. // add debug message
  668. this.ModLogger("NOTICE", "Spawning 'treasure' room.");
  669.  
  670. // add treasure room
  671. currentRoom = mod_level_instance.AddNewRoom(RoomType.Treasure);
  672.  
  673. }
  674.  
  675. // add debug message
  676. this.ModLogger("NOTICE", "Finished spawning 'treasure' rooms.");
  677.  
  678. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  679. // %%% Add Some Shop Rooms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  680. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  681.  
  682. // set current room
  683. currentRoom = mod_level_instance.SpawnRoom;
  684.  
  685. // create pseudorandom layout
  686. for
  687. (
  688. int i = 0;
  689. i < shop_room_multiplier;
  690. i++
  691. )
  692. {
  693.  
  694. // add debug message
  695. this.ModLogger("NOTICE", "Spawning 'shop' room.");
  696.  
  697. // add shop room
  698. currentRoom = mod_level_instance.AddNewRoom(RoomType.Shop);
  699.  
  700. }
  701.  
  702. // add debug message
  703. this.ModLogger("NOTICE", "Finished spawning 'shop' rooms.");
  704.  
  705. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  706. // %%%% Link up Rooms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  707. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  708.  
  709. // link up rooms
  710. mod_level_instance.LinkAllNormalRooms();
  711.  
  712.  
  713.  
  714. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  715. // %%% Add Some Bogus Bosses for Extra Loot %%%%%%%%%%%%%%%%%%%%%%%%%
  716. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  717.  
  718. // create bogus bosses layout
  719. for
  720. (
  721. int i = 0;
  722. i < bogus_boss_room_multiplier;
  723. i++
  724. )
  725. {
  726. currentRoom = mod_level_instance.AddNewRoom(RoomType.Boss);
  727. }
  728.  
  729.  
  730.  
  731. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  732. // %%% Add Extra Weapon Rooms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  733. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  734.  
  735. // create pseudorandom layout
  736. for
  737. (
  738. int i = 0;
  739. i < mod_level_instance.LevelNumber * extra_weapon_room_multiplier;
  740. i++
  741. )
  742. {
  743. currentRoom = mod_level_instance.AddNewRoom(RoomType.Weapon);
  744. }
  745.  
  746.  
  747. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  748. // %%% Add Final Boss Room %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  749. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  750.  
  751. // add debug message
  752. this.ModLogger("NOTICE", "Attempting to lookup random room that is not our spawn room.");
  753.  
  754. // this loop prevents ever linking a start room to a boss room
  755. while (currentRoom == mod_level_instance.SpawnRoom)
  756. {
  757. currentRoom = mod_level_instance.GetRandomNormalRoom();
  758. }
  759.  
  760. // set lookup succeeded notice
  761. this.ModLogger("NOTICE", "Lookup succeeded.");
  762.  
  763. // add boss room
  764. currentRoom = mod_level_instance.AddNewRoom(RoomType.Boss, currentRoom);
  765.  
  766. // set lookup succeeded notice
  767. this.ModLogger("NOTICE", "Final boss room has been added.");
  768.  
  769.  
  770. // attempt to link to level if we have a next level
  771. if (mod_level_instance.LevelNumber != 5)
  772. {
  773.  
  774. // set lookup succeeded notice
  775. this.ModLogger("NOTICE", "Adding final weapon room.");
  776.  
  777. // set current room
  778. currentRoom = mod_level_instance.AddNewRoom(RoomType.Weapon, currentRoom);
  779.  
  780. // set lookup succeeded notice
  781. this.ModLogger("NOTICE", "Final weapon room has been added.");
  782.  
  783. // link the new weapon room to the next level (level + 1)
  784. mod_level_instance.LinkRoomToLevel
  785. (
  786. currentRoom,
  787. mod_level_instance.GetAvailableDirection(currentRoom),
  788. mod_level_instance.LevelNumber + 1
  789. );
  790.  
  791. // set lookup succeeded notice
  792. this.ModLogger("NOTICE", "Final weapon room has been linked to next level.");
  793.  
  794. }
  795. else
  796. {
  797.  
  798. // if you beat the game link to victory level
  799. mod_level_instance.LinkRoomToLevel
  800. (
  801. currentRoom,
  802. mod_level_instance.GetAvailableDirection(currentRoom),
  803. LevelDesign.VictoryLevelNumber
  804. );
  805.  
  806. }
  807.  
  808. }
  809. catch (Exception e)
  810. {
  811. Debug.Log("Legend of Luca Adventure Mod: Level Generator Error Caused Regen: " + e.ToString());
  812. mod_level_instance.ClearLevel();
  813. level.SetLevel();
  814. return;
  815. }
  816.  
  817. // exit
  818. return;
  819.  
  820. }
  821.  
  822. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  823. // %%% Load/Save Game Game Methods %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  824. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  825.  
  826. // load mod game state
  827. public bool LoadModGameState(String load_file)
  828. {
  829.  
  830. // ensure the save game exists
  831. if (!File.Exists(load_file))
  832. return false;
  833.  
  834. // load json save data
  835. var json_save_data = System.IO.File.ReadAllText(load_file);
  836.  
  837. // load json data as a new object
  838. AdventureModSaveGame save_game_object = JsonUtility.FromJson<AdventureModSaveGame>(json_save_data);
  839.  
  840.  
  841. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  842. // %%% Load Player Attributes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  843. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  844.  
  845. // set player bombs
  846. if (save_game_object.Bombs > 0)
  847. Player.Instance.Bombs = save_game_object.Bombs;
  848.  
  849. // set player keys
  850. if (save_game_object.Keys > 0)
  851. Player.Instance.Keys = save_game_object.Keys;
  852.  
  853. // set player coins
  854. if (save_game_object.Coins > 0)
  855. Player.Instance.Coins = save_game_object.Coins;
  856.  
  857. // set player damage
  858. if (save_game_object.Damage > 0)
  859. Player.Instance.Damage = save_game_object.Damage;
  860.  
  861. // current playthrough
  862. if (save_game_object.Playthrough > 0)
  863. this.Playthrough = save_game_object.Playthrough;
  864.  
  865. // set max health
  866. if (save_game_object.Maxhealth > 0)
  867. Player.Instance.Damageable.MaxHealth = save_game_object.Maxhealth;
  868.  
  869. // set health
  870. if (save_game_object.Health > 0)
  871. Player.Instance.Damageable.Health = save_game_object.Health;
  872.  
  873. // set the current save game as the loaded save game
  874. this.current_save_game = save_game_object;
  875.  
  876. // return indicating success
  877. return true;
  878.  
  879. }
  880.  
  881. // attempt to save mod game state
  882. public bool SaveModGameState
  883. (
  884. String save_file,
  885. AdventureModSaveGame save_game_info
  886. )
  887. {
  888.  
  889. // create json from json info
  890. var save_as_json = JsonUtility.ToJson(save_game_info);
  891. if (save_as_json == null)
  892. return false;
  893.  
  894. // write our json to disk
  895. System.IO.File.WriteAllText(save_file, save_as_json);
  896.  
  897. // return indicating success
  898. return true;
  899.  
  900. }
  901.  
  902.  
  903.  
  904. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement