Instead of using dummy buffs, I'd have these items/abilities use OnAbilityAdded/OnRemoveAbility functions to set up a table on the affected unit. Then you can just query table entries directly-- which is much faster-- instead of having to go through the buff system. Example:
Code: c++
- OnAbilityAdded = function(self, unit)
- if not unit.FavorModData then
- unit.FavorModData = {}
- end
- unit.FavorModData[self.Name] = true
- end,
- RemoveAbility = function(self, unit)
- unit.FavorModData[self.Name] = false
- end,
So to find out whether or not a unit has this item/ability, we first check 'if unit.FavorModData then', and then check 'if unit.FavorModData.AbilityName then' and run appropriate code. 'AbilityName' is obviously the name of the ability, which these functions dynamically set by referring to self.Name (self being the ability blueprint in this case). You should be able to pretty much copy-paste this set of functions right into any item ability that you want to do external stuff with.
DoTakeDamage is the place you want to do this, for damage abilities. I dunno if you know how to hook a unit class, so I'll run through that real quickly - this would go in hook\lua\sim\ForgeUnit.lua:
Code: c++
- local prevClass = ForgeUnit
- ForgeUnit = Class(prevClass) {
- DoTakeDamage = function(self, data)
- --Do our new damage stuff here
- prevClass.DoTakeDamage(self, data)
- end,
- }
Now, for example, if you want to add the Arcane Mastery damage, you can do that non-destructively here. Lemme see if I can just quickly translate that into this hook:
Code: c++
- DoTakeDamage = function(self, data)
- --Check for FavorMod ability data on instigator
- if data.Instigator and IsUnit(data.Instigator) and not data.Instigator:IsDead() and data.Instigator.FavorModData then
- --Create a local ref to instigator's FavorModData
- local FavorModData = data.Instigator.FavorModData
- local originaldamage = data.Amount
- --Arcane Mastery
- if FavorModData.AchievementArcaneMastery and data.Type == 'Spell' or data.Type == 'SpellFire' then
- if Random(1, 100) > 79 then
- data.Amount = data.Amount + ((originaldamage * 2) - originaldamage))
- #LOG("GOT DAMAGE BONUS ACHIEVEMENT")
- --What does this do?
- damagebuff = 2
- end
- end
- end
- prevClass.DoTakeDamage(self, data)
- end,
I don't know what 'damagebuff' does, since that part of your code wasn't included, but hopefully you should understand where I'm going with this. Ability crits can be done here too - just look for the crit ability's flag, calculate and add your extra damage, and set data.IsCrit = true. The latter will turn the float text yellow, and fire the instigator's OnCriticalHit callbacks.
Also notice how I changed the way it calculates damage, to copy the way crits do it. This way it will add each of the extra damage amounts together, and you can change the multiplier of each without breaking anything.