1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-03 20:49:41 +00:00

[General] Implement PlayerJail packet

Rework server's DeathFunctions into MechanicsFunctions

Remove connection between PlayerResurrect and jailing
This commit is contained in:
David Cernat 2017-07-11 13:34:09 +03:00
parent b1b27728e2
commit 3280f0c5ee
11 changed files with 44 additions and 54 deletions

View file

@ -85,8 +85,8 @@ set(SERVER
Script/Functions/Actors.cpp Script/Functions/World.cpp Script/Functions/Miscellaneous.cpp Script/Functions/Actors.cpp Script/Functions/World.cpp Script/Functions/Miscellaneous.cpp
Script/Functions/Books.cpp Script/Functions/Cells.cpp Script/Functions/CharClass.cpp Script/Functions/Books.cpp Script/Functions/Cells.cpp Script/Functions/CharClass.cpp
Script/Functions/Chat.cpp Script/Functions/Death.cpp Script/Functions/Dialogue.cpp Script/Functions/Chat.cpp Script/Functions/Dialogue.cpp Script/Functions/Factions.cpp
Script/Functions/Factions.cpp Script/Functions/GUI.cpp Script/Functions/Items.cpp Script/Functions/GUI.cpp Script/Functions/Items.cpp Script/Functions/Mechanics.cpp
Script/Functions/Positions.cpp Script/Functions/Quests.cpp Script/Functions/Settings.cpp Script/Functions/Positions.cpp Script/Functions/Quests.cpp Script/Functions/Settings.cpp
Script/Functions/Spells.cpp Script/Functions/Stats.cpp Script/Functions/Timer.cpp Script/Functions/Spells.cpp Script/Functions/Stats.cpp Script/Functions/Timer.cpp

View file

@ -1,19 +0,0 @@
#ifndef OPENMW_DEATHAPI_HPP
#define OPENMW_DEATHAPI_HPP
#include "../Types.hpp"
#define DEATHAPI \
{"SetDeathPenaltyJailDays", DeathFunctions::SetDeathPenaltyJailDays},\
\
{"Resurrect", DeathFunctions::Resurrect}
class DeathFunctions
{
public:
static void SetDeathPenaltyJailDays(unsigned short pid, int days) noexcept;
static void Resurrect(unsigned short pid, unsigned int type) noexcept;
};
#endif //OPENMW_DEATHAPI_HPP

View file

@ -1,4 +1,4 @@
#include "Death.hpp" #include "Mechanics.hpp"
#include <apps/openmw-mp/Script/ScriptFunctions.hpp> #include <apps/openmw-mp/Script/ScriptFunctions.hpp>
#include <components/openmw-mp/NetworkMessages.hpp> #include <components/openmw-mp/NetworkMessages.hpp>
#include <apps/openmw-mp/Networking.hpp> #include <apps/openmw-mp/Networking.hpp>
@ -7,20 +7,25 @@
#include <iostream> #include <iostream>
using namespace std; using namespace std;
void DeathFunctions::SetDeathPenaltyJailDays(unsigned short pid, int days) noexcept void MechanicsFunctions::Jail(unsigned short pid, int jailDays, bool ignoreJailTeleportation) noexcept
{ {
Player *player; Player *player;
GET_PLAYER(pid, player, ); GET_PLAYER(pid, player, );
player->deathPenaltyJailDays = days; player->jailDays = jailDays;
player->ignoreJailTeleportation = ignoreJailTeleportation;
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_JAIL)->setPlayer(player);
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_JAIL)->Send(false);
} }
void DeathFunctions::Resurrect(unsigned short pid, unsigned int type) noexcept void MechanicsFunctions::Resurrect(unsigned short pid, unsigned int type) noexcept
{ {
Player *player; Player *player;
GET_PLAYER(pid, player, ); GET_PLAYER(pid, player, );
player->resurrectType = type; player->resurrectType = type;
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_RESURRECT)->setPlayer(player); mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_RESURRECT)->setPlayer(player);
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_RESURRECT)->Send(false); mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_RESURRECT)->Send(false);
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_RESURRECT)->Send(true); mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_RESURRECT)->Send(true);

