Problem is:
PHP:
if(getAnimator() != nullptr)
return getAnimator()->getPhase();
getAnimator() is defined in
thing.h:
PHP:
AnimatorPtr getAnimator() { return rawGetThingType()->getAnimator(); }
Which means, it will take
Animator from
rawGetThingType(), which is defined in
effect.cpp:
PHP:
ThingType *Effect::rawGetThingType()
{
return g_things.rawGetThingType(m_id, ThingCategoryEffect);
}
Which means, it will return same
Animator object for all
Effects with same m_id (effect id).
1. I would define 'AnimatorPtr m_effectAnimator' in
effect.h
2. In
Effect:nAppear() I would clone
Animator from
getAnimator() to
m_effectAnimator . We got AnimatorPtr, which contains inside pointer to Animator, a bit weird for me, I dont' knowe how to copy it 'deep'.
3. Then you need to reset values of
m_effectAnimator clone (maybe call
resetAnimation of Animator?).
4. Important part of 'effect' is that it disappears after animation. Now there is a code in
onAppear:
PHP:
// schedule removal
auto self = asEffect();
g_dispatcher.scheduleEvent([self]() { g_map.removeThing(self); }, m_phaseDuration * getAnimationPhases());
Which uses constant animation speed and count frames:
m_phaseDuration * getAnimationPhases()
Now you got to calculate time of
Animator (sum all 'phaseDurations' ? ) and set valid time to remove effect from game.
-------------------------
If you plan to make your code public, you should not use
Animator (just copy some of it's values to new variables in
effect.h) and put 'something like animator code' in
effect.cpp
Animator is designed to show infinite animations of items, loops in forward/backward order.
Effect play all frames of animation only once.
You should also remember that OTClient must support old clients with simple effect animations (no animator).