private void AccessPoint_AccessPointAvailable(object sender, AccessPointAvailableEventArgs e) { if (e != null && e.removedNpc != null) { foreach (var npc in npcs) { if (npc.Type == e.removedNpc) { npc.Count--; break; } } } NpcAccessPoint accessPoint = sender as NpcAccessPoint; if (accessPoint != null) { if (!_availableAccessPoints.Contains(accessPoint)) { _availableAccessPoints.Add(accessPoint); } SpawnNpc(_availableAccessPoints[Random.Range(0, _availableAccessPoints.Count - 1)]); } }
public void AddAccessPoint(NpcAccessPoint accessPoint) { accessPoint.AccessPointAvailable += AccessPoint_AccessPointAvailable; _accessPoints.Add(accessPoint); _availableAccessPoints.Add(accessPoint); AccessPoint_AccessPointAvailable(accessPoint, null); }
public List <NpcAccessPoint> GetDestinationsForNpcType(NpcType type, NpcAccessPoint excluded) { List <NpcAccessPoint> compatibleAPs = new List <NpcAccessPoint>(); foreach (var ap in _accessPoints) { if (ap != null) { // Make sure we are not using destinations from the same ship/planet that the NPC was spawned if (ap.transform.parent != null && excluded != null && excluded.transform.parent != null) { if (ap.transform.parent == excluded.transform.parent) { continue; } } if (ap != excluded && type.IsAccessPointCompatible(ap.type)) { compatibleAPs.Add(ap); } } } return(compatibleAPs); }
private void SpawnNpc(NpcAccessPoint accessPoint) { List <CompleteNpc> compatiblePrefabs = GetPrefabsForAccessPointType(accessPoint.type); if (compatiblePrefabs != null && compatiblePrefabs.Count > 0) { CompleteNpc randomNpc = compatiblePrefabs[Random.Range(0, compatiblePrefabs.Count - 1)]; if (randomNpc != null) { List <NpcAccessPoint> compatibleDestinations = GetDestinationsForNpcType(randomNpc.Type, accessPoint); if (randomNpc != null && compatibleDestinations != null && compatibleDestinations.Count > 0) { accessPoint.SpawnNpc(randomNpc.prefab, compatibleDestinations); _availableAccessPoints.Remove(accessPoint); randomNpc.Count++; } else { Debug.LogWarning("Failed to spawn an NPC"); } } else { Debug.LogError("An NPC is missing its NpcType component"); } } else { Debug.Log("All NPCs types have been maxed out"); } }
public bool IsAccessPointCompatible(NpcAccessPoint.AccessPointType apType) { foreach(var compatibleAP in compatibleAccessPoints) { if (apType.Equals(compatibleAP)) { return true; } } return false; }
public void Spawn(NpcAccessPoint spawnPoint) { switch (spawnPoint.type) { case NpcAccessPoint.AccessPointType.Warp: if (_warpDrive == null) { _warpDrive = GetComponent<AIWarpDrive>(); } _warpDrive.EnterFromWarp(transform.position, transform.rotation); break; default: break; } }
public void Spawn(NpcAccessPoint spawnPoint) { switch (spawnPoint.type) { case NpcAccessPoint.AccessPointType.Warp: if (_warpDrive == null) { _warpDrive = GetComponent <AIWarpDrive>(); } _warpDrive.EnterFromWarp(transform.position, transform.rotation); break; default: break; } }
public void Dock(NpcAccessPoint.AccessPointType dockingType) { Debug.Log("Ship is ready to dock"); switch (dockingType) { case NpcAccessPoint.AccessPointType.Planet: Destroy(gameObject); break; case NpcAccessPoint.AccessPointType.SpaceStation: Destroy(gameObject); break; case NpcAccessPoint.AccessPointType.Warp: _warpDrive.ExitToWarp(); break; } }
public List<NpcAccessPoint> GetDestinationsForNpcType(NpcType type, NpcAccessPoint excluded) { List<NpcAccessPoint> compatibleAPs = new List<NpcAccessPoint>(); foreach(var ap in _accessPoints) { if (ap != null) { // Make sure we are not using destinations from the same ship/planet that the NPC was spawned if (ap.transform.parent != null && excluded != null && excluded.transform.parent != null) { if (ap.transform.parent == excluded.transform.parent) { continue; } } if (ap != excluded && type.IsAccessPointCompatible(ap.type)) { compatibleAPs.Add(ap); } } } return compatibleAPs; }
public void RemoveAccessPoint(NpcAccessPoint accessPoint) { _accessPoints.Remove(accessPoint); _availableAccessPoints.Remove(accessPoint); }
private void SpawnNpc(NpcAccessPoint accessPoint) { List<CompleteNpc> compatiblePrefabs = GetPrefabsForAccessPointType(accessPoint.type); if (compatiblePrefabs != null && compatiblePrefabs.Count > 0) { CompleteNpc randomNpc = compatiblePrefabs[Random.Range(0, compatiblePrefabs.Count - 1)]; if (randomNpc != null) { List<NpcAccessPoint> compatibleDestinations = GetDestinationsForNpcType(randomNpc.Type, accessPoint); if (randomNpc != null && compatibleDestinations != null && compatibleDestinations.Count > 0) { accessPoint.SpawnNpc(randomNpc.prefab, compatibleDestinations); _availableAccessPoints.Remove(accessPoint); randomNpc.Count++; } else { Debug.LogError("Failed to spawn an NPC"); } } else { Debug.LogError("An NPC is missing its NpcType component"); } } else { Debug.Log("All NPCs types have been maxed out"); } }
private List<CompleteNpc> GetPrefabsForAccessPointType(NpcAccessPoint.AccessPointType type) { List<CompleteNpc> compatibleNPCs = new List<CompleteNpc>(); foreach(var npc in npcs) { if (npc.Type.IsAccessPointCompatible(type)) { if (npc.Count < npc.maxCount) { compatibleNPCs.Add(npc); } } } return compatibleNPCs; }
IEnumerator PerformDock(float time, NpcAccessPoint.AccessPointType type) { Vector3 startPosition = _destination.position; Vector3 endPosition = transform.position; Quaternion startRotation = transform.rotation; Quaternion endRotation = Quaternion.LookRotation(-_destination.forward); float timeSinceStarted = 0f; float percentageComplete = 0f; float startTime = Time.time; while (percentageComplete < 1f) { timeSinceStarted = Time.time - startTime; percentageComplete = timeSinceStarted / time; transform.position = Vector3.Lerp(startPosition, endPosition, percentageComplete); transform.rotation = Quaternion.Slerp(startRotation, endRotation, percentageComplete); yield return null; } OnDestinationReached(); NpcType npcType = GetComponent<NpcType>(); if (npcType != null) { npcType.Dock(type); } }
public void Dock(NpcAccessPoint.AccessPointType type) { _isActive = false; StartCoroutine(PerformDock(1f / rotateSpeed, type)); }