forked from mirror/openmw-tes3mp
Detecting reason of death
This commit is contained in:
parent
6eae017561
commit
79532cf797
4 changed files with 50 additions and 9 deletions
|
@ -247,17 +247,22 @@ void Networking::Update(RakNet::Packet *packet)
|
||||||
{
|
{
|
||||||
myPacket->Read(player);
|
myPacket->Read(player);
|
||||||
|
|
||||||
#if defined(DEBUG)
|
Player *target = Players::GetPlayer(player->GetAttack()->target);
|
||||||
cout << "Player: " << player->Npc()->mName << " atk state: " << (player->GetAttack()->pressed == 1) <<
|
|
||||||
endl;
|
if (target == nullptr)
|
||||||
|
target = player;
|
||||||
|
|
||||||
|
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Player: %s attaked %s state: %d", player->Npc()->mName.c_str(),
|
||||||
|
target->Npc()->mName.c_str(), player->GetAttack()->pressed == 1);
|
||||||
if (player->GetAttack()->pressed == 0)
|
if (player->GetAttack()->pressed == 0)
|
||||||
{
|
{
|
||||||
cout << "success: " << (player->GetAttack()->success == 1);
|
LOG_APPEND(Log::LOG_VERBOSE, "success: %d", player->GetAttack()->success == 1);
|
||||||
if (player->GetAttack()->success == 1)
|
if (player->GetAttack()->success == 1)
|
||||||
cout << " damage: " << player->GetAttack()->damage;
|
{
|
||||||
cout << endl;
|
LOG_APPEND(Log::LOG_VERBOSE, "damage: %d", player->GetAttack()->damage == 1);
|
||||||
|
player->setLastAttackerID(target->GetID());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
myPacket->Send(player, true);
|
myPacket->Send(player, true);
|
||||||
controller->GetPacket(ID_GAME_DYNAMICSTATS)->RequestData(player->GetAttack()->target);
|
controller->GetPacket(ID_GAME_DYNAMICSTATS)->RequestData(player->GetAttack()->target);
|
||||||
|
@ -278,10 +283,23 @@ void Networking::Update(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());
|
||||||
|
|
||||||
|
short reason = 0; // unknown;
|
||||||
|
|
||||||
|
if (!killer)
|
||||||
|
killer = player;
|
||||||
|
else if(killer->GetID() == player->GetID())
|
||||||
|
reason = 2; //suicide
|
||||||
|
else
|
||||||
|
reason = 1; //killed
|
||||||
|
|
||||||
|
player->resetLastAttacker();
|
||||||
|
|
||||||
player->CreatureStats()->mDead = true;
|
player->CreatureStats()->mDead = true;
|
||||||
myPacket->Send(player, true);
|
myPacket->Send(player, true);
|
||||||
|
|
||||||
Script::Call<Script::CallbackIdentity("OnPlayerDeath")>(player->GetID());
|
Script::Call<Script::CallbackIdentity("OnPlayerDeath")>(player->GetID(), reason, killer->GetID());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,7 @@ Player::Player(RakNet::RakNetGUID id) : BasePlayer(id)
|
||||||
{
|
{
|
||||||
handshake = false;
|
handshake = false;
|
||||||
loaded = false;
|
loaded = false;
|
||||||
|
lastAttacker = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player::~Player()
|
Player::~Player()
|
||||||
|
@ -104,5 +105,22 @@ int Player::LoadedState()
|
||||||
|
|
||||||
Player *Players::GetPlayer(unsigned short id)
|
Player *Players::GetPlayer(unsigned short id)
|
||||||
{
|
{
|
||||||
|
if (slots.find(id) == slots.end())
|
||||||
|
return nullptr;
|
||||||
return slots[id];
|
return slots[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::setLastAttackerID(unsigned short pid)
|
||||||
|
{
|
||||||
|
lastAttacker = pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::resetLastAttacker()
|
||||||
|
{
|
||||||
|
lastAttacker = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned short Player::getLastAttackerID()
|
||||||
|
{
|
||||||
|
return lastAttacker;
|
||||||
|
}
|
||||||
|
|
|
@ -57,10 +57,15 @@ public:
|
||||||
void Loaded(int state);
|
void Loaded(int state);
|
||||||
int LoadedState();
|
int LoadedState();
|
||||||
|
|
||||||
|
void setLastAttackerID(unsigned short pid);
|
||||||
|
void resetLastAttacker();
|
||||||
|
unsigned short getLastAttackerID();
|
||||||
|
|
||||||
virtual ~Player();
|
virtual ~Player();
|
||||||
private:
|
private:
|
||||||
bool handshake;
|
bool handshake;
|
||||||
int loaded;
|
int loaded;
|
||||||
|
unsigned short lastAttacker;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //OPENMW_PLAYER_HPP
|
#endif //OPENMW_PLAYER_HPP
|
||||||
|
|
|
@ -98,7 +98,7 @@ public:
|
||||||
{"OnServerExit", Function<void, bool>()},
|
{"OnServerExit", Function<void, bool>()},
|
||||||
{"OnPlayerConnect", Function<bool, unsigned short>()},
|
{"OnPlayerConnect", Function<bool, unsigned short>()},
|
||||||
{"OnPlayerDisconnect", Function<void, unsigned short>()},
|
{"OnPlayerDisconnect", Function<void, unsigned short>()},
|
||||||
{"OnPlayerDeath", Function<void, unsigned short>()},
|
{"OnPlayerDeath", Function<void, unsigned short, short, unsigned short>()},
|
||||||
{"OnPlayerResurrect", Function<void, unsigned short>()},
|
{"OnPlayerResurrect", Function<void, unsigned short>()},
|
||||||
{"OnPlayerChangeCell", Function<void, unsigned short>()},
|
{"OnPlayerChangeCell", Function<void, unsigned short>()},
|
||||||
{"OnPlayerChangeAttributes", Function<void, unsigned short>()},
|
{"OnPlayerChangeAttributes", Function<void, unsigned short>()},
|
||||||
|
|
Loading…
Reference in a new issue