2020-09-07 03:40:28 -04:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class HazardManager
|
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
private GameManager gameManager;
|
2020-09-07 03:40:28 -04:00
|
|
|
|
|
2020-09-08 04:10:07 -04:00
|
|
|
|
public HazardManager(GameManager gameManager)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
this.gameManager = gameManager;
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateHazards()
|
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
if (gameManager.hazardsEnabled == true)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
if (gameManager.player.timeToDeliver == false && gameManager.rocketScript.gameTime < 2000)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
|
|
|
|
// Pirate attacks
|
2020-09-08 04:10:07 -04:00
|
|
|
|
if (gameManager.rocketScript.day >= 10 && gameManager.GetComponent<StateManager>().worldLoaded == true)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
gameManager.pirateAttackTimer += 1 * Time.deltaTime;
|
|
|
|
|
if (gameManager.loadedPirateTimer == true)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
FileBasedPrefs.SetFloat(gameManager.GetComponent<StateManager>().WorldName + "pirateAttackTimer", gameManager.pirateAttackTimer);
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
2020-09-08 04:10:07 -04:00
|
|
|
|
if (gameManager.pirateAttackTimer >= 530 & gameManager.pirateAttackTimer < 540)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
if (gameManager.player != null)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
gameManager.player.pirateAttackWarningActive = true;
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-08 04:10:07 -04:00
|
|
|
|
else if (gameManager.pirateAttackTimer >= 540 && gameManager.pirateAttackTimer < 600)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
if (gameManager.player != null)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
gameManager.player.pirateAttackWarningActive = false;
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
2020-09-08 04:10:07 -04:00
|
|
|
|
gameManager.pirateFrequency = 40 - gameManager.rocketScript.day;
|
|
|
|
|
if (gameManager.pirateFrequency < 2)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
gameManager.pirateFrequency = 2;
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
2020-09-08 04:10:07 -04:00
|
|
|
|
gameManager.pirateTimer += 1 * Time.deltaTime;
|
|
|
|
|
if (gameManager.pirateTimer >= gameManager.pirateFrequency && gameManager.GetComponent<StateManager>().worldLoaded == true)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
|
|
|
|
float x = Random.Range(-4500, 4500);
|
|
|
|
|
float z = Random.Range(-4500, 4500);
|
|
|
|
|
int RandomSpawn = Random.Range(1, 5);
|
|
|
|
|
if (RandomSpawn == 1)
|
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
Object.Instantiate(gameManager.pirateObject, new Vector3(x, 400, 10000), gameManager.transform.rotation);
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
|
|
|
|
if (RandomSpawn == 2)
|
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
GameObject pirate = Object.Instantiate(gameManager.pirateObject, new Vector3(x, 400, -10000), gameManager.transform.rotation);
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
|
|
|
|
if (RandomSpawn == 3)
|
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
GameObject pirate = Object.Instantiate(gameManager.pirateObject, new Vector3(10000, 400, z), gameManager.transform.rotation);
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
|
|
|
|
if (RandomSpawn == 4)
|
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
GameObject pirate = Object.Instantiate(gameManager.pirateObject, new Vector3(-10000, 400, z), gameManager.transform.rotation);
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
2020-09-08 04:10:07 -04:00
|
|
|
|
gameManager.pirateTimer = 0;
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-08 04:10:07 -04:00
|
|
|
|
else if (gameManager.pirateAttackTimer >= 900)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
gameManager.pirateAttackTimer = 0;
|
|
|
|
|
gameManager.player.destructionMessageActive = false;
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Meteor showers
|
2020-09-08 04:10:07 -04:00
|
|
|
|
if (gameManager.GetComponent<StateManager>().worldLoaded)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
gameManager.meteorShowerTimer += 1 * Time.deltaTime;
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-08 04:10:07 -04:00
|
|
|
|
if (gameManager.loadedMeteorTimer == true)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
FileBasedPrefs.SetFloat(gameManager.GetComponent<StateManager>().WorldName + "meteorShowerTimer", gameManager.meteorShowerTimer);
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
2020-09-08 04:10:07 -04:00
|
|
|
|
if (gameManager.meteorShowerTimer >= 530 && gameManager.meteorShowerTimer < 540)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
if (gameManager.player != null)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
gameManager.player.meteorShowerWarningActive = true;
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-08 04:10:07 -04:00
|
|
|
|
else if (gameManager.meteorShowerTimer >= 540 && gameManager.meteorShowerTimer < 600)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
|
|
|
|
bool locationFound = false;
|
|
|
|
|
GameObject[] allObjects = GameObject.FindGameObjectsWithTag("Built");
|
|
|
|
|
foreach (GameObject go in allObjects)
|
|
|
|
|
{
|
|
|
|
|
if (locationFound == false)
|
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
if (!gameManager.meteorShowerLocationList.Contains(go.transform.position))
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
gameManager.meteorShowerLocation = go.transform.position;
|
|
|
|
|
gameManager.meteorShowerLocationList.Add(gameManager.meteorShowerLocation);
|
2020-09-07 03:40:28 -04:00
|
|
|
|
locationFound = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-08 04:10:07 -04:00
|
|
|
|
if (locationFound == false && gameManager.meteorShowerLocationList.Count > 0)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
gameManager.meteorShowerLocationList.Clear();
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
2020-09-08 04:10:07 -04:00
|
|
|
|
gameManager.meteorTimer += 1 * Time.deltaTime;
|
|
|
|
|
if (gameManager.meteorTimer > 0.5f && gameManager.GetComponent<StateManager>().worldLoaded == true)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
float x = Random.Range(gameManager.meteorShowerLocation.x - 500, gameManager.meteorShowerLocation.x + 500);
|
|
|
|
|
float z = Random.Range(gameManager.meteorShowerLocation.z - 500, gameManager.meteorShowerLocation.z + 500);
|
|
|
|
|
Object.Instantiate(gameManager.meteorObject, new Vector3(x, 500, z), gameManager.transform.rotation);
|
|
|
|
|
gameManager.meteorTimer = 0;
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
2020-09-08 04:10:07 -04:00
|
|
|
|
if (gameManager.player != null)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
gameManager.player.meteorShowerWarningActive = false;
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-08 04:10:07 -04:00
|
|
|
|
else if (gameManager.meteorShowerTimer >= 900)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
gameManager.meteorShowerTimer = 0;
|
|
|
|
|
gameManager.player.destructionMessageActive = false;
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
gameManager.pirateAttackTimer = 0;
|
|
|
|
|
gameManager.meteorShowerTimer = 120;
|
|
|
|
|
if (gameManager.player != null)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
gameManager.player.destructionMessageActive = false;
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
StopHazards();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Removes all hazards from the world
|
|
|
|
|
private void StopHazards()
|
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
gameManager.pirateTimer = 0;
|
|
|
|
|
gameManager.meteorTimer = 0;
|
|
|
|
|
gameManager.pirateAttackTimer = 0;
|
|
|
|
|
gameManager.meteorShowerTimer = 120;
|
|
|
|
|
if (gameManager.loadedMeteorTimer == true)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
FileBasedPrefs.SetFloat(gameManager.GetComponent<StateManager>().WorldName + "meteorShowerTimer", gameManager.meteorShowerTimer);
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
2020-09-08 04:10:07 -04:00
|
|
|
|
if (gameManager.loadedPirateTimer == true)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
FileBasedPrefs.SetFloat(gameManager.GetComponent<StateManager>().WorldName + "pirateAttackTimer", gameManager.pirateAttackTimer);
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
2020-09-08 04:10:07 -04:00
|
|
|
|
if (gameManager.player != null)
|
2020-09-07 03:40:28 -04:00
|
|
|
|
{
|
2020-09-08 04:10:07 -04:00
|
|
|
|
gameManager.player.meteorShowerWarningActive = false;
|
|
|
|
|
gameManager.player.pirateAttackWarningActive = false;
|
|
|
|
|
gameManager.player.destructionMessageActive = false;
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
2020-09-08 04:10:07 -04:00
|
|
|
|
gameManager.hazardRemovalCoroutine = gameManager.StartCoroutine(HazardRemovalCoroutine());
|
2020-09-07 03:40:28 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Removes all hazards from the world
|
|
|
|
|
private IEnumerator HazardRemovalCoroutine()
|
|
|
|
|
{
|
|
|
|
|
Meteor[] allMeteors = Object.FindObjectsOfType<Meteor>();
|
|
|
|
|
foreach (Meteor meteor in allMeteors)
|
|
|
|
|
{
|
|
|
|
|
if (meteor.destroying == false)
|
|
|
|
|
{
|
|
|
|
|
meteor.Explode();
|
|
|
|
|
}
|
|
|
|
|
yield return new WaitForSeconds(0.1f);
|
|
|
|
|
}
|
|
|
|
|
Pirate[] allPirates = Object.FindObjectsOfType<Pirate>();
|
|
|
|
|
foreach (Pirate pirate in allPirates)
|
|
|
|
|
{
|
|
|
|
|
if (pirate.destroying == false)
|
|
|
|
|
{
|
|
|
|
|
pirate.Explode();
|
|
|
|
|
}
|
|
|
|
|
yield return new WaitForSeconds(0.1f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|