using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class Mission : MonoBehaviour {

	public enum MissionType {
		Build
	};

	private bool set = false;

	public AudioSource complete;

	MissionType mType;

	// build mission rewards
	private int quantity;
	private int buildingID;
	private int reward;

	private GameMenu gm;

	public void BeBuildMission(int buildID, int quant, int rwrd)
	{
		gm = GameObject.Find("ViewController").GetComponent<GameMenu>();
		mType = MissionType.Build;
		buildingID = buildID;
		quantity = quant;
		reward = rwrd;
		gm.buildEvent.AddListener(BuildAdjust);
		set = true;
	}

	void BuildAdjust(int bType)
	{
		if (bType == buildingID)
			quantity--;
	}

	void Update()
	{
		if (set)
		{
			switch(mType)
			{
				case MissionType.Build:
				{
					if (quantity == 0)
					{
						gm.money += reward;
						complete.Play();
						Destroy(gameObject);
					}

					break;
				}
			}
		}
	}
}
