Exemplo n.º 1
0
 public PathConstructor(OpponentData data, bool isSmallBlind)
 {
     _data          = data;
     _currentRound  = 0;
     _isSmallBlind  = isSmallBlind;
     _roundEndIndex = new int[4];
 }
Exemplo n.º 2
0
 private void checkForNewOvertakes(GameStateData previousGameState, GameStateData currentGameState)
 {
     if (currentGameState.SessionData.SessionPhase == SessionPhase.Green &&
         currentGameState.SessionData.SessionType == SessionType.Race && currentGameState.SessionData.CompletedLaps > 0)
     {
         if (currentGameState.Now > lastPassCheck.Add(passCheckInterval))
         {
             lastPassCheck = currentGameState.Now;
             if (currentGameState.SessionData.TimeDeltaFront > 0)
             {
                 gapsAhead.Add(currentGameState.SessionData.TimeDeltaFront);
             }
             if (currentGameState.SessionData.TimeDeltaBehind > 0)
             {
                 gapsBehind.Add(currentGameState.SessionData.TimeDeltaBehind);
             }
             string currentOpponentAheadKey  = currentGameState.getOpponentKeyInFront(true);
             string currentOpponentBehindKey = currentGameState.getOpponentKeyBehind(true);
             // seems like belt and braces, but as Raceroom names aren't unique we need to double check a pass actually happened here:
             if (frequencyOfOvertakingMessages > 0 && currentOpponentAheadKey != opponentAheadKey)
             {
                 if (currentGameState.SessionData.CurrentLapIsValid && !currentGameState.PitData.InPitlane &&
                     currentOpponentBehindKey == opponentAheadKey && isPassMessageCandidate(gapsAhead, passCheckSamplesToCheck, minAverageGapForPassMessage))
                 {
                     OpponentData carWeJustPassed = currentGameState.OpponentData[currentOpponentBehindKey];
                     if (carWeJustPassed.CompletedLaps == currentGameState.SessionData.CompletedLaps &&
                         CarData.IsCarClassEqual(carWeJustPassed.CarClass, currentGameState.carClass))
                     {
                         timeWhenWeMadeAPass           = currentGameState.Now;
                         opponentKeyForCarWeJustPassed = currentOpponentBehindKey;
                         lastOvertakeWasClean          = true;
                         if (currentGameState.CarDamageData.LastImpactTime > 0 && (currentGameState.SessionData.SessionRunningTime - currentGameState.CarDamageData.LastImpactTime) < secondsToCheckForDamageOnPass)
                         {
                             lastOvertakeWasClean = false;
                         }
                     }
                 }
                 gapsAhead.Clear();
             }
             if (frequencyOfBeingOvertakenMessages > 0 && opponentBehindKey != currentOpponentBehindKey)
             {
                 if (!currentGameState.PitData.InPitlane && currentOpponentAheadKey == opponentBehindKey && isPassMessageCandidate(gapsBehind, beingPassedCheckSamplesToCheck, minAverageGapForBeingPassedMessage))
                 {
                     // TODO: check if we need to do a pit check here - don't think so
                     OpponentData carThatJustPassedUs = currentGameState.OpponentData[currentOpponentAheadKey];
                     if (carThatJustPassedUs.CompletedLaps == currentGameState.SessionData.CompletedLaps &&
                         CarData.IsCarClassEqual(carThatJustPassedUs.CarClass, currentGameState.carClass))
                     {
                         timeWhenWeWerePassed = currentGameState.Now;
                         opponentKeyForCarThatJustPassedUs = currentOpponentAheadKey;
                     }
                 }
                 gapsBehind.Clear();
             }
             opponentAheadKey  = currentOpponentAheadKey;
             opponentBehindKey = currentOpponentBehindKey;
         }
     }
 }
Exemplo n.º 3
0
 public TreeConstructor(PokerGame game, OpponentData data)
 {
     _player       = game.Players[1];
     _settings     = game.Settings;
     _street       = game.Hand.Street;
     _data         = data;
     _evCalculator = new EVCalculator(game, game.Settings);
 }
Exemplo n.º 4
0
 public PokerTree(PokerGame game, List <Card> street, Player player, Settings settings, int currentRoundNumber, OpponentData data)
 {
     RootNode      = CreateTree(street, player, settings, currentRoundNumber);
     _currentNode  = RootNode;
     _data         = data;
     _isSmallBlind = player.IsSmallBlind;
     _pokerGame    = game;
 }
Exemplo n.º 5
0
        private OpponentData makeTempDriver(String driverName, List <String> rawDriverNames)
        {
            OpponentData opponent = new OpponentData();

            opponent.DriverRawName = driverName;
            rawDriverNames.Add(driverName);
            return(opponent);
        }
