mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-06 10:44:08 +00:00
Remove multiple Script syntax (#1496)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "NtCombatChallengeDummy.h"
|
||||
#include "EntityManager.h"
|
||||
#include "Entity.h"
|
||||
|
||||
void NtCombatChallengeDummy::OnDie(Entity* self, Entity* killer) {
|
||||
const auto challengeObjectID = self->GetVar<LWOOBJID>(u"challengeObjectID");
|
||||
@@ -7,9 +8,7 @@ void NtCombatChallengeDummy::OnDie(Entity* self, Entity* killer) {
|
||||
auto* challengeObject = Game::entityManager->GetEntity(challengeObjectID);
|
||||
|
||||
if (challengeObject != nullptr) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(challengeObject)) {
|
||||
script->OnDie(challengeObject, killer);
|
||||
}
|
||||
challengeObject->GetScript()->OnDie(challengeObject, killer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +18,6 @@ void NtCombatChallengeDummy::OnHitOrHealResult(Entity* self, Entity* attacker, i
|
||||
auto* challengeObject = Game::entityManager->GetEntity(challengeObjectID);
|
||||
|
||||
if (challengeObject != nullptr) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(challengeObject)) {
|
||||
script->OnHitOrHealResult(challengeObject, attacker, damage);
|
||||
}
|
||||
challengeObject->GetScript()->OnHitOrHealResult(challengeObject, attacker, damage);
|
||||
}
|
||||
}
|
||||
|
@@ -9,9 +9,7 @@ void NtCombatChallengeExplodingDummy::OnDie(Entity* self, Entity* killer) {
|
||||
auto* challengeObject = Game::entityManager->GetEntity(challengeObjectID);
|
||||
|
||||
if (challengeObject != nullptr) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(challengeObject)) {
|
||||
script->OnDie(challengeObject, killer);
|
||||
}
|
||||
challengeObject->GetScript()->OnDie(challengeObject, killer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,9 +30,7 @@ void NtCombatChallengeExplodingDummy::OnHitOrHealResult(Entity* self, Entity* at
|
||||
auto* challengeObject = Game::entityManager->GetEntity(challengeObjectID);
|
||||
|
||||
if (challengeObject != nullptr) {
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(challengeObject)) {
|
||||
script->OnHitOrHealResult(challengeObject, attacker, damage);
|
||||
}
|
||||
challengeObject->GetScript()->OnHitOrHealResult(challengeObject, attacker, damage);
|
||||
}
|
||||
auto skillComponent = self->GetComponent<SkillComponent>();
|
||||
if (skillComponent != nullptr) {
|
||||
|
@@ -11,7 +11,6 @@ set(DSCRIPTS_SOURCES
|
||||
"InvalidScript.cpp"
|
||||
"NPCAddRemoveItem.cpp"
|
||||
"NtFactionSpyServer.cpp"
|
||||
"ScriptComponent.cpp"
|
||||
"ScriptedPowerupSpawner.cpp"
|
||||
"SpawnPetBaseServer.cpp")
|
||||
|
||||
|
@@ -322,16 +322,18 @@
|
||||
#include "WblRobotCitizen.h"
|
||||
|
||||
namespace {
|
||||
InvalidScript* invalidToReturn = new InvalidScript();
|
||||
// This is in the translation unit instead of the header to prevent wierd linker errors
|
||||
InvalidScript* const InvalidToReturn = new InvalidScript();
|
||||
std::map<std::string, CppScripts::Script*> m_Scripts;
|
||||
};
|
||||
|
||||
CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scriptName) {
|
||||
if (m_Scripts.find(scriptName) != m_Scripts.end()) {
|
||||
return m_Scripts[scriptName];
|
||||
CppScripts::Script* const CppScripts::GetScript(Entity* parent, const std::string& scriptName) {
|
||||
auto itr = m_Scripts.find(scriptName);
|
||||
if (itr != m_Scripts.end()) {
|
||||
return itr->second;
|
||||
}
|
||||
|
||||
Script* script = invalidToReturn;
|
||||
Script* script = InvalidToReturn;
|
||||
|
||||
//VE / AG:
|
||||
if (scriptName == "scripts\\ai\\AG\\L_AG_SHIP_PLAYER_DEATH_TRIGGER.lua")
|
||||
@@ -950,7 +952,7 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr
|
||||
|
||||
// handle invalid script reporting if the path is greater than zero and it's not an ignored script
|
||||
// information not really needed for sys admins but is for developers
|
||||
else if (script == invalidToReturn) {
|
||||
else if (script == InvalidToReturn) {
|
||||
if ((scriptName.length() > 0) && !((scriptName == "scripts\\02_server\\Enemy\\General\\L_SUSPEND_LUA_AI.lua") ||
|
||||
(scriptName == "scripts\\02_server\\Enemy\\General\\L_BASE_ENEMY_SPIDERLING.lua") ||
|
||||
(scriptName =="scripts\\ai\\FV\\L_ACT_NINJA_STUDENT.lua") ||
|
||||
@@ -963,13 +965,6 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr
|
||||
return script;
|
||||
}
|
||||
|
||||
std::vector<CppScripts::Script*> CppScripts::GetEntityScripts(Entity* entity) {
|
||||
std::vector<CppScripts::Script*> scripts;
|
||||
std::vector<ScriptComponent*> comps = entity->GetScriptComponents();
|
||||
for (ScriptComponent* scriptComp : comps) {
|
||||
if (scriptComp != nullptr) {
|
||||
scripts.push_back(scriptComp->GetScript());
|
||||
}
|
||||
}
|
||||
return scripts;
|
||||
CppScripts::Script* const CppScripts::GetInvalidScript() {
|
||||
return InvalidToReturn;
|
||||
}
|
||||
|
@@ -357,6 +357,10 @@ namespace CppScripts {
|
||||
virtual void OnRequestActivityExit(Entity* sender, LWOOBJID player, bool canceled){};
|
||||
};
|
||||
|
||||
Script* GetScript(Entity* parent, const std::string& scriptName);
|
||||
std::vector<Script*> GetEntityScripts(Entity* entity);
|
||||
Script* const GetScript(Entity* parent, const std::string& scriptName);
|
||||
|
||||
// Get the invalid script. Would be a static variable of the namespace, but that would be
|
||||
// more cluttery to use. Also this allows us to control where this invalid script is defined and initialized
|
||||
// since we dont want anyone externally modifying it.
|
||||
Script* const GetInvalidScript();
|
||||
};
|
||||
|
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* 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* 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);
|
||||
}
|
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* 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* 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
|
Reference in New Issue
Block a user