Give bot skins

This commit is contained in:
Gray
2024-03-19 13:11:02 -04:00
parent 54b2383124
commit 5bfe3a6179
19 changed files with 388 additions and 227 deletions

View File

@@ -2,6 +2,7 @@
#include "FortGameModeAthena.h"
#include "OnlineReplStructs.h"
#include "FortAthenaAIBotController.h"
#include "BuildingContainer.h"
class BotPOI
@@ -21,7 +22,13 @@ public:
class PlayerBot
{
public:
AController* Controller = nullptr;
static inline UClass* PawnClass = nullptr;
static inline UClass* ControllerClass = nullptr;
AController* Controller = nullptr; // This can be 1. AFortAthenaAIBotController OR AFortPlayerControllerAthena
bool bIsAthenaController = false;
AFortPlayerPawnAthena* Pawn = nullptr;
AFortPlayerStateAthena* PlayerState = nullptr;
BotPOIEncounter currentBotEncounter;
int TotalPlayersEncountered;
std::vector<BotPOI> POIsTraveled;
@@ -38,64 +45,180 @@ public:
}
void Initialize(const FTransform& SpawnTransform)
static bool ShouldUseAIBotController()
{
auto GameState = Cast<AFortGameStateAthena>(GetWorld()->GetGameState());
auto GameMode = Cast<AFortGameModeAthena>(GetWorld()->GetGameMode());
return Fortnite_Version >= 11 && Engine_Version < 500;
}
static UClass* PawnClass = nullptr;
static UClass* ControllerClass = nullptr;
static void InitializeBotClasses()
{
static auto BlueprintGeneratedClassClass = FindObject<UClass>(L"/Script/Engine.BlueprintGeneratedClass");
bool bUsePhoebeClasses = false;
if (!PawnClass)
if (!ShouldUseAIBotController())
{
if (!bUsePhoebeClasses)
PawnClass = FindObject<UClass>(L"/Game/Athena/PlayerPawn_Athena.PlayerPawn_Athena_C");
else
PawnClass = FindObject<UClass>(L"/Game/Athena/AI/Phoebe/BP_PlayerPawn_Athena_Phoebe.BP_PlayerPawn_Athena_Phoebe_C");
PawnClass = FindObject<UClass>(L"/Game/Athena/PlayerPawn_Athena.PlayerPawn_Athena_C");
ControllerClass = AFortPlayerControllerAthena::StaticClass();
}
else
{
PawnClass = LoadObject<UClass>(L"/Game/Athena/AI/Phoebe/BP_PlayerPawn_Athena_Phoebe.BP_PlayerPawn_Athena_Phoebe_C", BlueprintGeneratedClassClass);
// ControllerClass = PawnClass->CreateDefaultObject()->GetAIControllerClass();
}
if (!ControllerClass)
{
if (!bUsePhoebeClasses)
ControllerClass = AFortPlayerControllerAthena::StaticClass();
else
ControllerClass = FindObject<UClass>(L"/Game/Athena/AI/Phoebe/BP_PhoebePlayerController.BP_PhoebePlayerController_C");
}
if (!ControllerClass || !PawnClass)
if (/* !ControllerClass
|| */ !PawnClass
)
{
LOG_ERROR(LogBots, "Failed to find a class for the bots!");
return;
}
}
static auto FortAthenaAIBotControllerClass = FindObject<UClass>(L"/Script/FortniteGame.FortAthenaAIBotController");
static bool IsReadyToSpawnBot()
{
return PawnClass;
}
Controller = GetWorld()->SpawnActor<AController>(ControllerClass);
AFortPlayerPawnAthena* Pawn = GetWorld()->SpawnActor<AFortPlayerPawnAthena>(PawnClass, SpawnTransform, CreateSpawnParameters(ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn));
AFortPlayerStateAthena* PlayerState = Cast<AFortPlayerStateAthena>(Controller->GetPlayerState());
void SetupInventory()
{
auto GameState = Cast<AFortGameStateAthena>(GetWorld()->GetGameState());
auto GameMode = Cast<AFortGameModeAthena>(GetWorld()->GetGameMode());
if (!Pawn || !PlayerState)
return;
bool bUseOverrideName = false;
FString NewName;
if (bUseOverrideName)
if (!ShouldUseAIBotController()) // TODO REWRITE
{
NewName = L"Override";
AFortInventory** Inventory = nullptr;
if (auto FortPlayerController = Cast<AFortPlayerController>(Controller))
{
Inventory = &FortPlayerController->GetWorldInventory();
}
else
{
if (auto FortAthenaAIBotController = Cast<AFortAthenaAIBotController>(Controller))
{
static auto InventoryOffset = Controller->GetOffset("Inventory");
Inventory = Controller->GetPtr<AFortInventory*>(InventoryOffset);
}
}
if (!Inventory)
{
LOG_ERROR(LogBots, "No inventory pointer!");
Pawn->K2_DestroyActor();
Controller->K2_DestroyActor();
return;
}
static auto FortInventoryClass = FindObject<UClass>(L"/Script/FortniteGame.FortInventory"); // AFortInventory::StaticClass()
*Inventory = GetWorld()->SpawnActor<AFortInventory>(FortInventoryClass, FTransform{}, CreateSpawnParameters(ESpawnActorCollisionHandlingMethod::AlwaysSpawn, false, Controller));
if (!*Inventory)
{
LOG_ERROR(LogBots, "Failed to spawn Inventory!");
Pawn->K2_DestroyActor();
Controller->K2_DestroyActor();
return;
}
(*Inventory)->GetInventoryType() = EFortInventoryType::World;
if (auto FortPlayerController = Cast<AFortPlayerController>(Controller))
{
static auto bHasInitializedWorldInventoryOffset = FortPlayerController->GetOffset("bHasInitializedWorldInventory");
FortPlayerController->Get<bool>(bHasInitializedWorldInventoryOffset) = true;
}
// if (false)
{
if (Inventory)
{
auto& StartingItems = GameMode->GetStartingItems();
for (int i = 0; i < StartingItems.Num(); ++i)
{
auto& StartingItem = StartingItems.at(i);
(*Inventory)->AddItem(StartingItem.GetItem(), nullptr, StartingItem.GetCount());
}
if (auto FortPlayerController = Cast<AFortPlayerController>(Controller))
{
UFortItem* PickaxeInstance = FortPlayerController->AddPickaxeToInventory();
if (PickaxeInstance)
{
FortPlayerController->ServerExecuteInventoryItemHook(FortPlayerController, PickaxeInstance->GetItemEntry()->GetItemGuid());
}
}
(*Inventory)->Update();
}
}
}
}
void Initialize(const FTransform& SpawnTransform, AActor* InSpawnLocator)
{
auto GameState = Cast<AFortGameStateAthena>(GetWorld()->GetGameState());
auto GameMode = Cast<AFortGameModeAthena>(GetWorld()->GetGameMode());
if (!IsReadyToSpawnBot())
{
LOG_ERROR(LogBots, "We are not prepared to spawn a bot!");
return;
}
if (!ShouldUseAIBotController())
{
Controller = GetWorld()->SpawnActor<AController>(ControllerClass);
Pawn = GetWorld()->SpawnActor<AFortPlayerPawnAthena>(PawnClass, SpawnTransform, CreateSpawnParameters(ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn));
PlayerState = Cast<AFortPlayerStateAthena>(Controller->GetPlayerState());
}
else
{
static int CurrentBotNum = 1;
auto BotNumWStr = std::to_wstring(CurrentBotNum++);
NewName = (L"RebootBot" + BotNumWStr).c_str();
Pawn = GameMode->GetServerBotManager()->GetCachedBotMutator()->SpawnBot(PawnClass, InSpawnLocator, SpawnTransform.Translation, SpawnTransform.Rotation.Rotator(), false);
if (Fortnite_Version < 17)
Controller = Cast<AFortAthenaAIBotController>(Pawn->GetController());
else
Controller = GetWorld()->SpawnActor<AFortAthenaAIBotController>(Pawn->GetAIControllerClass());
PlayerState = Cast<AFortPlayerStateAthena>(Controller->GetPlayerState());
}
if (auto PlayerController = Cast<APlayerController>(Controller))
PlayerController->ServerChangeName(NewName);
if (!Controller || !Pawn || !PlayerState)
{
LOG_ERROR(LogBots, "Failed to spawn controller, pawn or playerstate ({} {})!", bool(__int64(Controller)), bool(__int64(Pawn)), bool(__int64(Controller->GetPlayerState())));
return;
}
PlayerState->SetIsBot(true);
if (Controller->GetPawn() != Pawn)
{
Controller->Possess(Pawn);
}
static int CurrentBotNum = 1;
auto BotNumWStr = std::to_wstring(CurrentBotNum++);
FString NewName = (L"Jimmy" + BotNumWStr).c_str();
if (true ||
Fortnite_Version < 9
)
{
if (auto PlayerController = Cast<APlayerController>(Controller))
{
PlayerController->ServerChangeName(NewName);
}
}
else
{
GameMode->ChangeName(Controller, NewName, true);
}
PlayerState->OnRep_PlayerName();
@@ -108,111 +231,11 @@ public:
GameState->AddPlayerStateToGameMemberInfo(PlayerState);
PlayerState->SetIsBot(true);
/*
static auto FortRegisteredPlayerInfoClass = FindObject<UClass>("/Script/FortniteGame.FortRegisteredPlayerInfo");
static auto MyPlayerInfoOffset = PlayerController->GetOffset("MyPlayerInfo");
PlayerController->Get(MyPlayerInfoOffset) = UGameplayStatics::SpawnObject(FortRegisteredPlayerInfoClass, PlayerController);
if (!PlayerController->Get(MyPlayerInfoOffset))
{
LOG_ERROR(LogBots, "Failed to spawn PlayerInfo!");
Pawn->K2_DestroyActor();
PlayerController->K2_DestroyActor();
return nullptr;
}
auto& PlayerInfo = PlayerController->Get(MyPlayerInfoOffset);
static auto UniqueIdOffset = PlayerState->GetOffset("UniqueId");
static auto PlayerInfo_PlayerNameOffset = PlayerInfo->GetOffset("PlayerName");
static auto PlayerIDOffset = PlayerInfo->GetOffset("PlayerID");
PlayerInfo->GetPtr<FUniqueNetIdRepl>(PlayerIDOffset)->CopyFromAnotherUniqueId(PlayerState->GetPtr<FUniqueNetIdRepl>(UniqueIdOffset));
PlayerInfo->Get<FString>(PlayerInfo_PlayerNameOffset) = PlayerState->GetPlayerName();
*/
Controller->Possess(Pawn);
Pawn->SetHealth(100);
Pawn->SetMaxHealth(100);
AFortInventory** Inventory = nullptr;
if (auto FortPlayerController = Cast<AFortPlayerController>(Controller))
{
Inventory = &FortPlayerController->GetWorldInventory();
}
else
{
if (Controller->IsA(FortAthenaAIBotControllerClass))
{
static auto InventoryOffset = Controller->GetOffset("Inventory");
Inventory = Controller->GetPtr<AFortInventory*>(InventoryOffset);
}
}
if (!Inventory)
{
LOG_ERROR(LogBots, "No inventory pointer!");
Pawn->K2_DestroyActor();
Controller->K2_DestroyActor();
return;
}
FTransform InventorySpawnTransform{};
static auto FortInventoryClass = FindObject<UClass>(L"/Script/FortniteGame.FortInventory"); // AFortInventory::StaticClass()
*Inventory = GetWorld()->SpawnActor<AFortInventory>(FortInventoryClass, InventorySpawnTransform, CreateSpawnParameters(ESpawnActorCollisionHandlingMethod::AlwaysSpawn, false, Controller));
if (!*Inventory)
{
LOG_ERROR(LogBots, "Failed to spawn Inventory!");
Pawn->K2_DestroyActor();
Controller->K2_DestroyActor();
return;
}
(*Inventory)->GetInventoryType() = EFortInventoryType::World;
if (auto FortPlayerController = Cast<AFortPlayerController>(Controller))
{
static auto bHasInitializedWorldInventoryOffset = FortPlayerController->GetOffset("bHasInitializedWorldInventory");
FortPlayerController->Get<bool>(bHasInitializedWorldInventoryOffset) = true;
}
// if (false)
{
if (Inventory)
{
auto& StartingItems = GameMode->GetStartingItems();
for (int i = 0; i < StartingItems.Num(); ++i)
{
auto& StartingItem = StartingItems.at(i);
(*Inventory)->AddItem(StartingItem.GetItem(), nullptr, StartingItem.GetCount());
}
if (auto FortPlayerController = Cast<AFortPlayerController>(Controller))
{
UFortItem* PickaxeInstance = FortPlayerController->AddPickaxeToInventory();
if (PickaxeInstance)
{
FortPlayerController->ServerExecuteInventoryItemHook(FortPlayerController, PickaxeInstance->GetItemEntry()->GetItemGuid());
}
}
(*Inventory)->Update();
}
}
auto PlayerAbilitySet = GetPlayerAbilitySet();
auto AbilitySystemComponent = PlayerState->GetAbilitySystemComponent();
@@ -221,13 +244,13 @@ public:
PlayerAbilitySet->GiveToAbilitySystem(AbilitySystemComponent);
}
SetupInventory();
// PlayerController->GetCosmeticLoadout()->GetCharacter() = FindObject("/Game/Athena/Items/Cosmetics/Characters/CID_263_Athena_Commando_F_MadCommander.CID_263_Athena_Commando_F_MadCommander");
// Pawn->GetCosmeticLoadout()->GetCharacter() = PlayerController->GetCosmeticLoadout()->GetCharacter();
// PlayerController->ApplyCosmeticLoadout();
/*
auto AllHeroTypes = GetAllObjectsOfClass(FindObject<UClass>(L"/Script/FortniteGame.FortHeroType"));
std::vector<UFortItemDefinition*> AthenaHeroTypes;
@@ -249,38 +272,19 @@ public:
static auto HeroTypeOffset = PlayerState->GetOffset("HeroType");
if (HeroTypeOffset != -1)
{
PlayerState->Get(HeroTypeOffset) = HeroType;
static auto OwningGameInstanceOffset = GetWorld()->GetOffset("OwningGameInstance");
auto OwningGameInstance = GetWorld()->Get(OwningGameInstanceOffset);
static auto RegisteredPlayersOffset = OwningGameInstance->GetOffset("RegisteredPlayers");
auto& RegisteredPlayers = OwningGameInstance->Get<TArray<UObject*>>(RegisteredPlayersOffset);
static auto FortRegisteredPlayerInfoClass = FindObject<UClass>("/Script/FortniteGame.FortRegisteredPlayerInfo");
auto NewPlayerInfo = UGameplayStatics::SpawnObject(FortRegisteredPlayerInfoClass, Controller);
static auto PlayerIDOffset = NewPlayerInfo->GetOffset("PlayerID");
static auto UniqueIdOffset = PlayerState->GetOffset("UniqueId");
auto PlayerStateUniqueId = PlayerState->GetPtr<FUniqueNetIdRepl>(UniqueIdOffset);
NewPlayerInfo->GetPtr<FUniqueNetIdRepl>(PlayerIDOffset)->CopyFromAnotherUniqueId(PlayerStateUniqueId);
static auto MyPlayerInfoOffset = Controller->GetOffset("MyPlayerInfo");
Controller->Get(MyPlayerInfoOffset) = NewPlayerInfo;
RegisteredPlayers.Add(NewPlayerInfo);
}
ApplyHID(Pawn, HeroType, true);
*/
GameState->GetPlayersLeft()++;
GameState->OnRep_PlayersLeft();
if (auto FortPlayerControllerAthena = Cast<AFortPlayerControllerAthena>(Controller))
GameMode->GetAlivePlayers().Add(FortPlayerControllerAthena);
LOG_INFO(LogDev, "Finished spawning bot!")
}
};
@@ -288,10 +292,10 @@ static inline std::vector<PlayerBot> AllPlayerBotsToTick;
namespace Bots
{
static AController* SpawnBot(FTransform SpawnTransform)
static AController* SpawnBot(FTransform SpawnTransform, AActor* InSpawnLocator)
{
auto playerBot = PlayerBot();
playerBot.Initialize(SpawnTransform);
playerBot.Initialize(SpawnTransform, InSpawnLocator);
AllPlayerBotsToTick.push_back(playerBot);
return playerBot.Controller;
}
@@ -303,27 +307,36 @@ namespace Bots
auto GameState = Cast<AFortGameStateAthena>(GetWorld()->GetGameState());
auto GameMode = Cast<AFortGameModeAthena>(GetWorld()->GetGameMode());
static auto FortPlayerStartCreativeClass = FindObject<UClass>(L"/Script/FortniteGame.FortPlayerStartCreative");
static auto FortPlayerStartWarmupClass = FindObject<UClass>(L"/Script/FortniteGame.FortPlayerStartWarmup");
TArray<AActor*> PlayerStarts = UGameplayStatics::GetAllActorsOfClass(GetWorld(), Globals::bCreative ? FortPlayerStartCreativeClass : FortPlayerStartWarmupClass);
int ActorsNum = PlayerStarts.Num();
// Actors.Free();
if (ActorsNum == 0)
{
// LOG_INFO(LogDev, "No Actors!");
return;
}
// Find playerstart (scuffed)
for (int i = 0; i < AmountOfBots; ++i)
{
FTransform SpawnTransform{};
SpawnTransform.Translation = FVector(1, 1, 10000);
SpawnTransform.Rotation = FQuat();
SpawnTransform.Scale3D = FVector(1, 1, 1);
auto NewBot = SpawnBot(SpawnTransform);
auto PlayerStart = GameMode->K2_FindPlayerStart(NewBot, NewBot->GetPlayerState()->GetPlayerName()); // i dont think this works
AActor* PlayerStart = PlayerStarts.at(std::rand() % (PlayerStarts.size() - 1));
if (!PlayerStart)
{
LOG_ERROR(LogBots, "Failed to find PlayerStart for bot!");
NewBot->GetPawn()->K2_DestroyActor();
NewBot->K2_DestroyActor();
continue;
return;
}
NewBot->TeleportTo(PlayerStart->GetActorLocation(), FRotator());
auto NewBot = SpawnBot(PlayerStart->GetTransform(), PlayerStart);
NewBot->SetCanBeDamaged(Fortnite_Version < 7); // idk lol for spawn island
}
return;
}
static void Tick()
@@ -346,9 +359,14 @@ namespace Bots
auto CurrentPawn = CurrentPlayer->GetPawn();
if (CurrentPawn->IsActorBeingDestroyed())
continue;
auto CurrentPlayerState = Cast<AFortPlayerStateAthena>(CurrentPlayer->GetPlayerState());
if (!CurrentPlayerState || !CurrentPlayerState->IsBot())
if (!CurrentPlayerState
// || !CurrentPlayerState->IsBot()
)
continue;
if (GameState->GetGamePhase() == EAthenaGamePhase::Warmup)
@@ -362,7 +380,7 @@ namespace Bots
} */
}
if (CurrentPlayerState->IsInAircraft() && !CurrentPlayerState->HasThankedBusDriver())
if (PlayerBot.bIsAthenaController && CurrentPlayerState->IsInAircraft() && !CurrentPlayerState->HasThankedBusDriver())
{
static auto ServerThankBusDriverFn = FindObject<UFunction>(L"/Script/FortniteGame.FortPlayerControllerAthena.ServerThankBusDriver");
CurrentPlayer->ProcessEvent(ServerThankBusDriverFn);