Post by vivere on Jun 4, 2021 15:50:06 GMT
Hello again, and once again thank you for the tutorial series. In the tutorial, in the Status Effects section, you introduced one way of adding status effects to units. Then, due to a fear of an explosion of classes, in the Ability Effects portion you also introduced the InflictAbilityEffect class using Reflection. Finally, you also introduced an example of a dependent ability effect with the Life Leech one. First, I am not even entirely certain I know how InflictAbilityEffect works because the code is hard for me to read. However, I do, I think, understand that its application chance has nothing to do with the rest of the ability effects hitting first and it is a self-contained effect with its own hit rate. Also in the Status Effects section, you talked about the idea of an "OnHitAddStatus" class and how, due to class explosion, it might make more sense to write something using Reflection (which later became InflictAbilityEffect). I'm currently trying to figure out how to do that. I want to be able to make abilities where I attack a target and, if that attack hits, I apply a status effect to either the attacker or the defender.
My general thoughts are that I would need to first have a dependent ability effect similar to the Life Leech (Absorb) one that you made, i.e. an ability effect that listens for if the attack hits or misses. Then, in the OnEffectHit, in addition to getting the damage amount of the effect, I would need to also post another notification that I want to apply a certain status effect. Let's call that notification HitAndNeedToApplyStatus for the sake of discussion, where the 'Status' part of that name was different for each status effect. Then, I would need another ability effect that was also a dependent ability effect like the Life Leech one. Instead of listening to hit notifications, it would listen for its corresponding HitAndNeedToApplyStatus notification.
So, say, I want an ability that, upon hitting, also blinds the target. I would have AttackIfHitBlindAbilityEffect that listens for HitNotification and has a trackedSiblingIndex of the child # of the hit rate, which would be 0. If the hit rate succeeds and thus posts a HitNotification, my AttackIfHitBlindAbilityEffect class applies damage and sends a HitAndNeedToApplyBlind notification. Then, I have a second ability effect which tracks AttackIfHitBlindAbilityEffect called HitSoApplyBlindAbilityEffect that listens for HitAndNeedToApplyBlind notification and has a trackedSiblingIndex of the child # of AttackIfHitBlindAbilityEffect, which would be 1.
After that part, if it is even right, I get confused on how to then use InflictAbilityEffect from AttackIfHitBlindAbilityEffect without attaching it to the ability. Also, having to have 2 different classes that listen for notifications seems like the same explosion of classes problem. I don't know how to marry InflictAbilityEffect and AttackIfHitBlindAbilityEffect, nor do I know how to apply the status effect otherwise without having the same explosion of classes problem you mentioned. This tells me that I'm thinking about it fundamentally incorrectly, which I don't doubt, though I don't know. My guess is that there is a better way to go about this that involves an actual dedicated class called OnHitAddStatus that somehow interacts with InflictAbilityEffect. I also have no idea how that class would look on a fundamental structural level. Would it be a subclass of InflictAbilityEffect? If so, I have no idea how that would work. Since your stated point for using Reflection and writing InflictAbilityEffect was so that you wouldn't have to write more than one class for applying status effects to targets, I'm confused how InflictAbilityEffect can be used to create an OnHitAddStatus class. I'm confused at this because InflictAbilityEffect is a class that uses Predict and OnApply from BaseAbilityEffect, meaning that you'd think it would be the first ability effect in a line of ability effects, if anything.
Also, when considering an attack that, if it hits, applies a status effect to the attacker instead of the defender(s) is another puzzle for me without having a class explosion or somehow marrying OnHitAddStatus with InflictAbilityEffect. Ideally, the solution would be something that doesn't care whether the status effect would be being applied to defender(s) or to the attacker.
So yeah, when you wrote the blog about InflictAbilityEffect removing the need for writing a bunch of classes for applying status effects, how did you envision it could be used for OnHitAddStatus? Additionally, how wrong are my thoughts on how it could be done, and what better way can you think of to do it? Thank you very much for your time and for reading this rather long post.
EDIT: My other idea was to use the AutoStatusController to listen for HitAndNeedToApplyBlind, or HitAndNeedToApplyEvasionUpToAttacker, or whatever else, but if I used that, I still don't understand how to apply the status effect from the AutoStatusController since it wouldn't be part of the ability prefab in that case. If it is possible to apply a status effect to a unit from AutoStatusController, it is not obvious to me, because the example of the KO'd status effect being applied by the AutoStatusController used a Stats.DidChangeNotification referencing stat types, and the whole AutoStatusController, at least in its current state, only has methods that deal with looking at stat types. Since status effects aren't stat types, I am unsure how you would go about adding functionality to the AutoStatusController to get status effects and apply them.
My general thoughts are that I would need to first have a dependent ability effect similar to the Life Leech (Absorb) one that you made, i.e. an ability effect that listens for if the attack hits or misses. Then, in the OnEffectHit, in addition to getting the damage amount of the effect, I would need to also post another notification that I want to apply a certain status effect. Let's call that notification HitAndNeedToApplyStatus for the sake of discussion, where the 'Status' part of that name was different for each status effect. Then, I would need another ability effect that was also a dependent ability effect like the Life Leech one. Instead of listening to hit notifications, it would listen for its corresponding HitAndNeedToApplyStatus notification.
So, say, I want an ability that, upon hitting, also blinds the target. I would have AttackIfHitBlindAbilityEffect that listens for HitNotification and has a trackedSiblingIndex of the child # of the hit rate, which would be 0. If the hit rate succeeds and thus posts a HitNotification, my AttackIfHitBlindAbilityEffect class applies damage and sends a HitAndNeedToApplyBlind notification. Then, I have a second ability effect which tracks AttackIfHitBlindAbilityEffect called HitSoApplyBlindAbilityEffect that listens for HitAndNeedToApplyBlind notification and has a trackedSiblingIndex of the child # of AttackIfHitBlindAbilityEffect, which would be 1.
After that part, if it is even right, I get confused on how to then use InflictAbilityEffect from AttackIfHitBlindAbilityEffect without attaching it to the ability. Also, having to have 2 different classes that listen for notifications seems like the same explosion of classes problem. I don't know how to marry InflictAbilityEffect and AttackIfHitBlindAbilityEffect, nor do I know how to apply the status effect otherwise without having the same explosion of classes problem you mentioned. This tells me that I'm thinking about it fundamentally incorrectly, which I don't doubt, though I don't know. My guess is that there is a better way to go about this that involves an actual dedicated class called OnHitAddStatus that somehow interacts with InflictAbilityEffect. I also have no idea how that class would look on a fundamental structural level. Would it be a subclass of InflictAbilityEffect? If so, I have no idea how that would work. Since your stated point for using Reflection and writing InflictAbilityEffect was so that you wouldn't have to write more than one class for applying status effects to targets, I'm confused how InflictAbilityEffect can be used to create an OnHitAddStatus class. I'm confused at this because InflictAbilityEffect is a class that uses Predict and OnApply from BaseAbilityEffect, meaning that you'd think it would be the first ability effect in a line of ability effects, if anything.
Also, when considering an attack that, if it hits, applies a status effect to the attacker instead of the defender(s) is another puzzle for me without having a class explosion or somehow marrying OnHitAddStatus with InflictAbilityEffect. Ideally, the solution would be something that doesn't care whether the status effect would be being applied to defender(s) or to the attacker.
So yeah, when you wrote the blog about InflictAbilityEffect removing the need for writing a bunch of classes for applying status effects, how did you envision it could be used for OnHitAddStatus? Additionally, how wrong are my thoughts on how it could be done, and what better way can you think of to do it? Thank you very much for your time and for reading this rather long post.
EDIT: My other idea was to use the AutoStatusController to listen for HitAndNeedToApplyBlind, or HitAndNeedToApplyEvasionUpToAttacker, or whatever else, but if I used that, I still don't understand how to apply the status effect from the AutoStatusController since it wouldn't be part of the ability prefab in that case. If it is possible to apply a status effect to a unit from AutoStatusController, it is not obvious to me, because the example of the KO'd status effect being applied by the AutoStatusController used a Stats.DidChangeNotification referencing stat types, and the whole AutoStatusController, at least in its current state, only has methods that deal with looking at stat types. Since status effects aren't stat types, I am unsure how you would go about adding functionality to the AutoStatusController to get status effects and apply them.