4#include "Kismet/KismetMathLibrary.h"
10#include "GameFramework/GameModeBase.h"
29 int32 CompletedStepsCount = 0;
30 int32 TotalNumberOfSteps = 0;
32 if (GetWorld()->GetAuthGameMode()->GetClass()->ImplementsInterface(UPixoCoreInterface::StaticClass()))
34 if (
UStoryManager* StoryManagerRef = Cast<UStoryManager>(IPixoCoreInterface::Execute_GetManagerRef(GetWorld()->GetAuthGameMode(), UStoryManager::StaticClass())))
36 TArray<FPassedExperiences> PassedExperiences = StoryManagerRef->PassedExperiencesArray;
38 for (
const auto & PassExpElement : PassedExperiences)
40 TotalNumberOfSteps += PassExpElement.PassedStepData.Num();
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;
63 FXAPIExtension Extension;
64 TArray<FString> ExtensionParameterKeys;
65 ExtensionParameters.GetKeys(ExtensionParameterKeys);
66 for (
auto ExtensionKey : ExtensionParameterKeys)
68 FString Key = ExtensionKey;
69 FString Value = ExtensionParameters.FindRef(ExtensionKey);
70 Extension.AddString(Key, Value);
73 FSessionData NewSessionData;
74 NewSessionData.Complete =
false;
75 NewSessionData.Success =
false;
76 NewSessionData.Score = Score;
77 NewSessionData.ScoreScaled = MaxScore > 0.f? Score/MaxScore : 0.f;
78 NewSessionData.ScoreMin = 0.0f;
79 NewSessionData.ScoreMax = MaxScore;
81 NewSessionData.AdditionalResultData = Extension;
86void UApexReportingManager::OnEndStoryReached_Implementation()
90void UApexReportingManager::OnInitialized_Implementation()
94FXAPIStatement UApexReportingManager::GetStatementData_Implementation()
96 FXAPIStatement StatementData;
98 StatementData.Verb.ID = FString(
"https://pixovr.com/xapi/verbs/completed");
99 StatementData.Target.ID = FString(
"https://pixovr.com/xapi/objects/") +
102 return StatementData;
108 for (
const auto & PassExpElement : PassedExperiences)
110 for (
const auto & Step : PassExpElement.PassedStepData)
112 if (Step.Step.Completed)
123 return (UKismetMathLibrary::Now() -
ApexStartTime).GetTotalSeconds();
128 ApexSubSystem = GetWorld()->GetGameInstance()->GetSubsystem<UApexAPI>();
134 const FXAPIExtension Extension;
135 ApexSubSystem->JoinSession(FString(FApp::GetProjectName()), Extension);
139 UE_LOG(LogTemp, Error, TEXT (
"Apex SubSystem is not valid"));
152 const UStoryManager* StoryManager = Cast<UStoryManager>(IPixoCoreInterface::Execute_GetManagerRef(GetWorld()->GetAuthGameMode(), UStoryManager::StaticClass()));
165 UE_LOG(LogTemp, Error, TEXT(
"ApexSubSystem reference is not valid!"));
#define DEFINE_EVENT_HANDLER(TEventType)
UApexAPI * ApexSubSystem
UPROPERTY(BlueprintReadOnly)
FXAPIStatement GetStatementData()
This function can be implemented in blueprint to send custom FXAPIStatement.
virtual 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(BlueprintNativeEvent)
FText CurrentStep
UPROPERTY(BlueprintReadOnly)
int32 ScoreFactor
The value by which the score reported in 'CompleteApexSession' will be multiplied.
void OnEndStoryReached()
UFUNCTION(BlueprintNativeEvent)
virtual void EarlyExitSession(float Score, float MaxScore, TMap< FString, FString > ExtensionParameters)
This function is responsible for quitting the session without completing it.
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)
FText StepName
UPROPERTY(BlueprintReadWrite, EditAnywhere)