mirror of
				https://github.com/DarkflameUniverse/DarkflameServer.git
				synced 2025-11-03 22:21:59 +00:00 
			
		
		
		
	Added fallback to default values if CDClient data cannot be loaded
This commit is contained in:
		@@ -1,24 +1,45 @@
 | 
			
		||||
#include "CDPetComponentTable.h"
 | 
			
		||||
 | 
			
		||||
namespace {
 | 
			
		||||
	// Default entries for fallback
 | 
			
		||||
	CDPetComponent defaultEntry {
 | 
			
		||||
		.id = static_cast<unsigned int>(-1),
 | 
			
		||||
		UNUSED_DEFAULT(.minTameUpdateTime = 60.0f,)
 | 
			
		||||
		UNUSED_DEFAULT(.maxTameUpdateTime = 300.0f,)
 | 
			
		||||
		UNUSED_DEFAULT(.percentTameChance = 101.0f,)
 | 
			
		||||
		UNUSED_DEFAULT(.tameability = 100.0f,)
 | 
			
		||||
		UNUSED_DEFAULT(.elementType = 1,)
 | 
			
		||||
		.walkSpeed = 2.5f,
 | 
			
		||||
		.runSpeed = 5.0f,
 | 
			
		||||
		.sprintSpeed = 10.0f,
 | 
			
		||||
		UNUSED_DEFAULT(.idleTimeMin = 60.0f,)
 | 
			
		||||
		UNUSED_DEFAULT(.idleTimeMax = 300.0f,)
 | 
			
		||||
		UNUSED_DEFAULT(.petForm = 0,)
 | 
			
		||||
		.imaginationDrainRate = 60.0f,
 | 
			
		||||
		UNUSED_DEFAULT(.AudioMetaEventSet = "",)
 | 
			
		||||
		UNUSED_DEFAULT(.buffIDs = "",)
 | 
			
		||||
	};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CDPetComponentTable::LoadValuesFromDatabase() {
 | 
			
		||||
	auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM PetComponent");
 | 
			
		||||
	while (!tableData.eof()) {
 | 
			
		||||
		CDPetComponent entry;
 | 
			
		||||
		entry.id = tableData.getIntField("id", -1);
 | 
			
		||||
		UNUSED_COLUMN(entry.minTameUpdateTime = tableData.getFloatField("minTameUpdateTime", 60.0f);)
 | 
			
		||||
		UNUSED_COLUMN(entry.maxTameUpdateTime = tableData.getFloatField("maxTameUpdateTime", 300.0f);)
 | 
			
		||||
		UNUSED_COLUMN(entry.percentTameChance = tableData.getFloatField("percentTameChance", 101.0f);)
 | 
			
		||||
		UNUSED_COLUMN(entry.tameability = tableData.getFloatField("tamability", 100.0f);) // Mispelled as "tamability" in CDClient
 | 
			
		||||
		UNUSED_COLUMN(entry.elementType = tableData.getIntField("elementType", 1);)
 | 
			
		||||
		entry.walkSpeed = tableData.getFloatField("walkSpeed", 2.5f);
 | 
			
		||||
		entry.runSpeed = tableData.getFloatField("runSpeed", 5.0f);
 | 
			
		||||
		entry.sprintSpeed = tableData.getFloatField("sprintSpeed", 10.0f);
 | 
			
		||||
		UNUSED_COLUMN(entry.idleTimeMin = tableData.getFloatField("idleTimeMin", 60.0f);)
 | 
			
		||||
		UNUSED_COLUMN(entry.idleTimeMax = tableData.getFloatField("idleTimeMax", 300.0f);)
 | 
			
		||||
		entry.id = tableData.getIntField("id", defaultEntry.id);
 | 
			
		||||
		UNUSED_COLUMN(entry.minTameUpdateTime = tableData.getFloatField("minTameUpdateTime", defaultEntry.minTameUpdateTime);)
 | 
			
		||||
		UNUSED_COLUMN(entry.maxTameUpdateTime = tableData.getFloatField("maxTameUpdateTime", defaultEntry.maxTameUpdateTime);)
 | 
			
		||||
		UNUSED_COLUMN(entry.percentTameChance = tableData.getFloatField("percentTameChance", defaultEntry.percentTameChance);)
 | 
			
		||||
		UNUSED_COLUMN(entry.tameability = tableData.getFloatField("tamability", defaultEntry.tameability);) // Mispelled as "tamability" in CDClient
 | 
			
		||||
		UNUSED_COLUMN(entry.elementType = tableData.getIntField("elementType", defaultEntry.elementType);)
 | 
			
		||||
		entry.walkSpeed = tableData.getFloatField("walkSpeed", defaultEntry.walkSpeed);
 | 
			
		||||
		entry.runSpeed = tableData.getFloatField("runSpeed", defaultEntry.runSpeed);
 | 
			
		||||
		entry.sprintSpeed = tableData.getFloatField("sprintSpeed", defaultEntry.sprintSpeed);
 | 
			
		||||
		UNUSED_COLUMN(entry.idleTimeMin = tableData.getFloatField("idleTimeMin", defaultEntry.idleTimeMin);)
 | 
			
		||||
		UNUSED_COLUMN(entry.idleTimeMax = tableData.getFloatField("idleTimeMax", defaultEntry.idleTimeMax);)
 | 
			
		||||
		UNUSED_COLUMN(entry.petForm = tableData.getIntField("petForm", 0);)
 | 
			
		||||
		entry.imaginationDrainRate = tableData.getFloatField("imaginationDrainRate", 60.0f);
 | 
			
		||||
		UNUSED_COLUMN(entry.AudioMetaEventSet = tableData.getStringField("AudioMetaEventSet", "");)
 | 
			
		||||
		UNUSED_COLUMN(entry.buffIDs = tableData.getStringField("buffIDs", "");)
 | 
			
		||||
		entry.imaginationDrainRate = tableData.getFloatField("imaginationDrainRate", defaultEntry.imaginationDrainRate);
 | 
			
		||||
		UNUSED_COLUMN(entry.AudioMetaEventSet = tableData.getStringField("AudioMetaEventSet", defaultEntry.AudioMetaEventSet);)
 | 
			
		||||
		UNUSED_COLUMN(entry.buffIDs = tableData.getStringField("buffIDs", defaultEntry.buffIDs);)
 | 
			
		||||
 | 
			
		||||
		m_entries.insert(std::make_pair(entry.id, entry));
 | 
			
		||||
		tableData.nextRow();
 | 
			
		||||
@@ -30,6 +51,9 @@ void CDPetComponentTable::LoadValuesFromDatabase() {
 | 
			
		||||
 | 
			
		||||
CDPetComponent& CDPetComponentTable::GetByID(unsigned int componentID) {
 | 
			
		||||
	auto itr = m_entries.find(componentID);
 | 
			
		||||
	if (itr == m_entries.end()) throw std::exception(); // TODO: Use a default set of values instead?
 | 
			
		||||
	if (itr == m_entries.end()) {
 | 
			
		||||
		LOG("Unable to load pet component (ID %i) values from database! Using default values instead.", componentID);
 | 
			
		||||
		return defaultEntry;
 | 
			
		||||
	}
 | 
			
		||||
	return itr->second;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -23,6 +23,9 @@
 | 
			
		||||
// Enable this to skip some unused columns in some tables
 | 
			
		||||
#define UNUSED_COLUMN(v)
 | 
			
		||||
 | 
			
		||||
// Use this to skip unused defaults for unused columns in some tables
 | 
			
		||||
#define UNUSED_DEFAULT(v, x)
 | 
			
		||||
 | 
			
		||||
#pragma warning (disable : 4244) //Disable double to float conversion warnings
 | 
			
		||||
#pragma warning (disable : 4715) //Disable "not all control paths return a value"
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -73,6 +73,38 @@ std::map<LOT, int32_t> PetComponent::petFlags = {
 | 
			
		||||
		{ 13067, 838 }, // Skeleton dragon
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
PetComponent::PetComponent(Entity* parentEntity, uint32_t componentId) : Component{ parentEntity },
 | 
			
		||||
	m_PetInfo{ CDClientManager::Instance().GetTable<CDPetComponentTable>()->GetByID(componentId) } {
 | 
			
		||||
	m_ComponentId = componentId;
 | 
			
		||||
	m_Interaction = LWOOBJID_EMPTY;
 | 
			
		||||
	m_InteractType = PetInteractType::none;
 | 
			
		||||
	m_Owner = LWOOBJID_EMPTY;
 | 
			
		||||
	m_ModerationStatus = 0;
 | 
			
		||||
	m_Tamer = LWOOBJID_EMPTY;
 | 
			
		||||
	m_ModelId = LWOOBJID_EMPTY;
 | 
			
		||||
	m_Timer = 0;
 | 
			
		||||
	m_TimerAway = 0;
 | 
			
		||||
	m_TimerBounce = 0;
 | 
			
		||||
	m_DatabaseId = LWOOBJID_EMPTY;
 | 
			
		||||
	m_Flags = PetFlag::SPAWNING; // Tameable
 | 
			
		||||
	m_Ability = ePetAbilityType::Invalid;
 | 
			
		||||
	m_StartPosition = m_Parent->GetPosition();
 | 
			
		||||
	m_MovementAI = nullptr;
 | 
			
		||||
	m_Preconditions = nullptr;
 | 
			
		||||
 | 
			
		||||
	m_ReadyToInteract = false;
 | 
			
		||||
	SetPetAiState(PetAiState::spawn);
 | 
			
		||||
	SetIsHandlingInteraction(false);
 | 
			
		||||
 | 
			
		||||
	std::string checkPreconditions = GeneralUtils::UTF16ToWTF8(parentEntity->GetVar<std::u16string>(u"CheckPrecondition"));
 | 
			
		||||
 | 
			
		||||
	if (!checkPreconditions.empty()) {
 | 
			
		||||
		SetPreconditions(checkPreconditions);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	m_FollowRadius = 8.0f; //Game::zoneManager->GetPetFollowRadius(); // TODO: FIX THIS TO LOAD DYNAMICALLY
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void PetComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
 | 
			
		||||
	const bool tamed = m_Owner != LWOOBJID_EMPTY;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -68,48 +68,13 @@ class PetComponent : public Component {
 | 
			
		||||
public:
 | 
			
		||||
	inline static const eReplicaComponentType ComponentType = eReplicaComponentType::PET;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Pet information loaded from the CDClientDatabase
 | 
			
		||||
	 */
 | 
			
		||||
	CDPetComponent& m_PetInfo;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * PetComponent constructor
 | 
			
		||||
	 * @param parentEntity The parent entity
 | 
			
		||||
	 * @param componentId The component id
 | 
			
		||||
	*/
 | 
			
		||||
	explicit PetComponent(Entity* parentEntity, uint32_t componentId) : Component{ parentEntity },
 | 
			
		||||
		m_PetInfo{ CDClientManager::Instance().GetTable<CDPetComponentTable>()->GetByID(componentId) } {
 | 
			
		||||
		m_ComponentId = componentId;
 | 
			
		||||
		m_Interaction = LWOOBJID_EMPTY;
 | 
			
		||||
		m_InteractType = PetInteractType::none;
 | 
			
		||||
		m_Owner = LWOOBJID_EMPTY;
 | 
			
		||||
		m_ModerationStatus = 0;
 | 
			
		||||
		m_Tamer = LWOOBJID_EMPTY;
 | 
			
		||||
		m_ModelId = LWOOBJID_EMPTY;
 | 
			
		||||
		m_Timer = 0;
 | 
			
		||||
		m_TimerAway = 0;
 | 
			
		||||
		m_TimerBounce = 0;
 | 
			
		||||
		m_DatabaseId = LWOOBJID_EMPTY;
 | 
			
		||||
		m_Flags = PetFlag::SPAWNING; // Tameable
 | 
			
		||||
		m_Ability = ePetAbilityType::Invalid;
 | 
			
		||||
		m_StartPosition = m_Parent->GetPosition();
 | 
			
		||||
		m_MovementAI = nullptr;
 | 
			
		||||
		m_Preconditions = nullptr;
 | 
			
		||||
 | 
			
		||||
		m_ReadyToInteract = false;
 | 
			
		||||
		SetPetAiState(PetAiState::spawn);
 | 
			
		||||
		SetIsHandlingInteraction(false);
 | 
			
		||||
 | 
			
		||||
		std::string checkPreconditions = GeneralUtils::UTF16ToWTF8(parentEntity->GetVar<std::u16string>(u"CheckPrecondition"));
 | 
			
		||||
 | 
			
		||||
		if (!checkPreconditions.empty()) {
 | 
			
		||||
			SetPreconditions(checkPreconditions);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		m_FollowRadius = 8.0f; //Game::zoneManager->GetPetFollowRadius(); // TODO: FIX THIS TO LOAD DYNAMICALLY
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	explicit PetComponent(Entity* parentEntity, uint32_t componentId);
 | 
			
		||||
	
 | 
			
		||||
	~PetComponent() override;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
@@ -615,6 +580,11 @@ private:
 | 
			
		||||
	 * Preconditions that need to be met before an entity can tame this pet
 | 
			
		||||
	 */
 | 
			
		||||
	PreconditionExpression* m_Preconditions;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Pet information loaded from the CDClientDatabase
 | 
			
		||||
	 */
 | 
			
		||||
	CDPetComponent& m_PetInfo;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // PETCOMPONENT_H
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user