[General] Implement selected spell sync as part of PlayerMiscellaneous

0.6.3
David Cernat 7 years ago
parent 029dfc56ba
commit 74765b3ace

@ -68,6 +68,14 @@ double MechanicsFunctions::GetMarkRotZ(unsigned short pid) noexcept
return player->markPosition.rot[2]; return player->markPosition.rot[2];
} }
const char *MechanicsFunctions::GetSelectedSpellId(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0);
return player->selectedSpellId.c_str();
}
double MechanicsFunctions::GetScale(unsigned short pid) noexcept double MechanicsFunctions::GetScale(unsigned short pid) noexcept
{ {
Player *player; Player *player;
@ -111,6 +119,14 @@ void MechanicsFunctions::SetMarkRot(unsigned short pid, double x, double z) noex
player->markPosition.rot[2] = z; player->markPosition.rot[2] = z;
} }
void MechanicsFunctions::SetSelectedSpellId(unsigned short pid, const char *spellId) noexcept
{
Player *player;
GET_PLAYER(pid, player, );
player->selectedSpellId = spellId;
}
void MechanicsFunctions::SetScale(unsigned short pid, double scale) noexcept void MechanicsFunctions::SetScale(unsigned short pid, double scale) noexcept
{ {
Player *player; Player *player;
@ -138,6 +154,17 @@ void MechanicsFunctions::SendMarkLocation(unsigned short pid)
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MISCELLANEOUS)->Send(false); mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MISCELLANEOUS)->Send(false);
} }
void MechanicsFunctions::SendSelectedSpell(unsigned short pid)
{
Player *player;
GET_PLAYER(pid, player, );
player->miscellaneousChangeType = mwmp::MISCELLANEOUS_CHANGE_TYPE::SELECTED_SPELL;
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MISCELLANEOUS)->setPlayer(player);
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MISCELLANEOUS)->Send(false);
}
void MechanicsFunctions::SendShapeshift(unsigned short pid) void MechanicsFunctions::SendShapeshift(unsigned short pid)
{ {
Player *player; Player *player;

@ -12,6 +12,7 @@
{"GetMarkPosZ", MechanicsFunctions::GetMarkPosZ},\ {"GetMarkPosZ", MechanicsFunctions::GetMarkPosZ},\
{"GetMarkRotX", MechanicsFunctions::GetMarkRotX},\ {"GetMarkRotX", MechanicsFunctions::GetMarkRotX},\
{"GetMarkRotZ", MechanicsFunctions::GetMarkRotZ},\ {"GetMarkRotZ", MechanicsFunctions::GetMarkRotZ},\
{"GetSelectedSpellId", MechanicsFunctions::GetSelectedSpellId},\
\ \
{"GetScale", MechanicsFunctions::GetScale},\ {"GetScale", MechanicsFunctions::GetScale},\
{"IsWerewolf", MechanicsFunctions::IsWerewolf},\ {"IsWerewolf", MechanicsFunctions::IsWerewolf},\
@ -19,11 +20,13 @@
{"SetMarkCell", MechanicsFunctions::SetMarkCell},\ {"SetMarkCell", MechanicsFunctions::SetMarkCell},\
{"SetMarkPos", MechanicsFunctions::SetMarkPos},\ {"SetMarkPos", MechanicsFunctions::SetMarkPos},\
{"SetMarkRot", MechanicsFunctions::SetMarkRot},\ {"SetMarkRot", MechanicsFunctions::SetMarkRot},\
{"SetSelectedSpellId", MechanicsFunctions::SetSelectedSpellId},\
\ \
{"SetScale", MechanicsFunctions::SetScale},\ {"SetScale", MechanicsFunctions::SetScale},\
{"SetWerewolfState", MechanicsFunctions::SetWerewolfState},\ {"SetWerewolfState", MechanicsFunctions::SetWerewolfState},\
\ \
{"SendMarkLocation", MechanicsFunctions::SendMarkLocation},\ {"SendMarkLocation", MechanicsFunctions::SendMarkLocation},\
{"SendSelectedSpell", MechanicsFunctions::SendSelectedSpell},\
{"SendShapeshift", MechanicsFunctions::SendShapeshift},\ {"SendShapeshift", MechanicsFunctions::SendShapeshift},\
\ \
{"Jail", MechanicsFunctions::Jail},\ {"Jail", MechanicsFunctions::Jail},\
@ -89,6 +92,14 @@ public:
*/ */
static double GetMarkRotZ(unsigned short pid) noexcept; static double GetMarkRotZ(unsigned short pid) noexcept;
/**
* \brief Get the ID of a player's selected spell.
*
* \param pid The player ID.
* \return The spell ID.
*/
static const char *GetSelectedSpellId(unsigned short pid) noexcept;
/** /**
* \brief Get the scale of a player. * \brief Get the scale of a player.
* *
@ -149,6 +160,18 @@ public:
*/ */
static void SetMarkRot(unsigned short pid, double x, double z) noexcept; static void SetMarkRot(unsigned short pid, double x, double z) noexcept;
/**
* \brief Set the ID of a player's selected spell.
*
* This changes the spell ID recorded for that player in the server memory, but does not by itself
* send a packet.
*
* \param pid The player ID.
* \param spellId The spell ID.
* \return void
*/
static void SetSelectedSpellId(unsigned short pid, const char *spellId) noexcept;
/** /**
* \brief Set the scale of a player. * \brief Set the scale of a player.
* *
@ -181,6 +204,14 @@ public:
*/ */
static void SendMarkLocation(unsigned short pid); static void SendMarkLocation(unsigned short pid);
/**
* \brief Send a PlayerMiscellaneous packet with a selected spell ID to a player.
*
* \param pid The player ID.
* \return void
*/
static void SendSelectedSpell(unsigned short pid);
/** /**
* \brief Send a PlayerShapeshift packet about a player. * \brief Send a PlayerShapeshift packet about a player.
* *

@ -232,7 +232,8 @@ namespace MWGui
/* /*
Start of tes3mp addition Start of tes3mp addition
Send a PLAYER_QUICKKEYS packet whenever a key is assigned to an item Send a PlayerQuickKeys packet whenever a key is assigned to an item
by a player, not by a packet received from the server
*/ */
if (!mwmp::Main::get().getLocalPlayer()->isReceivingQuickKeys) if (!mwmp::Main::get().getLocalPlayer()->isReceivingQuickKeys)
mwmp::Main::get().getLocalPlayer()->sendQuickKey(mSelectedIndex, Type_Item, item.getCellRef().getRefId()); mwmp::Main::get().getLocalPlayer()->sendQuickKey(mSelectedIndex, Type_Item, item.getCellRef().getRefId());
@ -407,6 +408,16 @@ namespace MWGui
store.setSelectedEnchantItem(store.end()); store.setSelectedEnchantItem(store.end());
MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, int(MWMechanics::getSpellSuccessChance(spellId, player))); MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, int(MWMechanics::getSpellSuccessChance(spellId, player)));
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Spell); MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Spell);
/*
Start of tes3mp addition
Send a PlayerMiscellaneous packet with the player's new selected spell
*/
mwmp::Main::get().getLocalPlayer()->sendSelectedSpell(spellId);
/*
End of tes3mp addition
*/
} }
else if (type == Type_Item) else if (type == Type_Item)
{ {

@ -186,6 +186,16 @@ namespace MWGui
MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, int(MWMechanics::getSpellSuccessChance(spellId, player))); MWBase::Environment::get().getWindowManager()->setSelectedSpell(spellId, int(MWMechanics::getSpellSuccessChance(spellId, player)));
updateSpells(); updateSpells();
/*
Start of tes3mp addition
Send a PlayerMiscellaneous packet with the player's new selected spell
*/
mwmp::Main::get().getLocalPlayer()->sendSelectedSpell(spellId);
/*
End of tes3mp addition
*/
} }
void SpellWindow::onDeleteSpellAccept() void SpellWindow::onDeleteSpellAccept()

