Strange Autocast bug

I want to make a weapon that scales with the shards in the players possession in the most crude way of adding 1 fire damage for every fire shard

the straight forward idea of putting a <calculate> into the weapon didn't work because i couldn't find a tag to get the unit owner

but since even the devs had to build a work around for Pariden. I thought i might just copy that. Turns out it seem not possible to add an ability to a unit through a non consumable item, at least I couldn't find a way and all the core items that are supposed to do it ( like stealth boots) do not work as well, so i simply put the Autocast code block into the item.

And be hold my hero will cast at the beginning of each battle .. twice i guess it gets registered with the unit and then again from the weapon at the beginning of the battle, it also stacks with itself although being a non stack able spell.

I'm at a loss here does anybody have any ideas?

6,633 views 3 replies
Reply #1 Top

I have encountered this exact same issue. All BattleAutoCastSpell get triggered twice if put on an item.

I haven't tried this, but it should work. What if your first spell sets a unitstat_flagforcasted on the unit. Then, when the second spell is cast, it includes that number in the calculation.

 

Calc1 = Shard * number

Calc2 = unitstat_flagforcasted

Calc3 = Calc1 * Calc2

Calc4 = Calc1 - Calc3

 

3 shards, +1 for each

First cast:

3*1

0

3*0=0

3-0 = 3

 

Second cast:

3*1

1

3*1=3

3-3=0

Remember to create the unitstat like a new one, also the modifier for unitstat_flagforcasted should be after the modifier for the attack

+1 Loading…
Reply #2 Top

Two other ways that I used to circumvent this, but I don't think they'll be much help to you.

1) Instead of adjusting a unitstat, apply a new trait to the unit. Since the unit can't have the same trait more than once... anything inside the trait only gets applied once.

2) Instead of using AdjustUnitStat, use SetUnitStat. But then you can't change the number again in the battle.

Reply #3 Top

It was more a proof of concept i wanted to build, I'm still mapping out the possibilities within the xml before i decide on any real modding im going to do this post is mostly a result at my astonishment that  UnlockUnitAbility and BattleAutoCastSpell  are both horribly broken for items, even with items that are trying to use them lingering around in the CoreItems xml. I would have tried to fix it by simply halving the bonus and then let them ad as far as i have seen they use floats everywhere anyways. However I see a bigger problem coming when i want to use mage units that get their main damage from this kind of buff ( the staffs would only give multipliers). If they ever get into an auto fight where the Game seems not to use Spells they would die horribly. The main concern was to key mages to shards so they dont just feel like another archer unit

but thank you very much for your fast and elegant solution