mirror of
				https://github.com/TES3MP/openmw-tes3mp.git
				synced 2025-10-31 14:56:44 +00:00 
			
		
		
		
	Make server script functions for spells consistent with those from items
This commit is contained in:
		
							parent
							
								
									6b14ca0775
								
							
						
					
					
						commit
						e7675d94d4
					
				
					 6 changed files with 6 additions and 43 deletions
				
			
		|  | @ -237,22 +237,7 @@ void Networking::processPlayerPacket(RakNet::Packet *packet) | |||
|         DEBUG_PRINTF("ID_GAME_SPELLBOOK\n"); | ||||
|         myPacket->Read(player); | ||||
| 
 | ||||
|         string str; | ||||
|         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()); | ||||
|         Script::Call<Script::CallbackIdentity("OnPlayerChangeSpellbook")>(player->getId(), player->packetSpells.action); | ||||
| 
 | ||||
|         break; | ||||
|     } | ||||
|  |  | |||
|  | @ -70,7 +70,6 @@ public: | |||
| public: | ||||
|     mwmp::PacketItems packetItemsBuffer; | ||||
|     mwmp::PacketSpells packetSpellsBuffer; | ||||
|     std::vector<ESM::Spell> spellbook; | ||||
| 
 | ||||
| private: | ||||
|     bool handshakeState; | ||||
|  |  | |||
|  | @ -153,6 +153,7 @@ void ItemFunctions::SendItems(unsigned short pid) noexcept | |||
| { | ||||
|     Player *player; | ||||
|     GET_PLAYER(pid, player, ); | ||||
| 
 | ||||
|     std::swap(player->packetItems, player->packetItemsBuffer); | ||||
|     mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_INVENTORY)->Send(player, false); | ||||
|     player->packetItems = std::move(player->packetItemsBuffer); | ||||
|  |  | |||
|  | @ -11,7 +11,7 @@ unsigned int SpellFunctions::GetSpellbookSize(unsigned short pid) noexcept | |||
|     Player *player; | ||||
|     GET_PLAYER(pid, player, 0); | ||||
| 
 | ||||
|     return player->spellbook.size(); | ||||
|     return player->packetSpells.count; | ||||
| } | ||||
| 
 | ||||
| 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; | ||||
| } | ||||
| 
 | ||||
| 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 | ||||
| { | ||||
|     Player *player; | ||||
|     GET_PLAYER(pid, player, ""); | ||||
| 
 | ||||
|     if (i >= player->spellbook.size()) | ||||
|     if (i >= player->packetSpells.count) | ||||
|         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 | ||||
|  | @ -74,15 +63,6 @@ void SpellFunctions::SendSpells(unsigned short pid) noexcept | |||
|     Player *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); | ||||
|     mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_SPELLBOOK)->Send(player, false); | ||||
|     player->packetSpells = std::move(player->packetSpellsBuffer); | ||||
|  |  | |||
|  | @ -8,7 +8,6 @@ | |||
|     {"RemoveSpell",      SpellFunctions::RemoveSpell},\ | ||||
|     {"ClearSpellbook",   SpellFunctions::ClearSpellbook},\ | ||||
|     \ | ||||
|     {"HasSpell",         SpellFunctions::HasSpell},\ | ||||
|     {"GetSpellId",       SpellFunctions::GetSpellId},\ | ||||
|     \ | ||||
|     {"SendSpells",       SpellFunctions::SendSpells} | ||||
|  | @ -23,7 +22,6 @@ public: | |||
|     static void RemoveSpell(unsigned short pid, const char* spellId) 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 void SendSpells(unsigned short pid) noexcept; | ||||
|  |  | |||
|  | @ -110,7 +110,7 @@ public: | |||
|             {"OnPlayerChangeLevel",      Function<void, unsigned short>()}, | ||||
|             {"OnPlayerChangeEquipment",  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*>()}, | ||||
|             {"OnPlayerEndCharGen",       Function<void, unsigned short>()}, | ||||
|             {"OnGUIAction",              Function<void, unsigned short, int, const char*>()} | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue