mirror of
https://github.com/TES3MP/TES3MP.git
synced 2025-10-17 10:52:26 -04:00
[General] Modernize packet style for PlayerJournal
This commit is contained in:
parent
1ab5916078
commit
4f98d67ed4
@ -13,7 +13,7 @@ void QuestFunctions::ClearJournalChanges(unsigned short pid) noexcept
|
|||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, );
|
GET_PLAYER(pid, player, );
|
||||||
|
|
||||||
player->journalChanges.journalItems.clear();
|
player->journalChanges.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int QuestFunctions::GetJournalChangesSize(unsigned short pid) noexcept
|
unsigned int QuestFunctions::GetJournalChangesSize(unsigned short pid) noexcept
|
||||||
@ -21,7 +21,7 @@ unsigned int QuestFunctions::GetJournalChangesSize(unsigned short pid) noexcept
|
|||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, 0);
|
GET_PLAYER(pid, player, 0);
|
||||||
|
|
||||||
return player->journalChanges.count;
|
return player->journalChanges.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuestFunctions::AddJournalEntry(unsigned short pid, const char* quest, unsigned int index, const char* actorRefId) noexcept
|
void QuestFunctions::AddJournalEntry(unsigned short pid, const char* quest, unsigned int index, const char* actorRefId) noexcept
|
||||||
@ -36,7 +36,7 @@ void QuestFunctions::AddJournalEntry(unsigned short pid, const char* quest, unsi
|
|||||||
journalItem.actorRefId = actorRefId;
|
journalItem.actorRefId = actorRefId;
|
||||||
journalItem.hasTimestamp = false;
|
journalItem.hasTimestamp = false;
|
||||||
|
|
||||||
player->journalChanges.journalItems.push_back(journalItem);
|
player->journalChanges.push_back(journalItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuestFunctions::AddJournalEntryWithTimestamp(unsigned short pid, const char* quest, unsigned int index, const char* actorRefId,
|
void QuestFunctions::AddJournalEntryWithTimestamp(unsigned short pid, const char* quest, unsigned int index, const char* actorRefId,
|
||||||
@ -56,7 +56,7 @@ void QuestFunctions::AddJournalEntryWithTimestamp(unsigned short pid, const char
|
|||||||
journalItem.timestamp.month = month;
|
journalItem.timestamp.month = month;
|
||||||
journalItem.timestamp.day = day;
|
journalItem.timestamp.day = day;
|
||||||
|
|
||||||
player->journalChanges.journalItems.push_back(journalItem);
|
player->journalChanges.push_back(journalItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuestFunctions::AddJournalIndex(unsigned short pid, const char* quest, unsigned int index) noexcept
|
void QuestFunctions::AddJournalIndex(unsigned short pid, const char* quest, unsigned int index) noexcept
|
||||||
@ -69,7 +69,7 @@ void QuestFunctions::AddJournalIndex(unsigned short pid, const char* quest, unsi
|
|||||||
journalItem.quest = quest;
|
journalItem.quest = quest;
|
||||||
journalItem.index = index;
|
journalItem.index = index;
|
||||||
|
|
||||||
player->journalChanges.journalItems.push_back(journalItem);
|
player->journalChanges.push_back(journalItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuestFunctions::SetReputation(unsigned short pid, int value) noexcept
|
void QuestFunctions::SetReputation(unsigned short pid, int value) noexcept
|
||||||
@ -85,10 +85,10 @@ const char *QuestFunctions::GetJournalItemQuest(unsigned short pid, unsigned int
|
|||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, "");
|
GET_PLAYER(pid, player, "");
|
||||||
|
|
||||||
if (index >= player->journalChanges.count)
|
if (index >= player->journalChanges.size())
|
||||||
return "invalid";
|
return "invalid";
|
||||||
|
|
||||||
return player->journalChanges.journalItems.at(index).quest.c_str();
|
return player->journalChanges.at(index).quest.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
int QuestFunctions::GetJournalItemIndex(unsigned short pid, unsigned int index) noexcept
|
int QuestFunctions::GetJournalItemIndex(unsigned short pid, unsigned int index) noexcept
|
||||||
@ -96,7 +96,7 @@ int QuestFunctions::GetJournalItemIndex(unsigned short pid, unsigned int index)
|
|||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, 0);
|
GET_PLAYER(pid, player, 0);
|
||||||
|
|
||||||
return player->journalChanges.journalItems.at(index).index;
|
return player->journalChanges.at(index).index;
|
||||||
}
|
}
|
||||||
|
|
||||||
int QuestFunctions::GetJournalItemType(unsigned short pid, unsigned int index) noexcept
|
int QuestFunctions::GetJournalItemType(unsigned short pid, unsigned int index) noexcept
|
||||||
@ -104,7 +104,7 @@ int QuestFunctions::GetJournalItemType(unsigned short pid, unsigned int index) n
|
|||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, 0);
|
GET_PLAYER(pid, player, 0);
|
||||||
|
|
||||||
return player->journalChanges.journalItems.at(index).type;
|
return player->journalChanges.at(index).type;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *QuestFunctions::GetJournalItemActorRefId(unsigned short pid, unsigned int index) noexcept
|
const char *QuestFunctions::GetJournalItemActorRefId(unsigned short pid, unsigned int index) noexcept
|
||||||
@ -112,7 +112,7 @@ const char *QuestFunctions::GetJournalItemActorRefId(unsigned short pid, unsigne
|
|||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, 0);
|
GET_PLAYER(pid, player, 0);
|
||||||
|
|
||||||
return player->journalChanges.journalItems.at(index).actorRefId.c_str();
|
return player->journalChanges.at(index).actorRefId.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
int QuestFunctions::GetReputation(unsigned short pid) noexcept
|
int QuestFunctions::GetReputation(unsigned short pid) noexcept
|
||||||
|
@ -732,17 +732,25 @@ void LocalPlayer::addSpells()
|
|||||||
|
|
||||||
void LocalPlayer::addJournalItems()
|
void LocalPlayer::addJournalItems()
|
||||||
{
|
{
|
||||||
for (const auto &journalItem : journalChanges.journalItems)
|
for (const auto &journalItem : journalChanges)
|
||||||
{
|
{
|
||||||
MWWorld::Ptr ptrFound;
|
MWWorld::Ptr ptrFound;
|
||||||
|
|
||||||
if (journalItem.type == JournalItem::ENTRY)
|
if (journalItem.type == JournalItem::ENTRY)
|
||||||
{
|
{
|
||||||
|
LOG_APPEND(TimedLog::LOG_VERBOSE, "- type: ENTRY, quest: %s, index: %i, actorRefId: %s",
|
||||||
|
journalItem.quest.c_str(), journalItem.index, journalItem.actorRefId.c_str());
|
||||||
|
|
||||||
ptrFound = MWBase::Environment::get().getWorld()->searchPtr(journalItem.actorRefId, false);
|
ptrFound = MWBase::Environment::get().getWorld()->searchPtr(journalItem.actorRefId, false);
|
||||||
|
|
||||||
if (!ptrFound)
|
if (!ptrFound)
|
||||||
ptrFound = getPlayerPtr();
|
ptrFound = getPlayerPtr();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG_APPEND(TimedLog::LOG_VERBOSE, "- type: INDEX, quest: %s, index: %i",
|
||||||
|
journalItem.quest.c_str(), journalItem.index);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -1504,7 +1512,7 @@ void LocalPlayer::sendQuickKey(unsigned short slot, int type, const std::string&
|
|||||||
|
|
||||||
void LocalPlayer::sendJournalEntry(const std::string& quest, int index, const MWWorld::Ptr& actor)
|
void LocalPlayer::sendJournalEntry(const std::string& quest, int index, const MWWorld::Ptr& actor)
|
||||||
{
|
{
|
||||||
journalChanges.journalItems.clear();
|
journalChanges.clear();
|
||||||
|
|
||||||
mwmp::JournalItem journalItem;
|
mwmp::JournalItem journalItem;
|
||||||
journalItem.type = JournalItem::ENTRY;
|
journalItem.type = JournalItem::ENTRY;
|
||||||
@ -1513,7 +1521,7 @@ void LocalPlayer::sendJournalEntry(const std::string& quest, int index, const MW
|
|||||||
journalItem.actorRefId = actor.getCellRef().getRefId();
|
journalItem.actorRefId = actor.getCellRef().getRefId();
|
||||||
journalItem.hasTimestamp = false;
|
journalItem.hasTimestamp = false;
|
||||||
|
|
||||||
journalChanges.journalItems.push_back(journalItem);
|
journalChanges.push_back(journalItem);
|
||||||
|
|
||||||
getNetworking()->getPlayerPacket(ID_PLAYER_JOURNAL)->setPlayer(this);
|
getNetworking()->getPlayerPacket(ID_PLAYER_JOURNAL)->setPlayer(this);
|
||||||
getNetworking()->getPlayerPacket(ID_PLAYER_JOURNAL)->Send();
|
getNetworking()->getPlayerPacket(ID_PLAYER_JOURNAL)->Send();
|
||||||
@ -1521,14 +1529,14 @@ void LocalPlayer::sendJournalEntry(const std::string& quest, int index, const MW
|
|||||||
|
|
||||||
void LocalPlayer::sendJournalIndex(const std::string& quest, int index)
|
void LocalPlayer::sendJournalIndex(const std::string& quest, int index)
|
||||||
{
|
{
|
||||||
journalChanges.journalItems.clear();
|
journalChanges.clear();
|
||||||
|
|
||||||
mwmp::JournalItem journalItem;
|
mwmp::JournalItem journalItem;
|
||||||
journalItem.type = JournalItem::INDEX;
|
journalItem.type = JournalItem::INDEX;
|
||||||
journalItem.quest = quest;
|
journalItem.quest = quest;
|
||||||
journalItem.index = index;
|
journalItem.index = index;
|
||||||
|
|
||||||
journalChanges.journalItems.push_back(journalItem);
|
journalChanges.push_back(journalItem);
|
||||||
|
|
||||||
getNetworking()->getPlayerPacket(ID_PLAYER_JOURNAL)->setPlayer(this);
|
getNetworking()->getPlayerPacket(ID_PLAYER_JOURNAL)->setPlayer(this);
|
||||||
getNetworking()->getPlayerPacket(ID_PLAYER_JOURNAL)->Send();
|
getNetworking()->getPlayerPacket(ID_PLAYER_JOURNAL)->Send();
|
||||||
|
@ -88,12 +88,6 @@ namespace mwmp
|
|||||||
int type; // 0 - Cell load, 1 - Cell unload
|
int type; // 0 - Cell load, 1 - Cell unload
|
||||||
};
|
};
|
||||||
|
|
||||||
struct JournalChanges
|
|
||||||
{
|
|
||||||
std::vector<JournalItem> journalItems;
|
|
||||||
unsigned int count;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct FactionChanges
|
struct FactionChanges
|
||||||
{
|
{
|
||||||
std::vector<Faction> factions;
|
std::vector<Faction> factions;
|
||||||
@ -245,7 +239,7 @@ namespace mwmp
|
|||||||
InventoryChanges inventoryChanges;
|
InventoryChanges inventoryChanges;
|
||||||
SpellbookChanges spellbookChanges;
|
SpellbookChanges spellbookChanges;
|
||||||
QuickKeyChanges quickKeyChanges;
|
QuickKeyChanges quickKeyChanges;
|
||||||
JournalChanges journalChanges;
|
std::vector<JournalItem> journalChanges;
|
||||||
FactionChanges factionChanges;
|
FactionChanges factionChanges;
|
||||||
TopicChanges topicChanges;
|
TopicChanges topicChanges;
|
||||||
BookChanges bookChanges;
|
BookChanges bookChanges;
|
||||||
|
@ -13,20 +13,21 @@ void PacketPlayerJournal::Packet(RakNet::BitStream *bs, bool send)
|
|||||||
{
|
{
|
||||||
PlayerPacket::Packet(bs, send);
|
PlayerPacket::Packet(bs, send);
|
||||||
|
|
||||||
|
uint32_t count;
|
||||||
|
|
||||||
if (send)
|
if (send)
|
||||||
player->journalChanges.count = (unsigned int)(player->journalChanges.journalItems.size());
|
count = static_cast<uint32_t>(player->journalChanges.size());
|
||||||
else
|
|
||||||
player->journalChanges.journalItems.clear();
|
|
||||||
|
|
||||||
RW(player->journalChanges.count, send);
|
RW(count, send);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < player->journalChanges.count; i++)
|
if (!send)
|
||||||
{
|
{
|
||||||
JournalItem journalItem;
|
player->journalChanges.clear();
|
||||||
|
player->journalChanges.resize(count);
|
||||||
if (send)
|
}
|
||||||
journalItem = player->journalChanges.journalItems.at(i);
|
|
||||||
|
|
||||||
|
for (auto &&journalItem : player->journalChanges)
|
||||||
|
{
|
||||||
RW(journalItem.type, send);
|
RW(journalItem.type, send);
|
||||||
RW(journalItem.quest, send, true);
|
RW(journalItem.quest, send, true);
|
||||||
RW(journalItem.index, send);
|
RW(journalItem.index, send);
|
||||||
@ -44,8 +45,5 @@ void PacketPlayerJournal::Packet(RakNet::BitStream *bs, bool send)
|
|||||||
RW(journalItem.timestamp.day, send);
|
RW(journalItem.timestamp.day, send);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!send)
|
|
||||||
player->journalChanges.journalItems.push_back(journalItem);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user