1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-29 22:45:34 +00:00

[Client] Combine methods for sending spell packets into a single one

This commit is contained in:
David Cernat 2018-08-21 01:20:30 +03:00
parent 140e0ed52c
commit 45b011452e
5 changed files with 9 additions and 25 deletions

View file

@ -172,7 +172,7 @@ namespace MWGui
Send an ID_PLAYER_SPELLBOOK packet every time a player buys a spell
*/
mwmp::Main::get().getLocalPlayer()->sendSpellAddition(mSpellsWidgetMap.find(_sender)->second);
mwmp::Main::get().getLocalPlayer()->sendSpellChange(mSpellsWidgetMap.find(_sender)->second, mwmp::SpellbookChanges::ADD);
/*
End of tes3mp addition
*/

View file

@ -229,7 +229,7 @@ namespace MWGui
Send an ID_PLAYER_SPELLBOOK packet every time a player deletes one of their spells
*/
mwmp::Main::get().getLocalPlayer()->sendSpellRemoval(mSpellToDelete);
mwmp::Main::get().getLocalPlayer()->sendSpellChange(mSpellToDelete, mwmp::SpellbookChanges::REMOVE);
/*
End of tes3mp addition
*/

View file

@ -1425,9 +1425,10 @@ void LocalPlayer::sendCellStates()
getNetworking()->getPlayerPacket(ID_PLAYER_CELL_STATE)->Send();
}
void LocalPlayer::sendSpellAddition(std::string id)
void LocalPlayer::sendSpellChange(std::string id, unsigned int action)
{
if (id.find("$dynamic") != string::npos) // skip custom spells
// Skip any bugged spells that somehow have clientside-only dynamic IDs
if (id.find("$dynamic") != string::npos)
return;
spellbookChanges.spells.clear();
@ -1436,23 +1437,7 @@ void LocalPlayer::sendSpellAddition(std::string id)
spell.mId = id;
spellbookChanges.spells.push_back(spell);
spellbookChanges.action = SpellbookChanges::ADD;
getNetworking()->getPlayerPacket(ID_PLAYER_SPELLBOOK)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_SPELLBOOK)->Send();
}
void LocalPlayer::sendSpellRemoval(std::string id)
{
if (id.find("$dynamic") != string::npos) // skip custom spells
return;
spellbookChanges.spells.clear();
ESM::Spell spell;
spell.mId = id;
spellbookChanges.spells.push_back(spell);
spellbookChanges.action = SpellbookChanges::REMOVE;
spellbookChanges.action = action;
getNetworking()->getPlayerPacket(ID_PLAYER_SPELLBOOK)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_SPELLBOOK)->Send();
}

View file

@ -73,8 +73,7 @@ namespace mwmp
void sendInventory();
void sendSpellbook();
void sendCellStates();
void sendSpellAddition(std::string id);
void sendSpellRemoval(std::string id);
void sendSpellChange(std::string id, unsigned int action);
void sendQuickKey(unsigned short slot, int type, const std::string& itemId = "");
void sendJournalEntry(const std::string& quest, int index, const MWWorld::Ptr& actor);
void sendJournalIndex(const std::string& quest, int index);

View file

@ -479,7 +479,7 @@ namespace MWScript
through a script
*/
if (ptr == MWMechanics::getPlayer())
mwmp::Main::get().getLocalPlayer()->sendSpellAddition(id);
mwmp::Main::get().getLocalPlayer()->sendSpellChange(id, mwmp::SpellbookChanges::ADD);
/*
End of tes3mp addition
*/
@ -515,7 +515,7 @@ namespace MWScript
through a script
*/
if (ptr == MWMechanics::getPlayer())
mwmp::Main::get().getLocalPlayer()->sendSpellRemoval(id);
mwmp::Main::get().getLocalPlayer()->sendSpellChange(id, mwmp::SpellbookChanges::REMOVE);
/*
End of tes3mp addition
*/