[Client] Add and use mwmp::PlayerList::isDedicatedPlayer()

0.6.1
David Cernat 8 years ago
parent b1a394cd02
commit 07c2d4251e

@ -627,9 +627,9 @@ namespace MWClass
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr())
{ {
mwmp::Main::get().getLocalPlayer()->attack.success = true; mwmp::Main::get().getLocalPlayer()->attack.success = true;
mwmp::DedicatedPlayer *dedicatedPlayer = mwmp::PlayerList::getPlayer(victim);
if (dedicatedPlayer != nullptr) if (mwmp::PlayerList::isDedicatedPlayer(victim))
mwmp::Main::get().getLocalPlayer()->attack.target.guid = dedicatedPlayer->guid; mwmp::Main::get().getLocalPlayer()->attack.target.guid = mwmp::PlayerList::getPlayer(victim)->guid;
} }
/* /*
End of tes3mp addition End of tes3mp addition
@ -804,13 +804,7 @@ namespace MWClass
If the attacker is a DedicatedPlayer with a successful knockdown, apply the knockdown; If the attacker is a DedicatedPlayer with a successful knockdown, apply the knockdown;
otherwise, use default probability roll otherwise, use default probability roll
*/ */
mwmp::DedicatedPlayer *dedicatedPlayer = mwmp::PlayerList::getPlayer(attacker); if (mwmp::PlayerList::isDedicatedPlayer(attacker) && mwmp::PlayerList::getPlayer(attacker)->attack.knockdown)
bool isDedicated = dedicatedPlayer != nullptr;
bool isDedicatedKnockdown = false;
if (isDedicated)
isDedicatedKnockdown = dedicatedPlayer->attack.knockdown;
if (isDedicatedKnockdown)
stats.setKnockedDown(true); stats.setKnockedDown(true);
else if (ishealth && agilityTerm <= damage && knockdownTerm <= Misc::Rng::roll0to99()) 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 If the victim was the LocalPlayer, check whether packets should be sent about
their new dynamic stats and position their new dynamic stats and position
*/ */
mwmp::DedicatedPlayer *victimPlayer = mwmp::PlayerList::getPlayer(ptr); if (attacker == MWMechanics::getPlayer() && mwmp::PlayerList::isDedicatedPlayer(ptr))
if (attacker == MWMechanics::getPlayer() && victimPlayer != nullptr)
{ {
mwmp::DedicatedPlayer *victimPlayer = mwmp::PlayerList::getPlayer(ptr);
mwmp::Attack *attack = &mwmp::Main::get().getLocalPlayer()->attack; mwmp::Attack *attack = &mwmp::Main::get().getLocalPlayer()->attack;
attack->damage = damage; attack->damage = damage;
attack->target.guid = victimPlayer->guid; attack->target.guid = victimPlayer->guid;
attack->knockdown = getCreatureStats(ptr).getKnockedDown(); attack->knockdown = getCreatureStats(ptr).getKnockedDown();
mwmp::Main::get().getLocalPlayer()->sendAttack(mwmp::Attack::MELEE); // todo: make this sensitive to different weapon types mwmp::Main::get().getLocalPlayer()->sendAttack(mwmp::Attack::MELEE); // todo: make this sensitive to different weapon types
} }

@ -1132,9 +1132,8 @@ namespace MWMechanics
If this actor is a DedicatedPlayer, update their mAttackingOrSpell If this actor is a DedicatedPlayer, update their mAttackingOrSpell
*/ */
mwmp::DedicatedPlayer *dedicatedPlayer = mwmp::PlayerList::getPlayer(iter->first); if (mwmp::PlayerList::isDedicatedPlayer(iter->first))
if (dedicatedPlayer != NULL) mwmp::PlayerList::getPlayer(iter->first)->updateActor(iter->second);
dedicatedPlayer->updateActor(iter->second);
/* /*
End of tes3mp addition End of tes3mp addition
*/ */

@ -123,13 +123,13 @@ namespace MWMechanics
Only calculate block chance for blockers who are not DedicatedPlayers Only calculate block chance for blockers who are not DedicatedPlayers
and update block state for LocalPlayer and update block state for LocalPlayer
*/ */
mwmp::DedicatedPlayer *dedicatedPlayer = mwmp::PlayerList::getPlayer(blocker);
bool isDedicated = dedicatedPlayer != NULL;
if (attacker == MWMechanics::getPlayer()) if (attacker == MWMechanics::getPlayer())
mwmp::Main::get().getLocalPlayer()->attack.block = false; mwmp::Main::get().getLocalPlayer()->attack.block = false;
bool isDedicated = mwmp::PlayerList::isDedicatedPlayer(blocker);
if ((!isDedicated && Misc::Rng::roll0to99() < x) || if ((!isDedicated && Misc::Rng::roll0to99() < x) ||
(isDedicated && dedicatedPlayer->attack.block == 1)) (isDedicated && mwmp::PlayerList::getPlayer(blocker)->attack.block == true))
{ {
if (attacker == MWMechanics::getPlayer()) if (attacker == MWMechanics::getPlayer())
mwmp::Main::get().getLocalPlayer()->attack.block = true; mwmp::Main::get().getLocalPlayer()->attack.block = true;

@ -849,14 +849,15 @@ namespace MWMechanics
can be accounted for like it is in OpenMW's corresponding code can be accounted for like it is in OpenMW's corresponding code
*/ */
mwmp::DedicatedPlayer *dedicatedPlayer = mwmp::PlayerList::getPlayer(mCaster); mwmp::DedicatedPlayer *dedicatedPlayer = mwmp::PlayerList::getPlayer(mCaster);
bool isDedicated = dedicatedPlayer != NULL;
bool isDedicated = mwmp::PlayerList::isDedicatedPlayer(mCaster);
if (isDedicated) if (isDedicated)
dedicatedPlayer->attack.pressed = false; dedicatedPlayer->attack.pressed = false;
// Check success // Check success
if ((!isDedicated && !mwmp::Main::get().getLocalPlayer()->attack.success) || if ((!isDedicated && !mwmp::Main::get().getLocalPlayer()->attack.success) ||
(isDedicated && dedicatedPlayer->attack.success == 0)) (isDedicated && dedicatedPlayer->attack.success == false))
{ {
if (mCaster == getPlayer()) if (mCaster == getPlayer())
{ {

@ -233,6 +233,14 @@ DedicatedPlayer *PlayerList::getPlayer(const MWWorld::Ptr &ptr)
return 0; return 0;
} }
bool PlayerList::isDedicatedPlayer(const MWWorld::Ptr &ptr)
{
if (getPlayer(ptr))
return true;
return false;
}
void DedicatedPlayer::move(float dt) void DedicatedPlayer::move(float dt)
{ {
if (state != 2) return; if (state != 2) return;

@ -40,6 +40,8 @@ namespace mwmp
static DedicatedPlayer *getPlayer(RakNet::RakNetGUID guid); static DedicatedPlayer *getPlayer(RakNet::RakNetGUID guid);
static DedicatedPlayer *getPlayer(const MWWorld::Ptr &ptr); static DedicatedPlayer *getPlayer(const MWWorld::Ptr &ptr);
static bool isDedicatedPlayer(const MWWorld::Ptr &ptr);
private: private:
static std::map<RakNet::RakNetGUID, DedicatedPlayer *> players; static std::map<RakNet::RakNetGUID, DedicatedPlayer *> players;

Loading…
Cancel
Save