Exemplo n.º 1
0
    public static void SpawnOneEntityInChunkNonAlloc(SpawnableEntity se, EntityData?data, ChunkCoords cc)
    {
        //pick a position within the chunk coordinates
        Vector2     spawnPos = Vector2.zero;
        Vector2Pair range    = ChunkCoords.GetCellArea(cc, EntityNetwork.CHUNK_SIZE);

        switch (se.posType)
        {
        case SpawnableEntity.SpawnPosition.Random:
            spawnPos.x = Random.Range(range.a.x, range.b.x);
            spawnPos.y = Random.Range(range.a.y, range.b.y);
            break;

        case SpawnableEntity.SpawnPosition.Center:
            spawnPos = ChunkCoords.GetCenterCell(cc, EntityNetwork.CHUNK_SIZE);
            break;
        }
        //spawn it
        Entity newEntity = Instantiate(
            se.prefab,
            spawnPos,
            Quaternion.identity,
            instance.holders[se.entityName].transform);

        newEntity.ApplyData(data);
    }
Exemplo n.º 2
0
    public static List <Entity> SpawnEntityInChunkNorthOfCamera(SpawnableEntity se, EntityData?data = null)
    {
        Vector3     cameraPos = Camera.main.transform.position;
        ChunkCoords cc        = new ChunkCoords(cameraPos, EntityNetwork.CHUNK_SIZE);

        cc.y++;
        cc = cc.Validate();
        return(SpawnEntityInChunk(se, data, cc));
    }
Exemplo n.º 3
0
 private void UpdateMenuType(SpawnableEntity entity)
 {
     switch (entity.EntityType)
     {
     case EntityType.Resource:
         ChangeMenu(PlayerMenuType.Use);
         break;
     }
 }
Exemplo n.º 4
0
    public static List <Entity> SpawnEntityInChunkNorthOfCamera(string entityName)
    {
        Vector3     cameraPos = Camera.main.transform.position;
        ChunkCoords cc        = new ChunkCoords(cameraPos, EntityNetwork.CHUNK_SIZE);

        cc.y++;
        cc = cc.Validate();
        SpawnableEntity se = GetSpawnableEntity(entityName);

        return(SpawnEntityInChunk(se, null, cc));
    }
Exemplo n.º 5
0
    public static List <Entity> SpawnEntity(EntityData data)
    {
        if (data.type == null)
        {
            return(null);
        }

        SpawnableEntity se = GetSpawnableEntity(data.type);

        return(SpawnEntity(se, data));
    }
Exemplo n.º 6
0
    public static List <Entity> SpawnEntity(Entity e)
    {
        if (e == null)
        {
            return(null);
        }

        SpawnableEntity se = GetSpawnableEntity(e);

        return(SpawnEntity(se));
    }
Exemplo n.º 7
0
 void SpawnEntity()
 {
     if (spawnQueue.Count > 0)
     {
         SpawnableEntity next = SpawnManager.instance.Search(spawnQueue.Dequeue());
         next.Create(transform.position, Quaternion.identity);
     }
     else
     {
         Debug.LogWarning("Empty Queue");
     }
 }
Exemplo n.º 8
0
    public static void SpawnEntityInChunkNonAlloc(SpawnableEntity se, EntityData?data, ChunkCoords cc)
    {
        if (se == null)
        {
            return;
        }
        //determine how many to spawn
        int numToSpawn = Random.Range(se.minSpawnCountInChunk, se.maxSpawnCountInChunk + 1);

        for (int j = 0; j < numToSpawn; j++)
        {
            SpawnOneEntityInChunkNonAlloc(se, data, cc);
        }
    }
Exemplo n.º 9
0
    private void CreateHolders()
    {
        for (int i = 0; i < Prefabs.Count; i++)
        {
            SpawnableEntity e = Prefabs[i];
            if (holders.ContainsKey(e.entityName))
            {
                continue;
            }
            holders.Add(e.entityName, new GameObject(e.entityName));
        }

        Debug.Log("Entity Generator Loaded");
        OnPrefabsLoaded?.Invoke();
        OnPrefabsLoaded = null;
    }
Exemplo n.º 10
0
    public static List <Entity> SpawnEntityInChunk(SpawnableEntity se, EntityData?data, ChunkCoords cc)
    {
        if (se == null)
        {
            return(null);
        }
        //determine how many to spawn
        int           numToSpawn      = Random.Range(se.minSpawnCountInChunk, se.maxSpawnCountInChunk + 1);
        List <Entity> spawnedEntities = new List <Entity>(numToSpawn);

        for (int j = 0; j < numToSpawn; j++)
        {
            spawnedEntities.Add(SpawnOneEntityInChunk(se, data, cc));
        }
        return(spawnedEntities);
    }
Exemplo n.º 11
0
    public void StartFindEnergySourceQuest()
    {
        if (MainChar == null)
        {
            return;
        }

        //create a deranged bot
        ChunkCoords     emptyChunk = EntityGenerator.GetNearbyEmptyChunk();
        SpawnableEntity se         = EntityGenerator.GetSpawnableEntity("deranged bot");
        Entity          newEntity  = EntityGenerator.SpawnOneEntityInChunk(se, null, emptyChunk);
        //set waypoint to new bot
        //attach dialogue prompt when player approaches bot
        VicinityTrigger entityPrompt = newEntity.GetComponentsInChildren <VicinityTrigger>()
                                       .Where(t => t.gameObject.layer == LayerMask.NameToLayer("VicinityTrigger")).FirstOrDefault();
        Action <IActor> triggerEnterAction = null;

        triggerEnterAction = (IActor actor) =>
        {
            if (!(actor is Shuttle))
            {
                return;
            }
            StartDialogue(foundDerangedBotConversation, false);
            entityPrompt.OnEnteredTrigger -= triggerEnterAction;
        };
        entityPrompt.OnEnteredTrigger += triggerEnterAction;

        List <QuestReward> qRewards = new List <QuestReward>();

        List <QuestRequirement> qReqs = new List <QuestRequirement>();
        Waypoint wp = Waypoint.CreateWaypoint(MainChar, entityPrompt,
                                              entityPrompt.PivotPosition);

        qReqs.Add(new GatheringQReq(Item.Type.CorruptedCorvorite,
                                    MainChar, "Find the nearby energy source.", wp));

        Quest q = new Quest(
            "Acquire an Energy Source",
            "The ship appears intact, however it is in a powered-down state. We need to find an energy source.",
            MainQuester, qRewards, qReqs);

        q.OnQuestComplete += CompletedFindEnergySourceQuest;

        GiveQuest(MainQuester, q);
    }
