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

0.6.1
David Cernat 8 years ago
parent 940ae5c2fb
commit 1d504a665f

@ -14,6 +14,14 @@ unsigned int FactionFunctions::GetFactionChangesSize(unsigned short pid) noexcep
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
{
Player *player;
@ -59,6 +67,8 @@ void FactionFunctions::SendFactionChanges(unsigned short pid) noexcept
Player *player;
GET_PLAYER(pid, player, );
player->factionChangesBuffer.action = mwmp::FactionChanges::BOTH;
std::swap(player->factionChanges, player->factionChangesBuffer);
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_FACTION)->setPlayer(player);
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_FACTION)->Send(false);

@ -3,6 +3,7 @@
#define FACTIONAPI \
{"GetFactionChangesSize", FactionFunctions::GetFactionChangesSize},\
{"GetFactionChangesAction", FactionFunctions::GetFactionChangesAction},\
\
{"AddFaction", FactionFunctions::AddFaction},\
\
@ -17,6 +18,7 @@ class FactionFunctions
public:
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;

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

@ -1252,7 +1252,7 @@ namespace MWMechanics
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
*/

@ -955,24 +955,30 @@ void LocalPlayer::setFactions()
if (!ptrNpcStats.isInFaction(faction.factionId))
ptrNpcStats.joinFaction(faction.factionId);
// While the faction rank is different in the packet than in the NpcStats,
// adjust the NpcStats accordingly
while (faction.rank != ptrNpcStats.getFactionRanks().at(faction.factionId))
if (factionChanges.action == mwmp::FactionChanges::RANK || factionChanges.action == mwmp::FactionChanges::BOTH)
{
if (faction.rank > ptrNpcStats.getFactionRanks().at(faction.factionId))
ptrNpcStats.raiseRank(faction.factionId);
else
ptrNpcStats.lowerRank(faction.factionId);
// While the faction rank is different in the packet than in the NpcStats,
// adjust the NpcStats accordingly
while (faction.rank != ptrNpcStats.getFactionRanks().at(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,
// adjust the NpcStats accordingly
if (faction.isExpelled != ptrNpcStats.getExpelled(faction.factionId))
if (factionChanges.action == mwmp::FactionChanges::EXPULSION || factionChanges.action == mwmp::FactionChanges::BOTH)
{
if (faction.isExpelled)
ptrNpcStats.expell(faction.factionId);
else
ptrNpcStats.clearExpelled(faction.factionId);
// If the expelled state is different in the packet than in the NpcStats,
// adjust the NpcStats accordingly
if (faction.isExpelled != ptrNpcStats.getExpelled(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();
}
void LocalPlayer::sendFaction(const std::string& factionId, int rank, bool isExpelled)
void LocalPlayer::sendFactionRank(const std::string& factionId, int rank)
{
factionChanges.factions.clear();
factionChanges.action = FactionChanges::RANK;
mwmp::Faction faction;
faction.factionId = factionId;
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;
factionChanges.factions.push_back(faction);

@ -73,7 +73,8 @@ namespace mwmp
void sendSpellRemoval(const ESM::Spell &spell);
void sendJournalEntry(const std::string& quest, int index, const MWWorld::Ptr& actor);
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 sendKill(const std::string& refId, int number);
void sendBook(const std::string& bookId);

@ -609,7 +609,7 @@ namespace MWScript
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
*/
@ -658,7 +658,7 @@ namespace MWScript
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
*/
@ -700,7 +700,7 @@ namespace MWScript
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
*/
@ -1035,7 +1035,7 @@ namespace MWScript
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
*/
@ -1072,7 +1072,7 @@ namespace MWScript
Send an ID_PLAYER_FACTION packet every time a player is no longer expelled from a faction
*/
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
*/

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

@ -13,6 +13,8 @@ void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
RW(player->factionChanges.action, send);
if (send)
player->factionChanges.count = (unsigned int)(player->factionChanges.factions.size());
else
@ -28,7 +30,11 @@ void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send)
faction = player->factionChanges.factions.at(i);
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);
if (!send)

Loading…
Cancel
Save