Esempio n. 1
0
    // 开始pve单机战斗
    public void StartBattle(int mapID, BattleType battleType)
    {
        if (_battleState != State.NONE)
        {
            // 已经在比赛中
            return;
        }

        // 显示ui
        UIManager.Instance.OpenWindow <UIBattleView>();

        // 竞技场配置数据
        var cfg = ArenaConfigLoader.GetConfig(mapID);

        if (cfg == null)
        {
            return;
        }

        _arenaID    = mapID;
        _battleType = battleType;

        // 加载场景
        StartCoroutine(LoadScene(cfg.Map));

        //if (_battleType == BattleType.PVP) {
        //    // pvp战斗,先连接战斗服务器
        //    ConnectToBattleServer();
        //}
    }
Esempio n. 2
0
    // 服务器确认,开始战斗
    public void OnStartBattle(S2C_StartBattle data)
    {
        // 设置随机数种子
        UnityEngine.Random.seed = data.RandomSeed;
        _battleState            = State.GAME;
        ServerTurnIndex         = 0;
        ClientTurnIndex         = 0;
        _accumilatedTime        = 0;

        Mana = GameConfig.START_MANA * GameConfig.MANA_MUL;

        // 清理出牌卡组
        DeckCardList.Clear();
        DeckCardList.AddRange(CardList);

        // 创建塔
        ArenaConfig cfg = ArenaConfigLoader.GetConfig(_arenaID);

        if (cfg == null)
        {
            return;
        }

        _enemyTower.Clear();

        // 判定主客场 只有判定了主客场,才能开始整场战斗
        if (data.UserID1 == UserID)
        {
            // 主场 我在左边
            IsHomeCourt = true;

            // 敌人的id和等级
            EnemyUserID    = data.UserID2;
            EnemyUserLevel = data.UserLevel2;

            // 创建我方的塔 (我在左边)
            // 主场玩家左侧为我方塔,右侧为敌方塔,非主场玩家则相反。 将来统一坐标系后再考虑玩家统一在左方,现在双方玩家跟服务器坐标一致,通过塔的颜色来区分
            _enemyTower.Add(CreateTower(GameConfig.TOWER_ID, UserLevel, cfg.TowerLeft1, UserID));
            _enemyTower.Add(CreateTower(GameConfig.TOWER_ID, UserLevel, cfg.TowerLeft2, UserID));
            _enemyTower.Add(CreateTower(GameConfig.KING_TOWER_ID, UserLevel, cfg.CastleLeft, UserID));

            // 创建敌方的塔
            _enemyTower.Add(CreateTower(GameConfig.TOWER_ID, EnemyUserLevel, cfg.TowerRight1, EnemyUserID));
            _enemyTower.Add(CreateTower(GameConfig.TOWER_ID, EnemyUserLevel, cfg.TowerRight2, EnemyUserID));
            _enemyTower.Add(CreateTower(GameConfig.KING_TOWER_ID, EnemyUserLevel, cfg.CastleRight, EnemyUserID));
        }
        else
        {
            // 客场,我在右边
            IsHomeCourt = false;

            // 敌人的id和等级
            EnemyUserID    = data.UserID1;
            EnemyUserLevel = data.UserLevel1;

            // 创建我方的塔 (我在右边)

            _enemyTower.Add(CreateTower(GameConfig.TOWER_ID, UserLevel, cfg.TowerRight1, UserID));
            _enemyTower.Add(CreateTower(GameConfig.TOWER_ID, UserLevel, cfg.TowerRight2, UserID));
            _enemyTower.Add(CreateTower(GameConfig.KING_TOWER_ID, UserLevel, cfg.CastleRight, UserID));

            // 创建敌方的塔
            _enemyTower.Add(CreateTower(GameConfig.TOWER_ID, EnemyUserLevel, cfg.TowerLeft1, EnemyUserID));
            _enemyTower.Add(CreateTower(GameConfig.TOWER_ID, EnemyUserLevel, cfg.TowerLeft2, EnemyUserID));
            _enemyTower.Add(CreateTower(GameConfig.KING_TOWER_ID, EnemyUserLevel, cfg.CastleLeft, EnemyUserID));
        }

        // 产生4张卡牌
        const float TIME = 0.3f;

        PushNewCard(0, null, 0);
        PushNewCard(1, null, TIME * 1);
        PushNewCard(2, null, TIME * 2);
        PushNewCard(3, null, TIME * 3);

        // 生成下一张卡牌
        GenerateCard();
    }