[General] Fix information exchange for players sharing a cell

Previously, two players entering the same cell only sent and received their latest changes for dynamic stats, attributes, skills and equipment when they started sharing that cell.
0.6.3
David Cernat 7 years ago
parent 7db74509e0
commit 66d5109509

@ -30,10 +30,14 @@ namespace mwmp
{
LOG_APPEND(Log::LOG_INFO, "- Moved to %s", player.cell.getDescription().c_str());
player.exchangeFullInfo = true;
player.forEachLoaded([this](Player *pl, Player *other) {
LOG_APPEND(Log::LOG_INFO, "- Started information exchange with %s", other->npc.mName.c_str());
other->exchangeFullInfo = true;
playerController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(other);
playerController->GetPacket(ID_PLAYER_ATTRIBUTE)->setPlayer(other);
playerController->GetPacket(ID_PLAYER_POSITION)->setPlayer(other);
@ -64,6 +68,8 @@ namespace mwmp
playerController->GetPacket(ID_PLAYER_ANIM_FLAGS)->Send(other->guid);
playerController->GetPacket(ID_PLAYER_SHAPESHIFT)->Send(other->guid);
other->exchangeFullInfo = false;
LOG_APPEND(Log::LOG_INFO, "- Finished information exchange with %s", other->npc.mName.c_str());
});
@ -75,6 +81,8 @@ namespace mwmp
Script::Call<Script::CallbackIdentity("OnPlayerCellChange")>(player.getId());
LOG_APPEND(Log::LOG_INFO, "- Finished processing ID_PLAYER_CELL_CHANGE", player.cell.getDescription().c_str());
player.exchangeFullInfo = false;
}
else
LOG_APPEND(Log::LOG_INFO, "- Ignored because %s is dead", player.npc.mName.c_str());

@ -227,6 +227,7 @@ namespace mwmp
spellbookChanges.action = 0;
spellbookChanges.count = 0;
exchangeFullInfo = false;
displayCreatureName = false;
resetStats = false;
enforcedLogLevel = -1;
@ -259,6 +260,8 @@ namespace mwmp
// with the items themselves being stored in equipmentItems
std::vector<int> equipmentIndexChanges;
bool exchangeFullInfo;
InventoryChanges inventoryChanges;
SpellbookChanges spellbookChanges;
QuickKeyChanges quickKeyChanges;

@ -13,7 +13,17 @@ void PacketPlayerAttribute::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
RW(player->exchangeFullInfo, send);
if (player->exchangeFullInfo)
{
RW(player->creatureStats.mAttributes, send);
RW(player->npcStats.mSkillIncrease, send);
}
else
{
uint32_t count;
if (send)
count = static_cast<uint32_t>(player->attributeIndexChanges.size());
@ -32,4 +42,5 @@ void PacketPlayerAttribute::Packet(RakNet::BitStream *bs, bool send)
RW(player->creatureStats.mAttributes[attributeIndex], send);
RW(player->npcStats.mSkillIncrease[attributeIndex], send);
}
}
}

@ -1,4 +1,5 @@
#include "PacketPlayerEquipment.hpp"
#include <components/openmw-mp/NetworkMessages.hpp>
using namespace mwmp;
@ -12,6 +13,17 @@ void PacketPlayerEquipment::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
RW(player->exchangeFullInfo, send);
if (player->exchangeFullInfo)
{
for (auto &&equipmentItem : player->equipmentItems)
{
ExchangeItemInformation(equipmentItem, send);
}
}
else
{
uint32_t count;
if (send)
count = static_cast<uint32_t>(player->equipmentIndexChanges.size());
@ -27,10 +39,16 @@ void PacketPlayerEquipment::Packet(RakNet::BitStream *bs, bool send)
for (auto &&equipmentIndex : player->equipmentIndexChanges)
{
RW(equipmentIndex, send);
RW(player->equipmentItems[equipmentIndex].refId, send);
RW(player->equipmentItems[equipmentIndex].count, send);
RW(player->equipmentItems[equipmentIndex].charge, send);
RW(player->equipmentItems[equipmentIndex].enchantmentCharge, send);
ExchangeItemInformation(player->equipmentItems[equipmentIndex], send);
}
}
}
void PacketPlayerEquipment::ExchangeItemInformation(Item &item, bool send)
{
RW(item.refId, send);
RW(item.count, send);
RW(item.charge, send);
RW(item.enchantmentCharge, send);
}

@ -15,6 +15,7 @@ namespace mwmp
PacketPlayerEquipment(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
void ExchangeItemInformation(Item &item, bool send);
};
}

@ -14,6 +14,14 @@ void PacketPlayerSkill::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
RW(player->exchangeFullInfo, send);
if (player->exchangeFullInfo)
{
RW(player->npcStats.mSkills, send);
}
else
{
uint32_t count;
if (send)
@ -32,4 +40,5 @@ void PacketPlayerSkill::Packet(RakNet::BitStream *bs, bool send)
RW(skillId, send);
RW(player->npcStats.mSkills[skillId], send);
}
}
}

@ -1,4 +1,5 @@
#include "PacketPlayerStatsDynamic.hpp"
#include <components/openmw-mp/NetworkMessages.hpp>
using namespace mwmp;
@ -12,7 +13,16 @@ void PacketPlayerStatsDynamic::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
RW(player->exchangeFullInfo, send);
if (player->exchangeFullInfo)
{
RW(player->creatureStats.mDynamic, send);
}
else
{
uint32_t count;
if (send)
count = static_cast<uint32_t>(player->statsDynamicIndexChanges.size());
@ -30,4 +40,5 @@ void PacketPlayerStatsDynamic::Packet(RakNet::BitStream *bs, bool send)
RW(player->creatureStats.mDynamic[statsDynamicIndex], send);
}
}
}

Loading…
Cancel
Save