Exemplo n.º 12
0
    public static List <Entity> SpawnEntity(SpawnableEntity se, EntityData?data = null)
    {
        if (se == null)
        {
            return(null);
        }

        ChunkCoords cc = instance.ClosestValidNonFilledChunk(se);

        if (cc == ChunkCoords.Invalid)
        {
            return(null);
        }

        ChunkCoords emptyChunk = GetNearbyEmptyChunk();

        return(SpawnEntityInChunk(se, data, emptyChunk));
    }
Exemplo n.º 13
0
 private List <SpawnableEntityChance> GetPrefabs(float distance)
 {
     cachedChances.Clear();
     for (int i = 0; i < Prefabs.Count; i++)
     {
         SpawnableEntity se = Prefabs[i];
         if (se.ignore)
         {
             continue;
         }
         float chance = se.GetChance(distance);
         if (chance == 0f)
         {
             continue;
         }
         cachedChances.Add(new SpawnableEntityChance(se, chance));
     }
     return(cachedChances);
 }
Exemplo n.º 14
0
    void SpawnEntity()
    {
        if (spawnQueue.Count > 0)
        {
            SpawnableEntity next = SpawnManager.instance.Search(spawnQueue.Dequeue());
            next.Create(transform.position, Quaternion.identity);
            variantTimer += currentDelta;
            spawnDelay    = variantTimer;

            if (spawnQueue.Count <= 0 && spawnWaves.Count > 0)
            {
                FillQueue();
            }
        }
        else
        {
            Debug.LogWarning("No more waves");
        }
    }
Exemplo n.º 15
0
    private SpawnableEntity ChooseEntityToSpawn(float distance)
    {
        List <SpawnableEntityChance> validPrefabs = GetPrefabs(distance);
        float totalRarity  = SpawnableEntityChance.GetTotalChance(validPrefabs);
        float randomChoose = Random.Range(0f, totalRarity);

        //choose which non priority entities to spawn
        for (int i = 0; i < validPrefabs.Count; i++)
        {
            SpawnableEntityChance sec = validPrefabs[i];
            SpawnableEntity       se  = sec.entity;
            float chance = sec.chance;
            randomChoose -= chance;
            if (randomChoose <= 0f)
            {
                return(se);
            }
        }
        Debug.Log("No Spawnable Entity Chosen");
        return(null);
    }
Exemplo n.º 16
0
    private void SpawnHelper(bool respawn)
    {
        if (!_shouldSpawn)
        {
            return;
        }

        SpawnableEntity entity = Spawn(_spawnLocation);

        if (RespawnOnEntityDestroy)
        {
            if (entity != null)
            {
                entity.transform.SetParent(transform);
                entity.OnDestroyed += () => { SpawnAfterTimeout(RespawnTimeoutSeconds, false); };
            }
        }

        if (respawn)
        {
            SpawnAfterTimeout(RespawnTimeoutSeconds, respawn);
        }
    }
Exemplo n.º 17
0
    public static void FillChunk(ChunkCoords cc, bool excludePriority = false)
    {
        //don't bother if the given coordinates are not valid
        if (!cc.IsValid())
        {
            return;
        }
        //if these coordinates have no been generated yet then reserve some space for the new coordinates
        instance.GenerateVoid(cc);
        //don't bother if the coordinates have already been filled
        if (instance.Chunk(cc))
        {
            return;
        }
        //flag that this chunk coordinates was filled
        instance.Column(cc)[cc.y] = true;

        //look through the space priority entities and check if one may spawn
        SpawnableEntity se = instance.ChooseEntityToSpawn(
            ChunkCoords.GetCenterCell(cc, EntityNetwork.CHUNK_SIZE).magnitude);

        SpawnEntityInChunkNonAlloc(se, null, cc);
    }
Exemplo n.º 18
0
    private ChunkCoords ClosestValidNonFilledChunk(SpawnableEntity se)
    {
        int         minRange = Mathf.Max(0, se.rarityZoneOffset);
        ChunkCoords coords   = ChunkCoords.Invalid;

        while (coords == ChunkCoords.Invalid)
        {
            EntityNetwork.IterateCoordsOnRangeBorder(ChunkCoords.Zero, minRange,
                                                     cc =>
            {
                if (!Chunk(cc))
                {
                    coords = cc;
                    return(true);
                }

                return(false);
            },
                                                     true);
            minRange++;
        }
        return(ChunkCoords.Invalid);
    }
Exemplo n.º 19
0
    public static List <Entity> SpawnEntity(string entityName)
    {
        SpawnableEntity se = GetSpawnableEntity(entityName);

        return(SpawnEntity(se));
    }
Exemplo n.º 20
0
 public SpawnableEntityChance(SpawnableEntity se, float chance)
 {
     this.entity = se;
     this.chance = chance;
 }