diff --git a/apps/openmw/mwmp/MechanicsHelper.cpp b/apps/openmw/mwmp/MechanicsHelper.cpp index 8bfb5132c..791b2217e 100644 --- a/apps/openmw/mwmp/MechanicsHelper.cpp +++ b/apps/openmw/mwmp/MechanicsHelper.cpp @@ -1,4 +1,5 @@ #include +#include #include @@ -269,6 +270,35 @@ bool MechanicsHelper::getSpellSuccess(std::string spellId, const MWWorld::Ptr& c return Misc::Rng::roll0to99() < MWMechanics::getSpellSuccessChance(spellId, caster, nullptr, true, false); } +bool MechanicsHelper::isTeamMember(const MWWorld::Ptr& playerChecked, const MWWorld::Ptr& playerWithTeam) +{ + bool isTeamMember = false; + bool playerCheckedIsLocal = playerChecked == MWMechanics::getPlayer(); + bool playerCheckedIsDedicated = !playerCheckedIsLocal ? mwmp::PlayerList::isDedicatedPlayer(playerChecked) : false; + bool playerWithTeamIsLocal = !playerCheckedIsLocal ? playerWithTeam == MWMechanics::getPlayer() : false; + bool playerWithTeamIsDedicated = !playerWithTeamIsLocal ? mwmp::PlayerList::isDedicatedPlayer(playerWithTeam) : false; + + if (playerCheckedIsLocal || playerCheckedIsDedicated) + { + if (playerWithTeamIsLocal || playerWithTeamIsDedicated) + { + RakNet::RakNetGUID playerCheckedGuid; + + if (playerCheckedIsLocal) + playerCheckedGuid = mwmp::Main::get().getLocalPlayer()->guid; + else + playerCheckedGuid = PlayerList::getPlayer(playerChecked)->guid; + + if (playerWithTeamIsLocal) + isTeamMember = Utils::vectorContains(mwmp::Main::get().getLocalPlayer()->teamMembers, playerCheckedGuid); + else + isTeamMember = Utils::vectorContains(PlayerList::getPlayer(playerWithTeam)->teamMembers, playerCheckedGuid); + } + } + + return isTeamMember; +} + void MechanicsHelper::processAttack(Attack attack, const MWWorld::Ptr& attacker) { LOG_MESSAGE_SIMPLE(TimedLog::LOG_VERBOSE, "Processing attack from %s of type %i", diff --git a/apps/openmw/mwmp/MechanicsHelper.hpp b/apps/openmw/mwmp/MechanicsHelper.hpp index 3b8d6badb..c4bd358ad 100644 --- a/apps/openmw/mwmp/MechanicsHelper.hpp +++ b/apps/openmw/mwmp/MechanicsHelper.hpp @@ -34,6 +34,12 @@ namespace MechanicsHelper void resetAttack(mwmp::Attack* attack); void resetCast(mwmp::Cast* cast); + // See whether playerChecked belongs to playerWithTeam's team + // Note: This is not supposed to also check if playerWithTeam is on playerChecked's + // team, because it should technically be possible to be allied to someone + // who isn't mutually allied to you + bool isTeamMember(const MWWorld::Ptr& playedChecked, const MWWorld::Ptr& playerWithTeam); + bool getSpellSuccess(std::string spellId, const MWWorld::Ptr& caster); void processAttack(mwmp::Attack attack, const MWWorld::Ptr& attacker);