"Having a small difficulty, with displaying the correct damage dealt. I added a damage modifier based on the character type. For example if the unit type is Knight, the hp lost from a hit is reduced 25%. I simply listen for onhpdidchange, then if knight reduce25. If a mage add 25. The damage taken seems to actually subtract correctly, however the damage amount shown on the screen is the predict amount.
Could be a few things. For example, if you wait to modify the damage dealt until after a HP change notification, then that is probably too late. I would try observing a different notification such as a when determining the amount of damage to inflict in the first place. I would expect to see those kinds of modifiers already factored in to the predicted amount. There are a variety of notifications for getting stats and determining attack power based on the attacker and target for these purposes.
Even if you still want to wait and only modify based on damage dealt, then I would next suggest you try observing the “WillChangeNotification” of the HP instead of the “DidChangeNotification”. This is one last chance to modify the values before they are truly applied. Then when you go to display the final value, it should already have been correctly determined.
Also, make sure the label, or whatever it is, which displays the damage dealt is listening to the correct notification. I would want to listen to something which tells me the amount of damage that was applied, not the actual amount of HP lost. For example, say you do a really strong attack that has a damage force of 9999, but the target only had 1 hitpoint. I would care more about seeing the strength of my attack than the mere amount of HP I could reduce.
"Thank you for the feedback! I checked again and as you said, I actually had already set to listen to the OnHPWillChange, Stats.WillChangeNotification(StatTypes.hp)
Was trying base it off of the haste effect mostly. In the baseabilityeffect when I set the new hit rate info, I think that I need to update here somehow. It seems that in the predict function the getstat for damage is not applying my modification."
"So after some back and forth I may be getting further from the goal.
Just to walk through and get my thoughts clear,
So the unit has a new script on it called element. Element gives the unit an element type, and a weakness automatically via dictionary Enums. (This works out well and seems to function as intended.)
Right now it listens to OnHPWillChange and adjusts for elemental strength/weakness accordingly. (This works fine, damage is dealt as expected.)
The predict part of an ability however does not take the element into effect.
Since the hit rate floating message is based off of the predict, not the actual amount dealt, the numbers do not match up.
I feel that it should go here in predict somehow, then not register the OnHPWillChange listener. Basically it will just be an added 10% bonus or penalty for various elements.
Is there an example of something like this? I am just not very sure I understand the exceptions system that is in place for calculating the attack damage. Perhaps my logic is missing something somewhere?"
1. The predicted amount of damage is intentionally not the actual amount of damage. Look in the `DamageAbilityEffect` `OnApply` method. After the predicted damage is determined, an additional random variance of damage is also applied. This was part of the game design. 2. The Stats.WillChangeNotification(StatTypes.hp) is not invoked, and not intended to be invoked, as part of the process of predicting damage in an attack. It is only intended to be used while actually applying the damage, such as after the attack has been performed. 3. To make sure that the appropriate amount of damage is dealt AND displayed by a prediction, then I would recommend working it into an observation of either BaseAbilityEffect's `GetAttackNotification` or `GetDefenseNotification`. The user info that is posted with both will be an object that has a reference to the attacker, target, and a list of ValueModifiers. So, for example, you could observe the notification in a "Job" component, where the attacker would see the notification attacker was itself, then determine the attack modifiers to apply based on its job type vs the target job type, and append a ValueModifier accordingly.
Make sure to re-read the lesson on Stats, it was the lesson that introduced the Value Modifiers, and it provides a "Test & Demo" section that shows how to use them to stop changes, manually specify changes, or even proportionally modify changes. Hopefully it will help.
Ok, so I made a call in the predict function to the element on the unit, which calculates and returns the bonus modification. All things works and run smoothly, but I definitely need to recheck notifications for the damage stacking. Feels like I will definitely need to refactor it later once I understand it better.
I think I follow what you mean, thank you for the hint!!! I will follow up on this in the next few days.