Dynamic Action Speed Formula

By default, action speed is based on agility.  But let's say I decide to cast a fireball spell. In this case, I want my action speed to be based on my MAT parameter, not the AGI parameter.


So what I'm looking for is a way to specify, for a particular skill type, that a different action speed formula be used.


Example:  


Player has 20 agility and 40 MAT.


Enemy has 30 agility and 50 MAT.


If the player and enemy both use basic attack, the enemy should act first (because 30 > 20).


If the player uses a magic spell and the enemy uses a basic attack, the player should act first (because 40 > 30).


If the player and enemy both use magic spells, the enemy should act first (because 50 > 40).


Basically, if you use a magic spell, then it looks at your MAT and not your AGI as the value to determine action speed.  


Not sure how simple or difficult this plugin would be to write, but it would be greatly appreciated!  Also, I would want it to be compatible with Yanfly's Battle Engine. Thank you in advance.

Original thread: https://forums.rpgmakerweb.com/threads/dynamic-action-speed-formula.55290/