using Assets.Scripts.Entities; using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// Objective, where the goal is to "remove" all Entitys, how is defined by the Entity itself. /// public class EntityObjective : Objective { List prefabList; List entityList; /// /// Creates a new instance of an EntityObjective. /// /// /// public EntityObjective(Room caller, List prefabList) : base(caller) { this.entityList = new List(); this.prefabList = prefabList; } /// /// Handle activation code for a goal. /// /// Player public override void ActivateGoal(Player ply) { if ( activated ) return; base.ActivateGoal(ply); List spawnPointList = room.GetSpawnpoints(); if (spawnPointList.Count == 0) { finished = true; return; } foreach ( GameObject i in prefabList ) { Debug.Log("[ROOMS] Spawning Entity..."); if(i == null || player == null) { Debug.Log("[ROOMS] Failed.. Entity not set in GameController!"); return; } GameObject tempObject = UnityEngine.Object.Instantiate(i); tempObject.transform.position = spawnPointList[Random.Range(0, spawnPointList.Count)].position; tempObject.GetComponent().SetObjective(this); entityList.Add(tempObject); } room.Lock(); } /// /// Removes an Entity from the list. And checks if the goal was reached. /// /// Entity public void RemoveEntity(Entity e) { if ( e == null ) return; entityList.Remove(e.gameObject); UpdateGoal(); } /// /// Tracks / Updates the progess of a goal. /// public override void UpdateGoal() { // Goal: if ( entityList.Count == 0 ) ReachedGoal(); } }