From 9817d3a563883839ad9e528dfc172a2223fb0219 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 20 Jul 2021 03:22:16 +0200 Subject: [PATCH] [Client] Add method to PlayerList for getting players by their actorId --- apps/openmw/mwmp/PlayerList.cpp | 17 +++++++++++++++++ apps/openmw/mwmp/PlayerList.hpp | 1 + 2 files changed, 18 insertions(+) diff --git a/apps/openmw/mwmp/PlayerList.cpp b/apps/openmw/mwmp/PlayerList.cpp index 6f57a6812..195b692cd 100644 --- a/apps/openmw/mwmp/PlayerList.cpp +++ b/apps/openmw/mwmp/PlayerList.cpp @@ -80,6 +80,23 @@ DedicatedPlayer *PlayerList::getPlayer(const MWWorld::Ptr &ptr) return nullptr; } +DedicatedPlayer* PlayerList::getPlayer(int actorId) +{ + for (auto& playerEntry : playerList) + { + if (playerEntry.second == nullptr || playerEntry.second->getPtr().mRef == nullptr) + continue; + + MWWorld::Ptr playerPtr = playerEntry.second->getPtr(); + int playerActorId = playerPtr.getClass().getCreatureStats(playerPtr).getActorId(); + + if (actorId == playerActorId) + return playerEntry.second; + } + + return nullptr; +} + std::vector PlayerList::getPlayersInCell(const ESM::Cell& cell) { std::vector playersInCell; diff --git a/apps/openmw/mwmp/PlayerList.hpp b/apps/openmw/mwmp/PlayerList.hpp index 5a3e09850..097c4259c 100644 --- a/apps/openmw/mwmp/PlayerList.hpp +++ b/apps/openmw/mwmp/PlayerList.hpp @@ -34,6 +34,7 @@ namespace mwmp static DedicatedPlayer *getPlayer(RakNet::RakNetGUID guid); static DedicatedPlayer *getPlayer(const MWWorld::Ptr &ptr); + static DedicatedPlayer* getPlayer(int actorId); static std::vector getPlayersInCell(const ESM::Cell& cell); static bool isDedicatedPlayer(const MWWorld::Ptr &ptr);