1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-03 15:19:42 +00:00

[General] Add RANK, EXPULSION and BOTH actions to PlayerFaction packets

This commit is contained in:
David Cernat 2017-07-05 07:05:52 +03:00
parent 940ae5c2fb
commit 1d504a665f
9 changed files with 72 additions and 24 deletions

View file

@ -14,6 +14,14 @@ unsigned int FactionFunctions::GetFactionChangesSize(unsigned short pid) noexcep
return player->factionChanges.count; return player->factionChanges.count;
} }
unsigned char FactionFunctions::GetFactionChangesAction(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0);
return player->factionChanges.action;
}
void FactionFunctions::AddFaction(unsigned short pid, const char* factionId, unsigned int rank, bool isExpelled) noexcept void FactionFunctions::AddFaction(unsigned short pid, const char* factionId, unsigned int rank, bool isExpelled) noexcept
{ {
Player *player; Player *player;
@ -59,6 +67,8 @@ void FactionFunctions::SendFactionChanges(unsigned short pid) noexcept
Player *player; Player *player;
GET_PLAYER(pid, player, ); GET_PLAYER(pid, player, );
player->factionChangesBuffer.action = mwmp::FactionChanges::BOTH;
std::swap(player->factionChanges, player->factionChangesBuffer); std::swap(player->factionChanges, player->factionChangesBuffer);
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_FACTION)->setPlayer(player); mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_FACTION)->setPlayer(player);
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_FACTION)->Send(false); mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_FACTION)->Send(false);

View file

@ -3,6 +3,7 @@
#define FACTIONAPI \ #define FACTIONAPI \
{"GetFactionChangesSize", FactionFunctions::GetFactionChangesSize},\ {"GetFactionChangesSize", FactionFunctions::GetFactionChangesSize},\
{"GetFactionChangesAction", FactionFunctions::GetFactionChangesAction},\
\ \
{"AddFaction", FactionFunctions::AddFaction},\ {"AddFaction", FactionFunctions::AddFaction},\
\ \
@ -17,6 +18,7 @@ class FactionFunctions
public: public:
static unsigned int GetFactionChangesSize(unsigned short pid) noexcept; static unsigned int GetFactionChangesSize(unsigned short pid) noexcept;
static unsigned char GetFactionChangesAction(unsigned short pid) noexcept;
static void AddFaction(unsigned short pid, const char* factionId, unsigned int rank, bool isExpelled) noexcept; static void AddFaction(unsigned short pid, const char* factionId, unsigned int rank, bool isExpelled) noexcept;

View file

@ -7,7 +7,6 @@
*/ */
#include "../mwmp/Main.hpp" #include "../mwmp/Main.hpp"
#include "../mwmp/LocalPlayer.hpp" #include "../mwmp/LocalPlayer.hpp"
#include <regex>
/* /*
End of tes3mp addition End of tes3mp addition
*/ */

View file

@ -1252,7 +1252,7 @@ namespace MWMechanics
Send an ID_PLAYER_FACTION packet every time a player is expelled from a faction Send an ID_PLAYER_FACTION packet every time a player is expelled from a faction
*/ */
mwmp::Main::get().getLocalPlayer()->sendFaction(Misc::StringUtils::lowerCase(factionID), playerRanks.at(Misc::StringUtils::lowerCase(factionID)), true); mwmp::Main::get().getLocalPlayer()->sendFactionExpulsionState(Misc::StringUtils::lowerCase(factionID), true);
/* /*
End of tes3mp addition End of tes3mp addition
*/ */

View file

