@@ -384,6 +384,91 @@ namespace gameanalytics
384384 }
385385 }
386386
387+ void GameAnalyticsServer::addPlayerProgressionEventInternal (Player& player, EGAProgressionStatus progressionStatus, std::string const & progression01, std::string const & progression02, std::string const & progression03, int score, bool sendScore, std::string const & customFields)
388+ {
389+ try
390+ {
391+ if (!state::GAState::isEventSubmissionEnabled ())
392+ {
393+ return ;
394+ }
395+
396+ // Validate event params
397+ validators::ValidationResult validationResult;
398+ validators::GAValidator::validateProgressionEvent (progressionStatus, progression01, progression02, progression03, validationResult);
399+ if (!validationResult.result )
400+ {
401+ http::GAHTTPApi& httpInstance = http::GAHTTPApi::getInstance ();
402+ httpInstance.sendSdkErrorEvent (validationResult.category , validationResult.area , validationResult.action , validationResult.parameter , validationResult.reason , state::GAState::getGameKey (), state::GAState::getGameSecret ());
403+ return ;
404+ }
405+
406+ // Create empty eventData
407+ json eventDict = PlayerDatabase::getPlayerAnnotations (player);
408+
409+ // Progression identifier
410+ std::string progressionIdentifier = progression01;
411+
412+ if (!progression02.empty ())
413+ {
414+ progressionIdentifier += ' :' ;
415+ progressionIdentifier += progression02;
416+
417+ if (!progression03.empty ())
418+ {
419+ progressionIdentifier += ' :' ;
420+ progressionIdentifier += progression03;
421+ }
422+ }
423+
424+ const std::string statusString = events::GAEvents::progressionStatusString (progressionStatus);
425+
426+ eventDict[" category" ] = events::GAEvents::CategoryProgression;
427+ eventDict[" event_id" ] = statusString + ' :' + progressionIdentifier;
428+
429+ // Attempt
430+ int attempt_num = 0 ;
431+
432+ // Add score if specified and status is not start
433+ if (sendScore && progressionStatus != EGAProgressionStatus::Start)
434+ {
435+ eventDict[" score" ] = score;
436+ }
437+
438+ // Count attempts on each progression fail and persist
439+ if (progressionStatus == EGAProgressionStatus::Fail)
440+ {
441+ // Increment attempt number
442+ player.progressionTries .incrementTries (progressionIdentifier);
443+ }
444+
445+ // increment and add attempt_num on complete and delete persisted
446+ if (progressionStatus == EGAProgressionStatus::Complete)
447+ {
448+ // Increment attempt number
449+ player.progressionTries .incrementTries (progressionIdentifier);
450+
451+ // Add to event
452+ attempt_num = player.progressionTries .getTries (progressionIdentifier);
453+ eventDict[" attempt_num" ] = attempt_num;
454+
455+ // Clear
456+ state::GAState::clearProgressionTries (progressionIdentifier);
457+ }
458+
459+ // Log
460+ logging::GALogger::i (" Add PROGRESSION event: {status:%s, progression01:%s, progression02:%s, progression03:%s, score:%d, attempt:%d, fields:%s}" ,
461+ statusString.c_str (), progression01.c_str (), progression02.c_str (), progression03.c_str (), score, attempt_num, customFields.c_str ());
462+
463+ // Send to store
464+ events::GAEvents::getInstance ().addEventToStore (eventDict);
465+ }
466+ catch (std::exception& e)
467+ {
468+ logging::GALogger::e (" addProgressionEvent - Exception thrown: %s" , e.what ());
469+ }
470+ }
471+
387472 void GameAnalyticsServer::addPlayerDesignEvent (Player& player, std::string const & eventId, double value, std::string const & customFields)
388473 {
389474 threading::GAThreading::performTaskOnGAThread (
@@ -424,6 +509,16 @@ namespace gameanalytics
424509 );
425510 }
426511
512+ void GameAnalyticsServer::addPlayerProgressionEvent (Player& player, EGAProgressionStatus progressionStatus, std::string const & progression01, std::string const & progression02, std::string const & progression03, int score, bool sendScore, std::string const & customFields)
513+ {
514+ threading::GAThreading::performTaskOnGAThread (
515+ [this , &player, progressionStatus, progression01, progression02, progression03, sendScore, score, customFields]()
516+ {
517+ addPlayerProgressionEventInternal (player, progressionStatus, progression01, progression02, progression03, sendScore, score, customFields);
518+ }
519+ );
520+ }
521+
427522 void GameAnalyticsServer::addPlayerDesignEvent (std::string const & userId, std::string const & eventId, double value, std::string const & customFields)
428523 {
429524 if (isExistingPlayer (userId))
@@ -471,4 +566,16 @@ namespace gameanalytics
471566 logging::GALogger::w (" Invalid user id: %s" , userId.c_str ());
472567 }
473568 }
569+
570+ void GameAnalyticsServer::addPlayerProgressionEvent (std::string const & userId, EGAProgressionStatus progressionStatus, std::string const & progression01, std::string const & progression02, std::string const & progression03, int score, bool sendScore, std::string const & customFields)
571+ {
572+ if (isExistingPlayer (userId))
573+ {
574+ return addPlayerProgressionEvent (getPlayer (userId), progressionStatus, progression01, progression02, progression03, sendScore, score, customFields);
575+ }
576+ else
577+ {
578+ logging::GALogger::w (" Invalid user id: %s" , userId.c_str ());
579+ }
580+ }
474581}
0 commit comments