From 43a3daf0aad015bc1da3de70d4a7d6be1d77f60f Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 15 Jul 2017 09:02:19 +0300 Subject: [PATCH] [General] Add & implement PlayerShapeshift packet for werewolf states --- apps/openmw-mp/CMakeLists.txt | 7 +- apps/openmw-mp/Script/ScriptFunctions.hpp | 1 + .../processors/ProcessorInitializer.cpp | 2 + .../player/ProcessorPlayerShapeshift.hpp | 27 ++++ apps/openmw/CMakeLists.txt | 4 +- apps/openmw/mwmp/DedicatedPlayer.cpp | 5 + apps/openmw/mwmp/DedicatedPlayer.hpp | 1 + apps/openmw/mwmp/LocalPlayer.cpp | 120 ++++++++++-------- apps/openmw/mwmp/LocalPlayer.hpp | 2 + .../mwmp/processors/ProcessorInitializer.cpp | 2 + .../player/ProcessorPlayerShapeshift.hpp | 30 +++++ apps/openmw/mwscript/statsextensions.cpp | 11 ++ components/CMakeLists.txt | 3 +- components/openmw-mp/Base/BasePlayer.hpp | 2 + .../Controllers/PlayerPacketController.cpp | 2 + components/openmw-mp/NetworkMessages.hpp | 1 + .../Packets/Player/PacketPlayerShapeshift.cpp | 16 +++ .../Packets/Player/PacketPlayerShapeshift.hpp | 17 +++ 18 files changed, 195 insertions(+), 58 deletions(-) create mode 100644 apps/openmw-mp/processors/player/ProcessorPlayerShapeshift.hpp create mode 100644 apps/openmw/mwmp/processors/player/ProcessorPlayerShapeshift.hpp create mode 100644 components/openmw-mp/Packets/Player/PacketPlayerShapeshift.cpp create mode 100644 components/openmw-mp/Packets/Player/PacketPlayerShapeshift.hpp diff --git a/apps/openmw-mp/CMakeLists.txt b/apps/openmw-mp/CMakeLists.txt index 2a38be755..fc9ee0527 100644 --- a/apps/openmw-mp/CMakeLists.txt +++ b/apps/openmw-mp/CMakeLists.txt @@ -131,9 +131,10 @@ set(PROCESSORS_PLAYER processors/player/ProcessorPlayerJournal.hpp processors/player/ProcessorPlayerKillCount.hpp processors/player/ProcessorPlayerLevel.hpp processors/player/ProcessorPlayerMap.hpp processors/player/ProcessorPlayerPosition.hpp processors/player/ProcessorPlayerRest.hpp - processors/player/ProcessorPlayerResurrect.hpp processors/player/ProcessorPlayerSkill.hpp - processors/player/ProcessorPlayerSpeech.hpp processors/player/ProcessorPlayerSpellbook.hpp - processors/player/ProcessorPlayerStatsDynamic.hpp processors/player/ProcessorPlayerTopic.hpp + processors/player/ProcessorPlayerResurrect.hpp processors/player/ProcessorPlayerShapeshift.hpp + processors/player/ProcessorPlayerSkill.hpp processors/player/ProcessorPlayerSpeech.hpp + processors/player/ProcessorPlayerSpellbook.hpp processors/player/ProcessorPlayerStatsDynamic.hpp + processors/player/ProcessorPlayerTopic.hpp ) source_group(tes3mp-server\\processors\\player FILES ${PROCESSORS_PLAYER}) diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index 3f38c64dd..6ad47a55d 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -145,6 +145,7 @@ public: {"OnPlayerInventory", Function()}, {"OnPlayerJournal", Function()}, {"OnPlayerFaction", Function()}, + {"OnPlayerShapeshift", Function()}, {"OnPlayerSpellbook", Function()}, {"OnPlayerTopic", Function()}, {"OnPlayerDisposition", Function()}, diff --git a/apps/openmw-mp/processors/ProcessorInitializer.cpp b/apps/openmw-mp/processors/ProcessorInitializer.cpp index 8167e635d..62257b63e 100644 --- a/apps/openmw-mp/processors/ProcessorInitializer.cpp +++ b/apps/openmw-mp/processors/ProcessorInitializer.cpp @@ -33,6 +33,7 @@ #include "player/ProcessorPlayerPosition.hpp" #include "player/ProcessorPlayerRest.hpp" #include "player/ProcessorPlayerResurrect.hpp" +#include "player/ProcessorPlayerShapeshift.hpp" #include "player/ProcessorPlayerSkill.hpp" #include "player/ProcessorPlayerSpeech.hpp" #include "player/ProcessorPlayerSpellbook.hpp" @@ -101,6 +102,7 @@ void ProcessorInitializer() PlayerProcessor::AddProcessor(new ProcessorPlayerPosition()); PlayerProcessor::AddProcessor(new ProcessorPlayerRest()); PlayerProcessor::AddProcessor(new ProcessorPlayerResurrect()); + PlayerProcessor::AddProcessor(new ProcessorPlayerShapeshift()); PlayerProcessor::AddProcessor(new ProcessorPlayerSkill()); PlayerProcessor::AddProcessor(new ProcessorPlayerSpeech()); PlayerProcessor::AddProcessor(new ProcessorPlayerSpellbook()); diff --git a/apps/openmw-mp/processors/player/ProcessorPlayerShapeshift.hpp b/apps/openmw-mp/processors/player/ProcessorPlayerShapeshift.hpp new file mode 100644 index 000000000..aa9f6f0d3 --- /dev/null +++ b/apps/openmw-mp/processors/player/ProcessorPlayerShapeshift.hpp @@ -0,0 +1,27 @@ +#ifndef OPENMW_PROCESSORPLAYERSHAPESHIFT_HPP +#define OPENMW_PROCESSORPLAYERSHAPESHIFT_HPP + +#include "../PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerShapeshift : public PlayerProcessor + { + public: + ProcessorPlayerShapeshift() + { + BPP_INIT(ID_PLAYER_SHAPESHIFT) + } + + void Do(PlayerPacket &packet, Player &player) override + { + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received %s from %s", strPacketID.c_str(), player.npc.mName.c_str()); + + packet.Send(true); + + Script::Call(player.getId()); + } + }; +} + +#endif //OPENMW_PROCESSORPLAYERSHAPESHIFT_HPP diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 2699ca0c0..ede543e3c 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -117,8 +117,8 @@ add_openmw_dir (mwmp/processors/player ProcessorChatMessage ProcessorGUIMessageB ProcessorPlayerBook ProcessorPlayerBounty ProcessorPlayerCellChange ProcessorPlayerCellState ProcessorPlayerCharClass ProcessorPlayerCharGen ProcessorPlayerDeath ProcessorPlayerDisposition ProcessorPlayerEquipment ProcessorPlayerFaction ProcessorPlayerInventory ProcessorPlayerJail ProcessorPlayerJournal ProcessorPlayerKillCount ProcessorPlayerLevel - ProcessorPlayerMap ProcessorPlayerPosition ProcessorPlayerResurrect ProcessorPlayerSkill ProcessorPlayerSpeech - ProcessorPlayerSpellbook ProcessorPlayerStatsDynamic ProcessorPlayerTopic + ProcessorPlayerMap ProcessorPlayerPosition ProcessorPlayerResurrect ProcessorPlayerShapeshift ProcessorPlayerSkill + ProcessorPlayerSpeech ProcessorPlayerSpellbook ProcessorPlayerStatsDynamic ProcessorPlayerTopic ) add_openmw_dir (mwmp/processors/world BaseObjectProcessor ProcessorConsoleCommand ProcessorContainer ProcessorDoorState diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index 9b40f9722..66ca293ec 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -237,6 +237,11 @@ void DedicatedPlayer::setCell() Main::get().getCellController()->getCell(cell)->updateLocal(true); } +void DedicatedPlayer::setShapeshift() +{ + MWBase::Environment::get().getMechanicsManager()->setWerewolf(ptr, isWerewolf); +} + void DedicatedPlayer::updateMarker() { if (!markerEnabled) diff --git a/apps/openmw/mwmp/DedicatedPlayer.hpp b/apps/openmw/mwmp/DedicatedPlayer.hpp index ce91de558..212279852 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.hpp +++ b/apps/openmw/mwmp/DedicatedPlayer.hpp @@ -37,6 +37,7 @@ namespace mwmp void setAnimFlags(); void setEquipment(); void setCell(); + void setShapeshift(); void updateMarker(); void removeMarker(); diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index a84543978..85ffe6f44 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -149,8 +149,8 @@ bool LocalPlayer::charGenThread() else if (charGenStage.end != 0) { MWBase::World *world = MWBase::Environment::get().getWorld(); - MWWorld::Ptr player = world->getPlayerPtr(); - npc = *player.get()->mBase; + MWWorld::Ptr ptrPlayer = world->getPlayerPtr(); + npc = *ptrPlayer.get()->mBase; birthsign = world->getPlayer().getBirthSign(); LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Sending ID_PLAYER_BASEINFO to server with my CharGen info"); @@ -187,9 +187,9 @@ bool LocalPlayer::hasFinishedCharGen() void LocalPlayer::updateStatsDynamic(bool forceUpdate) { - MWWorld::Ptr player = getPlayerPtr(); + MWWorld::Ptr ptrPlayer = getPlayerPtr(); - MWMechanics::CreatureStats *ptrCreatureStats = &player.getClass().getCreatureStats(player); + MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer); MWMechanics::DynamicStat health(ptrCreatureStats->getHealth()); MWMechanics::DynamicStat magicka(ptrCreatureStats->getMagicka()); MWMechanics::DynamicStat fatigue(ptrCreatureStats->getFatigue()); @@ -223,8 +223,8 @@ void LocalPlayer::updateStatsDynamic(bool forceUpdate) void LocalPlayer::updateAttributes(bool forceUpdate) { - MWWorld::Ptr player = getPlayerPtr(); - const MWMechanics::NpcStats &ptrNpcStats = player.getClass().getNpcStats(player); + MWWorld::Ptr ptrPlayer = getPlayerPtr(); + const MWMechanics::NpcStats &ptrNpcStats = ptrPlayer.getClass().getNpcStats(ptrPlayer); bool attributesChanged = false; for (int i = 0; i < 8; ++i) @@ -245,8 +245,8 @@ void LocalPlayer::updateAttributes(bool forceUpdate) void LocalPlayer::updateSkills(bool forceUpdate) { - MWWorld::Ptr player = getPlayerPtr(); - const MWMechanics::NpcStats &ptrNpcStats = player.getClass().getNpcStats(player); + MWWorld::Ptr ptrPlayer = getPlayerPtr(); + const MWMechanics::NpcStats &ptrNpcStats = ptrPlayer.getClass().getNpcStats(ptrPlayer); // Track whether skills have changed their values, but not whether // progress towards skill increases has changed (to not spam server @@ -282,8 +282,8 @@ void LocalPlayer::updateSkills(bool forceUpdate) void LocalPlayer::updateLevel(bool forceUpdate) { - MWWorld::Ptr player = getPlayerPtr(); - const MWMechanics::CreatureStats &ptrCreatureStats = player.getClass().getCreatureStats(player); + MWWorld::Ptr ptrPlayer = getPlayerPtr(); + const MWMechanics::CreatureStats &ptrCreatureStats = ptrPlayer.getClass().getCreatureStats(ptrPlayer); if (ptrCreatureStats.getLevel() != creatureStats.mLevel || forceUpdate) { @@ -299,8 +299,8 @@ void LocalPlayer::updateLevel(bool forceUpdate) void LocalPlayer::updateBounty(bool forceUpdate) { - MWWorld::Ptr player = getPlayerPtr(); - const MWMechanics::NpcStats &ptrNpcStats = player.getClass().getNpcStats(player); + MWWorld::Ptr ptrPlayer = getPlayerPtr(); + const MWMechanics::NpcStats &ptrNpcStats = ptrPlayer.getClass().getNpcStats(ptrPlayer); if (ptrNpcStats.getBounty() != npcStats.mBounty || forceUpdate) { @@ -313,14 +313,14 @@ void LocalPlayer::updateBounty(bool forceUpdate) void LocalPlayer::updatePosition(bool forceUpdate) { MWBase::World *world = MWBase::Environment::get().getWorld(); - MWWorld::Ptr player = world->getPlayerPtr(); + MWWorld::Ptr ptrPlayer = world->getPlayerPtr(); static bool posWasChanged = false; static bool isJumping = false; static bool sentJumpEnd = true; static float oldRot[2] = {0}; - position = player.getRefData().getPosition(); + position = ptrPlayer.getRefData().getPosition(); bool posIsChanging = (direction.pos[0] != 0 || direction.pos[1] != 0 || position.rot[0] != oldRot[0] || position.rot[2] != oldRot[1]); @@ -332,13 +332,13 @@ void LocalPlayer::updatePosition(bool forceUpdate) posWasChanged = posIsChanging; - if (!isJumping && !world->isOnGround(player) && !world->isFlying(player)) + if (!isJumping && !world->isOnGround(ptrPlayer) && !world->isFlying(ptrPlayer)) isJumping = true; getNetworking()->getPlayerPacket(ID_PLAYER_POSITION)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_POSITION)->Send(); } - else if (isJumping && world->isOnGround(player)) + else if (isJumping && world->isOnGround(ptrPlayer)) { isJumping = false; sentJumpEnd = false; @@ -347,7 +347,7 @@ void LocalPlayer::updatePosition(bool forceUpdate) else if (!sentJumpEnd) { sentJumpEnd = true; - position = player.getRefData().getPosition(); + position = ptrPlayer.getRefData().getPosition(); getNetworking()->getPlayerPacket(ID_PLAYER_POSITION)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_POSITION)->Send(); } @@ -402,14 +402,14 @@ void LocalPlayer::updateChar() void LocalPlayer::updateEquipment(bool forceUpdate) { - MWWorld::Ptr player = getPlayerPtr(); + MWWorld::Ptr ptrPlayer = getPlayerPtr(); static bool equipmentChanged = false; if (forceUpdate) equipmentChanged = true; - MWWorld::InventoryStore &invStore = player.getClass().getInventoryStore(player); + MWWorld::InventoryStore &invStore = ptrPlayer.getClass().getInventoryStore(ptrPlayer); for (int slot = 0; slot < MWWorld::InventoryStore::Slots; slot++) { auto &item = equipedItems[slot]; @@ -425,8 +425,8 @@ void LocalPlayer::updateEquipment(bool forceUpdate) if (slot == MWWorld::InventoryStore::Slot_CarriedRight) { MWMechanics::WeaponType weaptype; - MWMechanics::getActiveWeapon(player.getClass().getCreatureStats(player), - player.getClass().getInventoryStore(player), &weaptype); + MWMechanics::getActiveWeapon(ptrPlayer.getClass().getCreatureStats(ptrPlayer), + ptrPlayer.getClass().getInventoryStore(ptrPlayer), &weaptype); if (weaptype != MWMechanics::WeapType_Thrown) item.count = 1; } @@ -536,9 +536,9 @@ void LocalPlayer::updateAttack() void LocalPlayer::updateDeadState(bool forceUpdate) { - MWWorld::Ptr player = getPlayerPtr(); + MWWorld::Ptr ptrPlayer = getPlayerPtr(); - MWMechanics::NpcStats *ptrNpcStats = &player.getClass().getNpcStats(player); + MWMechanics::NpcStats *ptrNpcStats = &ptrPlayer.getClass().getNpcStats(ptrPlayer); static bool isDead = false; if (ptrNpcStats->isDead() && !isDead) @@ -561,9 +561,9 @@ void LocalPlayer::updateDeadState(bool forceUpdate) void LocalPlayer::updateAnimFlags(bool forceUpdate) { MWBase::World *world = MWBase::Environment::get().getWorld(); - MWWorld::Ptr player = world->getPlayerPtr(); + MWWorld::Ptr ptrPlayer = world->getPlayerPtr(); - MWMechanics::NpcStats ptrNpcStats = player.getClass().getNpcStats(player); + MWMechanics::NpcStats ptrNpcStats = ptrPlayer.getClass().getNpcStats(ptrPlayer); using namespace MWMechanics; static bool wasRunning = ptrNpcStats.getMovementFlag(CreatureStats::Flag_Run); @@ -576,16 +576,16 @@ void LocalPlayer::updateAnimFlags(bool forceUpdate) bool isForceJumping = ptrNpcStats.getMovementFlag(CreatureStats::Flag_ForceJump); bool isForceMoveJumping = ptrNpcStats.getMovementFlag(CreatureStats::Flag_ForceMoveJump); - isFlying = world->isFlying(player); - bool isJumping = !world->isOnGround(player) && !isFlying; + 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, // so keep track of what we were doing last frame static bool wasJumping = false; static bool wasFlying = false; - MWMechanics::DrawState_ currentDrawState = player.getClass().getNpcStats(player).getDrawState(); - static MWMechanics::DrawState_ lastDrawState = player.getClass().getNpcStats(player).getDrawState(); + MWMechanics::DrawState_ currentDrawState = ptrPlayer.getClass().getNpcStats(ptrPlayer).getDrawState(); + static MWMechanics::DrawState_ lastDrawState = ptrPlayer.getClass().getNpcStats(ptrPlayer).getDrawState(); if (wasRunning != isRunning || wasSneaking != isSneaking || wasForceJumping != isForceJumping || @@ -649,7 +649,7 @@ void LocalPlayer::addSpells() for (const auto &spell : spellbookChanges.spells) ptrSpells.add(spell.mId); - + } void LocalPlayer::addJournalItems() @@ -714,9 +714,9 @@ void LocalPlayer::removeSpells() void LocalPlayer::setDynamicStats() { MWBase::World *world = MWBase::Environment::get().getWorld(); - MWWorld::Ptr player = world->getPlayerPtr(); + MWWorld::Ptr ptrPlayer = world->getPlayerPtr(); - MWMechanics::CreatureStats *ptrCreatureStats = &player.getClass().getCreatureStats(player); + MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer); MWMechanics::DynamicStat dynamicStat; for (int i = 0; i < 3; ++i) @@ -731,9 +731,9 @@ void LocalPlayer::setDynamicStats() void LocalPlayer::setAttributes() { MWBase::World *world = MWBase::Environment::get().getWorld(); - MWWorld::Ptr player = world->getPlayerPtr(); + MWWorld::Ptr ptrPlayer = world->getPlayerPtr(); - MWMechanics::CreatureStats *ptrCreatureStats = &player.getClass().getCreatureStats(player); + MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer); MWMechanics::AttributeValue attributeValue; for (int i = 0; i < 8; ++i) @@ -746,9 +746,9 @@ void LocalPlayer::setAttributes() void LocalPlayer::setSkills() { MWBase::World *world = MWBase::Environment::get().getWorld(); - MWWorld::Ptr player = world->getPlayerPtr(); + MWWorld::Ptr ptrPlayer = world->getPlayerPtr(); - MWMechanics::NpcStats *ptrNpcStats = &player.getClass().getNpcStats(player); + MWMechanics::NpcStats *ptrNpcStats = &ptrPlayer.getClass().getNpcStats(ptrPlayer); MWMechanics::SkillValue skillValue; for (int i = 0; i < 27; ++i) @@ -766,25 +766,25 @@ void LocalPlayer::setSkills() void LocalPlayer::setLevel() { MWBase::World *world = MWBase::Environment::get().getWorld(); - MWWorld::Ptr player = world->getPlayerPtr(); + MWWorld::Ptr ptrPlayer = world->getPlayerPtr(); - MWMechanics::CreatureStats *ptrCreatureStats = &player.getClass().getCreatureStats(player); + MWMechanics::CreatureStats *ptrCreatureStats = &ptrPlayer.getClass().getCreatureStats(ptrPlayer); ptrCreatureStats->setLevel(creatureStats.mLevel); } void LocalPlayer::setBounty() { MWBase::World *world = MWBase::Environment::get().getWorld(); - MWWorld::Ptr player = world->getPlayerPtr(); + MWWorld::Ptr ptrPlayer = world->getPlayerPtr(); - MWMechanics::NpcStats *ptrNpcStats = &player.getClass().getNpcStats(player); + MWMechanics::NpcStats *ptrNpcStats = &ptrPlayer.getClass().getNpcStats(ptrPlayer); ptrNpcStats->setBounty(npcStats.mBounty); } void LocalPlayer::setPosition() { MWBase::World *world = MWBase::Environment::get().getWorld(); - MWWorld::Ptr player = world->getPlayerPtr(); + MWWorld::Ptr ptrPlayer = world->getPlayerPtr(); // If we're ignoring this position packet because of an invalid cell change, // don't make the next one get ignored as well @@ -793,8 +793,8 @@ void LocalPlayer::setPosition() else { world->getPlayer().setTeleported(true); - world->moveObject(player, position.pos[0], position.pos[1], position.pos[2]); - world->rotateObject(player, position.rot[0], position.rot[1], position.rot[2]); + world->moveObject(ptrPlayer, position.pos[0], position.pos[1], position.pos[2]); + world->rotateObject(ptrPlayer, position.rot[0], position.rot[1], position.rot[2]); } updatePosition(true); @@ -806,7 +806,7 @@ void LocalPlayer::setPosition() void LocalPlayer::setCell() { MWBase::World *world = MWBase::Environment::get().getWorld(); - MWWorld::Ptr player = world->getPlayerPtr(); + MWWorld::Ptr ptrPlayer = world->getPlayerPtr(); ESM::Position pos; // To avoid crashes, close any container menus this player may be in @@ -829,12 +829,12 @@ void LocalPlayer::setCell() pos.rot[0] = pos.rot[1] = pos.rot[2] = 0; world->changeToExteriorCell(pos, true); - world->fixPosition(player); + world->fixPosition(ptrPlayer); } else if (world->findExteriorPosition(cell.mName, pos)) { world->changeToExteriorCell(pos, true); - world->fixPosition(player); + world->fixPosition(ptrPlayer); } else { @@ -950,8 +950,8 @@ void LocalPlayer::setSpellbook() void LocalPlayer::setFactions() { - MWWorld::Ptr player = getPlayerPtr(); - MWMechanics::NpcStats &ptrNpcStats = player.getClass().getNpcStats(player); + MWWorld::Ptr ptrPlayer = getPlayerPtr(); + MWMechanics::NpcStats &ptrNpcStats = ptrPlayer.getClass().getNpcStats(ptrPlayer); for (const auto &faction : factionChanges.factions) { @@ -997,8 +997,8 @@ void LocalPlayer::setKills() void LocalPlayer::setBooks() { - MWWorld::Ptr player = getPlayerPtr(); - MWMechanics::NpcStats &ptrNpcStats = player.getClass().getNpcStats(player); + MWWorld::Ptr ptrPlayer = getPlayerPtr(); + MWMechanics::NpcStats &ptrNpcStats = ptrPlayer.getClass().getNpcStats(ptrPlayer); for (const auto &book : bookChanges.books) ptrNpcStats.flagAsUsed(book.bookId); @@ -1006,8 +1006,8 @@ void LocalPlayer::setBooks() void LocalPlayer::setMapExplored() { - MWWorld::Ptr player = getPlayerPtr(); - MWMechanics::NpcStats &ptrNpcStats = player.getClass().getNpcStats(player); + MWWorld::Ptr ptrPlayer = getPlayerPtr(); + MWMechanics::NpcStats &ptrNpcStats = ptrPlayer.getClass().getNpcStats(ptrPlayer); for (const auto &cellExplored : mapChanges.cellsExplored) { @@ -1018,6 +1018,12 @@ void LocalPlayer::setMapExplored() } } +void LocalPlayer::setShapeshift() +{ + MWWorld::Ptr ptrPlayer = getPlayerPtr(); + MWBase::Environment::get().getMechanicsManager()->setWerewolf(ptrPlayer, isWerewolf); +} + void LocalPlayer::sendClass() { MWBase::World *world = MWBase::Environment::get().getWorld(); @@ -1259,6 +1265,16 @@ void LocalPlayer::sendBook(const std::string& bookId) getNetworking()->getPlayerPacket(ID_PLAYER_BOOK)->Send(); } +void LocalPlayer::sendShapeshift(bool werewolfState) +{ + isWerewolf = werewolfState; + + LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Sending ID_PLAYER_SHAPESHIFT with isWerewolf of %s", isWerewolf ? "true" : "false"); + + getNetworking()->getPlayerPacket(ID_PLAYER_SHAPESHIFT)->setPlayer(this); + getNetworking()->getPlayerPacket(ID_PLAYER_SHAPESHIFT)->Send(); +} + void LocalPlayer::clearCellStates() { cellStateChanges.cellStates.clear(); diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index 65722f90e..23308428c 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -62,6 +62,7 @@ namespace mwmp void setKills(); void setBooks(); void setMapExplored(); + void setShapeshift(); void sendClass(); void sendInventory(); @@ -79,6 +80,7 @@ namespace mwmp void sendTopic(const std::string& topic); void sendKill(const std::string& refId, int number); void sendBook(const std::string& bookId); + void sendShapeshift(bool isWerewolf); void clearCellStates(); void clearCurrentContainer(); diff --git a/apps/openmw/mwmp/processors/ProcessorInitializer.cpp b/apps/openmw/mwmp/processors/ProcessorInitializer.cpp index 987fd1795..537177970 100644 --- a/apps/openmw/mwmp/processors/ProcessorInitializer.cpp +++ b/apps/openmw/mwmp/processors/ProcessorInitializer.cpp @@ -38,6 +38,7 @@ #include "player/ProcessorPlayerRegionAuthority.hpp" #include "player/ProcessorPlayerRest.hpp" #include "player/ProcessorPlayerResurrect.hpp" +#include "player/ProcessorPlayerShapeshift.hpp" #include "player/ProcessorPlayerSkill.hpp" #include "player/ProcessorPlayerSpeech.hpp" #include "player/ProcessorPlayerSpellbook.hpp" @@ -115,6 +116,7 @@ void ProcessorInitializer() PlayerProcessor::AddProcessor(new ProcessorPlayerRegionAuthority()); PlayerProcessor::AddProcessor(new ProcessorPlayerRest()); PlayerProcessor::AddProcessor(new ProcessorPlayerResurrect()); + PlayerProcessor::AddProcessor(new ProcessorPlayerShapeshift()); PlayerProcessor::AddProcessor(new ProcessorPlayerSkill()); PlayerProcessor::AddProcessor(new ProcessorPlayerSpeech()); PlayerProcessor::AddProcessor(new ProcessorPlayerSpellbook()); diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerShapeshift.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerShapeshift.hpp new file mode 100644 index 000000000..70479221f --- /dev/null +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerShapeshift.hpp @@ -0,0 +1,30 @@ +#ifndef OPENMW_PROCESSORPLAYERSHAPESHIFT_HPP +#define OPENMW_PROCESSORPLAYERSHAPESHIFT_HPP + +#include "../PlayerProcessor.hpp" + +namespace mwmp +{ + class ProcessorPlayerShapeshift : public PlayerProcessor + { + public: + ProcessorPlayerShapeshift() + { + BPP_INIT(ID_PLAYER_SHAPESHIFT) + } + + virtual void Do(PlayerPacket &packet, BasePlayer *player) + { + if (isLocal()) + { + static_cast(player)->setShapeshift(); + } + else if (player != 0) + { + static_cast(player)->setShapeshift(); + } + } + }; +} + +#endif //OPENMW_PROCESSORPLAYERSHAPESHIFT_HPP diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index af6fe5f97..90b53170b 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -1224,6 +1224,17 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); MWBase::Environment::get().getMechanicsManager()->setWerewolf(ptr, set); + + /* + Start of tes3mp addition + + When the player's werewolf state changes, send an ID_PLAYER_SHAPESHIFT packet + */ + if (ptr == MWMechanics::getPlayer()) + mwmp::Main::get().getLocalPlayer()->sendShapeshift(set); + /* + End of tes3mp addition + */ } }; diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index cd905ce50..c02fab8c9 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -182,7 +182,8 @@ add_component_dir (openmw-mp/Packets/Player PacketPlayerCellState PacketPlayerClass PacketPlayerDeath PacketPlayerEquipment PacketPlayerFaction PacketPlayerInventory PacketPlayerJail PacketPlayerJournal PacketPlayerKillCount PacketPlayerLevel PacketPlayerMap PacketPlayerPosition PacketPlayerRegionAuthority PacketPlayerRest PacketPlayerResurrect - PacketPlayerSkill PacketPlayerSpeech PacketPlayerSpellbook PacketPlayerStatsDynamic PacketPlayerTopic + PacketPlayerShapeshift PacketPlayerSkill PacketPlayerSpeech PacketPlayerSpellbook PacketPlayerStatsDynamic + PacketPlayerTopic ) add_component_dir (openmw-mp/Packets/World diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 1f40f34f6..4f4bdbd4b 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -246,6 +246,8 @@ namespace mwmp std::string chatMessage; CGStage charGenStage; std::string passw; + + bool isWerewolf; std::string creatureModel; bool useCreatureName; diff --git a/components/openmw-mp/Controllers/PlayerPacketController.cpp b/components/openmw-mp/Controllers/PlayerPacketController.cpp index 4d9f8dd48..d155b5066 100644 --- a/components/openmw-mp/Controllers/PlayerPacketController.cpp +++ b/components/openmw-mp/Controllers/PlayerPacketController.cpp @@ -31,6 +31,7 @@ #include "../Packets/Player/PacketPlayerRegionAuthority.hpp" #include "../Packets/Player/PacketPlayerRest.hpp" #include "../Packets/Player/PacketPlayerResurrect.hpp" +#include "../Packets/Player/PacketPlayerShapeshift.hpp" #include "../Packets/Player/PacketPlayerSkill.hpp" #include "../Packets/Player/PacketPlayerSpeech.hpp" #include "../Packets/Player/PacketPlayerSpellbook.hpp" @@ -83,6 +84,7 @@ mwmp::PlayerPacketController::PlayerPacketController(RakNet::RakPeerInterface *p AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); + AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); diff --git a/components/openmw-mp/NetworkMessages.hpp b/components/openmw-mp/NetworkMessages.hpp index 649fd786d..7c4823a15 100644 --- a/components/openmw-mp/NetworkMessages.hpp +++ b/components/openmw-mp/NetworkMessages.hpp @@ -47,6 +47,7 @@ enum GameMessages ID_PLAYER_REGION_AUTHORITY, ID_PLAYER_RESURRECT, ID_PLAYER_REST, + ID_PLAYER_SHAPESHIFT, ID_PLAYER_SKILL, ID_PLAYER_SPEECH, ID_PLAYER_SPELLBOOK, diff --git a/components/openmw-mp/Packets/Player/PacketPlayerShapeshift.cpp b/components/openmw-mp/Packets/Player/PacketPlayerShapeshift.cpp new file mode 100644 index 000000000..1e6c06a70 --- /dev/null +++ b/components/openmw-mp/Packets/Player/PacketPlayerShapeshift.cpp @@ -0,0 +1,16 @@ +#include "PacketPlayerShapeshift.hpp" +#include + +using namespace mwmp; + +PacketPlayerShapeshift::PacketPlayerShapeshift(RakNet::RakPeerInterface *peer) : PlayerPacket(peer) +{ + packetID = ID_PLAYER_SHAPESHIFT; +} + +void PacketPlayerShapeshift::Packet(RakNet::BitStream *bs, bool send) +{ + PlayerPacket::Packet(bs, send); + + RW(player->isWerewolf, send); +} diff --git a/components/openmw-mp/Packets/Player/PacketPlayerShapeshift.hpp b/components/openmw-mp/Packets/Player/PacketPlayerShapeshift.hpp new file mode 100644 index 000000000..fb6c41045 --- /dev/null +++ b/components/openmw-mp/Packets/Player/PacketPlayerShapeshift.hpp @@ -0,0 +1,17 @@ +#ifndef OPENMW_PACKETPLAYERSHAPESHIFT_HPP +#define OPENMW_PACKETPLAYERSHAPESHIFT_HPP + +#include + +namespace mwmp +{ + class PacketPlayerShapeshift : public PlayerPacket + { + public: + PacketPlayerShapeshift(RakNet::RakPeerInterface *peer); + + virtual void Packet(RakNet::BitStream *bs, bool send); + }; +} + +#endif //OPENMW_PACKETPLAYERSHAPESHIFT_HPP