|
3 | 3 | #include "EnvQueryTest_Faction.h"
|
4 | 4 | #include "EnvironmentQuery/Items/EnvQueryItemType_ActorBase.h"
|
5 | 5 |
|
| 6 | +#include "FactionsLibrary.h" |
| 7 | + |
6 | 8 | #define LOCTEXT_NAMESPACE "UEnvQueryTest_Faction"
|
7 | 9 |
|
8 | 10 |
|
9 |
| -UEnvQueryTest_Faction::UEnvQueryTest_Faction(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) |
| 11 | +UEnvQueryTest_Faction::UEnvQueryTest_Faction() |
| 12 | + : Super() |
| 13 | + , bCompareTowardsContextActor(false) |
10 | 14 | {
|
11 |
| - TestPurpose = EEnvTestPurpose::Filter; |
12 |
| - |
13 |
| - Cost = EEnvTestCost::Low; |
14 |
| - SetWorkOnFloatValues(false); |
15 |
| - ValidItemType = UEnvQueryItemType_ActorBase::StaticClass(); |
| 15 | + TestPurpose = EEnvTestPurpose::Filter; |
16 | 16 |
|
| 17 | + Cost = EEnvTestCost::Low; |
| 18 | + SetWorkOnFloatValues(false); |
| 19 | + ValidItemType = UEnvQueryItemType_ActorBase::StaticClass(); |
17 | 20 | }
|
18 | 21 |
|
19 | 22 | void UEnvQueryTest_Faction::RunTest(FEnvQueryInstance& QueryInstance) const
|
20 | 23 | {
|
| 24 | + UObject* Owner = QueryInstance.Owner.Get(); |
| 25 | + if (!Owner) |
| 26 | + return; |
| 27 | + |
| 28 | + BoolValue.BindData(Owner, QueryInstance.QueryID); |
| 29 | + const bool bNegate = BoolValue.GetValue(); |
| 30 | + |
| 31 | + FFaction TargetFaction{ Faction }; |
| 32 | + if (bCompareTowardsContextActor) |
| 33 | + { |
| 34 | + // don't support context Location here, it doesn't make any sense |
| 35 | + TArray<AActor*> ContextItems; |
| 36 | + if (!QueryInstance.PrepareContext(Context, ContextItems)) |
| 37 | + return; |
| 38 | + |
| 39 | + if (ContextItems.Num() <= 0) |
| 40 | + TargetFaction = FFaction::NoFaction; |
| 41 | + else |
| 42 | + TargetFaction = UFactionsLibrary::GetFaction(ContextItems[0]); |
| 43 | + } |
| 44 | + |
| 45 | + switch (Mode) |
| 46 | + { |
| 47 | + case EFactionTestMode::IsTheSame: |
| 48 | + for (FEnvQueryInstance::ItemIterator It(this, QueryInstance); It; ++It) |
| 49 | + { |
| 50 | + AActor* PointActor = GetItemActor(QueryInstance, It.GetIndex()); |
| 51 | + |
| 52 | + const bool bIsTheSame = UFactionsLibrary::GetFaction(PointActor) == TargetFaction; |
| 53 | + It.SetScore(TestPurpose, FilterType, bIsTheSame, bNegate); |
| 54 | + } |
| 55 | + break; |
| 56 | + |
| 57 | + case EFactionTestMode::IsFriendly: |
| 58 | + for (FEnvQueryInstance::ItemIterator It(this, QueryInstance); It; ++It) |
| 59 | + { |
| 60 | + AActor* PointActor = GetItemActor(QueryInstance, It.GetIndex()); |
| 61 | + |
| 62 | + const bool bIsFriendly = UFactionsLibrary::GetFaction(PointActor).IsFriendlyTowards(TargetFaction); |
| 63 | + It.SetScore(TestPurpose, FilterType, bIsFriendly, bNegate); |
| 64 | + } |
| 65 | + break; |
| 66 | + |
| 67 | + case EFactionTestMode::IsNeutral: |
| 68 | + for (FEnvQueryInstance::ItemIterator It(this, QueryInstance); It; ++It) |
| 69 | + { |
| 70 | + AActor* PointActor = GetItemActor(QueryInstance, It.GetIndex()); |
| 71 | + |
| 72 | + const bool bIsNeutral = UFactionsLibrary::GetFaction(PointActor).IsNeutralTowards(TargetFaction); |
| 73 | + It.SetScore(TestPurpose, FilterType, bIsNeutral, bNegate); |
| 74 | + } |
| 75 | + break; |
| 76 | + |
| 77 | + case EFactionTestMode::IsHostile: |
| 78 | + for (FEnvQueryInstance::ItemIterator It(this, QueryInstance); It; ++It) |
| 79 | + { |
| 80 | + AActor* PointActor = GetItemActor(QueryInstance, It.GetIndex()); |
| 81 | + |
| 82 | + const bool bIsHostile = UFactionsLibrary::GetFaction(PointActor).IsHostileTowards(TargetFaction); |
| 83 | + It.SetScore(TestPurpose, FilterType, bIsHostile, bNegate); |
| 84 | + } |
| 85 | + break; |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +FText UEnvQueryTest_Faction::GetDescriptionTitle() const |
| 90 | +{ |
| 91 | + const bool bNegate = BoolValue.GetValue(); |
| 92 | + FString ModeDesc; |
| 93 | + |
| 94 | + if (Mode == EFactionTestMode::IsTheSame) |
| 95 | + { |
| 96 | + ModeDesc = bNegate? TEXT("Doesn't equal ") : TEXT("Equals "); |
| 97 | + } |
| 98 | + else |
| 99 | + { |
| 100 | + ModeDesc = TEXT(""); |
| 101 | + if (bNegate) |
| 102 | + ModeDesc += TEXT("Not "); |
| 103 | + |
| 104 | + switch (Mode) |
| 105 | + { |
| 106 | + case EFactionTestMode::IsFriendly: |
| 107 | + ModeDesc += TEXT("Friendly towards "); |
| 108 | + break; |
| 109 | + case EFactionTestMode::IsNeutral: |
| 110 | + ModeDesc += TEXT("Neutral towards "); |
| 111 | + break; |
| 112 | + case EFactionTestMode::IsHostile: |
| 113 | + ModeDesc += TEXT("Hostile towards "); |
| 114 | + break; |
| 115 | + default: |
| 116 | + break; |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + if (bCompareTowardsContextActor) |
| 121 | + { |
| 122 | + ModeDesc += *UEnvQueryTypes::DescribeContext(Context).ToString(); |
| 123 | + ModeDesc += TEXT("'s faction"); |
| 124 | + } |
| 125 | + else |
| 126 | + { |
| 127 | + ModeDesc += Faction.GetDisplayName(); |
| 128 | + } |
| 129 | + |
| 130 | + return FText::FromString(*ModeDesc); |
21 | 131 | }
|
22 | 132 |
|
23 | 133 | FText UEnvQueryTest_Faction::GetDescriptionDetails() const
|
24 | 134 | {
|
25 |
| - return Super::GetDescriptionDetails(); |
| 135 | + return FText::Format(LOCTEXT("DescriptionFormat", "{0} test: {1}"), Super::GetDescriptionTitle(), DescribeFloatTestParams()); |
26 | 136 | }
|
27 | 137 |
|
28 | 138 | #undef LOCTEXT_NAMESPACE
|
0 commit comments