LevelProgressionComponent cleanup

This commit is contained in:
EmosewaMC 2023-07-04 22:38:46 -07:00
parent 8ede5b87ca
commit cfec9801a8
2 changed files with 17 additions and 12 deletions

View File

@ -43,47 +43,48 @@ void LevelProgressionComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
void LevelProgressionComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) { void LevelProgressionComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
outBitStream->Write(bIsInitialUpdate || m_DirtyLevelInfo); outBitStream->Write(bIsInitialUpdate || m_DirtyLevelInfo);
if (bIsInitialUpdate || m_DirtyLevelInfo) outBitStream->Write(m_Level); if (bIsInitialUpdate || m_DirtyLevelInfo) {
m_DirtyLevelInfo = false; outBitStream->Write(m_Level);
if (!bIsInitialUpdate) m_DirtyLevelInfo = false;
}
} }
void LevelProgressionComponent::HandleLevelUp() { void LevelProgressionComponent::HandleLevelUp() {
auto* rewardsTable = CDClientManager::Instance().GetTable<CDRewardsTable>(); auto* rewardsTable = CDClientManager::Instance().GetTable<CDRewardsTable>();
const auto& rewards = rewardsTable->GetByLevelID(m_Level); const auto& rewards = rewardsTable->GetByLevelID(m_Level);
bool rewardingItem = rewards.size() > 0; if (rewards.empty()) return;
auto* inventoryComponent = m_ParentEntity->GetComponent<InventoryComponent>(); auto* inventoryComponent = m_ParentEntity->GetComponent<InventoryComponent>();
auto* controllablePhysicsComponent = m_ParentEntity->GetComponent<ControllablePhysicsComponent>(); auto* controllablePhysicsComponent = m_ParentEntity->GetComponent<ControllablePhysicsComponent>();
if (!inventoryComponent || !controllablePhysicsComponent) return; if (!inventoryComponent || !controllablePhysicsComponent) return;
// Tell the client we beginning to send level rewards. // Tell the client we beginning to send level rewards.
if (rewardingItem) GameMessages::NotifyLevelRewards(m_ParentEntity->GetObjectID(), m_ParentEntity->GetSystemAddress(), m_Level, rewardingItem); GameMessages::NotifyLevelRewards(m_ParentEntity->GetObjectID(), m_ParentEntity->GetSystemAddress(), m_Level, true);
for (auto* reward : rewards) { for (auto* reward : rewards) {
switch (reward->rewardType) { switch (reward->rewardType) {
case 0: case 0:
inventoryComponent->AddItem(reward->value, reward->count, eLootSourceType::LEVEL_REWARD); inventoryComponent->AddItem(reward->value, reward->count, eLootSourceType::LEVEL_REWARD);
break; break;
case 4: case 4: {
{
auto* items = inventoryComponent->GetInventory(eInventoryType::ITEMS); auto* items = inventoryComponent->GetInventory(eInventoryType::ITEMS);
if (!items) continue;
items->SetSize(items->GetSize() + reward->value); items->SetSize(items->GetSize() + reward->value);
}
break; break;
}
case 9: case 9:
SetSpeedBase(static_cast<float>(reward->value)); SetSpeedBase(static_cast<float>(reward->value));
controllablePhysicsComponent->SetSpeedMultiplier(GetSpeedBase() / 500.0f); controllablePhysicsComponent->SetSpeedMultiplier(GetSpeedBase() / 500.0f);
break; break;
case 11: case 11:
case 12: case 12:
break;
default: default:
break; break;
} }
} }
// Tell the client we have finished sending level rewards. // Tell the client we have finished sending level rewards.
if (rewardingItem) GameMessages::NotifyLevelRewards(m_ParentEntity->GetObjectID(), m_ParentEntity->GetSystemAddress(), m_Level, !rewardingItem); GameMessages::NotifyLevelRewards(m_ParentEntity->GetObjectID(), m_ParentEntity->GetSystemAddress(), m_Level, false);
} }
void LevelProgressionComponent::SetRetroactiveBaseSpeed() { void LevelProgressionComponent::SetRetroactiveBaseSpeed() {

View File

@ -11,7 +11,7 @@
* *
*/ */
class LevelProgressionComponent : public Component { class LevelProgressionComponent final : public Component {
public: public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::LEVEL_PROGRESSION; inline static const eReplicaComponentType ComponentType = eReplicaComponentType::LEVEL_PROGRESSION;
@ -45,7 +45,11 @@ public:
* Sets the level of the entity * Sets the level of the entity
* @param level the level to set * @param level the level to set
*/ */
void SetLevel(uint32_t level) { m_Level = level; m_DirtyLevelInfo = true; } void SetLevel(uint32_t level) {
if (m_Level == level) return;
m_Level = level;
m_DirtyLevelInfo = true;
}
/** /**
* Gets the current Speed Base of the entity * Gets the current Speed Base of the entity
@ -98,7 +102,7 @@ private:
float m_SpeedBase; float m_SpeedBase;
/** /**
* The Character format version * The Character format version. Certain bug fixes increment this version number.
*/ */
eCharacterVersion m_CharacterVersion; eCharacterVersion m_CharacterVersion;