Ejemplo n.º 1
0
        public void OnBikeTurnCmd(BikeTurnMsg msg)
        {
            BaseBike bb = CoreData.GetBaseBike(msg.bikeId);

            logger.Verbose($"OnBikeTurnCmd({msg.dir}) Now: {FrameApianTime} Ts: {msg.TimeStamp} Bike:{msg.bikeId}");
            if (bb == null)
            {
                logger.Warn($"OnBikeTurnCmd() Bike:{msg.bikeId} not found!");
            }
            bb?.ApplyTurn(msg.dir, msg.entryHead, new Vector2(msg.nextPtX, msg.nextPtZ), msg.TimeStamp, msg.bikeState);
        }
Ejemplo n.º 2
0
        // Game code calls with a list of the currently existing games
        // Since this is the CLI app, we mostly ignore that and fetch the "gameName" cli parameter
        // and use that (in a gui App we'd display the list + have a way for the player to
        // enter params for a new game)

        // In the general GUI app case this is an async frontend gui thing
        // and ends with the frontend setting the result for a passed-in TaskCompletionResult

        // In THIS case, we just return (but have to await something to be async)
        public async Task <GameSelectedEventArgs> SelectGameAsync(IDictionary <string, AceGameAnnounceData> existingGames)
        {
            // gameName cli param can end in:
            //  '+' = means join the game if it exists, create if not
            //  '*' = means create if it oes not exist. Error if it's already there
            //  '' = "nothing" means join if it's there, or error
            string gameName = null;

            GameSelectedEventArgs.ReturnCode result;
            int         maxPlayers      = 2;
            int         minValidators   = 1;
            int         validatorWaitMs = 5000;
            AceGameInfo gameInfo;

            string argStr;

            if (userSettings.tempSettings.TryGetValue("gameName", out argStr))
            {
                string groupType;
                if (userSettings.tempSettings.TryGetValue("groupType", out groupType))
                {
                    if (!AceApianFactory.ApianGroupTypes.Contains(groupType))
                    {
                        throw new Exception($"Unknown Group Type: {groupType}.");
                    }
                    logger.Warn($"Requested group type: {groupType}");
                }
                else
                {
                    groupType = CreatorSezGroupManager.kGroupType;
                }


                gameName = argStr.TrimEnd(new [] { '+', '*' });
                result   = (argStr.EndsWith("*")) || (argStr.EndsWith("+") && !existingGames.Keys.Contains(gameName)) ? GameSelectedEventArgs.ReturnCode.kCreate
                    : GameSelectedEventArgs.ReturnCode.kJoin;

                // TODO: does the frontend have any busniess selecting an agreement type?
                // Hmm. Actually, it kinda does: a user might well want to choose from a set of them.
                gameInfo = existingGames.Keys.Contains(gameName) ? existingGames[gameName].GameInfo
                    :  AceAppl.aceGameNet.CreateAceGameInfo(gameName, groupType, maxPlayers, minValidators, validatorWaitMs);

                AceGameStatus gameStatus = existingGames.Keys.Contains(gameName) ? existingGames[gameName].GameStatus : null;

                // If we are asking to be a player - is there room in this game?
                bool isValidator = userSettings.tempSettings.TryGetValue("validator", out var value) ? Convert.ToBoolean(value) : false;
                if (!isValidator && gameStatus?.PlayerCount >= gameInfo.MaxPlayers)
                {
                    result = GameSelectedEventArgs.ReturnCode.kMaxPlayers;
                }
            }
            else
            {
                throw new Exception($"gameName setting missing.");
            }

            await Task.Delay(0); // Yuk, But usually this is an async UI operation

            return(new GameSelectedEventArgs(gameInfo, result));
        }
Ejemplo n.º 3
0
 // TODO: On-the-fly LocalPeerData() from GmeNet should go away (in GameNet)
 // and be replaced with JoinGame(gameId, localPeerDataStr);
 public string LocalPeerData()
 {
     // Game-level (not group-level) data about us
     if (LocalPeer == null)
     {
         Logger.Warn("LocalPeerData() - no local peer");
     }
     return(JsonConvert.SerializeObject(LocalPeer));
 }
Ejemplo n.º 4
0
        // Game code calls with a list of the currently existing games
        // Since this is the CLI app, we mostly ignore that and fetch the "gameName" cli parameter
        // and use that (in a gui App we'd display the list + have a way for the player to
        // enter params for a new game)

        // In the general GUI app case this is an async frontend gui thing
        // and ends with the frontend setting the result for a passed-in TaskCompletionResult

        // In THIS case, we just return (but have to await something to be async)
        public async Task <GameSelectedArgs> SelectGameAsync(IDictionary <string, BeamGameInfo> existingGames)
        {
            // gameName cli param can end in:
            //  '+' = means join the game if it exists, create if not
            //  '*' = means create if it oes not exist. Error if it's already there
            //  '' = "nothing" means join if it's there, or error
            string gameName = null;

            GameSelectedArgs.ReturnCode result;
            BeamGameInfo gameInfo;

            string argStr;

            if (userSettings.tempSettings.TryGetValue("gameName", out argStr))
            {
                string groupType;
                if (userSettings.tempSettings.TryGetValue("groupType", out groupType))
                {
                    if (!BeamApianFactory.ApianGroupTypes.Contains(groupType))
                    {
                        throw new Exception($"Unknown Group Type: {groupType}.");
                    }
                    logger.Warn($"Requested group type: {groupType}");
                }
                else
                {
                    groupType = CreatorSezGroupManager.kGroupType;
                }


                gameName = argStr.TrimEnd(new [] { '+', '*' });
                result   = (argStr.EndsWith("*")) || (argStr.EndsWith("+") && !existingGames.Keys.Contains(gameName)) ? GameSelectedArgs.ReturnCode.kCreate
                    : GameSelectedArgs.ReturnCode.kJoin;

                // TODO: does the frontend have any busniess selecting an agreement type?
                // Hmm. Actually, it kinda does: a user might well want to choose from a set of them.
                gameInfo = existingGames.Keys.Contains(gameName) ? existingGames[gameName]
                    : beamAppl.beamGameNet.CreateBeamGameInfo(gameName, groupType);
            }
            else
            {
                throw new Exception($"gameName setting missing.");
            }

            await Task.Delay(0); // Yuk, But usually this is an async UI operation

            return(new GameSelectedArgs(gameInfo, result));
        }
Ejemplo n.º 5
0
        public void ApplyTurn(TurnDir dir, Heading entryHeading, Vector2 nextPt, long cmdTime, BeamMessage.BikeState reportedState)
        {
            // TODO: &&&& reported state really should not be there.

            Vector2 testPt = UpcomingGridPoint(basePosition); // use the last logged position

            if (!testPt.Equals(nextPt))
            {
                logger.Warn($"ApplyTurn(): {(nextPt.ToString())} is the wrong upcoming point for bike: {bikeId}");
                logger.Warn($"We think it should be {(testPt.ToString())}");
                logger.Warn($"Reported State:\n{JsonConvert.SerializeObject(reportedState)}");
                logger.Warn($"Actual State:\n{JsonConvert.SerializeObject(new BeamMessage.BikeState(this)) }");
            }
            basePendingTurn = dir;
        }