Skip to content

Commit b89ca28

Browse files
authored
Merge pull request #10024 from Frankie-hz/superlink
[cpp] Fixes linking issue for battlefield framework with superLinkGroup
2 parents 07de714 + d51f0f9 commit b89ca28

3 files changed

Lines changed: 41 additions & 6 deletions

File tree

scripts/battlefields/Sacrificial_Chamber/temple_of_uggalepih.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ content.groups =
4747
},
4848
},
4949

50+
superlink = true,
51+
5052
allDeath = function(battlefield, mob)
5153
battlefield:setStatus(xi.battlefield.status.WON)
5254
end,

src/map/lua/lua_battlefield.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ void CLuaBattlefield::addGroups(const sol::table& groups, bool hasMultipleArenas
368368
// The entities to be added to the battlefield
369369
std::set<uint32> entities;
370370
std::set<uint32> spawnedEntities;
371+
std::set<uint32> explicitPartyEntities;
371372

372373
std::vector<BattlefieldGroup> battlefieldGroups;
373374
for (const auto& entry : groups)
@@ -490,6 +491,8 @@ void CLuaBattlefield::addGroups(const sol::table& groups, bool hasMultipleArenas
490491
{
491492
party->AddMember(PMob);
492493
}
494+
495+
explicitPartyEntities.insert(entity->id);
493496
}
494497
}
495498

@@ -586,7 +589,8 @@ void CLuaBattlefield::addGroups(const sol::table& groups, bool hasMultipleArenas
586589

587590
for (const auto& modifier : mobMods.get<sol::table>())
588591
{
589-
PMob->setMobMod(modifier.first.as<uint16>(), modifier.second.as<uint16>());
592+
const auto mobMod = modifier.first.as<uint16>();
593+
PMob->setMobMod(mobMod, modifier.second.as<uint16>());
590594
}
591595
PMob->saveMobModifiers();
592596
}
@@ -680,6 +684,37 @@ void CLuaBattlefield::addGroups(const sol::table& groups, bool hasMultipleArenas
680684
m_PLuaBattlefield->addGroup(group);
681685
}
682686

687+
// Rebuild party links after all the battlefield groups have their modifiers applied
688+
// This avoids ordering bugs when SUPERLINK/SUBLINK or other link-affecting state
689+
// are assigned after the zone-load party pass.
690+
for (uint32 entityID : entities)
691+
{
692+
if (explicitPartyEntities.find(entityID) != explicitPartyEntities.end())
693+
{
694+
continue;
695+
}
696+
697+
auto* PMob = dynamic_cast<CMobEntity*>(zoneutils::GetEntity(entityID, TYPE_MOB));
698+
if (PMob != nullptr && PMob->PParty != nullptr)
699+
{
700+
PMob->PParty->RemoveMember(PMob);
701+
}
702+
}
703+
704+
for (uint32 entityID : entities)
705+
{
706+
if (explicitPartyEntities.find(entityID) != explicitPartyEntities.end())
707+
{
708+
continue;
709+
}
710+
711+
CBaseEntity* entity = zoneutils::GetEntity(entityID, TYPE_MOB);
712+
if (entity != nullptr)
713+
{
714+
m_PLuaBattlefield->GetZone()->FindPartyForMob(entity);
715+
}
716+
}
717+
683718
if (m_PLuaBattlefield->GetArmouryCrate() != 0)
684719
{
685720
if (auto* entity = dynamic_cast<CNpcEntity*>(zoneutils::GetEntity(m_PLuaBattlefield->GetArmouryCrate(), TYPE_NPC)))

src/map/zone_entities.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ void CZoneEntities::FindPartyForMob(CBaseEntity* PEntity)
378378
}
379379

380380
// Determine if these mobs should be in the same party.
381-
// Force-link mobs with SUPERLINK only group with mobs sharing the same
382-
// SUPERLINK value (used by BCNMs/Dynamis to link all mobs in an instance).
381+
// Check SUPERLINK first in cases that forceLink is enables with SUPERLINK. (Like BCNMs/Dynamis)
382+
// If no SUPERLINK then check if forceLink is enabled and the mob should force link.
383383
// Otherwise, mobs link by family or sublink as normal.
384384
bool match = false;
385385
int16 superlink = PMob->getMobMod(MOBMOD_SUPERLINK);
@@ -389,9 +389,7 @@ void CZoneEntities::FindPartyForMob(CBaseEntity* PEntity)
389389
}
390390
else if (forceLink)
391391
{
392-
match = PCurrentMob->ShouldForceLink() &&
393-
((PCurrentMob->m_Link && PCurrentMob->m_SuperFamily == PMob->m_SuperFamily) ||
394-
(sublink && sublink == PCurrentMob->getMobMod(MOBMOD_SUBLINK)));
392+
match = PCurrentMob->ShouldForceLink();
395393
}
396394
else
397395
{

0 commit comments

Comments
 (0)