[Client] Set and clear hitAttemptActorId for DedicatedPlayers

This allows a DedicatedPlayer's follower NPCs to target enemies attacking the DedicatedPlayer.
0.6.1
David Cernat 8 years ago
parent 4e5c8873e0
commit 1c6e359fe9

@ -411,17 +411,31 @@ namespace MWClass
if (!attacker.isEmpty() && attacker.getClass().isActor() && !ptr.isEmpty() && ptr.getClass().isActor()) if (!attacker.isEmpty() && attacker.getClass().isActor() && !ptr.isEmpty() && ptr.getClass().isActor())
{ {
MWMechanics::CreatureStats& statsAttacker = attacker.getClass().getCreatureStats(attacker); MWMechanics::CreatureStats& statsAttacker = attacker.getClass().getCreatureStats(attacker);
/*
Start of tes3mp change (minor)
Instead of only checking whether an attacker is the LocalPlayer, also
check if they are a DedicatedPlayer
*/
// First handle the attacked actor // First handle the attacked actor
if ((stats.getHitAttemptActorId() == -1) if ((stats.getHitAttemptActorId() == -1)
&& (statsAttacker.getAiSequence().isInCombat(ptr) && (statsAttacker.getAiSequence().isInCombat(ptr)
|| attacker == MWMechanics::getPlayer())) || attacker == MWMechanics::getPlayer()
|| mwmp::PlayerList::isDedicatedPlayer(attacker)))
stats.setHitAttemptActorId(statsAttacker.getActorId()); stats.setHitAttemptActorId(statsAttacker.getActorId());
// Next handle the attacking actor // Next handle the attacking actor
if ((statsAttacker.getHitAttemptActorId() == -1) if ((statsAttacker.getHitAttemptActorId() == -1)
&& (statsAttacker.getAiSequence().isInCombat(ptr) && (statsAttacker.getAiSequence().isInCombat(ptr)
|| attacker == MWMechanics::getPlayer())) || attacker == MWMechanics::getPlayer()
|| mwmp::PlayerList::isDedicatedPlayer(attacker)))
statsAttacker.setHitAttemptActorId(stats.getActorId()); statsAttacker.setHitAttemptActorId(stats.getActorId());
/*
End of tes3mp change (minor)
*/
} }
if (!object.isEmpty()) if (!object.isEmpty())

@ -740,17 +740,31 @@ namespace MWClass
if (!attacker.isEmpty() && attacker.getClass().isActor() && !ptr.isEmpty() && ptr.getClass().isActor()) if (!attacker.isEmpty() && attacker.getClass().isActor() && !ptr.isEmpty() && ptr.getClass().isActor())
{ {
MWMechanics::CreatureStats& statsAttacker = attacker.getClass().getCreatureStats(attacker); MWMechanics::CreatureStats& statsAttacker = attacker.getClass().getCreatureStats(attacker);
/*
Start of tes3mp change (minor)
Instead of only checking whether an attacker is the LocalPlayer, also
check if they are a DedicatedPlayer
*/
// First handle the attacked actor // First handle the attacked actor
if ((stats.getHitAttemptActorId() == -1) if ((stats.getHitAttemptActorId() == -1)
&& (statsAttacker.getAiSequence().isInCombat(ptr) && (statsAttacker.getAiSequence().isInCombat(ptr)
|| attacker == MWMechanics::getPlayer())) || attacker == MWMechanics::getPlayer()
|| mwmp::PlayerList::isDedicatedPlayer(attacker)))
stats.setHitAttemptActorId(statsAttacker.getActorId()); stats.setHitAttemptActorId(statsAttacker.getActorId());
// Next handle the attacking actor // Next handle the attacking actor
if ((statsAttacker.getHitAttemptActorId() == -1) if ((statsAttacker.getHitAttemptActorId() == -1)
&& (statsAttacker.getAiSequence().isInCombat(ptr) && (statsAttacker.getAiSequence().isInCombat(ptr)
|| attacker == MWMechanics::getPlayer())) || attacker == MWMechanics::getPlayer()
|| mwmp::PlayerList::isDedicatedPlayer(attacker)))
statsAttacker.setHitAttemptActorId(stats.getActorId()); statsAttacker.setHitAttemptActorId(stats.getActorId());
/*
End of tes3mp change (minor)
*/
} }
if (!object.isEmpty()) if (!object.isEmpty())

