1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-28 20:36:42 +00:00

[General] Synchronize TCL state for players

Additionally, only purge temporary levitation effect for DedicatedPlayers if one has been added.
This commit is contained in:
David Cernat 2019-12-01 18:13:24 +02:00
parent 7120f41cfa
commit 1283d5d487
6 changed files with 37 additions and 5 deletions

View file

@ -53,6 +53,7 @@ DedicatedPlayer::DedicatedPlayer(RakNet::RakNetGUID guid) : BasePlayer(guid)
creatureStats.mDynamic[2].mBase = 1000; creatureStats.mDynamic[2].mBase = 1000;
movementFlags = 0; movementFlags = 0;
hasTcl = false;
attack.instant = false; attack.instant = false;
cell.blank(); cell.blank();
@ -251,14 +252,18 @@ void DedicatedPlayer::setAnimFlags()
// Until we figure out a better workaround for disabling player gravity, // 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 // 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); 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); MWMechanics::CastSpell levitationCast(ptr, ptr);
levitationCast.mHitPosition = ptr.getRefData().getPosition().asVec3(); levitationCast.mHitPosition = ptr.getRefData().getPosition().asVec3();
levitationCast.mAlwaysSucceed = true; levitationCast.mAlwaysSucceed = true;
levitationCast.cast("Levitate"); levitationCast.cast("Levitate");
isLevitationPurged = false;
} }
MWMechanics::CreatureStats *ptrCreatureStats = &ptr.getClass().getCreatureStats(ptr); MWMechanics::CreatureStats *ptrCreatureStats = &ptr.getClass().getCreatureStats(ptr);

View file

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

View file

@ -83,6 +83,7 @@ LocalPlayer::LocalPlayer()
scale = 1; scale = 1;
isWerewolf = false; isWerewolf = false;
hasTcl = false;
isReceivingInventory = false; isReceivingInventory = false;
isReceivingQuickKeys = false; isReceivingQuickKeys = false;
@ -621,10 +622,11 @@ void LocalPlayer::updateAnimFlags(bool forceUpdate)
isFlying = world->isFlying(ptrPlayer); isFlying = world->isFlying(ptrPlayer);
bool isJumping = !world->isOnGround(ptrPlayer) && !isFlying; 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 // so keep track of what we were doing last frame
static bool wasJumping = false; static bool wasJumping = false;
static bool wasFlying = false; static bool wasFlying = false;
static bool hadTcl = false;
drawState = ptrPlayer.getClass().getNpcStats(ptrPlayer).getDrawState(); drawState = ptrPlayer.getClass().getNpcStats(ptrPlayer).getDrawState();
static char lastDrawState = 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 || if (wasRunning != isRunning ||
wasSneaking != isSneaking || wasForceJumping != isForceJumping || wasSneaking != isSneaking || wasForceJumping != isForceJumping ||
wasForceMoveJumping != isForceMoveJumping || lastDrawState != drawState || wasForceMoveJumping != isForceMoveJumping || lastDrawState != drawState ||
wasJumping || isJumping || wasFlying != isFlying || wasJumping || isJumping || wasFlying != isFlying || hadTcl != hasTcl ||
forceUpdate) forceUpdate)
{ {
wasSneaking = isSneaking; wasSneaking = isSneaking;
@ -641,8 +643,9 @@ void LocalPlayer::updateAnimFlags(bool forceUpdate)
wasForceMoveJumping = isForceMoveJumping; wasForceMoveJumping = isForceMoveJumping;
lastDrawState = drawState; lastDrawState = drawState;
wasFlying = isFlying;
wasJumping = isJumping; wasJumping = isJumping;
wasFlying = isFlying;
hadTcl = hasTcl;
movementFlags = 0; movementFlags = 0;

View file

@ -7,6 +7,17 @@
#include <components/interpreter/runtime.hpp> #include <components/interpreter/runtime.hpp>
#include <components/interpreter/opcodes.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/environment.hpp"
#include "../mwbase/inputmanager.hpp" #include "../mwbase/inputmanager.hpp"
#include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/mechanicsmanager.hpp"
@ -67,6 +78,16 @@ namespace MWScript
{ {
bool enabled = MWBase::Environment::get().getWorld()->toggleCollisionMode(); 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"); runtime.getContext().report (enabled ? "Collision -> On" : "Collision -> Off");
} }
}; };

View file

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

View file

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