Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using ClipperLib;
- using System;
- using Legend;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Reflection;
- using UnityEngine;
- using X_UniTMX;
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Save Game Information %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // save game class (restored or stored from JSON)
- public class AdventureModSaveGame
- {
- // current playthrough
- public int Playthrough;
- // last level number
- public int LevelNumber;
- // players max health
- public float Maxhealth;
- // players current health
- public float Health;
- // players damage output
- public float Damage;
- // players current bomb count
- public int Bombs;
- // players current coin count
- public int Coins;
- // players current key count
- public int Keys;
- };
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Mod Class Implementation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- public class ExampleMod : IMod
- {
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Mod Basic Information %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // set mod name
- public string Name { get { return "Legend of Luca Adventure Mod"; } }
- // set your mod description here
- public string Description { get { return "Legend of Luca Adventure Mod"; } }
- // set your mod author here
- public string Author { get { return "Some Guy"; } }
- // set your mod version here
- public int Version { get { return 1; } }
- // returns debug
- public int DebugMode { get { return 1; } }
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Player OnLoad Hook %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // mod playthrough (set via save)
- int Playthrough;
- // onload
- public void OnLoad()
- {
- // set initial playthrough to 1
- this.Playthrough = 1;
- }
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Player Spawn Load Hook (Called When Player Spawns %%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // called when player spawns into the game (start of level, game load)
- public void OnPlayerSpawn(Player player)
- {
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Add Custom Items To Game %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- /*
- // Create new item type
- ItemType itemType = new ItemType();
- itemType.Id = (ItemId)9000;
- itemType.Category = ItemCategory.Upgrade;
- itemType.Description = "\"Adventure Random Weapon Modifier\"";
- itemType.OnFound = delegate (Item item, Player player_cb)
- {
- player_cb.Damageable.MaxHealth += 1f;
- player_cb.Damageable.Health += 1f;
- };
- ItemBase.AddItem(itemType);
- */
- // display adventure mod
- // HUD.ShowMessage("Level Load", "A new Adventure has been Loaded!", 6);
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Set Player Attributes Here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // adjust players max health
- player.Damageable.MaxHealth = 20;
- // adjust players starting health
- player.Damageable.Health = 5;
- // load save state
- this.LoadModGameState("./AdventureMod.savestate");
- // set player info from save state
- if(this.current_save_game != null)
- {
- player.Coins = this.current_save_game.Coins;
- player.Bombs = this.current_save_game.Bombs;
- player.Keys = this.current_save_game.Keys;
- player.Damageable.MaxHealth = this.current_save_game.Maxhealth;
- player.Damageable.Health = this.current_save_game.Health;
- player.Damage = this.current_save_game.Damage;
- this.Playthrough = this.current_save_game.Playthrough;
- }
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Add Items To Inventory on Spawn %%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // add custom item to player inventory
- // player.AddItem(ItemId.Map);
- }
- // simply logs a message to the debug file
- public void ModLogger(String report_level, String report_message)
- {
- // log to file
- Debug.Log("Legend of Luca Adventure Mod: " + report_level + ": " + report_message);
- }
- // load all level designs
- public void LoadLevelDesignByIdx(int idx)
- {
- // exit the method
- return;
- }
- // set on level load to the current save game available
- AdventureModSaveGame current_save_game;
- // custom level loader
- public void OnGotoLevel(LevelDesign level)
- {
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Level Generator Prologue %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // Never work on levels 0, 6, or 7. Mod only works on levels 1-5.
- switch(Level.Instance.LevelNumber)
- {
- case 0:
- case 6:
- case 7:
- return;
- default:
- break;
- }
- // clear the level on startup
- Level.Instance.ClearLevel();
- // load state if it exists
- if(!this.LoadModGameState("./AdventureMod.savestate"))
- {
- // attempt to create state if no state exists
- this.SaveModGameState("./AdventureMod.savestate", this.current_save_game);
- // attempt to load from the new save (sets class member for future save data)
- this.LoadModGameState("./AdventureMod.savestate");
- }
- // go to level number if loaded level is not the same as our current level
- if(this.current_save_game != null)
- if(Level.Instance.LevelNumber != this.current_save_game.LevelNumber)
- {
- // set the instance level number before moving levels
- Level.Instance.LevelNumber = this.current_save_game.LevelNumber;
- // move levels
- Level.Instance.GotoLevel(this.current_save_game.LevelNumber);
- // exit here to prevent overlap (recurses)
- return;
- }
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Custom Load All Room Designs First %%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // Step 1) Load all room designs
- foreach (var design in Level.Instance.Designs)
- {
- if (design.Rooms == null)
- continue;
- // load room design
- design.LoadRoomDesigns(design.Rooms);
- }
- // step 2) merge all room designs into new level
- Dictionary<RoomType, List<TileLayer>> merged_design = new Dictionary<RoomType, List<TileLayer>>();
- // create lists for merged itemms
- merged_design[RoomType.Boss] = new List<TileLayer>();
- merged_design[RoomType.Hidden] = new List<TileLayer>();
- merged_design[RoomType.Normal] = new List<TileLayer>();
- merged_design[RoomType.Shop] = new List<TileLayer>();
- merged_design[RoomType.Start] = new List<TileLayer>();
- merged_design[RoomType.Treasure] = new List<TileLayer>();
- merged_design[RoomType.Weapon] = new List<TileLayer>();
- // walk the level designs
- foreach (var design in Level.Instance.Designs)
- {
- // ensure room designs aren't null
- if (design.RoomDesigns != null)
- {
- foreach (KeyValuePair<RoomType, List<TileLayer>> entry in design.RoomDesigns)
- {
- // switch on RoomType and add to the correct range
- switch(entry.Key)
- {
- // add to boss rooms
- case RoomType.Boss:
- merged_design[RoomType.Boss].AddRange(entry.Value);
- break;
- // add to hidden rooms
- case RoomType.Hidden:
- merged_design[RoomType.Hidden].AddRange(entry.Value);
- break;
- // add to normal rooms
- case RoomType.Normal:
- merged_design[RoomType.Normal].AddRange(entry.Value);
- break;
- // add to shop rooms
- case RoomType.Shop:
- merged_design[RoomType.Shop].AddRange(entry.Value);
- break;
- // add to start rooms
- case RoomType.Start:
- merged_design[RoomType.Start].AddRange(entry.Value);
- break;
- // add to treasure rooms
- case RoomType.Treasure:
- merged_design[RoomType.Treasure].AddRange(entry.Value);
- break;
- // add to weapon rooms
- case RoomType.Weapon:
- merged_design[RoomType.Weapon].AddRange(entry.Value);
- break;
- // don't add anything/bad value
- default:
- break;
- }
- }
- }
- }
- // step 3) Replace all the current room designs in our current level with the
- // merged version. This effectively gives us access to all levels in our single level.
- if (merged_design[RoomType.Boss].Count > 0)
- {
- this.ModLogger("NOTICE", "Attempting to add merged boss rooms.");
- level.RoomDesigns[RoomType.Boss] = merged_design[RoomType.Boss];
- }
- if (merged_design[RoomType.Hidden].Count > 0)
- {
- this.ModLogger("NOTICE", "Attempting to add merged weapon rooms.");
- level.RoomDesigns[RoomType.Hidden] = merged_design[RoomType.Hidden];
- }
- if (merged_design[RoomType.Normal].Count > 0)
- {
- this.ModLogger("NOTICE", "Attempting to add merged normal rooms.");
- level.RoomDesigns[RoomType.Normal] = merged_design[RoomType.Normal];
- }
- if (merged_design[RoomType.Shop].Count > 0)
- {
- this.ModLogger("NOTICE", "Attempting to add merged shop rooms.");
- level.RoomDesigns[RoomType.Shop] = merged_design[RoomType.Shop];
- }
- if (merged_design[RoomType.Start].Count > 0)
- {
- this.ModLogger("NOTICE", "Attempting to add merged starting rooms.");
- level.RoomDesigns[RoomType.Start] = merged_design[RoomType.Start];
- }
- if (merged_design[RoomType.Treasure].Count > 0)
- {
- this.ModLogger("NOTICE", "Attempting to add merged treasure rooms.");
- level.RoomDesigns[RoomType.Treasure] = merged_design[RoomType.Treasure];
- }
- if (merged_design[RoomType.Weapon].Count > 0)
- {
- this.ModLogger("NOTICE", "Attempting to add merged weapon rooms.");
- level.RoomDesigns[RoomType.Weapon] = merged_design[RoomType.Weapon];
- }
- // display mod startup notice
- this.ModLogger("NOTICE", "All level layouts have been added.");
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Level Generation Multipliers %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // Note: All multipliers are (current level * multiplier)
- // normal room multiplier
- float normal_room_multiplier = 0f;
- // pseudo random room multiplier
- float pseudo_random_room_multiplier = 0f;
- // shop room multiplier
- float shop_room_multiplier = 0f;
- // hidden room multiplier
- float hidden_room_multiplier = 0f;
- // default treasure room multiplier
- float treasure_room_multiplier = 0f;
- // the number of bogus boss rooms (there is only one actual boss room)
- float bogus_boss_room_multiplier = 0f;
- // the number of weapon rooms
- float extra_weapon_room_multiplier = 0f;
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Multiplier Adjustments Per Level %%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // setup randomizers (for adding to multiplier ranges)
- System.Random normal_room_randomizer = new System.Random();
- System.Random pseudo_random_room_randomizer = new System.Random();
- System.Random shop_room_randomizer = new System.Random();
- System.Random hidden_room_randomizer = new System.Random();
- System.Random treasure_room_randomizer = new System.Random();
- System.Random bogus_boss_room_randomizer = new System.Random();
- System.Random extra_weapon_room_randomizer = new System.Random();
- // set the instance
- Level mod_level_instance = Level.Instance;
- // perform arbitrary adjustments for level 1
- if (mod_level_instance.LevelNumber == 1)
- {
- // create level number for display
- 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.");
- // show the load message
- HUD.ShowMessage("Act 1:", display_msg, 12);
- // no adjustments required for level 1
- normal_room_multiplier = normal_room_randomizer.Next(70, 90);
- pseudo_random_room_multiplier = pseudo_random_room_randomizer.Next(70, 90);
- shop_room_multiplier = shop_room_randomizer.Next(4, 9);
- hidden_room_multiplier = hidden_room_randomizer.Next(4, 9);
- treasure_room_multiplier = treasure_room_randomizer.Next(4, 9);
- bogus_boss_room_multiplier = bogus_boss_room_randomizer.Next(4, 9);
- extra_weapon_room_multiplier = extra_weapon_room_randomizer.Next(4, 9);
- }
- // perform arbitrary adjustments for level 2 (multiply all values by 2;
- if (mod_level_instance.LevelNumber == 2)
- {
- // create level number for display
- 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)");
- // show the load message
- HUD.ShowMessage("Act 2:", display_msg, 12);
- // reduce player damage by 25% (scales mob HP)
- Player.Instance.Damage *= 0.90f;
- // no adjustments required for level 1
- normal_room_multiplier = normal_room_randomizer.Next(70, 100);
- pseudo_random_room_multiplier = pseudo_random_room_randomizer.Next(70, 100);
- shop_room_multiplier = shop_room_randomizer.Next(4, 11);
- hidden_room_multiplier = hidden_room_randomizer.Next(4, 11);
- treasure_room_multiplier = treasure_room_randomizer.Next(4, 11);
- bogus_boss_room_multiplier = bogus_boss_room_randomizer.Next(4, 11);
- extra_weapon_room_multiplier = extra_weapon_room_randomizer.Next(4, 11);
- }
- // perform arbitrary adjustments for level 3
- if (mod_level_instance.LevelNumber == 3)
- {
- // create level number for display
- 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)");
- // show the load message
- HUD.ShowMessage("Act 3:", display_msg, 12);
- // reduce player damage by 25% (scales mob HP further)
- Player.Instance.Damage *= 0.90f;
- // no adjustments required for level 1
- normal_room_multiplier = normal_room_randomizer.Next(80, 120);
- pseudo_random_room_multiplier = pseudo_random_room_randomizer.Next(80, 120);
- shop_room_multiplier = shop_room_randomizer.Next(5, 13);
- hidden_room_multiplier = hidden_room_randomizer.Next(5, 13);
- treasure_room_multiplier = treasure_room_randomizer.Next(5, 13);
- bogus_boss_room_multiplier = bogus_boss_room_randomizer.Next(5, 13);
- extra_weapon_room_multiplier = extra_weapon_room_randomizer.Next(5, 13);
- }
- // perform arbitrary adjustments for level 4
- if (mod_level_instance.LevelNumber == 4)
- {
- // create level number for display
- 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)");
- // show the load message
- HUD.ShowMessage("Act 4:", display_msg, 12);
- // reduce player damage by 25% (scales mob HP further)
- Player.Instance.Damage *= 0.90f;
- // no adjustments required for level 1
- normal_room_multiplier = normal_room_randomizer.Next(90, 130);
- pseudo_random_room_multiplier = pseudo_random_room_randomizer.Next(30, 130);
- shop_room_multiplier = shop_room_randomizer.Next(6, 16);
- hidden_room_multiplier = hidden_room_randomizer.Next(6, 16);
- treasure_room_multiplier = treasure_room_randomizer.Next(6, 16);
- bogus_boss_room_multiplier = bogus_boss_room_randomizer.Next(6, 16);
- extra_weapon_room_multiplier = extra_weapon_room_randomizer.Next(6, 16);
- }
- // perform arbitrary adjustments for level 5
- if (mod_level_instance.LevelNumber == 5)
- {
- // create level number for display
- 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)");
- // show the load message
- HUD.ShowMessage("Act 5:", display_msg, 12);
- // reduce player damage by 35% (scales mob HP further)
- Player.Instance.Damage *= 0.90f;
- // no adjustments required for level 1
- normal_room_multiplier = normal_room_randomizer.Next(120, 150);
- pseudo_random_room_multiplier = pseudo_random_room_randomizer.Next(120, 150);
- shop_room_multiplier = shop_room_randomizer.Next(8, 20);
- hidden_room_multiplier = hidden_room_randomizer.Next(8, 20);
- treasure_room_multiplier = treasure_room_randomizer.Next(8, 20);
- bogus_boss_room_multiplier = bogus_boss_room_randomizer.Next(8, 20);
- extra_weapon_room_multiplier = extra_weapon_room_randomizer.Next(8, 20);
- }
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Level Generation Loop %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // NOTE: This try except creates a "loop". If level generation fails (and it does fail, this is normal)
- // the loop will attempt to create the level again. Levels will fail generation when the generation
- // engine "paints itself into a corner."
- // attempt level generation
- try
- {
- // set spawn room
- mod_level_instance.SpawnRoom = mod_level_instance.CreateRoom(Level.CenterRoomsX, Level.CenterRoomsY, RoomType.Start);
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Step 1) Create "Normal" Rooms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // set current room
- var currentRoom = mod_level_instance.SpawnRoom;
- // create "normal" rooms first (using random direction)
- for
- (
- int i = 0;
- i < normal_room_multiplier;
- i++
- )
- {
- // add debug message
- this.ModLogger("NOTICE", "Spawning 'normal' room.");
- // add normal room in random direction
- currentRoom = mod_level_instance.AddRoom(currentRoom, Level.RandomDirection());
- }
- // add debug message
- this.ModLogger("NOTICE", "Finished spawning 'normal' room.");
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Add Some Pseudo-Random Rooms (Adds Depth to Layouts) %%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // set current room
- currentRoom = mod_level_instance.SpawnRoom;
- // create pseudorandom layout
- for
- (
- int i = 0;
- i < pseudo_random_room_multiplier;
- i++
- )
- {
- // add debug message
- this.ModLogger("NOTICE", "Spawning 'pseudo random' room.");
- // add pr room
- currentRoom = mod_level_instance.AddRoom(currentRoom, mod_level_instance.PsudoRandomDirection(currentRoom));
- }
- // add debug message
- this.ModLogger("NOTICE", "Finished spawning 'pseudo random' rooms.");
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Add Some Hidden Rooms (Adds Depth to Layouts) %%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // set current room
- currentRoom = mod_level_instance.SpawnRoom;
- // create pseudorandom layout
- for
- (
- int i = 0;
- i < hidden_room_multiplier;
- i++
- )
- {
- // add debug message
- this.ModLogger("NOTICE", "Spawning 'hidden' room.");
- // add hidden room
- currentRoom = mod_level_instance.AddNewRoom(RoomType.Hidden);
- }
- // add debug message
- this.ModLogger("NOTICE", "Finished spawning 'hidden' rooms.");
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Add Some Treasure Rooms (Adds Depth to Layouts) %%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // set current room
- currentRoom = mod_level_instance.SpawnRoom;
- // create pseudorandom layout
- for
- (
- int i = 0;
- i < treasure_room_multiplier;
- i++
- )
- {
- // add debug message
- this.ModLogger("NOTICE", "Spawning 'treasure' room.");
- // add treasure room
- currentRoom = mod_level_instance.AddNewRoom(RoomType.Treasure);
- }
- // add debug message
- this.ModLogger("NOTICE", "Finished spawning 'treasure' rooms.");
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Add Some Shop Rooms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // set current room
- currentRoom = mod_level_instance.SpawnRoom;
- // create pseudorandom layout
- for
- (
- int i = 0;
- i < shop_room_multiplier;
- i++
- )
- {
- // add debug message
- this.ModLogger("NOTICE", "Spawning 'shop' room.");
- // add shop room
- currentRoom = mod_level_instance.AddNewRoom(RoomType.Shop);
- }
- // add debug message
- this.ModLogger("NOTICE", "Finished spawning 'shop' rooms.");
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%% Link up Rooms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // link up rooms
- mod_level_instance.LinkAllNormalRooms();
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Add Some Bogus Bosses for Extra Loot %%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // create bogus bosses layout
- for
- (
- int i = 0;
- i < bogus_boss_room_multiplier;
- i++
- )
- {
- currentRoom = mod_level_instance.AddNewRoom(RoomType.Boss);
- }
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Add Extra Weapon Rooms %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // create pseudorandom layout
- for
- (
- int i = 0;
- i < mod_level_instance.LevelNumber * extra_weapon_room_multiplier;
- i++
- )
- {
- currentRoom = mod_level_instance.AddNewRoom(RoomType.Weapon);
- }
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Add Final Boss Room %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // add debug message
- this.ModLogger("NOTICE", "Attempting to lookup random room that is not our spawn room.");
- // this loop prevents ever linking a start room to a boss room
- while (currentRoom == mod_level_instance.SpawnRoom)
- {
- currentRoom = mod_level_instance.GetRandomNormalRoom();
- }
- // set lookup succeeded notice
- this.ModLogger("NOTICE", "Lookup succeeded.");
- // add boss room
- currentRoom = mod_level_instance.AddNewRoom(RoomType.Boss, currentRoom);
- // set lookup succeeded notice
- this.ModLogger("NOTICE", "Final boss room has been added.");
- // attempt to link to level if we have a next level
- if (mod_level_instance.LevelNumber != 5)
- {
- // set lookup succeeded notice
- this.ModLogger("NOTICE", "Adding final weapon room.");
- // set current room
- currentRoom = mod_level_instance.AddNewRoom(RoomType.Weapon, currentRoom);
- // set lookup succeeded notice
- this.ModLogger("NOTICE", "Final weapon room has been added.");
- // link the new weapon room to the next level (level + 1)
- mod_level_instance.LinkRoomToLevel
- (
- currentRoom,
- mod_level_instance.GetAvailableDirection(currentRoom),
- mod_level_instance.LevelNumber + 1
- );
- // set lookup succeeded notice
- this.ModLogger("NOTICE", "Final weapon room has been linked to next level.");
- }
- else
- {
- // if you beat the game link to victory level
- mod_level_instance.LinkRoomToLevel
- (
- currentRoom,
- mod_level_instance.GetAvailableDirection(currentRoom),
- LevelDesign.VictoryLevelNumber
- );
- }
- }
- catch (Exception e)
- {
- Debug.Log("Legend of Luca Adventure Mod: Level Generator Error Caused Regen: " + e.ToString());
- mod_level_instance.ClearLevel();
- level.SetLevel();
- return;
- }
- // exit
- return;
- }
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Load/Save Game Game Methods %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // load mod game state
- public bool LoadModGameState(String load_file)
- {
- // ensure the save game exists
- if (!File.Exists(load_file))
- return false;
- // load json save data
- var json_save_data = System.IO.File.ReadAllText(load_file);
- // load json data as a new object
- AdventureModSaveGame save_game_object = JsonUtility.FromJson<AdventureModSaveGame>(json_save_data);
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%% Load Player Attributes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- // set player bombs
- if (save_game_object.Bombs > 0)
- Player.Instance.Bombs = save_game_object.Bombs;
- // set player keys
- if (save_game_object.Keys > 0)
- Player.Instance.Keys = save_game_object.Keys;
- // set player coins
- if (save_game_object.Coins > 0)
- Player.Instance.Coins = save_game_object.Coins;
- // set player damage
- if (save_game_object.Damage > 0)
- Player.Instance.Damage = save_game_object.Damage;
- // current playthrough
- if (save_game_object.Playthrough > 0)
- this.Playthrough = save_game_object.Playthrough;
- // set max health
- if (save_game_object.Maxhealth > 0)
- Player.Instance.Damageable.MaxHealth = save_game_object.Maxhealth;
- // set health
- if (save_game_object.Health > 0)
- Player.Instance.Damageable.Health = save_game_object.Health;
- // set the current save game as the loaded save game
- this.current_save_game = save_game_object;
- // return indicating success
- return true;
- }
- // attempt to save mod game state
- public bool SaveModGameState
- (
- String save_file,
- AdventureModSaveGame save_game_info
- )
- {
- // create json from json info
- var save_as_json = JsonUtility.ToJson(save_game_info);
- if (save_as_json == null)
- return false;
- // write our json to disk
- System.IO.File.WriteAllText(save_file, save_as_json);
- // return indicating success
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement