mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-12-12 02:58:32 +00:00
Merge branch 'main' into raw-parsing-for-scene-data
This commit is contained in:
29
.github/copilot-instructions.md
vendored
Normal file
29
.github/copilot-instructions.md
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
# GitHub Copilot Instructions
|
||||
|
||||
* c++20 standard, please use the latest features except NO modules.
|
||||
* use `.contains` for searching in associative containers
|
||||
* use const as much as possible. If it can be const, it should be made const
|
||||
* DO NOT USE const_cast EVER.
|
||||
* use `cstdint` bitwidth types ALWAYS for integral types.
|
||||
* NEVER use std::wstring. If wide strings are necessary, use std::u16string with conversion utilties in GeneralUtils.h.
|
||||
* Functions are ALWAYS PascalCase.
|
||||
* local variables are camelCase
|
||||
* NEVER use snake case
|
||||
* indentation is TABS, not SPACES.
|
||||
* TABS are 4 spaces by default
|
||||
* Use trailing braces ALWAYS
|
||||
* global variables are prefixed with `g_`
|
||||
* if global variables or functions are needed, they should be located in an anonymous namespace
|
||||
* Use `GeneralUtils::TryParse` for ANY parsing of strings to integrals.
|
||||
* Use brace initialization when possible.
|
||||
* ALWAYS default initialize variables.
|
||||
* Pointers should be avoided unless necessary. Use references when the pointer has been checked and should not be null
|
||||
* headers should be as compact as possible. Do NOT include extra data that isnt needed.
|
||||
* Remember to include logs (LOG macro uses printf style logging) while putting verbose logs under LOG_DEBUG.
|
||||
* NEVER USE `RakNet::BitStream::ReadBit`
|
||||
* NEVER assume pointers are good, always check if they are null. Once a pointer is checked and is known to be non-null, further accesses no longer need checking
|
||||
* Be wary of TOCTOU. Prevent all possible issues relating to TOCTOU.
|
||||
* new memory allocations should never be used unless absolutely necessary.
|
||||
* new for reconstruction of objects is allowed
|
||||
* Prefer following the format of the file over correct formatting. Consistency over correctness.
|
||||
* When using auto, ALWAYS put a * for pointers.
|
||||
@@ -271,6 +271,9 @@ std::vector<Lxfml::Result> Lxfml::Split(const std::string_view data, const NiPoi
|
||||
std::unordered_set<std::string> usedBrickRefs;
|
||||
std::unordered_set<tinyxml2::XMLElement*> usedRigidSystems;
|
||||
|
||||
// Track used groups to avoid processing them twice
|
||||
std::unordered_set<tinyxml2::XMLElement*> usedGroups;
|
||||
|
||||
// Helper to create output document from sets of brick refs and rigidsystem pointers
|
||||
auto makeOutput = [&](const std::unordered_set<std::string>& bricksToInclude, const std::vector<tinyxml2::XMLElement*>& rigidSystemsToInclude, const std::vector<tinyxml2::XMLElement*>& groupsToInclude = {}) {
|
||||
tinyxml2::XMLDocument outDoc;
|
||||
@@ -323,19 +326,27 @@ std::vector<Lxfml::Result> Lxfml::Split(const std::string_view data, const NiPoi
|
||||
|
||||
// 1) Process groups (each top-level Group becomes one output; nested groups are included)
|
||||
for (auto* groupRoot : groupRoots) {
|
||||
// collect all partRefs in this group's subtree
|
||||
std::unordered_set<std::string> partRefs;
|
||||
std::function<void(const tinyxml2::XMLElement*)> collectParts = [&](const tinyxml2::XMLElement* g) {
|
||||
// Skip if this group was already processed as part of another group
|
||||
if (usedGroups.find(groupRoot) != usedGroups.end()) continue;
|
||||
|
||||
// Helper to collect all partRefs in a group's subtree
|
||||
std::function<void(const tinyxml2::XMLElement*, std::unordered_set<std::string>&)> collectParts = [&](const tinyxml2::XMLElement* g, std::unordered_set<std::string>& partRefs) {
|
||||
if (!g) return;
|
||||
const char* partAttr = g->Attribute("partRefs");
|
||||
if (partAttr) {
|
||||
for (auto& tok : GeneralUtils::SplitString(partAttr, ',')) partRefs.insert(tok);
|
||||
}
|
||||
for (auto* child = g->FirstChildElement("Group"); child; child = child->NextSiblingElement("Group")) collectParts(child);
|
||||
for (auto* child = g->FirstChildElement("Group"); child; child = child->NextSiblingElement("Group")) collectParts(child, partRefs);
|
||||
};
|
||||
collectParts(groupRoot);
|
||||
|
||||
// Build initial sets of bricks and boneRefs
|
||||
// Collect all groups that need to be merged into this output
|
||||
std::vector<tinyxml2::XMLElement*> groupsToInclude{ groupRoot };
|
||||
usedGroups.insert(groupRoot);
|
||||
|
||||
// Build initial sets of bricks and boneRefs from the starting group
|
||||
std::unordered_set<std::string> partRefs;
|
||||
collectParts(groupRoot, partRefs);
|
||||
|
||||
std::unordered_set<std::string> bricksIncluded;
|
||||
std::unordered_set<std::string> boneRefsIncluded;
|
||||
for (const auto& pref : partRefs) {
|
||||
@@ -355,6 +366,7 @@ std::vector<Lxfml::Result> Lxfml::Split(const std::string_view data, const NiPoi
|
||||
}
|
||||
|
||||
// Iteratively include any RigidSystems that reference any boneRefsIncluded
|
||||
// and check if those rigid systems' bricks span other groups
|
||||
bool changed = true;
|
||||
std::vector<tinyxml2::XMLElement*> rigidSystemsToInclude;
|
||||
int maxIterations = 1000; // Safety limit to prevent infinite loops
|
||||
@@ -362,6 +374,8 @@ std::vector<Lxfml::Result> Lxfml::Split(const std::string_view data, const NiPoi
|
||||
while (changed && iteration < maxIterations) {
|
||||
changed = false;
|
||||
iteration++;
|
||||
|
||||
// First, expand rigid systems based on current boneRefsIncluded
|
||||
for (auto* rs : rigidSystems) {
|
||||
if (usedRigidSystems.find(rs) != usedRigidSystems.end()) continue;
|
||||
// parse boneRefs of this rigid system (from its <Rigid> children)
|
||||
@@ -392,6 +406,53 @@ std::vector<Lxfml::Result> Lxfml::Split(const std::string_view data, const NiPoi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Second, check if the newly included bricks span any other groups
|
||||
// If so, merge those groups into the current output
|
||||
for (auto* otherGroup : groupRoots) {
|
||||
if (usedGroups.find(otherGroup) != usedGroups.end()) continue;
|
||||
|
||||
// Collect partRefs from this other group
|
||||
std::unordered_set<std::string> otherPartRefs;
|
||||
collectParts(otherGroup, otherPartRefs);
|
||||
|
||||
// Check if any of these partRefs correspond to bricks we've already included
|
||||
bool spansOtherGroup = false;
|
||||
for (const auto& pref : otherPartRefs) {
|
||||
auto pit = partRefToBrick.find(pref);
|
||||
if (pit != partRefToBrick.end()) {
|
||||
const char* bref = pit->second->Attribute("refID");
|
||||
if (bref && bricksIncluded.find(std::string(bref)) != bricksIncluded.end()) {
|
||||
spansOtherGroup = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (spansOtherGroup) {
|
||||
// Merge this group into the current output
|
||||
usedGroups.insert(otherGroup);
|
||||
groupsToInclude.push_back(otherGroup);
|
||||
changed = true;
|
||||
|
||||
// Add all partRefs, boneRefs, and bricks from this group
|
||||
for (const auto& pref : otherPartRefs) {
|
||||
auto pit = partRefToBrick.find(pref);
|
||||
if (pit != partRefToBrick.end()) {
|
||||
const char* bref = pit->second->Attribute("refID");
|
||||
if (bref) bricksIncluded.insert(std::string(bref));
|
||||
}
|
||||
auto partIt = partRefToPart.find(pref);
|
||||
if (partIt != partRefToPart.end()) {
|
||||
auto* bone = partIt->second->FirstChildElement("Bone");
|
||||
if (bone) {
|
||||
const char* bref = bone->Attribute("refID");
|
||||
if (bref) boneRefsIncluded.insert(std::string(bref));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (iteration >= maxIterations) {
|
||||
@@ -402,10 +463,9 @@ std::vector<Lxfml::Result> Lxfml::Split(const std::string_view data, const NiPoi
|
||||
// include bricks from bricksIncluded into used set
|
||||
for (const auto& b : bricksIncluded) usedBrickRefs.insert(b);
|
||||
|
||||
// make output doc and push result (include this group's XML)
|
||||
std::vector<tinyxml2::XMLElement*> groupsVec{ groupRoot };
|
||||
auto normalized = makeOutput(bricksIncluded, rigidSystemsToInclude, groupsVec);
|
||||
results.push_back(normalized);
|
||||
// make output doc and push result (include all merged groups' XML)
|
||||
auto normalized = makeOutput(bricksIncluded, rigidSystemsToInclude, groupsToInclude);
|
||||
results.push_back(normalized);
|
||||
}
|
||||
|
||||
// 2) Process remaining RigidSystems (each becomes its own file)
|
||||
|
||||
@@ -84,6 +84,8 @@
|
||||
#include "GhostComponent.h"
|
||||
#include "AchievementVendorComponent.h"
|
||||
#include "VanityUtilities.h"
|
||||
#include "ObjectIDManager.h"
|
||||
#include "ePlayerFlag.h"
|
||||
|
||||
// Table includes
|
||||
#include "CDComponentsRegistryTable.h"
|
||||
@@ -192,7 +194,10 @@ Entity::~Entity() {
|
||||
}
|
||||
|
||||
void Entity::Initialize() {
|
||||
RegisterMsg(MessageType::Game::REQUEST_SERVER_OBJECT_INFO, this, &Entity::MsgRequestServerObjectInfo);
|
||||
RegisterMsg<GameMessages::RequestServerObjectInfo>(this, &Entity::MsgRequestServerObjectInfo);
|
||||
RegisterMsg<GameMessages::DropClientLoot>(this, &Entity::MsgDropClientLoot);
|
||||
RegisterMsg<GameMessages::GetFactionTokenType>(this, &Entity::MsgGetFactionTokenType);
|
||||
RegisterMsg<GameMessages::PickupItem>(this, &Entity::MsgPickupItem);
|
||||
/**
|
||||
* Setup trigger
|
||||
*/
|
||||
@@ -287,7 +292,7 @@ void Entity::Initialize() {
|
||||
AddComponent<LUPExhibitComponent>(lupExhibitID);
|
||||
}
|
||||
|
||||
const auto racingControlID =compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RACING_CONTROL);
|
||||
const auto racingControlID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RACING_CONTROL);
|
||||
if (racingControlID > 0) {
|
||||
AddComponent<RacingControlComponent>(racingControlID);
|
||||
}
|
||||
@@ -1663,7 +1668,7 @@ void Entity::AddLootItem(const Loot::Info& info) const {
|
||||
|
||||
auto* const characterComponent = GetComponent<CharacterComponent>();
|
||||
if (!characterComponent) return;
|
||||
|
||||
LOG("Player %llu has been allowed to pickup %i with id %llu", m_ObjectID, info.lot, info.id);
|
||||
auto& droppedLoot = characterComponent->GetDroppedLoot();
|
||||
droppedLoot[info.id] = info;
|
||||
}
|
||||
@@ -2275,3 +2280,73 @@ bool Entity::MsgRequestServerObjectInfo(GameMessages::GameMsg& msg) {
|
||||
if (client) GameMessages::SendUIMessageServerToSingleClient("ToggleObjectDebugger", response, client->GetSystemAddress());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Entity::MsgDropClientLoot(GameMessages::GameMsg& msg) {
|
||||
auto& dropLootMsg = static_cast<GameMessages::DropClientLoot&>(msg);
|
||||
|
||||
if (dropLootMsg.item != LOT_NULL && dropLootMsg.item != 0) {
|
||||
Loot::Info info{
|
||||
.id = dropLootMsg.lootID,
|
||||
.lot = dropLootMsg.item,
|
||||
.count = dropLootMsg.count,
|
||||
};
|
||||
AddLootItem(info);
|
||||
}
|
||||
|
||||
if (dropLootMsg.item == LOT_NULL && dropLootMsg.currency != 0) {
|
||||
RegisterCoinDrop(dropLootMsg.currency);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Entity::MsgGetFlag(GameMessages::GameMsg& msg) {
|
||||
auto& flagMsg = static_cast<GameMessages::GetFlag&>(msg);
|
||||
if (m_Character) flagMsg.flag = m_Character->GetPlayerFlag(flagMsg.flagID);
|
||||
return true;
|
||||
}
|
||||
bool Entity::MsgGetFactionTokenType(GameMessages::GameMsg& msg) {
|
||||
auto& tokenMsg = static_cast<GameMessages::GetFactionTokenType&>(msg);
|
||||
GameMessages::GetFlag getFlagMsg{};
|
||||
|
||||
getFlagMsg.flagID = ePlayerFlag::ASSEMBLY_FACTION;
|
||||
MsgGetFlag(getFlagMsg);
|
||||
if (getFlagMsg.flag) tokenMsg.tokenType = 8318;
|
||||
|
||||
getFlagMsg.flagID = ePlayerFlag::SENTINEL_FACTION;
|
||||
MsgGetFlag(getFlagMsg);
|
||||
if (getFlagMsg.flag) tokenMsg.tokenType = 8319;
|
||||
|
||||
getFlagMsg.flagID = ePlayerFlag::PARADOX_FACTION;
|
||||
MsgGetFlag(getFlagMsg);
|
||||
if (getFlagMsg.flag) tokenMsg.tokenType = 8320;
|
||||
|
||||
getFlagMsg.flagID = ePlayerFlag::VENTURE_FACTION;
|
||||
MsgGetFlag(getFlagMsg);
|
||||
if (getFlagMsg.flag) tokenMsg.tokenType = 8321;
|
||||
|
||||
LOG("Returning token type %i", tokenMsg.tokenType);
|
||||
return tokenMsg.tokenType != LOT_NULL;
|
||||
}
|
||||
|
||||
bool Entity::MsgPickupItem(GameMessages::GameMsg& msg) {
|
||||
auto& pickupItemMsg = static_cast<GameMessages::PickupItem&>(msg);
|
||||
if (GetObjectID() == pickupItemMsg.lootOwnerID) {
|
||||
PickupItem(pickupItemMsg.lootID);
|
||||
} else {
|
||||
auto* const characterComponent = GetComponent<CharacterComponent>();
|
||||
if (!characterComponent) return false;
|
||||
auto& droppedLoot = characterComponent->GetDroppedLoot();
|
||||
const auto it = droppedLoot.find(pickupItemMsg.lootID);
|
||||
if (it != droppedLoot.end()) {
|
||||
CDObjectsTable* objectsTable = CDClientManager::GetTable<CDObjectsTable>();
|
||||
const CDObjects& object = objectsTable->GetByID(it->second.lot);
|
||||
if (object.id != 0 && object.type == "Powerup") {
|
||||
return false; // Let powerups be duplicated
|
||||
}
|
||||
}
|
||||
droppedLoot.erase(pickupItemMsg.lootID);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -176,6 +176,10 @@ public:
|
||||
void AddComponent(eReplicaComponentType componentId, Component* component);
|
||||
|
||||
bool MsgRequestServerObjectInfo(GameMessages::GameMsg& msg);
|
||||
bool MsgDropClientLoot(GameMessages::GameMsg& msg);
|
||||
bool MsgGetFlag(GameMessages::GameMsg& msg);
|
||||
bool MsgGetFactionTokenType(GameMessages::GameMsg& msg);
|
||||
bool MsgPickupItem(GameMessages::GameMsg& msg);
|
||||
|
||||
// This is expceted to never return nullptr, an assert checks this.
|
||||
CppScripts::Script* const GetScript() const;
|
||||
@@ -342,6 +346,12 @@ public:
|
||||
RegisterMsg(msgId, std::bind(handler, self, std::placeholders::_1));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void RegisterMsg(auto* self, const auto handler) {
|
||||
T msg;
|
||||
RegisterMsg(msg.msgId, self, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The observable for player entity position updates.
|
||||
*/
|
||||
@@ -600,5 +610,5 @@ auto Entity::GetComponents() const {
|
||||
|
||||
template<typename... T>
|
||||
auto Entity::GetComponentsMut() const {
|
||||
return std::tuple{GetComponent<T>()...};
|
||||
return std::tuple{ GetComponent<T>()... };
|
||||
}
|
||||
|
||||
@@ -9,6 +9,16 @@ Team::Team() {
|
||||
lootOption = Game::config->GetValue("default_team_loot") == "0" ? 0 : 1;
|
||||
}
|
||||
|
||||
LWOOBJID Team::GetNextLootOwner() {
|
||||
lootRound++;
|
||||
|
||||
if (lootRound >= members.size()) {
|
||||
lootRound = 0;
|
||||
}
|
||||
|
||||
return members[lootRound];
|
||||
}
|
||||
|
||||
TeamManager::TeamManager() {
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
struct Team {
|
||||
Team();
|
||||
|
||||
LWOOBJID GetNextLootOwner();
|
||||
LWOOBJID teamID = LWOOBJID_EMPTY;
|
||||
char lootOption = 0;
|
||||
std::vector<LWOOBJID> members{};
|
||||
|
||||
@@ -45,33 +45,6 @@ ActivityComponent::ActivityComponent(Entity* parent, int32_t componentID) : Comp
|
||||
m_ActivityID = parent->GetVar<int32_t>(u"activityID");
|
||||
LoadActivityData(m_ActivityID);
|
||||
}
|
||||
|
||||
auto* destroyableComponent = m_Parent->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (destroyableComponent) {
|
||||
// First lookup the loot matrix id for this component id.
|
||||
CDActivityRewardsTable* activityRewardsTable = CDClientManager::GetTable<CDActivityRewardsTable>();
|
||||
std::vector<CDActivityRewards> activityRewards = activityRewardsTable->Query([=](CDActivityRewards entry) {return (entry.LootMatrixIndex == destroyableComponent->GetLootMatrixID()); });
|
||||
|
||||
uint32_t startingLMI = 0;
|
||||
|
||||
// If we have one, set the starting loot matrix id to that.
|
||||
if (activityRewards.size() > 0) {
|
||||
startingLMI = activityRewards[0].LootMatrixIndex;
|
||||
}
|
||||
|
||||
if (startingLMI > 0) {
|
||||
// We may have more than 1 loot matrix index to use depending ont the size of the team that is looting the activity.
|
||||
// So this logic will get the rest of the loot matrix indices for this activity.
|
||||
|
||||
std::vector<CDActivityRewards> objectTemplateActivities = activityRewardsTable->Query([=](CDActivityRewards entry) {return (activityRewards[0].objectTemplate == entry.objectTemplate); });
|
||||
for (const auto& item : objectTemplateActivities) {
|
||||
if (item.activityRating > 0 && item.activityRating < 5) {
|
||||
m_ActivityLootMatrices.insert({ item.activityRating, item.LootMatrixIndex });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void ActivityComponent::LoadActivityData(const int32_t activityId) {
|
||||
CDActivitiesTable* activitiesTable = CDClientManager::GetTable<CDActivitiesTable>();
|
||||
@@ -698,10 +671,6 @@ bool ActivityComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) {
|
||||
}
|
||||
}
|
||||
|
||||
auto& lootMatrices = activityInfo.PushDebug("Loot Matrices");
|
||||
for (const auto& [activityRating, lootMatrixID] : m_ActivityLootMatrices) {
|
||||
lootMatrices.PushDebug<AMFIntValue>("Loot Matrix " + std::to_string(activityRating)) = lootMatrixID;
|
||||
}
|
||||
activityInfo.PushDebug<AMFIntValue>("ActivityID") = m_ActivityID;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -341,12 +341,6 @@ public:
|
||||
*/
|
||||
void SetInstanceMapID(uint32_t mapID) { m_ActivityInfo.instanceMapID = mapID; };
|
||||
|
||||
/**
|
||||
* Returns the LMI that this activity points to for a team size
|
||||
* @param teamSize the team size to get the LMI for
|
||||
* @return the LMI that this activity points to for a team size
|
||||
*/
|
||||
uint32_t GetLootMatrixForTeamSize(uint32_t teamSize) { return m_ActivityLootMatrices[teamSize]; }
|
||||
private:
|
||||
|
||||
bool OnGetObjectReportInfo(GameMessages::GameMsg& msg);
|
||||
@@ -370,11 +364,6 @@ private:
|
||||
*/
|
||||
std::vector<ActivityPlayer*> m_ActivityPlayers;
|
||||
|
||||
/**
|
||||
* LMIs for team sizes
|
||||
*/
|
||||
std::unordered_map<uint32_t, uint32_t> m_ActivityLootMatrices;
|
||||
|
||||
/**
|
||||
* The activity id
|
||||
*/
|
||||
|
||||
@@ -756,36 +756,7 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
//NANI?!
|
||||
if (!isPlayer) {
|
||||
if (owner != nullptr) {
|
||||
auto* team = TeamManager::Instance()->GetTeam(owner->GetObjectID());
|
||||
|
||||
if (team != nullptr && m_Parent->GetComponent<BaseCombatAIComponent>() != nullptr) {
|
||||
LWOOBJID specificOwner = LWOOBJID_EMPTY;
|
||||
auto* scriptedActivityComponent = m_Parent->GetComponent<ScriptedActivityComponent>();
|
||||
uint32_t teamSize = team->members.size();
|
||||
uint32_t lootMatrixId = GetLootMatrixID();
|
||||
|
||||
if (scriptedActivityComponent) {
|
||||
lootMatrixId = scriptedActivityComponent->GetLootMatrixForTeamSize(teamSize);
|
||||
}
|
||||
|
||||
if (team->lootOption == 0) { // Round robin
|
||||
specificOwner = TeamManager::Instance()->GetNextLootOwner(team);
|
||||
|
||||
auto* member = Game::entityManager->GetEntity(specificOwner);
|
||||
|
||||
if (member) Loot::DropLoot(member, m_Parent->GetObjectID(), lootMatrixId, GetMinCoins(), GetMaxCoins());
|
||||
} else {
|
||||
for (const auto memberId : team->members) { // Free for all
|
||||
auto* member = Game::entityManager->GetEntity(memberId);
|
||||
|
||||
if (member == nullptr) continue;
|
||||
|
||||
Loot::DropLoot(member, m_Parent->GetObjectID(), lootMatrixId, GetMinCoins(), GetMaxCoins());
|
||||
}
|
||||
}
|
||||
} else { // drop loot for non team user
|
||||
Loot::DropLoot(owner, m_Parent->GetObjectID(), GetLootMatrixID(), GetMinCoins(), GetMaxCoins());
|
||||
}
|
||||
Loot::DropLoot(owner, m_Parent->GetObjectID(), GetLootMatrixID(), GetMinCoins(), GetMaxCoins());
|
||||
}
|
||||
} else {
|
||||
//Check if this zone allows coin drops
|
||||
@@ -1046,8 +1017,8 @@ void DestroyableComponent::DoHardcoreModeDrops(const LWOOBJID source) {
|
||||
auto maxHealth = GetMaxHealth();
|
||||
const auto uscoreMultiplier = Game::entityManager->GetHardcoreUscoreEnemiesMultiplier();
|
||||
const bool isUscoreReducedLot =
|
||||
Game::entityManager->GetHardcoreUscoreReducedLots().contains(lot) ||
|
||||
Game::entityManager->GetHardcoreUscoreReduced();
|
||||
Game::entityManager->GetHardcoreUscoreReducedLots().contains(lot) ||
|
||||
Game::entityManager->GetHardcoreUscoreReduced();
|
||||
const auto uscoreReduction = isUscoreReducedLot ? Game::entityManager->GetHardcoreUscoreReduction() : 1.0f;
|
||||
|
||||
int uscore = maxHealth * Game::entityManager->GetHardcoreUscoreEnemiesMultiplier() * uscoreReduction;
|
||||
|
||||
@@ -443,7 +443,7 @@ Item* InventoryComponent::FindItemBySubKey(LWOOBJID id, eInventoryType inventory
|
||||
}
|
||||
}
|
||||
|
||||
bool InventoryComponent::HasSpaceForLoot(const std::unordered_map<LOT, int32_t>& loot) {
|
||||
bool InventoryComponent::HasSpaceForLoot(const Loot::Return& loot) {
|
||||
std::unordered_map<eInventoryType, int32_t> spaceOffset{};
|
||||
|
||||
uint32_t slotsNeeded = 0;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "eInventoryType.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
#include "eLootSourceType.h"
|
||||
#include "Loot.h"
|
||||
|
||||
class Entity;
|
||||
class ItemSet;
|
||||
@@ -200,7 +201,7 @@ public:
|
||||
* @param loot a map of items to add and how many to add
|
||||
* @return whether the entity has enough space for all the items
|
||||
*/
|
||||
bool HasSpaceForLoot(const std::unordered_map<LOT, int32_t>& loot);
|
||||
bool HasSpaceForLoot(const Loot::Return& loot);
|
||||
|
||||
/**
|
||||
* Equips an item in the specified slot
|
||||
|
||||
@@ -31,6 +31,8 @@ MissionComponent::MissionComponent(Entity* parent, const int32_t componentID) :
|
||||
m_LastUsedMissionOrderUID = Game::zoneManager->GetUniqueMissionIdStartingValue();
|
||||
|
||||
RegisterMsg<GetObjectReportInfo>(this, &MissionComponent::OnGetObjectReportInfo);
|
||||
RegisterMsg<GameMessages::GetMissionState>(this, &MissionComponent::OnGetMissionState);
|
||||
RegisterMsg<GameMessages::MissionNeedsLot>(this, &MissionComponent::OnMissionNeedsLot);
|
||||
}
|
||||
|
||||
//! Destructor
|
||||
@@ -733,3 +735,15 @@ bool MissionComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MissionComponent::OnGetMissionState(GameMessages::GameMsg& msg) {
|
||||
auto misState = static_cast<GameMessages::GetMissionState&>(msg);
|
||||
misState.missionState = GetMissionState(misState.missionID);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MissionComponent::OnMissionNeedsLot(GameMessages::GameMsg& msg) {
|
||||
const auto& needMsg = static_cast<GameMessages::MissionNeedsLot&>(msg);
|
||||
return RequiresItem(needMsg.item);
|
||||
}
|
||||
|
||||
@@ -172,6 +172,8 @@ public:
|
||||
void ResetMission(const int32_t missionId);
|
||||
private:
|
||||
bool OnGetObjectReportInfo(GameMessages::GameMsg& msg);
|
||||
bool OnGetMissionState(GameMessages::GameMsg& msg);
|
||||
bool OnMissionNeedsLot(GameMessages::GameMsg& msg);
|
||||
/**
|
||||
* All the missions owned by this entity, mapped by mission ID
|
||||
*/
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace {
|
||||
{ REQUEST_USE, []() { return std::make_unique<RequestUse>(); }},
|
||||
{ REQUEST_SERVER_OBJECT_INFO, []() { return std::make_unique<RequestServerObjectInfo>(); } },
|
||||
{ SHOOTING_GALLERY_FIRE, []() { return std::make_unique<ShootingGalleryFire>(); } },
|
||||
{ PICKUP_ITEM, []() { return std::make_unique<PickupItem>(); } },
|
||||
};
|
||||
};
|
||||
|
||||
@@ -281,11 +282,6 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream& inStream, const System
|
||||
break;
|
||||
}
|
||||
|
||||
case MessageType::Game::PICKUP_ITEM: {
|
||||
GameMessages::HandlePickupItem(inStream, entity);
|
||||
break;
|
||||
}
|
||||
|
||||
case MessageType::Game::RESURRECT: {
|
||||
GameMessages::HandleResurrect(inStream, entity);
|
||||
break;
|
||||
|
||||
@@ -1103,52 +1103,6 @@ void GameMessages::SendDropClientLoot(Entity* entity, const LWOOBJID& sourceID,
|
||||
|
||||
finalPosition = NiPoint3(static_cast<float>(spawnPos.GetX() + sin_v), spawnPos.GetY(), static_cast<float>(spawnPos.GetZ() + cos_v));
|
||||
}
|
||||
|
||||
//Write data to packet & send:
|
||||
CBITSTREAM;
|
||||
CMSGHEADER;
|
||||
|
||||
bitStream.Write(entity->GetObjectID());
|
||||
bitStream.Write(MessageType::Game::DROP_CLIENT_LOOT);
|
||||
|
||||
bitStream.Write(bUsePosition);
|
||||
|
||||
bitStream.Write(finalPosition != NiPoint3Constant::ZERO);
|
||||
if (finalPosition != NiPoint3Constant::ZERO) bitStream.Write(finalPosition);
|
||||
|
||||
bitStream.Write(currency);
|
||||
bitStream.Write(item);
|
||||
bitStream.Write(lootID);
|
||||
bitStream.Write(owner);
|
||||
bitStream.Write(sourceID);
|
||||
|
||||
bitStream.Write(spawnPos != NiPoint3Constant::ZERO);
|
||||
if (spawnPos != NiPoint3Constant::ZERO) bitStream.Write(spawnPos);
|
||||
|
||||
auto* team = TeamManager::Instance()->GetTeam(owner);
|
||||
|
||||
// Currency and powerups should not sync
|
||||
if (team != nullptr && currency == 0) {
|
||||
CDObjectsTable* objectsTable = CDClientManager::GetTable<CDObjectsTable>();
|
||||
|
||||
const CDObjects& object = objectsTable->GetByID(item);
|
||||
|
||||
if (object.type != "Powerup") {
|
||||
for (const auto memberId : team->members) {
|
||||
auto* member = Game::entityManager->GetEntity(memberId);
|
||||
|
||||
if (member == nullptr) continue;
|
||||
|
||||
SystemAddress sysAddr = member->GetSystemAddress();
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
SystemAddress sysAddr = entity->GetSystemAddress();
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
void GameMessages::SendSetPlayerControlScheme(Entity* entity, eControlScheme controlScheme) {
|
||||
@@ -2597,6 +2551,14 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream& inStream, Entity* ent
|
||||
|
||||
// Uncompress the data, split, and nornmalize the model
|
||||
const auto asStr = sd0.GetAsStringUncompressed();
|
||||
|
||||
if (Game::config->GetValue("save_lxfmls") == "1") {
|
||||
// save using localId to avoid conflicts
|
||||
std::ofstream outFile("debug_lxfml_uncompressed_" + std::to_string(localId) + ".lxfml");
|
||||
outFile << asStr;
|
||||
outFile.close();
|
||||
}
|
||||
|
||||
auto splitLxfmls = Lxfml::Split(asStr);
|
||||
LOG_DEBUG("Split into %zu models", splitLxfmls.size());
|
||||
|
||||
@@ -5725,27 +5687,6 @@ void GameMessages::HandleModularBuildMoveAndEquip(RakNet::BitStream& inStream, E
|
||||
inv->MoveItemToInventory(item, eInventoryType::MODELS, 1, false, true);
|
||||
}
|
||||
|
||||
void GameMessages::HandlePickupItem(RakNet::BitStream& inStream, Entity* entity) {
|
||||
LWOOBJID lootObjectID;
|
||||
LWOOBJID playerID;
|
||||
inStream.Read(lootObjectID);
|
||||
inStream.Read(playerID);
|
||||
|
||||
entity->PickupItem(lootObjectID);
|
||||
|
||||
auto* team = TeamManager::Instance()->GetTeam(entity->GetObjectID());
|
||||
|
||||
if (team != nullptr) {
|
||||
for (const auto memberId : team->members) {
|
||||
auto* member = Game::entityManager->GetEntity(memberId);
|
||||
|
||||
if (member == nullptr || memberId == playerID) continue;
|
||||
|
||||
SendTeamPickupItem(lootObjectID, lootObjectID, playerID, member->GetSystemAddress());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GameMessages::HandleResurrect(RakNet::BitStream& inStream, Entity* entity) {
|
||||
bool immediate = inStream.ReadBit();
|
||||
|
||||
@@ -6329,6 +6270,11 @@ namespace GameMessages {
|
||||
return Game::entityManager->SendMessage(*this);
|
||||
}
|
||||
|
||||
bool GameMsg::Send(const LWOOBJID _target) {
|
||||
target = _target;
|
||||
return Send();
|
||||
}
|
||||
|
||||
void GameMsg::Send(const SystemAddress& sysAddr) const {
|
||||
CBITSTREAM;
|
||||
CMSGHEADER;
|
||||
@@ -6496,4 +6442,49 @@ namespace GameMessages {
|
||||
stream.Write(emoteID);
|
||||
stream.Write(targetID);
|
||||
}
|
||||
|
||||
void DropClientLoot::Serialize(RakNet::BitStream& stream) const {
|
||||
stream.Write(bUsePosition);
|
||||
|
||||
stream.Write(finalPosition != NiPoint3Constant::ZERO);
|
||||
if (finalPosition != NiPoint3Constant::ZERO) stream.Write(finalPosition);
|
||||
|
||||
stream.Write(currency);
|
||||
stream.Write(item);
|
||||
stream.Write(lootID);
|
||||
stream.Write(ownerID);
|
||||
stream.Write(sourceID);
|
||||
|
||||
stream.Write(spawnPos != NiPoint3Constant::ZERO);
|
||||
if (spawnPos != NiPoint3Constant::ZERO) stream.Write(spawnPos);
|
||||
}
|
||||
|
||||
bool PickupItem::Deserialize(RakNet::BitStream& stream) {
|
||||
if (!stream.Read(lootID)) return false;
|
||||
if (!stream.Read(lootOwnerID)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void PickupItem::Handle(Entity& entity, const SystemAddress& sysAddr) {
|
||||
auto* team = TeamManager::Instance()->GetTeam(entity.GetObjectID());
|
||||
LOG("Has team %i picking up %llu:%llu", team != nullptr, lootID, lootOwnerID);
|
||||
if (team) {
|
||||
for (const auto memberId : team->members) {
|
||||
this->Send(memberId);
|
||||
TeamPickupItem teamPickupMsg{};
|
||||
teamPickupMsg.target = lootID;
|
||||
teamPickupMsg.lootID = lootID;
|
||||
teamPickupMsg.lootOwnerID = lootOwnerID;
|
||||
const auto* const memberEntity = Game::entityManager->GetEntity(memberId);
|
||||
if (memberEntity) teamPickupMsg.Send(memberEntity->GetSystemAddress());
|
||||
}
|
||||
} else {
|
||||
entity.PickupItem(lootID);
|
||||
}
|
||||
}
|
||||
|
||||
void TeamPickupItem::Serialize(RakNet::BitStream& stream) const {
|
||||
stream.Write(lootID);
|
||||
stream.Write(lootOwnerID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ enum class eQuickBuildState : uint32_t;
|
||||
enum class BehaviorSlot : int32_t;
|
||||
enum class eVendorTransactionResult : uint32_t;
|
||||
enum class eReponseMoveItemBetweenInventoryTypeCode : int32_t;
|
||||
enum class eMissionState : int;
|
||||
|
||||
enum class eCameraTargetCyclingMode : int32_t {
|
||||
ALLOW_CYCLE_TEAMMATES,
|
||||
@@ -57,6 +58,7 @@ namespace GameMessages {
|
||||
|
||||
// Sends a message to the entity manager to route to the target
|
||||
bool Send();
|
||||
bool Send(const LWOOBJID _target);
|
||||
|
||||
// Sends the message to the specified client or
|
||||
// all clients if UNASSIGNED_SYSTEM_ADDRESS is specified
|
||||
@@ -850,9 +852,9 @@ namespace GameMessages {
|
||||
|
||||
struct EmotePlayed : public GameMsg {
|
||||
EmotePlayed() : GameMsg(MessageType::Game::EMOTE_PLAYED), emoteID(0), targetID(0) {}
|
||||
|
||||
|
||||
void Serialize(RakNet::BitStream& stream) const override;
|
||||
|
||||
|
||||
int32_t emoteID;
|
||||
LWOOBJID targetID;
|
||||
};
|
||||
@@ -870,5 +872,65 @@ namespace GameMessages {
|
||||
|
||||
bool bIgnoreChecks{ false };
|
||||
};
|
||||
|
||||
struct DropClientLoot : public GameMsg {
|
||||
DropClientLoot() : GameMsg(MessageType::Game::DROP_CLIENT_LOOT) {}
|
||||
|
||||
void Serialize(RakNet::BitStream& stream) const override;
|
||||
LWOOBJID sourceID{ LWOOBJID_EMPTY };
|
||||
LOT item{ LOT_NULL };
|
||||
int32_t currency{};
|
||||
NiPoint3 spawnPos{};
|
||||
NiPoint3 finalPosition{};
|
||||
int32_t count{};
|
||||
bool bUsePosition{};
|
||||
LWOOBJID lootID{ LWOOBJID_EMPTY };
|
||||
LWOOBJID ownerID{ LWOOBJID_EMPTY };
|
||||
};
|
||||
|
||||
struct GetMissionState : public GameMsg {
|
||||
GetMissionState() : GameMsg(MessageType::Game::GET_MISSION_STATE) {}
|
||||
|
||||
int32_t missionID{};
|
||||
eMissionState missionState{};
|
||||
bool cooldownInfoRequested{};
|
||||
bool cooldownFinished{};
|
||||
};
|
||||
|
||||
struct GetFlag : public GameMsg {
|
||||
GetFlag() : GameMsg(MessageType::Game::GET_FLAG) {}
|
||||
|
||||
uint32_t flagID{};
|
||||
bool flag{};
|
||||
};
|
||||
|
||||
struct GetFactionTokenType : public GameMsg {
|
||||
GetFactionTokenType() : GameMsg(MessageType::Game::GET_FACTION_TOKEN_TYPE) {}
|
||||
|
||||
LOT tokenType{ LOT_NULL };
|
||||
};
|
||||
|
||||
struct MissionNeedsLot : public GameMsg {
|
||||
MissionNeedsLot() : GameMsg(MessageType::Game::MISSION_NEEDS_LOT) {}
|
||||
|
||||
LOT item{};
|
||||
};
|
||||
|
||||
struct PickupItem : public GameMsg {
|
||||
PickupItem() : GameMsg(MessageType::Game::PICKUP_ITEM) {}
|
||||
|
||||
void Handle(Entity& entity, const SystemAddress& sysAddr) override;
|
||||
bool Deserialize(RakNet::BitStream& stream) override;
|
||||
LWOOBJID lootID{};
|
||||
LWOOBJID lootOwnerID{};
|
||||
};
|
||||
|
||||
struct TeamPickupItem : public GameMsg {
|
||||
TeamPickupItem() : GameMsg(MessageType::Game::TEAM_PICKUP_ITEM) {}
|
||||
|
||||
void Serialize(RakNet::BitStream& stream) const override;
|
||||
LWOOBJID lootID{};
|
||||
LWOOBJID lootOwnerID{};
|
||||
};
|
||||
};
|
||||
#endif // GAMEMESSAGES_H
|
||||
|
||||
@@ -343,9 +343,9 @@ void Item::UseNonEquip(Item* item) {
|
||||
if (this->GetPreconditionExpression()->Check(playerInventoryComponent->GetParent())) {
|
||||
auto* entityParent = playerInventoryComponent->GetParent();
|
||||
// Roll the loot for all the packages then see if it all fits. If it fits, give it to the player, otherwise don't.
|
||||
std::unordered_map<LOT, int32_t> rolledLoot{};
|
||||
Loot::Return rolledLoot{};
|
||||
for (auto& pack : packages) {
|
||||
auto thisPackage = Loot::RollLootMatrix(entityParent, pack.LootMatrixIndex);
|
||||
const auto thisPackage = Loot::RollLootMatrix(entityParent, pack.LootMatrixIndex);
|
||||
for (auto& loot : thisPackage) {
|
||||
// If we already rolled this lot, add it to the existing one, otherwise create a new entry.
|
||||
auto existingLoot = rolledLoot.find(loot.first);
|
||||
@@ -356,6 +356,7 @@ void Item::UseNonEquip(Item* item) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (playerInventoryComponent->HasSpaceForLoot(rolledLoot)) {
|
||||
Loot::GiveLoot(playerInventoryComponent->GetParent(), rolledLoot, eLootSourceType::CONSUMPTION);
|
||||
item->SetCount(item->GetCount() - 1);
|
||||
|
||||
@@ -18,131 +18,27 @@
|
||||
#include "MissionComponent.h"
|
||||
#include "eMissionState.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
#include "TeamManager.h"
|
||||
#include "CDObjectsTable.h"
|
||||
#include "ObjectIDManager.h"
|
||||
|
||||
namespace {
|
||||
std::unordered_set<uint32_t> CachedMatrices;
|
||||
constexpr float g_MAX_DROP_RADIUS = 700.0f;
|
||||
}
|
||||
|
||||
void Loot::CacheMatrix(uint32_t matrixIndex) {
|
||||
if (CachedMatrices.contains(matrixIndex)) return;
|
||||
struct LootDropInfo {
|
||||
CDLootTable table{};
|
||||
uint32_t count{ 0 };
|
||||
};
|
||||
|
||||
CachedMatrices.insert(matrixIndex);
|
||||
std::map<LOT, LootDropInfo> RollLootMatrix(uint32_t matrixIndex) {
|
||||
CDComponentsRegistryTable* componentsRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
|
||||
CDItemComponentTable* itemComponentTable = CDClientManager::GetTable<CDItemComponentTable>();
|
||||
CDLootMatrixTable* lootMatrixTable = CDClientManager::GetTable<CDLootMatrixTable>();
|
||||
CDLootTableTable* lootTableTable = CDClientManager::GetTable<CDLootTableTable>();
|
||||
CDRarityTableTable* rarityTableTable = CDClientManager::GetTable<CDRarityTableTable>();
|
||||
|
||||
const auto& matrix = lootMatrixTable->GetMatrix(matrixIndex);
|
||||
|
||||
for (const auto& entry : matrix) {
|
||||
const auto& lootTable = lootTableTable->GetTable(entry.LootTableIndex);
|
||||
const auto& rarityTable = rarityTableTable->GetRarityTable(entry.RarityTableIndex);
|
||||
for (const auto& loot : lootTable) {
|
||||
uint32_t itemComponentId = componentsRegistryTable->GetByIDAndType(loot.itemid, eReplicaComponentType::ITEM);
|
||||
uint32_t rarity = itemComponentTable->GetItemComponentByID(itemComponentId).rarity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::unordered_map<LOT, int32_t> Loot::RollLootMatrix(Entity* player, uint32_t matrixIndex) {
|
||||
CDComponentsRegistryTable* componentsRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
|
||||
CDItemComponentTable* itemComponentTable = CDClientManager::GetTable<CDItemComponentTable>();
|
||||
CDLootMatrixTable* lootMatrixTable = CDClientManager::GetTable<CDLootMatrixTable>();
|
||||
CDLootTableTable* lootTableTable = CDClientManager::GetTable<CDLootTableTable>();
|
||||
CDRarityTableTable* rarityTableTable = CDClientManager::GetTable<CDRarityTableTable>();
|
||||
auto* missionComponent = player->GetComponent<MissionComponent>();
|
||||
|
||||
std::unordered_map<LOT, int32_t> drops;
|
||||
|
||||
if (missionComponent == nullptr) return drops;
|
||||
|
||||
const auto& matrix = lootMatrixTable->GetMatrix(matrixIndex);
|
||||
|
||||
for (const auto& entry : matrix) {
|
||||
if (GeneralUtils::GenerateRandomNumber<float>(0, 1) < entry.percent) { // GetTable
|
||||
const auto& lootTable = lootTableTable->GetTable(entry.LootTableIndex);
|
||||
const auto& rarityTable = rarityTableTable->GetRarityTable(entry.RarityTableIndex);
|
||||
|
||||
uint32_t dropCount = GeneralUtils::GenerateRandomNumber<uint32_t>(entry.minToDrop, entry.maxToDrop);
|
||||
for (uint32_t i = 0; i < dropCount; ++i) {
|
||||
uint32_t maxRarity = 1;
|
||||
|
||||
float rarityRoll = GeneralUtils::GenerateRandomNumber<float>(0, 1);
|
||||
|
||||
for (const auto& rarity : rarityTable) {
|
||||
if (rarity.randmax >= rarityRoll) {
|
||||
maxRarity = rarity.rarity;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool rarityFound = false;
|
||||
std::vector<CDLootTable> possibleDrops;
|
||||
|
||||
for (const auto& loot : lootTable) {
|
||||
uint32_t itemComponentId = componentsRegistryTable->GetByIDAndType(loot.itemid, eReplicaComponentType::ITEM);
|
||||
uint32_t rarity = itemComponentTable->GetItemComponentByID(itemComponentId).rarity;
|
||||
|
||||
if (rarity == maxRarity) {
|
||||
possibleDrops.push_back(loot);
|
||||
rarityFound = true;
|
||||
} else if (rarity < maxRarity && !rarityFound) {
|
||||
possibleDrops.push_back(loot);
|
||||
maxRarity = rarity;
|
||||
}
|
||||
}
|
||||
|
||||
if (possibleDrops.size() > 0) {
|
||||
const auto& drop = possibleDrops[GeneralUtils::GenerateRandomNumber<uint32_t>(0, possibleDrops.size() - 1)];
|
||||
|
||||
// filter out uneeded mission items
|
||||
if (drop.MissionDrop && !missionComponent->RequiresItem(drop.itemid))
|
||||
continue;
|
||||
|
||||
LOT itemID = drop.itemid;
|
||||
// convert faction token proxy
|
||||
if (itemID == 13763) {
|
||||
if (missionComponent->GetMissionState(545) == eMissionState::COMPLETE)
|
||||
itemID = 8318; // "Assembly Token"
|
||||
else if (missionComponent->GetMissionState(556) == eMissionState::COMPLETE)
|
||||
itemID = 8321; // "Venture League Token"
|
||||
else if (missionComponent->GetMissionState(567) == eMissionState::COMPLETE)
|
||||
itemID = 8319; // "Sentinels Token"
|
||||
else if (missionComponent->GetMissionState(578) == eMissionState::COMPLETE)
|
||||
itemID = 8320; // "Paradox Token"
|
||||
}
|
||||
|
||||
if (itemID == 13763) {
|
||||
continue;
|
||||
} // check if we aren't in faction
|
||||
|
||||
// drops[itemID]++; this should work?
|
||||
if (drops.find(itemID) == drops.end()) {
|
||||
drops.insert({ itemID, 1 });
|
||||
} else {
|
||||
++drops[itemID];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& drop : drops) {
|
||||
LOG("Player %llu has rolled %i of item %i from loot matrix %i", player->GetObjectID(), drop.second, drop.first, matrixIndex);
|
||||
}
|
||||
|
||||
return drops;
|
||||
}
|
||||
|
||||
std::unordered_map<LOT, int32_t> Loot::RollLootMatrix(uint32_t matrixIndex) {
|
||||
CDComponentsRegistryTable* componentsRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
|
||||
CDItemComponentTable* itemComponentTable = CDClientManager::GetTable<CDItemComponentTable>();
|
||||
CDLootMatrixTable* lootMatrixTable = CDClientManager::GetTable<CDLootMatrixTable>();
|
||||
CDLootTableTable* lootTableTable = CDClientManager::GetTable<CDLootTableTable>();
|
||||
CDRarityTableTable* rarityTableTable = CDClientManager::GetTable<CDRarityTableTable>();
|
||||
std::unordered_map<LOT, int32_t> drops;
|
||||
std::map<LOT, LootDropInfo> drops;
|
||||
|
||||
const auto& matrix = lootMatrixTable->GetMatrix(matrixIndex);
|
||||
|
||||
@@ -181,14 +77,12 @@ std::unordered_map<LOT, int32_t> Loot::RollLootMatrix(uint32_t matrixIndex) {
|
||||
}
|
||||
}
|
||||
|
||||
if (possibleDrops.size() > 0) {
|
||||
if (!possibleDrops.empty()) {
|
||||
const auto& drop = possibleDrops[GeneralUtils::GenerateRandomNumber<uint32_t>(0, possibleDrops.size() - 1)];
|
||||
|
||||
if (drops.find(drop.itemid) == drops.end()) {
|
||||
drops.insert({ drop.itemid, 1 });
|
||||
} else {
|
||||
++drops[drop.itemid];
|
||||
}
|
||||
auto& info = drops[drop.itemid];
|
||||
if (info.count == 0) info.table = drop;
|
||||
info.count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,15 +91,395 @@ std::unordered_map<LOT, int32_t> Loot::RollLootMatrix(uint32_t matrixIndex) {
|
||||
return drops;
|
||||
}
|
||||
|
||||
// Generates a 'random' final position for the loot drop based on its input spawn position.
|
||||
void CalcFinalDropPos(GameMessages::DropClientLoot& lootMsg) {
|
||||
lootMsg.bUsePosition = true;
|
||||
|
||||
//Calculate where the loot will go:
|
||||
uint16_t degree = GeneralUtils::GenerateRandomNumber<uint16_t>(0, 360);
|
||||
|
||||
double rad = degree * 3.14 / 180;
|
||||
double sin_v = sin(rad) * 4.2;
|
||||
double cos_v = cos(rad) * 4.2;
|
||||
|
||||
const auto [x, y, z] = lootMsg.spawnPos;
|
||||
lootMsg.finalPosition = NiPoint3(static_cast<float>(x + sin_v), y, static_cast<float>(z + cos_v));
|
||||
}
|
||||
|
||||
// Visually drop the loot to all team members, though only the lootMsg.ownerID can pick it up
|
||||
void DistrbuteMsgToTeam(const GameMessages::DropClientLoot& lootMsg, const Team& team) {
|
||||
for (const auto memberClient : team.members) {
|
||||
const auto* const memberEntity = Game::entityManager->GetEntity(memberClient);
|
||||
if (memberEntity) lootMsg.Send(memberEntity->GetSystemAddress());
|
||||
}
|
||||
}
|
||||
|
||||
// The following 8 functions are all ever so slightly different such that combining them
|
||||
// would make the logic harder to follow. Please read the comments!
|
||||
|
||||
// Given a faction token proxy LOT to drop, drop 1 token for each player on a team, or the provided player.
|
||||
// token drops are always given to every player on the team.
|
||||
void DropFactionLoot(Entity& player, GameMessages::DropClientLoot& lootMsg) {
|
||||
const auto playerID = player.GetObjectID();
|
||||
|
||||
GameMessages::GetFactionTokenType factionTokenType{};
|
||||
factionTokenType.target = playerID;
|
||||
// If we're not in a faction, this message will return false
|
||||
if (factionTokenType.Send()) {
|
||||
lootMsg.item = factionTokenType.tokenType;
|
||||
lootMsg.target = playerID;
|
||||
lootMsg.ownerID = playerID;
|
||||
lootMsg.lootID = ObjectIDManager::GenerateObjectID();
|
||||
CalcFinalDropPos(lootMsg);
|
||||
// Register the drop on the player
|
||||
lootMsg.Send();
|
||||
// Visually drop it for the player
|
||||
lootMsg.Send(player.GetSystemAddress());
|
||||
}
|
||||
}
|
||||
|
||||
// Drops 1 token for each player on a team
|
||||
// token drops are always given to every player on the team.
|
||||
void DropFactionLoot(const Team& team, GameMessages::DropClientLoot& lootMsg) {
|
||||
for (const auto member : team.members) {
|
||||
GameMessages::GetPosition memberPosMsg{};
|
||||
memberPosMsg.target = member;
|
||||
memberPosMsg.Send();
|
||||
if (NiPoint3::Distance(memberPosMsg.pos, lootMsg.spawnPos) > g_MAX_DROP_RADIUS) continue;
|
||||
|
||||
GameMessages::GetFactionTokenType factionTokenType{};
|
||||
factionTokenType.target = member;
|
||||
// If we're not in a faction, this message will return false
|
||||
if (factionTokenType.Send()) {
|
||||
lootMsg.item = factionTokenType.tokenType;
|
||||
lootMsg.target = member;
|
||||
lootMsg.ownerID = member;
|
||||
lootMsg.lootID = ObjectIDManager::GenerateObjectID();
|
||||
CalcFinalDropPos(lootMsg);
|
||||
// Register the drop on this team member
|
||||
lootMsg.Send();
|
||||
// Show the rewards on all connected members of the team. Only the loot owner will be able to pick the tokens up.
|
||||
DistrbuteMsgToTeam(lootMsg, team);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Drop the power up with no owner
|
||||
// Power ups can be picked up by anyone on a team, however unlike actual loot items,
|
||||
// if multiple clients say they picked one up, we let them pick it up.
|
||||
void DropPowerupLoot(Entity& player, GameMessages::DropClientLoot& lootMsg) {
|
||||
const auto playerID = player.GetObjectID();
|
||||
CalcFinalDropPos(lootMsg);
|
||||
|
||||
lootMsg.lootID = ObjectIDManager::GenerateObjectID();
|
||||
lootMsg.ownerID = playerID;
|
||||
lootMsg.target = playerID;
|
||||
|
||||
// Register the drop on the player
|
||||
lootMsg.Send();
|
||||
// Visually drop it for the player
|
||||
lootMsg.Send(player.GetSystemAddress());
|
||||
}
|
||||
|
||||
// Drop the power up with no owner
|
||||
// Power ups can be picked up by anyone on a team, however unlike actual loot items,
|
||||
// if multiple clients say they picked one up, we let them pick it up.
|
||||
void DropPowerupLoot(const Team& team, GameMessages::DropClientLoot& lootMsg) {
|
||||
lootMsg.lootID = ObjectIDManager::GenerateObjectID();
|
||||
lootMsg.ownerID = LWOOBJID_EMPTY; // By setting ownerID to empty, any client that gets this DropClientLoot message can pick up the item.
|
||||
CalcFinalDropPos(lootMsg);
|
||||
|
||||
// We want to drop the powerups as the same ID and the same position to all members of the team
|
||||
for (const auto member : team.members) {
|
||||
GameMessages::GetPosition memberPosMsg{};
|
||||
memberPosMsg.target = member;
|
||||
memberPosMsg.Send();
|
||||
if (NiPoint3::Distance(memberPosMsg.pos, lootMsg.spawnPos) > g_MAX_DROP_RADIUS) continue;
|
||||
|
||||
lootMsg.target = member;
|
||||
// By sending this message with the same ID to all players on the team, all players on the team are allowed to pick it up.
|
||||
lootMsg.Send();
|
||||
// No need to send to all members in a loop since that will happen by using the outer loop above and also since there is no owner
|
||||
// sending to all will do nothing.
|
||||
const auto* const memberEntity = Game::entityManager->GetEntity(member);
|
||||
if (memberEntity) lootMsg.Send(memberEntity->GetSystemAddress());
|
||||
}
|
||||
}
|
||||
|
||||
// Drops a mission item for a player
|
||||
// If the player does not need this item, it will not be dropped.
|
||||
void DropMissionLoot(Entity& player, GameMessages::DropClientLoot& lootMsg) {
|
||||
GameMessages::MissionNeedsLot needMsg{};
|
||||
needMsg.item = lootMsg.item;
|
||||
const auto playerID = player.GetObjectID();
|
||||
needMsg.target = playerID;
|
||||
// Will return false if the item is not required
|
||||
if (needMsg.Send()) {
|
||||
lootMsg.target = playerID;
|
||||
lootMsg.ownerID = playerID;
|
||||
lootMsg.lootID = ObjectIDManager::GenerateObjectID();
|
||||
CalcFinalDropPos(lootMsg);
|
||||
// Register the drop with the player
|
||||
lootMsg.Send();
|
||||
// Visually drop the loot to be picked up
|
||||
lootMsg.Send(player.GetSystemAddress());
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the item needs to be dropped for anyone on the team
|
||||
// Only players who need the item will have it dropped
|
||||
void DropMissionLoot(const Team& team, GameMessages::DropClientLoot& lootMsg) {
|
||||
GameMessages::MissionNeedsLot needMsg{};
|
||||
needMsg.item = lootMsg.item;
|
||||
for (const auto member : team.members) {
|
||||
GameMessages::GetPosition memberPosMsg{};
|
||||
memberPosMsg.target = member;
|
||||
memberPosMsg.Send();
|
||||
if (NiPoint3::Distance(memberPosMsg.pos, lootMsg.spawnPos) > g_MAX_DROP_RADIUS) continue;
|
||||
|
||||
needMsg.target = member;
|
||||
// Will return false if the item is not required
|
||||
if (needMsg.Send()) {
|
||||
lootMsg.target = member;
|
||||
lootMsg.ownerID = member;
|
||||
lootMsg.lootID = ObjectIDManager::GenerateObjectID();
|
||||
CalcFinalDropPos(lootMsg);
|
||||
// Register the drop with the player
|
||||
lootMsg.Send();
|
||||
DistrbuteMsgToTeam(lootMsg, team);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Drop a regular piece of loot.
|
||||
// Most items will go through this.
|
||||
// A player will always get a drop that goes through this function
|
||||
void DropRegularLoot(Entity& player, GameMessages::DropClientLoot& lootMsg) {
|
||||
const auto playerID = player.GetObjectID();
|
||||
|
||||
CalcFinalDropPos(lootMsg);
|
||||
|
||||
lootMsg.lootID = ObjectIDManager::GenerateObjectID();
|
||||
lootMsg.target = playerID;
|
||||
lootMsg.ownerID = playerID;
|
||||
// Register the drop with the player
|
||||
lootMsg.Send();
|
||||
// Visually drop the loot to be picked up
|
||||
lootMsg.Send(player.GetSystemAddress());
|
||||
|
||||
}
|
||||
|
||||
// Drop a regular piece of loot.
|
||||
// Most items will go through this.
|
||||
// Finds the next loot owner on the team the is in range of the kill and gives them this reward.
|
||||
void DropRegularLoot(Team& team, GameMessages::DropClientLoot& lootMsg) {
|
||||
auto earningPlayer = LWOOBJID_EMPTY;
|
||||
lootMsg.lootID = ObjectIDManager::GenerateObjectID();
|
||||
CalcFinalDropPos(lootMsg);
|
||||
GameMessages::GetPosition memberPosMsg{};
|
||||
// Find the next loot owner. Eventually this will run into the `player` passed into this function, since those will
|
||||
// have the same ID, this loop will only ever run at most 4 times.
|
||||
do {
|
||||
earningPlayer = team.GetNextLootOwner();
|
||||
memberPosMsg.target = earningPlayer;
|
||||
memberPosMsg.Send();
|
||||
} while (NiPoint3::Distance(memberPosMsg.pos, lootMsg.spawnPos) > g_MAX_DROP_RADIUS);
|
||||
|
||||
if (team.lootOption == 0 /* Shared loot */) {
|
||||
lootMsg.target = earningPlayer;
|
||||
lootMsg.ownerID = earningPlayer;
|
||||
lootMsg.Send();
|
||||
} else /* Free for all loot */ {
|
||||
lootMsg.ownerID = LWOOBJID_EMPTY;
|
||||
// By sending the loot with NO owner and to ALL members of the team,
|
||||
// its a first come, first serve with who picks the item up.
|
||||
for (const auto ffaMember : team.members) {
|
||||
lootMsg.target = ffaMember;
|
||||
lootMsg.Send();
|
||||
}
|
||||
}
|
||||
|
||||
DistrbuteMsgToTeam(lootMsg, team);
|
||||
}
|
||||
|
||||
void DropLoot(Entity* player, const LWOOBJID source, const std::map<LOT, LootDropInfo>& rolledItems, uint32_t minCoins, uint32_t maxCoins) {
|
||||
player = player->GetOwner(); // if the owner is overwritten, we collect that here
|
||||
const auto playerID = player->GetObjectID();
|
||||
if (!player || !player->IsPlayer()) {
|
||||
LOG("Trying to drop loot for non-player %llu:%i", playerID, player->GetLOT());
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO should be scene based instead of radius based
|
||||
// drop loot to either single player or team
|
||||
// powerups never have an owner when dropped
|
||||
// for every player on the team in a radius of 700 (arbitrary value, not lore)
|
||||
// if shared loot, drop everything but tokens to the next team member that gets loot,
|
||||
// then tokens to everyone (1 token drop in a 3 person team means everyone gets a token)
|
||||
// if Free for all, drop everything with NO owner, except tokens which follow the same logic as above
|
||||
auto* team = TeamManager::Instance()->GetTeam(playerID);
|
||||
|
||||
GameMessages::GetPosition posMsg;
|
||||
posMsg.target = source;
|
||||
posMsg.Send();
|
||||
|
||||
const auto spawnPosition = posMsg.pos;
|
||||
auto* const objectsTable = CDClientManager::GetTable<CDObjectsTable>();
|
||||
|
||||
constexpr LOT TOKEN_PROXY = 13763;
|
||||
// Go through the drops 1 at a time to drop them
|
||||
for (auto it = rolledItems.begin(); it != rolledItems.end(); it++) {
|
||||
auto& [lootLot, info] = *it;
|
||||
for (int i = 0; i < info.count; i++) {
|
||||
GameMessages::DropClientLoot lootMsg{};
|
||||
lootMsg.spawnPos = spawnPosition;
|
||||
lootMsg.sourceID = source;
|
||||
lootMsg.item = lootLot;
|
||||
lootMsg.count = 1;
|
||||
lootMsg.currency = 0;
|
||||
const CDObjects& object = objectsTable->GetByID(lootLot);
|
||||
|
||||
if (lootLot == TOKEN_PROXY) {
|
||||
team ? DropFactionLoot(*team, lootMsg) : DropFactionLoot(*player, lootMsg);
|
||||
} else if (info.table.MissionDrop) {
|
||||
team ? DropMissionLoot(*team, lootMsg) : DropMissionLoot(*player, lootMsg);
|
||||
} else if (object.type == "Powerup") {
|
||||
team ? DropPowerupLoot(*team, lootMsg) : DropPowerupLoot(*player, lootMsg);
|
||||
} else {
|
||||
team ? DropRegularLoot(*team, lootMsg) : DropRegularLoot(*player, lootMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Coin roll is divided up between the members, rounded up, then dropped for each player
|
||||
const uint32_t coinRoll = static_cast<uint32_t>(minCoins + GeneralUtils::GenerateRandomNumber<float>(0, 1) * (maxCoins - minCoins));
|
||||
const auto droppedCoins = team ? std::ceil(coinRoll / team->members.size()) : coinRoll;
|
||||
if (team) {
|
||||
for (auto member : team->members) {
|
||||
GameMessages::DropClientLoot lootMsg{};
|
||||
lootMsg.target = member;
|
||||
lootMsg.ownerID = member;
|
||||
lootMsg.currency = droppedCoins;
|
||||
lootMsg.spawnPos = spawnPosition;
|
||||
lootMsg.sourceID = source;
|
||||
lootMsg.item = LOT_NULL;
|
||||
lootMsg.Send();
|
||||
const auto* const memberEntity = Game::entityManager->GetEntity(member);
|
||||
if (memberEntity) lootMsg.Send(memberEntity->GetSystemAddress());
|
||||
}
|
||||
} else {
|
||||
GameMessages::DropClientLoot lootMsg{};
|
||||
lootMsg.target = playerID;
|
||||
lootMsg.ownerID = playerID;
|
||||
lootMsg.currency = droppedCoins;
|
||||
lootMsg.spawnPos = spawnPosition;
|
||||
lootMsg.sourceID = source;
|
||||
lootMsg.item = LOT_NULL;
|
||||
lootMsg.Send();
|
||||
lootMsg.Send(player->GetSystemAddress());
|
||||
}
|
||||
}
|
||||
|
||||
void Loot::DropItem(Entity& player, GameMessages::DropClientLoot& lootMsg, bool useTeam, bool forceFfa) {
|
||||
auto* const team = useTeam ? TeamManager::Instance()->GetTeam(player.GetObjectID()) : nullptr;
|
||||
char oldTeamLoot{};
|
||||
if (team && forceFfa) {
|
||||
oldTeamLoot = team->lootOption;
|
||||
team->lootOption = 1;
|
||||
}
|
||||
|
||||
auto* const objectsTable = CDClientManager::GetTable<CDObjectsTable>();
|
||||
const CDObjects& object = objectsTable->GetByID(lootMsg.item);
|
||||
|
||||
constexpr LOT TOKEN_PROXY = 13763;
|
||||
if (lootMsg.item == TOKEN_PROXY) {
|
||||
team ? DropFactionLoot(*team, lootMsg) : DropFactionLoot(player, lootMsg);
|
||||
} else if (object.type == "Powerup") {
|
||||
team ? DropPowerupLoot(*team, lootMsg) : DropPowerupLoot(player, lootMsg);
|
||||
} else {
|
||||
team ? DropRegularLoot(*team, lootMsg) : DropRegularLoot(player, lootMsg);
|
||||
}
|
||||
|
||||
if (team) team->lootOption = oldTeamLoot;
|
||||
}
|
||||
|
||||
void Loot::CacheMatrix(uint32_t matrixIndex) {
|
||||
if (CachedMatrices.contains(matrixIndex)) return;
|
||||
|
||||
CachedMatrices.insert(matrixIndex);
|
||||
CDComponentsRegistryTable* componentsRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
|
||||
CDItemComponentTable* itemComponentTable = CDClientManager::GetTable<CDItemComponentTable>();
|
||||
CDLootMatrixTable* lootMatrixTable = CDClientManager::GetTable<CDLootMatrixTable>();
|
||||
CDLootTableTable* lootTableTable = CDClientManager::GetTable<CDLootTableTable>();
|
||||
CDRarityTableTable* rarityTableTable = CDClientManager::GetTable<CDRarityTableTable>();
|
||||
|
||||
const auto& matrix = lootMatrixTable->GetMatrix(matrixIndex);
|
||||
|
||||
for (const auto& entry : matrix) {
|
||||
const auto& lootTable = lootTableTable->GetTable(entry.LootTableIndex);
|
||||
const auto& rarityTable = rarityTableTable->GetRarityTable(entry.RarityTableIndex);
|
||||
for (const auto& loot : lootTable) {
|
||||
uint32_t itemComponentId = componentsRegistryTable->GetByIDAndType(loot.itemid, eReplicaComponentType::ITEM);
|
||||
uint32_t rarity = itemComponentTable->GetItemComponentByID(itemComponentId).rarity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loot::Return Loot::RollLootMatrix(Entity* player, uint32_t matrixIndex) {
|
||||
auto* const missionComponent = player ? player->GetComponent<MissionComponent>() : nullptr;
|
||||
|
||||
Loot::Return toReturn;
|
||||
const auto drops = ::RollLootMatrix(matrixIndex);
|
||||
// if no mission component, just convert the map and skip checking if its a mission drop
|
||||
if (!missionComponent) {
|
||||
for (const auto& [lot, info] : drops) toReturn[lot] = info.count;
|
||||
} else {
|
||||
for (const auto& [lot, info] : drops) {
|
||||
const auto& itemInfo = info.table;
|
||||
|
||||
// filter out uneeded mission items
|
||||
if (itemInfo.MissionDrop && !missionComponent->RequiresItem(itemInfo.itemid))
|
||||
continue;
|
||||
|
||||
LOT itemLot = lot;
|
||||
// convert faction token proxy
|
||||
if (itemLot == 13763) {
|
||||
if (missionComponent->GetMissionState(545) == eMissionState::COMPLETE)
|
||||
itemLot = 8318; // "Assembly Token"
|
||||
else if (missionComponent->GetMissionState(556) == eMissionState::COMPLETE)
|
||||
itemLot = 8321; // "Venture League Token"
|
||||
else if (missionComponent->GetMissionState(567) == eMissionState::COMPLETE)
|
||||
itemLot = 8319; // "Sentinels Token"
|
||||
else if (missionComponent->GetMissionState(578) == eMissionState::COMPLETE)
|
||||
itemLot = 8320; // "Paradox Token"
|
||||
}
|
||||
|
||||
if (itemLot == 13763) {
|
||||
continue;
|
||||
} // check if we aren't in faction
|
||||
|
||||
toReturn[itemLot] = info.count;
|
||||
}
|
||||
}
|
||||
|
||||
if (player) {
|
||||
for (const auto& [lot, count] : toReturn) {
|
||||
LOG("Player %llu has rolled %i of item %i from loot matrix %i", player->GetObjectID(), count, lot, matrixIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
void Loot::GiveLoot(Entity* player, uint32_t matrixIndex, eLootSourceType lootSourceType) {
|
||||
player = player->GetOwner(); // If the owner is overwritten, we collect that here
|
||||
|
||||
std::unordered_map<LOT, int32_t> result = RollLootMatrix(player, matrixIndex);
|
||||
const auto result = RollLootMatrix(player, matrixIndex);
|
||||
|
||||
GiveLoot(player, result, lootSourceType);
|
||||
}
|
||||
|
||||
void Loot::GiveLoot(Entity* player, std::unordered_map<LOT, int32_t>& result, eLootSourceType lootSourceType) {
|
||||
void Loot::GiveLoot(Entity* player, const Loot::Return& result, eLootSourceType lootSourceType) {
|
||||
player = player->GetOwner(); // if the owner is overwritten, we collect that here
|
||||
|
||||
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
|
||||
@@ -260,34 +534,9 @@ void Loot::DropLoot(Entity* player, const LWOOBJID source, uint32_t matrixIndex,
|
||||
if (!inventoryComponent)
|
||||
return;
|
||||
|
||||
std::unordered_map<LOT, int32_t> result = RollLootMatrix(player, matrixIndex);
|
||||
const auto result = ::RollLootMatrix(matrixIndex);
|
||||
|
||||
DropLoot(player, source, result, minCoins, maxCoins);
|
||||
}
|
||||
|
||||
void Loot::DropLoot(Entity* player, const LWOOBJID source, std::unordered_map<LOT, int32_t>& result, uint32_t minCoins, uint32_t maxCoins) {
|
||||
player = player->GetOwner(); // if the owner is overwritten, we collect that here
|
||||
|
||||
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
|
||||
|
||||
if (!inventoryComponent)
|
||||
return;
|
||||
|
||||
GameMessages::GetPosition posMsg;
|
||||
posMsg.target = source;
|
||||
posMsg.Send();
|
||||
|
||||
const auto spawnPosition = posMsg.pos;
|
||||
|
||||
for (const auto& pair : result) {
|
||||
for (int i = 0; i < pair.second; ++i) {
|
||||
GameMessages::SendDropClientLoot(player, source, pair.first, 0, spawnPosition, 1);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t coins = static_cast<uint32_t>(minCoins + GeneralUtils::GenerateRandomNumber<float>(0, 1) * (maxCoins - minCoins));
|
||||
|
||||
GameMessages::SendDropClientLoot(player, source, LOT_NULL, coins, spawnPosition);
|
||||
::DropLoot(player, source, result, minCoins, maxCoins);
|
||||
}
|
||||
|
||||
void Loot::DropActivityLoot(Entity* player, const LWOOBJID source, uint32_t activityID, int32_t rating) {
|
||||
|
||||
@@ -6,20 +6,25 @@
|
||||
|
||||
class Entity;
|
||||
|
||||
namespace GameMessages {
|
||||
struct DropClientLoot;
|
||||
};
|
||||
|
||||
namespace Loot {
|
||||
struct Info {
|
||||
LWOOBJID id = 0;
|
||||
LOT lot = 0;
|
||||
uint32_t count = 0;
|
||||
int32_t count = 0;
|
||||
};
|
||||
|
||||
std::unordered_map<LOT, int32_t> RollLootMatrix(Entity* player, uint32_t matrixIndex);
|
||||
std::unordered_map<LOT, int32_t> RollLootMatrix(uint32_t matrixIndex);
|
||||
using Return = std::map<LOT, int32_t>;
|
||||
|
||||
Loot::Return RollLootMatrix(Entity* player, uint32_t matrixIndex);
|
||||
void CacheMatrix(const uint32_t matrixIndex);
|
||||
void GiveLoot(Entity* player, uint32_t matrixIndex, eLootSourceType lootSourceType = eLootSourceType::NONE);
|
||||
void GiveLoot(Entity* player, std::unordered_map<LOT, int32_t>& result, eLootSourceType lootSourceType = eLootSourceType::NONE);
|
||||
void GiveLoot(Entity* player, const Loot::Return& result, eLootSourceType lootSourceType = eLootSourceType::NONE);
|
||||
void GiveActivityLoot(Entity* player, const LWOOBJID source, uint32_t activityID, int32_t rating = 0);
|
||||
void DropLoot(Entity* player, const LWOOBJID source, uint32_t matrixIndex, uint32_t minCoins, uint32_t maxCoins);
|
||||
void DropLoot(Entity* player, const LWOOBJID source, std::unordered_map<LOT, int32_t>& result, uint32_t minCoins, uint32_t maxCoins);
|
||||
void DropItem(Entity& player, GameMessages::DropClientLoot& lootMsg, bool useTeam = false, bool forceFfa = false);
|
||||
void DropActivityLoot(Entity* player, const LWOOBJID source, uint32_t activityID, int32_t rating = 0);
|
||||
};
|
||||
|
||||
@@ -1314,7 +1314,7 @@ namespace DEVGMCommands {
|
||||
|
||||
for (uint32_t i = 0; i < loops; i++) {
|
||||
while (true) {
|
||||
auto lootRoll = Loot::RollLootMatrix(lootMatrixIndex.value());
|
||||
const auto lootRoll = Loot::RollLootMatrix(nullptr, lootMatrixIndex.value());
|
||||
totalRuns += 1;
|
||||
bool doBreak = false;
|
||||
for (const auto& kv : lootRoll) {
|
||||
@@ -1479,15 +1479,20 @@ namespace DEVGMCommands {
|
||||
void Inspect(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
|
||||
const auto splitArgs = GeneralUtils::SplitString(args, ' ');
|
||||
if (splitArgs.empty()) return;
|
||||
const auto idParsed = GeneralUtils::TryParse<LWOOBJID>(splitArgs[0]);
|
||||
|
||||
// First try to get the object by its ID if provided.
|
||||
// Second try to get the object by player name.
|
||||
// Lastly assume we were passed a component or LDF and try to find the closest entity with that component or LDF.
|
||||
Entity* closest = nullptr;
|
||||
if (idParsed) closest = Game::entityManager->GetEntity(idParsed.value());
|
||||
float closestDistance = 0.0f;
|
||||
|
||||
std::u16string ldf;
|
||||
|
||||
bool isLDF = false;
|
||||
|
||||
closest = PlayerManager::GetPlayer(splitArgs[0]);
|
||||
if (!closest) closest = PlayerManager::GetPlayer(splitArgs[0]);
|
||||
if (!closest) {
|
||||
auto component = GeneralUtils::TryParse<eReplicaComponentType>(splitArgs[0]);
|
||||
if (!component) {
|
||||
|
||||
@@ -15,11 +15,6 @@ void ScriptedPowerupSpawner::OnTimerDone(Entity* self, std::string message) {
|
||||
|
||||
const auto itemLOT = self->GetVar<LOT>(u"lootLOT");
|
||||
|
||||
// Build drop table
|
||||
std::unordered_map<LOT, int32_t> drops;
|
||||
|
||||
drops.emplace(itemLOT, 1);
|
||||
|
||||
// Spawn the required number of powerups
|
||||
auto* owner = Game::entityManager->GetEntity(self->GetSpawnerID());
|
||||
if (owner != nullptr) {
|
||||
@@ -28,8 +23,19 @@ void ScriptedPowerupSpawner::OnTimerDone(Entity* self, std::string message) {
|
||||
if (renderComponent != nullptr) {
|
||||
renderComponent->PlayEffect(0, u"cast", "N_cast");
|
||||
}
|
||||
GameMessages::GetPosition posMsg{};
|
||||
posMsg.target = self->GetObjectID();
|
||||
posMsg.Send();
|
||||
|
||||
Loot::DropLoot(owner, self->GetObjectID(), drops, 0, 0);
|
||||
GameMessages::DropClientLoot lootMsg{};
|
||||
lootMsg.target = owner->GetObjectID();
|
||||
lootMsg.ownerID = owner->GetObjectID();
|
||||
lootMsg.sourceID = self->GetObjectID();
|
||||
lootMsg.spawnPos = posMsg.pos;
|
||||
lootMsg.item = itemLOT;
|
||||
lootMsg.count = 1;
|
||||
lootMsg.currency = 0;
|
||||
Loot::DropItem(*owner, lootMsg, true, true);
|
||||
}
|
||||
|
||||
// Increment the current cycle
|
||||
|
||||
@@ -10,8 +10,21 @@ void AgPicnicBlanket::OnUse(Entity* self, Entity* user) {
|
||||
return;
|
||||
self->SetVar<bool>(u"active", true);
|
||||
|
||||
auto lootTable = std::unordered_map<LOT, int32_t>{ {935, 3} };
|
||||
Loot::DropLoot(user, self->GetObjectID(), lootTable, 0, 0);
|
||||
GameMessages::GetPosition posMsg{};
|
||||
posMsg.target = self->GetObjectID();
|
||||
posMsg.Send();
|
||||
|
||||
for (int32_t i = 0; i < 3; i++) {
|
||||
GameMessages::DropClientLoot lootMsg{};
|
||||
lootMsg.target = user->GetObjectID();
|
||||
lootMsg.ownerID = user->GetObjectID();
|
||||
lootMsg.sourceID = self->GetObjectID();
|
||||
lootMsg.item = 935;
|
||||
lootMsg.count = 1;
|
||||
lootMsg.spawnPos = posMsg.pos;
|
||||
lootMsg.currency = 0;
|
||||
Loot::DropItem(*user, lootMsg, true);
|
||||
}
|
||||
|
||||
self->AddCallbackTimer(5.0f, [self]() {
|
||||
self->SetVar<bool>(u"active", false);
|
||||
|
||||
@@ -415,9 +415,7 @@ void SGCannon::SpawnNewModel(Entity* self) {
|
||||
}
|
||||
|
||||
if (lootMatrix != 0) {
|
||||
std::unordered_map<LOT, int32_t> toDrop = {};
|
||||
toDrop = Loot::RollLootMatrix(player, lootMatrix);
|
||||
|
||||
const auto toDrop = Loot::RollLootMatrix(player, lootMatrix);
|
||||
for (const auto [lot, count] : toDrop) {
|
||||
GameMessages::SetModelToBuild modelToBuild{};
|
||||
modelToBuild.modelLot = lot;
|
||||
|
||||
@@ -47,7 +47,7 @@ client_net_version=171022
|
||||
|
||||
# Turn to 0 to default teams to use the live accurate Shared Loot (0) by default as opposed to Free for All (1)
|
||||
# This is used in both Chat and World servers.
|
||||
default_team_loot=1
|
||||
default_team_loot=0
|
||||
|
||||
# event gating for login response and luz gating
|
||||
event_1=Talk_Like_A_Pirate
|
||||
|
||||
@@ -106,3 +106,6 @@ hardcore_coin_keep=
|
||||
# Export terrain meshes to OBJ files when zones load
|
||||
# OBJ files will be saved as terrain_<zoneID>.obj in the server directory
|
||||
export_terrain_to_obj=0
|
||||
|
||||
# save pre-split lxfmls to disk for debugging
|
||||
save_lxfmls=0
|
||||
|
||||
@@ -8,6 +8,8 @@ set(LXFMLTESTFILES
|
||||
"no_bricks.lxfml"
|
||||
"test.lxfml"
|
||||
"too_few_values.lxfml"
|
||||
"group_issue.lxfml"
|
||||
"complex_grouping.lxfml"
|
||||
)
|
||||
|
||||
# Get the folder name and prepend it to the files above
|
||||
|
||||
132
tests/dCommonTests/LxfmlTestFiles/complex_grouping.lxfml
Normal file
132
tests/dCommonTests/LxfmlTestFiles/complex_grouping.lxfml
Normal file
@@ -0,0 +1,132 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<LXFML versionMajor="5" versionMinor="0">
|
||||
<Meta>
|
||||
<Application name="LEGO Universe" versionMajor="0" versionMinor="0"/>
|
||||
<Brand name="LEGOUniverse"/>
|
||||
<BrickSet version="457"/>
|
||||
</Meta>
|
||||
<Bricks>
|
||||
<Brick refID="0" designID="3001">
|
||||
<Part refID="0" designID="3001" materials="23">
|
||||
<Bone refID="0" transformation="1,0,0,0,1,0,0,0,1,-35.599998474121094,434.87997436523437,-56.400001525878906">
|
||||
</Bone>
|
||||
</Part>
|
||||
</Brick>
|
||||
<Brick refID="1" designID="3001">
|
||||
<Part refID="1" designID="3001" materials="23">
|
||||
<Bone refID="1" transformation="1,0,0,0,1,0,0,0,1,-35.599998474121094,433.91998291015625,-56.400001525878906">
|
||||
</Bone>
|
||||
</Part>
|
||||
</Brick>
|
||||
<Brick refID="2" designID="3001">
|
||||
<Part refID="2" designID="3001" materials="23">
|
||||
<Bone refID="2" transformation="1,0,0,0,1,0,0,0,1,-35.599998474121094,435.8399658203125,-56.399993896484375">
|
||||
</Bone>
|
||||
</Part>
|
||||
</Brick>
|
||||
<Brick refID="3" designID="3001">
|
||||
<Part refID="3" designID="3001" materials="23">
|
||||
<Bone refID="3" transformation="1,0,0,0,1,0,0,0,1,-35.599998474121094,432.95999145507812,-56.399993896484375">
|
||||
</Bone>
|
||||
</Part>
|
||||
</Brick>
|
||||
<Brick refID="4" designID="3001">
|
||||
<Part refID="4" designID="3001" materials="23">
|
||||
<Bone refID="4" transformation="1,0,0,0,1,0,0,0,1,-35.599998474121094,432.95999145507812,-51.600002288818359">
|
||||
</Bone>
|
||||
</Part>
|
||||
</Brick>
|
||||
<Brick refID="5" designID="3001">
|
||||
<Part refID="5" designID="3001" materials="23">
|
||||
<Bone refID="5" transformation="1,0,0,0,1,0,0,0,1,-35.599998474121094,433.91998291015625,-51.600002288818359">
|
||||
</Bone>
|
||||
</Part>
|
||||
</Brick>
|
||||
<Brick refID="6" designID="3001">
|
||||
<Part refID="6" designID="3001" materials="23">
|
||||
<Bone refID="6" transformation="1,0,0,0,1,0,0,0,1,-35.599998474121094,434.87997436523437,-51.600002288818359">
|
||||
</Bone>
|
||||
</Part>
|
||||
</Brick>
|
||||
<Brick refID="7" designID="3001">
|
||||
<Part refID="7" designID="3001" materials="23">
|
||||
<Bone refID="7" transformation="1,0,0,0,1,0,0,0,1,-35.599998474121094,435.8399658203125,-51.600002288818359">
|
||||
</Bone>
|
||||
</Part>
|
||||
</Brick>
|
||||
<Brick refID="8" designID="3001">
|
||||
<Part refID="8" designID="3001" materials="23">
|
||||
<Bone refID="8" transformation="1,0,0,0,1,0,0,0,1,-35.599998474121094,432.95999145507812,-50.000003814697266">
|
||||
</Bone>
|
||||
</Part>
|
||||
</Brick>
|
||||
<Brick refID="9" designID="3001">
|
||||
<Part refID="9" designID="3001" materials="23">
|
||||
<Bone refID="9" transformation="1,0,0,0,1,0,0,0,1,-35.599998474121094,433.91998291015625,-50.000003814697266">
|
||||
</Bone>
|
||||
</Part>
|
||||
</Brick>
|
||||
<Brick refID="10" designID="3001">
|
||||
<Part refID="10" designID="3001" materials="23">
|
||||
<Bone refID="10" transformation="1,0,0,0,1,0,0,0,1,-35.599998474121094,434.87997436523437,-50.000003814697266">
|
||||
</Bone>
|
||||
</Part>
|
||||
</Brick>
|
||||
<Brick refID="11" designID="3001">
|
||||
<Part refID="11" designID="3001" materials="23">
|
||||
<Bone refID="11" transformation="1,0,0,0,1,0,0,0,1,-35.599998474121094,435.8399658203125,-50.000003814697266">
|
||||
</Bone>
|
||||
</Part>
|
||||
</Brick>
|
||||
<Brick refID="12" designID="3001">
|
||||
<Part refID="12" designID="3001" materials="23">
|
||||
<Bone refID="12" transformation="1,0,0,0,1,0,0,0,1,-35.599998474121094,434.87997436523437,-54.800003051757813">
|
||||
</Bone>
|
||||
</Part>
|
||||
</Brick>
|
||||
<Brick refID="13" designID="3001">
|
||||
<Part refID="13" designID="3001" materials="23">
|
||||
<Bone refID="13" transformation="1,0,0,0,1,0,0,0,1,-35.599998474121094,433.91998291015625,-54.800003051757813">
|
||||
</Bone>
|
||||
</Part>
|
||||
</Brick>
|
||||
<Brick refID="14" designID="3001">
|
||||
<Part refID="14" designID="3001" materials="23">
|
||||
<Bone refID="14" transformation="1,0,0,0,1,0,0,0,1,-35.599998474121094,435.8399658203125,-54.800003051757813">
|
||||
</Bone>
|
||||
</Part>
|
||||
</Brick>
|
||||
<Brick refID="15" designID="3001">
|
||||
<Part refID="15" designID="3001" materials="23">
|
||||
<Bone refID="15" transformation="1,0,0,0,1,0,0,0,1,-35.599998474121094,432.95999145507812,-54.800003051757813">
|
||||
</Bone>
|
||||
</Part>
|
||||
</Brick>
|
||||
</Bricks>
|
||||
<RigidSystems>
|
||||
<RigidSystem>
|
||||
<Rigid refID="0" transformation="1,0,0,0,1,0,0,0,1,-35.599998474121094,434.87997436523437,-56.400001525878906" boneRefs="0,1,2,3"/>
|
||||
</RigidSystem>
|
||||
<RigidSystem>
|
||||
<Rigid refID="1" transformation="1,0,0,0,1,0,0,0,1,-35.599998474121094,432.95999145507812,-51.600002288818359" boneRefs="4,5,6,7"/>
|
||||
</RigidSystem>
|
||||
<RigidSystem>
|
||||
<Rigid refID="2" transformation="1,0,0,0,1,0,0,0,1,-35.599998474121094,432.95999145507812,-50.000003814697266" boneRefs="8,9,10,11"/>
|
||||
</RigidSystem>
|
||||
<RigidSystem>
|
||||
<Rigid refID="3" transformation="1,0,0,0,1,0,0,0,1,-35.599998474121094,434.87997436523437,-54.800003051757813" boneRefs="12,13,14,15"/>
|
||||
</RigidSystem>
|
||||
</RigidSystems>
|
||||
<GroupSystems>
|
||||
<GroupSystem>
|
||||
<Group transformation="1,0,0,0,1,0,0,0,1,0,0,0" pivot="0,0,0" partRefs="5,9"/>
|
||||
<Group transformation="1,0,0,0,1,0,0,0,1,0,0,0" pivot="0,0,0" partRefs="3,15">
|
||||
<Group transformation="1,0,0,0,1,0,0,0,1,0,0,0" pivot="0,0,0" partRefs="4,8"/>
|
||||
</Group>
|
||||
<Group transformation="1,0,0,0,1,0,0,0,1,0,0,0" pivot="0,0,0" partRefs="6,10"/>
|
||||
<Group transformation="1,0,0,0,1,0,0,0,1,0,0,0" pivot="0,0,0" partRefs="14,2">
|
||||
<Group transformation="1,0,0,0,1,0,0,0,1,0,0,0" pivot="0,0,0" partRefs="7,11"/>
|
||||
</Group>
|
||||
</GroupSystem>
|
||||
</GroupSystems>
|
||||
</LXFML>
|
||||
48
tests/dCommonTests/LxfmlTestFiles/group_issue.lxfml
Normal file
48
tests/dCommonTests/LxfmlTestFiles/group_issue.lxfml
Normal file
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<LXFML versionMajor="5" versionMinor="0">
|
||||
<Meta>
|
||||
<Application name="LEGO Universe" versionMajor="0" versionMinor="0"/>
|
||||
<Brand name="LEGOUniverse"/>
|
||||
<BrickSet version="457"/>
|
||||
</Meta>
|
||||
<Bricks>
|
||||
<Brick refID="0" designID="3001">
|
||||
<Part refID="0" designID="3001" materials="23">
|
||||
<Bone refID="0" transformation="1,0,0,0,1,0,0,0,1,-8.3999996185302734,433.91998291015625,-62.800003051757813">
|
||||
</Bone>
|
||||
</Part>
|
||||
</Brick>
|
||||
<Brick refID="1" designID="3001">
|
||||
<Part refID="1" designID="3001" materials="23">
|
||||
<Bone refID="1" transformation="1,0,0,0,1,0,0,0,1,-8.4000005722045898,432.95999145507812,-62.800003051757813">
|
||||
</Bone>
|
||||
</Part>
|
||||
</Brick>
|
||||
<Brick refID="2" designID="3001">
|
||||
<Part refID="2" designID="3001" materials="23">
|
||||
<Bone refID="2" transformation="1,0,0,0,1,0,0,0,1,-8.3999996185302734,433.91998291015625,-64.400001525878906">
|
||||
</Bone>
|
||||
</Part>
|
||||
</Brick>
|
||||
<Brick refID="3" designID="3001">
|
||||
<Part refID="3" designID="3001" materials="23">
|
||||
<Bone refID="3" transformation="1,0,0,0,1,0,0,0,1,-8.4000005722045898,432.95999145507812,-64.400001525878906">
|
||||
</Bone>
|
||||
</Part>
|
||||
</Brick>
|
||||
</Bricks>
|
||||
<RigidSystems>
|
||||
<RigidSystem>
|
||||
<Rigid refID="0" transformation="1,0,0,0,1,0,0,0,1,-8.3999996185302734,433.91998291015625,-62.800003051757813" boneRefs="0,1"/>
|
||||
</RigidSystem>
|
||||
<RigidSystem>
|
||||
<Rigid refID="1" transformation="1,0,0,0,1,0,0,0,1,-8.3999996185302734,433.91998291015625,-64.400001525878906" boneRefs="2,3"/>
|
||||
</RigidSystem>
|
||||
</RigidSystems>
|
||||
<GroupSystems>
|
||||
<GroupSystem>
|
||||
<Group transformation="1,0,0,0,1,0,0,0,1,0,0,0" pivot="0,0,0" partRefs="3,1"/>
|
||||
<Group transformation="1,0,0,0,1,0,0,0,1,0,0,0" pivot="0,0,0" partRefs="0,2"/>
|
||||
</GroupSystem>
|
||||
</GroupSystems>
|
||||
</LXFML>
|
||||
@@ -27,20 +27,25 @@ std::string SerializeElement(tinyxml2::XMLElement* elem) {
|
||||
return std::string(p.CStr());
|
||||
};
|
||||
|
||||
TEST(LxfmlTests, SplitUsesAllBricksAndNoDuplicates) {
|
||||
// Read the test.lxfml file copied to build directory by CMake
|
||||
std::string data = ReadFile("test.lxfml");
|
||||
ASSERT_FALSE(data.empty()) << "Failed to read test.lxfml from build directory";
|
||||
// Helper function to test splitting functionality
|
||||
static void TestSplitUsesAllBricksAndNoDuplicatesHelper(const std::string& filename) {
|
||||
// Read the LXFML file
|
||||
std::string data = ReadFile(filename);
|
||||
ASSERT_FALSE(data.empty()) << "Failed to read " << filename << " from build directory";
|
||||
|
||||
std::cout << "\n=== Testing LXFML splitting for: " << filename << " ===" << std::endl;
|
||||
|
||||
auto results = Lxfml::Split(data);
|
||||
ASSERT_GT(results.size(), 0);
|
||||
ASSERT_GT(results.size(), 0) << "Split results should not be empty for " << filename;
|
||||
|
||||
std::cout << "Split produced " << results.size() << " output(s)" << std::endl;
|
||||
|
||||
// parse original to count bricks
|
||||
tinyxml2::XMLDocument doc;
|
||||
ASSERT_EQ(doc.Parse(data.c_str()), tinyxml2::XML_SUCCESS);
|
||||
ASSERT_EQ(doc.Parse(data.c_str()), tinyxml2::XML_SUCCESS) << "Failed to parse " << filename;
|
||||
DocumentReader reader(doc);
|
||||
auto lxfml = reader["LXFML"];
|
||||
ASSERT_TRUE(lxfml);
|
||||
ASSERT_TRUE(lxfml) << "No LXFML element found in " << filename;
|
||||
|
||||
std::unordered_set<std::string> originalRigidSet;
|
||||
if (auto* rsParent = doc.FirstChildElement("LXFML")->FirstChildElement("RigidSystems")) {
|
||||
@@ -75,7 +80,20 @@ TEST(LxfmlTests, SplitUsesAllBricksAndNoDuplicates) {
|
||||
// Track used rigid systems and groups (serialized strings)
|
||||
std::unordered_set<std::string> usedRigidSet;
|
||||
std::unordered_set<std::string> usedGroupSet;
|
||||
|
||||
std::cout << "Original file contains " << originalBricks.size() << " bricks: ";
|
||||
for (const auto& brick : originalBricks) {
|
||||
std::cout << brick << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
int splitIndex = 0;
|
||||
std::filesystem::path baseFilename = std::filesystem::path(filename).stem();
|
||||
|
||||
for (const auto& res : results) {
|
||||
splitIndex++;
|
||||
std::cout << "\n--- Split " << splitIndex << " ---" << std::endl;
|
||||
|
||||
tinyxml2::XMLDocument outDoc;
|
||||
ASSERT_EQ(outDoc.Parse(res.lxfml.c_str()), tinyxml2::XML_SUCCESS);
|
||||
DocumentReader outReader(outDoc);
|
||||
@@ -104,32 +122,130 @@ TEST(LxfmlTests, SplitUsesAllBricksAndNoDuplicates) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Collect and display bricks in this split
|
||||
std::vector<std::string> splitBricks;
|
||||
for (const auto& brick : outLxfml["Bricks"]) {
|
||||
const auto* ref = brick.Attribute("refID");
|
||||
if (ref) {
|
||||
// no duplicate allowed
|
||||
ASSERT_EQ(usedBricks.find(ref), usedBricks.end()) << "Duplicate brick ref across splits: " << ref;
|
||||
usedBricks.insert(ref);
|
||||
splitBricks.push_back(ref);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Contains " << splitBricks.size() << " bricks: ";
|
||||
for (const auto& brick : splitBricks) {
|
||||
std::cout << brick << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
// Count rigid systems and groups
|
||||
int rigidCount = 0;
|
||||
if (auto* rsParent = outDoc.FirstChildElement("LXFML")->FirstChildElement("RigidSystems")) {
|
||||
for (auto* rs = rsParent->FirstChildElement("RigidSystem"); rs; rs = rs->NextSiblingElement("RigidSystem")) {
|
||||
rigidCount++;
|
||||
}
|
||||
}
|
||||
|
||||
int groupCount = 0;
|
||||
if (auto* gsParent = outDoc.FirstChildElement("LXFML")->FirstChildElement("GroupSystems")) {
|
||||
for (auto* gs = gsParent->FirstChildElement("GroupSystem"); gs; gs = gs->NextSiblingElement("GroupSystem")) {
|
||||
for (auto* g = gs->FirstChildElement("Group"); g; g = g->NextSiblingElement("Group")) {
|
||||
groupCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Contains " << rigidCount << " rigid systems and " << groupCount << " groups" << std::endl;
|
||||
}
|
||||
|
||||
// Every original brick must be used in one of the outputs
|
||||
for (const auto& bref : originalBricks) {
|
||||
ASSERT_NE(usedBricks.find(bref), usedBricks.end()) << "Brick not used in splits: " << bref;
|
||||
ASSERT_NE(usedBricks.find(bref), usedBricks.end()) << "Brick not used in splits: " << bref << " in " << filename;
|
||||
}
|
||||
|
||||
// And usedBricks should not contain anything outside original
|
||||
for (const auto& ub : usedBricks) {
|
||||
ASSERT_NE(originalBricks.find(ub), originalBricks.end()) << "Split produced unknown brick: " << ub;
|
||||
ASSERT_NE(originalBricks.find(ub), originalBricks.end()) << "Split produced unknown brick: " << ub << " in " << filename;
|
||||
}
|
||||
|
||||
// Ensure all original rigid systems and groups were used exactly once
|
||||
ASSERT_EQ(originalRigidSet.size(), usedRigidSet.size()) << "RigidSystem count mismatch";
|
||||
for (const auto& s : originalRigidSet) ASSERT_NE(usedRigidSet.find(s), usedRigidSet.end()) << "RigidSystem missing in splits";
|
||||
ASSERT_EQ(originalRigidSet.size(), usedRigidSet.size()) << "RigidSystem count mismatch in " << filename;
|
||||
for (const auto& s : originalRigidSet) ASSERT_NE(usedRigidSet.find(s), usedRigidSet.end()) << "RigidSystem missing in splits in " << filename;
|
||||
|
||||
ASSERT_EQ(originalGroupSet.size(), usedGroupSet.size()) << "Group count mismatch";
|
||||
for (const auto& s : originalGroupSet) ASSERT_NE(usedGroupSet.find(s), usedGroupSet.end()) << "Group missing in splits";
|
||||
ASSERT_EQ(originalGroupSet.size(), usedGroupSet.size()) << "Group count mismatch in " << filename;
|
||||
for (const auto& s : originalGroupSet) ASSERT_NE(usedGroupSet.find(s), usedGroupSet.end()) << "Group missing in splits in " << filename;
|
||||
}
|
||||
|
||||
TEST(LxfmlTests, SplitGroupIssueFile) {
|
||||
// Specific test for the group issue file
|
||||
TestSplitUsesAllBricksAndNoDuplicatesHelper("group_issue.lxfml");
|
||||
}
|
||||
|
||||
TEST(LxfmlTests, SplitTestFile) {
|
||||
// Specific test for the larger test file
|
||||
TestSplitUsesAllBricksAndNoDuplicatesHelper("test.lxfml");
|
||||
}
|
||||
|
||||
TEST(LxfmlTests, SplitComplexGroupingFile) {
|
||||
// Test for the complex grouping file - should produce only one split
|
||||
// because all groups are connected via rigid systems
|
||||
std::string data = ReadFile("complex_grouping.lxfml");
|
||||
ASSERT_FALSE(data.empty()) << "Failed to read complex_grouping.lxfml from build directory";
|
||||
|
||||
std::cout << "\n=== Testing complex grouping file ===" << std::endl;
|
||||
|
||||
auto results = Lxfml::Split(data);
|
||||
ASSERT_GT(results.size(), 0) << "Split results should not be empty";
|
||||
|
||||
// The complex grouping file should produce exactly ONE split
|
||||
// because all groups share bricks through rigid systems
|
||||
if (results.size() != 1) {
|
||||
FAIL() << "Complex grouping file produced " << results.size()
|
||||
<< " splits instead of 1 (all groups should be merged)";
|
||||
}
|
||||
|
||||
std::cout << "✓ Correctly produced 1 merged split" << std::endl;
|
||||
|
||||
// Verify the split contains all the expected elements
|
||||
tinyxml2::XMLDocument doc;
|
||||
ASSERT_EQ(doc.Parse(results[0].lxfml.c_str()), tinyxml2::XML_SUCCESS);
|
||||
|
||||
auto* lxfml = doc.FirstChildElement("LXFML");
|
||||
ASSERT_NE(lxfml, nullptr);
|
||||
|
||||
// Count bricks
|
||||
int brickCount = 0;
|
||||
if (auto* bricks = lxfml->FirstChildElement("Bricks")) {
|
||||
for (auto* brick = bricks->FirstChildElement("Brick"); brick; brick = brick->NextSiblingElement("Brick")) {
|
||||
brickCount++;
|
||||
}
|
||||
}
|
||||
std::cout << "Contains " << brickCount << " bricks" << std::endl;
|
||||
|
||||
// Count rigid systems
|
||||
int rigidCount = 0;
|
||||
if (auto* rigidSystems = lxfml->FirstChildElement("RigidSystems")) {
|
||||
for (auto* rs = rigidSystems->FirstChildElement("RigidSystem"); rs; rs = rs->NextSiblingElement("RigidSystem")) {
|
||||
rigidCount++;
|
||||
}
|
||||
}
|
||||
std::cout << "Contains " << rigidCount << " rigid systems" << std::endl;
|
||||
EXPECT_GT(rigidCount, 0) << "Should contain rigid systems";
|
||||
|
||||
// Count groups
|
||||
int groupCount = 0;
|
||||
if (auto* groupSystems = lxfml->FirstChildElement("GroupSystems")) {
|
||||
for (auto* gs = groupSystems->FirstChildElement("GroupSystem"); gs; gs = gs->NextSiblingElement("GroupSystem")) {
|
||||
for (auto* g = gs->FirstChildElement("Group"); g; g = g->NextSiblingElement("Group")) {
|
||||
groupCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::cout << "Contains " << groupCount << " groups" << std::endl;
|
||||
EXPECT_GT(groupCount, 1) << "Should contain multiple groups (all merged into one split)";
|
||||
}
|
||||
|
||||
// Tests for invalid input handling - now working with the improved Split function
|
||||
|
||||
Reference in New Issue
Block a user