diff --git a/dGame/dComponents/BuffComponent.h b/dGame/dComponents/BuffComponent.h index 507e53a0..ec550e1e 100644 --- a/dGame/dComponents/BuffComponent.h +++ b/dGame/dComponents/BuffComponent.h @@ -26,6 +26,24 @@ struct BuffParameter { * Meta information about a buff that can be applied, e.g. how long it's applied, who applied it, etc. */ struct Buff { + bool operator==(const Buff& other) const { + return id == other.id && + time == other.time && + tick == other.tick && + tickTime == other.tickTime && + stacks == other.stacks && + source == other.source && + behaviorID == other.behaviorID && + cancelOnDamaged == other.cancelOnDamaged && + cancelOnDeath == other.cancelOnDeath && + cancelOnLogout == other.cancelOnLogout && + cancelOnRemoveBuff == other.cancelOnRemoveBuff && + cancelOnUi == other.cancelOnUi && + cancelOnUnequip == other.cancelOnUnequip && + cancelOnZone == other.cancelOnZone && + applyOnTeammates == other.applyOnTeammates && + refCount == other.refCount; + } int32_t id = 0; float time = 0; float tick = 0; @@ -134,6 +152,9 @@ public: */ const std::vector& GetBuffParameters(int32_t buffId); + const std::map& GetBuffs() const { return m_Buffs; } + const std::set& GetBuffsToRemove() const { return m_BuffsToRemove; } + private: /** * The currently active buffs diff --git a/dGame/dComponents/CharacterComponent.cpp b/dGame/dComponents/CharacterComponent.cpp index d706af9c..205c9195 100644 --- a/dGame/dComponents/CharacterComponent.cpp +++ b/dGame/dComponents/CharacterComponent.cpp @@ -331,10 +331,12 @@ void CharacterComponent::UpdateXml(tinyxml2::XMLDocument& doc) { if (m_ClaimCodes[2] != 0) character->SetAttribute("co2", m_ClaimCodes[2]); if (m_ClaimCodes[3] != 0) character->SetAttribute("co3", m_ClaimCodes[3]); + // Tests have been written up to here + character->SetAttribute("ls", m_Uscore); // Custom attribute to keep track of reputation. character->SetAttribute("rpt", GetReputation()); - character->SetAttribute("stt", StatisticsToString().c_str()); + character->SetAttribute("stt", StatisticsToString().c_str()); // and also this already tested :) // Set the zone statistics of the form ... auto zoneStatistics = character->FirstChildElement("zs"); diff --git a/dGame/dComponents/CharacterComponent.h b/dGame/dComponents/CharacterComponent.h index 7e63b0bd..67c28249 100644 --- a/dGame/dComponents/CharacterComponent.h +++ b/dGame/dComponents/CharacterComponent.h @@ -307,6 +307,8 @@ public: void SetDroppedCoins(const uint64_t value) { m_DroppedCoins = value; }; + const std::array& GetClaimCodes() const { return m_ClaimCodes; }; + /** * Character info regarding this character, including clothing styles, etc. */ diff --git a/tests/dGameTests/dComponentsTests/SavingTests.cpp b/tests/dGameTests/dComponentsTests/SavingTests.cpp index bdff5010..9debefe5 100644 --- a/tests/dGameTests/dComponentsTests/SavingTests.cpp +++ b/tests/dGameTests/dComponentsTests/SavingTests.cpp @@ -10,7 +10,7 @@ protected: std::unique_ptr entity; std::unique_ptr character; tinyxml2::XMLDocument doc; - tinyxml2::XMLPrinter printer{0, true, 0}; + tinyxml2::XMLPrinter printer{ 0, true, 0 }; void SetUp() override { SetUpDependencies(); @@ -46,21 +46,51 @@ protected: } }; -TEST_F(SavingTest, EntityLevelTest) { +TEST_F(SavingTest, CharacterComponentTest) { // Print the original XML data - character->GetXMLDoc().Print(&printer); - std::string xmlDataOriginal(printer.CStr()); - printer.ClearBuffer(); + // character->GetXMLDoc().Print(&printer); + // std::string xmlDataOriginal(printer.CStr()); + // printer.ClearBuffer(); + // std::ofstream oldXml("./test_xml_data_original.xml"); + // oldXml << xmlDataOriginal; + auto* characterComponent = entity->GetComponent(); + + auto statsPrev = characterComponent->StatisticsToString(); + auto claimCodesPrev = characterComponent->GetClaimCodes(); + auto eyebrowsPrev = characterComponent->m_Character->GetEyebrows(); + auto eyesPrev = characterComponent->m_Character->GetEyes(); + auto hairColorPrev = characterComponent->m_Character->GetHairColor(); + auto hairStylePrev = characterComponent->m_Character->GetHairStyle(); + auto pantsColorPrev = characterComponent->m_Character->GetPantsColor(); + auto leftHandPrev = characterComponent->m_Character->GetLeftHand(); + auto mouthPrev = characterComponent->m_Character->GetMouth(); + auto rightHandPrev = characterComponent->m_Character->GetRightHand(); + auto shirtColorPrev = characterComponent->m_Character->GetShirtColor(); + + // Update the xml document so its been run through the saver character->SaveXMLToDatabase(); - // Load the modified XML data - character->GetXMLDoc().Print(&printer); - std::string xmlDataModified(printer.CStr()); - printer.ClearBuffer(); - std::ofstream oldXml("./test_xml_data_original.xml"); - std::ofstream newXml("./test_xml_data_new.xml"); - oldXml << xmlDataOriginal; - newXml << xmlDataModified; - ASSERT_EQ(xmlDataOriginal, xmlDataModified); + // Reload the component from the now updated xml data + characterComponent = entity->AddComponent(character.get(), UNASSIGNED_SYSTEM_ADDRESS); + characterComponent->LoadFromXml(entity->GetCharacter()->GetXMLDoc()); + + // Check that the buff component is the same as before + ASSERT_EQ(statsPrev, characterComponent->StatisticsToString()); + ASSERT_EQ(claimCodesPrev, characterComponent->GetClaimCodes()); + ASSERT_EQ(eyebrowsPrev, characterComponent->m_Character->GetEyebrows()); + ASSERT_EQ(eyesPrev, characterComponent->m_Character->GetEyes()); + ASSERT_EQ(hairColorPrev, characterComponent->m_Character->GetHairColor()); + ASSERT_EQ(hairStylePrev, characterComponent->m_Character->GetHairStyle()); + ASSERT_EQ(pantsColorPrev, characterComponent->m_Character->GetPantsColor()); + ASSERT_EQ(leftHandPrev, characterComponent->m_Character->GetLeftHand()); + ASSERT_EQ(mouthPrev, characterComponent->m_Character->GetMouth()); + ASSERT_EQ(rightHandPrev, characterComponent->m_Character->GetRightHand()); + ASSERT_EQ(shirtColorPrev, characterComponent->m_Character->GetShirtColor()); + + // character->GetXMLDoc().Print(&printer); + // std::string xmlDataModified(printer.CStr()); + // printer.ClearBuffer(); + // std::ofstream newXml("./test_xml_data_new.xml"); + // newXml << xmlDataModified; }