[General] Implement sending and reading of PlayerFaction packets

0.6.1
David Cernat 8 years ago
parent 04c9c5ed48
commit e6983993c2

@ -18,6 +18,8 @@ namespace mwmp
{ {
DEBUG_PRINTF(strPacketID.c_str()); DEBUG_PRINTF(strPacketID.c_str());
packet.Send(true);
Script::Call<Script::CallbackIdentity("OnPlayerFaction")>(player.getId()); Script::Call<Script::CallbackIdentity("OnPlayerFaction")>(player.getId());
} }
}; };

@ -107,9 +107,9 @@ add_openmw_dir (mwmp\\processors\\actor ProcessorActorAnimFlags ProcessorActorAn
) )
add_openmw_dir (mwmp\\processors\\player ProcessorChatMessage ProcessorGameConsole ProcessorGameTime ProcessorGUIMessageBox add_openmw_dir (mwmp\\processors\\player ProcessorChatMessage ProcessorGameConsole ProcessorGameTime ProcessorGUIMessageBox
ProcessorHandshake ProcessorUserDisconnected ProcessorUserMyID ProcessorPlayerBaseInfo ProcessorHandshake ProcessorUserDisconnected ProcessorUserMyID ProcessorPlayerBaseInfo ProcessorPlayerAnimFlags
ProcessorPlayerAnimFlags ProcessorPlayerAttack ProcessorPlayerAttribute ProcessorPlayerBounty ProcessorPlayerCellChange ProcessorPlayerAttack ProcessorPlayerAttribute ProcessorPlayerBounty ProcessorPlayerCellChange ProcessorPlayerCellState
ProcessorPlayerCellState ProcessorPlayerCharClass ProcessorPlayerCharGen ProcessorPlayerDeath ProcessorPlayerEquipment ProcessorPlayerCharClass ProcessorPlayerCharGen ProcessorPlayerDeath ProcessorPlayerEquipment ProcessorPlayerFaction
ProcessorPlayerInventory ProcessorPlayerJournal ProcessorPlayerLevel ProcessorPlayerPosition ProcessorPlayerResurrect ProcessorPlayerInventory ProcessorPlayerJournal ProcessorPlayerLevel ProcessorPlayerPosition ProcessorPlayerResurrect
ProcessorPlayerSkill ProcessorPlayerSpellbook ProcessorPlayerStatsDynamic ProcessorPlayerSkill ProcessorPlayerSpellbook ProcessorPlayerStatsDynamic
) )

@ -568,7 +568,6 @@ void LocalPlayer::updateAnimFlags(bool forceUpdate)
MWBase::World *world = MWBase::Environment::get().getWorld(); MWBase::World *world = MWBase::Environment::get().getWorld();
MWWorld::Ptr player = world->getPlayerPtr(); MWWorld::Ptr player = world->getPlayerPtr();
MWMechanics::NpcStats ptrNpcStats = player.getClass().getNpcStats(player); MWMechanics::NpcStats ptrNpcStats = player.getClass().getNpcStats(player);
using namespace MWMechanics; using namespace MWMechanics;
@ -962,6 +961,41 @@ void LocalPlayer::setSpellbook()
addSpells(); addSpells();
} }
void LocalPlayer::setFactions()
{
MWWorld::Ptr player = getPlayerPtr();
MWMechanics::NpcStats &ptrNpcStats = player.getClass().getNpcStats(player);
for (unsigned int i = 0; i < factionChanges.count; i++)
{
mwmp::Faction faction = factionChanges.factions.at(i);
// If the player isn't in this faction, make them join it
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 (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 (faction.isExpelled)
ptrNpcStats.expell(faction.factionId);
else
ptrNpcStats.clearExpelled(faction.factionId);
}
}
}
void LocalPlayer::sendClass() void LocalPlayer::sendClass()
{ {
MWBase::World *world = MWBase::Environment::get().getWorld(); MWBase::World *world = MWBase::Environment::get().getWorld();
@ -1117,6 +1151,21 @@ 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)
{
factionChanges.factions.clear();
mwmp::Faction faction;
faction.factionId = factionId;
faction.rank = rank;
faction.isExpelled = isExpelled;
factionChanges.factions.push_back(faction);
getNetworking()->getPlayerPacket(ID_PLAYER_FACTION)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_FACTION)->Send();
}
void LocalPlayer::clearCellStates() void LocalPlayer::clearCellStates()
{ {
cellStateChanges.cellStates.clear(); cellStateChanges.cellStates.clear();

@ -57,6 +57,7 @@ namespace mwmp
void setEquipment(); void setEquipment();
void setInventory(); void setInventory();
void setSpellbook(); void setSpellbook();
void setFactions();
void sendClass(); void sendClass();
void sendInventory(); void sendInventory();
@ -66,8 +67,9 @@ namespace mwmp
void sendSpellAddition(const ESM::Spell &spell); void sendSpellAddition(const ESM::Spell &spell);
void sendSpellRemoval(std::string id); void sendSpellRemoval(std::string id);
void sendSpellRemoval(const ESM::Spell &spell); void sendSpellRemoval(const ESM::Spell &spell);
void sendJournalEntry(const std::string& id, int index, const MWWorld::Ptr& actor); void sendJournalEntry(const std::string& quest, int index, const MWWorld::Ptr& actor);
void sendJournalIndex(const std::string& id, int index); void sendJournalIndex(const std::string& quest, int index);
void sendFaction(const std::string& factionId, int rank, bool isExpelled);
void clearCellStates(); void clearCellStates();
void clearCurrentContainer(); void clearCurrentContainer();

@ -16,7 +16,12 @@ namespace mwmp
virtual void Do(PlayerPacket &packet, BasePlayer *player) virtual void Do(PlayerPacket &packet, BasePlayer *player)
{ {
if (!isLocal()) return; if (isRequest())
{
// Entire faction membership cannot currently be requested from players
}
else
static_cast<LocalPlayer*>(player)->setFactions();
} }
}; };
} }

