2017-07-11 10:34:09 +00:00
|
|
|
#include "Mechanics.hpp"
|
2017-08-18 04:13:08 +00:00
|
|
|
|
2017-06-26 22:01:45 +00:00
|
|
|
#include <components/openmw-mp/NetworkMessages.hpp>
|
2019-08-19 18:39:33 +00:00
|
|
|
#include <components/openmw-mp/TimedLog.hpp>
|
2017-06-26 22:01:45 +00:00
|
|
|
|
2017-08-18 04:13:08 +00:00
|
|
|
#include <apps/openmw-mp/Script/ScriptFunctions.hpp>
|
|
|
|
#include <apps/openmw-mp/Networking.hpp>
|
|
|
|
|
2017-06-26 22:01:45 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2018-01-31 02:50:29 +00:00
|
|
|
static std::string tempCellDescription;
|
|
|
|
|
2019-12-05 17:15:11 +00:00
|
|
|
void MechanicsFunctions::ClearAlliedPlayersForPlayer(unsigned short pid) noexcept
|
2019-12-02 17:08:03 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
2019-12-05 17:15:11 +00:00
|
|
|
player->alliedPlayers.clear();
|
2019-12-02 17:08:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-31 02:50:29 +00:00
|
|
|
unsigned char MechanicsFunctions::GetMiscellaneousChangeType(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0);
|
|
|
|
|
|
|
|
return player->miscellaneousChangeType;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *MechanicsFunctions::GetMarkCell(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0);
|
|
|
|
|
|
|
|
tempCellDescription = player->cell.getDescription().c_str();
|
|
|
|
return tempCellDescription.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
double MechanicsFunctions::GetMarkPosX(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0.0f);
|
|
|
|
|
|
|
|
return player->markPosition.pos[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
double MechanicsFunctions::GetMarkPosY(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0.0f);
|
|
|
|
|
|
|
|
return player->markPosition.pos[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
double MechanicsFunctions::GetMarkPosZ(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0.0f);
|
|
|
|
|
|
|
|
return player->markPosition.pos[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
double MechanicsFunctions::GetMarkRotX(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0.0f);
|
|
|
|
|
|
|
|
return player->markPosition.rot[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
double MechanicsFunctions::GetMarkRotZ(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0.0f);
|
|
|
|
|
|
|
|
return player->markPosition.rot[2];
|
|
|
|
}
|
|
|
|
|
2018-07-05 19:24:51 +00:00
|
|
|
bool MechanicsFunctions::DoesPlayerHavePlayerKiller(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, false);
|
|
|
|
|
|
|
|
return player->killer.isPlayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MechanicsFunctions::GetPlayerKillerPid(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0);
|
|
|
|
|
|
|
|
Player *killer = Players::getPlayer(player->killer.guid);
|
|
|
|
|
|
|
|
if (killer != nullptr)
|
|
|
|
return killer->getId();
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *MechanicsFunctions::GetPlayerKillerRefId(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, "");
|
|
|
|
|
|
|
|
return player->killer.refId.c_str();
|
|
|
|
}
|
|
|
|
|
2018-07-13 01:12:03 +00:00
|
|
|
unsigned int MechanicsFunctions::GetPlayerKillerRefNum(unsigned short pid) noexcept
|
2018-07-05 19:24:51 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0);
|
|
|
|
|
2018-07-13 01:12:03 +00:00
|
|
|
return player->killer.refNum;
|
2018-07-05 19:24:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int MechanicsFunctions::GetPlayerKillerMpNum(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0);
|
|
|
|
|
|
|
|
return player->killer.mpNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *MechanicsFunctions::GetPlayerKillerName(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, "");
|
|
|
|
|
|
|
|
return player->killer.name.c_str();
|
|
|
|
}
|
|
|
|
|
2018-02-06 04:36:46 +00:00
|
|
|
const char *MechanicsFunctions::GetSelectedSpellId(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0);
|
|
|
|
|
|
|
|
return player->selectedSpellId.c_str();
|
|
|
|
}
|
|
|
|
|
2018-08-03 15:26:44 +00:00
|
|
|
unsigned int MechanicsFunctions::GetDrawState(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, false);
|
|
|
|
|
|
|
|
return player->drawState;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MechanicsFunctions::GetSneakState(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, false);
|
|
|
|
|
|
|
|
// TODO: Avoid having to use a magic number here
|
|
|
|
return (player->movementFlags & 8) != 0;
|
|
|
|
}
|
|
|
|
|
2018-01-31 02:50:29 +00:00
|
|
|
void MechanicsFunctions::SetMarkCell(unsigned short pid, const char *cellDescription) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
|
|
|
player->markCell = Utils::getCellFromDescription(cellDescription);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MechanicsFunctions::SetMarkPos(unsigned short pid, double x, double y, double z) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
|
|
|
player->markPosition.pos[0] = x;
|
|
|
|
player->markPosition.pos[1] = y;
|
|
|
|
player->markPosition.pos[2] = z;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MechanicsFunctions::SetMarkRot(unsigned short pid, double x, double z) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
|
|
|
player->markPosition.rot[0] = x;
|
|
|
|
player->markPosition.rot[2] = z;
|
|
|
|
}
|
|
|
|
|
2018-02-06 04:36:46 +00:00
|
|
|
void MechanicsFunctions::SetSelectedSpellId(unsigned short pid, const char *spellId) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
|
|
|
player->selectedSpellId = spellId;
|
|
|
|
}
|
|
|
|
|
2019-12-05 17:15:11 +00:00
|
|
|
void MechanicsFunctions::AddAlliedPlayerForPlayer(unsigned short pid, unsigned short alliedPlayerPid) noexcept
|
2019-12-02 17:08:03 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
2019-12-05 17:15:11 +00:00
|
|
|
Player *alliedPlayer;
|
|
|
|
GET_PLAYER(alliedPlayerPid, alliedPlayer, );
|
2019-12-02 17:08:03 +00:00
|
|
|
|
2019-12-05 17:15:11 +00:00
|
|
|
player->alliedPlayers.push_back(alliedPlayer->guid);
|
2019-12-02 17:08:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-31 02:50:29 +00:00
|
|
|
void MechanicsFunctions::SendMarkLocation(unsigned short pid)
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
|
|
|
player->miscellaneousChangeType = mwmp::MISCELLANEOUS_CHANGE_TYPE::MARK_LOCATION;
|
|
|
|
|
2018-07-07 15:29:31 +00:00
|
|
|
mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MISCELLANEOUS);
|
|
|
|
packet->setPlayer(player);
|
|
|
|
|
|
|
|
packet->Send(false);
|
2018-01-31 02:50:29 +00:00
|
|
|
}
|
|
|
|
|
2018-02-06 04:36:46 +00:00
|
|
|
void MechanicsFunctions::SendSelectedSpell(unsigned short pid)
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
|
|
|
player->miscellaneousChangeType = mwmp::MISCELLANEOUS_CHANGE_TYPE::SELECTED_SPELL;
|
|
|
|
|
2018-07-07 15:29:31 +00:00
|
|
|
mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MISCELLANEOUS);
|
|
|
|
packet->setPlayer(player);
|
|
|
|
|
|
|
|
packet->Send(false);
|
2018-02-06 04:36:46 +00:00
|
|
|
}
|
|
|
|
|
2019-12-05 17:15:11 +00:00
|
|
|
void MechanicsFunctions::SendAlliedPlayers(unsigned short pid, bool sendToOtherPlayers)
|
2019-12-02 17:08:03 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
2019-12-05 17:15:11 +00:00
|
|
|
mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_ALLY);
|
2019-12-02 17:08:03 +00:00
|
|
|
packet->setPlayer(player);
|
|
|
|
|
|
|
|
packet->Send(false);
|
|
|
|
if (sendToOtherPlayers)
|
|
|
|
packet->Send(true);
|
|
|
|
}
|
|
|
|
|
2017-07-13 17:13:28 +00:00
|
|
|
void MechanicsFunctions::Jail(unsigned short pid, int jailDays, bool ignoreJailTeleportation, bool ignoreJailSkillIncreases,
|
|
|
|
const char* jailProgressText, const char* jailEndText) noexcept
|
2017-07-03 12:45:21 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
2017-07-11 10:34:09 +00:00
|
|
|
player->jailDays = jailDays;
|
|
|
|
player->ignoreJailTeleportation = ignoreJailTeleportation;
|
2017-07-12 15:24:37 +00:00
|
|
|
player->ignoreJailSkillIncreases = ignoreJailSkillIncreases;
|
2017-07-13 17:13:28 +00:00
|
|
|
player->jailProgressText = jailProgressText;
|
|
|
|
player->jailEndText = jailEndText;
|
2017-07-11 10:34:09 +00:00
|
|
|
|
2018-07-07 15:29:31 +00:00
|
|
|
mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_JAIL);
|
|
|
|
packet->setPlayer(player);
|
|
|
|
|
|
|
|
packet->Send(false);
|
2017-07-03 12:45:21 +00:00
|
|
|
}
|
|
|
|
|
2017-07-11 10:34:09 +00:00
|
|
|
void MechanicsFunctions::Resurrect(unsigned short pid, unsigned int type) noexcept
|
2017-06-26 22:01:45 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
2017-06-27 06:49:39 +00:00
|
|
|
player->resurrectType = type;
|
2017-07-11 10:34:09 +00:00
|
|
|
|
2018-07-07 15:29:31 +00:00
|
|
|
mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_RESURRECT);
|
|
|
|
packet->setPlayer(player);
|
|
|
|
|
|
|
|
packet->Send(false);
|
|
|
|
packet->Send(true);
|
2017-06-26 22:01:45 +00:00
|
|
|
}
|
2018-07-05 19:24:51 +00:00
|
|
|
|
|
|
|
// All methods below are deprecated versions of methods from above
|
|
|
|
|
|
|
|
const char *MechanicsFunctions::GetDeathReason(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0);
|
|
|
|
|
|
|
|
if (player->killer.isPlayer)
|
|
|
|
{
|
|
|
|
Player *killerPlayer = Players::getPlayer(player->killer.guid);
|
|
|
|
|
|
|
|
if (killerPlayer != nullptr)
|
|
|
|
return killerPlayer->npc.mName.c_str();
|
|
|
|
}
|
|
|
|
else if (!player->killer.name.empty())
|
|
|
|
return player->killer.name.c_str();
|
|
|
|
|
|
|
|
return "suicide";
|
|
|
|
}
|
2018-07-13 01:12:03 +00:00
|
|
|
|
|
|
|
unsigned int MechanicsFunctions::GetPlayerKillerRefNumIndex(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
return GetPlayerKillerRefNum(pid);
|
|
|
|
}
|