﻿/*
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;

using PhotonHashTable = ExitGames.Client.Photon.Hashtable;


public class StartMatch : MonoBehaviour {

    // these prefabs are only used if the player isn't connected to photon
    // (so these are only used in the unity editor)
    public GameObject playerPrefab;

    public GameObject llamaPrefab;

    public GameObject[] wandPrefabs;
    public GameObject chestPrefab;

    MapScript mapScript;

    public int minWands = 100;
    public int maxWands = 150;

    public bool spawningPlayer;
    public bool loading;

    public GameObject StaticLoadingScreen;

    public static bool matchStarted;


    public AudioManager audioManager;

	public GameGenerator generator;

    void Awake() {
        matchStarted = false;
        StaticLoadingScreen.SetActive(true);
    }

    // Use this for initialization
    void Start () {
        StartCoroutine(FinishLoadingThenStart());
    }

    IEnumerator FinishLoadingThenStart() {
        loading = true;
        if (!PhotonNetwork.IsConnected) {
            while (GridHandler.initializing) {
                yield return null;
            }
        }
        else {
            bool completed = false;
			float forceStartTimer = 0f;
			while (!completed && !generator.startMatchForced) {
                if(!PhotonNetwork.IsConnected || PhotonNetwork.CurrentRoom == null) {
                    yield break;
                }
                Dictionary<int, Photon.Realtime.Player> players = PhotonNetwork.CurrentRoom.Players;
                if (players.Count > 1) {
                    completed = true;
                    foreach (KeyValuePair<int, Photon.Realtime.Player> player in players) {
                        PhotonHashTable playerTable = player.Value.CustomProperties;
                        object prop;
						if (playerTable.TryGetValue ("loading", out prop)) {
							if ((bool)prop) {
								Debug.LogError ("UserID: " + player.Value.UserId + ", Got Value");
								completed = false;
								yield return null;
								break;
							}
						} else {
							Debug.LogError ("UserID: " + player.Value.UserId + ", No Loading Value");
						}
                    }
					if (PhotonNetwork.IsMasterClient) {
						forceStartTimer += Time.unscaledDeltaTime;
						if (forceStartTimer > 45f) {
							generator.GetComponent<PhotonView>().RPC("ForcePlayerDrop", RpcTarget.AllBuffered);
						}
					}
					Debug.Log (forceStartTimer);
                }
                else
                    yield return null;
            }
        }
        loading = false;
        audioManager.StopMusic();
        StaticLoadingScreen.SetActive(false);
        mapScript = GameObject.FindGameObjectWithTag("Map Cam").GetComponent<MapScript>();
        mapScript.OpenMapForPlayerToChooseLocationForDrop();
        StartCoroutine(SpawnPlayers());
    }

    IEnumerator SpawnPlayers() {
        spawningPlayer = true;
        matchStarted = true;
        bool joinAsSpectator = false;
        object prop;
        if(PhotonNetwork.IsConnected && PhotonNetwork.LocalPlayer.CustomProperties.TryGetValue("IsSpectator", out prop)) {
            joinAsSpectator = (bool)prop;
        }
        yield return new WaitForSecondsRealtime(20f);

        // need to wait to recieve the random seed before spawning anything
        GameGenerator.SetRandomToOldSeed();
        SpawnLlama();

        Random.InitState(System.DateTime.Now.Millisecond + (int)(Time.unscaledTime * 1000));
        if (!joinAsSpectator) {
            if (!mapScript.HasPinBeenPlaced()) {
                SpawnLocalPlayerRandomly();
            }
            else {
                SpawnLocalPlayer(mapScript.GetWorldPositionOfPin());
            }
        }
        else {
            SpectatorController spectatorController = GameObject.FindGameObjectWithTag("Game Manager").GetComponent<SpectatorController>();
            spectatorController.SpectateAnyPlayer();
        }
        GameGenerator.SetRandomToOldSeed();
		if (!joinAsSpectator) {
			mapScript.CloseMapForPlayerToChooseLocationForDrop ();
		}
        spawningPlayer = false;
    }

    void SpawnLlama() {
        Vector3 spawnPoint = GetRandomSpawnPoint();
        spawnPoint.y += 4f;
        if (llamaPrefab)
            Instantiate(llamaPrefab, spawnPoint, Quaternion.identity);
    }

    void SpawnLocalPlayer(Vector3 spawnPoint) {
        spawnPoint.y += 150f;
		if (PhotonNetwork.IsConnected) {
            PhotonNetwork.Instantiate("player", spawnPoint, Quaternion.identity);
			audioManager.transform.GetComponentInParent<Rotate> ().canRot = false;
        }
        else {
			Instantiate(playerPrefab, spawnPoint, Quaternion.identity);
			audioManager.transform.GetComponentInParent<Rotate> ().canRot = false;
        }
    }

    void SpawnLocalPlayerRandomly() {
        SpawnLocalPlayer(GetRandomSpawnPoint());
    }

    void SpawnLocalPlayerAtPosition(Vector2 mapPoint) {
        SpawnLocalPlayer(GetSpawnPointFromMapPoint(mapPoint));
    }

    Vector3 GetRandomSpawnPoint() {
        Vector3 point = new Vector3(Random.Range(-500, 500), 300f, Random.Range(-500, 500));
        Ray ray = new Ray(point, Vector3.down);
        RaycastHit hit = new RaycastHit();
        if (Physics.Raycast(ray, out hit)) {
            point.y = hit.point.y;
        }
        return point;
    }

    Vector3 GetSpawnPointFromMapPoint(Vector2 mapPoint) {
        return mapPoint;
    }
}
*/
