Beispiel #1
0
    public static bool TrySpawnEnemy(Vector3 position, Quaternion rotation)
    {
        EnemyTypeInfo enemy = Instance.enemyinfos.RandomEntry(Weight);

        if (enemy == default(EnemyTypeInfo))
        {
            return(false);
        }

        EnemyType type = (EnemyType)Instance.enemyinfos.IndexOf(enemy);

        if (Instance.enemyinfos.Count <= (int)type)
        {
            Debug.LogWarning("No Info for EnemyType: " + enemy);
            return(false);
        }

        if (!enemy.AllowMore)
        {
            return(false);
        }

        Instance.SpawnEnemy(type, position, rotation);

        return(true);
    }
Beispiel #2
0
    /// <summary>
    /// Randomly generate a new enemy type with a certain total power
    /// 1: move
    /// 2: hp
    /// 3: power
    /// 4: range
    /// </summary>
    /// <param name="totalPower"></param>
    /// <returns></returns>
    public EnemyTypeInfo CreateNewEnemyType(int totalPower)
    {
        EnemyTypeInfo newTypeInfo = new EnemyTypeInfo();

        int[] abilityStrength    = { maxEnemyMoveRange, maxEnemyMaxHealth, maxEnemyAttackPower, maxEnemyAttackRange };
        int[] minAbilityStrength = { minEnemyMoveRange, minEnemyMaxHealth, minEnemyAttackPower, minEnemyAttackRange };
        int   targetDifference   = maxEnemyMoveRange + maxEnemyMaxHealth + maxEnemyAttackPower + maxEnemyAttackRange - totalPower;

        // Reduce ability strength to match total power
        while (targetDifference > 0)
        {
            int ability = BetterRandom.betterRandom(0, abilityStrength.Length - 1);

            // If strength can be decreased
            if (abilityStrength[ability] > minAbilityStrength[ability])
            {
                abilityStrength[ability]--;
                targetDifference--;
            }
        }

        newTypeInfo.moveRange   = abilityStrength[0];
        newTypeInfo.maxHealth   = abilityStrength[1];
        newTypeInfo.attackPower = abilityStrength[2];
        newTypeInfo.attackRange = abilityStrength[3];

        return(newTypeInfo);
    }
Beispiel #3
0
    /// <summary>
    /// Create a new enemy and place on a postion on the map
    /// Usually happened during map generation
    /// </summary>
    /// <param name="type"></param>
    /// <param name="xCoord"></param>
    /// <param name="zCoord"></param>
    public void CreateEnemy(EnemyTypeInfo typeInfo, int xCoord, int zCoord)
    {
        //// If there is no such enemy type
        //if (!enemyTypes.Exists(t => t.typeName == type))
        //{
        //    return;
        //}

        //// Create an enemy of this type
        //EnemyUnit newEnemy = new EnemyUnit();
        //newEnemy.Initialize(enemyTypes.Find(t => t.typeName == type));

        // Create an enemy with input type info
        GameObject newEnemy = Instantiate(enemyPrefab);

        newEnemy.GetComponent <EnemyUnit>().Initialize(typeInfo);

        // Add new enemy to EnemyManager
        thisLevelEnemies.Add(newEnemy.GetComponent <EnemyUnit>());

        // Place new enemy on target tile
        MapManager.PlaceObject(newEnemy.transform, xCoord, zCoord);
    }
Beispiel #4
0
 public static float Weight(EnemyTypeInfo info)
 {
     return(info.SpawnChance.Evaluate(DifficultyLevel));
 }