Example #1
0
        private bool TryGetRandomEnemy(out EnemyBlueprint enemyBlueprint)
        {
            var mobBlueprints = _context.EnemyBlueprints;

            enemyBlueprint = mobBlueprints.Random();
            return(enemyBlueprint != default);
        }
Example #2
0
        /// <summary>
        /// Load all the Enemy blueprints into the game
        /// </summary>
        private void LoadAllEnemyBlueprints()
        {
            string[] enemyFolders = Directory.GetDirectories("content\\Enemies");
            for (int i = 0; i < enemyFolders.Length; i++)
            {
                // This is a local path from the content directory.
                string path = enemyFolders[i] + "\\Animator\\";
                // This is the entire path from the drive to the directory of enemies.
                string fullpath = Environment.CurrentDirectory + "\\" + path;

                // This is all the text from the 'data.txt' file that an enemy
                // being imported will hold.
                string enemyRawData = File.ReadAllText(fullpath + "data.txt");
                // This is all that data being broke up by there line breaks
                string[] enemyData = enemyRawData.Split('\n');

                // Here we are importing all the data from the 'data.txt'
                EnemyBlueprint enemyBlueprint = new EnemyBlueprint(enemyData[0].Split(':')[1].Trim());
                float.TryParse(enemyData[1].Split(':')[1].Trim(), out enemyBlueprint.Damage);
                float.TryParse(enemyData[2].Split(':')[1].Trim(), out enemyBlueprint.AttackSpeed);
                float.TryParse(enemyData[3].Split(':')[1].Trim(), out enemyBlueprint.MoveSpeed);
                float.TryParse(enemyData[4].Split(':')[1].Trim(), out enemyBlueprint.Health);

                // for loop for every animation folder
                string[] enemyInfoFolders = Directory.GetDirectories(path);
                for (int a = 0; a < enemyInfoFolders.Length; a++)
                {
                    // get all the files in the animation folder
                    string[]  animationPNGFiles = Directory.GetFiles(enemyInfoFolders[a]);
                    Animation animation         = new Animation();
                    // new array (minus 1 to account for the .txt file)
                    animation.Sprites = new Texture2D[animationPNGFiles.Length - 1];
                    for (int z = 0; z < animationPNGFiles.Length; z++)
                    {
                        // make sure that this file is an image
                        if (animationPNGFiles[z].Contains(".xnb"))
                        {
                            // format file path
                            string fileName = animationPNGFiles[z].Remove(0, "Content\\".Length).Replace(".xnb", "");
                            // load and save Texture2D
                            Texture2D sprite = Content.Load <Texture2D>(fileName);
                            animation.Sprites[z] = sprite;
                        }
                    }
                    // read the animation data file
                    string[] animationData = File.ReadAllText(enemyInfoFolders[a] + "\\AnimationData.txt").Split('\n');
                    // parse the animation speed from the file
                    float.TryParse(animationData[0].Split(':')[1].Trim(), out animation.Speed);

                    // add this animation to this enemy blueprint
                    enemyBlueprint.Animations.Add(animation);
                }

                LoadedEnemyBlueprints.Add(enemyBlueprint.Name.ToLower(), enemyBlueprint);
            }
        }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        EnemyBlueprint bp = (EnemyBlueprint)target;

        if (GUILayout.Button("Recalculate Bounds"))
        {
            bp.CalculateBounds();
        }
    }
    void AttackAttempt()
    {
        EnemyBlueprint enemy = spawner.EnemyBlueprints[indexInList];

        Debug.Log(enemy.prefabName + " is attacking the player");

        float randAttack = Random.value * 100;

        if (randAttack < totalAttackChance)
        {
            Attack(randAttack, enemy);
        }
        else
        {
            Debug.Log(enemy.prefabName + " missed the attack");
        }
    }
    void Attack(float randAttack, EnemyBlueprint enemy)
    {
        if (randAttack <= enemy.critiaclChance)
        {
            Debug.Log(enemy.prefabName + " performs a critical attack: " + randAttack);
            characterStats.Health -= enemy.criticalAttack - ((enemy.criticalAttack * characterStats.Protection) / 100);
        }
        else if (randAttack > enemy.critiaclChance && randAttack <= enemy.bigAttackChance)
        {
            Debug.Log(enemy.prefabName + " performs a big attack: " + randAttack);
            characterStats.Health -= enemy.bigAttack - ((enemy.bigAttack * characterStats.Protection) / 100);
        }
        else
        {
            Debug.Log(enemy.prefabName + " performs a small attack: " + randAttack);
            characterStats.Health -= enemy.smallAttack - ((enemy.smallAttack * characterStats.Protection) / 100);
        }

        isAttacking = false;
    }
