1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-03 15:19:42 +00:00

[General] Implement PlayerKillCount packets

This commit is contained in:
David Cernat 2017-06-10 14:04:19 +03:00
parent 5b23da8e1c
commit 70d9374a6a
17 changed files with 241 additions and 8 deletions

View file

@ -76,6 +76,7 @@ public:
mwmp::JournalChanges journalChangesBuffer; mwmp::JournalChanges journalChangesBuffer;
mwmp::FactionChanges factionChangesBuffer; mwmp::FactionChanges factionChangesBuffer;
mwmp::TopicChanges topicChangesBuffer; mwmp::TopicChanges topicChangesBuffer;
mwmp::KillChanges killChangesBuffer;
private: private:
CellController::TContainer cells; CellController::TContainer cells;

View file

@ -14,6 +14,14 @@ unsigned int DialogueFunctions::GetTopicChangesSize(unsigned short pid) noexcept
return player->topicChanges.count; return player->topicChanges.count;
} }
unsigned int DialogueFunctions::GetKillChangesSize(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0);
return player->killChanges.count;
}
void DialogueFunctions::AddTopic(unsigned short pid, const char* topicId) noexcept void DialogueFunctions::AddTopic(unsigned short pid, const char* topicId) noexcept
{ {
Player *player; Player *player;
@ -25,6 +33,18 @@ void DialogueFunctions::AddTopic(unsigned short pid, const char* topicId) noexce
player->topicChangesBuffer.topics.push_back(topic); player->topicChangesBuffer.topics.push_back(topic);
} }
void DialogueFunctions::AddKill(unsigned short pid, const char* refId, int number) noexcept
{
Player *player;
GET_PLAYER(pid, player, );
mwmp::Kill kill;
kill.refId = refId;
kill.number = number;
player->killChangesBuffer.kills.push_back(kill);
}
const char *DialogueFunctions::GetTopicId(unsigned short pid, unsigned int i) noexcept const char *DialogueFunctions::GetTopicId(unsigned short pid, unsigned int i) noexcept
{ {
Player *player; Player *player;
@ -36,6 +56,25 @@ const char *DialogueFunctions::GetTopicId(unsigned short pid, unsigned int i) no
return player->topicChanges.topics.at(i).topicId.c_str(); return player->topicChanges.topics.at(i).topicId.c_str();
} }
const char *DialogueFunctions::GetKillRefId(unsigned short pid, unsigned int i) noexcept
{
Player *player;
GET_PLAYER(pid, player, "");
if (i >= player->killChanges.count)
return "invalid";
return player->killChanges.kills.at(i).refId.c_str();
}
int DialogueFunctions::GetKillNumber(unsigned short pid, unsigned int i) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0);
return player->killChanges.kills.at(i).number;
}
void DialogueFunctions::SendTopicChanges(unsigned short pid) noexcept void DialogueFunctions::SendTopicChanges(unsigned short pid) noexcept
{ {
Player *player; Player *player;
@ -47,3 +86,15 @@ void DialogueFunctions::SendTopicChanges(unsigned short pid) noexcept
player->topicChanges = std::move(player->topicChangesBuffer); player->topicChanges = std::move(player->topicChangesBuffer);
player->topicChangesBuffer.topics.clear(); player->topicChangesBuffer.topics.clear();
} }
void DialogueFunctions::SendKillChanges(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player, );
std::swap(player->killChanges, player->killChangesBuffer);
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_KILL_COUNT)->setPlayer(player);
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_KILL_COUNT)->Send(false);
player->killChanges = std::move(player->killChangesBuffer);
player->killChangesBuffer.kills.clear();
}

View file

