mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:53:51 +00:00
Change logic for death reasons so it makes sense
This commit is contained in:
parent
9c12aa2141
commit
eebe1f156a
3 changed files with 31 additions and 9 deletions
|
@ -242,7 +242,8 @@ void Networking::ProcessPlayerPacket(RakNet::Packet *packet)
|
||||||
if (player->GetAttack()->success == 1)
|
if (player->GetAttack()->success == 1)
|
||||||
{
|
{
|
||||||
LOG_APPEND(Log::LOG_VERBOSE, "damage: %d", player->GetAttack()->damage == 1);
|
LOG_APPEND(Log::LOG_VERBOSE, "damage: %d", player->GetAttack()->damage == 1);
|
||||||
player->setLastAttackerID(target->GetID());
|
target->setLastAttackerId(player->GetID());
|
||||||
|
target->setLastAttackerTime(std::chrono::steady_clock::now());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,19 +266,24 @@ void Networking::ProcessPlayerPacket(RakNet::Packet *packet)
|
||||||
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_GAME_DIE from %s",
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_GAME_DIE from %s",
|
||||||
player->Npc()->mName.c_str());
|
player->Npc()->mName.c_str());
|
||||||
|
|
||||||
Player *killer = Players::GetPlayer(player->getLastAttackerID());
|
Player *killer = Players::GetPlayer(player->getLastAttackerId());
|
||||||
|
|
||||||
short reason = 0; // unknown;
|
short reason = 0; // unknown;
|
||||||
|
int secondsSinceLastAttacker = std::chrono::duration_cast<std::chrono::duration<double>>(
|
||||||
|
std::chrono::steady_clock::now() - player->getLastAttackerTime()).count();
|
||||||
|
|
||||||
if (!killer)
|
if (!killer)
|
||||||
killer = player;
|
killer = player;
|
||||||
else if (killer->GetID() == player->GetID())
|
else if (secondsSinceLastAttacker < 3)
|
||||||
reason = 2; //suicide
|
reason = 1; // killed
|
||||||
else
|
else
|
||||||
reason = 1; //killed
|
reason = 2; //suicide
|
||||||
|
|
||||||
player->resetLastAttacker();
|
player->resetLastAttacker();
|
||||||
|
|
||||||
|
printf("Time since last attack time for %i: %i\n", player->GetID(),
|
||||||
|
secondsSinceLastAttacker);
|
||||||
|
|
||||||
player->CreatureStats()->mDead = true;
|
player->CreatureStats()->mDead = true;
|
||||||
myPacket->Send(player, true);
|
myPacket->Send(player, true);
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ Player *Players::GetPlayer(unsigned short id)
|
||||||
return slots[id];
|
return slots[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::setLastAttackerID(unsigned short pid)
|
void Player::setLastAttackerId(unsigned short pid)
|
||||||
{
|
{
|
||||||
lastAttacker = pid;
|
lastAttacker = pid;
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,17 @@ void Player::resetLastAttacker()
|
||||||
lastAttacker = id;
|
lastAttacker = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned short Player::getLastAttackerID()
|
unsigned short Player::getLastAttackerId()
|
||||||
{
|
{
|
||||||
return lastAttacker;
|
return lastAttacker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::setLastAttackerTime(std::chrono::steady_clock::time_point time)
|
||||||
|
{
|
||||||
|
lastAttackerTime = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::chrono::steady_clock::time_point Player::getLastAttackerTime()
|
||||||
|
{
|
||||||
|
return lastAttackerTime;
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <chrono>
|
||||||
#include <RakNetTypes.h>
|
#include <RakNetTypes.h>
|
||||||
|
|
||||||
#include <components/esm/npcstats.hpp>
|
#include <components/esm/npcstats.hpp>
|
||||||
|
@ -57,9 +58,12 @@ public:
|
||||||
void Loaded(int state);
|
void Loaded(int state);
|
||||||
int LoadedState();
|
int LoadedState();
|
||||||
|
|
||||||
void setLastAttackerID(unsigned short pid);
|
void setLastAttackerId(unsigned short pid);
|
||||||
void resetLastAttacker();
|
void resetLastAttacker();
|
||||||
unsigned short getLastAttackerID();
|
unsigned short getLastAttackerId();
|
||||||
|
|
||||||
|
void setLastAttackerTime(std::chrono::steady_clock::time_point time);
|
||||||
|
std::chrono::steady_clock::time_point getLastAttackerTime();
|
||||||
|
|
||||||
virtual ~Player();
|
virtual ~Player();
|
||||||
public:
|
public:
|
||||||
|
@ -68,6 +72,8 @@ private:
|
||||||
bool handshake;
|
bool handshake;
|
||||||
int loaded;
|
int loaded;
|
||||||
unsigned short lastAttacker;
|
unsigned short lastAttacker;
|
||||||
|
std::chrono::steady_clock::time_point lastAttackerTime;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //OPENMW_PLAYER_HPP
|
#endif //OPENMW_PLAYER_HPP
|
||||||
|
|
Loading…
Reference in a new issue