Пример #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)]);
        }
    }
Пример #2
0
 public void AddAccessPoint(NpcAccessPoint accessPoint)
 {
     accessPoint.AccessPointAvailable += AccessPoint_AccessPointAvailable;
     _accessPoints.Add(accessPoint);
     _availableAccessPoints.Add(accessPoint);
     AccessPoint_AccessPointAvailable(accessPoint, null);
 }
Пример #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);
    }
Пример #4
0
 public void AddAccessPoint(NpcAccessPoint accessPoint)
 {
     accessPoint.AccessPointAvailable += AccessPoint_AccessPointAvailable;
     _accessPoints.Add(accessPoint);
     _availableAccessPoints.Add(accessPoint);
     AccessPoint_AccessPointAvailable(accessPoint, null);
 }
Пример #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");
        }
    }
Пример #6
0
 public bool IsAccessPointCompatible(NpcAccessPoint.AccessPointType apType)
 {
     foreach(var compatibleAP in compatibleAccessPoints)
     {
         if (apType.Equals(compatibleAP))
         {
             return true;
         }
     }
     return false;
 }
Пример #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;
     }
 }
Пример #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;
        }
    }
Пример #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;
     }
 }
Пример #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;
    }
Пример #11
0
 public void RemoveAccessPoint(NpcAccessPoint accessPoint)
 {
     _accessPoints.Remove(accessPoint);
     _availableAccessPoints.Remove(accessPoint);
 }
Пример #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");
        }
    }
Пример #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;
    }
Пример #14
0
 public void RemoveAccessPoint(NpcAccessPoint accessPoint)
 {
     _accessPoints.Remove(accessPoint);
     _availableAccessPoints.Remove(accessPoint);
 }
Пример #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);
        }
    }
Пример #16
0
 public void Dock(NpcAccessPoint.AccessPointType type)
 {
     _isActive = false;
     StartCoroutine(PerformDock(1f / rotateSpeed, type));
 }