From 3835a214920b77192efeada596bbefedacae2998 Mon Sep 17 00:00:00 2001 From: Sebastian Mihalache Date: Thu, 30 Jan 2025 13:51:37 +0200 Subject: [PATCH] Multiplayer explosion --- DeadZone/source/Client/Client.cpp | 5 ++--- DeadZone/source/Entity/Bullet/ThrownGrenade.h | 3 +++ DeadZone/source/Server/Server.cpp | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/DeadZone/source/Client/Client.cpp b/DeadZone/source/Client/Client.cpp index 8244653..c73f366 100644 --- a/DeadZone/source/Client/Client.cpp +++ b/DeadZone/source/Client/Client.cpp @@ -485,14 +485,13 @@ void Client::sendBullet(const std::shared_ptr& const entity) } nlohmann::json jsonData; - jsonData["bullet"]["isThrownGrenade"] = isThrownGrenade; jsonData["bullet"]["x"] = entity->getX(); jsonData["bullet"]["y"] = entity->getY(); jsonData["bullet"]["rotateAngle"] = entity->getRotateAngle(); jsonData["bullet"]["speed"] = entity->getSpeed(); - jsonData["bullet"]["textureName2D"] = entity->getTextureName2D(); - jsonData["bullet"]["damage"] = entity->getDamage(); + jsonData["bullet"]["textureName2D"] = entity->getTextureName2D(); + jsonData["bullet"]["damage"] = isThrownGrenade ? std::dynamic_pointer_cast(entity)->getExplosionDamage() : entity->getDamage(); // TODO: trimite si ceilalti parametrii daca vrem sa avem mai multi modificatori diff --git a/DeadZone/source/Entity/Bullet/ThrownGrenade.h b/DeadZone/source/Entity/Bullet/ThrownGrenade.h index 6b42b0f..578b4fb 100644 --- a/DeadZone/source/Entity/Bullet/ThrownGrenade.h +++ b/DeadZone/source/Entity/Bullet/ThrownGrenade.h @@ -27,4 +27,7 @@ class ThrownGrenade : public virtual Bullet virtual void update() override; virtual void onCollide(CollidableEntity& other, glm::vec2 overlap) override; + + // Getters + double getExplosionDamage() const { return explosionDamage; } }; \ No newline at end of file diff --git a/DeadZone/source/Server/Server.cpp b/DeadZone/source/Server/Server.cpp index 18cabcc..817bc6d 100644 --- a/DeadZone/source/Server/Server.cpp +++ b/DeadZone/source/Server/Server.cpp @@ -476,7 +476,7 @@ void Server::update() jsonData["bullets"][otherConnectedClient.first]["rotateAngle"] = otherConnectedClient.second.bulletData.get()->getRotateAngle(); jsonData["bullets"][otherConnectedClient.first]["speed"] = otherConnectedClient.second.bulletData.get()->getSpeed(); jsonData["bullets"][otherConnectedClient.first]["textureName2D"] = otherConnectedClient.second.bulletData.get()->getTextureName2D(); - jsonData["bullets"][otherConnectedClient.first]["damage"] = otherConnectedClient.second.bulletData.get()->getDamage(); + jsonData["bullets"][otherConnectedClient.first]["damage"] = std::dynamic_pointer_cast(otherConnectedClient.second.bulletData)->getExplosionDamage(); } // closeRangeDamage