2018-04-21 12:22:17 +02:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2018-04-21 15:39:48 +02:00
|
|
|
|
public class Room : MonoBehaviour {
|
|
|
|
|
|
2018-04-22 16:05:05 +02:00
|
|
|
|
public enum TileType {
|
|
|
|
|
GROUND, WALL, DOOR, ROCK
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-23 16:59:39 +02:00
|
|
|
|
Vector2Int center;
|
2018-04-24 03:52:38 +02:00
|
|
|
|
Vector2Int position;
|
2018-04-23 16:59:39 +02:00
|
|
|
|
|
2018-04-21 15:39:48 +02:00
|
|
|
|
List<Door> doors;
|
2018-04-21 16:13:59 +02:00
|
|
|
|
List<Transform> spawnpoints;
|
2018-04-21 15:39:48 +02:00
|
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
GameObject doorsRootObject;
|
|
|
|
|
|
2018-04-21 16:13:59 +02:00
|
|
|
|
[SerializeField]
|
|
|
|
|
GameObject spawnpointRootObject;
|
|
|
|
|
|
2018-04-22 15:59:14 +02:00
|
|
|
|
private Objective objective;
|
2018-04-22 11:27:09 +02:00
|
|
|
|
|
2018-04-22 15:59:14 +02:00
|
|
|
|
// Use this for initialization
|
2018-04-23 02:23:06 +02:00
|
|
|
|
void Awake() {
|
2018-04-21 15:39:48 +02:00
|
|
|
|
doors = new List<Door>();
|
2018-04-22 17:52:20 +02:00
|
|
|
|
if ( doorsRootObject != null ) {
|
|
|
|
|
foreach ( Door d in doorsRootObject.GetComponentsInChildren<Door>() ) {
|
|
|
|
|
doors.Add(d);
|
|
|
|
|
}
|
2018-04-22 19:43:29 +02:00
|
|
|
|
//Debug.Log("[ROOMS] Doors: " + doors.Count);
|
2018-04-22 17:52:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spawnpoints = new List<Transform>();
|
|
|
|
|
if ( spawnpointRootObject != null ) {
|
|
|
|
|
foreach ( Transform t in spawnpointRootObject.GetComponentsInChildren<Transform>() ) {
|
|
|
|
|
if ( t.gameObject != spawnpointRootObject ) {
|
|
|
|
|
spawnpoints.Add(t);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-22 19:43:29 +02:00
|
|
|
|
//Debug.Log("[ROOMS] Spawnpoints: " + spawnpoints.Count);
|
2018-04-22 17:52:20 +02:00
|
|
|
|
}
|
2018-04-23 02:23:06 +02:00
|
|
|
|
Unlock();
|
2018-04-22 17:52:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-23 16:59:39 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Center point in Generation phase.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="v"></param>
|
|
|
|
|
public void SetCenter(Vector2Int v) {
|
|
|
|
|
center = v;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-24 03:52:38 +02:00
|
|
|
|
public void SetPosition(Vector2Int v) {
|
|
|
|
|
position = v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Vector2Int GetPosition() {
|
|
|
|
|
return position;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-23 16:59:39 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the Center as global from the generation. TODO change this
|
|
|
|
|
/// Is available after Generation and after Start Phase.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Vector2Int GetCenter() {
|
|
|
|
|
return center;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-22 17:52:20 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reloads the spawnpoints and doors.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Reload() {
|
|
|
|
|
doors = new List<Door>();
|
|
|
|
|
if ( doorsRootObject != null ) {
|
|
|
|
|
foreach ( Door d in doorsRootObject.GetComponentsInChildren<Door>() ) {
|
|
|
|
|
doors.Add(d);
|
|
|
|
|
}
|
2018-04-22 19:43:29 +02:00
|
|
|
|
//Debug.Log("[ROOMS] Doors: " + doors.Count);
|
2018-04-21 15:39:48 +02:00
|
|
|
|
}
|
2018-04-22 17:52:20 +02:00
|
|
|
|
|
2018-04-21 16:13:59 +02:00
|
|
|
|
spawnpoints = new List<Transform>();
|
2018-04-22 17:52:20 +02:00
|
|
|
|
if ( spawnpointRootObject != null ) {
|
|
|
|
|
foreach ( Transform t in spawnpointRootObject.GetComponentsInChildren<Transform>() ) {
|
|
|
|
|
if ( t.gameObject != spawnpointRootObject ) {
|
|
|
|
|
spawnpoints.Add(t);
|
|
|
|
|
}
|
2018-04-21 18:45:26 +02:00
|
|
|
|
}
|
2018-04-22 19:43:29 +02:00
|
|
|
|
//Debug.Log("[ROOMS] Spawnpoints: " + spawnpoints.Count);
|
2018-04-21 16:13:59 +02:00
|
|
|
|
}
|
2018-04-23 02:23:06 +02:00
|
|
|
|
Unlock(); // Ok to do so?
|
2018-04-22 17:52:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the doors root object.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="go"></param>
|
|
|
|
|
public void SetDoorsRootObject(GameObject go) {
|
|
|
|
|
doorsRootObject = go;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the spawnpoints root object.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="go"></param>
|
|
|
|
|
public void SetSpawnPointsRootObject(GameObject go) {
|
|
|
|
|
spawnpointRootObject = go;
|
2018-04-21 18:45:26 +02:00
|
|
|
|
}
|
2018-04-21 15:39:48 +02:00
|
|
|
|
|
2018-04-22 15:59:14 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Locks all doors associated with this room.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Lock() {
|
|
|
|
|
foreach ( Door d in doors ) {
|
2018-04-21 15:39:48 +02:00
|
|
|
|
d.Lock();
|
2018-04-23 18:52:21 +02:00
|
|
|
|
}
|
|
|
|
|
GameController.instance.GetAudioControl().SfxPlay(AudioControl.Sfx.door);
|
2018-04-22 15:59:14 +02:00
|
|
|
|
Debug.Log("[ROOMS] Locked all doors...");
|
2018-04-21 15:39:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-22 15:59:14 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Unlocks all doors associated with this room.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Unlock() {
|
|
|
|
|
foreach ( Door d in doors ) {
|
2018-04-21 15:39:48 +02:00
|
|
|
|
d.Unlock();
|
2018-04-23 18:52:21 +02:00
|
|
|
|
}
|
|
|
|
|
GameController.instance.GetAudioControl().SfxPlay(AudioControl.Sfx.door);
|
2018-04-22 15:59:14 +02:00
|
|
|
|
Debug.Log("[ROOMS] Unlocked all doors...");
|
2018-04-21 15:39:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-22 15:59:14 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the rooms Objective.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="obj">Objective</param>
|
|
|
|
|
public void SetObjective(Objective obj) {
|
|
|
|
|
objective = obj;
|
2018-04-22 05:57:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-22 15:59:14 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Informs the objective / activates it and ensures that a cleared room is not going to be activated again.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="player"></param>
|
|
|
|
|
public void OnPlayerEnter(Player player) {
|
2018-04-23 14:59:34 +02:00
|
|
|
|
if(objective == null) {
|
|
|
|
|
Debug.Log("[ROOMS] This Room has no objective!");
|
2018-04-22 11:27:09 +02:00
|
|
|
|
return;
|
2018-04-22 15:59:14 +02:00
|
|
|
|
}
|
2018-04-23 14:59:34 +02:00
|
|
|
|
if ( objective.GetFinished() ) {
|
|
|
|
|
Debug.Log("[ROOMS] This room has been cleared already.");
|
|
|
|
|
return;
|
2018-04-22 15:59:14 +02:00
|
|
|
|
}
|
2018-04-23 14:59:34 +02:00
|
|
|
|
Debug.Log("[ROOMS] Player activated Objective");
|
|
|
|
|
objective.ActivateGoal(player);
|
2018-04-21 18:45:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-22 15:59:14 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the Spawnpoints a room has.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<Transform> GetSpawnpoints() {
|
2018-04-21 16:13:59 +02:00
|
|
|
|
return spawnpoints;
|
|
|
|
|
}
|
2018-04-22 05:57:26 +02:00
|
|
|
|
|
2018-04-21 12:22:17 +02:00
|
|
|
|
}
|