Upgraded to new APIs

This commit is contained in:
wincent 2023-10-07 15:15:15 +02:00
parent 2097dbfff1
commit 89339d3003
7 changed files with 18 additions and 109 deletions

View File

@ -102,7 +102,7 @@ void BasicAttackBehavior::DoHandleBehavior(BehaviorContext* context, RakNet::Bit
totalDamageDealt = this->m_MinDamage; totalDamageDealt = this->m_MinDamage;
} }
auto* source = EntityManager::Instance()->GetEntity(context->originator); auto* source = Game::entityManager->GetEntity(context->originator);
auto* damageProfile = DamageProfile::FindDamageProfile(context->skillID); auto* damageProfile = DamageProfile::FindDamageProfile(context->skillID);
@ -206,7 +206,7 @@ void BasicAttackBehavior::DoBehaviorCalculation(BehaviorContext* context, RakNet
auto damage = this->m_MinDamage; auto damage = this->m_MinDamage;
auto* source = EntityManager::Instance()->GetEntity(context->originator); auto* source = Game::entityManager->GetEntity(context->originator);
auto* damageProfile = DamageProfile::FindDamageProfile(context->skillID); auto* damageProfile = DamageProfile::FindDamageProfile(context->skillID);

View File

@ -833,7 +833,7 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
} }
} }
std::vector<Entity*> scripts = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::SCRIPT); std::vector<Entity*> scripts = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::SCRIPT);
for (Entity* scriptEntity : scripts) { for (Entity* scriptEntity : scripts) {
// Prevent double triggering // Prevent double triggering
if (scriptEntity->GetObjectID() == zoneControl->GetObjectID()) continue; if (scriptEntity->GetObjectID() == zoneControl->GetObjectID()) continue;
@ -1135,7 +1135,7 @@ void DestroyableComponent::ComputeBaseStats(bool refill) {
if (currentArmor > maxArmor || refill) SetArmor(maxArmor); if (currentArmor > maxArmor || refill) SetArmor(maxArmor);
else SetArmor(currentArmor); else SetArmor(currentArmor);
EntityManager::Instance()->SerializeEntity(m_Parent); Game::entityManager->SerializeEntity(m_Parent);
} }
std::map<eStatTypes, float> DestroyableComponent::ComputeDamage(uint32_t baseDamage, Entity* source, DamageProfile* damageProfile) { std::map<eStatTypes, float> DestroyableComponent::ComputeDamage(uint32_t baseDamage, Entity* source, DamageProfile* damageProfile) {

View File

@ -41,7 +41,7 @@ void BossSpiderQueenEnemyServer::OnStartup(Entity* self) {
destroyable->GetInfo().armor = 330; destroyable->GetInfo().armor = 330;
destroyable->ComputeBaseStats(true); destroyable->ComputeBaseStats(true);
EntityManager::Instance()->SerializeEntity(self); Game::entityManager->SerializeEntity(self);
// Determine Spider Boss health transition thresholds // Determine Spider Boss health transition thresholds
int spiderBossHealth = destroyable->GetMaxHealth(); int spiderBossHealth = destroyable->GetMaxHealth();
@ -165,10 +165,6 @@ void BossSpiderQueenEnemyServer::WithdrawSpider(Entity* self, const bool withdra
destroyable->SetArmor(destroyable->GetMaxArmor() / 3); destroyable->SetArmor(destroyable->GetMaxArmor() / 3);
auto* destroyable = self->GetComponent<DestroyableComponent>();
destroyable->SetArmor(destroyable->GetMaxArmor() / 3);
Game::entityManager->SerializeEntity(self); Game::entityManager->SerializeEntity(self);
// Prepare a timer for post leap attack // Prepare a timer for post leap attack
@ -366,9 +362,9 @@ void BossSpiderQueenEnemyServer::RainOfFireManager(Entity* self) {
info.pos = entity->GetPosition(); info.pos = entity->GetPosition();
info.spawnerID = entity->GetObjectID(); info.spawnerID = entity->GetObjectID();
auto* spawned = EntityManager::Instance()->CreateEntity(info); auto* spawned = Game::entityManager->CreateEntity(info);
EntityManager::Instance()->ConstructEntity(spawned); Game::entityManager->ConstructEntity(spawned);
}); });
} }
else else
@ -388,9 +384,9 @@ void BossSpiderQueenEnemyServer::RainOfFireManager(Entity* self) {
info.pos = entity->GetPosition() + NiPoint3(x, 0, z); info.pos = entity->GetPosition() + NiPoint3(x, 0, z);
info.spawnerID = entity->GetObjectID(); info.spawnerID = entity->GetObjectID();
auto* spawned = EntityManager::Instance()->CreateEntity(info); auto* spawned = Game::entityManager->CreateEntity(info);
EntityManager::Instance()->ConstructEntity(spawned); Game::entityManager->ConstructEntity(spawned);
}); });
} }
@ -647,7 +643,7 @@ void BossSpiderQueenEnemyServer::OnPlayerDied(Entity* self, Entity* player) {
ply->SendToZone(1100); ply->SendToZone(1100);
self->AddCallbackTimer(10, [] () { self->AddCallbackTimer(10, [] () {
dZoneManager::Instance()->GetZoneControlObject()->SetVar(u"shutdown", true); Game::zoneManager->GetZoneControlObject()->SetVar(u"shutdown", true);
}); });
} }

View File

