From cc91b32b2f50ae70d0afeea9383325b693c71210 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Thu, 20 Jul 2017 17:58:00 +0300 Subject: [PATCH] [Server] Make spell script functions consistent with others --- apps/openmw-mp/Script/Functions/Books.hpp | 2 +- apps/openmw-mp/Script/Functions/Spells.cpp | 14 ++++---------- apps/openmw-mp/Script/Functions/Spells.hpp | 22 ++++++++-------------- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Books.hpp b/apps/openmw-mp/Script/Functions/Books.hpp index 9fb2672ff..3c1b7e89d 100644 --- a/apps/openmw-mp/Script/Functions/Books.hpp +++ b/apps/openmw-mp/Script/Functions/Books.hpp @@ -38,7 +38,7 @@ public: * \brief Add a new book to the book changes for a player. * * \param pid The player ID whose book changes should be used. - * \param topicId The bookId of the book. + * \param bookId The bookId of the book. * \return void */ static void AddBook(unsigned short pid, const char* bookId) noexcept; diff --git a/apps/openmw-mp/Script/Functions/Spells.cpp b/apps/openmw-mp/Script/Functions/Spells.cpp index 248a44195..2375fe591 100644 --- a/apps/openmw-mp/Script/Functions/Spells.cpp +++ b/apps/openmw-mp/Script/Functions/Spells.cpp @@ -12,7 +12,6 @@ void SpellFunctions::InitializeSpellbookChanges(unsigned short pid) noexcept GET_PLAYER(pid, player, ); player->spellbookChanges.spells.clear(); - player->spellbookChanges.action = SpellbookChanges::SET; } unsigned int SpellFunctions::GetSpellbookChangesSize(unsigned short pid) noexcept @@ -23,7 +22,7 @@ unsigned int SpellFunctions::GetSpellbookChangesSize(unsigned short pid) noexcep return player->spellbookChanges.count; } -unsigned int SpellFunctions::GetSpellbookAction(unsigned short pid) noexcept +unsigned int SpellFunctions::GetSpellbookChangesAction(unsigned short pid) noexcept { Player *player; GET_PLAYER(pid, player, 0); @@ -31,19 +30,15 @@ unsigned int SpellFunctions::GetSpellbookAction(unsigned short pid) noexcept return player->spellbookChanges.action; } -void SpellFunctions::AddSpell(unsigned short pid, const char* spellId) noexcept +void SpellFunctions::SetSpellbookChangesAction(unsigned short pid, unsigned char action) noexcept { Player *player; GET_PLAYER(pid, player, ); - ESM::Spell spell; - spell.mId = spellId; - - player->spellbookChanges.spells.push_back(spell); - player->spellbookChanges.action = SpellbookChanges::ADD; + player->spellbookChanges.action = action; } -void SpellFunctions::RemoveSpell(unsigned short pid, const char* spellId) noexcept +void SpellFunctions::AddSpell(unsigned short pid, const char* spellId) noexcept { Player *player; GET_PLAYER(pid, player, ); @@ -52,7 +47,6 @@ void SpellFunctions::RemoveSpell(unsigned short pid, const char* spellId) noexce spell.mId = spellId; player->spellbookChanges.spells.push_back(spell); - player->spellbookChanges.action = SpellbookChanges::REMOVE; } const char *SpellFunctions::GetSpellId(unsigned short pid, unsigned int i) noexcept diff --git a/apps/openmw-mp/Script/Functions/Spells.hpp b/apps/openmw-mp/Script/Functions/Spells.hpp index 1ce9c5a5a..bf3e1d307 100644 --- a/apps/openmw-mp/Script/Functions/Spells.hpp +++ b/apps/openmw-mp/Script/Functions/Spells.hpp @@ -5,10 +5,10 @@ {"InitializeSpellbookChanges", SpellFunctions::InitializeSpellbookChanges},\ \ {"GetSpellbookChangesSize", SpellFunctions::GetSpellbookChangesSize},\ - {"GetSpellbookAction", SpellFunctions::GetSpellbookAction},\ + {"GetSpellbookChangesAction", SpellFunctions::GetSpellbookChangesAction},\ \ + {"SetSpellbookChangesAction", SpellFunctions::SetSpellbookChangesAction},\ {"AddSpell", SpellFunctions::AddSpell},\ - {"RemoveSpell", SpellFunctions::RemoveSpell},\ \ {"GetSpellId", SpellFunctions::GetSpellId},\ \ @@ -42,31 +42,25 @@ public: * \param pid The player ID whose faction changes should be used. * \return The action type (0 for SET, 1 for ADD, 2 for REMOVE). */ - static unsigned int GetSpellbookAction(unsigned short pid) noexcept; + static unsigned int GetSpellbookChangesAction(unsigned short pid) noexcept; /** - * \brief Prepare the addition of a spell to a player. - * - * In practice, this changes the action type of the PlayerSpellbook packet to - * ADD and adds this spell to it. + * \brief Set the action type in a player's spellbook changes. * * \param pid The player ID whose spellbook changes should be used. - * \param topicId The spellId of the spell. + * \param action The action (0 for SET, 1 for ADD, 2 for REMOVE). * \return void */ - static void AddSpell(unsigned short pid, const char* spellId) noexcept; + static void SetSpellbookChangesAction(unsigned short pid, unsigned char action) noexcept; /** - * \brief Prepare the removal of a spell from a player. - * - * In practice, this changes the action type of the PlayerSpellbook packet to - * REMOVE and adds this spell to it. + * \brief Add a new spell to the spellbook changes for a player. * * \param pid The player ID whose spellbook changes should be used. * \param topicId The spellId of the spell. * \return void */ - static void RemoveSpell(unsigned short pid, const char* spellId) noexcept; + static void AddSpell(unsigned short pid, const char* spellId) noexcept; /** * \brief Get the spellId at a certain index in a player's latest spellbook changes.