[Server] Send level packets in Player's update() at the appropriate time

Previously, trying to send a level packet after base info and character class packets in a script actually led to the level packet being sent first and then being overridden by the others, with the player ending up at level 1 on their client.
new-script-api
David Cernat 7 years ago
parent 494b10b97e
commit 57a0415ba3

@ -19,11 +19,12 @@ NetActor::NetActor() : inventory(this), cellAPI(this)
void NetActor::resetUpdateFlags()
{
baseInfoChanged = false;
levelChanged = false;
statsChanged = false;
positionChanged = false;
skillsChanged = false;
attributesChanged = false;
baseInfoChanged = false;
positionChanged = false;
}
std::tuple<float, float, float> NetActor::getPosition() const

@ -64,7 +64,7 @@ public:
mwmp::BaseNetCreature *getNetCreature() { return netCreature; }
protected:
bool statsChanged, attributesChanged, skillsChanged, baseInfoChanged, positionChanged;
bool baseInfoChanged, levelChanged, statsChanged, positionChanged, attributesChanged, skillsChanged;
mwmp::BasePlayer *basePlayer;
mwmp::BaseNetCreature *netCreature;

@ -123,6 +123,14 @@ void Player::update()
// The character class can override values from below on the client, so send it first
cClass.update();
if (levelChanged)
{
auto packet = plPCtrl->GetPacket(ID_PLAYER_LEVEL);
packet->setPlayer(basePlayer);
packet->Send(false);
packet->Send(true);
}
if (statsChanged)
{
auto packet = plPCtrl->GetPacket(ID_PLAYER_STATS_DYNAMIC);
@ -356,10 +364,7 @@ void Player::setIsMale(bool male)
void Player::setLevel(int level)
{
creatureStats.mLevel = level;
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_LEVEL);
packet->setPlayer(this);
packet->Send(false);
packet->Send(true);
levelChanged = true;
}
int Player::getLevel() const

Loading…
Cancel
Save