A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
ApexReportingManager.cpp
Go to the documentation of this file.
1// Copyright(c) Pixo Group. All Rights Reserved.
2
4#include "Kismet/KismetMathLibrary.h"
10#include "GameFramework/GameModeBase.h"
12
21
23{
24 if (!ApexSubSystem)
25 {
26 return;
27 }
28
29 int32 CompletedStepsCount = 0;
30 int32 TotalNumberOfSteps = 0;
31
32 if (GetWorld()->GetAuthGameMode()->GetClass()->ImplementsInterface(UPixoCoreInterface::StaticClass()))
33 {
34 if (UStoryManager* StoryManagerRef = Cast<UStoryManager>(IPixoCoreInterface::Execute_GetManagerRef(GetWorld()->GetAuthGameMode(), UStoryManager::StaticClass())))
35 {
36 TArray<FPassedExperiences> PassedExperiences = StoryManagerRef->PassedExperiencesArray;
37 CompletedStepsCount = GetAmountOfCompletedSteps(PassedExperiences);
38 for (const auto & PassExpElement : PassedExperiences)
39 {
40 TotalNumberOfSteps += PassExpElement.PassedStepData.Num();
41 }
42 }
43 }
44
45 FSessionData NewSessionData;
46 NewSessionData.Complete = Completed;
47 NewSessionData.Success = Success;
48 NewSessionData.Score = CompletedStepsCount * ScoreFactor;
49 NewSessionData.ScoreScaled = UKismetMathLibrary::SafeDivide((float)CompletedStepsCount, (float)TotalNumberOfSteps);
50 NewSessionData.ScoreMin = 0.0f;
51 NewSessionData.ScoreMax = TotalNumberOfSteps * ScoreFactor;
52 NewSessionData.Duration = GetApexSessionDuration();
53 ApexSubSystem->CompleteSession(NewSessionData);
54}
55
56FXAPIStatement UApexReportingManager::GetStatementData_Implementation()
57{
58 FXAPIStatement StatementData;
59
60 StatementData.Verb.ID = FString("https://pixovr.com/xapi/verbs/completed");
61 StatementData.Target.ID = FString("https://pixovr.com/xapi/objects/") +
62 FString::FromInt(ApexSubSystem->LoadedModuleId) + FString("/") + CurrentStep.ToString();
63
64 return StatementData;
65}
66
67int32 UApexReportingManager::GetAmountOfCompletedSteps(const TArray<FPassedExperiences> PassedExperiences) const
68{
69 int32 Counter = 0;
70 for (const auto & PassExpElement : PassedExperiences)
71 {
72 for (const auto & Step : PassExpElement.PassedStepData)
73 {
74 if (Step.Step.Completed)
75 {
76 Counter++;
77 }
78 }
79 }
80 return Counter;
81}
82
84{
85 return (UKismetMathLibrary::Now() - ApexStartTime).GetTotalSeconds();
86}
87
89{
90 ApexSubSystem = GetWorld()->GetGameInstance()->GetSubsystem<UApexAPI>();
91 if (ApexSubSystem)
92 {
93 ApexStartTime = UKismetMathLibrary::Now();
95 {
96 const FXAPIExtension Extension;
97 ApexSubSystem->JoinSession(FString(FApp::GetProjectName()), Extension);
98 }
99 }
100 else
101 UE_LOG(LogTemp, Error, TEXT ("Apex SubSystem is not valid"));
102
104}
105
107{
108 CurrentStep = Event->CurrentStep.StepName;
109}
110
112{
113 CurrentStep = Event->CurrentStep.StepName;
114 const UStoryManager* StoryManager = Cast<UStoryManager>(IPixoCoreInterface::Execute_GetManagerRef(GetWorld()->GetAuthGameMode(), UStoryManager::StaticClass()));
115 LoadedStoryIndexesHistory.AddUnique(StoryManager->StoryIndex);
116}
117
119{
121 {
122 if (ApexSubSystem)
123 {
125 }
126 else
127 UE_LOG(LogTemp, Error, TEXT("ApexSubSystem reference is not valid!"));
128 }
129}
130
132{
134 {
135 CompleteApexSession(true, true);
136 }
137}
#define DEFINE_EVENT_HANDLER(TEventType)
Definition BaseManager.h:13
UCLASS(BlueprintType, Blueprintable)
Definition ApexAPI.h:68
bool SendSessionEvent(const FXAPIStatement &InStatement)
UFUNCTION(BlueprintCallable, Category = "Apex|API")
Definition ApexAPI.cpp:609
bool CompleteSession(const FSessionData &InSessionData)
UFUNCTION(BlueprintCallable, Category = "Apex|API")
Definition ApexAPI.cpp:500
bool JoinSession(FString InScenarioId, const FXAPIExtension &InContextExtension)
UFUNCTION(BlueprintCallable, Category = "Apex|API")
Definition ApexAPI.cpp:393
int LoadedModuleId
UPROPERTY(BlueprintReadOnly, Meta=(DisplayName="Module Id"))
Definition ApexAPI.h:107
UApexAPI * ApexSubSystem
UPROPERTY(BlueprintReadOnly)
FXAPIStatement GetStatementData()
This function can be implemented in blueprint to send custom FXAPIStatement.
void CompleteApexSession(bool Completed, bool Success)
This function is responsible for completing the session.
bool UseReportingEachStep
Indicates whether reporting should occur after completing each step.
int32 GetApexSessionDuration()
Retrieves the duration of the Apex session.
void OnInitialized()
UFUNCTION(BlueprintImplementableEvent)
FText CurrentStep
UPROPERTY(BlueprintReadOnly)
int32 ScoreFactor
The value by which the score reported in 'CompleteApexSession' will be multiplied.
TArray< int32 > LoadedStoryIndexesHistory
Array storing the history of loaded story indexes.
bool UseDefaultSessionEnd
Indicates whether the default session end should be used on UEndOfStoryReached.
int32 GetAmountOfCompletedSteps(const TArray< FPassedExperiences > PassedExperiences) const
bool UseDefaultSessionStart
Indicates whether the default session start should be used on UInitializationEvent.
void HandleEvent_Impl(class UBaseEvent *Event)
Event called when we complete last step.
Event called when we on init experience.
Event called when new step is loaded.
Event called when new story is loaded.
Event called when step is completed.
Manager that provides handling story-related operations and data.
int StoryIndex
UPROPERTY(BlueprintReadWrite, Replicated)
USTRUCT(BlueprintType)
Definition ApexTypes.h:184
bool Complete
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Apex|Session Data")
Definition ApexTypes.h:192
float Score
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Apex|Session Data")
Definition ApexTypes.h:204
float ScoreMin
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Apex|Session Data")
Definition ApexTypes.h:216
float ScoreScaled
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Apex|Session Data")
Definition ApexTypes.h:210
float ScoreMax
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Apex|Session Data")
Definition ApexTypes.h:222
int Duration
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Apex|Session Data")
Definition ApexTypes.h:228
bool Success
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Apex|Session Data")
Definition ApexTypes.h:198
FString ID
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Apex|XAPI|Activity")
Definition XAPITypes.h:572
USTRUCT(BlueprintType)
FXAPIVerb Verb
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Apex|XAPI|Statement")
Definition XAPITypes.h:1038
FXAPIActivity Target
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Apex|XAPI|Statement")
Definition XAPITypes.h:1045
USTRUCT(BlueprintType)
Definition XAPITypes.h:1156
FString ID
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Apex|XAPI|Verb")
Definition XAPITypes.h:510