Exemplo n.º 1
0
    public void GenerateFloor(int id)
    {
        MySceneManager.SceneType scene;
        DungeonData.RootObject   data = DungeonData.GetData(id);
        if (data.SceneIndex == 0)
        {
            scene = MySceneManager.SceneType.Explore;
        }
        else
        {
            scene = (MySceneManager.SceneType)data.SceneIndex;
        }

        StopEnemy();
        MySceneManager.Instance.ChangeScene(scene, () =>
        {
            LoadingUI.Instance.Open(() =>
            {
                if (scene != MySceneManager.SceneType.Explore)
                {
                    _mapInfo = GameObject.Find("DungeonFromScene").GetComponent <DungeonFromScene>().GetMapInfo();
                    InitPosition();
                    SetFloor();
                    LoadingUI.Instance.Close();
                }
                else
                {
                    DungeonBuilder.Instance.Generate(data);
                }
            });
        });
        Debug.Log("Generate Floor Complete");
    }
Exemplo n.º 2
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);
            }
        }
    }
Exemplo n.º 3
0
    public MapInfo(MapMemo memo)
    {
        ID    = memo.ID;
        Group = memo.Group;
        DungeonData.RootObject dungeonData = DungeonData.GetData(ID);
        NextFloor        = dungeonData.NextFloor;
        MapBound         = memo.MapBound;
        Start            = memo.Start;
        Goal             = memo.Goal;
        MapList          = Utility.StringToVector2Int(memo.MapList);
        GrassList        = Utility.StringToVector2Int(memo.GrassList);
        KeyList          = Utility.StringToVector2Int(memo.KeyList);
        DoorList         = Utility.StringToVector2Int(memo.DoorList);
        ExploredList     = Utility.StringToVector2Int(memo.ExploredList);
        ExploredWallList = Utility.StringToVector2Int(memo.ExploredWallList);
        GuardList        = Utility.StringToVector2Int(memo.GuardList);

        for (int i = 0; i < memo.RoomPositionList.Count; i++)
        {
            RoomPositionList.Add(Utility.StringToVector2Int(memo.RoomPositionList[i]));
        }

        foreach (KeyValuePair <string, int> item in memo.MoneyDic)
        {
            MoneyDic.Add(Utility.StringToVector2Int(item.Key), item.Value);
        }

        foreach (KeyValuePair <string, Event.TypeEnum> item in memo.ExploreEventDic)
        {
            Event @event = null;
            if (item.Value == Event.TypeEnum.Recover)
            {
                @event = new RecoverEvent1();
            }
            else if (item.Value == Event.TypeEnum.Telepoet)
            {
                @event = new TeleportEvent1();
            }
            ExploreEventDic.Add(Utility.StringToVector2Int(item.Key), @event);
        }

        foreach (KeyValuePair <string, Treasure> item in memo.TreasureDic)
        {
            TreasureDic.Add(Utility.StringToVector2Int(item.Key), item.Value);
        }
    }
Exemplo n.º 4
0
 public void ForceEnterBattle() //事件或測試時使用
 {
     DungeonData.RootObject data = DungeonData.GetData(_mapInfo.ID);
     EnterBattle(BattleGroupData.GetData(data.GetRandomBattleGroup()));
 }