Exemplo n.º 6
0
 public override bool isMessageStillValid(string eventSubType, GameStateData currentGameState, Dictionary <String, Object> validationData)
 {
     if (base.isMessageStillValid(eventSubType, currentGameState, validationData))
     {
         if (validationData != null)
         {
             if (validationData.ContainsKey(validationDriverAheadKey))
             {
                 String       expectedOpponentName = (String)validationData[validationDriverAheadKey];
                 OpponentData opponentInFront      = currentGameState.SessionData.Position > 1 ? currentGameState.getOpponentAtPosition(currentGameState.SessionData.Position - 1, false) : null;
                 String       actualOpponentName   = opponentInFront == null ? null : opponentInFront.DriverRawName;
                 if (actualOpponentName != expectedOpponentName)
                 {
                     if (actualOpponentName != null && expectedOpponentName != null)
                     {
                         Console.WriteLine("new car in front message for opponent " + expectedOpponentName +
                                           " no longer valid - driver in front is now " + actualOpponentName);
                     }
                     return(false);
                 }
                 else if (opponentInFront != null && (opponentInFront.InPits || opponentInFront.isEnteringPits()))
                 {
                     Console.WriteLine("new car in front message for opponent " + expectedOpponentName +
                                       " no longer valid - driver is " + (opponentInFront.InPits ? "in pits" : "is entering the pits"));
                 }
             }
             else if (validationData.ContainsKey(validationNewLeaderKey))
             {
                 String expectedLeaderName = (String)validationData[validationNewLeaderKey];
                 if (currentGameState.SessionData.Position == 1)
                 {
                     Console.WriteLine("new leader message for opponent " + expectedLeaderName +
                                       " no longer valid - player is now leader");
                     return(false);
                 }
                 OpponentData actualLeader     = currentGameState.getOpponentAtPosition(1, false);
                 String       actualLeaderName = actualLeader == null ? null : actualLeader.DriverRawName;
                 if (actualLeaderName != expectedLeaderName)
                 {
                     if (actualLeaderName != null && expectedLeaderName != null)
                     {
                         Console.WriteLine("new leader message for opponent " + expectedLeaderName +
                                           " no longer valid - leader is now " + actualLeaderName);
                     }
                     return(false);
                 }
             }
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 7
0
    void RTMPPlayerAdded(string message)
    {
        print("Player added:" + message);
        //txt.text = "Player added:" + message;

        string[]     temp = message.Split(',');
        OpponentData data = new OpponentData();

        data.opponentID   = temp[0];
        data.opponentName = temp[1];
        opponents.Add(data);

        if (mRTMPCallBacks != null)
        {
            mRTMPCallBacks.RTMPPlayerAdded(temp[0], temp[1]);
        }
    }
Exemplo n.º 8
0
        private float getOpponentBestLap(int opponentPosition, int lapsToCheck, GameStateData gameState)
        {
            OpponentData opponent = gameState.getOpponentAtClassPosition(opponentPosition, gameState.carClass);

            if (opponent == null || opponent.OpponentLapData.Count < lapsToCheck)
            {
                return(-1);
            }
            float bestLap = -1;

            for (int i = opponent.OpponentLapData.Count - 1; i >= opponent.OpponentLapData.Count - lapsToCheck; i--)
            {
                if (bestLap == -1 || bestLap > opponent.OpponentLapData[i].LapTime)
                {
                    bestLap = opponent.OpponentLapData[i].LapTime;
                }
            }
            return(bestLap);
        }
Exemplo n.º 9
0
    void opponentPictureLoaded(string id)
    {
        //print("got pic");
        using (AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
            using (AndroidJavaObject obj_Activity = cls_UnityPlayer.GetStatic <AndroidJavaObject>("currentActivity")) {
                AndroidJavaClass cls_CompassActivity = new AndroidJavaClass("com.tapinator.tank.simulator.MainActivity");
                byte[]           byteArray           = cls_CompassActivity.CallStatic <byte[]>("getOpponentImage", id);

                if (byteArray == null)
                {
                    return;
                }
                //print ("1");
                //foreach (OpponentData op in opponents) {
                for (int i = 0; i < opponents.Count; i++)
                {
                    OpponentData op = (OpponentData)opponents[i];
                    //print ("2");
                    if (op.opponentID.Equals(id))
                    {
                        //print ("3");
                        Texture2D tex = new Texture2D(4, 4);
                        tex.LoadImage(byteArray);
                        op.opponentPicture = tex;
                        //print ("4");
                        if (mPictureCallBacks != null)
                        {
                            //print ("5");
                            mPictureCallBacks.OpponentPictureLoaded(id, tex);
                        }

                        break;
                    }
                }
            }
        }
    }
Exemplo n.º 10
0
 public VpipController(OpponentData playerData)
 {
     _playerData = playerData;
     _pfr        = PFRStandard;
     _vpip       = VPIPStandard;
 }
Exemplo n.º 11
0
 private void checkCompletedOvertake(GameStateData currentGameState)
 {
     if (opponentKeyForCarWeJustPassed != null)
     {
         if (currentGameState.Now < timeWhenWeMadeAPass.Add(maxTimeToWaitBeforeReportingPass))
         {
             Boolean      reported        = false;
             OpponentData carWeJustPassed = currentGameState.OpponentData[opponentKeyForCarWeJustPassed];
             if (currentGameState.Now > timeWhenWeMadeAPass.Add(minTimeToWaitBeforeReportingPass))
             {
                 if (currentGameState.Now > lastOvertakeMessageTime.Add(minTimeBetweenOvertakeMessages) &&
                     carWeJustPassed.Position > currentGameState.SessionData.Position && currentGameState.SessionData.TimeDeltaBehind > minTimeDeltaForPassToBeCompleted)
                 {
                     lastOvertakeMessageTime = currentGameState.Now;
                     Console.WriteLine("Reporting overtake on car " + opponentKeyForCarWeJustPassed);
                     opponentKeyForCarWeJustPassed = null;
                     gapsAhead.Clear();
                     // adding a 'good' pearl with 0 probability of playing seems odd, but this forces the app to only
                     // allow an existing queued pearl to be played if it's type is 'good'
                     Dictionary <String, Object> validationData = new Dictionary <String, Object>();
                     validationData.Add(positionValidationKey, currentGameState.SessionData.Position);
                     audioPlayer.playMessage(new QueuedMessage(folderOvertaking, 0, this, validationData), PearlsOfWisdom.PearlType.GOOD, 0);
                     reported = true;
                 }
             }
             if (!reported)
             {
                 // check the pass is still valid
                 if (!currentGameState.SessionData.CurrentLapIsValid || carWeJustPassed.isEnteringPits() ||
                     currentGameState.PositionAndMotionData.CarSpeed - carWeJustPassed.Speed > maxSpeedDifferenceForReportablePass)
                 {
                     opponentKeyForCarWeJustPassed = null;
                     gapsAhead.Clear();
                 }
             }
         }
         else
         {
             opponentKeyForCarWeJustPassed = null;
             gapsAhead.Clear();
         }
     }
     if (opponentKeyForCarThatJustPassedUs != null)
     {
         if (currentGameState.Now < timeWhenWeWerePassed.Add(maxTimeToWaitBeforeReportingPass))
         {
             Boolean      reported            = false;
             OpponentData carThatJustPassedUs = currentGameState.OpponentData[opponentKeyForCarThatJustPassedUs];
             if (currentGameState.Now > timeWhenWeWerePassed.Add(minTimeToWaitBeforeReportingPass))
             {
                 if (currentGameState.Now > lastOvertakeMessageTime.Add(minTimeBetweenOvertakeMessages) &&
                     carThatJustPassedUs.Position < currentGameState.SessionData.Position && currentGameState.SessionData.TimeDeltaFront > minTimeDeltaForPassToBeCompleted)
                 {
                     lastOvertakeMessageTime = currentGameState.Now;
                     Console.WriteLine("Reporting being overtaken by car " + opponentKeyForCarThatJustPassedUs);
                     opponentKeyForCarThatJustPassedUs = null;
                     gapsBehind.Clear();
                     // adding a 'bad' pearl with 0 probability of playing seems odd, but this forces the app to only
                     // allow an existing queued pearl to be played if it's type is 'bad'
                     Dictionary <String, Object> validationData = new Dictionary <String, Object>();
                     validationData.Add(positionValidationKey, currentGameState.SessionData.Position);
                     audioPlayer.playMessage(new QueuedMessage(folderBeingOvertaken, 0, this, validationData), PearlsOfWisdom.PearlType.BAD, 0);
                     reported = true;
                 }
             }
             if (!reported)
             {
                 // check the pass is still valid - no lap validity check here because we're being passed
                 if (carThatJustPassedUs.isEnteringPits() ||
                     carThatJustPassedUs.Speed - currentGameState.PositionAndMotionData.CarSpeed > maxSpeedDifferenceForReportableBeingPassed)
                 {
                     opponentKeyForCarThatJustPassedUs = null;
                     gapsBehind.Clear();
                 }
             }
         }
         else
         {
             opponentKeyForCarThatJustPassedUs = null;
             gapsBehind.Clear();
         }
     }
 }
Exemplo n.º 12
0
        override protected void triggerInternal(GameStateData previousGameState, GameStateData currentGameState)
        {
            // store this in a local var so it's available for vocie command responses
            addExtraLap           = currentGameState.SessionData.HasExtraLap;
            leaderHasFinishedRace = currentGameState.SessionData.LeaderHasFinishedRace;
            timeLeft = currentGameState.SessionData.SessionTimeRemaining;
            if (currentGameState.SessionData.SessionNumberOfLaps > 0)
            {
                lapsLeft            = currentGameState.SessionData.SessionNumberOfLaps - currentGameState.SessionData.CompletedLaps;
                sessionLengthIsTime = false;
            }
            else
            {
                sessionLengthIsTime = true;
            }
            if (sessionLengthIsTime)
            {
                if (addExtraLap && gotHalfTime && timeLeft <= 0 && currentGameState.SessionData.IsNewLap)
                {
                    startedExtraLap = true;
                }
                if (!gotHalfTime)
                {
                    Console.WriteLine("Session time remaining = " + timeLeft);
                    halfTime    = timeLeft / 2;
                    gotHalfTime = true;
                    if (currentGameState.FuelData.FuelUseActive)
                    {
                        // don't allow the half way message to play if fuel use is active - there's already one in there
                        playedHalfWayHome = true;
                    }
                }
                PearlsOfWisdom.PearlType pearlType = PearlsOfWisdom.PearlType.NONE;
                if (currentGameState.SessionData.SessionType == SessionType.Race && currentGameState.SessionData.CompletedLaps > 1)
                {
                    pearlType = PearlsOfWisdom.PearlType.NEUTRAL;
                    if (currentGameState.SessionData.Position < 4)
                    {
                        pearlType = PearlsOfWisdom.PearlType.GOOD;
                    }
                    else if (currentGameState.SessionData.Position > currentGameState.SessionData.SessionStartPosition + 5 &&
                             !currentGameState.PitData.OnOutLap && !currentGameState.PitData.InPitlane &&
                             // yuk... AC SessionStartPosition is suspect so don't allow "you're shit" messages based on it.
                             CrewChief.gameDefinition.gameEnum != GameEnum.ASSETTO_32BIT && CrewChief.gameDefinition.gameEnum != GameEnum.ASSETTO_64BIT)
                    {
                        // don't play bad-pearl if we're on an out lap or are pitting
                        pearlType = PearlsOfWisdom.PearlType.BAD;
                    }
                }

                if (currentGameState.SessionData.SessionType == SessionType.Race && currentGameState.SessionData.IsNewLap &&
                    currentGameState.SessionData.SessionRunningTime > 60 && !playedLastLap)
                {
                    Boolean timeWillBeZeroAtEndOfLeadersLap = false;
                    if (currentGameState.SessionData.Position == 1)
                    {
                        timeWillBeZeroAtEndOfLeadersLap = timeLeft > 0 && currentGameState.SessionData.PlayerLapTimeSessionBest > 0 &&
                                                          timeLeft < currentGameState.SessionData.PlayerLapTimeSessionBest - 5;
                    }
                    else
                    {
                        OpponentData leader = currentGameState.getOpponentAtPosition(1, true);
                        timeWillBeZeroAtEndOfLeadersLap = leader != null && leader.isProbablyLastLap;
                    }
                    if ((addExtraLap && timeLeft <= 0) ||
                        (!addExtraLap && timeWillBeZeroAtEndOfLeadersLap))
                    {
                        playedLastLap     = true;
                        played2mins       = true;
                        played5mins       = true;
                        played10mins      = true;
                        played15mins      = true;
                        played20mins      = true;
                        playedHalfWayHome = true;
                        if (currentGameState.SessionData.Position == 1)
                        {
                            // don't add a pearl here - the audio clip already contains encouragement
                            audioPlayer.playMessage(new QueuedMessage(folderLastLapLeading, 0, this), pearlType, 0);
                        }
                        else if (currentGameState.SessionData.Position < 4)
                        {
                            // don't add a pearl here - the audio clip already contains encouragement
                            audioPlayer.playMessage(new QueuedMessage(folderLastLapPodium, 0, this), pearlType, 0);
                        }
                        else
                        {
                            audioPlayer.playMessage(new QueuedMessage(folderLastLap, 0, this));
                        }
                    }
                }
                if (currentGameState.SessionData.SessionRunningTime > 60 && timeLeft / 60 < 3 && timeLeft / 60 > 2.9)
                {
                    // disable pearls for the last part of the race
                    audioPlayer.disablePearlsOfWisdom = true;
                }
                // Console.WriteLine("Session time left = " + timeLeft + " SessionRunningTime = " + currentGameState.SessionData.SessionRunningTime);
                if (!currentGameState.SessionData.HasExtraLap &&
                    currentGameState.SessionData.SessionRunningTime >= 0 && !played0mins && timeLeft <= 0.2)
                {
                    played0mins       = true;
                    played2mins       = true;
                    played5mins       = true;
                    played10mins      = true;
                    played15mins      = true;
                    played20mins      = true;
                    playedHalfWayHome = true;
                    audioPlayer.suspendPearlsOfWisdom();
                    // PCars hack - don't play this if it's an unlimited session - no lap limit and no time limit
                    if (!currentGameState.SessionData.SessionHasFixedTime && currentGameState.SessionData.SessionNumberOfLaps <= 0)
                    {
                        Console.WriteLine("Skipping session end messages for unlimited session");
                    }
                    else if (currentGameState.SessionData.SessionType != SessionType.Race)
                    {
                        // don't play the chequered flag message in race sessions
                        audioPlayer.playMessage(new QueuedMessage("session_complete",
                                                                  MessageContents(folder0mins, Position.folderStub + currentGameState.SessionData.Position), 0, this));
                    }
                }
                if (currentGameState.SessionData.SessionRunningTime > 60 && !played2mins && timeLeft / 60 < 2 && timeLeft / 60 > 1.9)
                {
                    played2mins       = true;
                    played5mins       = true;
                    played10mins      = true;
                    played15mins      = true;
                    played20mins      = true;
                    playedHalfWayHome = true;
                    audioPlayer.suspendPearlsOfWisdom();
                    audioPlayer.playMessage(new QueuedMessage(folder2mins, 0, this));
                }
                if (currentGameState.SessionData.SessionRunningTime > 60 && !played5mins && timeLeft / 60 < 5 && timeLeft / 60 > 4.9)
                {
                    played5mins       = true;
                    played10mins      = true;
                    played15mins      = true;
                    played20mins      = true;
                    playedHalfWayHome = true;
                    if (currentGameState.SessionData.SessionType == SessionType.Race && currentGameState.SessionData.Position == 1)
                    {
                        // don't add a pearl here - the audio clip already contains encouragement
                        audioPlayer.playMessage(new QueuedMessage(folder5minsLeading, 0, this), pearlType, 0);
                    }
                    else if (currentGameState.SessionData.SessionType == SessionType.Race && currentGameState.SessionData.Position < 4)
                    {
                        // don't add a pearl here - the audio clip already contains encouragement
                        audioPlayer.playMessage(new QueuedMessage(folder5minsPodium, 0, this), pearlType, 0);
                    }
                    else
                    {
                        audioPlayer.playMessage(new QueuedMessage(folder5mins, 0, this), pearlType, 0.7);
                    }
                }
                if (currentGameState.SessionData.SessionRunningTime > 60 && !played10mins && timeLeft / 60 < 10 && timeLeft / 60 > 9.9)
                {
                    played10mins = true;
                    played15mins = true;
                    played20mins = true;
                    audioPlayer.playMessage(new QueuedMessage(folder10mins, 0, this), pearlType, 0.7);
                }
                if (currentGameState.SessionData.SessionRunningTime > 60 && !played15mins && timeLeft / 60 < 15 && timeLeft / 60 > 14.9)
                {
                    played15mins = true;
                    played20mins = true;
                    audioPlayer.playMessage(new QueuedMessage(folder15mins, 0, this), pearlType, 0.7);
                }
                if (currentGameState.SessionData.SessionRunningTime > 60 && !played20mins && timeLeft / 60 < 20 && timeLeft / 60 > 19.9)
                {
                    played20mins = true;
                    audioPlayer.playMessage(new QueuedMessage(folder20mins, 0, this), pearlType, 0.7);
                }
                else if (currentGameState.SessionData.SessionType == SessionType.Race &&
                         currentGameState.SessionData.SessionRunningTime > 60 && !playedHalfWayHome && timeLeft > 0 && timeLeft < halfTime)
                {
                    // this one sounds weird in practice and qual sessions, so skip it
                    playedHalfWayHome = true;
                    audioPlayer.playMessage(new QueuedMessage(folderHalfWayHome, 0, this), pearlType, 0.7);
                }
            }
        }
Exemplo n.º 13
0
        private PlayerAction _expectedAction; // For checking if the human player follows the calculated path.


        public ExpectiMaxDecisionMaking(OpponentData data)
        {
            _data = data;
        }
Exemplo n.º 14
0
        override protected void triggerInternal(GameStateData previousGameState, GameStateData currentGameState)
        {
            addExtraLapForDTM2015 = currentGameState.carClass.carClassEnum == CarData.CarClassEnum.DTM_2015;
            leaderHasFinishedRace = currentGameState.SessionData.LeaderHasFinishedRace;
            timeLeft = currentGameState.SessionData.SessionTimeRemaining;
            if (currentGameState.SessionData.SessionNumberOfLaps > 0)
            {
                lapsLeft            = currentGameState.SessionData.SessionNumberOfLaps - currentGameState.SessionData.CompletedLaps;
                sessionLengthIsTime = false;
            }
            else
            {
                sessionLengthIsTime = true;
            }
            if (sessionLengthIsTime)
            {
                if (addExtraLapForDTM2015 && gotHalfTime && timeLeft <= 0 && currentGameState.SessionData.IsNewLap)
                {
                    startedDTM2015ExtraLap = true;
                }
                if (!gotHalfTime)
                {
                    Console.WriteLine("Session time remaining = " + timeLeft);
                    halfTime    = timeLeft / 2;
                    gotHalfTime = true;
                    if (currentGameState.FuelData.FuelUseActive)
                    {
                        // don't allow the half way message to play if fuel use is active - there's already one in there
                        playedHalfWayHome = true;
                    }
                }
                PearlsOfWisdom.PearlType pearlType = PearlsOfWisdom.PearlType.NONE;
                if (currentGameState.SessionData.SessionType == SessionType.Race && currentGameState.SessionData.CompletedLaps > 1)
                {
                    pearlType = PearlsOfWisdom.PearlType.NEUTRAL;
                    if (currentGameState.SessionData.Position < 4)
                    {
                        pearlType = PearlsOfWisdom.PearlType.GOOD;
                    }
                    else if (currentGameState.SessionData.Position > currentGameState.SessionData.SessionStartPosition + 5 &&
                             !currentGameState.PitData.OnOutLap && !currentGameState.PitData.InPitlane)
                    {
                        // don't play bad-pearl if we're on an out lap or are pitting
                        pearlType = PearlsOfWisdom.PearlType.BAD;
                    }
                }

                if (currentGameState.SessionData.SessionType == SessionType.Race && currentGameState.SessionData.IsNewLap &&
                    currentGameState.SessionData.SessionRunningTime > 60 && !playedLastLap)
                {
                    Boolean timeWillBeZeroAtEndOfLeadersLap = false;
                    if (currentGameState.SessionData.Position == 1)
                    {
                        timeWillBeZeroAtEndOfLeadersLap = timeLeft > 0 && currentGameState.SessionData.PlayerLapTimeSessionBest > 0 &&
                                                          timeLeft < currentGameState.SessionData.PlayerLapTimeSessionBest - 5;
                    }
                    else
                    {
                        OpponentData leader = currentGameState.getOpponentAtPosition(1, true);
                        timeWillBeZeroAtEndOfLeadersLap = leader != null && leader.isProbablyLastLap;
                    }
                    if ((addExtraLapForDTM2015 && timeLeft <= 0) ||
                        (!addExtraLapForDTM2015 && timeWillBeZeroAtEndOfLeadersLap))
                    {
                        playedLastLap     = true;
                        played2mins       = true;
                        played5mins       = true;
                        played10mins      = true;
                        played15mins      = true;
                        played20mins      = true;
                        playedHalfWayHome = true;
                        if (currentGameState.SessionData.Position == 1)
                        {
                            // don't add a pearl here - the audio clip already contains encouragement
                            audioPlayer.playMessage(new QueuedMessage(folderLastLapLeading, 0, this), pearlType, 0);
                        }
                        else if (currentGameState.SessionData.Position < 4)
                        {
                            // don't add a pearl here - the audio clip already contains encouragement
                            audioPlayer.playMessage(new QueuedMessage(folderLastLapPodium, 0, this), pearlType, 0);
                        }
                        else
                        {
                            audioPlayer.playMessage(new QueuedMessage(folderLastLap, 0, this));
                        }
                    }
                }
                if (currentGameState.SessionData.SessionRunningTime > 60 && timeLeft / 60 < 3 && timeLeft / 60 > 2.9)
                {
                    // disable pearls for the last part of the race
                    audioPlayer.disablePearlsOfWisdom = true;
                }
                if (currentGameState.SessionData.SessionRunningTime > 60 && !played2mins && timeLeft / 60 < 2 && timeLeft / 60 > 1.9)
                {
                    played2mins       = true;
                    played5mins       = true;
                    played10mins      = true;
                    played15mins      = true;
                    played20mins      = true;
                    playedHalfWayHome = true;
                    audioPlayer.suspendPearlsOfWisdom();
                    audioPlayer.playMessage(new QueuedMessage(folder2mins, 0, this));
                }
                if (currentGameState.SessionData.SessionRunningTime > 60 && !played5mins && timeLeft / 60 < 5 && timeLeft / 60 > 4.9)
                {
                    played5mins       = true;
                    played10mins      = true;
                    played15mins      = true;
                    played20mins      = true;
                    playedHalfWayHome = true;
                    if (currentGameState.SessionData.SessionType == SessionType.Race && currentGameState.SessionData.Position == 1)
                    {
                        // don't add a pearl here - the audio clip already contains encouragement
                        audioPlayer.playMessage(new QueuedMessage(folder5minsLeading, 0, this), pearlType, 0);
                    }
                    else if (currentGameState.SessionData.SessionType == SessionType.Race && currentGameState.SessionData.Position < 4)
                    {
                        // don't add a pearl here - the audio clip already contains encouragement
                        audioPlayer.playMessage(new QueuedMessage(folder5minsPodium, 0, this), pearlType, 0);
                    }
                    else
                    {
                        audioPlayer.playMessage(new QueuedMessage(folder5mins, 0, this), pearlType, 0.7);
                    }
                }
                if (currentGameState.SessionData.SessionRunningTime > 60 && !played10mins && timeLeft / 60 < 10 && timeLeft / 60 > 9.9)
                {
                    played10mins = true;
                    played15mins = true;
                    played20mins = true;
                    audioPlayer.playMessage(new QueuedMessage(folder10mins, 0, this), pearlType, 0.7);
                }
                if (currentGameState.SessionData.SessionRunningTime > 60 && !played15mins && timeLeft / 60 < 15 && timeLeft / 60 > 14.9)
                {
                    played15mins = true;
                    played20mins = true;
                    audioPlayer.playMessage(new QueuedMessage(folder15mins, 0, this), pearlType, 0.7);
                }
                if (currentGameState.SessionData.SessionRunningTime > 60 && !played20mins && timeLeft / 60 < 20 && timeLeft / 60 > 19.9)
                {
                    played20mins = true;
                    audioPlayer.playMessage(new QueuedMessage(folder20mins, 0, this), pearlType, 0.7);
                }
                else if (currentGameState.SessionData.SessionType == SessionType.Race &&
                         currentGameState.SessionData.SessionRunningTime > 60 && !playedHalfWayHome && timeLeft > 0 && timeLeft < halfTime)
                {
                    // this one sounds weird in practice and qual sessions, so skip it
                    playedHalfWayHome = true;
                    audioPlayer.playMessage(new QueuedMessage(folderHalfWayHome, 0, this), pearlType, 0.7);
                }
            }
        }
Exemplo n.º 15
0
        protected override void triggerInternal(GameStateData previousGameState, GameStateData currentGameState)
        {
            isLeading         = currentGameState.SessionData.Position == 1;
            isLast            = currentGameState.isLast();
            isRace            = currentGameState.SessionData.SessionType == SessionType.Race;
            currentGapInFront = currentGameState.SessionData.TimeDeltaFront;
            currentGapBehind  = currentGameState.SessionData.TimeDeltaBehind;

            if (currentGameState.SessionData.IsNewLap)
            {
                playedGapBehindForThisLap = false;
            }

            if (gapsInFront == null || gapsBehind == null)
            {
                clearState();
            }
            if (!currentGameState.SessionData.IsRacingSameCarInFront)
            {
                gapsInFront.Clear();
                gapInFrontAtLastReport = -1;
            }
            if (!currentGameState.SessionData.IsRacingSameCarBehind)
            {
                gapsBehind.Clear();
                gapBehindAtLastReport = -1;
            }
            if (previousGameState != null && previousGameState.SessionData.CompletedLaps <= currentGameState.FlagData.lapCountWhenLastWentGreen)
            {
                return;
            }
            if (!currentGameState.PitData.InPitlane && enableGapMessages)
            {
                if (isRace && !CrewChief.readOpponentDeltasForEveryLap &&
                    IsNewSectorOrGapPoint(previousGameState, currentGameState))
                {
                    sectorsSinceLastGapAheadReport++;
                    sectorsSinceLastGapBehindReport++;
                    sectorsSinceLastCloseCarAheadReport++;
                    sectorsSinceLastCloseCarBehindReport++;
                    GapStatus gapInFrontStatus = GapStatus.NONE;
                    GapStatus gapBehindStatus  = GapStatus.NONE;
                    if (currentGameState.SessionData.Position != 1)
                    {
                        // AMS / RF1 hack - sometimes the gap data is stale, so don't put the exact same gap in the list
                        if (gapsInFront.Count == 0 || gapsInFront[0] != currentGameState.SessionData.TimeDeltaFront)
                        {
                            gapsInFront.Insert(0, currentGameState.SessionData.TimeDeltaFront);
                            gapInFrontStatus = getGapStatus(gapsInFront, gapInFrontAtLastReport);
                        }
                    }
                    if (!isLast)
                    {
                        // AMS / RF1 hack - sometimes the gap data is stale, so don't put the exact same gap in the list
                        if (gapsBehind.Count == 0 || gapsBehind[0] != currentGameState.SessionData.TimeDeltaBehind)
                        {
                            gapsBehind.Insert(0, currentGameState.SessionData.TimeDeltaBehind);
                            gapBehindStatus = getGapStatus(gapsBehind, gapBehindAtLastReport);
                        }
                    }

                    // Play which ever is the smaller gap, but we're not interested if the gap is < 0.5 or > 20 seconds or hasn't changed:
                    Boolean playGapInFront = gapInFrontStatus != GapStatus.NONE &&
                                             (gapBehindStatus == GapStatus.NONE || (gapsInFront.Count() > 0 && gapsBehind.Count() > 0 && gapsInFront[0] < gapsBehind[0]));

                    Boolean playGapBehind = !playGapInFront && gapBehindStatus != GapStatus.NONE;
                    if (playGapInFront)
                    {
                        if (gapInFrontStatus == GapStatus.CLOSE)
                        {
                            if (sectorsSinceLastCloseCarAheadReport >= sectorsUntilNextCloseCarAheadReport)
                            {
                                sectorsSinceLastCloseCarAheadReport = 0;
                                // only prefer mid-lap gap reports if we're on a track with no ad-hoc gapPoints
                                if (currentGameState.SessionData.TrackDefinition.gapPoints.Count() > 0)
                                {
                                    sectorsUntilNextCloseCarAheadReport = rand.Next(closeAheadMinSectorWait, closeAheadMaxSectorWait);
                                }
                                else
                                {
                                    sectorsUntilNextCloseCarAheadReport = adjustForMidLapPreference(currentGameState.SessionData.SectorNumber,
                                                                                                    rand.Next(closeAheadMinSectorWait, closeAheadMaxSectorWait));
                                }
                                audioPlayer.playMessage(new QueuedMessage(folderBeingHeldUp, 0, this, new Dictionary <string, object> {
                                    { "position", currentGameState.SessionData.Position }
                                }));
                                OpponentData opponent = currentGameState.getOpponentAtPosition(currentGameState.SessionData.Position - 1, false);
                                if (!trackLandmarkAttackDriverNamesUsed.ContainsKey(opponent.DriverRawName) ||
                                    trackLandmarkAttackDriverNamesUsed[opponent.DriverRawName] + minTimeBetweenAttackOrDefendByDriver < currentGameState.Now)
                                {
                                    CrewChiefV4.GameState.TrackLandmarksTiming.LandmarkAndDeltaType landmarkAndDeltaType =
                                        currentGameState.SessionData.trackLandmarksTiming.getLandmarkWhereIAmFaster(opponent.trackLandmarksTiming, true);
                                    if (landmarkAndDeltaType.landmarkName != null)
                                    {
                                        // either we're faster on entry or faster through
                                        String attackFolder = landmarkAndDeltaType.deltaType == TrackLandmarksTiming.DeltaType.Time ? folderHeIsSlowerThroughCorner : folderHeIsSlowerEnteringCorner;
                                        audioPlayer.playMessage(new QueuedMessage("Timings/corner_to_attack_in", MessageContents(Pause(200), attackFolder, "corners/" + landmarkAndDeltaType.landmarkName), 0, this));
                                        trackLandmarkAttackDriverNamesUsed[opponent.DriverRawName] = currentGameState.Now;
                                    }
                                }
                                gapInFrontAtLastReport = gapsInFront[0];
                            }
                        }
                        else if (gapInFrontStatus != GapStatus.NONE && sectorsSinceLastGapAheadReport >= sectorsUntilNextGapAheadReport)
                        {
                            sectorsSinceLastGapAheadReport = 0;
                            // only prefer mid-lap gap reports if we're on a track with no ad-hoc gapPoints
                            if (currentGameState.SessionData.TrackDefinition.gapPoints.Count() > 0)
                            {
                                sectorsUntilNextGapAheadReport = rand.Next(gapAheadMinSectorWait, gapAheadMaxSectorWait);
                            }
                            else
                            {
                                sectorsUntilNextGapAheadReport = adjustForMidLapPreference(currentGameState.SessionData.SectorNumber,
                                                                                           rand.Next(gapAheadMinSectorWait, gapAheadMaxSectorWait));
                            }
                            TimeSpan gapInFront = TimeSpan.FromMilliseconds(gapsInFront[0] * 1000);
                            Boolean  readGap    = gapInFront.Seconds > 0 || gapInFront.Milliseconds > 50;
                            if (readGap)
                            {
                                if (gapInFrontStatus == GapStatus.INCREASING)
                                {
                                    audioPlayer.playMessage(new QueuedMessage("Timings/gap_in_front",
                                                                              MessageContents(folderTheGapTo, currentGameState.getOpponentAtPosition(currentGameState.SessionData.Position - 1, false), folderAheadIsIncreasing,
                                                                                              gapInFront), MessageContents(folderGapInFrontIncreasing, gapInFront), 0, this, new Dictionary <string, object> {
                                        { "position", currentGameState.SessionData.Position }
                                    }));
                                }
                                else if (gapInFrontStatus == GapStatus.DECREASING)
                                {
                                    OpponentData opponent = currentGameState.getOpponentAtPosition(currentGameState.SessionData.Position - 1, false);
                                    audioPlayer.playMessage(new QueuedMessage("Timings/gap_in_front",
                                                                              MessageContents(folderYoureReeling, opponent, folderInTheGapIsNow, gapInFront),
                                                                              MessageContents(folderGapInFrontDecreasing, gapInFront), 0, this, new Dictionary <string, object> {
                                        { "position", currentGameState.SessionData.Position }
                                    }));
                                    if (!trackLandmarkAttackDriverNamesUsed.ContainsKey(opponent.DriverRawName) ||
                                        trackLandmarkAttackDriverNamesUsed[opponent.DriverRawName] + minTimeBetweenAttackOrDefendByDriver < currentGameState.Now)
                                    {
                                        CrewChiefV4.GameState.TrackLandmarksTiming.LandmarkAndDeltaType landmarkAndDeltaType =
                                            currentGameState.SessionData.trackLandmarksTiming.getLandmarkWhereIAmFaster(opponent.trackLandmarksTiming, true);
                                        if (landmarkAndDeltaType.landmarkName != null)
                                        {
                                            // either we're faster on entry or faster through
                                            String attackFolder = landmarkAndDeltaType.deltaType == TrackLandmarksTiming.DeltaType.Time ? folderHeIsSlowerThroughCorner : folderHeIsSlowerEnteringCorner;
                                            audioPlayer.playMessage(new QueuedMessage("Timings/corner_to_attack_in", MessageContents(Pause(200), attackFolder, "corners/" + landmarkAndDeltaType.landmarkName), 0, this));
                                            trackLandmarkAttackDriverNamesUsed[opponent.DriverRawName] = currentGameState.Now;
                                        }
                                    }
                                }
                                else if (gapInFrontStatus == GapStatus.OTHER)
                                {
                                    audioPlayer.playMessage(new QueuedMessage("Timings/gap_in_front",
                                                                              MessageContents(folderTheGapTo, currentGameState.getOpponentAtPosition(currentGameState.SessionData.Position - 1, false),
                                                                                              folderAheadIsNow, gapInFront), MessageContents(folderGapInFrontIsNow, gapInFront), 0, this, new Dictionary <string, object> {
                                        { "position", currentGameState.SessionData.Position }
                                    }));
                                }
                            }
                            gapInFrontAtLastReport = gapsInFront[0];
                        }
                    }
                    else if (playGapBehind)
                    {
                        if (gapBehindStatus == GapStatus.CLOSE)
                        {
                            if (sectorsSinceLastCloseCarBehindReport >= sectorsUntilNextCloseCarBehindReport)
                            {
                                sectorsSinceLastCloseCarBehindReport = 0;
                                // only prefer mid-lap gap reports if we're on a track with no ad-hoc gapPoints
                                if (currentGameState.SessionData.TrackDefinition.gapPoints.Count() > 0)
                                {
                                    sectorsUntilNextCloseCarBehindReport = rand.Next(closeBehindMinSectorWait, closeBehindMaxSectorWait);
                                }
                                else
                                {
                                    sectorsUntilNextCloseCarBehindReport = adjustForMidLapPreference(currentGameState.SessionData.SectorNumber,
                                                                                                     rand.Next(closeBehindMinSectorWait, closeBehindMaxSectorWait));
                                }
                                audioPlayer.playMessage(new QueuedMessage(folderBeingPressured, 0, this, new Dictionary <string, object> {
                                    { "position", currentGameState.SessionData.Position }
                                }));
                                OpponentData opponent = currentGameState.getOpponentAtPosition(currentGameState.SessionData.Position + 1, false);
                                if (!trackLandmarkDefendDriverNamesUsed.ContainsKey(opponent.DriverRawName) ||
                                    trackLandmarkDefendDriverNamesUsed[opponent.DriverRawName] + minTimeBetweenAttackOrDefendByDriver < currentGameState.Now)
                                {
                                    CrewChiefV4.GameState.TrackLandmarksTiming.LandmarkAndDeltaType landmarkAndDeltaType =
                                        currentGameState.SessionData.trackLandmarksTiming.getLandmarkWhereIAmSlower(opponent.trackLandmarksTiming, true);
                                    if (landmarkAndDeltaType.landmarkName != null)
                                    {
                                        // either we're slower on entry or slower through
                                        String defendFolder = landmarkAndDeltaType.deltaType == TrackLandmarksTiming.DeltaType.Time ? folderHeIsFasterThroughCorner : folderHeIsFasterEnteringCorner;
                                        audioPlayer.playMessage(new QueuedMessage("Timings/corner_to_defend_in", MessageContents(Pause(200), defendFolder, "corners/" + landmarkAndDeltaType.landmarkName), 0, this));
                                        trackLandmarkDefendDriverNamesUsed[opponent.DriverRawName] = currentGameState.Now;
                                    }
                                }
                                gapBehindAtLastReport = gapsBehind[0];
                            }
                        }
                        else if (gapBehindStatus != GapStatus.NONE && sectorsSinceLastGapBehindReport >= sectorsUntilNextGapBehindReport)
                        {
                            sectorsSinceLastGapBehindReport = 0;
                            // only prefer mid-lap gap reports if we're on a track with no ad-hoc gapPoints
                            if (currentGameState.SessionData.TrackDefinition.gapPoints.Count() > 0)
                            {
                                sectorsUntilNextGapBehindReport = rand.Next(gapBehindMinSectorWait, gapBehindMaxSectorWait);
                            }
                            else
                            {
                                sectorsUntilNextGapBehindReport = adjustForMidLapPreference(currentGameState.SessionData.SectorNumber,
                                                                                            rand.Next(gapBehindMinSectorWait, gapBehindMaxSectorWait));
                            }
                            TimeSpan gapBehind = TimeSpan.FromMilliseconds(gapsBehind[0] * 1000);
                            Boolean  readGap   = gapBehind.Seconds > 0 || gapBehind.Milliseconds > 50;
                            if (readGap)
                            {
                                if (gapBehindStatus == GapStatus.INCREASING)
                                {
                                    audioPlayer.playMessage(new QueuedMessage("Timings/gap_behind",
                                                                              MessageContents(folderTheGapTo, currentGameState.getOpponentAtPosition(currentGameState.SessionData.Position + 1, false),
                                                                                              folderBehindIsIncreasing, gapBehind), MessageContents(folderGapBehindIncreasing, gapBehind), 0, this, new Dictionary <string, object> {
                                        { "position", currentGameState.SessionData.Position }
                                    }));
                                }
                                else if (gapBehindStatus == GapStatus.DECREASING)
                                {
                                    OpponentData opponent = currentGameState.getOpponentAtPosition(currentGameState.SessionData.Position + 1, false);
                                    audioPlayer.playMessage(new QueuedMessage("Timings/gap_behind",
                                                                              MessageContents(opponent, folderIsReelingYouIn, gapBehind), MessageContents(folderGapBehindDecreasing, gapBehind),
                                                                              0, this, new Dictionary <string, object> {
                                        { "position", currentGameState.SessionData.Position }
                                    }));

                                    if (!trackLandmarkDefendDriverNamesUsed.ContainsKey(opponent.DriverRawName) ||
                                        trackLandmarkDefendDriverNamesUsed[opponent.DriverRawName] + minTimeBetweenAttackOrDefendByDriver < currentGameState.Now)
                                    {
                                        CrewChiefV4.GameState.TrackLandmarksTiming.LandmarkAndDeltaType landmarkAndDeltaType =
                                            currentGameState.SessionData.trackLandmarksTiming.getLandmarkWhereIAmSlower(opponent.trackLandmarksTiming, true);
                                        if (landmarkAndDeltaType.landmarkName != null)
                                        {
                                            // either we're slower on entry or slower through
                                            String defendFolder = landmarkAndDeltaType.deltaType == TrackLandmarksTiming.DeltaType.Time ? folderHeIsFasterThroughCorner : folderHeIsFasterEnteringCorner;
                                            audioPlayer.playMessage(new QueuedMessage("Timings/corner_to_defend_in", MessageContents(Pause(200), defendFolder, "corners/" + landmarkAndDeltaType.landmarkName), 0, this));
                                            trackLandmarkDefendDriverNamesUsed[opponent.DriverRawName] = currentGameState.Now;
                                        }
                                    }
                                }
                                else if (gapBehindStatus == GapStatus.OTHER)
                                {
                                    audioPlayer.playMessage(new QueuedMessage("Timings/gap_behind",
                                                                              MessageContents(folderTheGapTo, currentGameState.getOpponentAtPosition(currentGameState.SessionData.Position + 1, false),
                                                                                              folderBehindIsNow, gapBehind), MessageContents(folderGapBehindIsNow, gapBehind), 0, this, new Dictionary <string, object> {
                                        { "position", currentGameState.SessionData.Position }
                                    }));
                                }
                            }
                            gapBehindAtLastReport = gapsBehind[0];
                        }
                    }
                }
                if (isRace && CrewChief.readOpponentDeltasForEveryLap && currentGameState.SessionData.CompletedLaps > 0)
                {
                    if (currentGameState.SessionData.Position > 1 && currentGameState.SessionData.IsNewLap)
                    {
                        if (currentGapInFront > 0.05)
                        {
                            TimeSpan      gap     = TimeSpan.FromSeconds(currentGapInFront);
                            QueuedMessage message = new QueuedMessage("Timings/gap_ahead", MessageContents(folderTheGapTo,
                                                                                                           currentGameState.getOpponentAtPosition(currentGameState.SessionData.Position - 1, false), folderAheadIsNow, gap),
                                                                      MessageContents(folderGapInFrontIsNow, gap), 0, this, new Dictionary <string, object> {
                                { "position", currentGameState.SessionData.Position }
                            });
                            message.playEvenWhenSilenced = true;
                            audioPlayer.playMessage(message);
                        }
                    }
                    if (!currentGameState.isLast())
                    {
                        if (!playedGapBehindForThisLap && currentGapBehind > 0.05 && currentGameState.SessionData.LapTimeCurrent > 0 &&
                            currentGameState.SessionData.LapTimeCurrent >= currentGapBehind &&
                            currentGameState.SessionData.LapTimeCurrent <= currentGapBehind + CrewChief._timeInterval.TotalSeconds)
                        {
                            playedGapBehindForThisLap = true;
                            TimeSpan      gap     = TimeSpan.FromSeconds(currentGapBehind);
                            QueuedMessage message = new QueuedMessage("Timings/gap_behind", MessageContents(folderTheGapTo,
                                                                                                            currentGameState.getOpponentAtPosition(currentGameState.SessionData.Position + 1, false), folderBehindIsNow, gap),
                                                                      MessageContents(folderGapBehindIsNow, gap), 0, this, new Dictionary <string, object> {
                                { "position", currentGameState.SessionData.Position }
                            });
                            message.playEvenWhenSilenced = true;
                            audioPlayer.playMessage(message);
                        }
                    }
                }
            }
        }
Exemplo n.º 16
0
 public static MessageFragment Opponent(OpponentData opponent)
 {
     return(new MessageFragment(opponent));
 }
Exemplo n.º 17
0
        private void checkForNewOvertakes(GameStateData previousGameState, GameStateData currentGameState)
        {
            if (currentGameState.PenaltiesData.IsOffRacingSurface)
            {
                lastOffTrackSessionTime = currentGameState.SessionData.SessionRunningTime;
            }

            Boolean currentSectorIsYellow = currentGameState.SessionData.SectorNumber > 0 && currentGameState.SessionData.SectorNumber < 4 &&
                                            currentGameState.FlagData.sectorFlags[currentGameState.SessionData.SectorNumber - 1] == FlagEnum.YELLOW;

            if (currentGameState.FlagData.isLocalYellow || currentSectorIsYellow)
            {
                lastYellowFlagTime = currentGameState.SessionData.SessionRunningTime;
            }
            if (currentGameState.SessionData.SessionPhase == SessionPhase.Green &&
                currentGameState.SessionData.SessionType == SessionType.Race && currentGameState.SessionData.CompletedLaps > 0)
            {
                if (currentGameState.Now > lastPassCheck.Add(passCheckInterval))
                {
                    lastPassCheck = currentGameState.Now;
                    if (currentGameState.SessionData.TimeDeltaFront > 0)
                    {
                        gapsAhead.Add(currentGameState.SessionData.TimeDeltaFront);
                    }
                    if (currentGameState.SessionData.TimeDeltaBehind > 0)
                    {
                        gapsBehind.Add(currentGameState.SessionData.TimeDeltaBehind);
                    }
                    string currentOpponentAheadKey  = currentGameState.getOpponentKeyInFront(currentGameState.carClass);
                    string currentOpponentBehindKey = currentGameState.getOpponentKeyBehind(currentGameState.carClass);
                    // seems like belt and braces, but as Raceroom names aren't unique we need to double check a pass actually happened here:
                    if (frequencyOfOvertakingMessages > 0 && currentOpponentAheadKey != opponentAheadKey)
                    {
                        if (currentOpponentBehindKey != null &&
                            currentGameState.SessionData.CurrentLapIsValid && !currentGameState.PitData.InPitlane &&
                            currentOpponentBehindKey == opponentAheadKey && isPassMessageCandidate(gapsAhead, passCheckSamplesToCheck, minAverageGapForPassMessage))
                        {
                            OpponentData carWeJustPassed = currentGameState.OpponentData[currentOpponentBehindKey];
                            if (carWeJustPassed.CompletedLaps == currentGameState.SessionData.CompletedLaps &&
                                CarData.IsCarClassEqual(carWeJustPassed.CarClass, currentGameState.carClass))
                            {
                                timeWhenWeMadeAPass           = currentGameState.Now;
                                opponentKeyForCarWeJustPassed = currentOpponentBehindKey;
                                lastOvertakeWasClean          = true;
                                if (currentGameState.CarDamageData.LastImpactTime > 0.0f && (currentGameState.SessionData.SessionRunningTime - currentGameState.CarDamageData.LastImpactTime) < secondsToCheckForDamageOrOfftrackOnPass)
                                {
                                    lastOvertakeWasClean = false;
                                    Console.WriteLine("Overtake considered not clean due to vehicle damage.");
                                }
                                else if (lastOffTrackSessionTime > 0.0f && (currentGameState.SessionData.SessionRunningTime - lastOffTrackSessionTime) < secondsToCheckForDamageOrOfftrackOnPass)
                                {
                                    lastOvertakeWasClean = false;
                                    Console.WriteLine("Overtake considered not clean due to vehicle off track.");
                                }
                                else if (lastYellowFlagTime > 0.0f && (currentGameState.SessionData.SessionRunningTime - lastYellowFlagTime) < secondsToCheckForYellowOnPass)
                                {
                                    lastOvertakeWasClean = false;
                                    Console.WriteLine("Overtake considered not clean due to yellow flag.");
                                }
                            }
                        }
                        gapsAhead.Clear();
                    }
                    if (frequencyOfBeingOvertakenMessages > 0 && opponentBehindKey != currentOpponentBehindKey)
                    {
                        if (currentOpponentAheadKey != null &&
                            !currentGameState.PitData.InPitlane && currentOpponentAheadKey == opponentBehindKey &&
                            isPassMessageCandidate(gapsBehind, beingPassedCheckSamplesToCheck, minAverageGapForBeingPassedMessage))
                        {
                            OpponentData carThatJustPassedUs = currentGameState.OpponentData[currentOpponentAheadKey];
                            if (carThatJustPassedUs.CompletedLaps == currentGameState.SessionData.CompletedLaps &&
                                CarData.IsCarClassEqual(carThatJustPassedUs.CarClass, currentGameState.carClass))
                            {
                                timeWhenWeWerePassed = currentGameState.Now;
                                opponentKeyForCarThatJustPassedUs = currentOpponentAheadKey;
                            }
                        }
                        gapsBehind.Clear();
                    }
                    opponentAheadKey  = currentOpponentAheadKey;
                    opponentBehindKey = currentOpponentBehindKey;
                }
            }
        }
Exemplo n.º 18
0
 private MessageFragment(OpponentData opponent)
 {
     this.opponent = opponent;
     this.type     = FragmentType.Opponent;
 }
Exemplo n.º 19
0
        override protected void triggerInternal(GameStateData previousGameState, GameStateData currentGameState)
        {
            this.currentGameState = currentGameState;
            if (nextCarAheadChangeMessage == DateTime.MinValue)
            {
                nextCarAheadChangeMessage = currentGameState.Now.Add(TimeSpan.FromSeconds(30));
            }
            if (nextLeadChangeMessage == DateTime.MinValue)
            {
                nextLeadChangeMessage = currentGameState.Now.Add(TimeSpan.FromSeconds(30));
            }
            if (currentGameState.SessionData.SessionType != SessionType.Race || frequencyOfOpponentRaceLapTimes > 0)
            {
                foreach (KeyValuePair <string, OpponentData> entry in currentGameState.OpponentData)
                {
                    string       opponentKey  = entry.Key;
                    OpponentData opponentData = entry.Value;

                    if (opponentData.IsNewLap && opponentData.LastLapTime > 0 && opponentData.OpponentLapData.Count > 1 &&
                        opponentData.LastLapValid && opponentData.CurrentBestLapTime > 0)
                    {
                        float currentFastestLap;
                        if (currentGameState.SessionData.PlayerLapTimeSessionBest == -1)
                        {
                            currentFastestLap = currentGameState.SessionData.OpponentsLapTimeSessionBestOverall;
                        }
                        else if (currentGameState.SessionData.OpponentsLapTimeSessionBestOverall == -1)
                        {
                            currentFastestLap = currentGameState.SessionData.PlayerLapTimeSessionBest;
                        }
                        else
                        {
                            currentFastestLap = Math.Min(currentGameState.SessionData.PlayerLapTimeSessionBest, currentGameState.SessionData.OpponentsLapTimeSessionBestOverall);
                        }

                        // this opponent has just completed a lap - do we need to report it? if it's fast overall and more than
                        // a tenth quicker then his previous best we do...
                        if (((currentGameState.SessionData.SessionType == SessionType.Race && opponentData.CompletedLaps > 2) ||
                             (currentGameState.SessionData.SessionType != SessionType.Race && opponentData.CompletedLaps > 1)) && opponentData.LastLapTime <= currentFastestLap &&
                            (SoundCache.hasSuitableTTSVoice || SoundCache.availableDriverNames.Contains(DriverNameHelper.getUsableDriverName(opponentData.DriverRawName))))
                        {
                            audioPlayer.playMessage(new QueuedMessage("new_fastest_lap", MessageContents(folderNewFastestLapFor, opponentData,
                                                                                                         TimeSpan.FromSeconds(opponentData.LastLapTime)), 0, this));
                        }
                        else if ((currentGameState.SessionData.SessionType == SessionType.Race &&
                                  (opponentData.LastLapTime <= opponentData.CurrentBestLapTime &&
                                   opponentData.LastLapTime < opponentData.PreviousBestLapTime - minImprovementBeforeReadingOpponentRaceTime &&
                                   opponentData.LastLapTime < currentFastestLap + maxOffPaceBeforeReadingOpponentRaceTime)) ||
                                 ((currentGameState.SessionData.SessionType == SessionType.Practice || currentGameState.SessionData.SessionType == SessionType.Qualify) &&
                                  opponentData.LastLapTime <= opponentData.CurrentBestLapTime))
                        {
                            if (currentGameState.SessionData.UnFilteredPosition > 1 && opponentData.UnFilteredPosition == 1 &&
                                (currentGameState.SessionData.SessionType == SessionType.Race || frequencyOfOpponentPracticeAndQualLapTimes > 0))
                            {
                                // he's leading, and has recorded 3 or more laps, and this one's his fastest
                                Console.WriteLine("Leader fast lap - this lap time = " + opponentData.LastLapTime + " session best = " + currentFastestLap);
                                audioPlayer.playMessage(new QueuedMessage("leader_good_laptime", MessageContents(folderLeaderHasJustDoneA,
                                                                                                                 TimeSpan.FromSeconds(opponentData.LastLapTime)), 0, this));
                            }
                            else if (currentGameState.SessionData.UnFilteredPosition > 1 && opponentData.UnFilteredPosition == currentGameState.SessionData.Position - 1 &&
                                     (currentGameState.SessionData.SessionType == SessionType.Race || random.Next(10) < frequencyOfOpponentPracticeAndQualLapTimes))
                            {
                                // he's ahead of us, and has recorded 3 or more laps, and this one's his fastest
                                Console.WriteLine("Car ahead fast lap - this lap time = " + opponentData.LastLapTime + " session best = " + currentFastestLap);
                                audioPlayer.playMessage(new QueuedMessage("car_ahead_good_laptime", MessageContents(folderTheCarAheadHasJustDoneA,
                                                                                                                    TimeSpan.FromSeconds(opponentData.LastLapTime)), 0, this));
                            }
                            else if (!currentGameState.isLast() && opponentData.UnFilteredPosition == currentGameState.SessionData.Position + 1 &&
                                     (currentGameState.SessionData.SessionType == SessionType.Race || random.Next(10) < frequencyOfOpponentPracticeAndQualLapTimes))
                            {
                                // he's behind us, and has recorded 3 or more laps, and this one's his fastest
                                Console.WriteLine("Car behind fast lap - this lap time = " + opponentData.LastLapTime + " session best = " + currentFastestLap);
                                audioPlayer.playMessage(new QueuedMessage("car_behind_good_laptime", MessageContents(folderTheCarBehindHasJustDoneA,
                                                                                                                     TimeSpan.FromSeconds(opponentData.LastLapTime)), 0, this));
                            }
                        }
                    }
                }
            }

            if (currentGameState.SessionData.SessionType == SessionType.Race)
            {
                if (!currentGameState.SessionData.IsRacingSameCarInFront)
                {
                    if (currentGameState.SessionData.Position > 2 && currentGameState.Now > nextCarAheadChangeMessage && !currentGameState.PitData.InPitlane &&
                        currentGameState.SessionData.CompletedLaps > 0)
                    {
                        OpponentData opponentData = currentGameState.getOpponentAtPosition(currentGameState.SessionData.Position - 1, false);
                        if (opponentData != null && !opponentData.isEnteringPits() && !opponentData.InPits &&
                            (SoundCache.hasSuitableTTSVoice || SoundCache.availableDriverNames.Contains(DriverNameHelper.getUsableDriverName(opponentData.DriverRawName))))
                        {
                            audioPlayer.playMessage(new QueuedMessage("new_car_ahead", MessageContents(folderNextCarIs, opponentData),
                                                                      random.Next(Position.maxSecondsToWaitBeforeReportingPass + 1, Position.maxSecondsToWaitBeforeReportingPass + 3), this,
                                                                      new Dictionary <string, object> {
                                { validationDriverAheadKey, opponentData.DriverRawName }
                            }));
                            nextCarAheadChangeMessage = currentGameState.Now.Add(TimeSpan.FromSeconds(30));
                        }
                    }
                }
                if (currentGameState.SessionData.HasLeadChanged)
                {
                    OpponentData leader = currentGameState.getOpponentAtPosition(1, false);
                    if (leader != null)
                    {
                        String name = leader.DriverRawName;
                        if (currentGameState.SessionData.Position > 1 && previousGameState.SessionData.Position > 1 &&
                            currentGameState.Now > nextLeadChangeMessage &&
                            (SoundCache.hasSuitableTTSVoice || SoundCache.availableDriverNames.Contains(DriverNameHelper.getUsableDriverName(name))))
                        {
                            Console.WriteLine("Lead change, current leader is " + name + " laps completed = " + currentGameState.SessionData.CompletedLaps);
                            audioPlayer.playMessage(new QueuedMessage("new_leader", MessageContents(leader, folderIsNowLeading), 2, this,
                                                                      new Dictionary <string, object> {
                                { validationNewLeaderKey, name }
                            }));
                            nextLeadChangeMessage = currentGameState.Now.Add(TimeSpan.FromSeconds(30));
                        }
                    }
                }

                if (currentGameState.PitData.LeaderIsPitting &&
                    currentGameState.SessionData.SessionPhase != SessionPhase.Countdown && currentGameState.SessionData.SessionPhase != SessionPhase.Formation)
                {
                    audioPlayer.playMessage(new QueuedMessage("leader_is_pitting", MessageContents(folderTheLeader, currentGameState.PitData.OpponentForLeaderPitting,
                                                                                                   folderIsPitting), MessageContents(folderLeaderIsPitting), 0, this));
                }

                if (currentGameState.PitData.CarInFrontIsPitting && currentGameState.SessionData.TimeDeltaFront > 3 &&
                    currentGameState.SessionData.SessionPhase != SessionPhase.Countdown && currentGameState.SessionData.SessionPhase != SessionPhase.Formation)
                {
                    audioPlayer.playMessage(new QueuedMessage("car_in_front_is_pitting", MessageContents(currentGameState.PitData.OpponentForCarAheadPitting,
                                                                                                         folderAheadIsPitting), MessageContents(folderCarAheadIsPitting), 0, this));
                }

                if (currentGameState.PitData.CarBehindIsPitting && currentGameState.SessionData.TimeDeltaBehind > 3 &&
                    currentGameState.SessionData.SessionPhase != SessionPhase.Countdown && currentGameState.SessionData.SessionPhase != SessionPhase.Formation)
                {
                    audioPlayer.playMessage(new QueuedMessage("car_behind_is_pitting", MessageContents(currentGameState.PitData.OpponentForCarBehindPitting,
                                                                                                       folderBehindIsPitting), MessageContents(folderCarBehindIsPitting), 0, this));
                }
            }
        }
Exemplo n.º 20
0
        public override void respond(String voiceMessage)
        {
            Boolean gotData = false;

            if (currentGameState != null)
            {
                if (voiceMessage.StartsWith(SpeechRecogniser.WHAT_TYRE_IS) || voiceMessage.StartsWith(SpeechRecogniser.WHAT_TYRES_IS))
                {
                    string opponentKey = getOpponentKey(voiceMessage, " " + SpeechRecogniser.ON).Item1;
                    if (opponentKey != null)
                    {
                        OpponentData opponentData = currentGameState.OpponentData[opponentKey];
                        if (opponentData.CurrentTyres == TyreType.R3E_NEW_Option)
                        {
                            gotData = true;
                            audioPlayer.playMessageImmediately(new QueuedMessage(MandatoryPitStops.folderMandatoryPitStopsOptionTyres, 0, null));
                        }
                        else if (opponentData.CurrentTyres == TyreType.R3E_NEW_Prime)
                        {
                            gotData = true;
                            audioPlayer.playMessageImmediately(new QueuedMessage(MandatoryPitStops.folderMandatoryPitStopsPrimeTyres, 0, null));
                        }
                    }
                }

                if (voiceMessage.StartsWith(SpeechRecogniser.WHATS) &&
                    (voiceMessage.EndsWith(SpeechRecogniser.LAST_LAP) || voiceMessage.EndsWith(SpeechRecogniser.BEST_LAP)))
                {
                    if (voiceMessage.EndsWith(SpeechRecogniser.LAST_LAP))
                    {
                        float lastLap = getOpponentLastLap(getOpponentKey(voiceMessage, SpeechRecogniser.POSSESSIVE + " ").Item1);
                        if (lastLap != -1)
                        {
                            gotData = true;
                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentLastLap", MessageContents(
                                                                                     TimeSpan.FromSeconds(lastLap)), 0, null));
                        }
                    }
                    else
                    {
                        float bestLap = getOpponentBestLap(getOpponentKey(voiceMessage, SpeechRecogniser.POSSESSIVE + " ").Item1);
                        if (bestLap != -1)
                        {
                            gotData = true;
                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentBestLap", MessageContents(
                                                                                     TimeSpan.FromSeconds(bestLap)), 0, null));
                        }
                    }
                }
                else if (voiceMessage.StartsWith(SpeechRecogniser.WHERE_IS))
                {
                    Tuple <string, Boolean> response = getOpponentKey(voiceMessage, "");
                    string  opponentKey         = response.Item1;
                    Boolean gotByPositionNumber = response.Item2;
                    if (opponentKey != null && currentGameState.OpponentData.ContainsKey(opponentKey))
                    {
                        OpponentData opponent = currentGameState.OpponentData[opponentKey];
                        if (opponent.IsActive)
                        {
                            int position = opponent.Position;
                            OpponentData.OpponentDelta opponentDelta = opponent.getTimeDifferenceToPlayer(currentGameState.SessionData);
                            if (opponentDelta == null || (opponentDelta.lapDifference == 0 && Math.Abs(opponentDelta.time) < 0.05))
                            {
                                // the delta is not usable - say the position if we didn't directly ask by position

                                // TODO: we need a "right infront" or "right behind" type response here for when the delta is < 0.05 (< 1 tenth rounded)
                                if (!gotByPositionNumber)
                                {
                                    if (SoundCache.availableSounds.Contains(folderOpponentPositionIntro))
                                    {
                                        audioPlayer.playMessageImmediately(new QueuedMessage("opponentPosition", MessageContents(folderOpponentPositionIntro, Position.folderStub + position), 0, null));
                                    }
                                    else
                                    {
                                        audioPlayer.playMessageImmediately(new QueuedMessage("opponentPosition", MessageContents(Position.folderStub + position), 0, null));
                                    }
                                    gotData = true;
                                }
                            }
                            else
                            {
                                gotData = true;
                                if (opponentDelta.lapDifference == 1)
                                {
                                    if (!gotByPositionNumber)
                                    {
                                        if (SoundCache.availableSounds.Contains(folderOpponentPositionIntro))
                                        {
                                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                                 MessageContents(folderOpponentPositionIntro, Position.folderStub + position, Pause(200), Position.folderOneLapBehind), 0, null));
                                        }
                                        else
                                        {
                                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                                 MessageContents(Position.folderStub + position, Pause(200), Position.folderOneLapBehind), 0, null));
                                        }
                                    }
                                    else
                                    {
                                        audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta", MessageContents(Position.folderOneLapBehind), 0, null));
                                    }
                                }
                                else if (opponentDelta.lapDifference > 1)
                                {
                                    if (!gotByPositionNumber)
                                    {
                                        if (SoundCache.availableSounds.Contains(folderOpponentPositionIntro))
                                        {
                                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                                 MessageContents(folderOpponentPositionIntro, Position.folderStub + position, Pause(200), opponentDelta.lapDifference, Position.folderLapsBehind), 0, null));
                                        }
                                        else
                                        {
                                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                                 MessageContents(Position.folderStub + position, Pause(200), opponentDelta.lapDifference, Position.folderLapsBehind), 0, null));
                                        }
                                    }
                                    else
                                    {
                                        audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                             MessageContents(opponentDelta.lapDifference, Position.folderLapsBehind), 0, null));
                                    }
                                }
                                else if (opponentDelta.lapDifference == -1)
                                {
                                    if (!gotByPositionNumber)
                                    {
                                        if (SoundCache.availableSounds.Contains(folderOpponentPositionIntro))
                                        {
                                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                                 MessageContents(folderOpponentPositionIntro, Position.folderStub + position, Pause(200), Position.folderOneLapAhead), 0, null));
                                        }
                                        else
                                        {
                                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                                 MessageContents(Position.folderStub + position, Pause(200), Position.folderOneLapAhead), 0, null));
                                        }
                                    }
                                    else
                                    {
                                        audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta", MessageContents(Position.folderOneLapAhead), 0, null));
                                    }
                                }
                                else if (opponentDelta.lapDifference < -1)
                                {
                                    if (!gotByPositionNumber)
                                    {
                                        if (SoundCache.availableSounds.Contains(folderOpponentPositionIntro))
                                        {
                                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                                 MessageContents(folderOpponentPositionIntro, Position.folderStub + position, Pause(200), Math.Abs(opponentDelta.lapDifference), Position.folderLapsAhead), 0, null));
                                        }
                                        else
                                        {
                                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                                 MessageContents(Position.folderStub + position, Pause(200), Math.Abs(opponentDelta.lapDifference), Position.folderLapsAhead), 0, null));
                                        }
                                    }
                                    else
                                    {
                                        audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                             MessageContents(Math.Abs(opponentDelta.lapDifference), Position.folderLapsAhead), 0, null));
                                    }
                                }
                                else
                                {
                                    TimeSpan delta         = TimeSpan.FromSeconds(Math.Abs(opponentDelta.time));
                                    String   aheadOrBehind = Position.folderAhead;
                                    if (opponentDelta.time < 0)
                                    {
                                        aheadOrBehind = Position.folderBehind;
                                    }
                                    if (!gotByPositionNumber)
                                    {
                                        if (SoundCache.availableSounds.Contains(folderOpponentPositionIntro))
                                        {
                                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                                 MessageContents(folderOpponentPositionIntro, Position.folderStub + position, Pause(200), delta, aheadOrBehind), 0, null));
                                        }
                                        else
                                        {
                                            audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                                 MessageContents(Position.folderStub + position, Pause(200), delta, aheadOrBehind), 0, null));
                                        }
                                    }
                                    else
                                    {
                                        audioPlayer.playMessageImmediately(new QueuedMessage("opponentTimeDelta",
                                                                                             MessageContents(delta, aheadOrBehind), 0, null));
                                    }
                                }
                            }
                        }
                        else
                        {
                            Console.WriteLine("Driver " + opponent.DriverRawName + " is no longer active in this session");
                        }
                    }
                }
                else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHOS_BEHIND_ON_TRACK))
                {
                    string opponentKey = currentGameState.getOpponentKeyBehindOnTrack();
                    if (opponentKey != null)
                    {
                        OpponentData  opponent = currentGameState.OpponentData[opponentKey];
                        QueuedMessage queuedMessage;
                        if (SoundCache.useTTS)
                        {
                            queuedMessage = new QueuedMessage("opponentNameAndPosition", MessageContents(opponent,
                                                                                                         Position.folderStub + opponent.Position), 0, null);
                        }
                        else
                        {
                            queuedMessage = new QueuedMessage("opponentNameAndPosition", MessageContents(opponent,
                                                                                                         Position.folderStub + opponent.Position),
                                                              MessageContents(Position.folderStub + opponent.Position, folderCantPronounceName), 0, null);
                        }
                        if (queuedMessage.canBePlayed)
                        {
                            audioPlayer.playMessageImmediately(queuedMessage);
                            gotData = true;
                        }
                    }
                }
                else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHOS_IN_FRONT_ON_TRACK))
                {
                    string opponentKey = currentGameState.getOpponentKeyInFrontOnTrack();
                    if (opponentKey != null)
                    {
                        OpponentData  opponent = currentGameState.OpponentData[opponentKey];
                        QueuedMessage queuedMessage;
                        if (SoundCache.useTTS)
                        {
                            queuedMessage = new QueuedMessage("opponentName", MessageContents(opponent,
                                                                                              Position.folderStub + opponent.Position), 0, null);
                        }
                        else
                        {
                            queuedMessage = new QueuedMessage("opponentName", MessageContents(opponent,
                                                                                              Position.folderStub + opponent.Position),
                                                              MessageContents(Position.folderStub + opponent.Position, folderCantPronounceName), 0, null);
                        }

                        if (queuedMessage.canBePlayed)
                        {
                            audioPlayer.playMessageImmediately(queuedMessage);

                            gotData = true;
                        }
                    }
                }
                else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHOS_BEHIND_IN_THE_RACE))
                {
                    if (currentGameState.isLast())
                    {
                        audioPlayer.playMessageImmediately(new QueuedMessage(Position.folderLast, 0, null));

                        gotData = true;
                    }
                    else
                    {
                        OpponentData opponent = currentGameState.getOpponentAtPosition(currentGameState.SessionData.Position + 1, false);
                        if (opponent != null)
                        {
                            QueuedMessage queuedMessage;
                            if (SoundCache.useTTS)
                            {
                                queuedMessage = new QueuedMessage("opponentName", MessageContents(opponent), 0, null);
                            }
                            else
                            {
                                queuedMessage = new QueuedMessage("opponentName", MessageContents(opponent), MessageContents(folderCantPronounceName), 0, null);
                            }

                            if (queuedMessage.canBePlayed)
                            {
                                audioPlayer.playMessageImmediately(queuedMessage);

                                gotData = true;
                            }
                        }
                    }
                }
                else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHOS_IN_FRONT_IN_THE_RACE))
                {
                    if (currentGameState.SessionData.Position == 1)
                    {
                        audioPlayer.playMessageImmediately(new QueuedMessage(Position.folderLeading, 0, null));

                        gotData = true;
                    }
                    else
                    {
                        OpponentData opponent = currentGameState.getOpponentAtPosition(currentGameState.SessionData.Position - 1, false);
                        if (opponent != null)
                        {
                            QueuedMessage queuedMessage;
                            if (SoundCache.useTTS)
                            {
                                queuedMessage = new QueuedMessage("opponentName", MessageContents(opponent), 0, null);
                            }
                            else
                            {
                                queuedMessage = new QueuedMessage("opponentName", MessageContents(opponent), MessageContents(folderCantPronounceName), 0, null);
                            }

                            if (queuedMessage.canBePlayed)
                            {
                                audioPlayer.playMessageImmediately(queuedMessage);

                                gotData = true;
                            }
                        }
                    }
                }
                else if (SpeechRecogniser.ResultContains(voiceMessage, SpeechRecogniser.WHOS_LEADING) && currentGameState.SessionData.Position > 1)
                {
                    OpponentData opponent = currentGameState.getOpponentAtPosition(1, false);
                    if (opponent != null)
                    {
                        QueuedMessage queuedMessage;
                        if (SoundCache.useTTS)
                        {
                            queuedMessage = new QueuedMessage("opponentName", MessageContents(opponent), 0, null);
                        }
                        else
                        {
                            queuedMessage = new QueuedMessage("opponentName", MessageContents(opponent), MessageContents(folderCantPronounceName), 0, null);
                        }
                        if (queuedMessage.canBePlayed)
                        {
                            audioPlayer.playMessageImmediately(queuedMessage);

                            gotData = true;
                        }
                    }
                }
                else if (voiceMessage.StartsWith(SpeechRecogniser.WHOS_IN))
                {
                    string opponentKey = getOpponentKey(voiceMessage, "").Item1;
                    if (opponentKey != null)
                    {
                        if (opponentKey == positionIsPlayerKey)
                        {
                            audioPlayer.playMessageImmediately(new QueuedMessage(folderWeAre, 0, null));

                            gotData = true;
                        }
                        else if (currentGameState.OpponentData.ContainsKey(opponentKey))
                        {
                            OpponentData  opponent = currentGameState.OpponentData[opponentKey];
                            QueuedMessage queuedMessage;
                            if (SoundCache.useTTS)
                            {
                                queuedMessage = new QueuedMessage("opponentName", MessageContents(opponent), 0, null);
                            }
                            else
                            {
                                queuedMessage = new QueuedMessage("opponentName", MessageContents(opponent), MessageContents(folderCantPronounceName), 0, null);
                            }
                            if (queuedMessage.canBePlayed)
                            {
                                audioPlayer.playMessageImmediately(queuedMessage);

                                gotData = true;
                            }
                        }
                    }
                }
            }
            if (!gotData)
            {
                audioPlayer.playMessageImmediately(new QueuedMessage(AudioPlayer.folderNoData, 0, null));
            }
        }
