1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-07-13 02:21:42 +00:00

[Client] Add isTeamMember() method to MechanicsHelper

This commit is contained in:
David Cernat 2019-12-03 17:04:49 +02:00
parent 68f524b822
commit 3a52f7dcf5
2 changed files with 36 additions and 0 deletions

View file

@ -1,4 +1,5 @@
#include <components/openmw-mp/TimedLog.hpp>
#include <components/openmw-mp/Utils.hpp>
#include <components/misc/rng.hpp>
@ -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",

View file

@ -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);