From 04acfd96a044a84bd471481ce123e7a2cba9ad26 Mon Sep 17 00:00:00 2001 From: Anton Popovichenko Date: Fri, 5 Jul 2024 20:42:22 +0200 Subject: [PATCH] fix(Core/Unit): Invalidate update object cache when changing health in the same world update tick. (#19287) * fix(Core/Unit): Invalidate update object cache when changing health in the same world update tick. Should fix an issue when the client sees dead NPCs when they are not. * Fix styling * Another codestyle fix --- src/server/game/Entities/Unit/Unit.cpp | 14 ++++++++++++++ src/server/game/Entities/Unit/Unit.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index a53d70545..57d770907 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -21628,6 +21628,20 @@ bool Unit::IsInDisallowedMountForm() const return false; } +void Unit::SetUInt32Value(uint16 index, uint32 value) +{ + Object::SetUInt32Value(index, value); + + switch (index) + { + // Invalidating the cache on health change should fix an issue where the client sees dead NPCs when they are not. + // We might also need to invalidate the cache for some other fields as well. + case UNIT_FIELD_HEALTH: + InvalidateValuesUpdateCache(); + break; + } +} + std::string Unit::GetDebugInfo() const { std::stringstream sstr; diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index 16dc4f605..106a35eed 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -1571,6 +1571,8 @@ public: void ApplyAttackTimePercentMod(WeaponAttackType att, float val, bool apply); void ApplyCastTimePercentMod(float val, bool apply); + void SetUInt32Value(uint16 index, uint32 value); + UnitFlags GetUnitFlags() const { return UnitFlags(GetUInt32Value(UNIT_FIELD_FLAGS)); } bool HasUnitFlag(UnitFlags flags) const { return HasFlag(UNIT_FIELD_FLAGS, flags); } void SetUnitFlag(UnitFlags flags) { SetFlag(UNIT_FIELD_FLAGS, flags); }