View file

@ -0,0 +1,19 @@
#ifndef OPENMW_MECHANICSAPI_HPP
#define OPENMW_MECHANICSAPI_HPP
#include "../Types.hpp"
#define MECHANICSAPI \
{"Jail", MechanicsFunctions::Jail},\
\
{"Resurrect", MechanicsFunctions::Resurrect}
class MechanicsFunctions
{
public:
static void Jail(unsigned short pid, int jailDays, bool ignoreJailTeleportation) noexcept;
static void Resurrect(unsigned short pid, unsigned int type) noexcept;
};
#endif //OPENMW_MECHANICSAPI_HPP

View file

@ -9,11 +9,11 @@
#include <Script/Functions/Books.hpp> #include <Script/Functions/Books.hpp>
#include <Script/Functions/Cells.hpp> #include <Script/Functions/Cells.hpp>
#include <Script/Functions/CharClass.hpp> #include <Script/Functions/CharClass.hpp>
#include <Script/Functions/Death.hpp>
#include <Script/Functions/Dialogue.hpp> #include <Script/Functions/Dialogue.hpp>
#include <Script/Functions/Factions.hpp> #include <Script/Functions/Factions.hpp>
#include <Script/Functions/GUI.hpp> #include <Script/Functions/GUI.hpp>
#include <Script/Functions/Items.hpp> #include <Script/Functions/Items.hpp>
#include <Script/Functions/Mechanics.hpp>
#include <Script/Functions/Miscellaneous.hpp> #include <Script/Functions/Miscellaneous.hpp>
#include <Script/Functions/Positions.hpp> #include <Script/Functions/Positions.hpp>
#include <Script/Functions/Quests.hpp> #include <Script/Functions/Quests.hpp>
@ -112,11 +112,11 @@ public:
BOOKAPI, BOOKAPI,
CELLAPI, CELLAPI,
CHARCLASSAPI, CHARCLASSAPI,
DEATHAPI,
DIALOGUEAPI, DIALOGUEAPI,
FACTIONAPI, FACTIONAPI,
GUIAPI, GUIAPI,
ITEMAPI, ITEMAPI,
MECHANICSAPI,
MISCELLANEOUSAPI, MISCELLANEOUSAPI,
POSITIONAPI, POSITIONAPI,
QUESTAPI, QUESTAPI,

View file

