mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-15 04:38:21 +00:00
script comp
This commit is contained in:
parent
771eb65b92
commit
eebf484c4e
@ -1,7 +1,6 @@
|
|||||||
#include "CDScriptComponentTable.h"
|
#include "CDScriptComponentTable.h"
|
||||||
|
|
||||||
void CDScriptComponentTable::LoadValuesFromDatabase() {
|
void CDScriptComponentTable::LoadValuesFromDatabase() {
|
||||||
|
|
||||||
// First, get the size of the table
|
// First, get the size of the table
|
||||||
unsigned int size = 0;
|
unsigned int size = 0;
|
||||||
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM ScriptComponent");
|
auto tableSize = CDClientDatabase::ExecuteQuery("SELECT COUNT(*) FROM ScriptComponent");
|
||||||
@ -28,12 +27,8 @@ void CDScriptComponentTable::LoadValuesFromDatabase() {
|
|||||||
tableData.finalize();
|
tableData.finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
const CDScriptComponent& CDScriptComponentTable::GetByID(unsigned int id) {
|
const std::optional<CDScriptComponent> CDScriptComponentTable::GetByID(unsigned int id) {
|
||||||
std::map<unsigned int, CDScriptComponent>::iterator it = this->entries.find(id);
|
std::map<unsigned int, CDScriptComponent>::iterator it = this->entries.find(id);
|
||||||
if (it != this->entries.end()) {
|
return (it != this->entries.end()) ? std::make_optional<CDScriptComponent>(it->second) : std::nullopt;
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_ToReturnWhenNoneFound;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,11 +12,9 @@ struct CDScriptComponent {
|
|||||||
class CDScriptComponentTable : public CDTable<CDScriptComponentTable> {
|
class CDScriptComponentTable : public CDTable<CDScriptComponentTable> {
|
||||||
private:
|
private:
|
||||||
std::map<unsigned int, CDScriptComponent> entries;
|
std::map<unsigned int, CDScriptComponent> entries;
|
||||||
CDScriptComponent m_ToReturnWhenNoneFound;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void LoadValuesFromDatabase();
|
void LoadValuesFromDatabase();
|
||||||
// Gets an entry by scriptID
|
// Gets an entry by scriptID
|
||||||
const CDScriptComponent& GetByID(unsigned int id);
|
const std::optional<CDScriptComponent> GetByID(unsigned int id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -463,9 +463,11 @@ void Entity::Initialize() {
|
|||||||
if (scriptComponentID > 0 || m_Character) {
|
if (scriptComponentID > 0 || m_Character) {
|
||||||
std::string clientScriptName;
|
std::string clientScriptName;
|
||||||
if (!m_Character) {
|
if (!m_Character) {
|
||||||
CDScriptComponent scriptCompData = scriptCompTable->GetByID(scriptComponentID);
|
auto scriptCompData = scriptCompTable->GetByID(scriptComponentID);
|
||||||
scriptName = scriptCompData.script_name;
|
if (scriptCompData) {
|
||||||
clientScriptName = scriptCompData.client_script_name;
|
scriptName = scriptCompData->script_name;
|
||||||
|
clientScriptName = scriptCompData->client_script_name;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
scriptName = "";
|
scriptName = "";
|
||||||
}
|
}
|
||||||
@ -510,12 +512,13 @@ void Entity::Initialize() {
|
|||||||
|
|
||||||
if (zoneData) {
|
if (zoneData) {
|
||||||
int zoneScriptID = zoneData->scriptID;
|
int zoneScriptID = zoneData->scriptID;
|
||||||
CDScriptComponent zoneScriptData = scriptCompTable->GetByID(zoneScriptID);
|
auto zoneScriptData = scriptCompTable->GetByID(zoneScriptID);
|
||||||
|
if (zoneScriptData) {
|
||||||
ScriptComponent* comp = new ScriptComponent(this, zoneScriptData.script_name, true);
|
ScriptComponent* comp = new ScriptComponent(this, zoneScriptData->script_name, true);
|
||||||
m_Components.insert(std::make_pair(eReplicaComponentType::SCRIPT, comp));
|
m_Components.insert(std::make_pair(eReplicaComponentType::SCRIPT, comp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SKILL, -1) != -1 || m_Character) {
|
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SKILL, -1) != -1 || m_Character) {
|
||||||
SkillComponent* comp = new SkillComponent(this);
|
SkillComponent* comp = new SkillComponent(this);
|
||||||
|
@ -933,8 +933,9 @@ void InventoryComponent::EquipScripts(Item* equippedItem) {
|
|||||||
int32_t scriptComponentID = compRegistryTable->GetByIDAndType(equippedItem->GetLot(), eReplicaComponentType::SCRIPT, -1);
|
int32_t scriptComponentID = compRegistryTable->GetByIDAndType(equippedItem->GetLot(), eReplicaComponentType::SCRIPT, -1);
|
||||||
if (scriptComponentID > -1) {
|
if (scriptComponentID > -1) {
|
||||||
CDScriptComponentTable* scriptCompTable = CDClientManager::Instance().GetTable<CDScriptComponentTable>();
|
CDScriptComponentTable* scriptCompTable = CDClientManager::Instance().GetTable<CDScriptComponentTable>();
|
||||||
CDScriptComponent scriptCompData = scriptCompTable->GetByID(scriptComponentID);
|
auto scriptCompData = scriptCompTable->GetByID(scriptComponentID);
|
||||||
auto* itemScript = CppScripts::GetScript(m_Parent, scriptCompData.script_name);
|
if (!scriptCompData) return;
|
||||||
|
auto* itemScript = CppScripts::GetScript(m_Parent, scriptCompData->script_name);
|
||||||
if (!itemScript) {
|
if (!itemScript) {
|
||||||
Game::logger->Log("InventoryComponent", "null script?");
|
Game::logger->Log("InventoryComponent", "null script?");
|
||||||
}
|
}
|
||||||
@ -948,8 +949,9 @@ void InventoryComponent::UnequipScripts(Item* unequippedItem) {
|
|||||||
int32_t scriptComponentID = compRegistryTable->GetByIDAndType(unequippedItem->GetLot(), eReplicaComponentType::SCRIPT, -1);
|
int32_t scriptComponentID = compRegistryTable->GetByIDAndType(unequippedItem->GetLot(), eReplicaComponentType::SCRIPT, -1);
|
||||||
if (scriptComponentID > -1) {
|
if (scriptComponentID > -1) {
|
||||||
CDScriptComponentTable* scriptCompTable = CDClientManager::Instance().GetTable<CDScriptComponentTable>();
|
CDScriptComponentTable* scriptCompTable = CDClientManager::Instance().GetTable<CDScriptComponentTable>();
|
||||||
CDScriptComponent scriptCompData = scriptCompTable->GetByID(scriptComponentID);
|
auto scriptCompData = scriptCompTable->GetByID(scriptComponentID);
|
||||||
auto* itemScript = CppScripts::GetScript(m_Parent, scriptCompData.script_name);
|
if (!scriptCompData) return;
|
||||||
|
auto* itemScript = CppScripts::GetScript(m_Parent, scriptCompData->script_name);
|
||||||
if (!itemScript) {
|
if (!itemScript) {
|
||||||
Game::logger->Log("InventoryComponent", "null script?");
|
Game::logger->Log("InventoryComponent", "null script?");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user