@ -1189,16 +1189,26 @@ namespace MWMechanics
End of tes3mp addition End of tes3mp addition
*/ */
/*
Start of tes3mp change (major)
Allow this code to use the same logic for DedicatedPlayers as for LocalPlayers
*/
// If dead or no longer in combat, no longer store any actors who attempted to hit us. Also remove for the player. // If dead or no longer in combat, no longer store any actors who attempted to hit us. Also remove for the player.
if (iter->first != player && (iter->first.getClass().getCreatureStats(iter->first).isDead() if (iter->first != player && !mwmp::PlayerList::isDedicatedPlayer(iter->first) &&(iter->first.getClass().getCreatureStats(iter->first).isDead()
|| !iter->first.getClass().getCreatureStats(iter->first).getAiSequence().isInCombat() || !iter->first.getClass().getCreatureStats(iter->first).getAiSequence().isInCombat()
|| !inProcessingRange)) || !inProcessingRange))
{ {
iter->first.getClass().getCreatureStats(iter->first).setHitAttemptActorId(-1); iter->first.getClass().getCreatureStats(iter->first).setHitAttemptActorId(-1);
if (player.getClass().getCreatureStats(player).getHitAttemptActorId() == iter->first.getClass().getCreatureStats(iter->first).getActorId()) if (player.getClass().getCreatureStats(player).getHitAttemptActorId() == iter->first.getClass().getCreatureStats(iter->first).getActorId())
player.getClass().getCreatureStats(player).setHitAttemptActorId(-1); player.getClass().getCreatureStats(player).setHitAttemptActorId(-1);
mwmp::PlayerList::clearHitAttemptActorId(iter->first.getClass().getCreatureStats(iter->first).getActorId());
} }
/*
End of tes3mp change (major)
*/
const MWWorld::Ptr playerHitAttemptActor = MWBase::Environment::get().getWorld()->searchPtrViaActorId(player.getClass().getCreatureStats(player).getHitAttemptActorId()); const MWWorld::Ptr playerHitAttemptActor = MWBase::Environment::get().getWorld()->searchPtrViaActorId(player.getClass().getCreatureStats(player).getHitAttemptActorId());

@ -264,3 +264,23 @@ bool PlayerList::isDedicatedPlayer(const MWWorld::Ptr &ptr)
return (getPlayer(ptr) != 0); return (getPlayer(ptr) != 0);
} }
/*
Go through all DedicatedPlayers checking if their mHitAttemptActorId matches this one
and set it to -1 if it does
This resets the combat target for a DedicatedPlayer's followers in Actors::update()
*/
void PlayerList::clearHitAttemptActorId(int actorId)
{
for (std::map <RakNet::RakNetGUID, DedicatedPlayer *>::iterator it = players.begin(); it != players.end(); it++)
{
if (it->second == 0 || it->second->getPtr().mRef == 0)
continue;
MWMechanics::CreatureStats *playerCreatureStats = &it->second->getPtr().getClass().getCreatureStats(it->second->getPtr());
if (playerCreatureStats->getHitAttemptActorId() == actorId)
playerCreatureStats->setHitAttemptActorId(-1);
}
}

@ -38,6 +38,8 @@ namespace mwmp
static bool isDedicatedPlayer(const MWWorld::Ptr &ptr); static bool isDedicatedPlayer(const MWWorld::Ptr &ptr);
static void clearHitAttemptActorId(int actorId);
private: private:
static std::map<RakNet::RakNetGUID, DedicatedPlayer *> players; static std::map<RakNet::RakNetGUID, DedicatedPlayer *> players;

Loading…
Cancel
Save