|
|
|
@ -11,7 +11,7 @@ unsigned int SpellFunctions::GetSpellbookSize(unsigned short pid) noexcept
|
|
|
|
|
Player *player;
|
|
|
|
|
GET_PLAYER(pid, player, 0);
|
|
|
|
|
|
|
|
|
|
return player->spellbook.count;
|
|
|
|
|
return player->realSpellbook.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpellFunctions::AddSpell(unsigned short pid, const char* spellId) noexcept
|
|
|
|
@ -19,8 +19,8 @@ void SpellFunctions::AddSpell(unsigned short pid, const char* spellId) noexcept
|
|
|
|
|
Player *player;
|
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
|
|
|
|
|
Spell spell;
|
|
|
|
|
spell.id = spellId;
|
|
|
|
|
ESM::Spell spell;
|
|
|
|
|
spell.mId = spellId;
|
|
|
|
|
|
|
|
|
|
player->spellbookSendBuffer.spells.push_back(spell);
|
|
|
|
|
player->spellbookSendBuffer.action = Spellbook::ADD;
|
|
|
|
@ -31,8 +31,8 @@ void SpellFunctions::RemoveSpell(unsigned short pid, const char* spellId) noexce
|
|
|
|
|
Player *player;
|
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
|
|
|
|
|
Spell spell;
|
|
|
|
|
spell.id = spellId;
|
|
|
|
|
ESM::Spell spell;
|
|
|
|
|
spell.mId = spellId;
|
|
|
|
|
|
|
|
|
|
player->spellbookSendBuffer.spells.push_back(spell);
|
|
|
|
|
player->spellbookSendBuffer.action = Spellbook::REMOVE;
|
|
|
|
@ -52,8 +52,8 @@ bool SpellFunctions::HasSpell(unsigned short pid, const char* spellId)
|
|
|
|
|
Player *player;
|
|
|
|
|
GET_PLAYER(pid, player, false);
|
|
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < player->spellbook.count; i++)
|
|
|
|
|
if (Misc::StringUtils::ciEqual(player->spellbook.spells.at(i).id, spellId))
|
|
|
|
|
for (unsigned int i = 0; i < player->realSpellbook.size(); i++)
|
|
|
|
|
if (Misc::StringUtils::ciEqual(player->realSpellbook.at(i).mId, spellId))
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
@ -63,16 +63,26 @@ const char *SpellFunctions::GetSpellId(unsigned short pid, unsigned int i) noexc
|
|
|
|
|
Player *player;
|
|
|
|
|
GET_PLAYER(pid, player, "");
|
|
|
|
|
|
|
|
|
|
if (i >= player->spellbook.count)
|
|
|
|
|
if (i >= player->realSpellbook.size())
|
|
|
|
|
return "invalid";
|
|
|
|
|
|
|
|
|
|
return player->spellbook.spells.at(i).id.c_str();
|
|
|
|
|
return player->realSpellbook.at(i).mId.c_str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SpellFunctions::SendSpellbook(unsigned short pid) noexcept
|
|
|
|
|
{
|
|
|
|
|
Player *player;
|
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
|
|
|
|
|
for (auto spell : player->spellbookSendBuffer.spells)
|
|
|
|
|
{
|
|
|
|
|
if (player->spellbookSendBuffer.action == Spellbook::ADD)
|
|
|
|
|
player->realSpellbook.push_back(spell);
|
|
|
|
|
else if (player->spellbook.action == Spellbook::REMOVE)
|
|
|
|
|
player->realSpellbook.erase(remove_if(player->realSpellbook.begin(), player->realSpellbook.end(), [&spell](ESM::Spell s)->bool
|
|
|
|
|
{return spell.mId == s.mId; }), player->realSpellbook.end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::swap(player->spellbook, player->spellbookSendBuffer);
|
|
|
|
|
mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_SPELLBOOK)->Send(player, false);
|
|
|
|
|
player->spellbook = std::move(player->spellbookSendBuffer);
|
|
|
|
|