@ -955,24 +955,30 @@ void LocalPlayer::setFactions()
if (!ptrNpcStats.isInFaction(faction.factionId)) if (!ptrNpcStats.isInFaction(faction.factionId))
ptrNpcStats.joinFaction(faction.factionId); ptrNpcStats.joinFaction(faction.factionId);
// While the faction rank is different in the packet than in the NpcStats, if (factionChanges.action == mwmp::FactionChanges::RANK || factionChanges.action == mwmp::FactionChanges::BOTH)
// adjust the NpcStats accordingly
while (faction.rank != ptrNpcStats.getFactionRanks().at(faction.factionId))
{ {
if (faction.rank > ptrNpcStats.getFactionRanks().at(faction.factionId)) // While the faction rank is different in the packet than in the NpcStats,
ptrNpcStats.raiseRank(faction.factionId); // adjust the NpcStats accordingly
else while (faction.rank != ptrNpcStats.getFactionRanks().at(faction.factionId))
ptrNpcStats.lowerRank(faction.factionId); {
if (faction.rank > ptrNpcStats.getFactionRanks().at(faction.factionId))
ptrNpcStats.raiseRank(faction.factionId);
else
ptrNpcStats.lowerRank(faction.factionId);
}
} }
// If the expelled state is different in the packet than in the NpcStats, if (factionChanges.action == mwmp::FactionChanges::EXPULSION || factionChanges.action == mwmp::FactionChanges::BOTH)
// adjust the NpcStats accordingly
if (faction.isExpelled != ptrNpcStats.getExpelled(faction.factionId))
{ {
if (faction.isExpelled) // If the expelled state is different in the packet than in the NpcStats,
ptrNpcStats.expell(faction.factionId); // adjust the NpcStats accordingly
else if (faction.isExpelled != ptrNpcStats.getExpelled(faction.factionId))
ptrNpcStats.clearExpelled(faction.factionId); {
if (faction.isExpelled)
ptrNpcStats.expell(faction.factionId);
else
ptrNpcStats.clearExpelled(faction.factionId);
}
} }
} }
} }
@ -1151,13 +1157,28 @@ void LocalPlayer::sendJournalIndex(const std::string& quest, int index)
getNetworking()->getPlayerPacket(ID_PLAYER_JOURNAL)->Send(); getNetworking()->getPlayerPacket(ID_PLAYER_JOURNAL)->Send();
} }
void LocalPlayer::sendFaction(const std::string& factionId, int rank, bool isExpelled) void LocalPlayer::sendFactionRank(const std::string& factionId, int rank)
{ {
factionChanges.factions.clear(); factionChanges.factions.clear();
factionChanges.action = FactionChanges::RANK;
mwmp::Faction faction; mwmp::Faction faction;
faction.factionId = factionId; faction.factionId = factionId;
faction.rank = rank; faction.rank = rank;
factionChanges.factions.push_back(faction);
getNetworking()->getPlayerPacket(ID_PLAYER_FACTION)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_FACTION)->Send();
}
void LocalPlayer::sendFactionExpulsionState(const std::string& factionId, bool isExpelled)
{
factionChanges.factions.clear();
factionChanges.action = FactionChanges::EXPULSION;
mwmp::Faction faction;
faction.factionId = factionId;
faction.isExpelled = isExpelled; faction.isExpelled = isExpelled;
factionChanges.factions.push_back(faction); factionChanges.factions.push_back(faction);

View file

@ -73,7 +73,8 @@ namespace mwmp
void sendSpellRemoval(const ESM::Spell &spell); void sendSpellRemoval(const ESM::Spell &spell);
void sendJournalEntry(const std::string& quest, int index, const MWWorld::Ptr& actor); void sendJournalEntry(const std::string& quest, int index, const MWWorld::Ptr& actor);
void sendJournalIndex(const std::string& quest, int index); void sendJournalIndex(const std::string& quest, int index);
void sendFaction(const std::string& factionId, int rank, bool isExpelled); void sendFactionRank(const std::string& factionId, int rank);
void sendFactionExpulsionState(const std::string& factionId, bool isExpelled);
void sendTopic(const std::string& topic); void sendTopic(const std::string& topic);
void sendKill(const std::string& refId, int number); void sendKill(const std::string& refId, int number);
void sendBook(const std::string& bookId); void sendBook(const std::string& bookId);

View file

@ -609,7 +609,7 @@ namespace MWScript
Send an ID_PLAYER_FACTION packet every time a player joins a faction Send an ID_PLAYER_FACTION packet every time a player joins a faction
*/ */
mwmp::Main::get().getLocalPlayer()->sendFaction(factionID, player.getClass().getNpcStats(player).getFactionRanks().at(factionID), false); mwmp::Main::get().getLocalPlayer()->sendFactionRank(factionID, player.getClass().getNpcStats(player).getFactionRanks().at(factionID));
/* /*
End of tes3mp addition End of tes3mp addition
*/ */
@ -658,7 +658,7 @@ namespace MWScript
Send an ID_PLAYER_FACTION packet every time a player rises in a faction Send an ID_PLAYER_FACTION packet every time a player rises in a faction
*/ */
mwmp::Main::get().getLocalPlayer()->sendFaction(factionID, player.getClass().getNpcStats(player).getFactionRanks().at(factionID), player.getClass().getNpcStats(player).getExpelled(factionID)); mwmp::Main::get().getLocalPlayer()->sendFactionRank(factionID, player.getClass().getNpcStats(player).getFactionRanks().at(factionID));
/* /*
End of tes3mp addition End of tes3mp addition
*/ */
@ -700,7 +700,7 @@ namespace MWScript
Send an ID_PLAYER_FACTION packet every time a player falls in a faction Send an ID_PLAYER_FACTION packet every time a player falls in a faction
*/ */
mwmp::Main::get().getLocalPlayer()->sendFaction(factionID, player.getClass().getNpcStats(player).getFactionRanks().at(factionID), player.getClass().getNpcStats(player).getExpelled(factionID)); mwmp::Main::get().getLocalPlayer()->sendFactionRank(factionID, player.getClass().getNpcStats(player).getFactionRanks().at(factionID));
/* /*
End of tes3mp addition End of tes3mp addition
*/ */
@ -1035,7 +1035,7 @@ namespace MWScript
Send an ID_PLAYER_FACTION packet every time a player is expelled from a faction Send an ID_PLAYER_FACTION packet every time a player is expelled from a faction
*/ */
mwmp::Main::get().getLocalPlayer()->sendFaction(Misc::StringUtils::lowerCase(factionID), player.getClass().getNpcStats(player).getFactionRanks().at(Misc::StringUtils::lowerCase(factionID)), true); mwmp::Main::get().getLocalPlayer()->sendFactionExpulsionState(Misc::StringUtils::lowerCase(factionID), true);
/* /*
End of tes3mp addition End of tes3mp addition
*/ */
@ -1072,7 +1072,7 @@ namespace MWScript
Send an ID_PLAYER_FACTION packet every time a player is no longer expelled from a faction Send an ID_PLAYER_FACTION packet every time a player is no longer expelled from a faction
*/ */
if (factionID != "") if (factionID != "")
mwmp::Main::get().getLocalPlayer()->sendFaction(Misc::StringUtils::lowerCase(factionID), player.getClass().getNpcStats(player).getFactionRanks().at(Misc::StringUtils::lowerCase(factionID)), false); mwmp::Main::get().getLocalPlayer()->sendFactionExpulsionState(Misc::StringUtils::lowerCase(factionID), false);
/* /*
End of tes3mp addition End of tes3mp addition
*/ */

View file

@ -87,6 +87,15 @@ namespace mwmp
{ {
std::vector<Faction> factions; std::vector<Faction> factions;
unsigned int count; unsigned int count;
enum FACTION_ACTION
{
RANK = 0,
EXPULSION = 1,
BOTH = 2
};
int action; // 0 - Rank, 1 - Expulsion state, 2 - Both
}; };
struct TopicChanges struct TopicChanges

View file

@ -13,6 +13,8 @@ void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send)
{ {
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
RW(player->factionChanges.action, send);
if (send) if (send)
player->factionChanges.count = (unsigned int)(player->factionChanges.factions.size()); player->factionChanges.count = (unsigned int)(player->factionChanges.factions.size());
else else
@ -28,7 +30,11 @@ void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send)
faction = player->factionChanges.factions.at(i); faction = player->factionChanges.factions.at(i);
RW(faction.factionId, send, 1); RW(faction.factionId, send, 1);
RW(faction.rank, send);
if (player->factionChanges.action == FactionChanges::BOTH || player->factionChanges.action == FactionChanges::RANK)
RW(faction.rank, send);
if (player->factionChanges.action == FactionChanges::BOTH || player->factionChanges.action == FactionChanges::EXPULSION)
RW(faction.isExpelled, send); RW(faction.isExpelled, send);
if (!send) if (!send)