Ejemplo n.º 1
0
    private void GenerateEncounter(EncounterTemplate template)
    {
        //spawn terrain
        foreach (Hex rockpos in template.terrainPieces)
        {
            Entity rock = entFactory.CreateTerrain(rockTerrain);
            rock.AddToGrid(worldGrid, rockpos);
            allEntities.Add(rock);
        }

        //spawn player
        Hex playerspawn = template.playerSpawnPoints.GetRandom();

        player = entFactory.CreateEntity(40);
        player.AddToGrid(worldGrid, playerspawn);
        player.EnableStatusEffects(true);
        player.entityName = "Player";
        if (GameplayContext.LastPlayerHealth > -1)
        {
            player.Health.SetHealth(GameplayContext.LastPlayerHealth);
        }
        player.appearance.sprite       = Resources.Load <Sprite>("Sprites/PlayerArt");
        player.OnStatusEffectsChanged += UpdatePlayerStatusEffectPanel;
        ColorUtility.TryParseHtmlString("#46537d", out Color col);
        playerHealthBar.Colour   = col;
        playerHealthBar.MaxValue = player.Health.MaxHealth;


        //select enemygroup, ignoring difficulty when in debug mode
        EnemyGroup enemyGroup;

        if (GameplayContext.InDebugMode)
        {
            enemyGroup = entFactory.GetEnemyGroup(template.minEnemies, template.maxEnemies);
        }
        else
        {
            int maxDif = GameplayContext.CurrentDifficulty;
            int minDif = Math.Max(1, maxDif - difficultyThreshold);
            enemyGroup = entFactory.GetEnemyGroup(template.minEnemies, template.maxEnemies, minDif, maxDif);
            Debug.Log("making encounter using " + GameplayContext.CurrentDifficulty);
        }

        List <PODHex> enemySpots = new List <PODHex>(template.enemySpawnPoints);

        //spawn enemies
        foreach (string enemyType in enemyGroup.enemies)
        {
            if (enemySpots.Count == 0)
            {
                break;
            }

            Hex    spawnpoint = enemySpots.PopRandom();
            Entity e          = entFactory.CreateEntity(10);

            e.AddToGrid(worldGrid, spawnpoint);
            e.EnableStatusEffects(true);
            entFactory.AddAIController(e, enemyType);
            e.Health.OnDeath += () => { CleanupEntity(e); };
            Debug.Log("spawned: " + e.entityName);
            allEntities.Add(e);
            allEnemies.Add(e);
        }
        //
    }