Esempio n. 1
0
    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)]);
        }
    }
Esempio n. 2
0
 public void AddAccessPoint(NpcAccessPoint accessPoint)
 {
     accessPoint.AccessPointAvailable += AccessPoint_AccessPointAvailable;
     _accessPoints.Add(accessPoint);
     _availableAccessPoints.Add(accessPoint);
     AccessPoint_AccessPointAvailable(accessPoint, null);
 }
Esempio n. 3
0
    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);
    }
Esempio n. 4
0
 public void AddAccessPoint(NpcAccessPoint accessPoint)
 {
     accessPoint.AccessPointAvailable += AccessPoint_AccessPointAvailable;
     _accessPoints.Add(accessPoint);
     _availableAccessPoints.Add(accessPoint);
     AccessPoint_AccessPointAvailable(accessPoint, null);
 }
Esempio n. 5
0
    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");
        }
    }
Esempio n. 6
0
 public bool IsAccessPointCompatible(NpcAccessPoint.AccessPointType apType)
 {
     foreach(var compatibleAP in compatibleAccessPoints)
     {
         if (apType.Equals(compatibleAP))
         {
             return true;
         }
     }
     return false;
 }
Esempio n. 7
0
 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;
     }
 }
Esempio n. 8
0
    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;
        }
    }
Esempio n. 9
0
 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;
     }
 }
Esempio n. 10
0
    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;
    }
Esempio n. 11
0
 public void RemoveAccessPoint(NpcAccessPoint accessPoint)
 {
     _accessPoints.Remove(accessPoint);
     _availableAccessPoints.Remove(accessPoint);
 }
Esempio n. 12
0
    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");
        }
    }
Esempio n. 13
0
    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;
    }
Esempio n. 14
0
 public void RemoveAccessPoint(NpcAccessPoint accessPoint)
 {
     _accessPoints.Remove(accessPoint);
     _availableAccessPoints.Remove(accessPoint);
 }
Esempio n. 15
0
    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);
        }
    }
Esempio n. 16
0
 public void Dock(NpcAccessPoint.AccessPointType type)
 {
     _isActive = false;
     StartCoroutine(PerformDock(1f / rotateSpeed, type));
 }