From 07c2d4251e57ee247f08aba0e756b5eb815c5e35 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 17 Apr 2017 20:36:20 +0300 Subject: [PATCH] [Client] Add and use mwmp::PlayerList::isDedicatedPlayer() --- apps/openmw/mwclass/npc.cpp | 20 ++++++++------------ apps/openmw/mwmechanics/actors.cpp | 5 ++--- apps/openmw/mwmechanics/combat.cpp | 6 +++--- apps/openmw/mwmechanics/spellcasting.cpp | 5 +++-- apps/openmw/mwmp/DedicatedPlayer.cpp | 8 ++++++++ apps/openmw/mwmp/DedicatedPlayer.hpp | 2 ++ 6 files changed, 26 insertions(+), 20 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 78923e751..4cf8671f3 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -627,9 +627,9 @@ namespace MWClass if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) { mwmp::Main::get().getLocalPlayer()->attack.success = true; - mwmp::DedicatedPlayer *dedicatedPlayer = mwmp::PlayerList::getPlayer(victim); - if (dedicatedPlayer != nullptr) - mwmp::Main::get().getLocalPlayer()->attack.target.guid = dedicatedPlayer->guid; + + if (mwmp::PlayerList::isDedicatedPlayer(victim)) + mwmp::Main::get().getLocalPlayer()->attack.target.guid = mwmp::PlayerList::getPlayer(victim)->guid; } /* End of tes3mp addition @@ -804,13 +804,7 @@ namespace MWClass If the attacker is a DedicatedPlayer with a successful knockdown, apply the knockdown; otherwise, use default probability roll */ - mwmp::DedicatedPlayer *dedicatedPlayer = mwmp::PlayerList::getPlayer(attacker); - bool isDedicated = dedicatedPlayer != nullptr; - bool isDedicatedKnockdown = false; - if (isDedicated) - isDedicatedKnockdown = dedicatedPlayer->attack.knockdown; - - if (isDedicatedKnockdown) + if (mwmp::PlayerList::isDedicatedPlayer(attacker) && mwmp::PlayerList::getPlayer(attacker)->attack.knockdown) stats.setKnockedDown(true); else if (ishealth && agilityTerm <= damage && knockdownTerm <= Misc::Rng::roll0to99()) /* @@ -925,13 +919,15 @@ namespace MWClass If the victim was the LocalPlayer, check whether packets should be sent about their new dynamic stats and position */ - mwmp::DedicatedPlayer *victimPlayer = mwmp::PlayerList::getPlayer(ptr); - if (attacker == MWMechanics::getPlayer() && victimPlayer != nullptr) + if (attacker == MWMechanics::getPlayer() && mwmp::PlayerList::isDedicatedPlayer(ptr)) { + mwmp::DedicatedPlayer *victimPlayer = mwmp::PlayerList::getPlayer(ptr); + mwmp::Attack *attack = &mwmp::Main::get().getLocalPlayer()->attack; attack->damage = damage; attack->target.guid = victimPlayer->guid; attack->knockdown = getCreatureStats(ptr).getKnockedDown(); + mwmp::Main::get().getLocalPlayer()->sendAttack(mwmp::Attack::MELEE); // todo: make this sensitive to different weapon types } diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index eaf84848c..8019aad9b 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -1132,9 +1132,8 @@ namespace MWMechanics If this actor is a DedicatedPlayer, update their mAttackingOrSpell */ - mwmp::DedicatedPlayer *dedicatedPlayer = mwmp::PlayerList::getPlayer(iter->first); - if (dedicatedPlayer != NULL) - dedicatedPlayer->updateActor(iter->second); + if (mwmp::PlayerList::isDedicatedPlayer(iter->first)) + mwmp::PlayerList::getPlayer(iter->first)->updateActor(iter->second); /* End of tes3mp addition */ diff --git a/apps/openmw/mwmechanics/combat.cpp b/apps/openmw/mwmechanics/combat.cpp index f217627c6..8eccffe98 100644 --- a/apps/openmw/mwmechanics/combat.cpp +++ b/apps/openmw/mwmechanics/combat.cpp @@ -123,13 +123,13 @@ namespace MWMechanics Only calculate block chance for blockers who are not DedicatedPlayers and update block state for LocalPlayer */ - mwmp::DedicatedPlayer *dedicatedPlayer = mwmp::PlayerList::getPlayer(blocker); - bool isDedicated = dedicatedPlayer != NULL; if (attacker == MWMechanics::getPlayer()) mwmp::Main::get().getLocalPlayer()->attack.block = false; + bool isDedicated = mwmp::PlayerList::isDedicatedPlayer(blocker); + if ((!isDedicated && Misc::Rng::roll0to99() < x) || - (isDedicated && dedicatedPlayer->attack.block == 1)) + (isDedicated && mwmp::PlayerList::getPlayer(blocker)->attack.block == true)) { if (attacker == MWMechanics::getPlayer()) mwmp::Main::get().getLocalPlayer()->attack.block = true; diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index fd6dc4df7..cba1f1882 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -849,14 +849,15 @@ namespace MWMechanics can be accounted for like it is in OpenMW's corresponding code */ mwmp::DedicatedPlayer *dedicatedPlayer = mwmp::PlayerList::getPlayer(mCaster); - bool isDedicated = dedicatedPlayer != NULL; + + bool isDedicated = mwmp::PlayerList::isDedicatedPlayer(mCaster); if (isDedicated) dedicatedPlayer->attack.pressed = false; // Check success if ((!isDedicated && !mwmp::Main::get().getLocalPlayer()->attack.success) || - (isDedicated && dedicatedPlayer->attack.success == 0)) + (isDedicated && dedicatedPlayer->attack.success == false)) { if (mCaster == getPlayer()) { diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index a73aa9854..20f8d29ed 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -233,6 +233,14 @@ DedicatedPlayer *PlayerList::getPlayer(const MWWorld::Ptr &ptr) return 0; } +bool PlayerList::isDedicatedPlayer(const MWWorld::Ptr &ptr) +{ + if (getPlayer(ptr)) + return true; + + return false; +} + void DedicatedPlayer::move(float dt) { if (state != 2) return; diff --git a/apps/openmw/mwmp/DedicatedPlayer.hpp b/apps/openmw/mwmp/DedicatedPlayer.hpp index 267fdfae2..4b746a52b 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.hpp +++ b/apps/openmw/mwmp/DedicatedPlayer.hpp @@ -40,6 +40,8 @@ namespace mwmp static DedicatedPlayer *getPlayer(RakNet::RakNetGUID guid); static DedicatedPlayer *getPlayer(const MWWorld::Ptr &ptr); + static bool isDedicatedPlayer(const MWWorld::Ptr &ptr); + private: static std::map players;