@ -535,7 +535,7 @@ int main(int argc, char** argv) {
} }
} }
auto* controller = dZoneManager::Instance()->GetZoneControlObject(); auto* controller = Game::zoneManager->GetZoneControlObject();
if (controller != nullptr && controller->HasVar(u"shutdown") && controller->GetVar<bool>(u"shutdown")) { if (controller != nullptr && controller->HasVar(u"shutdown") && controller->GetVar<bool>(u"shutdown")) {
Game::shouldShutdown = true; Game::shouldShutdown = true;

View File

@ -3,5 +3,6 @@ set(DZONEMANAGER_SOURCES "dZoneManager.cpp"
"Spawner.cpp" "Spawner.cpp"
"Zone.cpp") "Zone.cpp")
set(DZONEMANAGER_SOURCES ${DZONEMANAGER_SOURCES} PARENT_SCOPE)
add_library(dZoneManager STATIC ${DZONEMANAGER_SOURCES}) add_library(dZoneManager STATIC ${DZONEMANAGER_SOURCES})
target_link_libraries(dZoneManager dPhysics) # target_link_libraries(dZoneManager dPhysics)

View File

@ -166,100 +166,11 @@ Entity* Spawner::Spawn(std::vector<SpawnerNode*> freeNodes, const bool force) {
m_LotsToCheck.push_back(spawn); m_LotsToCheck.push_back(spawn);
} }
Entity* rezdE = EntityManager::Instance()->CreateEntity(copy, nullptr); Entity* rezdE = Game::entityManager->CreateEntity(copy, nullptr);
rezdE->GetGroups() = m_Info.groups; rezdE->GetGroups() = m_Info.groups;
EntityManager::Instance()->ConstructEntity(rezdE); Game::entityManager->ConstructEntity(rezdE);
m_Entities.insert({ rezdE->GetObjectID(), spawnNode });
spawnNode->entities.push_back(rezdE->GetObjectID());
for (const auto& cb : m_EntitySpawnedCallbacks) {
cb(rezdE);
}
if (first == nullptr) {
first = rezdE;
}
break;
}
usedSpawnPattern = true;
if (m_Entities.size() == m_Info.amountMaintained) {
m_NeedsUpdate = false;
}
return first;
}
}
}
bool usedSpawnPattern = false;
if (m_SpawnPattern != nullptr) {
auto pattern = m_SpawnPattern->GetSpawnPatterns();
// Check the area rating
// std::map<LOT, std::vector<std::pair<NiPoint3, float>>> m_Ratings
for (const auto& lot : m_LotsToCheck)
{
const auto& it = m_Ratings.find(lot);
int32_t rating = 0;
if (it != m_Ratings.end()) {
// Check if we are within 50units of a rating
for (const auto& ratingIt : it->second)
{
if (NiPoint3::DistanceSquared(ratingIt.first, m_EntityInfo.pos) <= 100.0f * 100.0f)
{
rating = ratingIt.second;
break;
}
}
}
for (const auto& it : pattern)
{
if (it.first > rating) continue;
// Random number between 0 and 1
float random = GeneralUtils::GenerateRandomNumber<float>(0, 1);
const auto& change = it.second.first;
if (random >= change) continue;
usedSpawnPattern = true;
Entity* first = nullptr;
for (const auto& spawn : it.second.second)
{
float angle = GeneralUtils::GenerateRandomNumber<float>(0, 360) * M_PI / 180.0f;
float radius = GeneralUtils::GenerateRandomNumber<float>(0, 6);
float x = radius * cos(angle);
float z = radius * sin(angle);
auto copy = m_EntityInfo;
copy.pos.x += x;
copy.pos.z += z;
copy.lot = spawn;
if (std::find(m_LotsToCheck.begin(), m_LotsToCheck.end(), spawn) == m_LotsToCheck.end()) {
m_LotsToCheck.push_back(spawn);
}
Entity* rezdE = EntityManager::Instance()->CreateEntity(copy, nullptr);
rezdE->GetGroups() = m_Info.groups;
EntityManager::Instance()->ConstructEntity(rezdE);
m_Entities.insert({ rezdE->GetObjectID(), spawnNode }); m_Entities.insert({ rezdE->GetObjectID(), spawnNode });

View File

@ -13,7 +13,7 @@
#include "CDZoneTableTable.h" #include "CDZoneTableTable.h"
#include "Spawner.h" #include "Spawner.h"
#include "dZoneManager.h" #include "dZoneManager.h"
#include "dpWorld.h" //#include "dpWorld.h"
#include "eTriggerCommandType.h" #include "eTriggerCommandType.h"
#include "eTriggerEventType.h" #include "eTriggerEventType.h"
@ -557,12 +557,13 @@ void Zone::LoadPath(std::istream& file) {
} }
// We verify the waypoint heights against the navmesh because in many movement paths, // We verify the waypoint heights against the navmesh because in many movement paths,
// the waypoint is located near 0 height, // the waypoint is located near 0 height,
if (path.pathType == PathType::Movement) { /*if (path.pathType == PathType::Movement) {
if (dpWorld::Instance().IsLoaded()) { if (dpWorld::Instance().IsLoaded()) {
// 2000 should be large enough for every world. // 2000 should be large enough for every world.
waypoint.position.y = dpWorld::Instance().GetNavMesh()->GetHeightAtPoint(waypoint.position, 2000.0f); waypoint.position.y = dpWorld::Instance().GetNavMesh()->GetHeightAtPoint(waypoint.position, 2000.0f);
} }
} }
*/
path.pathWaypoints.push_back(waypoint); path.pathWaypoints.push_back(waypoint);
} }
m_Paths.push_back(path); m_Paths.push_back(path);