mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-05 18:24:12 +00:00
Split out Level progression component (#671)
* Split out Level progression component from Character Component This is to get to the Player forced movement Comp in a sane way * move XML to component insted of abusing charComp * use overrides should probably make everything that calls that call it correctly * fix linking issue
This commit is contained in:
@@ -7,6 +7,7 @@ set(DGAME_DCOMPONENTS_SOURCES "BaseCombatAIComponent.cpp"
|
||||
"ControllablePhysicsComponent.cpp"
|
||||
"DestroyableComponent.cpp"
|
||||
"InventoryComponent.cpp"
|
||||
"LevelProgressionComponent.cpp"
|
||||
"LUPExhibitComponent.cpp"
|
||||
"MissionComponent.cpp"
|
||||
"MissionOfferComponent.cpp"
|
||||
|
@@ -21,7 +21,6 @@ CharacterComponent::CharacterComponent(Entity* parent, Character* character) : C
|
||||
m_IsGM = false;
|
||||
m_IsLanding = false;
|
||||
m_IsLEGOClubMember = true;
|
||||
m_Level = 1;
|
||||
|
||||
m_DirtyCurrentActivity = false;
|
||||
m_DirtyGMInfo = false;
|
||||
@@ -80,8 +79,6 @@ CharacterComponent::~CharacterComponent() {
|
||||
}
|
||||
|
||||
void CharacterComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
outBitStream->Write1();
|
||||
outBitStream->Write(m_Level);
|
||||
outBitStream->Write0();
|
||||
|
||||
if (bIsInitialUpdate) {
|
||||
@@ -181,57 +178,6 @@ void CharacterComponent::SetPvpEnabled(const bool value)
|
||||
m_PvpEnabled = value;
|
||||
}
|
||||
|
||||
void CharacterComponent::HandleLevelUp()
|
||||
{
|
||||
auto* rewardsTable = CDClientManager::Instance()->GetTable<CDRewardsTable>("Rewards");
|
||||
|
||||
const auto& rewards = rewardsTable->GetByLevelID(m_Level);
|
||||
bool rewardingItem = rewards.size() > 0;
|
||||
|
||||
auto* parent = m_Character->GetEntity();
|
||||
|
||||
if (parent == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto* inventoryComponent = parent->GetComponent<InventoryComponent>();
|
||||
auto* controllablePhysicsComponent = parent->GetComponent<ControllablePhysicsComponent>();
|
||||
|
||||
if (inventoryComponent == nullptr || controllablePhysicsComponent == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Tell the client we beginning to send level rewards.
|
||||
if(rewardingItem) GameMessages::NotifyLevelRewards(parent->GetObjectID(), parent->GetSystemAddress(), m_Level, rewardingItem);
|
||||
|
||||
for (auto* reward : rewards)
|
||||
{
|
||||
switch (reward->rewardType)
|
||||
{
|
||||
case 0:
|
||||
inventoryComponent->AddItem(reward->value, reward->count, eLootSourceType::LOOT_SOURCE_LEVEL_REWARD);
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
auto* items = inventoryComponent->GetInventory(eInventoryType::ITEMS);
|
||||
items->SetSize(items->GetSize() + reward->value);
|
||||
}
|
||||
break;
|
||||
case 9:
|
||||
controllablePhysicsComponent->SetSpeedMultiplier(static_cast<float>(reward->value) / 500.0f);
|
||||
break;
|
||||
case 11:
|
||||
case 12:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Tell the client we have finished sending level rewards.
|
||||
if(rewardingItem) GameMessages::NotifyLevelRewards(parent->GetObjectID(), parent->GetSystemAddress(), m_Level, !rewardingItem);
|
||||
}
|
||||
|
||||
void CharacterComponent::SetGMLevel(int gmlevel) {
|
||||
m_DirtyGMInfo = true;
|
||||
if (gmlevel > 0) m_IsGM = true;
|
||||
@@ -332,14 +278,6 @@ void CharacterComponent::LoadFromXML() {
|
||||
}
|
||||
}
|
||||
|
||||
tinyxml2::XMLElement* level = doc->FirstChildElement("obj")->FirstChildElement("lvl");
|
||||
if (!level) {
|
||||
Game::logger->Log("CharacterComponent", "Failed to find lvl tag while loading XML!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
level->QueryAttribute("l", &m_Level);
|
||||
|
||||
if (character->FindAttribute("time")) {
|
||||
character->QueryUnsigned64Attribute("time", &m_TotalTimePlayed);
|
||||
} else {
|
||||
@@ -419,14 +357,6 @@ void CharacterComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
// End custom attributes
|
||||
//
|
||||
|
||||
tinyxml2::XMLElement* level = doc->FirstChildElement("obj")->FirstChildElement("lvl");
|
||||
if (!level) {
|
||||
Game::logger->Log("CharacterComponent", "Failed to find lvl tag while updating XML!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
level->SetAttribute("l", m_Level);
|
||||
|
||||
auto newUpdateTimestamp = std::time(nullptr);
|
||||
Game::logger->Log("TotalTimePlayed", "Time since last save: %d\n", newUpdateTimestamp - m_LastUpdateTimestamp);
|
||||
|
||||
|
@@ -95,18 +95,6 @@ public:
|
||||
*/
|
||||
void RocketUnEquip(Entity* player);
|
||||
|
||||
/**
|
||||
* Gets the current level of the entity
|
||||
* @return the current level of the entity
|
||||
*/
|
||||
const uint32_t GetLevel() const { return m_Level; }
|
||||
|
||||
/**
|
||||
* Sets the level of the entity
|
||||
* @param level the level to set
|
||||
*/
|
||||
void SetLevel(uint32_t level) { m_Level = level; }
|
||||
|
||||
/**
|
||||
* Gets the universe score of the entity
|
||||
* @return the universe score of the entity
|
||||
@@ -191,11 +179,6 @@ public:
|
||||
*/
|
||||
void SetMountItemID(LWOOBJID mountItemID) { m_MountItemID = mountItemID; }
|
||||
|
||||
/**
|
||||
* Gives the player rewards for the last level that they leveled up from
|
||||
*/
|
||||
void HandleLevelUp();
|
||||
|
||||
/**
|
||||
* Gets the name of this character
|
||||
* @return the name of this character
|
||||
@@ -323,11 +306,6 @@ private:
|
||||
*/
|
||||
uint8_t m_PossessableType = 1;
|
||||
|
||||
/**
|
||||
* Level of the entity
|
||||
*/
|
||||
uint32_t m_Level;
|
||||
|
||||
/**
|
||||
* Universe score of the entity
|
||||
*/
|
||||
|
74
dGame/dComponents/LevelProgressionComponent.cpp
Normal file
74
dGame/dComponents/LevelProgressionComponent.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#include "LevelProgressionComponent.h"
|
||||
#include "ControllablePhysicsComponent.h"
|
||||
#include "InventoryComponent.h"
|
||||
#include "CharacterComponent.h"
|
||||
#include "tinyxml2.h"
|
||||
|
||||
LevelProgressionComponent::LevelProgressionComponent(Entity* parent) : Component(parent) {
|
||||
m_Parent = parent;
|
||||
m_Level = 1;
|
||||
}
|
||||
|
||||
void LevelProgressionComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
tinyxml2::XMLElement* level = doc->FirstChildElement("obj")->FirstChildElement("lvl");
|
||||
if (!level) {
|
||||
Game::logger->Log("LevelProgressionComponent", "Failed to find lvl tag while updating XML!\n");
|
||||
return;
|
||||
}
|
||||
level->SetAttribute("l", m_Level);
|
||||
|
||||
}
|
||||
|
||||
void LevelProgressionComponent::LoadFromXml(tinyxml2::XMLDocument* doc){
|
||||
tinyxml2::XMLElement* level = doc->FirstChildElement("obj")->FirstChildElement("lvl");
|
||||
if (!level) {
|
||||
Game::logger->Log("LevelProgressionComponent", "Failed to find lvl tag while loading XML!\n");
|
||||
return;
|
||||
}
|
||||
level->QueryAttribute("l", &m_Level);
|
||||
|
||||
}
|
||||
|
||||
void LevelProgressionComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags){
|
||||
outBitStream->Write(bIsInitialUpdate || m_DirtyLevelInfo);
|
||||
if (bIsInitialUpdate || m_DirtyLevelInfo) outBitStream->Write(m_Level);
|
||||
m_DirtyLevelInfo = false;
|
||||
}
|
||||
|
||||
void LevelProgressionComponent::HandleLevelUp() {
|
||||
auto* rewardsTable = CDClientManager::Instance()->GetTable<CDRewardsTable>("Rewards");
|
||||
|
||||
const auto& rewards = rewardsTable->GetByLevelID(m_Level);
|
||||
bool rewardingItem = rewards.size() > 0;
|
||||
|
||||
auto* inventoryComponent = m_Parent->GetComponent<InventoryComponent>();
|
||||
auto* controllablePhysicsComponent = m_Parent->GetComponent<ControllablePhysicsComponent>();
|
||||
|
||||
if (!inventoryComponent || !controllablePhysicsComponent) return;
|
||||
// Tell the client we beginning to send level rewards.
|
||||
if(rewardingItem) GameMessages::NotifyLevelRewards(m_Parent->GetObjectID(), m_Parent->GetSystemAddress(), m_Level, rewardingItem);
|
||||
|
||||
for (auto* reward : rewards) {
|
||||
switch (reward->rewardType) {
|
||||
case 0:
|
||||
inventoryComponent->AddItem(reward->value, reward->count, eLootSourceType::LOOT_SOURCE_LEVEL_REWARD);
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
auto* items = inventoryComponent->GetInventory(eInventoryType::ITEMS);
|
||||
items->SetSize(items->GetSize() + reward->value);
|
||||
}
|
||||
break;
|
||||
case 9:
|
||||
controllablePhysicsComponent->SetSpeedMultiplier(static_cast<float>(reward->value) / 500.0f);
|
||||
break;
|
||||
case 11:
|
||||
case 12:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Tell the client we have finished sending level rewards.
|
||||
if(rewardingItem) GameMessages::NotifyLevelRewards(m_Parent->GetObjectID(), m_Parent->GetSystemAddress(), m_Level, !rewardingItem);
|
||||
}
|
63
dGame/dComponents/LevelProgressionComponent.h
Normal file
63
dGame/dComponents/LevelProgressionComponent.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include "Entity.h"
|
||||
#include "GameMessages.h"
|
||||
#include "Component.h"
|
||||
|
||||
/**
|
||||
* Component that handles level progression and serilization.
|
||||
*
|
||||
*/
|
||||
class LevelProgressionComponent : public Component {
|
||||
public:
|
||||
static const uint32_t ComponentType = eReplicaComponentType::COMPONENT_TYPE_LEVEL_PROGRESSION;
|
||||
|
||||
/**
|
||||
* Constructor for this component
|
||||
* @param parent parent that contains this component
|
||||
*/
|
||||
LevelProgressionComponent(Entity* parent);
|
||||
~LevelProgressionComponent() override {};
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
|
||||
/**
|
||||
* Save data from this componennt to character XML
|
||||
* @param doc the document to write data to
|
||||
*/
|
||||
void UpdateXml(tinyxml2::XMLDocument* doc) override;
|
||||
|
||||
/**
|
||||
* Load base data for this component from character XML
|
||||
* @param doc the document to read data from
|
||||
*/
|
||||
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
|
||||
|
||||
/**
|
||||
* Gets the current level of the entity
|
||||
* @return the current level of the entity
|
||||
*/
|
||||
const uint32_t GetLevel() const { return m_Level; }
|
||||
|
||||
/**
|
||||
* Sets the level of the entity
|
||||
* @param level the level to set
|
||||
*/
|
||||
void SetLevel(uint32_t level) { m_Level = level; m_DirtyLevelInfo = true; }
|
||||
|
||||
/**
|
||||
* Gives the player rewards for the last level that they leveled up from
|
||||
*/
|
||||
void HandleLevelUp();
|
||||
|
||||
private:
|
||||
/**
|
||||
* whether the level is dirty
|
||||
*/
|
||||
bool m_DirtyLevelInfo = false;
|
||||
|
||||
/**
|
||||
* Level of the entity
|
||||
*/
|
||||
uint32_t m_Level;
|
||||
};
|
Reference in New Issue
Block a user