From 32c7406eda5432d6b0db290fa0e87d5ccc0f3ac6 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Thu, 19 Dec 2019 13:53:18 +0200 Subject: [PATCH] [General] Implement OnObjectHit packet, part 3 Include damage, block states and knockdown states in ObjectHit packets about successful hits. Add serverside script functions for reading that information. --- apps/openmw-mp/Script/Functions/Objects.cpp | 15 ++++++++++ apps/openmw-mp/Script/Functions/Objects.hpp | 30 +++++++++++++++++++ .../Packets/Object/PacketObjectHit.cpp | 7 +++++ 3 files changed, 52 insertions(+) diff --git a/apps/openmw-mp/Script/Functions/Objects.cpp b/apps/openmw-mp/Script/Functions/Objects.cpp index 73cc90cf8..4a6a5e004 100644 --- a/apps/openmw-mp/Script/Functions/Objects.cpp +++ b/apps/openmw-mp/Script/Functions/Objects.cpp @@ -189,6 +189,21 @@ bool ObjectFunctions::GetObjectHitSuccess(unsigned int index) noexcept return readObjectList->baseObjects.at(index).hitAttack.success; } +double ObjectFunctions::GetObjectHitDamage(unsigned int index) noexcept +{ + return readObjectList->baseObjects.at(index).hitAttack.damage; +} + +bool ObjectFunctions::GetObjectHitBlock(unsigned int index) noexcept +{ + return readObjectList->baseObjects.at(index).hitAttack.block; +} + +bool ObjectFunctions::GetObjectHitKnockdown(unsigned int index) noexcept +{ + return readObjectList->baseObjects.at(index).hitAttack.knockdown; +} + bool ObjectFunctions::DoesObjectHavePlayerHitting(unsigned int index) noexcept { return readObjectList->baseObjects.at(index).hittingActor.isPlayer; diff --git a/apps/openmw-mp/Script/Functions/Objects.hpp b/apps/openmw-mp/Script/Functions/Objects.hpp index 66c656b3f..d8dfa2838 100644 --- a/apps/openmw-mp/Script/Functions/Objects.hpp +++ b/apps/openmw-mp/Script/Functions/Objects.hpp @@ -39,6 +39,9 @@ {"GetObjectActivatingName", ObjectFunctions::GetObjectActivatingName},\ \ {"GetObjectHitSuccess", ObjectFunctions::GetObjectHitSuccess},\ + {"GetObjectHitDamage", ObjectFunctions::GetObjectHitDamage},\ + {"GetObjectHitBlock", ObjectFunctions::GetObjectHitBlock},\ + {"GetObjectHitKnockdown", ObjectFunctions::GetObjectHitKnockdown},\ {"DoesObjectHavePlayerHitting", ObjectFunctions::DoesObjectHavePlayerHitting},\ {"GetObjectHittingPid", ObjectFunctions::GetObjectHittingPid},\ {"GetObjectHittingRefId", ObjectFunctions::GetObjectHittingRefId},\ @@ -427,6 +430,33 @@ public: */ static bool GetObjectHitSuccess(unsigned int index) noexcept; + /** + * \brief Get the damage caused to the object at a certain index in the read object list + * in a hit. + * + * \param index The index of the object. + * \return The damage. + */ + static double GetObjectHitDamage(unsigned int index) noexcept; + + /** + * \brief Check whether the object at a certain index in the read object list has + * blocked the hit on it. + * + * \param index The index of the object. + * \return The block state. + */ + static bool GetObjectHitBlock(unsigned int index) noexcept; + + /** + * \brief Check whether the object at a certain index in the read object list has been + * knocked down. + * + * \param index The index of the object. + * \return The knockdown state. + */ + static bool GetObjectHitKnockdown(unsigned int index) noexcept; + /** * \brief Check whether the object at a certain index in the read object list has been * hit by a player. diff --git a/components/openmw-mp/Packets/Object/PacketObjectHit.cpp b/components/openmw-mp/Packets/Object/PacketObjectHit.cpp index 5a45082ac..b82423446 100644 --- a/components/openmw-mp/Packets/Object/PacketObjectHit.cpp +++ b/components/openmw-mp/Packets/Object/PacketObjectHit.cpp @@ -44,6 +44,13 @@ void PacketObjectHit::Packet(RakNet::BitStream *newBitstream, bool send) RW(baseObject.hitAttack.success, send); + if (baseObject.hitAttack.success) + { + RW(baseObject.hitAttack.damage, send); + RW(baseObject.hitAttack.block, send); + RW(baseObject.hitAttack.knockdown, send); + } + if (!send) objectList->baseObjects.push_back(baseObject); }