mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-29 09:45:32 +00:00
[General] Send faction reputation via PlayerFaction packets
This commit is contained in:
parent
be93ec8ef6
commit
e36c0afc59
7 changed files with 99 additions and 11 deletions
|
@ -6,6 +6,9 @@
|
||||||
|
|
||||||
using namespace mwmp;
|
using namespace mwmp;
|
||||||
|
|
||||||
|
Faction tempFaction;
|
||||||
|
const Faction emptyFaction = {};
|
||||||
|
|
||||||
void FactionFunctions::InitializeFactionChanges(unsigned short pid) noexcept
|
void FactionFunctions::InitializeFactionChanges(unsigned short pid) noexcept
|
||||||
{
|
{
|
||||||
Player *player;
|
Player *player;
|
||||||
|
@ -57,6 +60,14 @@ bool FactionFunctions::GetFactionExpelledState(unsigned short pid, unsigned int
|
||||||
return player->factionChanges.factions.at(i).isExpelled;
|
return player->factionChanges.factions.at(i).isExpelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int FactionFunctions::GetFactionReputation(unsigned short pid, unsigned int i) noexcept
|
||||||
|
{
|
||||||
|
Player *player;
|
||||||
|
GET_PLAYER(pid, player, 0);
|
||||||
|
|
||||||
|
return player->factionChanges.factions.at(i).reputation;
|
||||||
|
}
|
||||||
|
|
||||||
void FactionFunctions::SetFactionChangesAction(unsigned short pid, unsigned char action) noexcept
|
void FactionFunctions::SetFactionChangesAction(unsigned short pid, unsigned char action) noexcept
|
||||||
{
|
{
|
||||||
Player *player;
|
Player *player;
|
||||||
|
@ -65,17 +76,34 @@ void FactionFunctions::SetFactionChangesAction(unsigned short pid, unsigned char
|
||||||
player->factionChanges.action = action;
|
player->factionChanges.action = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FactionFunctions::AddFaction(unsigned short pid, const char* factionId, unsigned int rank, bool isExpelled) noexcept
|
void FactionFunctions::SetFactionId(const char* factionId) noexcept
|
||||||
|
{
|
||||||
|
tempFaction.factionId = factionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FactionFunctions::SetFactionRank(unsigned int rank) noexcept
|
||||||
|
{
|
||||||
|
tempFaction.rank = rank;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FactionFunctions::SetFactionExpulsionState(bool isExpelled) noexcept
|
||||||
|
{
|
||||||
|
tempFaction.isExpelled = isExpelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FactionFunctions::SetFactionReputation(int reputation) noexcept
|
||||||
|
{
|
||||||
|
tempFaction.reputation = reputation;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FactionFunctions::AddFaction(unsigned short pid) noexcept
|
||||||
{
|
{
|
||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, );
|
GET_PLAYER(pid, player, );
|
||||||
|
|
||||||
mwmp::Faction faction;
|
player->factionChanges.factions.push_back(tempFaction);
|
||||||
faction.factionId = factionId;
|
|
||||||
faction.rank = rank;
|
|
||||||
faction.isExpelled = isExpelled;
|
|
||||||
|
|
||||||
player->factionChanges.factions.push_back(faction);
|
tempFaction = emptyFaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FactionFunctions::SendFactionChanges(unsigned short pid, bool toOthers) noexcept
|
void FactionFunctions::SendFactionChanges(unsigned short pid, bool toOthers) noexcept
|
||||||
|
|
|
@ -10,8 +10,14 @@
|
||||||
{"GetFactionId", FactionFunctions::GetFactionId},\
|
{"GetFactionId", FactionFunctions::GetFactionId},\
|
||||||
{"GetFactionRank", FactionFunctions::GetFactionRank},\
|
{"GetFactionRank", FactionFunctions::GetFactionRank},\
|
||||||
{"GetFactionExpelledState", FactionFunctions::GetFactionExpelledState},\
|
{"GetFactionExpelledState", FactionFunctions::GetFactionExpelledState},\
|
||||||
|
{"GetFactionReputation", FactionFunctions::GetFactionReputation},\
|
||||||
\
|
\
|
||||||
{"SetFactionChangesAction", FactionFunctions::SetFactionChangesAction},\
|
{"SetFactionChangesAction", FactionFunctions::SetFactionChangesAction},\
|
||||||
|
{"SetFactionId", FactionFunctions::SetFactionId},\
|
||||||
|
{"SetFactionRank", FactionFunctions::SetFactionRank},\
|
||||||
|
{"SetFactionExpulsionState", FactionFunctions::SetFactionExpulsionState},\
|
||||||
|
{"SetFactionReputation", FactionFunctions::SetFactionReputation},\
|
||||||
|
\
|
||||||
{"AddFaction", FactionFunctions::AddFaction},\
|
{"AddFaction", FactionFunctions::AddFaction},\
|
||||||
\
|
\
|
||||||
{"SendFactionChanges", FactionFunctions::SendFactionChanges}
|
{"SendFactionChanges", FactionFunctions::SendFactionChanges}
|
||||||
|
@ -28,9 +34,15 @@ public:
|
||||||
static const char *GetFactionId(unsigned short pid, unsigned int i) noexcept;
|
static const char *GetFactionId(unsigned short pid, unsigned int i) noexcept;
|
||||||
static int GetFactionRank(unsigned short pid, unsigned int i) noexcept;
|
static int GetFactionRank(unsigned short pid, unsigned int i) noexcept;
|
||||||
static bool GetFactionExpelledState(unsigned short pid, unsigned int i) noexcept;
|
static bool GetFactionExpelledState(unsigned short pid, unsigned int i) noexcept;
|
||||||
|
static int GetFactionReputation(unsigned short pid, unsigned int i) noexcept;
|
||||||
|
|
||||||
static void SetFactionChangesAction(unsigned short pid, unsigned char action) noexcept;
|
static void SetFactionChangesAction(unsigned short pid, unsigned char action) noexcept;
|
||||||
static void AddFaction(unsigned short pid, const char* factionId, unsigned int rank, bool isExpelled) noexcept;
|
static void SetFactionId(const char* factionId) noexcept;
|
||||||
|
static void SetFactionRank(unsigned int rank) noexcept;
|
||||||
|
static void SetFactionExpulsionState(bool isExpelled) noexcept;
|
||||||
|
static void SetFactionReputation(int reputation) noexcept;
|
||||||
|
|
||||||
|
static void AddFaction(unsigned short pid) noexcept;
|
||||||
|
|
||||||
static void SendFactionChanges(unsigned short pid, bool toOthers = false) noexcept;
|
static void SendFactionChanges(unsigned short pid, bool toOthers = false) noexcept;
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -982,6 +982,9 @@ void LocalPlayer::setFactions()
|
||||||
ptrNpcStats.clearExpelled(faction.factionId);
|
ptrNpcStats.clearExpelled(faction.factionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (factionChanges.action == mwmp::FactionChanges::REPUTATION)
|
||||||
|
ptrNpcStats.setFactionReputation(faction.factionId, faction.reputation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1189,6 +1192,21 @@ void LocalPlayer::sendFactionExpulsionState(const std::string& factionId, bool i
|
||||||
getNetworking()->getPlayerPacket(ID_PLAYER_FACTION)->Send();
|
getNetworking()->getPlayerPacket(ID_PLAYER_FACTION)->Send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LocalPlayer::sendFactionReputation(const std::string& factionId, int reputation)
|
||||||
|
{
|
||||||
|
factionChanges.factions.clear();
|
||||||
|
factionChanges.action = FactionChanges::REPUTATION;
|
||||||
|
|
||||||
|
mwmp::Faction faction;
|
||||||
|
faction.factionId = factionId;
|
||||||
|
faction.reputation = reputation;
|
||||||
|
|
||||||
|
factionChanges.factions.push_back(faction);
|
||||||
|
|
||||||
|
getNetworking()->getPlayerPacket(ID_PLAYER_FACTION)->setPlayer(this);
|
||||||
|
getNetworking()->getPlayerPacket(ID_PLAYER_FACTION)->Send();
|
||||||
|
}
|
||||||
|
|
||||||
void LocalPlayer::sendTopic(const std::string& topicId)
|
void LocalPlayer::sendTopic(const std::string& topicId)
|
||||||
{
|
{
|
||||||
topicChanges.topics.clear();
|
topicChanges.topics.clear();
|
||||||
|
|
|
@ -75,6 +75,7 @@ namespace mwmp
|
||||||
void sendJournalIndex(const std::string& quest, int index);
|
void sendJournalIndex(const std::string& quest, int index);
|
||||||
void sendFactionRank(const std::string& factionId, int rank);
|
void sendFactionRank(const std::string& factionId, int rank);
|
||||||
void sendFactionExpulsionState(const std::string& factionId, bool isExpelled);
|
void sendFactionExpulsionState(const std::string& factionId, bool isExpelled);
|
||||||
|
void sendFactionReputation(const std::string& factionId, int reputation);
|
||||||
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);
|
||||||
|
|
|
@ -609,7 +609,8 @@ 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()->sendFactionRank(factionID, player.getClass().getNpcStats(player).getFactionRanks().at(factionID));
|
int newRank = player.getClass().getNpcStats(player).getFactionRanks().at(factionID);
|
||||||
|
mwmp::Main::get().getLocalPlayer()->sendFactionRank(factionID, newRank);
|
||||||
/*
|
/*
|
||||||
End of tes3mp addition
|
End of tes3mp addition
|
||||||
*/
|
*/
|
||||||
|
@ -658,7 +659,8 @@ 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()->sendFactionRank(factionID, player.getClass().getNpcStats(player).getFactionRanks().at(factionID));
|
int newRank = player.getClass().getNpcStats(player).getFactionRanks().at(factionID);
|
||||||
|
mwmp::Main::get().getLocalPlayer()->sendFactionRank(factionID, newRank);
|
||||||
/*
|
/*
|
||||||
End of tes3mp addition
|
End of tes3mp addition
|
||||||
*/
|
*/
|
||||||
|
@ -700,7 +702,8 @@ 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()->sendFactionRank(factionID, player.getClass().getNpcStats(player).getFactionRanks().at(factionID));
|
int newRank = player.getClass().getNpcStats(player).getFactionRanks().at(factionID);
|
||||||
|
mwmp::Main::get().getLocalPlayer()->sendFactionRank(factionID, newRank);
|
||||||
/*
|
/*
|
||||||
End of tes3mp addition
|
End of tes3mp addition
|
||||||
*/
|
*/
|
||||||
|
@ -877,6 +880,16 @@ namespace MWScript
|
||||||
|
|
||||||
MWWorld::Ptr player = MWMechanics::getPlayer();
|
MWWorld::Ptr player = MWMechanics::getPlayer();
|
||||||
player.getClass().getNpcStats (player).setFactionReputation (factionId, value);
|
player.getClass().getNpcStats (player).setFactionReputation (factionId, value);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Start of tes3mp addition
|
||||||
|
|
||||||
|
Send an ID_PLAYER_FACTION packet every time a player's faction reputation changes
|
||||||
|
*/
|
||||||
|
mwmp::Main::get().getLocalPlayer()->sendFactionReputation(Misc::StringUtils::lowerCase(factionId), value);
|
||||||
|
/*
|
||||||
|
End of tes3mp addition
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -913,6 +926,17 @@ namespace MWScript
|
||||||
player.getClass().getNpcStats (player).setFactionReputation (factionId,
|
player.getClass().getNpcStats (player).setFactionReputation (factionId,
|
||||||
player.getClass().getNpcStats (player).getFactionReputation (factionId)+
|
player.getClass().getNpcStats (player).getFactionReputation (factionId)+
|
||||||
value);
|
value);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Start of tes3mp addition
|
||||||
|
|
||||||
|
Send an ID_PLAYER_FACTION packet every time a player's faction reputation changes
|
||||||
|
*/
|
||||||
|
int newReputation = player.getClass().getNpcStats(player).getFactionReputation(factionId);
|
||||||
|
mwmp::Main::get().getLocalPlayer()->sendFactionReputation(Misc::StringUtils::lowerCase(factionId), newReputation);
|
||||||
|
/*
|
||||||
|
End of tes3mp addition
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ namespace mwmp
|
||||||
{
|
{
|
||||||
std::string factionId;
|
std::string factionId;
|
||||||
int rank;
|
int rank;
|
||||||
|
int reputation;
|
||||||
bool isExpelled;
|
bool isExpelled;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -91,7 +92,8 @@ namespace mwmp
|
||||||
enum FACTION_ACTION
|
enum FACTION_ACTION
|
||||||
{
|
{
|
||||||
RANK = 0,
|
RANK = 0,
|
||||||
EXPULSION = 1
|
EXPULSION = 1,
|
||||||
|
REPUTATION = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
int action; // 0 - Rank, 1 - Expulsion state, 2 - Both
|
int action; // 0 - Rank, 1 - Expulsion state, 2 - Both
|
||||||
|
|
|
@ -37,6 +37,9 @@ void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send)
|
||||||
if (player->factionChanges.action == FactionChanges::EXPULSION)
|
if (player->factionChanges.action == FactionChanges::EXPULSION)
|
||||||
RW(faction.isExpelled, send);
|
RW(faction.isExpelled, send);
|
||||||
|
|
||||||
|
if (player->factionChanges.action == FactionChanges::REPUTATION)
|
||||||
|
RW(faction.reputation, send);
|
||||||
|
|
||||||
if (!send)
|
if (!send)
|
||||||
player->factionChanges.factions.push_back(faction);
|
player->factionChanges.factions.push_back(faction);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue