// Use this for initialization void Start() { player = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerProgramController>(); actionBtns = GameObject.FindGameObjectsWithTag("ActionBtn"); fastForwardTgl = GameObject.FindGameObjectWithTag("FFToggle").GetComponent <Toggle>(); DisplayHotkeys(); }
public void EnableExtraActions() { PlayerProgramController player = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerProgramController>(); bool isRepel = player.isRepelAvailable; bool isReveal = player.isRevealAvailable; bool isRevealUsed = player.isRevealUsed; bool isConvert = player.isConvertAvailable; repelBtn.interactable = isRepel; revealBtn.interactable = (isReveal && !isRevealUsed); convertBtn.interactable = isConvert; }
public void LoadPreviousLevelData() { if (File.Exists(levelEndFileName)) { string jsonSave = File.ReadAllText(levelEndFileName); LevelEndData loadedLevelEndData = JsonUtility.FromJson <LevelEndData>(jsonSave); PlayerProgramController playerCont = player.GetComponent <PlayerProgramController>(); playerCont.maxActionPoints = loadedLevelEndData.playerAP; playerCont.maxHealth = loadedLevelEndData.playerMaxHealth; playerCont.visibilityMultiplier = loadedLevelEndData.playerVisibility; playerCont.damage = loadedLevelEndData.playerDamage; playerCont.isRepelAvailable = loadedLevelEndData.isRepelAvailable; playerCont.isRevealAvailable = loadedLevelEndData.isRevealAvailable; playerCont.isConvertAvailable = loadedLevelEndData.isConvertAvailable; } }
public void IntegrateUpgrades() { PlayerProgramController playerCont = player.GetComponent <PlayerProgramController>(); if (File.Exists(upgradeFileName)) { string jsonSave = File.ReadAllText(upgradeFileName); UpgradeData loadedUpgradeData = JsonUtility.FromJson <UpgradeData>(jsonSave); //make initial stats consistent with last level playerCont.maxActionPoints += loadedUpgradeData.apIncrease; playerCont.maxHealth += loadedUpgradeData.healthIncrease; playerCont.currHealth = playerCont.maxHealth; playerCont.actionPoints = playerCont.maxActionPoints; playerCont.damage += loadedUpgradeData.damageIncrease; playerCont.visibilityMultiplier += loadedUpgradeData.visibilityIncrease; if (!playerCont.isRepelAvailable) { playerCont.isRepelAvailable = loadedUpgradeData.isRepelPurchased; } if (!playerCont.isRevealAvailable) { playerCont.isRevealAvailable = loadedUpgradeData.isRevealPurchased; } if (!playerCont.isConvertAvailable) { playerCont.isConvertAvailable = loadedUpgradeData.isConvertPurchased; } //save upgrades in the map data playerCont.lastPos = playerCont.transform.position; SaveMapData(null); File.Delete(upgradeFileName); } }
public void SaveEndOfLevelData() { //level is done so delete any data that was kept in case of losing and having to revert upgrades string upgradeCostRevertFileName = Path.Combine(Application.persistentDataPath, "UpgradeCostRevertData.json"); string totalUpgradeRevertFileName = Path.Combine(Application.persistentDataPath, "TotalUpgradeRevertData.json"); if (File.Exists(upgradeCostRevertFileName)) { File.Delete(upgradeCostRevertFileName); } if (File.Exists(totalUpgradeRevertFileName)) { File.Delete(totalUpgradeRevertFileName); } LevelEndData LevelEndData = new LevelEndData(); PlayerProgramController playerCont = player.GetComponent <PlayerProgramController>(); LevelEndData.playerMaxHealth = playerCont.maxHealth; LevelEndData.playerAP = playerCont.maxActionPoints; LevelEndData.playerDamage = playerCont.damage; LevelEndData.playerVisibility = playerCont.visibilityMultiplier; LevelEndData.isRepelAvailable = playerCont.isRepelAvailable; LevelEndData.isRevealAvailable = playerCont.isRevealAvailable; LevelEndData.isConvertAvailable = playerCont.isConvertAvailable; //save if key has been collected in level if (key == null) { if (SceneManager.GetActiveScene().buildIndex == 2) { if (!key1Collected) { key1Collected = true; numKeys++; } } if (SceneManager.GetActiveScene().buildIndex == 3) { if (!key2Collected) { key2Collected = true; numKeys++; } } if (SceneManager.GetActiveScene().buildIndex == 4) { if (!key3Collected) { key3Collected = true; numKeys++; } } if (SceneManager.GetActiveScene().buildIndex == 5) { if (!key4Collected) { key4Collected = true; numKeys++; } } } string json = JsonUtility.ToJson(LevelEndData); if (File.Exists(levelEndFileName)) { File.Delete(levelEndFileName); } File.WriteAllText(levelEndFileName, json); }
public void LoadMapData() { PlayerProgramController playerCont = player.GetComponent <PlayerProgramController>(); if (File.Exists(mapFileName)) { string jsonSave = File.ReadAllText(mapFileName); MapData loadedMapData = JsonUtility.FromJson <MapData>(jsonSave); player.transform.position = loadedMapData.playerPos; playerCont.actionPoints = loadedMapData.playerAP; playerCont.maxHealth = loadedMapData.playerMaxHealth; playerCont.maxActionPoints = loadedMapData.playerMaxAP; playerCont.actionPoints = loadedMapData.playerCurrAP; Debug.Log(loadedMapData.playerCurrAP); playerCont.visibilityMultiplier = loadedMapData.playerVisibility; playerCont.isRepelAvailable = loadedMapData.isRepelAvailable; playerCont.isRevealAvailable = loadedMapData.isRevealAvailable; playerCont.isConvertAvailable = loadedMapData.isConvertAvailable; TurnController._instance.speedChangeTgl.isOn = loadedMapData.isFastForward; TurnController._instance.ChangeSpeed(loadedMapData.isFastForward); OverlayController._instance.areHotkeysDisplayed = loadedMapData.areHotkeysDisplayed; foreach (GameObject enemy in enemies) { EnemyMap enemyData = enemy.GetComponent <EnemyMap>(); enemy.transform.position = loadedMapData.enemyPos[enemyData.enemyID]; enemyData.isAlive = loadedMapData.enemyState[enemyData.enemyID]; if (!enemyData.isAlive) { Destroy(enemy); } } foreach (PowerUpObject power in powerUps) { if (power.gameObject != null) { power.isCollected = loadedMapData.powerUpState[power.id]; if (power.isCollected) { power.gameObject.SetActive(false); } } } if (key != null) { KeyController keyData = key.GetComponent <KeyController>(); keyData.isCollected = loadedMapData.keyState; if (keyData.isCollected) { Destroy(key); } } } if (File.Exists(combatFileName)) { string jsonSave = File.ReadAllText(combatFileName); CombatData loadedCombatData = JsonUtility.FromJson <CombatData>(jsonSave); playerCont.currHealth = loadedCombatData.health; playerCont.damage = loadedCombatData.damage; playerCont.actionPoints = playerCont.actionPoints + loadedCombatData.apToAdd; Debug.Log(loadedCombatData.apToAdd); } }
public void SaveMapData(GameObject details) { MapData data = new MapData(); PlayerProgramController playerCont = player.GetComponent <PlayerProgramController>(); data.playerPos = playerCont.lastPos; data.playerAP = playerCont.actionPoints; data.playerMaxHealth = playerCont.maxHealth; data.playerMaxAP = playerCont.maxActionPoints; data.playerCurrAP = playerCont.actionPoints; Debug.Log(data.playerCurrAP); data.playerVisibility = playerCont.visibilityMultiplier; data.isRepelAvailable = playerCont.isRepelAvailable; data.isRevealAvailable = playerCont.isRevealAvailable; data.isConvertAvailable = playerCont.isConvertAvailable; data.enemyPos = new Vector3[enemiesCount]; data.enemyState = new bool[enemiesCount]; data.powerUpState = new bool[powerUps.Length]; data.keyState = (key == null); data.isFastForward = TurnController._instance.speedChangeTgl.isOn; data.areHotkeysDisplayed = OverlayController._instance.areHotkeysDisplayed; foreach (GameObject enemy in enemies) { if (enemy != null) { EnemyMap enemyData = enemy.GetComponent <EnemyMap>(); data.enemyPos[enemyData.enemyID] = enemy.transform.position; data.enemyState[enemyData.enemyID] = enemyData.isAlive; } } foreach (PowerUpObject power in powerUps) { if (power.gameObject != null) { data.powerUpState[power.id] = power.isCollected; } } if (details != null) { data.isEnemy = details.GetComponent <EnemyMap>().isEnemy; data.isSpider = details.GetComponent <EnemyMap>().isSpider; data.isTurret = details.GetComponent <EnemyMap>().isTurret; data.isTank = details.GetComponent <EnemyMap>().isTank; data.enemyAmt = details.GetComponent <EnemyMap>().enemyAmt; data.spiderAmt = details.GetComponent <EnemyMap>().spiderAmt; data.turretAmt = details.GetComponent <EnemyMap>().turretAmt; data.tankAmt = details.GetComponent <EnemyMap>().tankAmt; } string json = JsonUtility.ToJson(data); if (File.Exists(mapFileName)) { File.Delete(mapFileName); } File.WriteAllText(mapFileName, json); CombatData combatData = new CombatData(); combatData.health = playerCont.currHealth; combatData.damage = playerCont.damage; json = JsonUtility.ToJson(combatData); if (File.Exists(combatFileName)) { File.Delete(combatFileName); } File.WriteAllText(combatFileName, json); }
private void Start() { player = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerProgramController>(); }