[General] Rework and simplify death reasons so they work with NPCs

pull/249/merge
David Cernat 8 years ago
parent b745a33f18
commit 4d81455020

@ -69,7 +69,6 @@ Player::Player(RakNet::RakNetGUID guid) : BasePlayer(guid)
{
handshakeState = false;
loadState = NOTLOADED;
lastAttacker = 0;
}
Player::~Player()
@ -114,31 +113,6 @@ Player *Players::getPlayer(unsigned short id)
return slots[id];
}
void Player::setLastAttackerId(unsigned short pid)
{
lastAttacker = pid;
}
void Player::resetLastAttacker()
{
lastAttacker = id;
}
unsigned short Player::getLastAttackerId()
{
return lastAttacker;
}
void Player::setLastAttackerTime(std::chrono::steady_clock::time_point time)
{
lastAttackerTime = time;
}
std::chrono::steady_clock::time_point Player::getLastAttackerTime()
{
return lastAttackerTime;
}
CellController::TContainer *Player::getCells()
{
return &cells;

@ -63,13 +63,6 @@ public:
void setLoadState(int state);
int getLoadState();
void setLastAttackerId(unsigned short pid);
void resetLastAttacker();
unsigned short getLastAttackerId();
void setLastAttackerTime(std::chrono::steady_clock::time_point time);
std::chrono::steady_clock::time_point getLastAttackerTime();
virtual ~Player();
CellController::TContainer *getCells();
@ -86,8 +79,6 @@ private:
CellController::TContainer cells;
bool handshakeState;
int loadState;
unsigned short lastAttacker;
std::chrono::steady_clock::time_point lastAttackerTime;
};

@ -110,7 +110,6 @@ int StatsFunctions::GetIsMale(unsigned short pid) noexcept
const char *StatsFunctions::GetBirthsign(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0);
@ -133,6 +132,14 @@ bool StatsFunctions::IsCreatureName(unsigned short pid) noexcept
return player->useCreatureName;
}
const char *StatsFunctions::GetDeathReason(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0);
return player->deathReason.c_str();
}
int StatsFunctions::GetLevel(unsigned short pid) noexcept
{
Player *player;

@ -21,6 +21,7 @@
{"GetBirthsign", StatsFunctions::GetBirthsign},\
{"GetCreatureModel", StatsFunctions::GetCreatureModel},\
{"IsCreatureName", StatsFunctions::IsCreatureName},\
{"GetDeathReason", StatsFunctions::GetDeathReason},\
\
{"GetLevel", StatsFunctions::GetLevel},\
{"GetLevelProgress", StatsFunctions::GetLevelProgress},\
@ -100,6 +101,7 @@ public:
static const char *GetBirthsign(unsigned short pid) noexcept;
static const char *GetCreatureModel(unsigned short pid) noexcept;
static bool IsCreatureName(unsigned short pid) noexcept;
static const char *GetDeathReason(unsigned short pid) noexcept;
static int GetLevel(unsigned short pid) noexcept;
static int GetLevelProgress(unsigned short pid) noexcept;

@ -112,7 +112,7 @@ public:
{"OnServerExit", Function<void, bool>()},
{"OnPlayerConnect", Function<bool, unsigned short>()},
{"OnPlayerDisconnect", Function<void, unsigned short>()},
{"OnPlayerDeath", Function<void, unsigned short, short, unsigned short>()},
{"OnPlayerDeath", Function<void, unsigned short>()},
{"OnPlayerResurrect", Function<void, unsigned short>()},
{"OnPlayerCellChange", Function<void, unsigned short>()},
{"OnPlayerAttributesChange", Function<void, unsigned short>()},

@ -26,27 +26,7 @@ namespace mwmp
if (!player.creatureStats.mDead)
{
Player *target = Players::getPlayer(player.attack.target.guid);
if (target == nullptr)
target = &player;
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Player: %s attacked %s state: %d", player.npc.mName.c_str(),
target->npc.mName.c_str(), player.attack.pressed == 1);
if (player.attack.pressed == 0)
{
LOG_APPEND(Log::LOG_VERBOSE, "success: %d", player.attack.success == 1);
if (player.attack.success == 1)
{
LOG_APPEND(Log::LOG_VERBOSE, "damage: %d", player.attack.damage == 1);
target->setLastAttackerId(player.getId());
target->setLastAttackerTime(std::chrono::steady_clock::now());
}
}
//packet.Send(player, true);
player.sendToLoaded(&packet);
playerController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->RequestData(player.attack.target.guid);
}
}
};

@ -17,34 +17,15 @@ namespace mwmp
ProcessorPlayerDeath()
{
BPP_INIT(ID_PLAYER_DEATH)
avoidReading = true;
}
void Do(PlayerPacket &packet, Player &player) override
{
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received %s from %s", strPacketID.c_str(), player.npc.mName.c_str());
Player *killer = Players::getPlayer(player.getLastAttackerId());
short reason = 0; // unknown;
double secondsSinceLastAttacker = std::chrono::duration_cast<std::chrono::duration<double>>(
std::chrono::steady_clock::now() - player.getLastAttackerTime()).count();
if (!killer)
killer = &player;
if (secondsSinceLastAttacker < 3.0f)
reason = 1; // killed
else
reason = 2; //suicide
player.resetLastAttacker();
player.creatureStats.mDead = true;
packet.Send(true);
Script::Call<Script::CallbackIdentity("OnPlayerDeath")>(player.getId(), reason, killer->getId());
Script::Call<Script::CallbackIdentity("OnPlayerDeath")>(player.getId());
}
};
}

@ -938,10 +938,17 @@ namespace MWClass
localAttack->shouldSend = true;
}
else if (ptr == MWMechanics::getPlayer())
if (ptr == MWMechanics::getPlayer())
{
mwmp::Main::get().getLocalPlayer()->updateStatsDynamic(true);
mwmp::Main::get().getLocalPlayer()->updatePosition(true); // fix position after getting damage;
// Record the attacker as the LocalPlayer's death reason
if (getCreatureStats(ptr).isDead())
{
mwmp::Main::get().getLocalPlayer()->deathReason = attacker.getClass().getName(attacker);
}
}
/*
End of tes3mp addition

@ -50,6 +50,8 @@ LocalPlayer::LocalPlayer()
ignorePosPacket = false;
attack.shouldSend = false;
deathReason = "suicide";
}
LocalPlayer::~LocalPlayer()
@ -533,12 +535,16 @@ void LocalPlayer::updateDeadState(bool forceUpdate)
creatureStats.mDead = true;
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Sending ID_PLAYER_DEATH to server about myself");
LOG_APPEND(Log::LOG_INFO, "- deathReason was %s", deathReason.c_str());
getNetworking()->getPlayerPacket(ID_PLAYER_DEATH)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_DEATH)->Send();
isDead = true;
}
else if (ptrNpcStats->getHealth().getCurrent() > 0 && isDead)
{
deathReason = "suicide";
isDead = false;
}
}
void LocalPlayer::updateAnimFlags(bool forceUpdate)

@ -182,6 +182,8 @@ namespace mwmp
std::string passw;
std::string creatureModel;
bool useCreatureName;
std::string deathReason;
};
}

@ -22,6 +22,8 @@ namespace mwmp
{
PlayerPacket::Packet(bs, send);
RW(player->creatureStats.mDead, send);
RW(player->deathReason, send);
}
};
}

Loading…
Cancel
Save