forked from teamnwah/openmw-tes3coop
[General] Rework PacketPlayerFaction
This commit is contained in:
parent
29ba07fe8c
commit
7e5b929ea2
5 changed files with 36 additions and 42 deletions
|
@ -14,7 +14,6 @@ void Factions::Init(LuaState &lua)
|
|||
{
|
||||
lua.getState()->new_usertype<Factions>("Factions",
|
||||
"addFaction", &Factions::addFaction,
|
||||
"changesAction", sol::property(&Factions::getFactionChangesAction, &Factions::setFactionChangesAction),
|
||||
"getFaction", &Factions::getFaction,
|
||||
"setFaction", &Factions::setFaction,
|
||||
"clear", &Factions::clear,
|
||||
|
@ -40,20 +39,9 @@ void Factions::processUpdate()
|
|||
clear();
|
||||
}
|
||||
|
||||
mwmp::FactionChanges::Type Factions::getFactionChangesAction() const
|
||||
void Factions::addFaction(const Faction &faction)
|
||||
{
|
||||
return player->factionChanges.action;
|
||||
}
|
||||
|
||||
void Factions::setFactionChangesAction(mwmp::FactionChanges::Type action)
|
||||
{
|
||||
player->factionChanges.action = action;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
void Factions::addFaction(Faction faction)
|
||||
{
|
||||
player->factionChanges.factions.push_back(faction.faction);
|
||||
player->factionChanges.factions.emplace_back(faction.faction);
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
@ -63,7 +51,7 @@ Faction Factions::getFaction(int id) const
|
|||
return Faction(player->factionChanges.factions.at(id));
|
||||
}
|
||||
|
||||
void Factions::setFaction(int id, Faction faction)
|
||||
void Factions::setFaction(int id, const Faction &faction)
|
||||
{
|
||||
player->factionChanges.factions.at(id) = faction.faction;
|
||||
setChanged();
|
||||
|
@ -112,6 +100,7 @@ int Faction::getFactionRank() const
|
|||
|
||||
void Faction::setFactionRank(unsigned int rank)
|
||||
{
|
||||
faction.rankChanged();
|
||||
faction.rank = rank;
|
||||
}
|
||||
|
||||
|
@ -122,6 +111,7 @@ bool Faction::getFactionExpulsionState() const
|
|||
|
||||
void Faction::setFactionExpulsionState(bool expulsionState)
|
||||
{
|
||||
faction.expulsionChanged();
|
||||
faction.isExpelled = expulsionState;
|
||||
}
|
||||
|
||||
|
@ -132,5 +122,6 @@ int Faction::getFactionReputation() const
|
|||
|
||||
void Faction::setFactionReputation(int reputation)
|
||||
{
|
||||
faction.reputationChanged();
|
||||
faction.reputation = reputation;
|
||||
}
|
||||
|
|
|
@ -42,13 +42,9 @@ public:
|
|||
explicit Factions(Player *player);
|
||||
~Factions();
|
||||
|
||||
|
||||
mwmp::FactionChanges::Type getFactionChangesAction() const;
|
||||
void setFactionChangesAction(mwmp::FactionChanges::Type action);
|
||||
|
||||
void addFaction(Faction faction);
|
||||
void addFaction(const Faction &faction);
|
||||
Faction getFaction(int id) const;
|
||||
void setFaction(int id, Faction faction);
|
||||
void setFaction(int id, const Faction &faction);
|
||||
size_t size() const;
|
||||
void clear();
|
||||
|
||||
|
|
|
@ -1083,7 +1083,7 @@ void LocalPlayer::setFactions()
|
|||
if (!ptrNpcStats.isInFaction(faction.factionId))
|
||||
ptrNpcStats.joinFaction(faction.factionId);
|
||||
|
||||
if (factionChanges.action == mwmp::FactionChanges::Type::Rank)
|
||||
if (faction.isRankChanged())
|
||||
{
|
||||
// While the faction rank is different in the packet than in the NpcStats,
|
||||
// adjust the NpcStats accordingly
|
||||
|
@ -1095,7 +1095,8 @@ void LocalPlayer::setFactions()
|
|||
ptrNpcStats.lowerRank(faction.factionId);
|
||||
}
|
||||
}
|
||||
else if (factionChanges.action == mwmp::FactionChanges::Type::Expulsion)
|
||||
|
||||
if (faction.isExpulsionChanged())
|
||||
{
|
||||
// If the expelled state is different in the packet than in the NpcStats,
|
||||
// adjust the NpcStats accordingly
|
||||
|
@ -1108,7 +1109,7 @@ void LocalPlayer::setFactions()
|
|||
}
|
||||
}
|
||||
|
||||
else if (factionChanges.action == mwmp::FactionChanges::Type::Reputation)
|
||||
if (faction.isReputationChanged())
|
||||
ptrNpcStats.setFactionReputation(faction.factionId, faction.reputation);
|
||||
}
|
||||
}
|
||||
|
@ -1326,11 +1327,11 @@ void LocalPlayer::sendJournalIndex(const std::string& quest, int index)
|
|||
void LocalPlayer::sendFactionRank(const std::string& factionId, int rank)
|
||||
{
|
||||
factionChanges.factions.clear();
|
||||
factionChanges.action = FactionChanges::Type::Rank;
|
||||
|
||||
mwmp::Faction faction;
|
||||
faction.factionId = factionId;
|
||||
faction.rank = rank;
|
||||
faction.rankChanged();
|
||||
|
||||
factionChanges.factions.push_back(faction);
|
||||
|
||||
|
@ -1341,11 +1342,11 @@ void LocalPlayer::sendFactionRank(const std::string& factionId, int rank)
|
|||
void LocalPlayer::sendFactionExpulsionState(const std::string& factionId, bool isExpelled)
|
||||
{
|
||||
factionChanges.factions.clear();
|
||||
factionChanges.action = FactionChanges::Type::Expulsion;
|
||||
|
||||
mwmp::Faction faction;
|
||||
faction.factionId = factionId;
|
||||
faction.isExpelled = isExpelled;
|
||||
faction.expulsionChanged();
|
||||
|
||||
factionChanges.factions.push_back(faction);
|
||||
|
||||
|
@ -1356,11 +1357,11 @@ void LocalPlayer::sendFactionExpulsionState(const std::string& factionId, bool i
|
|||
void LocalPlayer::sendFactionReputation(const std::string& factionId, int reputation)
|
||||
{
|
||||
factionChanges.factions.clear();
|
||||
factionChanges.action = FactionChanges::Type::Reputation;
|
||||
|
||||
mwmp::Faction faction;
|
||||
faction.factionId = factionId;
|
||||
faction.reputation = reputation;
|
||||
faction.reputationChanged();
|
||||
|
||||
factionChanges.factions.push_back(faction);
|
||||
|
||||
|
|
|
@ -59,10 +59,26 @@ namespace mwmp
|
|||
|
||||
struct Faction
|
||||
{
|
||||
enum ChangesMask
|
||||
{
|
||||
Rank = 1,
|
||||
Expulsion = 2,
|
||||
Reputation = 4
|
||||
};
|
||||
|
||||
inline bool isRankChanged() const { return (changes & ChangesMask::Rank) > 0; }
|
||||
inline bool isExpulsionChanged() const { return (changes & ChangesMask::Expulsion) > 0; }
|
||||
inline bool isReputationChanged() const { return (changes & ChangesMask::Reputation) > 0; }
|
||||
inline void rankChanged() { changes |= ChangesMask::Rank; };
|
||||
inline void expulsionChanged() { changes |= ChangesMask::Expulsion; };
|
||||
inline void reputationChanged() { changes |= ChangesMask::Reputation; };
|
||||
|
||||
std::string factionId;
|
||||
int rank;
|
||||
int reputation;
|
||||
bool isExpelled;
|
||||
|
||||
uint8_t changes = 0;
|
||||
};
|
||||
|
||||
struct Topic
|
||||
|
@ -118,15 +134,6 @@ namespace mwmp
|
|||
struct FactionChanges
|
||||
{
|
||||
std::vector<Faction> factions;
|
||||
|
||||
enum class Type: uint8_t
|
||||
{
|
||||
Rank = 0,
|
||||
Expulsion,
|
||||
Reputation
|
||||
};
|
||||
|
||||
Type action;
|
||||
};
|
||||
|
||||
struct TopicChanges
|
||||
|
|
|
@ -12,9 +12,6 @@ PacketPlayerFaction::PacketPlayerFaction(RakNet::RakPeerInterface *peer) : Playe
|
|||
void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send)
|
||||
{
|
||||
PlayerPacket::Packet(bs, send);
|
||||
|
||||
RW(player->factionChanges.action, send);
|
||||
|
||||
uint32_t count;
|
||||
|
||||
if (send)
|
||||
|
@ -30,15 +27,17 @@ void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send)
|
|||
|
||||
for (auto &&faction : player->factionChanges.factions)
|
||||
{
|
||||
RW(faction.changes, send, true);
|
||||
|
||||
RW(faction.factionId, send, true);
|
||||
|
||||
if (player->factionChanges.action == FactionChanges::Type::Rank)
|
||||
if (faction.isRankChanged())
|
||||
RW(faction.rank, send);
|
||||
|
||||
if (player->factionChanges.action == FactionChanges::Type::Expulsion)
|
||||
if (faction.isExpulsionChanged())
|
||||
RW(faction.isExpelled, send);
|
||||
|
||||
if (player->factionChanges.action == FactionChanges::Type::Reputation)
|
||||
if (faction.isReputationChanged())
|
||||
RW(faction.reputation, send);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue