Merge remote-tracking branch 'upstream/main' into more-cdclient-cleanup

This commit is contained in:
David Markowitz
2023-05-13 16:16:58 -07:00
319 changed files with 4872 additions and 4158 deletions

View File

@@ -16,6 +16,7 @@
#include "eMissionTaskType.h"
#include "eReplicaComponentType.h"
#include "RenderComponent.h"
#include "eGameActivity.h"
void SGCannon::OnStartup(Entity* self) {
Game::logger->Log("SGCannon", "OnStartup");
@@ -103,7 +104,7 @@ void SGCannon::OnActivityStateChangeRequest(Entity* self, LWOOBJID senderID, int
if (characterComponent != nullptr) {
characterComponent->SetIsRacing(true);
characterComponent->SetCurrentActivity(2);
characterComponent->SetCurrentActivity(eGameActivity::SHOOTING_GALLERY);
auto possessor = player->GetComponent<PossessorComponent>();
if (possessor) {
possessor->SetPossessable(self->GetObjectID());
@@ -135,38 +136,26 @@ void SGCannon::OnActivityStateChangeRequest(Entity* self, LWOOBJID senderID, int
}
}
void SGCannon::OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier,
const std::u16string& userData) {
void SGCannon::OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) {
auto* player = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(PlayerIDVariable));
if (player != nullptr) {
if (button == 1 && identifier == u"Shooting_Gallery_Stop") {
if (!player) return;
if (identifier == u"Scoreboardinfo") {
GameMessages::SendDisplayMessageBox(player->GetObjectID(), true,
dZoneManager::Instance()->GetZoneControlObject()->GetObjectID(),
u"Shooting_Gallery_Retry", 2, u"Retry?",
u"", player->GetSystemAddress());
} else {
if ((button == 1 && (identifier == u"Shooting_Gallery_Retry" || identifier == u"RePlay")) || identifier == u"SG1" || button == 0) {
if (IsPlayerInActivity(self, player->GetObjectID())) return;
self->SetNetworkVar<bool>(ClearVariable, true);
StartGame(self);
} else if (button == 0 && ((identifier == u"Shooting_Gallery_Retry" || identifier == u"RePlay"))){
RemovePlayer(player->GetObjectID());
UpdatePlayer(self, player->GetObjectID(), true);
} else if (button == 1 && identifier == u"Shooting_Gallery_Exit") {
UpdatePlayer(self, player->GetObjectID(), true);
RemovePlayer(player->GetObjectID());
StopGame(self, true);
return;
}
if (identifier == u"Scoreboardinfo") {
GameMessages::SendDisplayMessageBox(player->GetObjectID(), true,
dZoneManager::Instance()->GetZoneControlObject()->GetObjectID(),
u"Shooting_Gallery_Retry?", 2, u"Retry?",
u"", player->GetSystemAddress());
} else {
if ((button == 1 && (identifier == u"Shooting_Gallery_Retry" || identifier == u"RePlay"))
|| identifier == u"SG1" || button == 0) {
if (identifier == u"RePlay") {
static_cast<Player*>(player)->SendToZone(1300);
return;
}
self->SetNetworkVar<bool>(ClearVariable, true);
StartGame(self);
} else if (button == 1 && identifier == u"Shooting_Gallery_Exit") {
UpdatePlayer(self, player->GetObjectID(), true);
RemovePlayer(player->GetObjectID());
}
}
}
}
@@ -267,13 +256,17 @@ void SGCannon::OnActivityTimerDone(Entity* self, const std::string& name) {
if (self->GetVar<bool>(GameStartedVariable)) {
const auto spawnNumber = (uint32_t)std::stoi(name.substr(7));
const auto& activeSpawns = self->GetVar<std::vector<SGEnemy>>(ActiveSpawnsVariable);
if (activeSpawns.size() < spawnNumber) {
Game::logger->Log("SGCannon", "Trying to spawn %i when spawns size is only %i", spawnNumber, activeSpawns.size());
return;
}
const auto& toSpawn = activeSpawns.at(spawnNumber);
const auto pathIndex = GeneralUtils::GenerateRandomNumber<float_t>(0, toSpawn.spawnPaths.size() - 1);
const auto* path = dZoneManager::Instance()->GetZone()->GetPath(
toSpawn.spawnPaths.at(pathIndex)
);
const auto* path = dZoneManager::Instance()->GetZone()->GetPath(toSpawn.spawnPaths.at(pathIndex));
if (!path) {
Game::logger->Log("SGCannon", "Path %s at index %i is null", toSpawn.spawnPaths.at(pathIndex).c_str(), pathIndex);
return;
}
auto info = EntityInfo{};
info.lot = toSpawn.lot;
@@ -294,32 +287,30 @@ void SGCannon::OnActivityTimerDone(Entity* self, const std::string& name) {
auto* enemy = EntityManager::Instance()->CreateEntity(info, nullptr, self);
EntityManager::Instance()->ConstructEntity(enemy);
if (true) {
auto* movementAI = new MovementAIComponent(enemy, {});
auto* movementAI = new MovementAIComponent(enemy, {});
enemy->AddComponent(eReplicaComponentType::MOVEMENT_AI, movementAI);
enemy->AddComponent(eReplicaComponentType::MOVEMENT_AI, movementAI);
movementAI->SetSpeed(toSpawn.initialSpeed);
movementAI->SetCurrentSpeed(toSpawn.initialSpeed);
movementAI->SetHaltDistance(0.0f);
movementAI->SetSpeed(toSpawn.initialSpeed);
movementAI->SetCurrentSpeed(toSpawn.initialSpeed);
movementAI->SetHaltDistance(0.0f);
std::vector<NiPoint3> pathWaypoints;
std::vector<NiPoint3> pathWaypoints;
for (const auto& waypoint : path->pathWaypoints) {
pathWaypoints.push_back(waypoint.position);
}
if (GeneralUtils::GenerateRandomNumber<float_t>(0, 1) < 0.5f) {
std::reverse(pathWaypoints.begin(), pathWaypoints.end());
}
movementAI->SetPath(pathWaypoints);
enemy->AddDieCallback([this, self, enemy, name]() {
RegisterHit(self, enemy, name);
});
for (const auto& waypoint : path->pathWaypoints) {
pathWaypoints.push_back(waypoint.position);
}
if (GeneralUtils::GenerateRandomNumber<float_t>(0, 1) < 0.5f) {
std::reverse(pathWaypoints.begin(), pathWaypoints.end());
}
movementAI->SetPath(pathWaypoints);
enemy->AddDieCallback([this, self, enemy, name]() {
RegisterHit(self, enemy, name);
});
// Save the enemy and tell it to start pathing
if (enemy != nullptr) {
const_cast<std::vector<LWOOBJID>&>(self->GetVar<std::vector<LWOOBJID>>(SpawnedObjects)).push_back(enemy->GetObjectID());
@@ -338,6 +329,7 @@ SGCannon::OnActivityTimerUpdate(Entity* self, const std::string& name, float_t t
}
void SGCannon::StartGame(Entity* self) {
if (self->GetVar<bool>(GameStartedVariable)) return;
self->SetNetworkVar<uint32_t>(TimeLimitVariable, self->GetVar<uint32_t>(TimeLimitVariable));
self->SetNetworkVar<bool>(AudioStartIntroVariable, true);
self->SetVar<LOT>(CurrentRewardVariable, LOT_NULL);
@@ -444,6 +436,14 @@ void SGCannon::RemovePlayer(LWOOBJID playerID) {
}
}
void SGCannon::OnRequestActivityExit(Entity* self, LWOOBJID player, bool canceled){
if (canceled){
StopGame(self, canceled);
RemovePlayer(player);
}
}
void SGCannon::StartChargedCannon(Entity* self, uint32_t optionalTime) {
optionalTime = optionalTime == 0 ? constants.chargedTime : optionalTime;
self->SetVar<bool>(SuperChargePausedVariable, false);
@@ -571,13 +571,13 @@ void SGCannon::StopGame(Entity* self, bool cancel) {
auto* inventory = player->GetComponent<InventoryComponent>();
if (inventory != nullptr) {
for (const auto rewardLot : self->GetVar<std::vector<LOT>>(RewardsVariable)) {
inventory->AddItem(rewardLot, 1, eLootSourceType::LOOT_SOURCE_ACTIVITY, eInventoryType::MODELS);
inventory->AddItem(rewardLot, 1, eLootSourceType::ACTIVITY, eInventoryType::MODELS);
}
}
self->SetNetworkVar<std::u16string>(u"UI_Rewards",
GeneralUtils::to_u16string(self->GetVar<uint32_t>(TotalScoreVariable)) + u"_0_0_0_0_0_0"
);
);
GameMessages::SendRequestActivitySummaryLeaderboardData(
player->GetObjectID(),

View File

@@ -63,12 +63,11 @@ public:
void OnStartup(Entity* self) override;
void OnPlayerLoaded(Entity* self, Entity* player) override;
void OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) override;
void OnActivityStateChangeRequest(Entity* self, LWOOBJID senderID, int32_t value1,
int32_t value2, const std::u16string& stringValue) override;
void OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier,
const std::u16string& userData) override;
void OnActivityStateChangeRequest(Entity* self, LWOOBJID senderID, int32_t value1, int32_t value2, const std::u16string& stringValue) override;
void OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) override;
void OnActivityTimerDone(Entity* self, const std::string& name) override;
void OnActivityTimerUpdate(Entity* self, const std::string& name, float_t timeRemaining, float_t elapsedTime) override;
void OnRequestActivityExit(Entity* self, LWOOBJID player, bool canceled) override;
private:
static std::vector<std::vector<SGEnemy>> GetWaves();
static SGConstants GetConstants();