Change logic for death reasons so it makes sense

pull/112/merge
David Cernat 8 years ago
parent 9c12aa2141
commit eebe1f156a

@ -242,7 +242,8 @@ void Networking::ProcessPlayerPacket(RakNet::Packet *packet)
if (player->GetAttack()->success == 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",
player->Npc()->mName.c_str());
Player *killer = Players::GetPlayer(player->getLastAttackerID());
Player *killer = Players::GetPlayer(player->getLastAttackerId());
short reason = 0; // unknown;
int secondsSinceLastAttacker = std::chrono::duration_cast<std::chrono::duration<double>>(
std::chrono::steady_clock::now() - player->getLastAttackerTime()).count();
if (!killer)
killer = player;
else if (killer->GetID() == player->GetID())
reason = 2; //suicide
else if (secondsSinceLastAttacker < 3)
reason = 1; // killed
else
reason = 1; //killed
reason = 2; //suicide
player->resetLastAttacker();
printf("Time since last attack time for %i: %i\n", player->GetID(),
secondsSinceLastAttacker);
player->CreatureStats()->mDead = true;
myPacket->Send(player, true);

@ -109,7 +109,7 @@ Player *Players::GetPlayer(unsigned short id)
return slots[id];
}
void Player::setLastAttackerID(unsigned short pid)
void Player::setLastAttackerId(unsigned short pid)
{
lastAttacker = pid;
}
@ -119,7 +119,17 @@ void Player::resetLastAttacker()
lastAttacker = id;
}
unsigned short Player::getLastAttackerID()
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;
}

@ -7,6 +7,7 @@
#include <map>
#include <string>
#include <chrono>
#include <RakNetTypes.h>
#include <components/esm/npcstats.hpp>
@ -57,9 +58,12 @@ public:
void Loaded(int state);
int LoadedState();
void setLastAttackerID(unsigned short pid);
void setLastAttackerId(unsigned short pid);
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();
public:
@ -68,6 +72,8 @@ private:
bool handshake;
int loaded;
unsigned short lastAttacker;
std::chrono::steady_clock::time_point lastAttackerTime;
};
#endif //OPENMW_PLAYER_HPP

Loading…
Cancel
Save