- Joined
- May 9, 2014
- Messages
- 1,810
I would suggest a slightly-more elegant approach, involving the unit's base damage, though it relies on the gameplay constant Damage Bonus per Attribute not being equal to 0, while the native
Before performing a check, let's make sure that the unit is a Hero. If not, return a default null expression of your choice.
If the unit's type's primary stat attribute has already been obtained, just return the result from it. Otherwise, get the unit's base damage from both indices (do not assume that only 1 will ever be used). Store those, because we'll need it later.
Now, we temporarily increment the Strength of the Hero by 1. If the current base damage is not equal to the previously stored base damage, we flag that as the main attribute. Then, with or without Strength being the main attribute, we decrement the Strength of the Hero by 1 (to counteract the addition operation earlier). Repeat with Agility and Intelligence.
Once we get the appropriate stat attribute, we then store it in a hashtable, and return the value.
GetHeroPrimaryAttribute
has not been publicly exposed. (This is based on the common.j file in 1.30.1)Before performing a check, let's make sure that the unit is a Hero. If not, return a default null expression of your choice.
If the unit's type's primary stat attribute has already been obtained, just return the result from it. Otherwise, get the unit's base damage from both indices (do not assume that only 1 will ever be used). Store those, because we'll need it later.
Now, we temporarily increment the Strength of the Hero by 1. If the current base damage is not equal to the previously stored base damage, we flag that as the main attribute. Then, with or without Strength being the main attribute, we decrement the Strength of the Hero by 1 (to counteract the addition operation earlier). Repeat with Agility and Intelligence.
Once we get the appropriate stat attribute, we then store it in a hashtable, and return the value.