@ -74,8 +74,7 @@ namespace MWGui
/* /*
Start of tes3mp change (minor) Start of tes3mp change (minor)
If the jail code is being used from elsewhere to lower skills, don't Prevent teleportation to jail if specified
teleport the player to the nearest prison
*/ */
if (!mwmp::Main::get().getLocalPlayer()->ignoreJailTeleportation) if (!mwmp::Main::get().getLocalPlayer()->ignoreJailTeleportation)
MWBase::Environment::get().getWorld()->teleportToClosestMarker(player, "prisonmarker"); MWBase::Environment::get().getWorld()->teleportToClosestMarker(player, "prisonmarker");
@ -129,21 +128,11 @@ namespace MWGui
/* /*
Start of tes3mp addition Start of tes3mp addition
If the jail code is being used from elsewhere to lower skills, reset the If jail teleportation was ignored, reset its boolean here
corresponding boolean and use more ambiguous wording for the message displayed
*/ */
if (mwmp::Main::get().getLocalPlayer()->ignoreJailTeleportation) if (mwmp::Main::get().getLocalPlayer()->ignoreJailTeleportation)
{ {
mwmp::Main::get().getLocalPlayer()->ignoreJailTeleportation = false; mwmp::Main::get().getLocalPlayer()->ignoreJailTeleportation = false;
const std::string stringToReplace = "been released";
const std::string stringToReplace2 = "in prison";
if (message.find(stringToReplace) != std::string::npos)
message.replace(message.find(stringToReplace), stringToReplace.size(), "recovered");
if (message.find(stringToReplace2) != std::string::npos)
message.replace(message.find(stringToReplace2), stringToReplace2.size(), "incapacitated");
} }
/* /*
End of tes3mp addition End of tes3mp addition

View file

@ -1,6 +1,9 @@
#ifndef OPENMW_PROCESSORPLAYERJAIL_HPP #ifndef OPENMW_PROCESSORPLAYERJAIL_HPP
#define OPENMW_PROCESSORPLAYERJAIL_HPP #define OPENMW_PROCESSORPLAYERJAIL_HPP
#include "apps/openmw/mwbase/environment.hpp"
#include "apps/openmw/mwgui/windowmanagerimp.hpp"
#include "../PlayerProcessor.hpp" #include "../PlayerProcessor.hpp"
#include "apps/openmw/mwmp/Main.hpp" #include "apps/openmw/mwmp/Main.hpp"
#include "apps/openmw/mwmp/Networking.hpp" #include "apps/openmw/mwmp/Networking.hpp"
@ -21,7 +24,11 @@ namespace mwmp
if (isLocal()) if (isLocal())
{ {
// To be filled in // Apply death penalties
if (player->jailDays > 0)
{
MWBase::Environment::get().getWindowManager()->goToJail(player->jailDays);
}
} }
} }
}; };

View file

@ -5,9 +5,6 @@
#ifndef OPENMW_PROCESSORPLAYERRESURRECT_HPP #ifndef OPENMW_PROCESSORPLAYERRESURRECT_HPP
#define OPENMW_PROCESSORPLAYERRESURRECT_HPP #define OPENMW_PROCESSORPLAYERRESURRECT_HPP
#include "apps/openmw/mwbase/environment.hpp"
#include "apps/openmw/mwgui/windowmanagerimp.hpp"
#include "../PlayerProcessor.hpp" #include "../PlayerProcessor.hpp"
#include "apps/openmw/mwmp/Main.hpp" #include "apps/openmw/mwmp/Main.hpp"
#include "apps/openmw/mwmp/Networking.hpp" #include "apps/openmw/mwmp/Networking.hpp"
@ -61,13 +58,6 @@ namespace mwmp
static_cast<LocalPlayer*>(player)->updateStatsDynamic(true); static_cast<LocalPlayer*>(player)->updateStatsDynamic(true);
Main::get().getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(player); Main::get().getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(player);
Main::get().getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->Send(serverAddr); Main::get().getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->Send(serverAddr);
// Apply death penalties
if (player->deathPenaltyJailDays > 0)
{
player->ignoreJailTeleportation = true;
MWBase::Environment::get().getWindowManager()->goToJail(player->deathPenaltyJailDays);
}
} }
else if (player != 0) else if (player != 0)
{ {

View file

@ -250,10 +250,9 @@ namespace mwmp
bool isChangingRegion; bool isChangingRegion;
std::string deathReason; std::string deathReason;
int deathPenaltyJailDays;
bool ignoreJailTeleportation;
int jailDays; int jailDays;
bool ignoreJailTeleportation;
unsigned int resurrectType; unsigned int resurrectType;
}; };

View file

@ -14,4 +14,5 @@ void PacketPlayerJail::Packet(RakNet::BitStream *bs, bool send)
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
RW(player->jailDays, send); RW(player->jailDays, send);
RW(player->ignoreJailTeleportation, send);
} }

View file

@ -14,5 +14,4 @@ void PacketPlayerResurrect::Packet(RakNet::BitStream *bs, bool send)
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
RW(player->resurrectType, send); RW(player->resurrectType, send);
RW(player->deathPenaltyJailDays, send);
} }