This commit is contained in:
MarcEricMartel 2023-12-06 13:42:15 -05:00
parent 1762043757
commit c47b36726b
3 changed files with 16 additions and 10 deletions

View File

@ -284,6 +284,9 @@ bool Player::AmIDead()
void Player::InflictDamage(float hitPoints) {
m_hp -= hitPoints;
if (m_hp < 0)
m_hp == 0;
//if (AmIDead())
//{ // Quand le joueur est mort.
//}

View File

@ -218,7 +218,7 @@ void Server::Run() {
int timer = m_game.countdown, sync_acc = 0, deadplayers = 0;
std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();
Timestamp last = 0;
std::vector<Chat> chatlog;
std::vector<Chat*> chatlog;
std::vector<ChunkMod*> chunkdiffs;
std::vector<Bullet*> bullets, outbox_bullets;
std::vector<BulletAdd*> netbull;
@ -237,6 +237,7 @@ void Server::Run() {
std::string str = "Timer: ";
Log(str.append(std::to_string(timer).append(" SyncAcc: ").append(std::to_string(sync_acc))), false, false);
}
last = tstamp;
for (auto& [key, conn] : m_conns) {
@ -258,8 +259,8 @@ void Server::Run() {
if (Deserialize(&sync, pck, &bsize)) {}
break;
case CHAT:
if (Deserialize(&chat, pck, &bsize))
chatlog.push_back(chat);
//if (Deserialize(&chat, pck, &bsize))
//chatlog.push_back(chat);
break;
default: break;
}
@ -272,17 +273,17 @@ void Server::Run() {
Timestamp tstamp = conn->Run(m_world);
if (conn->player->AmIDead() && tstamp) {
Chat chat;
chat.dest_id = chat.dest_team_id = chat.src_id = 0;
Chat* chat = new Chat();
chat->dest_id = chat->dest_team_id = chat->src_id = 0;
std::string killer = m_conns.at(key)->player->GetUsername();
std::string mess = getDeathMessage(conn->player->GetUsername(), killer);
strcpy(chat.mess, 140, mess.c_str());
Log("You is dead", false, false);
strcpy(chat->mess, 140, mess.c_str());
Log(mess, false, false);
m_chatlog[tstamp] = chat;
chatlog.emplace_back(chat);
++deadplayers;
conn->m_nsync == false;
}
@ -329,9 +330,10 @@ void Server::Run() {
}
for (auto& chat : chatlog) {
Log(chat.mess, false, false);
Log(chat->mess, false, false);
for (auto& [key, conn] : m_conns)
sendPackTo<Chat>(m_sock_udp, &chat, &m_buf, conn->getAddr());
sendPackTo<Chat>(m_sock_udp, chat, &m_buf, conn->getAddr());
delete chat;
}
for (auto& chmo : chunkdiffs) {

View File

@ -1422,6 +1422,7 @@ void Engine::Render(float elapsedTime) {
Sync comp = m_syncs[sync.timestamp];
m_player.InflictDamage(sync.hp - comp.hp);
Vector3f diff = sync.position - comp.position;
if (diff.y < 1.)