using System;
using UnityEngine;

public class Arena : MonoBehaviour {
	public MapData data;
	public GameObject explosionPrefab;
	
	public void Explode(Vector3 position, int strength) {
		if (strength <= 0)
			throw new ArgumentException("Explosion strength must be positive.");

		Vector3 explosionPos = data.GetClosestTilePos(position);

		for (int i = 0; i < 3; i++) {
			var rotation = explosionPrefab.transform.rotation;
			var newRotation = Quaternion.Euler(rotation.eulerAngles + Vector3.up * i * 60f);
			
			var explosion = Instantiate(explosionPrefab, explosionPos, newRotation);

			explosion.GetComponent<CapsuleCollider>().height = 2f * strength * data.hexHeight;
			explosion.transform.GetChild(0).localScale = new Vector3(1f, strength * data.hexHeight, 1f);
		
			Destroy(explosion, 1f);
		}
	}

	public Vector3 GetClosestTilePos(Vector3 pos) => data.GetClosestTilePos(pos);
}