Пример #1
0
        // read the position message. This is may be part of a long message queue so it can be a few seconds before it triggers.
        // Because of this, we use a delayed message event - when the message reaches the top of the queue it uses the latest
        // position, rather than the position when it was inserted into the queue.

        // For RF2 use a non-zero delay here because the position data isn't always updated in a timely fashion at the start of a new lap.
        private void playCurrentPositionMessage(PearlsOfWisdom.PearlType pearlType, float pearlLikelihood)
        {
            int delaySeconds = CrewChief.gameDefinition.gameEnum == GameEnum.RF2_64BIT ||
                               CrewChief.gameDefinition.gameEnum == GameEnum.ASSETTO_32BIT ||
                               CrewChief.gameDefinition.gameEnum == GameEnum.ASSETTO_64BIT ? 1 : 0;
            DelayedMessageEvent delayedMessageEvent = new DelayedMessageEvent("getPositionMessages", new Object[] { currentPosition }, this);

            audioPlayer.playMessage(new QueuedMessage("position", 10, delayedMessageEvent: delayedMessageEvent, secondsDelay: delaySeconds, priority: 10), pearlType, pearlLikelihood);
        }
Пример #2
0
        protected override void triggerInternal(GameStateData previousGameState, GameStateData currentGameState)
        {
            if (opponentKeyForCarThatJustPassedUs == null && opponentKeyForCarWeJustPassed == null)
            {
                checkForNewOvertakes(currentGameState, previousGameState);
            }
            checkCompletedOvertake(currentGameState);
            currentPosition = currentGameState.SessionData.Position;
            sessionType     = currentGameState.SessionData.SessionType;
            isLast          = currentGameState.isLast();
            if (previousPosition == 0)
            {
                previousPosition = currentPosition;
            }
            if (currentGameState.SessionData.SessionPhase == SessionPhase.Green || currentGameState.SessionData.SessionPhase == SessionPhase.FullCourseYellow)
            {
                if (currentGameState.SessionData.SessionType == SessionType.Race &&
                    enableRaceStartMessages && !playedRaceStartMessage &&
                    currentGameState.SessionData.CompletedLaps == 0 && currentGameState.SessionData.LapTimeCurrent > startMessageTime && !currentGameState.FlagData.isLocalYellow)
                {
                    playedRaceStartMessage = true;
                    Console.WriteLine("Race start message... isLast = " + isLast +
                                      " session start pos = " + currentGameState.SessionData.SessionStartPosition + " current pos = " + currentGameState.SessionData.Position);
                    if (currentGameState.SessionData.SessionStartPosition > 0)
                    {
                        if (currentGameState.SessionData.SessionStartPosition + 1 < currentGameState.SessionData.Position)
                        {
                            audioPlayer.playMessage(new QueuedMessage(folderBadStart, 0, this));
                        }
                        else if (!isLast && (currentGameState.SessionData.Position == 1 || currentGameState.SessionData.SessionStartPosition > currentGameState.SessionData.Position + 2) &&
                                 !currentGameState.PenaltiesData.HasDriveThrough && !currentGameState.PenaltiesData.HasStopAndGo)
                        {
                            audioPlayer.playMessage(new QueuedMessage(folderGoodStart, 0, this));
                        }
                        else if (currentGameState.SessionData.SessionStartPosition + 5 < currentGameState.SessionData.Position)
                        {
                            audioPlayer.playMessage(new QueuedMessage(folderTerribleStart, 0, this));
                        }
                        else if (!isLast && rand.NextDouble() > 0.6 &&
                                 !currentGameState.PenaltiesData.HasDriveThrough && !currentGameState.PenaltiesData.HasStopAndGo)
                        {
                            // only play the OK start message sometimes
                            audioPlayer.playMessage(new QueuedMessage(folderOKStart, 0, this));
                        }
                    }
                }
            }
            if (enablePositionMessages && currentGameState.SessionData.IsNewLap)
            {
                if (currentGameState.SessionData.CompletedLaps > 0)
                {
                    playedRaceStartMessage = true;
                }
                if (isLast)
                {
                    numberOfLapsInLastPlace++;
                }
                else
                {
                    numberOfLapsInLastPlace = 0;
                }
                if (previousPosition == 0 && currentGameState.SessionData.Position > 0)
                {
                    previousPosition = currentGameState.SessionData.Position;
                }
                else
                {
                    if (currentGameState.SessionData.CompletedLaps > lapNumberAtLastMessage + 3 ||
                        previousPosition != currentGameState.SessionData.Position)
                    {
                        PearlsOfWisdom.PearlType pearlType = PearlsOfWisdom.PearlType.NONE;
                        float pearlLikelihood = 0.2f;
                        if (currentGameState.SessionData.SessionType == SessionType.Race && currentGameState.SessionData.Position > 0)
                        {
                            if (!isLast && (previousPosition > currentGameState.SessionData.Position + 5 ||
                                            (previousPosition > currentGameState.SessionData.Position && currentGameState.SessionData.Position <= 5)))
                            {
                                pearlType       = PearlsOfWisdom.PearlType.GOOD;
                                pearlLikelihood = 0.8f;
                            }
                            else if (!isLast && previousPosition < currentGameState.SessionData.Position &&
                                     currentGameState.SessionData.Position > 5 && !previousGameState.PitData.OnOutLap &&
                                     !currentGameState.PitData.OnOutLap && !currentGameState.PitData.InPitlane)
                            {
                                // don't play bad-pearl if the lap just completed was an out lap or are in the pit

                                // note that we don't play a pearl for being last - there's a special set of
                                // insults reserved for this
                                pearlType       = PearlsOfWisdom.PearlType.BAD;
                                pearlLikelihood = 0.5f;
                            }
                            else if (!isLast)
                            {
                                pearlType = PearlsOfWisdom.PearlType.NEUTRAL;
                            }
                        }
                        // read the position message. This is may be part of a long message queue so it can be a few seconds before it triggers.
                        // Because of this, we use a delayed message event - when the message reaches the top of the queue it uses the latest
                        // position, rather than the position when it was inserted into the queue.

                        // For RF2 use a non-zero delay here because the position data isn't always updated in a timely fashion at the start of a new lap.
                        int delaySeconds = CrewChief.gameDefinition.gameEnum == GameEnum.RF2_64BIT ||
                                           CrewChief.gameDefinition.gameEnum == GameEnum.ASSETTO_32BIT ||
                                           CrewChief.gameDefinition.gameEnum == GameEnum.ASSETTO_64BIT ? 1 : 0;
                        DelayedMessageEvent delayedMessageEvent = new DelayedMessageEvent("getPositionMessages", new Object[] {
                            currentPosition
                        }, this);
                        audioPlayer.playMessage(new QueuedMessage("position", delayedMessageEvent, delaySeconds, null), pearlType, pearlLikelihood);
                        lapNumberAtLastMessage = currentGameState.SessionData.CompletedLaps;
                    }
                }
            }
        }