@ -19,6 +19,7 @@
#include "../mwmechanics/aitravel.hpp" #include "../mwmechanics/aitravel.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/mechanicsmanagerimp.hpp" #include "../mwmechanics/mechanicsmanagerimp.hpp"
#include "../mwmechanics/spellcasting.hpp"
#include "../mwscript/scriptmanagerimp.hpp" #include "../mwscript/scriptmanagerimp.hpp"
@ -1280,6 +1281,20 @@ void LocalPlayer::setMarkLocation()
MWBase::Environment::get().getWorld()->getPlayer().markPosition(ptrCellStore, markPosition); MWBase::Environment::get().getWorld()->getPlayer().markPosition(ptrCellStore, markPosition);
} }
void LocalPlayer::setSelectedSpell()
{
MWWorld::Ptr ptrPlayer = getPlayerPtr();
MWMechanics::CreatureStats& stats = ptrPlayer.getClass().getCreatureStats(ptrPlayer);
MWMechanics::Spells& spells = stats.getSpells();
if (!spells.hasSpell(selectedSpellId))
return;
MWBase::Environment::get().getWindowManager()->setSelectedSpell(selectedSpellId,
int(MWMechanics::getSpellSuccessChance(selectedSpellId, ptrPlayer)));
}
void LocalPlayer::sendClass() void LocalPlayer::sendClass()
{ {
MWBase::World *world = MWBase::Environment::get().getWorld(); MWBase::World *world = MWBase::Environment::get().getWorld();
@ -1586,6 +1601,15 @@ void LocalPlayer::sendMarkLocation(const ESM::Cell& newMarkCell, const ESM::Posi
getNetworking()->getPlayerPacket(ID_PLAYER_MISCELLANEOUS)->Send(); getNetworking()->getPlayerPacket(ID_PLAYER_MISCELLANEOUS)->Send();
} }
void LocalPlayer::sendSelectedSpell(const std::string& newSelectedSpellId)
{
miscellaneousChangeType = mwmp::MISCELLANEOUS_CHANGE_TYPE::SELECTED_SPELL;
selectedSpellId = newSelectedSpellId;
getNetworking()->getPlayerPacket(ID_PLAYER_MISCELLANEOUS)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_MISCELLANEOUS)->Send();
}
void LocalPlayer::clearCellStates() void LocalPlayer::clearCellStates()
{ {
cellStateChanges.cellStates.clear(); cellStateChanges.cellStates.clear();

@ -71,6 +71,7 @@ namespace mwmp
void setMapExplored(); void setMapExplored();
void setShapeshift(); void setShapeshift();
void setMarkLocation(); void setMarkLocation();
void setSelectedSpell();
void sendClass(); void sendClass();
void sendInventory(); void sendInventory();
@ -92,6 +93,7 @@ namespace mwmp
void sendScale(float newScale); void sendScale(float newScale);
void sendWerewolfState(bool isWerewolf); void sendWerewolfState(bool isWerewolf);
void sendMarkLocation(const ESM::Cell& newMarkCell, const ESM::Position& newMarkPosition); void sendMarkLocation(const ESM::Cell& newMarkCell, const ESM::Position& newMarkPosition);
void sendSelectedSpell(const std::string& newSelectedSpellId);
void clearCellStates(); void clearCellStates();
void clearCurrentContainer(); void clearCurrentContainer();

@ -26,6 +26,8 @@ namespace mwmp
if (player->miscellaneousChangeType == mwmp::MISCELLANEOUS_CHANGE_TYPE::MARK_LOCATION) if (player->miscellaneousChangeType == mwmp::MISCELLANEOUS_CHANGE_TYPE::MARK_LOCATION)
localPlayer.setMarkLocation(); localPlayer.setMarkLocation();
else if (player->miscellaneousChangeType == mwmp::MISCELLANEOUS_CHANGE_TYPE::SELECTED_SPELL)
localPlayer.setSelectedSpell();
} }
} }
}; };

@ -303,10 +303,11 @@ namespace mwmp
ESM::Cell markCell; ESM::Cell markCell;
ESM::Position markPosition; ESM::Position markPosition;
std::string selectedSpellId;
bool diedSinceArrestAttempt;
bool isReceivingQuickKeys; bool isReceivingQuickKeys;
bool isPlayingAnimation; bool isPlayingAnimation;
bool diedSinceArrestAttempt;
}; };
} }

@ -23,4 +23,6 @@ void PacketPlayerMiscellaneous::Packet(RakNet::BitStream *bs, bool send)
RW(player->markPosition.rot[0], send); RW(player->markPosition.rot[0], send);
RW(player->markPosition.rot[2], send); RW(player->markPosition.rot[2], send);
} }
else if (player->miscellaneousChangeType == mwmp::MISCELLANEOUS_CHANGE_TYPE::SELECTED_SPELL)
RW(player->selectedSpellId, send, 1);
} }

Loading…
Cancel
Save