@ -3,24 +3,34 @@
#define DIALOGUEAPI \ #define DIALOGUEAPI \
{"GetTopicChangesSize", DialogueFunctions::GetTopicChangesSize},\ {"GetTopicChangesSize", DialogueFunctions::GetTopicChangesSize},\
{"GetKillChangesSize", DialogueFunctions::GetKillChangesSize},\
\ \
{"AddTopic", DialogueFunctions::AddTopic},\ {"AddTopic", DialogueFunctions::AddTopic},\
{"AddKill", DialogueFunctions::AddKill},\
\ \
{"GetTopicId", DialogueFunctions::GetTopicId},\ {"GetTopicId", DialogueFunctions::GetTopicId},\
{"GetKillRefId", DialogueFunctions::GetKillRefId},\
{"GetKillNumber", DialogueFunctions::GetKillNumber},\
\ \
{"SendTopicChanges", DialogueFunctions::SendTopicChanges} {"SendTopicChanges", DialogueFunctions::SendTopicChanges},\
{"SendKillChanges", DialogueFunctions::SendKillChanges}
class DialogueFunctions class DialogueFunctions
{ {
public: public:
static unsigned int GetTopicChangesSize(unsigned short pid) noexcept; static unsigned int GetTopicChangesSize(unsigned short pid) noexcept;
static unsigned int GetKillChangesSize(unsigned short pid) noexcept;
static void AddTopic(unsigned short pid, const char* topicId) noexcept; static void AddTopic(unsigned short pid, const char* topicId) noexcept;
static void AddKill(unsigned short pid, const char* refId, int number) noexcept;
static const char *GetTopicId(unsigned short pid, unsigned int i) noexcept; static const char *GetTopicId(unsigned short pid, unsigned int i) noexcept;
static const char *GetKillRefId(unsigned short pid, unsigned int i) noexcept;
static int GetKillNumber(unsigned short pid, unsigned int i) noexcept;
static void SendTopicChanges(unsigned short pid) noexcept; static void SendTopicChanges(unsigned short pid) noexcept;
static void SendKillChanges(unsigned short pid) noexcept;
private: private:
}; };

View file

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

View file

@ -116,8 +116,9 @@ add_openmw_dir (mwmp/processors/player ProcessorChatMessage ProcessorGUIMessageB
ProcessorPlayerAnimFlags ProcessorPlayerAnimPlay ProcessorPlayerAttack ProcessorPlayerAttribute ProcessorPlayerBook ProcessorPlayerAnimFlags ProcessorPlayerAnimPlay ProcessorPlayerAttack ProcessorPlayerAttribute ProcessorPlayerBook
ProcessorPlayerBounty ProcessorPlayerCellChange ProcessorPlayerCellState ProcessorPlayerCharClass ProcessorPlayerCharGen ProcessorPlayerBounty ProcessorPlayerCellChange ProcessorPlayerCellState ProcessorPlayerCharClass ProcessorPlayerCharGen
ProcessorPlayerDeath ProcessorPlayerDisposition ProcessorPlayerEquipment ProcessorPlayerFaction ProcessorPlayerInventory ProcessorPlayerDeath ProcessorPlayerDisposition ProcessorPlayerEquipment ProcessorPlayerFaction ProcessorPlayerInventory
ProcessorPlayerJournal ProcessorPlayerLevel ProcessorPlayerMap ProcessorPlayerPosition ProcessorPlayerResurrect ProcessorPlayerJournal ProcessorPlayerKillCount ProcessorPlayerLevel ProcessorPlayerMap ProcessorPlayerPosition
ProcessorPlayerSkill ProcessorPlayerSpeech ProcessorPlayerSpellbook ProcessorPlayerStatsDynamic ProcessorPlayerTopic ProcessorPlayerResurrect ProcessorPlayerSkill ProcessorPlayerSpeech ProcessorPlayerSpellbook ProcessorPlayerStatsDynamic
ProcessorPlayerTopic
) )
add_openmw_dir (mwmp/processors/world BaseObjectProcessor ProcessorContainer ProcessorDoorState ProcessorMusicPlay add_openmw_dir (mwmp/processors/world BaseObjectProcessor ProcessorContainer ProcessorDoorState ProcessorMusicPlay

View file

@ -104,6 +104,16 @@ namespace MWBase
virtual int countDeaths (const std::string& id) const = 0; virtual int countDeaths (const std::string& id) const = 0;
///< Return the number of deaths for actors with the given ID. ///< Return the number of deaths for actors with the given ID.
/*
Start of tes3mp addition
Make it possible to set the number of deaths for an actor with the given refId
*/
virtual void setDeaths(const std::string& refId, int number) = 0;
/*
End of tes3mp addition
*/
/// Check if \a observer is potentially aware of \a ptr. Does not do a line of sight check! /// Check if \a observer is potentially aware of \a ptr. Does not do a line of sight check!
virtual bool awarenessCheck (const MWWorld::Ptr& ptr, const MWWorld::Ptr& observer) = 0; virtual bool awarenessCheck (const MWWorld::Ptr& ptr, const MWWorld::Ptr& observer) = 0;

View file

@ -1484,6 +1484,23 @@ namespace MWMechanics
++mDeathCount[Misc::StringUtils::lowerCase(iter->first.getCellRef().getRefId())]; ++mDeathCount[Misc::StringUtils::lowerCase(iter->first.getCellRef().getRefId())];
/*
Start of tes3mp addition
Send an ID_PLAYER_KILL_COUNT packet every time the kill count changes,
as long as we are the authority over the actor's cell
*/
if (mwmp::Main::get().getCellController()->isLocalActor(iter->first))
{
std::string refId = Misc::StringUtils::lowerCase(iter->first.getCellRef().getRefId());
int number = mDeathCount[refId];
mwmp::Main::get().getLocalPlayer()->sendKill(refId, number);
}
/*
End of tes3mp addition
*/
// Make sure spell effects are removed // Make sure spell effects are removed
purgeSpellEffects(stats.getActorId()); purgeSpellEffects(stats.getActorId());
@ -1615,6 +1632,19 @@ namespace MWMechanics
return 0; return 0;
} }
/*
Start of tes3mp addition
Make it possible to set the number of deaths for an actor with the given refId
*/
void Actors::setDeaths(const std::string& refId, int number)
{
mDeathCount[refId] = number;
}
/*
End of tes3mp addition
*/
void Actors::forceStateUpdate(const MWWorld::Ptr & ptr) void Actors::forceStateUpdate(const MWWorld::Ptr & ptr)
{ {
PtrActorMap::iterator iter = mActors.find(ptr); PtrActorMap::iterator iter = mActors.find(ptr);

View file

@ -107,6 +107,16 @@ namespace MWMechanics
int countDeaths (const std::string& id) const; int countDeaths (const std::string& id) const;
///< Return the number of deaths for actors with the given ID. ///< Return the number of deaths for actors with the given ID.
/*
Start of tes3mp addition
Make it possible to set the number of deaths for an actor with the given refId
*/
void setDeaths(const std::string& refId, int number);
/*
End of tes3mp addition
*/
void forceStateUpdate(const MWWorld::Ptr &ptr); void forceStateUpdate(const MWWorld::Ptr &ptr);
bool playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number, bool persist=false); bool playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number, bool persist=false);

