2022-07-24 18:04:02 +00:00
|
|
|
#include "LevelProgressionComponent.h"
|
|
|
|
#include "ControllablePhysicsComponent.h"
|
|
|
|
#include "InventoryComponent.h"
|
|
|
|
#include "CharacterComponent.h"
|
|
|
|
#include "tinyxml2.h"
|
|
|
|
|
2023-03-17 14:36:21 +00:00
|
|
|
#include "CDRewardsTable.h"
|
|
|
|
|
2022-07-24 18:04:02 +00:00
|
|
|
LevelProgressionComponent::LevelProgressionComponent(Entity* parent) : Component(parent) {
|
2023-06-07 01:59:53 +00:00
|
|
|
m_OwningEntity = parent;
|
2022-07-24 18:04:02 +00:00
|
|
|
m_Level = 1;
|
2022-12-19 19:45:50 +00:00
|
|
|
m_SpeedBase = 500.0f;
|
|
|
|
m_CharacterVersion = eCharacterVersion::LIVE;
|
2022-07-24 18:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LevelProgressionComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
|
|
|
tinyxml2::XMLElement* level = doc->FirstChildElement("obj")->FirstChildElement("lvl");
|
|
|
|
if (!level) {
|
2022-07-25 02:26:51 +00:00
|
|
|
Game::logger->Log("LevelProgressionComponent", "Failed to find lvl tag while updating XML!");
|
2022-07-24 18:04:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
level->SetAttribute("l", m_Level);
|
2022-12-19 19:45:50 +00:00
|
|
|
level->SetAttribute("sb", m_SpeedBase);
|
|
|
|
level->SetAttribute("cv", static_cast<uint32_t>(m_CharacterVersion));
|
2022-07-24 18:04:02 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void LevelProgressionComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
|
2022-07-24 18:04:02 +00:00
|
|
|
tinyxml2::XMLElement* level = doc->FirstChildElement("obj")->FirstChildElement("lvl");
|
|
|
|
if (!level) {
|
2022-07-25 02:26:51 +00:00
|
|
|
Game::logger->Log("LevelProgressionComponent", "Failed to find lvl tag while loading XML!");
|
2022-07-24 18:04:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
level->QueryAttribute("l", &m_Level);
|
2022-12-19 19:45:50 +00:00
|
|
|
level->QueryAttribute("sb", &m_SpeedBase);
|
|
|
|
uint32_t characterVersion;
|
|
|
|
level->QueryAttribute("cv", &characterVersion);
|
|
|
|
m_CharacterVersion = static_cast<eCharacterVersion>(characterVersion);
|
2022-07-24 18:04:02 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void LevelProgressionComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
2022-07-24 18:04:02 +00:00
|
|
|
outBitStream->Write(bIsInitialUpdate || m_DirtyLevelInfo);
|
|
|
|
if (bIsInitialUpdate || m_DirtyLevelInfo) outBitStream->Write(m_Level);
|
|
|
|
m_DirtyLevelInfo = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LevelProgressionComponent::HandleLevelUp() {
|
2023-03-17 14:36:21 +00:00
|
|
|
auto* rewardsTable = CDClientManager::Instance().GetTable<CDRewardsTable>();
|
2022-07-24 18:04:02 +00:00
|
|
|
|
|
|
|
const auto& rewards = rewardsTable->GetByLevelID(m_Level);
|
|
|
|
bool rewardingItem = rewards.size() > 0;
|
|
|
|
|
2023-06-07 07:23:50 +00:00
|
|
|
auto inventoryComponent = m_OwningEntity->GetComponent<InventoryComponent>();
|
|
|
|
auto controllablePhysicsComponent = m_OwningEntity->GetComponent<ControllablePhysicsComponent>();
|
2022-07-24 18:04:02 +00:00
|
|
|
|
|
|
|
if (!inventoryComponent || !controllablePhysicsComponent) return;
|
|
|
|
// Tell the client we beginning to send level rewards.
|
2023-06-07 01:59:53 +00:00
|
|
|
if (rewardingItem) GameMessages::NotifyLevelRewards(m_OwningEntity->GetObjectID(), m_OwningEntity->GetSystemAddress(), m_Level, rewardingItem);
|
2022-07-24 18:04:02 +00:00
|
|
|
|
|
|
|
for (auto* reward : rewards) {
|
|
|
|
switch (reward->rewardType) {
|
|
|
|
case 0:
|
2023-05-02 22:39:21 +00:00
|
|
|
inventoryComponent->AddItem(reward->value, reward->count, eLootSourceType::LEVEL_REWARD);
|
2022-07-24 18:04:02 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2022-07-28 13:39:57 +00:00
|
|
|
{
|
|
|
|
auto* items = inventoryComponent->GetInventory(eInventoryType::ITEMS);
|
|
|
|
items->SetSize(items->GetSize() + reward->value);
|
|
|
|
}
|
|
|
|
break;
|
2022-07-24 18:04:02 +00:00
|
|
|
case 9:
|
2022-12-19 19:45:50 +00:00
|
|
|
SetSpeedBase(static_cast<float>(reward->value) );
|
|
|
|
controllablePhysicsComponent->SetSpeedMultiplier(GetSpeedBase() / 500.0f);
|
2022-07-24 18:04:02 +00:00
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
case 12:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Tell the client we have finished sending level rewards.
|
2023-06-07 01:59:53 +00:00
|
|
|
if (rewardingItem) GameMessages::NotifyLevelRewards(m_OwningEntity->GetObjectID(), m_OwningEntity->GetSystemAddress(), m_Level, !rewardingItem);
|
2022-07-24 18:04:02 +00:00
|
|
|
}
|
2022-12-19 19:45:50 +00:00
|
|
|
|
|
|
|
void LevelProgressionComponent::SetRetroactiveBaseSpeed(){
|
|
|
|
if (m_Level >= 20) m_SpeedBase = 525.0f;
|
2023-06-07 07:23:50 +00:00
|
|
|
auto controllablePhysicsComponent = m_OwningEntity->GetComponent<ControllablePhysicsComponent>();
|
2022-12-19 19:45:50 +00:00
|
|
|
if (controllablePhysicsComponent) controllablePhysicsComponent->SetSpeedMultiplier(m_SpeedBase / 500.0f);
|
|
|
|
}
|