Jump to content

[Patch] Store tapping dynflags in UpdateEntry case


Schmoozerd

Recommended Posts

What bug does the patch fix? What features does the patch add?

Store the tapped-dynflags in case of Update Entry

For which repository revision was the patch created?

10607

Is there a thread in the bug report section or at lighthouse? If yes, please add a link to the thread.

http://www.scriptdev2.com/project.php?issueid=1120

none else seen around

Who has been writing this patch? Please include either forum user names or email addresses.

me

This patch is very fresh and not very thoughtfull, but I have the feeling that it is the right thing to store tapped information in such a case

Might be possible,

that UNIT_DYNFLAG_TRACK_UNIT (Hunters-mark and similar)

or UNIT_DYNFLAG_REFER_A_FRIEND (unused?, at least unknown for me)

should also be stored

Bug Description:

If a tapped npc UpdatesEntry, the Dynflags are resetted to new entry's dynflags, and so the tapped dynflag is overwritten, and the Updated npc cannot be lootet anymore.

Example: NPC 10812 which Updates whilest the fight (need sd2 installed)

Patch:

diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp
index 183b765..be23f1d 100644
--- a/src/game/Creature.cpp
+++ b/src/game/Creature.cpp
@@ -325,7 +325,17 @@ bool Creature::UpdateEntry(uint32 Entry, uint32 team, const CreatureData *data,

    SetUInt32Value(UNIT_FIELD_FLAGS, unitFlags);

+    // Tapping related dynflags should be stored
+    uint32 origDynamicFlags = GetUInt32Value(UNIT_DYNAMIC_FLAGS);
+    // Update Dynamic Flags
    SetUInt32Value(UNIT_DYNAMIC_FLAGS,GetCreatureInfo()->dynamicflags);
+    // Restore tapping if npc was tapped
+    if (origDynamicFlags & UNIT_DYNFLAG_TAPPED)
+        SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TAPPED);
+    if (origDynamicFlags & UNIT_DYNFLAG_TAPPED_BY_PLAYER)
+        SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TAPPED_BY_PLAYER);
+    if (origDynamicFlags & UNIT_DYNFLAG_TAPPED_BY_ALL_THREAT_LIST)
+        SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TAPPED_BY_ALL_THREAT_LIST);

    SetModifierValue(UNIT_MOD_ARMOR,             BASE_VALUE, float(GetCreatureInfo()->armor));
    SetModifierValue(UNIT_MOD_RESISTANCE_HOLY,   BASE_VALUE, float(GetCreatureInfo()->resistance1));

Edit: Alternative Version, _should_ do the same, in my view worse to read, but smaller code:

diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp
index 183b765..b5f713d 100644
--- a/src/game/Creature.cpp
+++ b/src/game/Creature.cpp
@@ -325,7 +325,9 @@ bool Creature::UpdateEntry(uint32 Entry, uint32 team, const CreatureData *data,

    SetUInt32Value(UNIT_FIELD_FLAGS, unitFlags);

-    SetUInt32Value(UNIT_DYNAMIC_FLAGS,GetCreatureInfo()->dynamicflags);
+    // Tapping related dynflags should be stored (default | (original & (tapped1 | tapped2 | tapped3)))
+    SetUInt32Value(UNIT_DYNAMIC_FLAGS, GetCreatureInfo()->dynamicflags | (GetUInt32Value(UNIT_DYNAMIC_FLAGS) &
+        (UNIT_DYNFLAG_TAPPED | UNIT_DYNFLAG_TAPPED_BY_PLAYER | UNIT_DYNFLAG_TAPPED_BY_ALL_THREAT_LIST)));

    SetModifierValue(UNIT_MOD_ARMOR,             BASE_VALUE, float(GetCreatureInfo()->armor));
    SetModifierValue(UNIT_MOD_RESISTANCE_HOLY,   BASE_VALUE, float(GetCreatureInfo()->resistance1));

Link to comment
Share on other sites

second version much better, you may split it into parts to make it look better:

// Tapping related dynflags should be stored
uint32 origDynamicFlags = GetUInt32Value(UNIT_DYNAMIC_FLAGS) & (UNIT_DYNFLAG_TAPPED|UNIT_DYNFLAG_TAPPED_BY_PLAYER|UNIT_DYNFLAG_TAPPED_BY_ALL_THREAT_LIST);
// Update Dynamic Flags
SetUInt32Value(UNIT_DYNAMIC_FLAGS,GetCreatureInfo()->dynamicflags | origDynamicFlags);

sadly, but there are o lot of values that shouldn't be modified( need modify base values only, and do not reset modifiers - cause they are came from auras):

like speed rates, object scale, resistances etc

Link to comment
Share on other sites

  • 2 weeks later...

I don't see any reason to not preserve any of the existing flags if they exist. In other words:

// preserve all current dynamic flags if exist
uint32 dynFlags = GetUInt32Value(UNIT_DYNAMIC_FLAGS);
SetUInt32Value(UNIT_DYNAMIC_FLAGS, dynFlags ? dynFlags : GetCreatureInfo()->dynamicflags);

More clean and probably most proper for this case.

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use