using System.Collections.Generic; using UnityEngine; public class MissionSelect : MonoBehaviour { private List<string> missionNames = new List<string>() { "Assault", "Defend", "Kill", "Protect", "Destroy", "Hack" }; private List<string> missionDetails = new List<string>() { "Take over the enemy held area", "Stop the enemy from destroying our structure and then destroy them", "Destroy all enemy bots in the area", "Allied bots are deployed in the area, protect them and destroy all enemy bots", "Destroy the enemy structure in the area", "Hack into the enemy terminal to gather data" }; private List<string> factionNames = new List<string>() { "Tannerick", "Foundry", "Intelligent Applications", "Welders", "Orbital Acquisions", "Holy Federation", "Reclaimers" }; private List<string> difficultySetting = new List<string>() { "Easy", "Normal", "Hard", "Insane" }; public List<Sprite> factionImages = new List<Sprite>(); public GameObject missionPrefab; private string missionName; private string missionDesc; private string factionName; private Sprite factionImage; private string difficulty; private int rewards1; private int rewards2; private HUBTracker hubTracker; private InventoryManager invMgr; private SaveFileManager saveMgr; private int currentCash; private GameObject spWarning; private List<GameObject> missionsGenerated = new List<GameObject>(); void Start() { hubTracker = GameObject.Find("Persistent Object").GetComponent<HUBTracker>(); invMgr = GameObject.Find("Persistent Object").GetComponent<InventoryManager>(); saveMgr = GameObject.Find("Persistent Object").GetComponent<SaveFileManager>(); spWarning = GameObject.Find("Un-Used Skill Points Warning Panel"); currentCash = invMgr.currency; int index = saveMgr.saveFileIndex; SaveGameData saveInfo = saveMgr.GetSaveData(index); Debug.Log("Mission data from save file: " + saveInfo.missions.Count); if (saveInfo.missions.Count != 0 && saveInfo.missions != null) { Debug.Log("Mission data was found, loading missions"); LoadMissions(); } else { Debug.Log("No mission data found, creating new missions"); CreateMissions(); } } void Update() { if (currentCash != invMgr.currency) currentCash = invMgr.currency; } public void CreateMissions() { int fourthRandom = Random.Range(3, 8); GameObject currentMissionPrefab = null; for (int i = 0; i < fourthRandom; i++) { int random = Random.Range(0, missionNames.Count); missionName = missionNames[random]; missionDesc = missionDetails[random]; int secondRandom = Random.Range(0, factionNames.Count); factionName = factionNames[secondRandom]; factionImage = factionImages[secondRandom]; int thirdRandom = 0; //thirdRandom is used to define the difficulty of a mission and decides the rewards that are given if (hubTracker.allBots[0].level >= 9 || hubTracker.allBots[1].level >= 9 || hubTracker.allBots[2].level >= 9 || hubTracker.allBots[3].level >= 9) //if any bots level is greater than or equal to 7, include insane missions { thirdRandom = Random.Range(0, 4); } else if (hubTracker.allBots[0].level >= 5 || hubTracker.allBots[1].level >= 5 || hubTracker.allBots[2].level >= 5 || hubTracker.allBots[3].level >= 5) //if any bots level is greater than or equal to 5, include hard missions { thirdRandom = Random.Range(0, 3); } else //if the bots levels are too low to satify any of the above requirements, only include easy and normal { thirdRandom = Random.Range(0, 2); } difficulty = difficultySetting[thirdRandom]; switch (thirdRandom) { case 0: rewards1 = 30; rewards2 = 15; break; case 1: rewards1 = 40; rewards2 = 20; break; case 2: rewards1 = 50; rewards2 = 25; break; case 3: rewards1 = 60; rewards2 = 30; break; } int fifthRandom = Random.Range(-10, 11); int sixthRandom = Random.Range(-10, 11); rewards1 += fifthRandom; rewards2 += sixthRandom; currentMissionPrefab = Instantiate(missionPrefab as GameObject, this.gameObject.transform, false); //spawn the number of random mission prefabs currentMissionPrefab.GetComponent<MissionSetup>().SetMissionInfo(missionName, missionDesc, factionName, factionImage, difficulty, rewards1, rewards2); currentMissionPrefab.GetComponent<MissionGetSPWarning>().SetWarningPanel(spWarning); missionsGenerated.Add(currentMissionPrefab); } Debug.Log("Finished creating new missions, sending mission info to the save file manager"); spWarning.SetActive(false); saveMgr.SendDataToSaveSystem(); } public void LoadMissions() { int index = saveMgr.saveFileIndex; SaveGameData saveInfo = saveMgr.GetSaveData(index); int numberOfMissions = saveInfo.missions.Count; GameObject currentMissionPrefab = null; for (int i = 0; i < numberOfMissions; i++) { missionName = saveInfo.missions[i].missionName; missionDesc = saveInfo.missions[i].missionDesc; factionName = saveInfo.missions[i].factionName; difficulty = saveInfo.missions[i].difficulty; rewards1 = saveInfo.missions[i].rewards1; rewards2 = saveInfo.missions[i].rewards2; for (int y = 0; y < factionNames.Count; y++) { if (factionNames[y] == factionName) { factionImage = factionImages[y]; break; } } currentMissionPrefab = Instantiate(missionPrefab as GameObject, this.gameObject.transform, false); //spawn the number of random mission prefabs currentMissionPrefab.GetComponent<MissionSetup>().SetMissionInfo(missionName, missionDesc, factionName, factionImage, difficulty, rewards1, rewards2); currentMissionPrefab.GetComponent<MissionGetSPWarning>().SetWarningPanel(spWarning); missionsGenerated.Add(currentMissionPrefab); } Debug.Log("Finished loading saved missions"); spWarning.SetActive(false); saveMgr.SendDataToSaveSystem(); } public void GenerateNewMissions() { if (currentCash >= 30) { foreach (GameObject child in GameObject.FindGameObjectsWithTag("Mission")) { Destroy(child); } missionsGenerated.Clear(); CreateMissions(); } } public List<GameObject> GetMissionsList() { return missionsGenerated; } }