@ -3,8 +3,16 @@
#include <iostream> #include <iostream>
#include <cmath> #include <cmath>
/*
Start of tes3mp addition
Include additional headers for multiplayer purposes
*/
#include "../mwmp/Main.hpp" #include "../mwmp/Main.hpp"
#include "../mwmp/LocalPlayer.hpp" #include "../mwmp/LocalPlayer.hpp"
/*
End of tes3mp addition
*/
#include <components/esm/loadnpc.hpp> #include <components/esm/loadnpc.hpp>
@ -595,6 +603,16 @@ namespace MWScript
{ {
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
player.getClass().getNpcStats(player).joinFaction(factionID); player.getClass().getNpcStats(player).joinFaction(factionID);
/*
Start of tes3mp addition
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);
/*
End of tes3mp addition
*/
} }
} }
}; };
@ -634,6 +652,16 @@ namespace MWScript
{ {
player.getClass().getNpcStats(player).raiseRank(factionID); player.getClass().getNpcStats(player).raiseRank(factionID);
} }
/*
Start of tes3mp addition
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));
/*
End of tes3mp addition
*/
} }
} }
}; };
@ -666,6 +694,16 @@ namespace MWScript
{ {
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
player.getClass().getNpcStats(player).lowerRank(factionID); player.getClass().getNpcStats(player).lowerRank(factionID);
/*
Start of tes3mp addition
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));
/*
End of tes3mp addition
*/
} }
} }
}; };
@ -991,6 +1029,16 @@ namespace MWScript
if(factionID!="") if(factionID!="")
{ {
player.getClass().getNpcStats(player).expell(factionID); player.getClass().getNpcStats(player).expell(factionID);
/*
Start of tes3mp addition
Send an ID_PLAYER_FACTION packet every time a player is expelled from a faction
*/
mwmp::Main::get().getLocalPlayer()->sendFaction(factionID, player.getClass().getNpcStats(player).getFactionRanks().at(factionID), true);
/*
End of tes3mp addition
*/
} }
} }
}; };
@ -1017,6 +1065,17 @@ namespace MWScript
MWWorld::Ptr player = MWMechanics::getPlayer(); MWWorld::Ptr player = MWMechanics::getPlayer();
if(factionID!="") if(factionID!="")
player.getClass().getNpcStats(player).clearExpelled(factionID); player.getClass().getNpcStats(player).clearExpelled(factionID);
/*
Start of tes3mp addition
Send an ID_PLAYER_FACTION packet every time a player is no longer expelled from a faction
*/
if (factionID != "")
mwmp::Main::get().getLocalPlayer()->sendFaction(factionID, player.getClass().getNpcStats(player).getFactionRanks().at(factionID), false);
/*
End of tes3mp addition
*/
} }
}; };

@ -56,6 +56,13 @@ namespace mwmp
int type; // 0 - An entire entry, 1 - An index int type; // 0 - An entire entry, 1 - An index
}; };
struct Faction
{
std::string factionId;
int rank;
bool isExpelled;
};
struct CellState struct CellState
{ {
ESM::Cell cell; ESM::Cell cell;
@ -75,6 +82,12 @@ namespace mwmp
unsigned int count; unsigned int count;
}; };
struct FactionChanges
{
std::vector<Faction> factions;
unsigned int count;
};
struct InventoryChanges struct InventoryChanges
{ {
std::vector<Item> items; std::vector<Item> items;
@ -157,6 +170,7 @@ namespace mwmp
InventoryChanges inventoryChanges; InventoryChanges inventoryChanges;
SpellbookChanges spellbookChanges; SpellbookChanges spellbookChanges;
JournalChanges journalChanges; JournalChanges journalChanges;
FactionChanges factionChanges;
CellStateChanges cellStateChanges; CellStateChanges cellStateChanges;
ESM::ActiveSpells activeSpells; ESM::ActiveSpells activeSpells;
CurrentContainer currentContainer; CurrentContainer currentContainer;

@ -12,4 +12,26 @@ PacketPlayerFaction::PacketPlayerFaction(RakNet::RakPeerInterface *peer) : Playe
void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send) void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send)
{ {
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
if (!send)
player->factionChanges.factions.clear();
else
player->factionChanges.count = (unsigned int)(player->factionChanges.factions.size());
RW(player->factionChanges.count, send);
for (unsigned int i = 0; i < player->factionChanges.count; i++)
{
Faction faction;
if (send)
faction = player->factionChanges.factions.at(i);
RW(faction.factionId, send);
RW(faction.rank, send);
RW(faction.isExpelled, send);
if (!send)
player->factionChanges.factions.push_back(faction);
}
} }

Loading…
Cancel
Save