Exemplo n.º 21
0
    private void Update()
    {
        if (shouldInitialize)
        {
            shouldInitialize = false;
            Initialize();

            if (CurrentGameMode == GameModes.Online)
            {
                if (myPlayerType == PlayerType.P1)
                {
                    Player1UserName.text = "Name : " + UserData.user.DisplayName;
                    int[] matchesInfo = UserData.ParseMatchesInfo();
                    Player1Rank.text = "Rank : " + matchesInfo[2].ToString();

                    Player2UserName.text = "Name : " + OpponentData.user.DisplayName;
                    int[] opponentMatchesInfo = OpponentData.ParseMatchesInfo();
                    Player2Rank.text = "Rank : " + opponentMatchesInfo[2].ToString();
                }
                else
                {
                    Player2UserName.text = "Name : " + UserData.user.DisplayName;
                    int[] matchesInfo = UserData.ParseMatchesInfo();
                    Player2Rank.text = "Rank : " + matchesInfo[2].ToString();

                    Player1UserName.text = "Name : " + OpponentData.user.DisplayName;
                    int[] opponentMatchesInfo = OpponentData.ParseMatchesInfo();
                    Player1Rank.text = "Rank : " + opponentMatchesInfo[2].ToString();
                }

                incrementPlayer1Coroutine = IncrementTimer(PlayerType.P1);
                incrementPlayer2Coroutine = IncrementTimer(PlayerType.P2);
                StopCoroutine(incrementPlayer1Coroutine);
                StopCoroutine(incrementPlayer2Coroutine);
                timer = maxTimeForTurn;
                StartCoroutine(incrementPlayer1Coroutine);
            }
        }


        //#region CameraResize
        //int width = Screen.width;
        //int height = Screen.height;
        //float screenRatio = Camera.main.aspect;
        //float bestRatio = 0.56f;

        //float cameraYValue = cameraInitialYValue;

        //if (screenRatio <= bestRatio)
        //{
        //  cameraYValue += (1f - screenRatio / bestRatio) / 2f;
        //}
        //else
        //{
        //  cameraYValue += (1f - bestRatio / screenRatio) / 2f;
        //}
        //cameraYValue = cameraYValue + (mapSize.x * 4);


        //Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, cameraYValue, Camera.main.transform.position.z);
        //#endregion
    }