View file

@ -637,6 +637,19 @@ namespace MWMechanics
return mActors.countDeaths (id); return mActors.countDeaths (id);
} }
/*
Start of tes3mp addition
Make it possible to set the number of deaths for an actor with the given refId
*/
void MechanicsManager::setDeaths(const std::string& refId, int number)
{
mActors.setDeaths(refId, number);
}
/*
End of tes3mp addition
*/
void MechanicsManager::getPersuasionDispositionChange (const MWWorld::Ptr& npc, PersuasionType type, bool& success, float& tempChange, float& permChange) void MechanicsManager::getPersuasionDispositionChange (const MWWorld::Ptr& npc, PersuasionType type, bool& success, float& tempChange, float& permChange)
{ {
const MWWorld::Store<ESM::GameSetting> &gmst = const MWWorld::Store<ESM::GameSetting> &gmst =

View file

@ -107,6 +107,16 @@ namespace MWMechanics
virtual int countDeaths (const std::string& id) const; virtual int countDeaths (const std::string& id) const;
///< Return the number of deaths for actors with the given ID. ///< Return the number of deaths for actors with the given ID.
/*
Start of tes3mp addition
Make it possible to set the number of deaths for an actor with the given refId
*/
virtual void setDeaths(const std::string& refId, int number);
/*
End of tes3mp addition
*/
virtual void getPersuasionDispositionChange (const MWWorld::Ptr& npc, PersuasionType type, bool& success, float& tempChange, float& permChange); virtual void getPersuasionDispositionChange (const MWWorld::Ptr& npc, PersuasionType type, bool& success, float& tempChange, float& permChange);
///< Perform a persuasion action on NPC ///< Perform a persuasion action on NPC

View file

@ -1014,6 +1014,18 @@ void LocalPlayer::setFactions()
} }
} }
void LocalPlayer::setKills()
{
for (unsigned int i = 0; i < killChanges.count; i++)
{
mwmp::Kill kill = killChanges.kills.at(i);
std::string refId = kill.refId;
int number = kill.number;
MWBase::Environment::get().getMechanicsManager()->setDeaths(refId, number);
}
}
void LocalPlayer::sendClass() void LocalPlayer::sendClass()
{ {
MWBase::World *world = MWBase::Environment::get().getWorld(); MWBase::World *world = MWBase::Environment::get().getWorld();
@ -1204,6 +1216,22 @@ void LocalPlayer::sendTopic(const std::string& topicId)
getNetworking()->getPlayerPacket(ID_PLAYER_TOPIC)->Send(); getNetworking()->getPlayerPacket(ID_PLAYER_TOPIC)->Send();
} }
void LocalPlayer::sendKill(const std::string& refId, int number)
{
killChanges.kills.clear();
mwmp::Kill kill;
kill.refId = refId;
kill.number = number;
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Sending ID_PLAYER_KILL_COUNT with refId %s, number %i", refId.c_str(), number);
killChanges.kills.push_back(kill);
getNetworking()->getPlayerPacket(ID_PLAYER_KILL_COUNT)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_KILL_COUNT)->Send();
}
void LocalPlayer::clearCellStates() void LocalPlayer::clearCellStates()
{ {
cellStateChanges.cellStates.clear(); cellStateChanges.cellStates.clear();

View file

@ -59,6 +59,7 @@ namespace mwmp
void setInventory(); void setInventory();
void setSpellbook(); void setSpellbook();
void setFactions(); void setFactions();
void setKills();
void sendClass(); void sendClass();
void sendInventory(); void sendInventory();
@ -72,6 +73,7 @@ namespace mwmp
void sendJournalIndex(const std::string& quest, int index); void sendJournalIndex(const std::string& quest, int index);
void sendFaction(const std::string& factionId, int rank, bool isExpelled); void sendFaction(const std::string& factionId, int rank, bool isExpelled);
void sendTopic(const std::string& topic); void sendTopic(const std::string& topic);
void sendKill(const std::string& refId, int number);
void clearCellStates(); void clearCellStates();
void clearCurrentContainer(); void clearCurrentContainer();

View file

@ -30,6 +30,7 @@
#include "player/ProcessorPlayerFaction.hpp" #include "player/ProcessorPlayerFaction.hpp"
#include "player/ProcessorPlayerInventory.hpp" #include "player/ProcessorPlayerInventory.hpp"
#include "player/ProcessorPlayerJournal.hpp" #include "player/ProcessorPlayerJournal.hpp"
#include "player/ProcessorPlayerKillCount.hpp"
#include "player/ProcessorPlayerLevel.hpp" #include "player/ProcessorPlayerLevel.hpp"
#include "player/ProcessorPlayerMap.hpp" #include "player/ProcessorPlayerMap.hpp"
#include "player/ProcessorPlayerPosition.hpp" #include "player/ProcessorPlayerPosition.hpp"
@ -103,6 +104,7 @@ void ProcessorInitializer()
PlayerProcessor::AddProcessor(new ProcessorPlayerFaction()); PlayerProcessor::AddProcessor(new ProcessorPlayerFaction());
PlayerProcessor::AddProcessor(new ProcessorPlayerInventory()); PlayerProcessor::AddProcessor(new ProcessorPlayerInventory());
PlayerProcessor::AddProcessor(new ProcessorPlayerJournal()); PlayerProcessor::AddProcessor(new ProcessorPlayerJournal());
PlayerProcessor::AddProcessor(new ProcessorPlayerKillCount());
PlayerProcessor::AddProcessor(new ProcessorPlayerLevel()); PlayerProcessor::AddProcessor(new ProcessorPlayerLevel());
PlayerProcessor::AddProcessor(new ProcessorPlayerMap()); PlayerProcessor::AddProcessor(new ProcessorPlayerMap());
PlayerProcessor::AddProcessor(new ProcessorPlayerPosition()); PlayerProcessor::AddProcessor(new ProcessorPlayerPosition());

View file

@ -0,0 +1,30 @@
#ifndef OPENMW_PROCESSORPLAYERKILLCOUNT_HPP
#define OPENMW_PROCESSORPLAYERKILLCOUNT_HPP
#include "../PlayerProcessor.hpp"
namespace mwmp
{
class ProcessorPlayerKillCount : public PlayerProcessor
{
public:
ProcessorPlayerKillCount()
{
BPP_INIT(ID_PLAYER_KILL_COUNT)
}
virtual void Do(PlayerPacket &packet, BasePlayer *player)
{
if (isRequest())
{
// Entire list of topics cannot currently be requested from players
}
else if (player != 0)
{
static_cast<LocalPlayer*>(player)->setKills();
}
}
};
}
#endif //OPENMW_PROCESSORPLAYERKILLCOUNT_HPP

View file

@ -178,10 +178,11 @@ add_component_dir (openmw-mp/Packets/Player
PlayerPacket PlayerPacket
PacketHandshake PacketChatMessage PacketGUIBoxes PacketGameTime PacketGameWeather PacketPlayerBaseInfo PacketPlayerCharGen PacketHandshake PacketChatMessage PacketGUIBoxes PacketGameTime PacketGameWeather PacketPlayerBaseInfo PacketPlayerCharGen
PacketPlayerActiveSkills PacketPlayerAnimFlags PacketPlayerAnimPlay PacketPlayerAttack PacketPlayerAttribute PacketPlayerActiveSkills PacketPlayerAnimFlags PacketPlayerAnimPlay PacketPlayerAttack PacketPlayerAttribute
PacketPlayerBook PacketPlayerBounty PacketPlayerCellChange PacketPlayerCellState PacketPlayerClass PacketPlayerDeath PacketPlayerBook PacketPlayerBounty PacketPlayerCellChange PacketPlayerCellState PacketPlayerClass
PacketPlayerEquipment PacketPlayerFaction PacketPlayerInventory PacketPlayerJournal PacketPlayerLevel PacketPlayerMap PacketPlayerDeath PacketPlayerEquipment PacketPlayerFaction PacketPlayerInventory PacketPlayerJournal
PacketPlayerPosition PacketPlayerRegionAuthority PacketPlayerRegionChange PacketPlayerRest PacketPlayerResurrect PacketPlayerKillCount PacketPlayerLevel PacketPlayerMap PacketPlayerPosition PacketPlayerRegionAuthority
PacketPlayerSkill PacketPlayerSpeech PacketPlayerSpellbook PacketPlayerStatsDynamic PacketPlayerTopic PacketPlayerRest PacketPlayerResurrect PacketPlayerSkill PacketPlayerSpeech PacketPlayerSpellbook
PacketPlayerStatsDynamic PacketPlayerTopic
) )
add_component_dir (openmw-mp/Packets/World add_component_dir (openmw-mp/Packets/World

View file

@ -56,6 +56,12 @@ namespace mwmp
std::string topicId; std::string topicId;
}; };
struct Kill
{
std::string refId;
int number;
};
struct CellState struct CellState
{ {
ESM::Cell cell; ESM::Cell cell;
@ -87,6 +93,12 @@ namespace mwmp
unsigned int count; unsigned int count;
}; };
struct KillChanges
{
std::vector<Kill> kills;
unsigned int count;
};
struct InventoryChanges struct InventoryChanges
{ {
std::vector<Item> items; std::vector<Item> items;
@ -171,6 +183,7 @@ namespace mwmp
JournalChanges journalChanges; JournalChanges journalChanges;
FactionChanges factionChanges; FactionChanges factionChanges;
TopicChanges topicChanges; TopicChanges topicChanges;
KillChanges killChanges;
CellStateChanges cellStateChanges; CellStateChanges cellStateChanges;
ESM::ActiveSpells activeSpells; ESM::ActiveSpells activeSpells;
CurrentContainer currentContainer; CurrentContainer currentContainer;

View file

@ -10,5 +10,24 @@ void mwmp::PacketPlayerKillCount::Packet(RakNet::BitStream *bs, bool send)
{ {
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
// Placeholder to be filled in later if (send)
player->killChanges.count = (unsigned int)(player->killChanges.kills.size());
else
player->killChanges.kills.clear();
RW(player->killChanges.count, send);
for (unsigned int i = 0; i < player->killChanges.count; i++)
{
Kill kill;
if (send)
kill = player->killChanges.kills.at(i);
RW(kill.refId, send, 1);
RW(kill.number, send);
if (!send)
player->killChanges.kills.push_back(kill);
}
} }