Ejemplo n.º 1
0
    private void GenerateEnemy()
    {
        for (int i = 0; i < _fieldEnemyList.Count; i++)
        {
            if (_fieldEnemyList[i] != null)
            {
                GameObject.Destroy(_fieldEnemyList[i].gameObject);
            }
        }

        _fieldEnemyList.Clear();
        FieldEnemy enemy;

        DungeonData.RootObject data = DungeonData.GetData(_mapInfo.ID);

        Vector2Int position;
        Vector2Int playerPosition = Vector2Int.RoundToInt(_player.transform.position);

        for (int i = 0; i < _mapInfo.RoomPositionList.Count; i++)
        {
            for (int j = 0; j < 1; j++) //每個房間生一隻怪
            {
                position = GetLegalPosition(_mapInfo.RoomPositionList[i]);
                if (Vector2.Distance(position, playerPosition) > 10 && AStarAlgor.Instance.GetPath(position, playerPosition, _pathFindList, true) != null) //如果位置不會離玩家太近
                {
                    enemy = ResourceManager.Instance.Spawn("FieldEnemy/FieldEnemyRandom", ResourceManager.Type.Other).GetComponent <FieldEnemy>();
                    enemy.OnPlayerEnterHandler += EnterBattle;
                    enemy.Init(data.GetRandomBattleGroup(), position);
                    _fieldEnemyList.Add(enemy);

                    if (enemy is FieldEnemyRandom)
                    {
                        ((FieldEnemyRandom)enemy).SetData(_player.transform, _pathFindList);
                    }
                }
            }
        }

        if (data.GoalBattleGroup != 0)
        {
            for (int i = 0; i < _mapInfo.GuardList.Count; i++)
            {
                enemy = ResourceManager.Instance.Spawn("FieldEnemy/FieldEnemyGuard", ResourceManager.Type.Other).GetComponent <FieldEnemy>();
                enemy.OnPlayerEnterHandler += EnterBattle;
                ((FieldEnemyGuard)enemy).CheckPositionHandler += EncounterGuard;
                enemy.Init(data.GoalBattleGroup, _mapInfo.GuardList[i]);
                _fieldEnemyList.Add(enemy);
            }
        }
    }
Ejemplo n.º 2
0
 public void ForceEnterBattle() //事件或測試時使用
 {
     DungeonData.RootObject data = DungeonData.GetData(_mapInfo.ID);
     EnterBattle(BattleGroupData.GetData(data.GetRandomBattleGroup()));
 }