mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-12-26 15:33:34 +00:00
Finish file
This commit is contained in:
parent
355f4f4df8
commit
2a8f40f8e8
@ -33,7 +33,7 @@ public:
|
|||||||
|
|
||||||
virtual void WriteToPacket(RakNet::BitStream* packet) = 0;
|
virtual void WriteToPacket(RakNet::BitStream* packet) = 0;
|
||||||
|
|
||||||
virtual const std::u16string& GetKey() = 0;
|
virtual const std::u16string& GetKey() const = 0;
|
||||||
|
|
||||||
virtual eLDFType GetValueType() = 0;
|
virtual eLDFType GetValueType() = 0;
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ public:
|
|||||||
/*!
|
/*!
|
||||||
\return The key
|
\return The key
|
||||||
*/
|
*/
|
||||||
const std::u16string& GetKey(void) override { return this->key; }
|
const std::u16string& GetKey(void) const override { return this->key; }
|
||||||
|
|
||||||
//! Gets the LDF Type
|
//! Gets the LDF Type
|
||||||
/*!
|
/*!
|
||||||
|
167
dGame/Entity.cpp
167
dGame/Entity.cpp
@ -1243,18 +1243,12 @@ void Entity::SetObservers(int8_t value) {
|
|||||||
|
|
||||||
void Entity::Sleep() {
|
void Entity::Sleep() {
|
||||||
auto* baseCombatAIComponent = GetComponent<BaseCombatAIComponent>();
|
auto* baseCombatAIComponent = GetComponent<BaseCombatAIComponent>();
|
||||||
|
if (baseCombatAIComponent) baseCombatAIComponent->Sleep();
|
||||||
if (baseCombatAIComponent != nullptr) {
|
|
||||||
baseCombatAIComponent->Sleep();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entity::Wake() {
|
void Entity::Wake() {
|
||||||
auto* baseCombatAIComponent = GetComponent<BaseCombatAIComponent>();
|
auto* baseCombatAIComponent = GetComponent<BaseCombatAIComponent>();
|
||||||
|
if (baseCombatAIComponent) baseCombatAIComponent->Wake();
|
||||||
if (baseCombatAIComponent != nullptr) {
|
|
||||||
baseCombatAIComponent->Wake();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Entity::IsSleeping() const {
|
bool Entity::IsSleeping() const {
|
||||||
@ -1263,173 +1257,164 @@ bool Entity::IsSleeping() const {
|
|||||||
|
|
||||||
|
|
||||||
const NiPoint3& Entity::GetPosition() const {
|
const NiPoint3& Entity::GetPosition() const {
|
||||||
auto* controllable = GetComponent<ControllablePhysicsComponent>();
|
auto* controllablePhysicsComponent = GetComponent<ControllablePhysicsComponent>();
|
||||||
|
|
||||||
if (controllable != nullptr) {
|
if (controllablePhysicsComponent != nullptr) {
|
||||||
return controllable->GetPosition();
|
return controllablePhysicsComponent->GetPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* phantom = GetComponent<PhantomPhysicsComponent>();
|
auto* phantomPhysicsComponent = GetComponent<PhantomPhysicsComponent>();
|
||||||
|
|
||||||
if (phantom != nullptr) {
|
if (phantomPhysicsComponent != nullptr) {
|
||||||
return phantom->GetPosition();
|
return phantomPhysicsComponent->GetPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* simple = GetComponent<SimplePhysicsComponent>();
|
auto* simplePhysicsComponent = GetComponent<SimplePhysicsComponent>();
|
||||||
|
|
||||||
if (simple != nullptr) {
|
if (simplePhysicsComponent != nullptr) {
|
||||||
return simple->GetPosition();
|
return simplePhysicsComponent->GetPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* vehicle = GetComponent<HavokVehiclePhysicsComponent>();
|
auto* vehiclePhysicsComponent = GetComponent<HavokVehiclePhysicsComponent>();
|
||||||
|
|
||||||
if (vehicle != nullptr) {
|
if (vehiclePhysicsComponent != nullptr) {
|
||||||
return vehicle->GetPosition();
|
return vehiclePhysicsComponent->GetPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
return NiPoint3::ZERO;
|
return NiPoint3::ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NiQuaternion& Entity::GetRotation() const {
|
const NiQuaternion& Entity::GetRotation() const {
|
||||||
auto* controllable = GetComponent<ControllablePhysicsComponent>();
|
auto* controllablePhysicsComponent = GetComponent<ControllablePhysicsComponent>();
|
||||||
|
|
||||||
if (controllable != nullptr) {
|
if (controllablePhysicsComponent != nullptr) {
|
||||||
return controllable->GetRotation();
|
return controllablePhysicsComponent->GetRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* phantom = GetComponent<PhantomPhysicsComponent>();
|
auto* phantomPhysicsComponent = GetComponent<PhantomPhysicsComponent>();
|
||||||
|
|
||||||
if (phantom != nullptr) {
|
if (phantomPhysicsComponent != nullptr) {
|
||||||
return phantom->GetRotation();
|
return phantomPhysicsComponent->GetRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* simple = GetComponent<SimplePhysicsComponent>();
|
auto* simplePhysicsComponent = GetComponent<SimplePhysicsComponent>();
|
||||||
|
|
||||||
if (simple != nullptr) {
|
if (simplePhysicsComponent != nullptr) {
|
||||||
return simple->GetRotation();
|
return simplePhysicsComponent->GetRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* vehicle = GetComponent<HavokVehiclePhysicsComponent>();
|
auto* vehiclePhysicsComponent = GetComponent<HavokVehiclePhysicsComponent>();
|
||||||
|
|
||||||
if (vehicle != nullptr) {
|
if (vehiclePhysicsComponent != nullptr) {
|
||||||
return vehicle->GetRotation();
|
return vehiclePhysicsComponent->GetRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
return NiQuaternion::IDENTITY;
|
return NiQuaternion::IDENTITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entity::SetPosition(const NiPoint3& position) {
|
void Entity::SetPosition(const NiPoint3& position) {
|
||||||
auto* controllable = GetComponent<ControllablePhysicsComponent>();
|
auto* controllablePhysicsComponent = GetComponent<ControllablePhysicsComponent>();
|
||||||
|
|
||||||
if (controllable != nullptr) {
|
if (controllablePhysicsComponent != nullptr) {
|
||||||
controllable->SetPosition(position);
|
controllablePhysicsComponent->SetPosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* phantom = GetComponent<PhantomPhysicsComponent>();
|
auto* phantomPhysicsComponent = GetComponent<PhantomPhysicsComponent>();
|
||||||
|
|
||||||
if (phantom != nullptr) {
|
if (phantomPhysicsComponent != nullptr) {
|
||||||
phantom->SetPosition(position);
|
phantomPhysicsComponent->SetPosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* simple = GetComponent<SimplePhysicsComponent>();
|
auto* simplePhysicsComponent = GetComponent<SimplePhysicsComponent>();
|
||||||
|
|
||||||
if (simple != nullptr) {
|
if (simplePhysicsComponent != nullptr) {
|
||||||
simple->SetPosition(position);
|
simplePhysicsComponent->SetPosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* vehicle = GetComponent<HavokVehiclePhysicsComponent>();
|
auto* vehiclePhysicsComponent = GetComponent<HavokVehiclePhysicsComponent>();
|
||||||
|
|
||||||
if (vehicle != nullptr) {
|
if (vehiclePhysicsComponent != nullptr) {
|
||||||
vehicle->SetPosition(position);
|
vehiclePhysicsComponent->SetPosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityManager::Instance()->SerializeEntity(this);
|
EntityManager::Instance()->SerializeEntity(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entity::SetRotation(const NiQuaternion& rotation) {
|
void Entity::SetRotation(const NiQuaternion& rotation) {
|
||||||
auto* controllable = GetComponent<ControllablePhysicsComponent>();
|
auto* controllablePhysicsComponent = GetComponent<ControllablePhysicsComponent>();
|
||||||
|
|
||||||
if (controllable != nullptr) {
|
if (controllablePhysicsComponent != nullptr) {
|
||||||
controllable->SetRotation(rotation);
|
controllablePhysicsComponent->SetRotation(rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* phantom = GetComponent<PhantomPhysicsComponent>();
|
auto* phantomPhysicsComponent = GetComponent<PhantomPhysicsComponent>();
|
||||||
|
|
||||||
if (phantom != nullptr) {
|
if (phantomPhysicsComponent != nullptr) {
|
||||||
phantom->SetRotation(rotation);
|
phantomPhysicsComponent->SetRotation(rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* simple = GetComponent<SimplePhysicsComponent>();
|
auto* simplePhysicsComponent = GetComponent<SimplePhysicsComponent>();
|
||||||
|
|
||||||
if (simple != nullptr) {
|
if (simplePhysicsComponent != nullptr) {
|
||||||
simple->SetRotation(rotation);
|
simplePhysicsComponent->SetRotation(rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* vehicle = GetComponent<HavokVehiclePhysicsComponent>();
|
auto* vehiclePhysicsComponent = GetComponent<HavokVehiclePhysicsComponent>();
|
||||||
|
|
||||||
if (vehicle != nullptr) {
|
if (vehiclePhysicsComponent != nullptr) {
|
||||||
vehicle->SetRotation(rotation);
|
vehiclePhysicsComponent->SetRotation(rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityManager::Instance()->SerializeEntity(this);
|
EntityManager::Instance()->SerializeEntity(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Move to header
|
||||||
bool Entity::GetBoolean(const std::u16string& name) const {
|
bool Entity::GetBoolean(const std::u16string& name) const {
|
||||||
return GetVar<bool>(name);
|
return GetVar<bool>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Move to header
|
||||||
int32_t Entity::GetI32(const std::u16string& name) const {
|
int32_t Entity::GetI32(const std::u16string& name) const {
|
||||||
return GetVar<int32_t>(name);
|
return GetVar<int32_t>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Move to header
|
||||||
int64_t Entity::GetI64(const std::u16string& name) const {
|
int64_t Entity::GetI64(const std::u16string& name) const {
|
||||||
return GetVar<int64_t>(name);
|
return GetVar<int64_t>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Move to header
|
||||||
void Entity::SetBoolean(const std::u16string& name, const bool value) {
|
void Entity::SetBoolean(const std::u16string& name, const bool value) {
|
||||||
SetVar(name, value);
|
SetVar(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Move to header
|
||||||
void Entity::SetI32(const std::u16string& name, const int32_t value) {
|
void Entity::SetI32(const std::u16string& name, const int32_t value) {
|
||||||
SetVar(name, value);
|
SetVar(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Move to header
|
||||||
void Entity::SetI64(const std::u16string& name, const int64_t value) {
|
void Entity::SetI64(const std::u16string& name, const int64_t value) {
|
||||||
SetVar(name, value);
|
SetVar(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Entity::HasVar(const std::u16string& name) const {
|
bool Entity::HasVar(const std::u16string& name) const {
|
||||||
for (auto* data : m_Settings) {
|
auto hasVar = std::find_if(m_Settings.begin(), m_Settings.end(), [&name](const LDFBaseData* data) {
|
||||||
if (data->GetKey() == name) {
|
return data->GetKey() == name;
|
||||||
return true;
|
});
|
||||||
}
|
return hasVar != m_Settings.end();
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Move to header
|
||||||
void Entity::SetNetworkId(const uint16_t id) {
|
void Entity::SetNetworkId(const uint16_t id) {
|
||||||
m_NetworkID = id;
|
m_NetworkID = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<LWOOBJID>& Entity::GetTargetsInPhantom() {
|
std::vector<LWOOBJID>& Entity::GetTargetsInPhantom() {
|
||||||
std::vector<LWOOBJID> valid;
|
auto toRemove = std::remove_if(m_TargetsInPhantom.begin(), m_TargetsInPhantom.end(), [this](const LWOOBJID& id) {
|
||||||
|
return EntityManager::Instance()->GetEntity(id) == nullptr;
|
||||||
// Clean up invalid targets, like disconnected players
|
});
|
||||||
for (auto i = 0u; i < m_TargetsInPhantom.size(); ++i) {
|
m_TargetsInPhantom.erase(toRemove, m_TargetsInPhantom.end());
|
||||||
const auto id = m_TargetsInPhantom.at(i);
|
|
||||||
|
|
||||||
auto* entity = EntityManager::Instance()->GetEntity(id);
|
|
||||||
|
|
||||||
if (entity == nullptr) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
valid.push_back(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_TargetsInPhantom = valid;
|
|
||||||
|
|
||||||
return m_TargetsInPhantom;
|
return m_TargetsInPhantom;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1439,34 +1424,18 @@ void Entity::SendNetworkVar(const std::string& data, const SystemAddress& sysAdd
|
|||||||
|
|
||||||
LDFBaseData* Entity::GetVarData(const std::u16string& name) const {
|
LDFBaseData* Entity::GetVarData(const std::u16string& name) const {
|
||||||
for (auto* data : m_Settings) {
|
for (auto* data : m_Settings) {
|
||||||
if (data == nullptr) {
|
if (data && data->GetKey() == name) return data;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data->GetKey() != name) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Entity::GetVarAsString(const std::u16string& name) const {
|
std::string Entity::GetVarAsString(const std::u16string& name) const {
|
||||||
auto* data = GetVarData(name);
|
auto* data = GetVarData(name);
|
||||||
|
return data ? data->GetValueAsString() : "";
|
||||||
if (data == nullptr) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
return data->GetValueAsString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entity::Resurrect() {
|
void Entity::Resurrect() {
|
||||||
if (IsPlayer()) {
|
if (IsPlayer()) GameMessages::SendResurrect(this);
|
||||||
GameMessages::SendResurrect(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entity::AddToGroups(const std::string& group) {
|
void Entity::AddToGroups(const std::string& group) {
|
||||||
|
Loading…
Reference in New Issue
Block a user