mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-04-12 02:36:57 +00:00
Merge branch 'main' into moreMovementAi
This commit is contained in:
@@ -13,11 +13,25 @@ include_directories(
|
||||
${PROJECT_SOURCE_DIR}/dGame
|
||||
)
|
||||
|
||||
add_library(dGameBase ${DGAME_SOURCES})
|
||||
add_library(dGameBase OBJECT ${DGAME_SOURCES})
|
||||
target_precompile_headers(dGameBase PRIVATE ${HEADERS_DGAME})
|
||||
target_link_libraries(dGameBase
|
||||
PUBLIC dDatabase dPhysics
|
||||
INTERFACE dComponents dEntity)
|
||||
target_include_directories(dGameBase PUBLIC "." "dEntity"
|
||||
PRIVATE "dComponents" "dGameMessages" "dBehaviors" "dMission" "dUtilities" "dInventory"
|
||||
$<TARGET_PROPERTY:dPropertyBehaviors,INTERFACE_INCLUDE_DIRECTORIES>
|
||||
"${PROJECT_SOURCE_DIR}/dCommon"
|
||||
"${PROJECT_SOURCE_DIR}/dCommon/dEnums"
|
||||
"${PROJECT_SOURCE_DIR}/dCommon/dClient"
|
||||
# dDatabase
|
||||
"${PROJECT_SOURCE_DIR}/dDatabase/CDClientDatabase"
|
||||
"${PROJECT_SOURCE_DIR}/dDatabase/CDClientDatabase/CDClientTables"
|
||||
"${PROJECT_SOURCE_DIR}/dDatabase/GameDatabase"
|
||||
"${PROJECT_SOURCE_DIR}/dDatabase/GameDatabase/ITables"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/mariadb-connector-cpp/include"
|
||||
# dPhysics
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/recastnavigation/Recast/Include"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/recastnavigation/Detour/Include"
|
||||
"${PROJECT_SOURCE_DIR}/dZoneManager"
|
||||
)
|
||||
|
||||
add_subdirectory(dBehaviors)
|
||||
add_subdirectory(dComponents)
|
||||
@@ -28,7 +42,26 @@ add_subdirectory(dMission)
|
||||
add_subdirectory(dPropertyBehaviors)
|
||||
add_subdirectory(dUtilities)
|
||||
|
||||
add_library(dGame INTERFACE)
|
||||
target_link_libraries(dGame INTERFACE
|
||||
dGameBase dBehaviors dComponents dEntity dGameMessages dInventory dMission dPropertyBehaviors dUtilities dScripts
|
||||
add_library(dGame STATIC
|
||||
$<TARGET_OBJECTS:dGameBase>
|
||||
$<TARGET_OBJECTS:dBehaviors>
|
||||
$<TARGET_OBJECTS:dComponents>
|
||||
$<TARGET_OBJECTS:dEntity>
|
||||
$<TARGET_OBJECTS:dGameMessages>
|
||||
$<TARGET_OBJECTS:dInventory>
|
||||
$<TARGET_OBJECTS:dMission>
|
||||
$<TARGET_OBJECTS:dPropertyBehaviors>
|
||||
$<TARGET_OBJECTS:dUtilities>
|
||||
)
|
||||
target_link_libraries(dGame INTERFACE dNet)
|
||||
target_include_directories(dGame INTERFACE
|
||||
$<TARGET_PROPERTY:dGameBase,INTERFACE_INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:dBehaviors,INTERFACE_INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:dComponents,INTERFACE_INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:dEntity,INTERFACE_INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:dGameMessages,INTERFACE_INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:dInventory,INTERFACE_INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:dMission,INTERFACE_INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:dPropertyBehaviors,INTERFACE_INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:dUtilities,INTERFACE_INCLUDE_DIRECTORIES>
|
||||
)
|
||||
|
||||
142
dGame/Entity.cpp
142
dGame/Entity.cpp
@@ -146,17 +146,15 @@ Entity::~Entity() {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity* zoneControl = Game::entityManager->GetZoneControlEntity();
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) {
|
||||
script->OnPlayerExit(zoneControl, this);
|
||||
auto* zoneControl = Game::entityManager->GetZoneControlEntity();
|
||||
if (zoneControl) {
|
||||
zoneControl->GetScript()->OnPlayerExit(zoneControl, this);
|
||||
}
|
||||
|
||||
std::vector<Entity*> scriptedActs = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::SCRIPTED_ACTIVITY);
|
||||
for (Entity* scriptEntity : scriptedActs) {
|
||||
if (scriptEntity->GetObjectID() != zoneControl->GetObjectID()) { // Don't want to trigger twice on instance worlds
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(scriptEntity)) {
|
||||
script->OnPlayerExit(scriptEntity, this);
|
||||
}
|
||||
scriptEntity->GetScript()->OnPlayerExit(scriptEntity, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -756,9 +754,7 @@ void Entity::Initialize() {
|
||||
|
||||
// Hacky way to trigger these when the object has had a chance to get constructed
|
||||
AddCallbackTimer(0, [this]() {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnStartup(this);
|
||||
}
|
||||
this->GetScript()->OnStartup(this);
|
||||
});
|
||||
|
||||
if (!m_Character && Game::entityManager->GetGhostingEnabled()) {
|
||||
@@ -833,17 +829,6 @@ bool Entity::HasComponent(const eReplicaComponentType componentId) const {
|
||||
return m_Components.find(componentId) != m_Components.end();
|
||||
}
|
||||
|
||||
std::vector<ScriptComponent*> Entity::GetScriptComponents() {
|
||||
std::vector<ScriptComponent*> comps;
|
||||
for (std::pair<eReplicaComponentType, void*> p : m_Components) {
|
||||
if (p.first == eReplicaComponentType::SCRIPT) {
|
||||
comps.push_back(static_cast<ScriptComponent*>(p.second));
|
||||
}
|
||||
}
|
||||
|
||||
return comps;
|
||||
}
|
||||
|
||||
void Entity::Subscribe(LWOOBJID scriptObjId, CppScripts::Script* scriptToAdd, const std::string& notificationName) {
|
||||
if (notificationName == "HitOrHealResult" || notificationName == "Hit") {
|
||||
auto* destroyableComponent = GetComponent<DestroyableComponent>();
|
||||
@@ -1272,9 +1257,7 @@ void Entity::Update(const float deltaTime) {
|
||||
// Remove the timer from the list of timers first so that scripts and events can remove timers without causing iterator invalidation
|
||||
auto timerName = timer.GetName();
|
||||
m_Timers.erase(m_Timers.begin() + timerPosition);
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnTimerDone(this, timerName);
|
||||
}
|
||||
GetScript()->OnTimerDone(this, timerName);
|
||||
|
||||
TriggerEvent(eTriggerEventType::TIMER_DONE, this);
|
||||
} else {
|
||||
@@ -1320,9 +1303,7 @@ void Entity::Update(const float deltaTime) {
|
||||
Wake();
|
||||
}
|
||||
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnUpdate(this);
|
||||
}
|
||||
GetScript()->OnUpdate(this);
|
||||
|
||||
for (const auto& pair : m_Components) {
|
||||
if (pair.second == nullptr) continue;
|
||||
@@ -1339,9 +1320,7 @@ void Entity::OnCollisionProximity(LWOOBJID otherEntity, const std::string& proxN
|
||||
Entity* other = Game::entityManager->GetEntity(otherEntity);
|
||||
if (!other) return;
|
||||
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnProximityUpdate(this, other, proxName, status);
|
||||
}
|
||||
GetScript()->OnProximityUpdate(this, other, proxName, status);
|
||||
|
||||
RocketLaunchpadControlComponent* rocketComp = GetComponent<RocketLaunchpadControlComponent>();
|
||||
if (!rocketComp) return;
|
||||
@@ -1353,9 +1332,7 @@ void Entity::OnCollisionPhantom(const LWOOBJID otherEntity) {
|
||||
auto* other = Game::entityManager->GetEntity(otherEntity);
|
||||
if (!other) return;
|
||||
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnCollisionPhantom(this, other);
|
||||
}
|
||||
GetScript()->OnCollisionPhantom(this, other);
|
||||
|
||||
for (const auto& callback : m_PhantomCollisionCallbacks) {
|
||||
callback(other);
|
||||
@@ -1394,9 +1371,7 @@ void Entity::OnCollisionLeavePhantom(const LWOOBJID otherEntity) {
|
||||
auto* other = Game::entityManager->GetEntity(otherEntity);
|
||||
if (!other) return;
|
||||
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnOffCollisionPhantom(this, other);
|
||||
}
|
||||
GetScript()->OnOffCollisionPhantom(this, other);
|
||||
|
||||
TriggerEvent(eTriggerEventType::EXIT, other);
|
||||
|
||||
@@ -1413,46 +1388,32 @@ void Entity::OnCollisionLeavePhantom(const LWOOBJID otherEntity) {
|
||||
}
|
||||
|
||||
void Entity::OnFireEventServerSide(Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnFireEventServerSide(this, sender, args, param1, param2, param3);
|
||||
}
|
||||
GetScript()->OnFireEventServerSide(this, sender, args, param1, param2, param3);
|
||||
}
|
||||
|
||||
void Entity::OnActivityStateChangeRequest(LWOOBJID senderID, int32_t value1, int32_t value2, const std::u16string& stringValue) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnActivityStateChangeRequest(this, senderID, value1, value2, stringValue);
|
||||
}
|
||||
GetScript()->OnActivityStateChangeRequest(this, senderID, value1, value2, stringValue);
|
||||
}
|
||||
|
||||
void Entity::OnCinematicUpdate(Entity* self, Entity* sender, eCinematicEvent event, const std::u16string& pathName,
|
||||
float_t pathTime, float_t totalTime, int32_t waypoint) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnCinematicUpdate(self, sender, event, pathName, pathTime, totalTime, waypoint);
|
||||
}
|
||||
GetScript()->OnCinematicUpdate(self, sender, event, pathName, pathTime, totalTime, waypoint);
|
||||
}
|
||||
|
||||
void Entity::NotifyObject(Entity* sender, const std::string& name, int32_t param1, int32_t param2) {
|
||||
GameMessages::SendNotifyObject(GetObjectID(), sender->GetObjectID(), GeneralUtils::ASCIIToUTF16(name), UNASSIGNED_SYSTEM_ADDRESS);
|
||||
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnNotifyObject(this, sender, name, param1, param2);
|
||||
}
|
||||
GetScript()->OnNotifyObject(this, sender, name, param1, param2);
|
||||
}
|
||||
|
||||
void Entity::OnEmoteReceived(const int32_t emote, Entity* target) {
|
||||
for (auto* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnEmoteReceived(this, emote, target);
|
||||
}
|
||||
GetScript()->OnEmoteReceived(this, emote, target);
|
||||
}
|
||||
|
||||
void Entity::OnUse(Entity* originator) {
|
||||
TriggerEvent(eTriggerEventType::INTERACT, originator);
|
||||
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnUse(this, originator);
|
||||
}
|
||||
|
||||
// component base class when
|
||||
GetScript()->OnUse(this, originator);
|
||||
|
||||
for (const auto& pair : m_Components) {
|
||||
if (pair.second == nullptr) continue;
|
||||
@@ -1462,82 +1423,63 @@ void Entity::OnUse(Entity* originator) {
|
||||
}
|
||||
|
||||
void Entity::OnHitOrHealResult(Entity* attacker, int32_t damage) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnHitOrHealResult(this, attacker, damage);
|
||||
}
|
||||
GetScript()->OnHitOrHealResult(this, attacker, damage);
|
||||
}
|
||||
|
||||
void Entity::OnHit(Entity* attacker) {
|
||||
TriggerEvent(eTriggerEventType::HIT, attacker);
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnHit(this, attacker);
|
||||
}
|
||||
GetScript()->OnHit(this, attacker);
|
||||
}
|
||||
|
||||
void Entity::OnZonePropertyEditBegin() {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnZonePropertyEditBegin(this);
|
||||
}
|
||||
GetScript()->OnZonePropertyEditBegin(this);
|
||||
}
|
||||
|
||||
void Entity::OnZonePropertyEditEnd() {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnZonePropertyEditEnd(this);
|
||||
}
|
||||
GetScript()->OnZonePropertyEditEnd(this);
|
||||
}
|
||||
|
||||
void Entity::OnZonePropertyModelEquipped() {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnZonePropertyModelEquipped(this);
|
||||
}
|
||||
GetScript()->OnZonePropertyModelEquipped(this);
|
||||
}
|
||||
|
||||
void Entity::OnZonePropertyModelPlaced(Entity* player) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnZonePropertyModelPlaced(this, player);
|
||||
}
|
||||
GetScript()->OnZonePropertyModelPlaced(this, player);
|
||||
}
|
||||
|
||||
void Entity::OnZonePropertyModelPickedUp(Entity* player) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnZonePropertyModelPickedUp(this, player);
|
||||
}
|
||||
GetScript()->OnZonePropertyModelPickedUp(this, player);
|
||||
}
|
||||
|
||||
void Entity::OnZonePropertyModelRemoved(Entity* player) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnZonePropertyModelRemoved(this, player);
|
||||
}
|
||||
GetScript()->OnZonePropertyModelRemoved(this, player);
|
||||
}
|
||||
|
||||
void Entity::OnZonePropertyModelRemovedWhileEquipped(Entity* player) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnZonePropertyModelRemovedWhileEquipped(this, player);
|
||||
}
|
||||
GetScript()->OnZonePropertyModelRemovedWhileEquipped(this, player);
|
||||
}
|
||||
|
||||
void Entity::OnZonePropertyModelRotated(Entity* player) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnZonePropertyModelRotated(this, player);
|
||||
}
|
||||
GetScript()->OnZonePropertyModelRotated(this, player);
|
||||
}
|
||||
|
||||
void Entity::OnMessageBoxResponse(Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnMessageBoxResponse(this, sender, button, identifier, userData);
|
||||
}
|
||||
GetScript()->OnMessageBoxResponse(this, sender, button, identifier, userData);
|
||||
}
|
||||
|
||||
void Entity::OnChoiceBoxResponse(Entity* sender, int32_t button, const std::u16string& buttonIdentifier, const std::u16string& identifier) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnChoiceBoxResponse(this, sender, button, buttonIdentifier, identifier);
|
||||
}
|
||||
GetScript()->OnChoiceBoxResponse(this, sender, button, buttonIdentifier, identifier);
|
||||
}
|
||||
|
||||
void Entity::RequestActivityExit(Entity* sender, LWOOBJID player, bool canceled) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnRequestActivityExit(sender, player, canceled);
|
||||
}
|
||||
GetScript()->OnRequestActivityExit(sender, player, canceled);
|
||||
}
|
||||
|
||||
CppScripts::Script* const Entity::GetScript() {
|
||||
auto* scriptComponent = GetComponent<ScriptComponent>();
|
||||
auto* script = scriptComponent ? scriptComponent->GetScript() : CppScripts::GetInvalidScript();
|
||||
DluAssert(script != nullptr);
|
||||
return script;
|
||||
}
|
||||
|
||||
void Entity::Smash(const LWOOBJID source, const eKillType killType, const std::u16string& deathType) {
|
||||
@@ -1570,9 +1512,7 @@ void Entity::Kill(Entity* murderer, const eKillType killType) {
|
||||
|
||||
//OMAI WA MOU, SHINDERIU
|
||||
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
|
||||
script->OnDie(this, murderer);
|
||||
}
|
||||
GetScript()->OnDie(this, murderer);
|
||||
|
||||
if (m_Spawner != nullptr) {
|
||||
m_Spawner->NotifyOfEntityDeath(m_ObjectID);
|
||||
@@ -2120,9 +2060,7 @@ void Entity::ProcessPositionUpdate(PositionUpdate& update) {
|
||||
havokVehiclePhysicsComponent->SetIsOnGround(update.onGround);
|
||||
havokVehiclePhysicsComponent->SetIsOnRail(update.onRail);
|
||||
havokVehiclePhysicsComponent->SetVelocity(update.velocity);
|
||||
havokVehiclePhysicsComponent->SetDirtyVelocity(update.velocity != NiPoint3Constant::ZERO);
|
||||
havokVehiclePhysicsComponent->SetAngularVelocity(update.angularVelocity);
|
||||
havokVehiclePhysicsComponent->SetDirtyAngularVelocity(update.angularVelocity != NiPoint3Constant::ZERO);
|
||||
havokVehiclePhysicsComponent->SetRemoteInputInfo(update.remoteInputInfo);
|
||||
} else {
|
||||
// Need to get the mount's controllable physics
|
||||
@@ -2187,9 +2125,3 @@ void Entity::SetRespawnRot(const NiQuaternion& rotation) {
|
||||
auto* characterComponent = GetComponent<CharacterComponent>();
|
||||
if (characterComponent) characterComponent->SetRespawnRot(rotation);
|
||||
}
|
||||
|
||||
void Entity::SetScale(const float scale) {
|
||||
if (scale == m_Scale) return;
|
||||
m_Scale = scale;
|
||||
Game::entityManager->SerializeEntity(this);
|
||||
}
|
||||
|
||||
@@ -146,7 +146,8 @@ public:
|
||||
|
||||
void AddComponent(eReplicaComponentType componentId, Component* component);
|
||||
|
||||
std::vector<ScriptComponent*> GetScriptComponents();
|
||||
// This is expceted to never return nullptr, an assert checks this.
|
||||
CppScripts::Script* const GetScript();
|
||||
|
||||
void Subscribe(LWOOBJID scriptObjId, CppScripts::Script* scriptToAdd, const std::string& notificationName);
|
||||
void Unsubscribe(LWOOBJID scriptObjId, const std::string& notificationName);
|
||||
@@ -295,7 +296,8 @@ public:
|
||||
|
||||
void ProcessPositionUpdate(PositionUpdate& update);
|
||||
|
||||
void SetScale(const float scale);
|
||||
// Scale will only be communicated to the client when the construction packet is sent
|
||||
void SetScale(const float scale) { m_Scale = scale; };
|
||||
|
||||
protected:
|
||||
LWOOBJID m_ObjectID;
|
||||
|
||||
@@ -418,10 +418,16 @@ void EntityManager::DestructEntity(Entity* entity, const SystemAddress& sysAddr)
|
||||
}
|
||||
|
||||
void EntityManager::SerializeEntity(Entity* entity) {
|
||||
if (!entity || entity->GetNetworkId() == 0) return;
|
||||
if (!entity) return;
|
||||
|
||||
EntityManager::SerializeEntity(*entity);
|
||||
}
|
||||
|
||||
if (std::find(m_EntitiesToSerialize.begin(), m_EntitiesToSerialize.end(), entity->GetObjectID()) == m_EntitiesToSerialize.end()) {
|
||||
m_EntitiesToSerialize.push_back(entity->GetObjectID());
|
||||
void EntityManager::SerializeEntity(const Entity& entity) {
|
||||
if (entity.GetNetworkId() == 0) return;
|
||||
|
||||
if (std::find(m_EntitiesToSerialize.cbegin(), m_EntitiesToSerialize.cend(), entity.GetObjectID()) == m_EntitiesToSerialize.cend()) {
|
||||
m_EntitiesToSerialize.push_back(entity.GetObjectID());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ public:
|
||||
void ConstructEntity(Entity* entity, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS, bool skipChecks = false);
|
||||
void DestructEntity(Entity* entity, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS);
|
||||
void SerializeEntity(Entity* entity);
|
||||
void SerializeEntity(const Entity& entity);
|
||||
|
||||
void ConstructAllEntities(const SystemAddress& sysAddr);
|
||||
void DestructAllEntities(const SystemAddress& sysAddr);
|
||||
|
||||
@@ -21,7 +21,6 @@ set(DGAME_DBEHAVIORS_SOURCES "AirMovementBehavior.cpp"
|
||||
"DamageReductionBehavior.cpp"
|
||||
"DarkInspirationBehavior.cpp"
|
||||
"DurationBehavior.cpp"
|
||||
"EmptyBehavior.cpp"
|
||||
"EndBehavior.cpp"
|
||||
"FallSpeedBehavior.cpp"
|
||||
"ForceMovementBehavior.cpp"
|
||||
@@ -56,7 +55,15 @@ set(DGAME_DBEHAVIORS_SOURCES "AirMovementBehavior.cpp"
|
||||
"VentureVisionBehavior.cpp"
|
||||
"VerifyBehavior.cpp")
|
||||
|
||||
add_library(dBehaviors STATIC ${DGAME_DBEHAVIORS_SOURCES})
|
||||
target_link_libraries(dBehaviors PUBLIC dPhysics)
|
||||
target_include_directories(dBehaviors PUBLIC ".")
|
||||
add_library(dBehaviors OBJECT ${DGAME_DBEHAVIORS_SOURCES})
|
||||
target_link_libraries(dBehaviors PUBLIC dDatabaseCDClient dPhysics)
|
||||
target_include_directories(dBehaviors PUBLIC "."
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dGameMessages" # via BehaviorContext.h
|
||||
PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dComponents" # direct BuffComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dUtilities" # Preconditions.h via QuickBuildComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dEntity" # via dZoneManager.h, Spawner.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dInventory" # via CharacterComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dZoneManager" # via BasicAttackBehavior.cpp
|
||||
)
|
||||
target_precompile_headers(dBehaviors REUSE_FROM dGameBase)
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "EmptyBehavior.h"
|
||||
|
||||
@@ -3,15 +3,14 @@
|
||||
#include "BehaviorContext.h"
|
||||
#include "EntityManager.h"
|
||||
#include "CppScripts.h"
|
||||
#include "Entity.h"
|
||||
|
||||
void SkillEventBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) {
|
||||
auto* target = Game::entityManager->GetEntity(branch.target);
|
||||
auto* caster = Game::entityManager->GetEntity(context->originator);
|
||||
|
||||
if (caster != nullptr && target != nullptr && this->m_effectHandle != nullptr && !this->m_effectHandle->empty()) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(target)) {
|
||||
script->OnSkillEventFired(target, caster, *this->m_effectHandle);
|
||||
}
|
||||
target->GetScript()->OnSkillEventFired(target, caster, *this->m_effectHandle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +20,6 @@ SkillEventBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitSt
|
||||
auto* caster = Game::entityManager->GetEntity(context->originator);
|
||||
|
||||
if (caster != nullptr && target != nullptr && this->m_effectHandle != nullptr && !this->m_effectHandle->empty()) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(target)) {
|
||||
script->OnSkillEventFired(target, caster, *this->m_effectHandle);
|
||||
}
|
||||
target->GetScript()->OnSkillEventFired(target, caster, *this->m_effectHandle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,15 @@
|
||||
#include "UserManager.h"
|
||||
#include "CDMissionsTable.h"
|
||||
|
||||
AchievementVendorComponent::AchievementVendorComponent(Entity* parent) : VendorComponent(parent) {
|
||||
RefreshInventory(true);
|
||||
};
|
||||
|
||||
bool AchievementVendorComponent::SellsItem(Entity* buyer, const LOT lot) {
|
||||
auto* missionComponent = buyer->GetComponent<MissionComponent>();
|
||||
if (!missionComponent) return false;
|
||||
|
||||
if (m_PlayerPurchasableItems[buyer->GetObjectID()].contains(lot)){
|
||||
if (m_PlayerPurchasableItems[buyer->GetObjectID()].contains(lot)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -35,7 +39,7 @@ void AchievementVendorComponent::Buy(Entity* buyer, LOT lot, uint32_t count) {
|
||||
int itemCompID = compRegistryTable->GetByIDAndType(lot, eReplicaComponentType::ITEM);
|
||||
CDItemComponent itemComp = itemComponentTable->GetItemComponentByID(itemCompID);
|
||||
uint32_t costLOT = itemComp.commendationLOT;
|
||||
|
||||
|
||||
if (costLOT == -1 || !SellsItem(buyer, lot)) {
|
||||
auto* user = UserManager::Instance()->GetUser(buyer->GetSystemAddress());
|
||||
CheatDetection::ReportCheat(user, buyer->GetSystemAddress(), "Attempted to buy item %i from achievement vendor %i that is not purchasable", lot, m_Parent->GetLOT());
|
||||
@@ -44,7 +48,7 @@ void AchievementVendorComponent::Buy(Entity* buyer, LOT lot, uint32_t count) {
|
||||
}
|
||||
|
||||
auto* inventoryComponent = buyer->GetComponent<InventoryComponent>();
|
||||
if (!inventoryComponent) {
|
||||
if (!inventoryComponent) {
|
||||
GameMessages::SendVendorTransactionResult(buyer, buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_FAIL);
|
||||
return;
|
||||
}
|
||||
@@ -69,4 +73,9 @@ void AchievementVendorComponent::Buy(Entity* buyer, LOT lot, uint32_t count) {
|
||||
inventoryComponent->AddItem(lot, count, eLootSourceType::VENDOR);
|
||||
GameMessages::SendVendorTransactionResult(buyer, buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_SUCCESS);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void AchievementVendorComponent::RefreshInventory(bool isCreation) {
|
||||
SetHasStandardCostItems(true);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,9 @@ class Entity;
|
||||
class AchievementVendorComponent final : public VendorComponent {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::ACHIEVEMENT_VENDOR;
|
||||
AchievementVendorComponent(Entity* parent) : VendorComponent(parent) {};
|
||||
AchievementVendorComponent(Entity* parent);
|
||||
|
||||
void RefreshInventory(bool isCreation = false) override;
|
||||
bool SellsItem(Entity* buyer, const LOT lot);
|
||||
void Buy(Entity* buyer, LOT lot, uint32_t count);
|
||||
|
||||
|
||||
@@ -48,11 +48,35 @@ set(DGAME_DCOMPONENTS_SOURCES
|
||||
"HavokVehiclePhysicsComponent.cpp"
|
||||
"VendorComponent.cpp"
|
||||
"MiniGameControlComponent.cpp"
|
||||
"ScriptComponent.cpp"
|
||||
)
|
||||
|
||||
add_library(dComponents STATIC ${DGAME_DCOMPONENTS_SOURCES})
|
||||
target_include_directories(dComponents PRIVATE ${PROJECT_SOURCE_DIR}/dScripts/02_server/Map/General) # PetDigServer.h
|
||||
add_library(dComponents OBJECT ${DGAME_DCOMPONENTS_SOURCES})
|
||||
target_include_directories(dComponents PUBLIC "."
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dPropertyBehaviors" # via ModelComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dPropertyBehaviors/ControlBehaviorMessages"
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dMission" # via MissionComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dBehaviors" # via InventoryComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dInventory" # via InventoryComponent.h
|
||||
PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/dCommon"
|
||||
"${PROJECT_SOURCE_DIR}/dCommon/dEnums"
|
||||
"${PROJECT_SOURCE_DIR}/dDatabase/CDClientDatabase"
|
||||
"${PROJECT_SOURCE_DIR}/dDatabase/CDClientDatabase/CDClientTables"
|
||||
"${PROJECT_SOURCE_DIR}/dDatabase/GameDatabase"
|
||||
"${PROJECT_SOURCE_DIR}/dDatabase/GameDatabase/ITables"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/mariadb-connector-cpp/include"
|
||||
# dPhysics (via dpWorld.h)
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/recastnavigation/Recast/Include"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/recastnavigation/Detour/Include"
|
||||
|
||||
"${PROJECT_SOURCE_DIR}/dScripts/02_server/Map/General" # PetDigServer.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dGameMessages" # direct
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dUtilities" # direct Loot.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dEntity" # via dZoneManager/Spawner.h
|
||||
"${PROJECT_SOURCE_DIR}/dZoneManager" # via BouncerComponent.cpp, ActivityComponent.cpp
|
||||
"${PROJECT_SOURCE_DIR}/dChatFilter" # via PetComponent.cpp
|
||||
)
|
||||
target_precompile_headers(dComponents REUSE_FROM dGameBase)
|
||||
target_link_libraries(dComponents
|
||||
PUBLIC dPhysics dDatabase
|
||||
INTERFACE dUtilities dCommon dBehaviors dChatFilter dMission dInventory)
|
||||
|
||||
target_link_libraries(dComponents INTERFACE dBehaviors)
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "RakNetTypes.h"
|
||||
#include "Character.h"
|
||||
#include "Component.h"
|
||||
#include "Item.h"
|
||||
#include <string>
|
||||
#include "CDMissionsTable.h"
|
||||
#include "tinyxml2.h"
|
||||
@@ -15,6 +14,8 @@
|
||||
|
||||
enum class eGameActivity : uint32_t;
|
||||
|
||||
class Item;
|
||||
|
||||
/**
|
||||
* The statistics that can be achieved per zone
|
||||
*/
|
||||
|
||||
@@ -21,7 +21,6 @@ ControllablePhysicsComponent::ControllablePhysicsComponent(Entity* entity) : Phy
|
||||
m_InJetpackMode = false;
|
||||
m_IsOnGround = true;
|
||||
m_IsOnRail = false;
|
||||
m_DirtyVelocity = true;
|
||||
m_dpEntity = nullptr;
|
||||
m_Static = false;
|
||||
m_SpeedMultiplier = 1;
|
||||
@@ -137,21 +136,23 @@ void ControllablePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bo
|
||||
outBitStream.Write(m_IsOnGround);
|
||||
outBitStream.Write(m_IsOnRail);
|
||||
|
||||
outBitStream.Write(isVelocityZero);
|
||||
if (isVelocityZero) {
|
||||
bool isNotZero = m_Velocity != NiPoint3Constant::ZERO;
|
||||
outBitStream.Write(isNotZero);
|
||||
if (isNotZero) {
|
||||
outBitStream.Write(m_Velocity.x);
|
||||
outBitStream.Write(m_Velocity.y);
|
||||
outBitStream.Write(m_Velocity.z);
|
||||
}
|
||||
|
||||
outBitStream.Write(isAngularVelocityZero);
|
||||
if (isAngularVelocityZero) {
|
||||
isNotZero = m_AngularVelocity != NiPoint3Constant::ZERO;
|
||||
outBitStream.Write(isNotZero);
|
||||
if (isNotZero) {
|
||||
outBitStream.Write(m_AngularVelocity.x);
|
||||
outBitStream.Write(m_AngularVelocity.y);
|
||||
outBitStream.Write(m_AngularVelocity.z);
|
||||
}
|
||||
|
||||
outBitStream.Write0(); // LocalSpaceInfo
|
||||
outBitStream.Write0();
|
||||
if (!bIsInitialUpdate) {
|
||||
m_DirtyPosition = false;
|
||||
outBitStream.Write(m_IsTeleporting);
|
||||
@@ -213,9 +214,7 @@ void ControllablePhysicsComponent::SetRotation(const NiQuaternion& rot) {
|
||||
}
|
||||
|
||||
void ControllablePhysicsComponent::SetVelocity(const NiPoint3& vel) {
|
||||
if (m_Static || m_Velocity == vel) {
|
||||
return;
|
||||
}
|
||||
if (m_Static || m_Velocity == vel) return;
|
||||
|
||||
m_Velocity = vel;
|
||||
m_DirtyPosition = true;
|
||||
@@ -224,22 +223,20 @@ void ControllablePhysicsComponent::SetVelocity(const NiPoint3& vel) {
|
||||
}
|
||||
|
||||
void ControllablePhysicsComponent::SetAngularVelocity(const NiPoint3& vel) {
|
||||
if (m_Static || m_AngularVelocity == vel) {
|
||||
return;
|
||||
}
|
||||
if (m_Static || m_AngularVelocity == vel) return;
|
||||
|
||||
m_AngularVelocity = vel;
|
||||
m_DirtyPosition = true;
|
||||
}
|
||||
|
||||
void ControllablePhysicsComponent::SetIsOnGround(bool val) {
|
||||
if (val == m_IsOnGround) return;
|
||||
if (m_IsOnGround == val) return;
|
||||
m_DirtyPosition = true;
|
||||
m_IsOnGround = val;
|
||||
}
|
||||
|
||||
void ControllablePhysicsComponent::SetIsOnRail(bool val) {
|
||||
if (val == m_IsOnRail) return;
|
||||
if (m_IsOnRail == val) return;
|
||||
m_DirtyPosition = true;
|
||||
m_IsOnRail = val;
|
||||
}
|
||||
|
||||
@@ -298,11 +298,6 @@ private:
|
||||
*/
|
||||
dpEntity* m_dpEntity;
|
||||
|
||||
/**
|
||||
* Whether or not the velocity is dirty, forcing a serialization of the velocity
|
||||
*/
|
||||
bool m_DirtyVelocity;
|
||||
|
||||
/**
|
||||
* The current velocity of the entity
|
||||
*/
|
||||
|
||||
@@ -785,16 +785,12 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
}
|
||||
|
||||
Entity* zoneControl = Game::entityManager->GetZoneControlEntity();
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) {
|
||||
script->OnPlayerDied(zoneControl, m_Parent);
|
||||
}
|
||||
if (zoneControl) zoneControl->GetScript()->OnPlayerDied(zoneControl, m_Parent);
|
||||
|
||||
std::vector<Entity*> scriptedActs = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::SCRIPTED_ACTIVITY);
|
||||
for (Entity* scriptEntity : scriptedActs) {
|
||||
if (scriptEntity->GetObjectID() != zoneControl->GetObjectID()) { // Don't want to trigger twice on instance worlds
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(scriptEntity)) {
|
||||
script->OnPlayerDied(scriptEntity, m_Parent);
|
||||
}
|
||||
scriptEntity->GetScript()->OnPlayerDied(scriptEntity, m_Parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ HavokVehiclePhysicsComponent::HavokVehiclePhysicsComponent(Entity* parent) : Phy
|
||||
m_IsOnGround = true;
|
||||
m_IsOnRail = false;
|
||||
m_DirtyPosition = true;
|
||||
m_DirtyVelocity = true;
|
||||
m_DirtyAngularVelocity = true;
|
||||
m_EndBehavior = GeneralUtils::GenerateRandomNumber<uint32_t>(0, 7);
|
||||
}
|
||||
|
||||
@@ -37,17 +35,9 @@ void HavokVehiclePhysicsComponent::SetIsOnRail(bool val) {
|
||||
}
|
||||
|
||||
void HavokVehiclePhysicsComponent::SetRemoteInputInfo(const RemoteInputInfo& remoteInputInfo) {
|
||||
if (m_RemoteInputInfo == remoteInputInfo) return;
|
||||
if (remoteInputInfo == m_RemoteInputInfo) return;
|
||||
this->m_RemoteInputInfo = remoteInputInfo;
|
||||
m_DirtyRemoteInput = true;
|
||||
}
|
||||
|
||||
void HavokVehiclePhysicsComponent::SetDirtyVelocity(bool val) {
|
||||
m_DirtyVelocity = val;
|
||||
}
|
||||
|
||||
void HavokVehiclePhysicsComponent::SetDirtyAngularVelocity(bool val) {
|
||||
m_DirtyAngularVelocity = val;
|
||||
m_DirtyPosition = true;
|
||||
}
|
||||
|
||||
void HavokVehiclePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
|
||||
@@ -67,18 +57,17 @@ void HavokVehiclePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bo
|
||||
outBitStream.Write(m_IsOnGround);
|
||||
outBitStream.Write(m_IsOnRail);
|
||||
|
||||
bool isVelocityZero = m_Velocity == NiPoint3Constant::ZERO;
|
||||
|
||||
outBitStream.Write(isVelocityZero);
|
||||
if (isVelocityZero) {
|
||||
bool isNotZero = m_Velocity != NiPoint3Constant::ZERO;
|
||||
outBitStream.Write(isNotZero);
|
||||
if (isNotZero) {
|
||||
outBitStream.Write(m_Velocity.x);
|
||||
outBitStream.Write(m_Velocity.y);
|
||||
outBitStream.Write(m_Velocity.z);
|
||||
}
|
||||
|
||||
bool isAngularVelocityZero = m_AngularVelocity == NiPoint3Constant::ZERO;
|
||||
outBitStream.Write(isAngularVelocityZero);
|
||||
if (isAngularVelocityZero) {
|
||||
isNotZero = m_AngularVelocity != NiPoint3Constant::ZERO;
|
||||
outBitStream.Write(isNotZero);
|
||||
if (isNotZero) {
|
||||
outBitStream.Write(m_AngularVelocity.x);
|
||||
outBitStream.Write(m_AngularVelocity.y);
|
||||
outBitStream.Write(m_AngularVelocity.z);
|
||||
@@ -86,14 +75,14 @@ void HavokVehiclePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bo
|
||||
|
||||
outBitStream.Write0(); // local_space_info. TODO: Implement this
|
||||
|
||||
outBitStream.Write(m_DirtyRemoteInput || bIsInitialUpdate); // remote_input_info
|
||||
if (m_DirtyRemoteInput || bIsInitialUpdate) {
|
||||
outBitStream.Write(m_RemoteInputInfo.m_RemoteInputX);
|
||||
outBitStream.Write(m_RemoteInputInfo.m_RemoteInputY);
|
||||
outBitStream.Write(m_RemoteInputInfo.m_IsPowersliding);
|
||||
outBitStream.Write(m_RemoteInputInfo.m_IsModified);
|
||||
m_DirtyRemoteInput = false;
|
||||
}
|
||||
// This structure only has this bool flag set to false if a ptr to the peVehicle is null, which we don't have
|
||||
// therefore, this will always be 1, even if all the values in the structure are 0.
|
||||
outBitStream.Write1(); // has remote_input_info
|
||||
outBitStream.Write(m_RemoteInputInfo.m_RemoteInputX);
|
||||
outBitStream.Write(m_RemoteInputInfo.m_RemoteInputY);
|
||||
outBitStream.Write(m_RemoteInputInfo.m_IsPowersliding);
|
||||
outBitStream.Write(m_RemoteInputInfo.m_IsModified);
|
||||
|
||||
|
||||
outBitStream.Write(125.0f); // remote_input_ping TODO: Figure out how this should be calculated as it seems to be constant through the whole race.
|
||||
|
||||
@@ -109,12 +98,3 @@ void HavokVehiclePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bo
|
||||
|
||||
outBitStream.Write0();
|
||||
}
|
||||
|
||||
void HavokVehiclePhysicsComponent::Update(float deltaTime) {
|
||||
if (m_SoftUpdate > 5) {
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
m_SoftUpdate = 0;
|
||||
} else {
|
||||
m_SoftUpdate += deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@ public:
|
||||
|
||||
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
void Update(float deltaTime) override;
|
||||
|
||||
/**
|
||||
* Sets the velocity
|
||||
* @param vel the new velocity
|
||||
@@ -67,22 +65,16 @@ public:
|
||||
*/
|
||||
const bool GetIsOnRail() const { return m_IsOnRail; }
|
||||
|
||||
void SetDirtyPosition(bool val);
|
||||
void SetDirtyVelocity(bool val);
|
||||
void SetDirtyAngularVelocity(bool val);
|
||||
void SetRemoteInputInfo(const RemoteInputInfo&);
|
||||
|
||||
private:
|
||||
bool m_DirtyVelocity;
|
||||
NiPoint3 m_Velocity;
|
||||
|
||||
bool m_DirtyAngularVelocity;
|
||||
NiPoint3 m_AngularVelocity;
|
||||
|
||||
bool m_IsOnGround;
|
||||
bool m_IsOnRail;
|
||||
|
||||
float m_SoftUpdate = 0;
|
||||
uint32_t m_EndBehavior;
|
||||
RemoteInputInfo m_RemoteInputInfo;
|
||||
bool m_DirtyRemoteInput;
|
||||
};
|
||||
|
||||
@@ -162,7 +162,7 @@ void MovingPlatformComponent::StartPathing() {
|
||||
const auto& nextWaypoint = m_Path->pathWaypoints[subComponent->mNextWaypointIndex];
|
||||
|
||||
subComponent->mPosition = currentWaypoint.position;
|
||||
subComponent->mSpeed = currentWaypoint.movingPlatform.speed;
|
||||
subComponent->mSpeed = currentWaypoint.speed;
|
||||
subComponent->mWaitTime = currentWaypoint.movingPlatform.wait;
|
||||
|
||||
targetPosition = nextWaypoint.position;
|
||||
@@ -183,9 +183,7 @@ void MovingPlatformComponent::StartPathing() {
|
||||
const auto travelNext = subComponent->mWaitTime + travelTime;
|
||||
|
||||
m_Parent->AddCallbackTimer(travelTime, [subComponent, this] {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(m_Parent)) {
|
||||
script->OnWaypointReached(m_Parent, subComponent->mNextWaypointIndex);
|
||||
}
|
||||
this->m_Parent->GetScript()->OnWaypointReached(m_Parent, subComponent->mNextWaypointIndex);
|
||||
});
|
||||
|
||||
m_Parent->AddCallbackTimer(travelNext, [this] {
|
||||
@@ -213,7 +211,7 @@ void MovingPlatformComponent::ContinuePathing() {
|
||||
const auto& nextWaypoint = m_Path->pathWaypoints[subComponent->mNextWaypointIndex];
|
||||
|
||||
subComponent->mPosition = currentWaypoint.position;
|
||||
subComponent->mSpeed = currentWaypoint.movingPlatform.speed;
|
||||
subComponent->mSpeed = currentWaypoint.speed;
|
||||
subComponent->mWaitTime = currentWaypoint.movingPlatform.wait; // + 2;
|
||||
|
||||
pathSize = m_Path->pathWaypoints.size() - 1;
|
||||
@@ -295,9 +293,7 @@ void MovingPlatformComponent::ContinuePathing() {
|
||||
const auto travelNext = subComponent->mWaitTime + travelTime;
|
||||
|
||||
m_Parent->AddCallbackTimer(travelTime, [subComponent, this] {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(m_Parent)) {
|
||||
script->OnWaypointReached(m_Parent, subComponent->mNextWaypointIndex);
|
||||
}
|
||||
this->m_Parent->GetScript()->OnWaypointReached(m_Parent, subComponent->mNextWaypointIndex);
|
||||
});
|
||||
|
||||
m_Parent->AddCallbackTimer(travelNext, [this] {
|
||||
|
||||
@@ -306,9 +306,7 @@ void PetComponent::OnUse(Entity* originator) {
|
||||
currentActivities.insert_or_assign(m_Tamer, m_Parent->GetObjectID());
|
||||
|
||||
// Notify the start of a pet taming minigame
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(m_Parent)) {
|
||||
script->OnNotifyPetTamingMinigame(m_Parent, originator, ePetTamingNotifyType::BEGIN);
|
||||
}
|
||||
m_Parent->GetScript()->OnNotifyPetTamingMinigame(m_Parent, originator, ePetTamingNotifyType::BEGIN);
|
||||
}
|
||||
|
||||
void PetComponent::Update(float deltaTime) {
|
||||
@@ -690,9 +688,7 @@ void PetComponent::RequestSetPetName(std::u16string name) {
|
||||
m_Tamer = LWOOBJID_EMPTY;
|
||||
|
||||
// Notify the end of a pet taming minigame
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(m_Parent)) {
|
||||
script->OnNotifyPetTamingMinigame(m_Parent, tamer, ePetTamingNotifyType::SUCCESS);
|
||||
}
|
||||
m_Parent->GetScript()->OnNotifyPetTamingMinigame(m_Parent, tamer, ePetTamingNotifyType::SUCCESS);
|
||||
}
|
||||
|
||||
void PetComponent::ClientExitTamingMinigame(bool voluntaryExit) {
|
||||
@@ -731,9 +727,7 @@ void PetComponent::ClientExitTamingMinigame(bool voluntaryExit) {
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
// Notify the end of a pet taming minigame
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(m_Parent)) {
|
||||
script->OnNotifyPetTamingMinigame(m_Parent, tamer, ePetTamingNotifyType::QUIT);
|
||||
}
|
||||
m_Parent->GetScript()->OnNotifyPetTamingMinigame(m_Parent, tamer, ePetTamingNotifyType::QUIT);
|
||||
}
|
||||
|
||||
void PetComponent::StartTimer() {
|
||||
@@ -782,9 +776,7 @@ void PetComponent::ClientFailTamingMinigame() {
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
// Notify the end of a pet taming minigame
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(m_Parent)) {
|
||||
script->OnNotifyPetTamingMinigame(m_Parent, tamer, ePetTamingNotifyType::FAILED);
|
||||
}
|
||||
m_Parent->GetScript()->OnNotifyPetTamingMinigame(m_Parent, tamer, ePetTamingNotifyType::FAILED);
|
||||
}
|
||||
|
||||
void PetComponent::Wander() {
|
||||
|
||||
@@ -353,7 +353,6 @@ private:
|
||||
|
||||
/**
|
||||
* Pet information loaded from the CDClientDatabase
|
||||
* TODO: Switch to a reference when safe to do so
|
||||
*/
|
||||
CDPetComponent m_PetInfo;
|
||||
};
|
||||
|
||||
@@ -214,9 +214,7 @@ bool PropertyManagementComponent::Claim(const LWOOBJID playerId) {
|
||||
Database::Get()->InsertNewProperty(info, templateId, worldId);
|
||||
|
||||
auto* zoneControlObject = Game::zoneManager->GetZoneControlObject();
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControlObject)) {
|
||||
script->OnZonePropertyRented(zoneControlObject, entity);
|
||||
}
|
||||
if (zoneControlObject) zoneControlObject->GetScript()->OnZonePropertyRented(zoneControlObject, entity);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -414,13 +414,11 @@ void QuickBuildComponent::StartQuickBuild(Entity* const user) {
|
||||
movingPlatform->OnQuickBuildInitilized();
|
||||
}
|
||||
|
||||
for (auto* script : CppScripts::GetEntityScripts(m_Parent)) {
|
||||
script->OnQuickBuildStart(m_Parent, user);
|
||||
}
|
||||
auto* script = m_Parent->GetScript();
|
||||
script->OnQuickBuildStart(m_Parent, user);
|
||||
|
||||
// Notify scripts and possible subscribers
|
||||
for (auto* script : CppScripts::GetEntityScripts(m_Parent))
|
||||
script->OnQuickBuildNotifyState(m_Parent, m_State);
|
||||
script->OnQuickBuildNotifyState(m_Parent, m_State);
|
||||
for (const auto& cb : m_QuickBuildStateCallbacks)
|
||||
cb(m_State);
|
||||
}
|
||||
@@ -485,10 +483,9 @@ void QuickBuildComponent::CompleteQuickBuild(Entity* const user) {
|
||||
}
|
||||
|
||||
// Notify scripts
|
||||
for (auto* script : CppScripts::GetEntityScripts(m_Parent)) {
|
||||
script->OnQuickBuildComplete(m_Parent, user);
|
||||
script->OnQuickBuildNotifyState(m_Parent, m_State);
|
||||
}
|
||||
auto* script = m_Parent->GetScript();
|
||||
script->OnQuickBuildComplete(m_Parent, user);
|
||||
script->OnQuickBuildNotifyState(m_Parent, m_State);
|
||||
|
||||
// Notify subscribers
|
||||
for (const auto& callback : m_QuickBuildStateCallbacks)
|
||||
@@ -539,8 +536,7 @@ void QuickBuildComponent::ResetQuickBuild(const bool failed) {
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
// Notify scripts and possible subscribers
|
||||
for (auto* script : CppScripts::GetEntityScripts(m_Parent))
|
||||
script->OnQuickBuildNotifyState(m_Parent, m_State);
|
||||
m_Parent->GetScript()->OnQuickBuildNotifyState(m_Parent, m_State);
|
||||
for (const auto& cb : m_QuickBuildStateCallbacks)
|
||||
cb(m_State);
|
||||
|
||||
@@ -571,8 +567,7 @@ void QuickBuildComponent::CancelQuickBuild(Entity* const entity, const eQuickBui
|
||||
m_StateDirty = true;
|
||||
|
||||
// Notify scripts and possible subscribers
|
||||
for (auto* script : CppScripts::GetEntityScripts(m_Parent))
|
||||
script->OnQuickBuildNotifyState(m_Parent, m_State);
|
||||
m_Parent->GetScript()->OnQuickBuildNotifyState(m_Parent, m_State);
|
||||
for (const auto& cb : m_QuickBuildStateCallbacks)
|
||||
cb(m_State);
|
||||
|
||||
|
||||
52
dGame/dComponents/ScriptComponent.cpp
Normal file
52
dGame/dComponents/ScriptComponent.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Darkflame Universe
|
||||
* Copyright 2018
|
||||
*/
|
||||
|
||||
#include "Entity.h"
|
||||
#include "ScriptComponent.h"
|
||||
|
||||
ScriptComponent::ScriptComponent(Entity* parent, std::string scriptName, bool serialized, bool client) : Component(parent) {
|
||||
m_Serialized = serialized;
|
||||
m_Client = client;
|
||||
|
||||
SetScript(scriptName);
|
||||
}
|
||||
|
||||
ScriptComponent::~ScriptComponent() {
|
||||
|
||||
}
|
||||
|
||||
void ScriptComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
|
||||
if (bIsInitialUpdate) {
|
||||
const auto& networkSettings = m_Parent->GetNetworkSettings();
|
||||
auto hasNetworkSettings = !networkSettings.empty();
|
||||
outBitStream.Write(hasNetworkSettings);
|
||||
|
||||
if (hasNetworkSettings) {
|
||||
|
||||
// First write the most inner LDF data
|
||||
RakNet::BitStream ldfData;
|
||||
ldfData.Write<uint8_t>(0);
|
||||
ldfData.Write<uint32_t>(networkSettings.size());
|
||||
|
||||
for (auto* networkSetting : networkSettings) {
|
||||
networkSetting->WriteToPacket(ldfData);
|
||||
}
|
||||
|
||||
// Finally write everything to the stream
|
||||
outBitStream.Write<uint32_t>(ldfData.GetNumberOfBytesUsed());
|
||||
outBitStream.Write(ldfData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CppScripts::Script* const ScriptComponent::GetScript() {
|
||||
return m_Script;
|
||||
}
|
||||
|
||||
void ScriptComponent::SetScript(const std::string& scriptName) {
|
||||
// Scripts are managed by the CppScripts class and are effecitvely singletons
|
||||
// and they may also be used by other script components so DON'T delete them.
|
||||
m_Script = CppScripts::GetScript(m_Parent, scriptName);
|
||||
}
|
||||
65
dGame/dComponents/ScriptComponent.h
Normal file
65
dGame/dComponents/ScriptComponent.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Darkflame Universe
|
||||
* Copyright 2018
|
||||
*/
|
||||
|
||||
#ifndef SCRIPTCOMPONENT_H
|
||||
#define SCRIPTCOMPONENT_H
|
||||
|
||||
#include "CppScripts.h"
|
||||
#include "Component.h"
|
||||
#include <string>
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
class Entity;
|
||||
|
||||
/**
|
||||
* Handles the loading and execution of server side scripts on entities, scripts were originally written in Lua,
|
||||
* here they're written in C++
|
||||
*/
|
||||
class ScriptComponent final : public Component {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::SCRIPT;
|
||||
|
||||
ScriptComponent(Entity* parent, std::string scriptName, bool serialized, bool client = false);
|
||||
~ScriptComponent() override;
|
||||
|
||||
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
/**
|
||||
* Returns the script that's attached to this entity
|
||||
* @return the script that's attached to this entity
|
||||
*/
|
||||
CppScripts::Script* const GetScript();
|
||||
|
||||
/**
|
||||
* Sets whether the entity should be serialized, unused
|
||||
* @param var whether the entity should be serialized
|
||||
*/
|
||||
void SetSerialized(const bool var) { m_Serialized = var; }
|
||||
|
||||
/**
|
||||
* Sets the script using a path by looking through dScripts for a script that matches
|
||||
* @param scriptName the name of the script to find
|
||||
*/
|
||||
void SetScript(const std::string& scriptName);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* The script attached to this entity
|
||||
*/
|
||||
CppScripts::Script* m_Script;
|
||||
|
||||
/**
|
||||
* Whether or not the comp should be serialized, unused
|
||||
*/
|
||||
bool m_Serialized;
|
||||
|
||||
/**
|
||||
* Whether or not this script is a client script
|
||||
*/
|
||||
bool m_Client;
|
||||
};
|
||||
|
||||
#endif // SCRIPTCOMPONENT_H
|
||||
@@ -268,9 +268,7 @@ SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, c
|
||||
|
||||
behavior->Calculate(context, bitStream, { target, 0 });
|
||||
|
||||
for (auto* script : CppScripts::GetEntityScripts(m_Parent)) {
|
||||
script->OnSkillCast(m_Parent, skillId);
|
||||
}
|
||||
m_Parent->GetScript()->OnSkillCast(m_Parent, skillId);
|
||||
|
||||
if (!context->foundTarget) {
|
||||
delete context;
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "MovementAIComponent.h"
|
||||
#include "eEndBehavior.h"
|
||||
#include "PlayerManager.h"
|
||||
#include "Game.h"
|
||||
#include "EntityManager.h"
|
||||
|
||||
TriggerComponent::TriggerComponent(Entity* parent, const std::string triggerInfo): Component(parent) {
|
||||
m_Parent = parent;
|
||||
@@ -194,9 +196,7 @@ std::vector<Entity*> TriggerComponent::GatherTargets(LUTriggers::Command* comman
|
||||
}
|
||||
|
||||
void TriggerComponent::HandleFireEvent(Entity* targetEntity, std::string args) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(targetEntity)) {
|
||||
script->OnFireEventServerSide(targetEntity, m_Parent, args, 0, 0, 0);
|
||||
}
|
||||
targetEntity->GetScript()->OnFireEventServerSide(targetEntity, m_Parent, args, 0, 0, 0);
|
||||
}
|
||||
|
||||
void TriggerComponent::HandleDestroyObject(Entity* targetEntity, std::string args){
|
||||
|
||||
@@ -40,9 +40,19 @@ void VendorComponent::RefreshInventory(bool isCreation) {
|
||||
SetHasMultiCostItems(false);
|
||||
m_Inventory.clear();
|
||||
|
||||
// Custom code for Max vanity NPC and Mr.Ree cameras
|
||||
if(isCreation && m_Parent->GetLOT() == 9749 && Game::server->GetZoneID() == 1201) {
|
||||
SetupMaxCustomVendor();
|
||||
// Custom code for Vanity Vendor Invetory Override
|
||||
if(m_Parent->HasVar(u"vendorInvOverride")) {
|
||||
std::vector<std::string> items = GeneralUtils::SplitString(m_Parent->GetVarAsString(u"vendorInvOverride"), ',');
|
||||
uint32_t sortPriority = -1;
|
||||
for (auto& itemString : items) {
|
||||
itemString.erase(remove_if(itemString.begin(), itemString.end(), isspace), itemString.end());
|
||||
auto item = GeneralUtils::TryParse<uint32_t>(itemString);
|
||||
if (!item) continue;
|
||||
if (SetupItem(item.value())) {
|
||||
sortPriority++;
|
||||
m_Inventory.push_back(SoldItem(item.value(), sortPriority));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -52,24 +62,12 @@ void VendorComponent::RefreshInventory(bool isCreation) {
|
||||
if (lootMatrices.empty()) return;
|
||||
|
||||
auto* lootTableTable = CDClientManager::GetTable<CDLootTableTable>();
|
||||
auto* itemComponentTable = CDClientManager::GetTable<CDItemComponentTable>();
|
||||
auto* compRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
|
||||
|
||||
for (const auto& lootMatrix : lootMatrices) {
|
||||
auto vendorItems = lootTableTable->GetTable(lootMatrix.LootTableIndex);
|
||||
if (lootMatrix.maxToDrop == 0 || lootMatrix.minToDrop == 0) {
|
||||
for (const auto& item : vendorItems) {
|
||||
if (!m_HasStandardCostItems || !m_HasMultiCostItems) {
|
||||
auto itemComponentID = compRegistryTable->GetByIDAndType(item.itemid, eReplicaComponentType::ITEM, -1);
|
||||
if (itemComponentID == -1) {
|
||||
LOG("Attempted to add item %i with ItemComponent ID -1 to vendor %i inventory. Not adding item!", itemComponentID, m_Parent->GetLOT());
|
||||
continue;
|
||||
}
|
||||
auto itemComponent = itemComponentTable->GetItemComponentByID(itemComponentID);
|
||||
if (!m_HasStandardCostItems && itemComponent.baseValue != -1) SetHasStandardCostItems(true);
|
||||
if (!m_HasMultiCostItems && !itemComponent.currencyCosts.empty()) SetHasMultiCostItems(true);
|
||||
}
|
||||
m_Inventory.push_back(SoldItem(item.itemid, item.sortPriority));
|
||||
if (SetupItem(item.itemid)) m_Inventory.push_back(SoldItem(item.itemid, item.sortPriority));
|
||||
}
|
||||
} else {
|
||||
auto randomCount = GeneralUtils::GenerateRandomNumber<int32_t>(lootMatrix.minToDrop, lootMatrix.maxToDrop);
|
||||
@@ -79,17 +77,7 @@ void VendorComponent::RefreshInventory(bool isCreation) {
|
||||
auto randomItemIndex = GeneralUtils::GenerateRandomNumber<int32_t>(0, vendorItems.size() - 1);
|
||||
const auto& randomItem = vendorItems.at(randomItemIndex);
|
||||
vendorItems.erase(vendorItems.begin() + randomItemIndex);
|
||||
if (!m_HasStandardCostItems || !m_HasMultiCostItems) {
|
||||
auto itemComponentID = compRegistryTable->GetByIDAndType(randomItem.itemid, eReplicaComponentType::ITEM, -1);
|
||||
if (itemComponentID == -1) {
|
||||
LOG("Attempted to add item %i with ItemComponent ID -1 to vendor %i inventory. Not adding item!", itemComponentID, m_Parent->GetLOT());
|
||||
continue;
|
||||
}
|
||||
auto itemComponent = itemComponentTable->GetItemComponentByID(itemComponentID);
|
||||
if (!m_HasStandardCostItems && itemComponent.baseValue != -1) SetHasStandardCostItems(true);
|
||||
if (!m_HasMultiCostItems && !itemComponent.currencyCosts.empty()) SetHasMultiCostItems(true);
|
||||
}
|
||||
m_Inventory.push_back(SoldItem(randomItem.itemid, randomItem.sortPriority));
|
||||
if (SetupItem(randomItem.itemid)) m_Inventory.push_back(SoldItem(randomItem.itemid, randomItem.sortPriority));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,15 +114,6 @@ bool VendorComponent::SellsItem(const LOT item) const {
|
||||
}) > 0;
|
||||
}
|
||||
|
||||
|
||||
void VendorComponent::SetupMaxCustomVendor(){
|
||||
SetHasStandardCostItems(true);
|
||||
m_Inventory.push_back(SoldItem(11909, 0)); // Top hat w frog
|
||||
m_Inventory.push_back(SoldItem(7785, 0)); // Flash bulb
|
||||
m_Inventory.push_back(SoldItem(12764, 0)); // Big fountain soda
|
||||
m_Inventory.push_back(SoldItem(12241, 0)); // Hot cocoa (from fb)
|
||||
}
|
||||
|
||||
void VendorComponent::HandleMrReeCameras(){
|
||||
if (m_Parent->GetLOT() == 13569) {
|
||||
SetHasStandardCostItems(true);
|
||||
@@ -211,5 +190,25 @@ void VendorComponent::Buy(Entity* buyer, LOT lot, uint32_t count) {
|
||||
character->SetCoins(character->GetCoins() - (coinCost), eLootSourceType::VENDOR);
|
||||
inventoryComponent->AddItem(lot, count, eLootSourceType::VENDOR);
|
||||
GameMessages::SendVendorTransactionResult(buyer, buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_SUCCESS);
|
||||
}
|
||||
|
||||
bool VendorComponent::SetupItem(LOT item) {
|
||||
|
||||
auto* itemComponentTable = CDClientManager::GetTable<CDItemComponentTable>();
|
||||
auto* compRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
|
||||
|
||||
auto itemComponentID = compRegistryTable->GetByIDAndType(item, eReplicaComponentType::ITEM, -1);
|
||||
if (itemComponentID == -1) {
|
||||
LOG("Attempted to add item %i with ItemComponent ID -1 to vendor %i inventory. Not adding item!", itemComponentID, m_Parent->GetLOT());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_HasStandardCostItems || !m_HasMultiCostItems) {
|
||||
auto itemComponent = itemComponentTable->GetItemComponentByID(itemComponentID);
|
||||
if (!m_HasStandardCostItems && itemComponent.baseValue != -1) SetHasStandardCostItems(true);
|
||||
if (!m_HasMultiCostItems && !itemComponent.currencyCosts.empty()) SetHasMultiCostItems(true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
void OnUse(Entity* originator) override;
|
||||
void RefreshInventory(bool isCreation = false);
|
||||
virtual void RefreshInventory(bool isCreation = false);
|
||||
void SetupConstants();
|
||||
bool SellsItem(const LOT item) const;
|
||||
float GetBuyScalar() const { return m_BuyScalar; }
|
||||
@@ -50,8 +50,8 @@ public:
|
||||
void Buy(Entity* buyer, LOT lot, uint32_t count);
|
||||
|
||||
private:
|
||||
void SetupMaxCustomVendor();
|
||||
void HandleMrReeCameras();
|
||||
bool SetupItem(LOT item);
|
||||
float m_BuyScalar = 0.0f;
|
||||
float m_SellScalar = 0.0f;
|
||||
float m_RefreshTimeSeconds = 0.0f;
|
||||
|
||||
@@ -2,6 +2,6 @@ set(DGAME_DENTITY_SOURCES
|
||||
"EntityCallbackTimer.cpp"
|
||||
"EntityTimer.cpp")
|
||||
|
||||
add_library(dEntity STATIC ${DGAME_DENTITY_SOURCES})
|
||||
add_library(dEntity OBJECT ${DGAME_DENTITY_SOURCES})
|
||||
target_include_directories(dEntity PUBLIC ".")
|
||||
target_precompile_headers(dEntity REUSE_FROM dGameBase)
|
||||
|
||||
@@ -4,6 +4,20 @@ set(DGAME_DGAMEMESSAGES_SOURCES
|
||||
"PropertyDataMessage.cpp"
|
||||
"PropertySelectQueryProperty.cpp")
|
||||
|
||||
add_library(dGameMessages STATIC ${DGAME_DGAMEMESSAGES_SOURCES})
|
||||
target_link_libraries(dGameMessages PUBLIC dDatabase)
|
||||
add_library(dGameMessages OBJECT ${DGAME_DGAMEMESSAGES_SOURCES})
|
||||
target_link_libraries(dGameMessages
|
||||
PUBLIC dDatabase
|
||||
INTERFACE dGameBase # TradingManager
|
||||
)
|
||||
target_include_directories(dGameMessages PUBLIC "."
|
||||
PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dComponents" # direct MissionComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dUtilities" # direct SlashCommandHandler.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dPropertyBehaviors" # direct ControlBehaviors.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dMission" # via MissionComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dBehaviors" # via InventoryComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dInventory" # via InventoryComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dEntity" # via dZoneManager/Spawner.h
|
||||
"${PROJECT_SOURCE_DIR}/dZoneManager" # via GameMessages.cpp, GameMessageHandler.cpp
|
||||
)
|
||||
target_precompile_headers(dGameMessages REUSE_FROM dGameBase)
|
||||
|
||||
@@ -136,16 +136,14 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream& inStream, const System
|
||||
}
|
||||
|
||||
Entity* zoneControl = Game::entityManager->GetZoneControlEntity();
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) {
|
||||
script->OnPlayerLoaded(zoneControl, entity);
|
||||
if (zoneControl) {
|
||||
zoneControl->GetScript()->OnPlayerLoaded(zoneControl, entity);
|
||||
}
|
||||
|
||||
std::vector<Entity*> scriptedActs = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::SCRIPT);
|
||||
for (Entity* scriptEntity : scriptedActs) {
|
||||
if (scriptEntity->GetObjectID() != zoneControl->GetObjectID()) { // Don't want to trigger twice on instance worlds
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(scriptEntity)) {
|
||||
script->OnPlayerLoaded(scriptEntity, entity);
|
||||
}
|
||||
scriptEntity->GetScript()->OnPlayerLoaded(scriptEntity, entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -321,9 +321,9 @@ void GameMessages::SendPlayNDAudioEmitter(Entity* entity, const SystemAddress& s
|
||||
CMSGHEADER;
|
||||
|
||||
bitStream.Write(entity->GetObjectID());
|
||||
bitStream.Write((uint16_t)eGameMessageType::PLAY_ND_AUDIO_EMITTER);
|
||||
bitStream.Write(eGameMessageType::PLAY_ND_AUDIO_EMITTER);
|
||||
bitStream.Write0(); // callback message data {lwoobjid}
|
||||
bitStream.Write0(); // audio emmitterid {uint32_t}}
|
||||
bitStream.Write0(); // audio emitterid {uint32_t}
|
||||
|
||||
uint32_t length = audioGUID.size();
|
||||
bitStream.Write(length);
|
||||
@@ -331,8 +331,8 @@ void GameMessages::SendPlayNDAudioEmitter(Entity* entity, const SystemAddress& s
|
||||
bitStream.Write<char>(audioGUID[k]);
|
||||
}
|
||||
|
||||
bitStream.Write(uint32_t(0)); // size of NDAudioMetaEventName (then print he string like the guid)
|
||||
bitStream.Write0(); //result {bool}
|
||||
bitStream.Write<uint32_t>(0); // size of NDAudioMetaEventName (then print the string like the guid)
|
||||
bitStream.Write0(); // result {bool}
|
||||
bitStream.Write0(); // m_TargetObjectIDForNDAudioCallbackMessages {lwoobjid}
|
||||
|
||||
SEND_PACKET_BROADCAST;
|
||||
@@ -5083,9 +5083,7 @@ void GameMessages::HandleRespondToMission(RakNet::BitStream& inStream, Entity* e
|
||||
return;
|
||||
}
|
||||
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(offerer)) {
|
||||
script->OnRespondToMission(offerer, missionID, Game::entityManager->GetEntity(playerID), reward);
|
||||
}
|
||||
offerer->GetScript()->OnRespondToMission(offerer, missionID, Game::entityManager->GetEntity(playerID), reward);
|
||||
}
|
||||
|
||||
void GameMessages::HandleMissionDialogOK(RakNet::BitStream& inStream, Entity* entity) {
|
||||
@@ -5101,9 +5099,7 @@ void GameMessages::HandleMissionDialogOK(RakNet::BitStream& inStream, Entity* en
|
||||
inStream.Read(responder);
|
||||
player = Game::entityManager->GetEntity(responder);
|
||||
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(entity)) {
|
||||
script->OnMissionDialogueOK(entity, player, missionID, iMissionState);
|
||||
}
|
||||
if (entity) entity->GetScript()->OnMissionDialogueOK(entity, player, missionID, iMissionState);
|
||||
|
||||
// Get the player's mission component
|
||||
MissionComponent* missionComponent = static_cast<MissionComponent*>(player->GetComponent(eReplicaComponentType::MISSION));
|
||||
@@ -5556,9 +5552,7 @@ void GameMessages::HandleModularBuildFinish(RakNet::BitStream& inStream, Entity*
|
||||
|
||||
ScriptComponent* script = static_cast<ScriptComponent*>(entity->GetComponent(eReplicaComponentType::SCRIPT));
|
||||
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(entity)) {
|
||||
script->OnModularBuildExit(entity, character, count >= 3, modList);
|
||||
}
|
||||
entity->GetScript()->OnModularBuildExit(entity, character, count >= 3, modList);
|
||||
|
||||
// Move remaining temp models back to models
|
||||
std::vector<Item*> items;
|
||||
@@ -5734,16 +5728,14 @@ void GameMessages::HandleResurrect(RakNet::BitStream& inStream, Entity* entity)
|
||||
bool immediate = inStream.ReadBit();
|
||||
|
||||
Entity* zoneControl = Game::entityManager->GetZoneControlEntity();
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) {
|
||||
script->OnPlayerResurrected(zoneControl, entity);
|
||||
if (zoneControl) {
|
||||
zoneControl->GetScript()->OnPlayerResurrected(zoneControl, entity);
|
||||
}
|
||||
|
||||
std::vector<Entity*> scriptedActs = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::SCRIPTED_ACTIVITY);
|
||||
for (Entity* scriptEntity : scriptedActs) {
|
||||
if (scriptEntity->GetObjectID() != zoneControl->GetObjectID()) { // Don't want to trigger twice on instance worlds
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(scriptEntity)) {
|
||||
script->OnPlayerResurrected(scriptEntity, entity);
|
||||
}
|
||||
scriptEntity->GetScript()->OnPlayerResurrected(scriptEntity, entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5977,9 +5969,7 @@ void GameMessages::HandlePlayerRailArrivedNotification(RakNet::BitStream& inStre
|
||||
|
||||
const auto possibleRails = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::RAIL_ACTIVATOR);
|
||||
for (auto* possibleRail : possibleRails) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(possibleRail)) {
|
||||
script->OnPlayerRailArrived(possibleRail, entity, pathName, waypointNumber);
|
||||
}
|
||||
if (possibleRail) possibleRail->GetScript()->OnPlayerRailArrived(possibleRail, entity, pathName, waypointNumber);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,32 @@ set(DGAME_DINVENTORY_SOURCES
|
||||
"ItemSet.cpp"
|
||||
"ItemSetPassiveAbility.cpp")
|
||||
|
||||
add_library(dInventory OBJECT ${DGAME_DINVENTORY_SOURCES})
|
||||
target_include_directories(dInventory PUBLIC "."
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dUtilities" # Item.h uses Preconditions.h
|
||||
"${PROJECT_SOURCE_DIR}/dCommon/eEnums" # Item.h uses dCommonVars.h
|
||||
PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/dCommon"
|
||||
"${PROJECT_SOURCE_DIR}/dCommon/dEnums"
|
||||
"${PROJECT_SOURCE_DIR}/dCommon/dClient" # Item.cpp uses AssetManager
|
||||
|
||||
"${PROJECT_SOURCE_DIR}/dDatabase/CDClientDatabase"
|
||||
"${PROJECT_SOURCE_DIR}/dDatabase/CDClientDatabase/CDClientTables"
|
||||
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dGameMessages" # direct
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dComponents" # direct InventoryComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dBehaviors" # via InventoryComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dEntity" # via dZoneManager/Spawner.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dMission" # via MissionComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dZoneManager" # via Item.cpp
|
||||
)
|
||||
target_precompile_headers(dInventory REUSE_FROM dGameBase)
|
||||
# Workaround for compiler bug where the optimized code could result in a memcpy of 0 bytes, even though that isnt possible.
|
||||
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97185
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
set_source_files_properties("Item.cpp" PROPERTIES COMPILE_FLAGS "-Wno-stringop-overflow")
|
||||
endif()
|
||||
|
||||
add_library(dInventory STATIC ${DGAME_DINVENTORY_SOURCES})
|
||||
target_precompile_headers(dInventory REUSE_FROM dGameBase)
|
||||
# INTERFACE link w/o dependency
|
||||
#set_property(TARGET dInventory APPEND PROPERTY INTERFACE_LINK_LIBRARIES
|
||||
# dNet dDatabaseCDClient
|
||||
#)
|
||||
|
||||
@@ -3,6 +3,16 @@ set(DGAME_DMISSION_SOURCES
|
||||
"MissionPrerequisites.cpp"
|
||||
"MissionTask.cpp")
|
||||
|
||||
add_library(dMission STATIC ${DGAME_DMISSION_SOURCES})
|
||||
add_library(dMission OBJECT ${DGAME_DMISSION_SOURCES})
|
||||
target_link_libraries(dMission PUBLIC dDatabase)
|
||||
target_include_directories(dMission PUBLIC "."
|
||||
PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dComponents"
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dInventory" # via CharacterComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dUtilities" # via CharacterComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dGameMessages" # via LevelProgressionComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dEntity" # via dZoneManager/Spawner.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dBehaviors" # via InventoryComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dZoneManager" # via Mission.cpp, MissionTask.cpp
|
||||
)
|
||||
target_precompile_headers(dMission REUSE_FROM dGameBase)
|
||||
|
||||
@@ -12,5 +12,15 @@ foreach(file ${DGAME_DPROPERTYBEHAVIORS_CONTROLBEHAVIORMESSAGES})
|
||||
set(DGAME_DPROPERTYBEHAVIORS_SOURCES ${DGAME_DPROPERTYBEHAVIORS_SOURCES} "ControlBehaviorMessages/${file}")
|
||||
endforeach()
|
||||
|
||||
add_library(dPropertyBehaviors STATIC ${DGAME_DPROPERTYBEHAVIORS_SOURCES})
|
||||
add_library(dPropertyBehaviors OBJECT ${DGAME_DPROPERTYBEHAVIORS_SOURCES})
|
||||
target_link_libraries(dPropertyBehaviors PRIVATE dDatabaseCDClient)
|
||||
target_include_directories(dPropertyBehaviors PUBLIC "." "ControlBehaviorMessages"
|
||||
PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/dCommon/dClient" # ControlBehaviors.cpp uses AssetManager
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dUtilities" # ObjectIdManager.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dGameMessages" # GameMessages.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dComponents" # ModelComponent.h
|
||||
)
|
||||
target_precompile_headers(dPropertyBehaviors REUSE_FROM dGameBase)
|
||||
|
||||
target_link_libraries(dPropertyBehaviors INTERFACE dComponents)
|
||||
|
||||
@@ -8,8 +8,18 @@ set(DGAME_DUTILITIES_SOURCES "BrickDatabase.cpp"
|
||||
"SlashCommandHandler.cpp"
|
||||
"VanityUtilities.cpp")
|
||||
|
||||
add_library(dUtilities STATIC ${DGAME_DUTILITIES_SOURCES})
|
||||
add_library(dUtilities OBJECT ${DGAME_DUTILITIES_SOURCES})
|
||||
target_precompile_headers(dUtilities REUSE_FROM dGameBase)
|
||||
target_include_directories(dUtilities PUBLIC "."
|
||||
PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dComponents"
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dInventory" # transitive via PossessableComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dGameMessages"
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dBehaviors" # transitive via InventoryComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dMission" # transitive via MissionComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dEntity" # transitive via dZoneManager/Spawner.h
|
||||
"${PROJECT_SOURCE_DIR}/dZoneManager" # Mail.cpp
|
||||
)
|
||||
target_link_libraries(dUtilities
|
||||
PUBLIC dDatabase dPhysics
|
||||
INTERFACE dZoneManager)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "dCommonVars.h"
|
||||
#include "eLootSourceType.h"
|
||||
#include <unordered_map>
|
||||
|
||||
class Entity;
|
||||
|
||||
@@ -22,9 +22,18 @@
|
||||
|
||||
#include <fstream>
|
||||
|
||||
std::vector<VanityObject> VanityUtilities::m_Objects = {};
|
||||
std::set<std::string> VanityUtilities::m_LoadedFiles = {};
|
||||
|
||||
namespace {
|
||||
std::vector<VanityObject> objects;
|
||||
std::set<std::string> loadedFiles;
|
||||
}
|
||||
|
||||
void SetupNPCTalk(Entity* npc);
|
||||
void NPCTalk(Entity* npc);
|
||||
void ParseXml(const std::string& file);
|
||||
LWOOBJID SpawnSpawner(const VanityObject& object, const VanityObjectLocation& location);
|
||||
Entity* SpawnObject(const VanityObject& object, const VanityObjectLocation& location);
|
||||
VanityObject* GetObject(const std::string& name);
|
||||
|
||||
void VanityUtilities::SpawnVanity() {
|
||||
const uint32_t zoneID = Game::server->GetZoneID();
|
||||
@@ -36,21 +45,19 @@ void VanityUtilities::SpawnVanity() {
|
||||
info.pos = { 259.5f, 246.4f, -705.2f };
|
||||
info.rot = { 0.0f, 0.0f, 1.0f, 0.0f };
|
||||
info.spawnerID = Game::entityManager->GetZoneControlEntity()->GetObjectID();
|
||||
|
||||
info.settings = { new LDFData<bool>(u"hasCustomText", true),
|
||||
new LDFData<std::string>(u"customText", ParseMarkdown((BinaryPathFinder::GetBinaryDir() / "vanity/TESTAMENT.md").string())) };
|
||||
info.settings = {
|
||||
new LDFData<bool>(u"hasCustomText", true),
|
||||
new LDFData<std::string>(u"customText", ParseMarkdown((BinaryPathFinder::GetBinaryDir() / "vanity/TESTAMENT.md").string()))
|
||||
};
|
||||
|
||||
auto* entity = Game::entityManager->CreateEntity(info);
|
||||
|
||||
Game::entityManager->ConstructEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
if (Game::config->GetValue("disable_vanity") == "1") {
|
||||
return;
|
||||
}
|
||||
if (Game::config->GetValue("disable_vanity") == "1") return;
|
||||
|
||||
for (const auto& npc : m_Objects) {
|
||||
for (const auto& npc : objects) {
|
||||
if (npc.m_ID == LWOOBJID_EMPTY) continue;
|
||||
if (npc.m_LOT == 176){
|
||||
Game::zoneManager->RemoveSpawner(npc.m_ID);
|
||||
@@ -61,13 +68,13 @@ void VanityUtilities::SpawnVanity() {
|
||||
}
|
||||
}
|
||||
|
||||
m_Objects.clear();
|
||||
m_LoadedFiles.clear();
|
||||
objects.clear();
|
||||
loadedFiles.clear();
|
||||
|
||||
ParseXML((BinaryPathFinder::GetBinaryDir() / "vanity/root.xml").string());
|
||||
ParseXml((BinaryPathFinder::GetBinaryDir() / "vanity/root.xml").string());
|
||||
|
||||
// Loop through all objects
|
||||
for (auto& object : m_Objects) {
|
||||
for (auto& object : objects) {
|
||||
if (object.m_Locations.find(Game::server->GetZoneID()) == object.m_Locations.end()) continue;
|
||||
|
||||
const std::vector<VanityObjectLocation>& locations = object.m_Locations.at(Game::server->GetZoneID());
|
||||
@@ -79,12 +86,6 @@ void VanityUtilities::SpawnVanity() {
|
||||
float rate = GeneralUtils::GenerateRandomNumber<float>(0, 1);
|
||||
if (location.m_Chance < rate) continue;
|
||||
|
||||
if (object.m_Config.empty()) {
|
||||
object.m_Config = {
|
||||
new LDFData<std::vector<std::u16string>>(u"syncLDF", { u"custom_script_client" }),
|
||||
new LDFData<std::u16string>(u"custom_script_client", u"scripts\\ai\\SPEC\\MISSION_MINIGAME_CLIENT.lua")
|
||||
};
|
||||
}
|
||||
if (object.m_LOT == 176){
|
||||
object.m_ID = SpawnSpawner(object, location);
|
||||
} else {
|
||||
@@ -94,20 +95,13 @@ void VanityUtilities::SpawnVanity() {
|
||||
object.m_ID = objectEntity->GetObjectID();
|
||||
if (!object.m_Phrases.empty()){
|
||||
objectEntity->SetVar<std::vector<std::string>>(u"chats", object.m_Phrases);
|
||||
|
||||
auto* scriptComponent = objectEntity->GetComponent<ScriptComponent>();
|
||||
|
||||
if (scriptComponent && !object.m_Script.empty()) {
|
||||
scriptComponent->SetScript(object.m_Script);
|
||||
scriptComponent->SetSerialized(false);
|
||||
}
|
||||
SetupNPCTalk(objectEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LWOOBJID VanityUtilities::SpawnSpawner(const VanityObject& object, const VanityObjectLocation& location) {
|
||||
LWOOBJID SpawnSpawner(const VanityObject& object, const VanityObjectLocation& location) {
|
||||
SceneObject obj;
|
||||
obj.lot = object.m_LOT;
|
||||
// guratantee we have no collisions
|
||||
@@ -121,7 +115,7 @@ LWOOBJID VanityUtilities::SpawnSpawner(const VanityObject& object, const VanityO
|
||||
return obj.id;
|
||||
}
|
||||
|
||||
Entity* VanityUtilities::SpawnObject(const VanityObject& object, const VanityObjectLocation& location) {
|
||||
Entity* SpawnObject(const VanityObject& object, const VanityObjectLocation& location) {
|
||||
EntityInfo info;
|
||||
info.lot = object.m_LOT;
|
||||
info.pos = location.m_Position;
|
||||
@@ -131,18 +125,16 @@ Entity* VanityUtilities::SpawnObject(const VanityObject& object, const VanityObj
|
||||
info.settings = object.m_Config;
|
||||
|
||||
auto* entity = Game::entityManager->CreateEntity(info);
|
||||
entity->SetVar(u"npcName", object.m_Name);
|
||||
if (!object.m_Name.empty()) entity->SetVar(u"npcName", object.m_Name);
|
||||
if (entity->GetVar<bool>(u"noGhosting")) entity->SetIsGhostingCandidate(false);
|
||||
|
||||
auto* inventoryComponent = entity->GetComponent<InventoryComponent>();
|
||||
|
||||
if (inventoryComponent && !object.m_Equipment.empty()) {
|
||||
inventoryComponent->SetNPCItems(object.m_Equipment);
|
||||
}
|
||||
|
||||
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (destroyableComponent != nullptr) {
|
||||
if (destroyableComponent) {
|
||||
destroyableComponent->SetIsGMImmune(true);
|
||||
destroyableComponent->SetMaxHealth(0);
|
||||
destroyableComponent->SetHealth(0);
|
||||
@@ -153,12 +145,12 @@ Entity* VanityUtilities::SpawnObject(const VanityObject& object, const VanityObj
|
||||
return entity;
|
||||
}
|
||||
|
||||
void VanityUtilities::ParseXML(const std::string& file) {
|
||||
if (m_LoadedFiles.contains(file)){
|
||||
void ParseXml(const std::string& file) {
|
||||
if (loadedFiles.contains(file)){
|
||||
LOG("Trying to load vanity file %s twice!!!", file.c_str());
|
||||
return;
|
||||
}
|
||||
m_LoadedFiles.insert(file);
|
||||
loadedFiles.insert(file);
|
||||
// Read the entire file
|
||||
std::ifstream xmlFile(file);
|
||||
std::string xml((std::istreambuf_iterator<char>(xmlFile)), std::istreambuf_iterator<char>());
|
||||
@@ -176,24 +168,26 @@ void VanityUtilities::ParseXML(const std::string& file) {
|
||||
if (enabled != "1") {
|
||||
continue;
|
||||
}
|
||||
ParseXML((BinaryPathFinder::GetBinaryDir() / "vanity" / filename).string());
|
||||
ParseXml((BinaryPathFinder::GetBinaryDir() / "vanity" / filename).string());
|
||||
}
|
||||
}
|
||||
|
||||
// Read the objects
|
||||
auto* objects = doc.FirstChildElement("objects");
|
||||
|
||||
if (objects) {
|
||||
for (auto* object = objects->FirstChildElement("object"); object != nullptr; object = object->NextSiblingElement("object")) {
|
||||
auto* objectsElement = doc.FirstChildElement("objects");
|
||||
const uint32_t currentZoneID = Game::server->GetZoneID();
|
||||
if (objectsElement) {
|
||||
for (auto* object = objectsElement->FirstChildElement("object"); object != nullptr; object = object->NextSiblingElement("object")) {
|
||||
// for use later when adding to the vector of VanityObjects
|
||||
bool useLocationsAsRandomSpawnPoint = false;
|
||||
// Get the NPC name
|
||||
auto* name = object->Attribute("name");
|
||||
|
||||
if (!name) name = "";
|
||||
|
||||
// Get the NPC lot
|
||||
auto* lot = object->Attribute("lot");
|
||||
auto lot = GeneralUtils::TryParse<LOT>(object->Attribute("lot")).value_or(LOT_NULL);
|
||||
|
||||
if (lot == nullptr) {
|
||||
if (lot == LOT_NULL) {
|
||||
LOG("Failed to parse object lot");
|
||||
continue;
|
||||
}
|
||||
@@ -211,17 +205,17 @@ void VanityUtilities::ParseXML(const std::string& file) {
|
||||
std::vector<std::string> splitEquipment = GeneralUtils::SplitString(equipmentString, ',');
|
||||
|
||||
for (auto& item : splitEquipment) {
|
||||
inventory.push_back(std::stoi(item));
|
||||
// remove spaces for tryParse to work
|
||||
item.erase(remove_if(item.begin(), item.end(), isspace), item.end());
|
||||
auto itemInt = GeneralUtils::TryParse<uint32_t>(item);
|
||||
if (itemInt) inventory.push_back(itemInt.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Get the phrases
|
||||
auto* phrases = object->FirstChildElement("phrases");
|
||||
|
||||
std::vector<std::string> phraseList = {};
|
||||
|
||||
if (phrases) {
|
||||
for (auto* phrase = phrases->FirstChildElement("phrase"); phrase != nullptr;
|
||||
phrase = phrase->NextSiblingElement("phrase")) {
|
||||
@@ -235,41 +229,34 @@ void VanityUtilities::ParseXML(const std::string& file) {
|
||||
}
|
||||
}
|
||||
|
||||
// Get the script
|
||||
auto* scriptElement = object->FirstChildElement("script");
|
||||
|
||||
std::string scriptName = "";
|
||||
|
||||
if (scriptElement != nullptr) {
|
||||
auto* scriptNameAttribute = scriptElement->Attribute("name");
|
||||
if (scriptNameAttribute) scriptName = scriptNameAttribute;
|
||||
}
|
||||
|
||||
auto* configElement = object->FirstChildElement("config");
|
||||
std::vector<std::u16string> keys = {};
|
||||
|
||||
std::vector<LDFBaseData*> config = {};
|
||||
if(configElement) {
|
||||
for (auto* key = configElement->FirstChildElement("key"); key != nullptr;
|
||||
key = key->NextSiblingElement("key")) {
|
||||
// Get the config data
|
||||
auto* data = key->Attribute("data");
|
||||
auto* data = key->GetText();
|
||||
if (!data) continue;
|
||||
|
||||
LDFBaseData* configData = LDFBaseData::DataFromString(data);
|
||||
if (configData->GetKey() == u"useLocationsAsRandomSpawnPoint" && configData->GetValueType() == eLDFType::LDF_TYPE_BOOLEAN){
|
||||
useLocationsAsRandomSpawnPoint = static_cast<bool>(configData);
|
||||
continue;
|
||||
}
|
||||
keys.push_back(configData->GetKey());
|
||||
config.push_back(configData);
|
||||
}
|
||||
}
|
||||
if (!keys.empty()) config.push_back(new LDFData<std::vector<std::u16string>>(u"syncLDF", keys));
|
||||
|
||||
VanityObject objectData;
|
||||
objectData.m_Name = name;
|
||||
objectData.m_LOT = std::stoi(lot);
|
||||
objectData.m_Equipment = inventory;
|
||||
objectData.m_Phrases = phraseList;
|
||||
objectData.m_Script = scriptName;
|
||||
objectData.m_Config = config;
|
||||
VanityObject objectData {
|
||||
.m_Name = name,
|
||||
.m_LOT = lot,
|
||||
.m_Equipment = inventory,
|
||||
.m_Phrases = phraseList,
|
||||
.m_Config = config
|
||||
};
|
||||
|
||||
// Get the locations
|
||||
auto* locations = object->FirstChildElement("locations");
|
||||
@@ -283,64 +270,67 @@ void VanityUtilities::ParseXML(const std::string& file) {
|
||||
location = location->NextSiblingElement("location")) {
|
||||
|
||||
// Get the location data
|
||||
auto* zoneID = location->Attribute("zone");
|
||||
auto* x = location->Attribute("x");
|
||||
auto* y = location->Attribute("y");
|
||||
auto* z = location->Attribute("z");
|
||||
auto* rw = location->Attribute("rw");
|
||||
auto* rx = location->Attribute("rx");
|
||||
auto* ry = location->Attribute("ry");
|
||||
auto* rz = location->Attribute("rz");
|
||||
auto zoneID = GeneralUtils::TryParse<uint32_t>(location->Attribute("zone"));
|
||||
auto x = GeneralUtils::TryParse<float>(location->Attribute("x"));
|
||||
auto y = GeneralUtils::TryParse<float>(location->Attribute("y"));
|
||||
auto z = GeneralUtils::TryParse<float>(location->Attribute("z"));
|
||||
auto rw = GeneralUtils::TryParse<float>(location->Attribute("rw"));
|
||||
auto rx = GeneralUtils::TryParse<float>(location->Attribute("rx"));
|
||||
auto ry = GeneralUtils::TryParse<float>(location->Attribute("ry"));
|
||||
auto rz = GeneralUtils::TryParse<float>(location->Attribute("rz"));
|
||||
|
||||
if (zoneID == nullptr || x == nullptr || y == nullptr || z == nullptr || rw == nullptr || rx == nullptr || ry == nullptr
|
||||
|| rz == nullptr) {
|
||||
if (!zoneID || !x || !y || !z || !rw || !rx || !ry || !rz) {
|
||||
LOG("Failed to parse NPC location data");
|
||||
continue;
|
||||
}
|
||||
|
||||
VanityObjectLocation locationData;
|
||||
locationData.m_Position = { std::stof(x), std::stof(y), std::stof(z) };
|
||||
locationData.m_Rotation = { std::stof(rw), std::stof(rx), std::stof(ry), std::stof(rz) };
|
||||
locationData.m_Chance = 1.0f;
|
||||
if (zoneID.value() != currentZoneID) {
|
||||
LOG_DEBUG("Skipping (%s) %i location because it is in %i and not the current zone (%i)", name, lot, zoneID.value(), currentZoneID);
|
||||
continue;
|
||||
}
|
||||
|
||||
VanityObjectLocation locationData {
|
||||
.m_Position = { x.value(), y.value(), z.value() },
|
||||
.m_Rotation = { rw.value(), rx.value(), ry.value(), rz.value() },
|
||||
};
|
||||
|
||||
if (location->Attribute("chance")) {
|
||||
locationData.m_Chance = std::stof(location->Attribute("chance"));
|
||||
locationData.m_Chance = GeneralUtils::TryParse<float>(location->Attribute("chance")).value_or(1.0f);
|
||||
}
|
||||
|
||||
if (location->Attribute("scale")) {
|
||||
locationData.m_Scale = std::stof(location->Attribute("scale"));
|
||||
locationData.m_Scale = GeneralUtils::TryParse<float>(location->Attribute("scale")).value_or(1.0f);
|
||||
}
|
||||
|
||||
|
||||
const auto& it = objectData.m_Locations.find(std::stoi(zoneID));
|
||||
const auto& it = objectData.m_Locations.find(zoneID.value());
|
||||
|
||||
if (it != objectData.m_Locations.end()) {
|
||||
it->second.push_back(locationData);
|
||||
} else {
|
||||
std::vector<VanityObjectLocation> locations;
|
||||
locations.push_back(locationData);
|
||||
objectData.m_Locations.insert(std::make_pair(std::stoi(zoneID), locations));
|
||||
objectData.m_Locations.insert(std::make_pair(zoneID.value(), locations));
|
||||
}
|
||||
|
||||
if (!(std::find(keys.begin(), keys.end(), u"teleport") != keys.end())) {
|
||||
m_Objects.push_back(objectData);
|
||||
if (!useLocationsAsRandomSpawnPoint) {
|
||||
objects.push_back(objectData);
|
||||
objectData.m_Locations.clear();
|
||||
}
|
||||
}
|
||||
if (std::find(keys.begin(), keys.end(), u"teleport") != keys.end()) {
|
||||
m_Objects.push_back(objectData);
|
||||
}
|
||||
|
||||
if (useLocationsAsRandomSpawnPoint && !objectData.m_Locations.empty()) {
|
||||
objects.push_back(objectData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VanityObject* VanityUtilities::GetObject(const std::string& name) {
|
||||
for (size_t i = 0; i < m_Objects.size(); i++) {
|
||||
if (m_Objects[i].m_Name == name) {
|
||||
return &m_Objects[i];
|
||||
for (size_t i = 0; i < objects.size(); i++) {
|
||||
if (objects[i].m_Name == name) {
|
||||
return &objects[i];
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -350,7 +340,7 @@ std::string VanityUtilities::ParseMarkdown(const std::string& file) {
|
||||
// Read the file into a string
|
||||
std::ifstream t(file);
|
||||
std::stringstream output;
|
||||
// If the file does not exist, return an empty string.
|
||||
// If the file does not exist, return a useful error.
|
||||
if (!t.good()) {
|
||||
output << "File ";
|
||||
output << file.substr(file.rfind("/") + 1);
|
||||
@@ -408,13 +398,13 @@ std::string VanityUtilities::ParseMarkdown(const std::string& file) {
|
||||
return output.str();
|
||||
}
|
||||
|
||||
void VanityUtilities::SetupNPCTalk(Entity* npc) {
|
||||
void SetupNPCTalk(Entity* npc) {
|
||||
npc->AddCallbackTimer(15.0f, [npc]() { NPCTalk(npc); });
|
||||
|
||||
npc->SetProximityRadius(20.0f, "talk");
|
||||
}
|
||||
|
||||
void VanityUtilities::NPCTalk(Entity* npc) {
|
||||
void NPCTalk(Entity* npc) {
|
||||
auto* proximityMonitorComponent = npc->GetComponent<ProximityMonitorComponent>();
|
||||
|
||||
if (!proximityMonitorComponent->GetProximityObjects("talk").empty()) {
|
||||
|
||||
@@ -5,58 +5,30 @@
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
struct VanityObjectLocation
|
||||
{
|
||||
struct VanityObjectLocation {
|
||||
float m_Chance = 1.0f;
|
||||
NiPoint3 m_Position;
|
||||
NiQuaternion m_Rotation;
|
||||
float m_Scale = 1.0f;
|
||||
};
|
||||
|
||||
struct VanityObject
|
||||
{
|
||||
struct VanityObject {
|
||||
LWOOBJID m_ID = LWOOBJID_EMPTY;
|
||||
std::string m_Name;
|
||||
LOT m_LOT;
|
||||
LOT m_LOT = LOT_NULL;
|
||||
std::vector<LOT> m_Equipment;
|
||||
std::vector<std::string> m_Phrases;
|
||||
std::string m_Script;
|
||||
std::map<uint32_t, std::vector<VanityObjectLocation>> m_Locations;
|
||||
std::vector<LDFBaseData*> m_Config;
|
||||
};
|
||||
|
||||
|
||||
class VanityUtilities
|
||||
{
|
||||
public:
|
||||
static void SpawnVanity();
|
||||
namespace VanityUtilities {
|
||||
void SpawnVanity();
|
||||
|
||||
static Entity* SpawnObject(
|
||||
const VanityObject& object,
|
||||
const VanityObjectLocation& location
|
||||
);
|
||||
VanityObject* GetObject(const std::string& name);
|
||||
|
||||
static LWOOBJID SpawnSpawner(
|
||||
const VanityObject& object,
|
||||
const VanityObjectLocation& location
|
||||
);
|
||||
|
||||
static std::string ParseMarkdown(
|
||||
std::string ParseMarkdown(
|
||||
const std::string& file
|
||||
);
|
||||
|
||||
static void ParseXML(
|
||||
const std::string& file
|
||||
);
|
||||
|
||||
static VanityObject* GetObject(const std::string& name);
|
||||
|
||||
private:
|
||||
static void SetupNPCTalk(Entity* npc);
|
||||
|
||||
static void NPCTalk(Entity* npc);
|
||||
|
||||
static std::vector<VanityObject> m_Objects;
|
||||
|
||||
static std::set<std::string> m_LoadedFiles;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user