Example #1
0
    private IEnumerator showRaceResults(TubeRaceEvents.EndGameResultsReceived results)
    {
        FinishScreen.SetActive(value: true);
        DefaultScreen.SetActive(value: false);
        List <long> sortedSessionIds = new List <long>(results.PlayerIdToPlacement.Keys);

        sortedSessionIds.Sort((long o1, long o2) => results.PlayerIdToPlacement[o1].CompareTo(results.PlayerIdToPlacement[o2]));
        for (int i = 0; i < LeaderBoardItems.Length; i++)
        {
            if (i < sortedSessionIds.Count)
            {
                PartyGameSessionMessages.TubeRacePlayerResult resultBySessionId = getResultBySessionId(results.PlayerResults, sortedSessionIds[i]);
                if (resultBySessionId != null)
                {
                    LeaderBoardItems[i].SetData(sortedSessionIds[i], (int)resultBySessionId.OverallScore);
                    LeaderBoardItems[i].gameObject.SetActive(value: true);
                }
                else
                {
                    LeaderBoardItems[i].gameObject.SetActive(value: false);
                }
            }
            else
            {
                LeaderBoardItems[i].gameObject.SetActive(value: false);
            }
        }
        yield return(new WaitForSeconds(TimeToShowFinishScreenInSeconds));

        showDefaultScreen();
    }
 private void handleTubeRacePlayerResult(string data)
 {
     PartyGameSessionMessages.TubeRacePlayerResult tubeRacePlayerResult = null;
     try
     {
         tubeRacePlayerResult = jsonService.Deserialize <PartyGameSessionMessages.TubeRacePlayerResult>(data);
     }
     catch (Exception)
     {
     }
     if (tubeRacePlayerResult != null)
     {
         playerResults.Add(tubeRacePlayerResult);
         if (tubeRacePlayerResult.PlayerId == Service.Get <CPDataEntityCollection>().LocalPlayerSessionId)
         {
             int num = (int)Math.Round(tubeRacePlayerResult.OverallScore);
             Service.Get <ICPSwrveService>().Action("tube_race_finish", num.ToString());
             showEndGameScreen();
         }
         else
         {
             eventDispatcher.DispatchEvent(new TubeRaceEvents.PlayerResultReceived(tubeRacePlayerResult));
         }
     }
 }
    private void setLocalPlayerData(PartyGameSessionMessages.TubeRacePlayerResult data)
    {
        DateTime dateTime = DateTimeUtils.DateTimeFromUnixTime(data.CompletionTimeInMilliseconds);

        TimeText.text     = dateTime.ToString("mm:ss:ff");
        ModifierText.text = Math.Abs(data.ScoreModifier).ToString();
        ModifierSpriteSelector.SelectSprite((!(data.ScoreModifier >= 0f)) ? 1 : 0);
        ModifierSignText.text = ((data.ScoreModifier >= 0f) ? "+" : "-");
    }
Example #4
0
 private PartyGameSessionMessages.TubeRacePlayerResult getResultBySessionId(List <PartyGameSessionMessages.TubeRacePlayerResult> results, long sessionId)
 {
     PartyGameSessionMessages.TubeRacePlayerResult result = null;
     for (int i = 0; i < results.Count; i++)
     {
         if (results[i].PlayerId == sessionId)
         {
             result = results[i];
             break;
         }
     }
     return(result);
 }
    public void SetData(PartyGameSessionMessages.TubeRacePlayerResult data, PartyGameDefinition partyGameDefinition)
    {
        skinForDefinition(partyGameDefinition);
        ScoreText.text = data.OverallScore.ToString();
        CPDataEntityCollection cPDataEntityCollection = Service.Get <CPDataEntityCollection>();
        DataEntityHandle       dataEntityHandle       = cPDataEntityCollection.FindEntity <SessionIdData, long>(data.PlayerId);
        DisplayNameData        component = default(DisplayNameData);

        if (!dataEntityHandle.IsNull && cPDataEntityCollection.TryGetComponent(dataEntityHandle, out component))
        {
            NameText.text = component.DisplayName;
        }
        if (data.PlayerId == cPDataEntityCollection.LocalPlayerSessionId)
        {
            setLocalPlayerData(data);
        }
    }
            public void EndSession(long userSessionId)
            {
                timer.Stop();
                JsonService jsonService = Service.Get <JsonService>();

                PartyGameSessionMessages.TubeRacePlayerResult tubeRacePlayerResult = new PartyGameSessionMessages.TubeRacePlayerResult();
                tubeRacePlayerResult.CompletionTimeInMilliseconds = timer.ElapsedMilliseconds;
                tubeRacePlayerResult.OverallScore  = raceDefinition.StartingPoints - timer.ElapsedMilliseconds * raceDefinition.PointsDeductedPerSecond / 1000 + userScores[userSessionId];
                tubeRacePlayerResult.PlayerId      = userSessionId;
                tubeRacePlayerResult.ScoreModifier = userScores[userSessionId];
                PartyGameSessionMessages.TubeRacePlayerResult objectToSerialize = tubeRacePlayerResult;
                PartyGameMessageEvent partyGameMessageEvent = default(PartyGameMessageEvent);

                partyGameMessageEvent.sessionId = sessionId;
                partyGameMessageEvent.type      = 13;
                partyGameMessageEvent.message   = jsonService.Serialize(objectToSerialize);
                PartyGameMessageEvent partyGameMessageEvent2 = partyGameMessageEvent;

                processEvent(GameServerEvent.PARTY_GAME_MESSAGE, partyGameMessageEvent2);
                if (Service.Get <IGameData>().Get <Dictionary <int, PartyGameDefinition> >().TryGetValue(cpItem.gameTemplateId, out var value))
                {
                    foreach (PartyGameDefinition.PartyGameReward reward in value.Rewards)
                    {
                        if (reward.Placement == PartyGameEndPlacement.FIRST)
                        {
                            Dictionary <string, RewardJsonReader> dictionary = new Dictionary <string, RewardJsonReader>();
                            dictionary.Add(userSessionId.ToString(), jsonService.Deserialize <RewardJsonReader>(jsonService.Serialize(RewardJsonWritter.FromReward(reward.Reward.ToReward()))));
                            SignedResponse <RewardedUserCollectionJsonHelper> signedResponse = new SignedResponse <RewardedUserCollectionJsonHelper>();
                            signedResponse.Data = new RewardedUserCollectionJsonHelper
                            {
                                rewards  = dictionary,
                                source   = RewardSource.MINI_GAME,
                                sourceId = sessionId.ToString()
                            };
                            SignedResponse <RewardedUserCollectionJsonHelper> arg = signedResponse;
                            processEvent(GameServerEvent.RECEIVED_REWARDS_DELAYED, arg);
                            break;
                        }
                    }
                }
                CoroutineRunner.StartPersistent(finishEndSession(), this, "finishEndSession");
            }
Example #7
0
 public PlayerResultReceived(PartyGameSessionMessages.TubeRacePlayerResult playerResult)
 {
     PlayerResult = playerResult;
 }