Detecting reason of death

pull/78/head
Koncord 8 years ago
parent 6eae017561
commit 79532cf797

@ -247,17 +247,22 @@ void Networking::Update(RakNet::Packet *packet)
{
myPacket->Read(player);
#if defined(DEBUG)
cout << "Player: " << player->Npc()->mName << " atk state: " << (player->GetAttack()->pressed == 1) <<
endl;
Player *target = Players::GetPlayer(player->GetAttack()->target);
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)
{
cout << "success: " << (player->GetAttack()->success == 1);
LOG_APPEND(Log::LOG_VERBOSE, "success: %d", 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);
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",
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;
myPacket->Send(player, true);
Script::Call<Script::CallbackIdentity("OnPlayerDeath")>(player->GetID());
Script::Call<Script::CallbackIdentity("OnPlayerDeath")>(player->GetID(), reason, killer->GetID());
break;
}

@ -65,6 +65,7 @@ Player::Player(RakNet::RakNetGUID id) : BasePlayer(id)
{
handshake = false;
loaded = false;
lastAttacker = 0;
}
Player::~Player()
@ -104,5 +105,22 @@ int Player::LoadedState()
Player *Players::GetPlayer(unsigned short id)
{
if (slots.find(id) == slots.end())
return nullptr;
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);
int LoadedState();
void setLastAttackerID(unsigned short pid);
void resetLastAttacker();
unsigned short getLastAttackerID();
virtual ~Player();
private:
bool handshake;
int loaded;
unsigned short lastAttacker;
};
#endif //OPENMW_PLAYER_HPP

@ -98,7 +98,7 @@ public:
{"OnServerExit", Function<void, bool>()},
{"OnPlayerConnect", Function<bool, 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>()},
{"OnPlayerChangeCell", Function<void, unsigned short>()},
{"OnPlayerChangeAttributes", Function<void, unsigned short>()},

Loading…
Cancel
Save