mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-06 10:44:08 +00:00
doesnt compile
This commit is contained in:
@@ -36,6 +36,7 @@ set(DGAME_DCOMPONENTS_SOURCES "BaseCombatAIComponent.cpp"
|
||||
"RigidbodyPhantomPhysicsComponent.cpp"
|
||||
"MultiZoneEntranceComponent.cpp"
|
||||
"RocketLaunchpadControlComponent.cpp"
|
||||
"ScriptComponent.cpp"
|
||||
"ScriptedActivityComponent.cpp"
|
||||
"ShootingGalleryComponent.cpp"
|
||||
"SimplePhysicsComponent.cpp"
|
||||
|
72
dGame/dComponents/ScriptComponent.cpp
Normal file
72
dGame/dComponents/ScriptComponent.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Darkflame Universe
|
||||
* Copyright 2018
|
||||
*/
|
||||
|
||||
#include "Entity.h"
|
||||
#include "ScriptComponent.h"
|
||||
#include "CDClientManager.h"
|
||||
#include "CDScriptComponentTable.h"
|
||||
#include "CDZoneTableTable.h"
|
||||
#include "dZoneManager.h"
|
||||
|
||||
ScriptComponent::ScriptComponent(Entity* parent, const std::string& scriptName) : Component(parent) {
|
||||
SetScript(scriptName);
|
||||
}
|
||||
|
||||
void ScriptComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
if (bIsInitialUpdate) {
|
||||
const auto& networkSettings = m_ParentEntity->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* ScriptComponent::GetScript() {
|
||||
return m_Script;
|
||||
}
|
||||
|
||||
void ScriptComponent::SetScript(const std::string& scriptName) {
|
||||
m_Script = CppScripts::GetScript(m_ParentEntity, scriptName);
|
||||
}
|
||||
|
||||
const std::string ScriptComponent::GetScriptName(Entity* parentEntity, const uint32_t componentId) {
|
||||
if (!parentEntity || componentId == 0) return "";
|
||||
// LDF key script overrides script component Id
|
||||
const auto customScriptServer = parentEntity->GetVarAsString(u"custom_script_server");
|
||||
if (!customScriptServer.empty()) return customScriptServer;
|
||||
|
||||
auto* scriptCompTable = CDClientManager::Instance().GetTable<CDScriptComponentTable>();
|
||||
CDScriptComponent scriptCompData = scriptCompTable->GetByID(componentId);
|
||||
return scriptCompData.script_name;
|
||||
}
|
||||
|
||||
const std::string ScriptComponent::GetZoneScriptName(const uint32_t componentId) {
|
||||
auto* zoneTable = CDClientManager::Instance().GetTable<CDZoneTableTable>();
|
||||
const auto zoneID = dZoneManager::Instance()->GetZoneID();
|
||||
const auto* zoneData = zoneTable->Query(zoneID.GetMapID());
|
||||
|
||||
if (!zoneData) return "";
|
||||
|
||||
int zoneScriptID = zoneData->scriptID;
|
||||
if (zoneScriptID == -1) return "";
|
||||
auto* scriptCompTable = CDClientManager::Instance().GetTable<CDScriptComponentTable>();
|
||||
const auto& zoneScriptData = scriptCompTable->GetByID(zoneScriptID);
|
||||
return zoneScriptData.script_name;
|
||||
}
|
53
dGame/dComponents/ScriptComponent.h
Normal file
53
dGame/dComponents/ScriptComponent.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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 : public Component {
|
||||
public:
|
||||
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::SCRIPT;
|
||||
|
||||
ScriptComponent(Entity* parent, const std::string& scriptName);
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
|
||||
/**
|
||||
* Returns the script that's attached to this entity
|
||||
* @return the script that's attached to this entity
|
||||
*/
|
||||
CppScripts::Script* GetScript();
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
// Get the script attached to the provided component id.
|
||||
// LDF key custom_script_server overrides component id script.
|
||||
static const std::string GetScriptName(Entity* parentEntity, const uint32_t componentId = 0);
|
||||
|
||||
static const std::string GetZoneScriptName(const uint32_t componentId);
|
||||
private:
|
||||
|
||||
/**
|
||||
* The script attached to this entity
|
||||
*/
|
||||
CppScripts::Script* m_Script;
|
||||
};
|
||||
|
||||
#endif // SCRIPTCOMPONENT_H
|
Reference in New Issue
Block a user