[General] Synchronize TCL state for players

Additionally, only purge temporary levitation effect for DedicatedPlayers if one has been added.
pull/556/head
David Cernat 5 years ago
parent 7120f41cfa
commit 1283d5d487

@ -53,6 +53,7 @@ DedicatedPlayer::DedicatedPlayer(RakNet::RakNetGUID guid) : BasePlayer(guid)
creatureStats.mDynamic[2].mBase = 1000;
movementFlags = 0;
hasTcl = false;
attack.instant = false;
cell.blank();
@ -251,14 +252,18 @@ void DedicatedPlayer::setAnimFlags()
// Until we figure out a better workaround for disabling player gravity,
// simply cast Levitate over and over on a player that's supposed to be flying
if (!isFlying)
if (!isFlying && !hasTcl && !isLevitationPurged)
{
ptr.getClass().getCreatureStats(ptr).getActiveSpells().purgeEffect(ESM::MagicEffect::Levitate);
else if (isFlying && !world->isFlying(ptr))
isLevitationPurged = true;
}
else if ((isFlying || hasTcl) && !world->isFlying(ptr))
{
MWMechanics::CastSpell levitationCast(ptr, ptr);
levitationCast.mHitPosition = ptr.getRefData().getPosition().asVec3();
levitationCast.mAlwaysSucceed = true;
levitationCast.cast("Levitate");
isLevitationPurged = false;
}
MWMechanics::CreatureStats *ptrCreatureStats = &ptr.getClass().getCreatureStats(ptr);

@ -76,6 +76,7 @@ namespace mwmp
std::string creatureRecordId;
bool hasFinishedInitialTeleportation;
bool isLevitationPurged;
};
}
#endif //OPENMW_DEDICATEDPLAYER_HPP

@ -83,6 +83,7 @@ LocalPlayer::LocalPlayer()
scale = 1;
isWerewolf = false;
hasTcl = false;
isReceivingInventory = false;
isReceivingQuickKeys = false;
@ -621,10 +622,11 @@ void LocalPlayer::updateAnimFlags(bool forceUpdate)
isFlying = world->isFlying(ptrPlayer);
bool isJumping = !world->isOnGround(ptrPlayer) && !isFlying;
// We need to send a new packet at the end of jumping and flying too,
// We need to send a new packet at the end of jumping, flying and TCL-ing too,
// so keep track of what we were doing last frame
static bool wasJumping = false;
static bool wasFlying = false;
static bool hadTcl = false;
drawState = ptrPlayer.getClass().getNpcStats(ptrPlayer).getDrawState();
static char lastDrawState = ptrPlayer.getClass().getNpcStats(ptrPlayer).getDrawState();
@ -632,7 +634,7 @@ void LocalPlayer::updateAnimFlags(bool forceUpdate)
if (wasRunning != isRunning ||
wasSneaking != isSneaking || wasForceJumping != isForceJumping ||
wasForceMoveJumping != isForceMoveJumping || lastDrawState != drawState ||
wasJumping || isJumping || wasFlying != isFlying ||
wasJumping || isJumping || wasFlying != isFlying || hadTcl != hasTcl ||
forceUpdate)
{
wasSneaking = isSneaking;
@ -641,8 +643,9 @@ void LocalPlayer::updateAnimFlags(bool forceUpdate)
wasForceMoveJumping = isForceMoveJumping;
lastDrawState = drawState;
wasFlying = isFlying;
wasJumping = isJumping;
wasFlying = isFlying;
hadTcl = hasTcl;
movementFlags = 0;

@ -7,6 +7,17 @@
#include <components/interpreter/runtime.hpp>
#include <components/interpreter/opcodes.hpp>
/*
Start of tes3mp addition
Include additional headers for multiplayer purposes
*/
#include "../mwmp/Main.hpp"
#include "../mwmp/LocalPlayer.hpp"
/*
End of tes3mp addition
*/
#include "../mwbase/environment.hpp"
#include "../mwbase/inputmanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"
@ -67,6 +78,16 @@ namespace MWScript
{
bool enabled = MWBase::Environment::get().getWorld()->toggleCollisionMode();
/*
Start of tes3mp addition
Update the LocalPlayer's tclState so it gets sent to the server
*/
mwmp::Main::get().getLocalPlayer()->hasTcl = !enabled;
/*
End of tes3mp addition
*/
runtime.getContext().report (enabled ? "Collision -> On" : "Collision -> Off");
}
};

@ -232,6 +232,7 @@ namespace mwmp
char movementAnim;
char drawState;
bool isFlying;
bool hasTcl;
ESM::Position position;
ESM::Position direction;

@ -13,4 +13,5 @@ void mwmp::PacketPlayerAnimFlags::Packet(RakNet::BitStream *bs, bool send)
RW(player->movementFlags, send);
RW(player->drawState, send);
RW(player->isFlying, send);
RW(player->hasTcl, send);
}

Loading…
Cancel
Save