Make server script functions for spells consistent with those from items

pull/133/head
David Cernat 8 years ago
parent 6b14ca0775
commit e7675d94d4

@ -237,22 +237,7 @@ void Networking::processPlayerPacket(RakNet::Packet *packet)
DEBUG_PRINTF("ID_GAME_SPELLBOOK\n"); DEBUG_PRINTF("ID_GAME_SPELLBOOK\n");
myPacket->Read(player); myPacket->Read(player);
string str; Script::Call<Script::CallbackIdentity("OnPlayerChangeSpellbook")>(player->getId(), player->packetSpells.action);
for (auto spell : player->packetSpells.spells)
{
str += spell.mId;
if (spell.mId != player->packetSpells.spells.back().mId)
str += ";";
if (player->packetSpells.action == PacketSpells::ADD)
player->spellbook.push_back(spell);
else if (player->packetSpells.action == PacketSpells::REMOVE)
{
player->spellbook.erase(remove_if(player->spellbook.begin(), player->spellbook.end(), [&spell](ESM::Spell s)->bool
{return spell.mId == s.mId; }), player->spellbook.end());
}
}
Script::Call<Script::CallbackIdentity("OnPlayerChangeSpellbook")>(player->getId(), player->packetSpells.action, str.c_str());
break; break;
} }

@ -70,7 +70,6 @@ public:
public: public:
mwmp::PacketItems packetItemsBuffer; mwmp::PacketItems packetItemsBuffer;
mwmp::PacketSpells packetSpellsBuffer; mwmp::PacketSpells packetSpellsBuffer;
std::vector<ESM::Spell> spellbook;
private: private:
bool handshakeState; bool handshakeState;

@ -153,6 +153,7 @@ void ItemFunctions::SendItems(unsigned short pid) noexcept
{ {
Player *player; Player *player;
GET_PLAYER(pid, player, ); GET_PLAYER(pid, player, );
std::swap(player->packetItems, player->packetItemsBuffer); std::swap(player->packetItems, player->packetItemsBuffer);
mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_INVENTORY)->Send(player, false); mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_INVENTORY)->Send(player, false);
player->packetItems = std::move(player->packetItemsBuffer); player->packetItems = std::move(player->packetItemsBuffer);

@ -11,7 +11,7 @@ unsigned int SpellFunctions::GetSpellbookSize(unsigned short pid) noexcept
Player *player; Player *player;
GET_PLAYER(pid, player, 0); GET_PLAYER(pid, player, 0);
return player->spellbook.size(); return player->packetSpells.count;
} }
void SpellFunctions::AddSpell(unsigned short pid, const char* spellId) noexcept void SpellFunctions::AddSpell(unsigned short pid, const char* spellId) noexcept
@ -47,26 +47,15 @@ void SpellFunctions::ClearSpellbook(unsigned short pid) noexcept
player->packetSpellsBuffer.action = PacketSpells::UPDATE; player->packetSpellsBuffer.action = PacketSpells::UPDATE;
} }
bool SpellFunctions::HasSpell(unsigned short pid, const char* spellId)
{
Player *player;
GET_PLAYER(pid, player, false);
for (unsigned int i = 0; i < player->spellbook.size(); i++)
if (Misc::StringUtils::ciEqual(player->spellbook.at(i).mId, spellId))
return true;
return false;
}
const char *SpellFunctions::GetSpellId(unsigned short pid, unsigned int i) noexcept const char *SpellFunctions::GetSpellId(unsigned short pid, unsigned int i) noexcept
{ {
Player *player; Player *player;
GET_PLAYER(pid, player, ""); GET_PLAYER(pid, player, "");
if (i >= player->spellbook.size()) if (i >= player->packetSpells.count)
return "invalid"; return "invalid";
return player->spellbook.at(i).mId.c_str(); return player->packetSpells.spells.at(i).mId.c_str();
} }
void SpellFunctions::SendSpells(unsigned short pid) noexcept void SpellFunctions::SendSpells(unsigned short pid) noexcept
@ -74,15 +63,6 @@ void SpellFunctions::SendSpells(unsigned short pid) noexcept
Player *player; Player *player;
GET_PLAYER(pid, player, ); GET_PLAYER(pid, player, );
for (auto spell : player->packetSpellsBuffer.spells)
{
if (player->packetSpellsBuffer.action == PacketSpells::ADD)
player->spellbook.push_back(spell);
else if (player->packetSpells.action == PacketSpells::REMOVE)
player->spellbook.erase(remove_if(player->spellbook.begin(), player->spellbook.end(), [&spell](ESM::Spell s)->bool
{return spell.mId == s.mId; }), player->spellbook.end());
}
std::swap(player->packetSpells, player->packetSpellsBuffer); std::swap(player->packetSpells, player->packetSpellsBuffer);
mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_SPELLBOOK)->Send(player, false); mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_SPELLBOOK)->Send(player, false);
player->packetSpells = std::move(player->packetSpellsBuffer); player->packetSpells = std::move(player->packetSpellsBuffer);

@ -8,7 +8,6 @@
{"RemoveSpell", SpellFunctions::RemoveSpell},\ {"RemoveSpell", SpellFunctions::RemoveSpell},\
{"ClearSpellbook", SpellFunctions::ClearSpellbook},\ {"ClearSpellbook", SpellFunctions::ClearSpellbook},\
\ \
{"HasSpell", SpellFunctions::HasSpell},\
{"GetSpellId", SpellFunctions::GetSpellId},\ {"GetSpellId", SpellFunctions::GetSpellId},\
\ \
{"SendSpells", SpellFunctions::SendSpells} {"SendSpells", SpellFunctions::SendSpells}
@ -23,7 +22,6 @@ public:
static void RemoveSpell(unsigned short pid, const char* spellId) noexcept; static void RemoveSpell(unsigned short pid, const char* spellId) noexcept;
static void ClearSpellbook(unsigned short pid) noexcept; static void ClearSpellbook(unsigned short pid) noexcept;
static bool HasSpell(unsigned short pid, const char* itemName);
static const char *GetSpellId(unsigned short pid, unsigned int i) noexcept; static const char *GetSpellId(unsigned short pid, unsigned int i) noexcept;
static void SendSpells(unsigned short pid) noexcept; static void SendSpells(unsigned short pid) noexcept;

@ -110,7 +110,7 @@ public:
{"OnPlayerChangeLevel", Function<void, unsigned short>()}, {"OnPlayerChangeLevel", Function<void, unsigned short>()},
{"OnPlayerChangeEquipment", Function<void, unsigned short>()}, {"OnPlayerChangeEquipment", Function<void, unsigned short>()},
{"OnPlayerChangeInventory", Function<void, unsigned short>()}, {"OnPlayerChangeInventory", Function<void, unsigned short>()},
{"OnPlayerChangeSpellbook", Function<void, unsigned short, int, const char*>()}, {"OnPlayerChangeSpellbook", Function<void, unsigned short, int>()},
{"OnPlayerSendMessage", Function<bool, unsigned short, const char*>()}, {"OnPlayerSendMessage", Function<bool, unsigned short, const char*>()},
{"OnPlayerEndCharGen", Function<void, unsigned short>()}, {"OnPlayerEndCharGen", Function<void, unsigned short>()},
{"OnGUIAction", Function<void, unsigned short, int, const char*>()} {"OnGUIAction", Function<void, unsigned short, int, const char*>()}

Loading…
Cancel
Save