コード例 #1
0
ファイル: ModeSplash.cs プロジェクト: Apian-Framework/Ace
        public async override void Start(object param = null)
        {
            base.Start();
            announcedGames = new Dictionary <string, AceGameInfo>();

            settings = appl.frontend.GetUserSettings();
            appl.AddAppCore(null);

            try {
                appl.ConnectToNetwork(kNetConnectionString);
                await appl.JoinGameNetworkAsync(kNetworkName);

                logger.Info("Local splash network joined");

                AceGameInfo gameInfo = appl.aceGameNet.CreateAceGameInfo(
                    kApianGroupName,
                    SinglePeerGroupManager.kGroupType,
                    2, // maxPlayers
                    0, // min validators
                    kValidatorWaitMs
                    );

                SplashAppCore = CreateCorePair(gameInfo);
                appl.AddAppCore(SplashAppCore);
                SplashAppCore.PlayerJoinedEvt += _OnPlayerJoinedEvt;
                SplashAppCore.Start(AceCoreModeFactory.kStart);

                LocalPeerJoinedGameData joinData = await appl.CreateAndJoinGameAsync(gameInfo, SplashAppCore);
            } catch (Exception ex) {
                ExitAbruptly($"{ex.Message}");

                return;
            }
        }
コード例 #2
0
ファイル: AceGameMode.cs プロジェクト: Apian-Framework/Ace
        protected AceAppCore CreateCorePair(AceGameInfo gameInfo)
        {
            // Create gameinstance and ApianInstance
            AceAppCore appCore = new AceAppCore();
            AceApian   apian   = AceApianFactory.Create(gameInfo.GroupType, appl.aceGameNet, appCore);

            return(appCore);
        }
コード例 #3
0
ファイル: ModePlay.cs プロジェクト: Apian-Framework/Ace
        private AceAppCore _SetupCorePair(AceGameInfo gameInfo)
        {
            if (gameInfo == null)
            {
                ExitAbruptly($"_SetupCorePair(): null gameInfo");
            }

            AceAppCore appCore = CreateCorePair(gameInfo);

            appl.AddAppCore(appCore);
            appCore.PlayerJoinedEvt += _OnPlayerJoinedEvt;
            appCore.Start(AceCoreModeFactory.kStart);
            return(appCore);
        }
コード例 #4
0
        public static AceApian Create(string apianGroupType, IAceGameNet aceGameNet, AceAppCore appCore)
        {
            AceApian result;

            switch (apianGroupType)
            {
            case SinglePeerGroupManager.kGroupType:
                result = new AceApianSinglePeer(aceGameNet, appCore);
                break;

            case CreatorSezGroupManager.kGroupType:
                result = new AceApianCreatorSez(aceGameNet, appCore);
                break;

            default:
                UniLogger.GetLogger("Apian").Warn($"AceApianFactory.Create() Unknown GroupType: {apianGroupType}");
                result = null;
                break;
            }
            return(result);
        }
コード例 #5
0
 public AceApianSinglePeer(IAceGameNet _gn, AceAppCore _client) : base(_gn, _client)
 {
     ApianClock = new CoopApianClock(this); // FIXME: Ace needs a virtual timer-based clock
     GroupMgr   = new SinglePeerGroupManager(this);
 }
コード例 #6
0
ファイル: ModePlay.cs プロジェクト: Apian-Framework/Ace
        protected const float kListenForGamesSecs = 2.0f; // TODO: belongs here?

        public async override void Start(object param = null)
        {
            base.Start();
            announcedGames = new Dictionary <string, AceGameInfo>();

            settings = appl.frontend.GetUserSettings();
            appl.AddAppCore(null);

            try {
                appl.ConnectToNetwork(settings.p2pConnectionString); // should be async? GameNet.Connect() currently is not
                GameNet.PeerJoinedNetworkData netJoinData = await appl.JoinGameNetworkAsync(settings.apianNetworkName);

                Dictionary <string, AceGameAnnounceData> gamesAvail = await appl.GetExistingGamesAsync((int)(kListenForGamesSecs * 1000));

                GameSelectedEventArgs selection = await appl.SelectGameAsync(gamesAvail);

                if (selection.result == GameSelectedEventArgs.ReturnCode.kCancel)
                {
                    ExitAbruptly($"No Game Selected.");
                }

                AceGameInfo gameInfo = selection.gameInfo;
                AceAppCore  appCore  = _SetupCorePair(gameInfo);

                bool targetGameExisted = (gameInfo.GameName != null) && gamesAvail.ContainsKey(gameInfo.GameName);

                LocalPeerJoinedGameData gameJoinedResult = null;

                bool isValidator = settings.tempSettings.TryGetValue("validator", out var value) ? Convert.ToBoolean(value) : false;

                switch (selection.result)
                {
                case  GameSelectedEventArgs.ReturnCode.kCreate:
                    // Create and join
                    if (targetGameExisted)
                    {
                        ExitAbruptly($"Cannot create.  Beam Game \"{gameInfo.GameName}\" already exists");
                    }
                    else
                    {
                        gameJoinedResult = await appl.CreateAndJoinGameAsync(gameInfo, appCore);
                    }
                    break;

                case GameSelectedEventArgs.ReturnCode.kJoin:
                    // Join existing
                    if (!targetGameExisted)
                    {
                        ExitAbruptly($"Cannot Join.  Beam Game \"{gameInfo.GameName}\" not found");
                        return;
                    }
                    else
                    {
                        gameJoinedResult = await appl.JoinExistingGameAsync(gameInfo, appCore);
                    }
                    break;

                case GameSelectedEventArgs.ReturnCode.kMaxPlayers:
                    gameJoinedResult = new LocalPeerJoinedGameData(gameInfo.GroupId, false,
                                                                   $"Cannot Join as player. Beam Game \"{gameInfo.GameName}\" already has {gameInfo.MaxPlayers} players.");
                    break;

                case GameSelectedEventArgs.ReturnCode.kCancel:
                    gameJoinedResult = new LocalPeerJoinedGameData(gameInfo.GroupId, false, "Join Cancelled");
                    break;
                }

                if (!gameJoinedResult.success)
                {
                    ExitAbruptly(gameJoinedResult.failureReason);
                    return;
                }

                if (isValidator)
                {
                    logger.Info($"Validator setting is set. Will not create a player.");
                }
                else
                {
                    logger.Info($"Requesting new player.");
                    PlayerJoinedEventArgs joinData = await appl.CreateNewPlayerAsync(appCore, gameJoinedResult.groupId, appl.MakeAiPlayer());

                    if (joinData == null)
                    {
                        ExitAbruptly("Failed to Create New Player");
                        return;
                    }
                }
            } catch (Exception ex) {
                ExitAbruptly($"{ex.Message}");

                return;
            }
        }