Example #6
0
    public void SpawnSelectedEnemy(EnemyBlueprint enemy) //used for selecting turrets to build
    {
        enemyToSpawn = enemy;

        if (player.Money < enemy.cost)
        {
            Debug.Log("You don't have enough money friend");
            return;
        }

        player.MoneyGenerationIncrease(enemy.incomeUpgrade); // increases the amount of money per 5 seconds the player gains by the amount the minion is worth
        player.Money -= enemy.cost;                          // deducts money to the price of the enemy


        int i = Random.Range(0, 2); // the second number is exclusive, meaning it wont ever be called so it will call 0 or 1 in this case

        Debug.Log("I have spawned at SpawnPoint: " + i);

        // TODO - Make it so it can differenciate between which players spawned them and send in the right spawners
        // Currently just spawns in both portals of team 1

        GameObject enemySpwaned = (GameObject)Instantiate(enemyToSpawn.prefab, SpawnPoints.spawnLocationsTeamOne[i].position, Quaternion.identity);
    }
    // visualize the npc state
    void OnDrawGizmos()
    {
        if (spawner.characterType == CharacterType.Enemy)
        {
            EnemyBlueprint enemy = spawner.EnemyBlueprints[indexInList];

            switch (enemyState)
            {
            case EnemyState.patrolling:
            {
                Gizmos.color = gizmos.PatrolingEnemyGizmo * 1.0f;
                Gizmos.DrawWireSphere(transform.position, enemy.enemySpotRadius);

                Gizmos.color = gizmos.AttackingEnemyGizmo * 0.5f;
                Gizmos.DrawWireSphere(transform.position, enemy.enemyAttackRadius);

                Gizmos.color = gizmos.EvadingEnemyGizmo * 0.5f;
                Gizmos.DrawWireSphere(transform.position, enemy.enemyForgetRadius);
            }
            break;

            case EnemyState.attacking:
            {
                Gizmos.color = gizmos.PatrolingEnemyGizmo * 0.5f;
                Gizmos.DrawWireSphere(transform.position, enemy.enemySpotRadius);

                Gizmos.color = gizmos.AttackingEnemyGizmo * 1.0f;
                Gizmos.DrawWireSphere(transform.position, enemy.enemyAttackRadius);

                Gizmos.color = gizmos.EvadingEnemyGizmo * 0.5f;
                Gizmos.DrawWireSphere(transform.position, enemy.enemyForgetRadius);
            }
            break;

            case EnemyState.evading:
            {
                Gizmos.color = gizmos.PatrolingEnemyGizmo * 0.5f;
                Gizmos.DrawWireSphere(transform.position, enemy.enemySpotRadius);

                Gizmos.color = gizmos.AttackingEnemyGizmo * 0.5f;
                Gizmos.DrawWireSphere(transform.position, enemy.enemyAttackRadius);

                Gizmos.color = gizmos.EvadingEnemyGizmo * 1.0f;
                Gizmos.DrawWireSphere(transform.position, enemy.enemyForgetRadius);
            }
            break;

            default:
                break;
            }
        }
        else
        {
            switch (spawner.passiveNPCBlueprints[indexInList].npcState)
            {
            case NPCState.idle:
            {
                Gizmos.color = gizmos.IdleNPCGizmo * 1.0f;
                Gizmos.DrawWireSphere(transform.position, spawner.passiveNPCBlueprints[indexInList].npcInteractionRadius);

                Gizmos.color = gizmos.FocusedNPCGizmo * 0.5f;
                Gizmos.DrawWireSphere(transform.position, spawner.passiveNPCBlueprints[indexInList].npcInteractionRadius);
            }
            break;

            case NPCState.focused:
            {
                Gizmos.color = gizmos.IdleNPCGizmo * 0.5f;
                Gizmos.DrawWireSphere(transform.position, spawner.passiveNPCBlueprints[indexInList].npcInteractionRadius);

                Gizmos.color = gizmos.FocusedNPCGizmo * 1.0f;
                Gizmos.DrawWireSphere(transform.position, spawner.passiveNPCBlueprints[indexInList].npcInteractionRadius);
            }
            break;

            default:
                break;
            }
        }
    }
Example #8
0
 void SpawnEnemy(EnemyBlueprint enemyBlueprint)
 {
     Instantiate(enemyBlueprint.enemyPrefab, spawnPoint.position, spawnPoint.rotation);
 }
Example #9
0
 private void CreateEnemy(EnemyBlueprint enemyBlueprint, in Vector2 position)