2018-04-23 16:44:02 +02:00
|
|
|
|
using Assets.Scripts.Entities;
|
|
|
|
|
using System.Collections;
|
2018-04-21 15:18:53 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2018-04-22 15:59:14 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Objective, where the goal is to "remove" all Entitys, how is defined by the Entity itself.
|
|
|
|
|
/// </summary>
|
2018-04-22 05:57:26 +02:00
|
|
|
|
public class EntityObjective : Objective {
|
2018-04-22 15:59:14 +02:00
|
|
|
|
List<GameObject> prefabList;
|
|
|
|
|
List<GameObject> entityList;
|
2018-04-21 15:18:53 +02:00
|
|
|
|
|
2018-04-22 15:59:14 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a new instance of an EntityObjective.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="caller"></param>
|
|
|
|
|
/// <param name="prefabList"></param>
|
|
|
|
|
public EntityObjective(Room caller, List<GameObject> prefabList) : base(caller) {
|
2018-04-22 05:57:26 +02:00
|
|
|
|
this.entityList = new List<GameObject>();
|
2018-04-22 15:59:14 +02:00
|
|
|
|
this.prefabList = prefabList;
|
|
|
|
|
}
|
2018-04-21 15:18:53 +02:00
|
|
|
|
|
2018-04-22 15:59:14 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handle activation code for a goal.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ply">Player</param>
|
|
|
|
|
public override void ActivateGoal(Player ply) {
|
2018-04-23 02:23:06 +02:00
|
|
|
|
if ( activated )
|
|
|
|
|
return;
|
2018-04-22 15:59:14 +02:00
|
|
|
|
base.ActivateGoal(ply);
|
2018-04-24 00:38:31 +02:00
|
|
|
|
|
|
|
|
|
List<Transform> spawnPointList = room.GetSpawnpoints();
|
2018-04-24 01:53:28 +02:00
|
|
|
|
if (spawnPointList.Count == 0) {
|
|
|
|
|
finished = true;
|
2018-04-24 00:38:31 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-22 15:59:14 +02:00
|
|
|
|
foreach ( GameObject i in prefabList ) {
|
|
|
|
|
Debug.Log("[ROOMS] Spawning Entity...");
|
2018-04-23 16:44:02 +02:00
|
|
|
|
if(i == null || player == null) {
|
|
|
|
|
Debug.Log("[ROOMS] Failed.. Entity not set in GameController!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-24 00:38:31 +02:00
|
|
|
|
GameObject tempObject = UnityEngine.Object.Instantiate(i);
|
2018-04-24 01:53:28 +02:00
|
|
|
|
tempObject.transform.position = spawnPointList[Random.Range(0, spawnPointList.Count)].position;
|
2018-04-23 23:14:55 +02:00
|
|
|
|
tempObject.GetComponent<Entity>().SetObjective(this);
|
2018-04-22 05:57:26 +02:00
|
|
|
|
entityList.Add(tempObject);
|
2018-04-22 15:59:14 +02:00
|
|
|
|
}
|
2018-04-21 15:18:53 +02:00
|
|
|
|
|
2018-04-22 15:59:14 +02:00
|
|
|
|
room.Lock();
|
|
|
|
|
}
|
2018-04-21 15:18:53 +02:00
|
|
|
|
|
2018-04-22 15:59:14 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes an Entity from the list. And checks if the goal was reached.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="e">Entity</param>
|
|
|
|
|
public void RemoveEntity(Entity e) {
|
|
|
|
|
if ( e == null )
|
|
|
|
|
return;
|
|
|
|
|
entityList.Remove(e.gameObject);
|
|
|
|
|
UpdateGoal();
|
|
|
|
|
}
|
2018-04-22 05:57:26 +02:00
|
|
|
|
|
2018-04-22 15:59:14 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tracks / Updates the progess of a goal.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public override void UpdateGoal() {
|
|
|
|
|
// Goal:
|
|
|
|
|
if ( entityList.Count == 0 )
|
|
|
|
|
ReachedGoal();
|
2018-04-22 05:57:26 +02:00
|
|
|
|
}
|
2018-04-21 15:18:53 +02:00
|
|
|
|
}
|