Changes to Affect Modifiers

Handling a skill or spell with multiple modifiers in code has always been a bit of a nuisance.  I changed that around a bit so that they work they way I want them to.

So, here’s what adding three effects looked like in code beforehand:

Affect af = new Affect( Affect.AffectType.spell, spell.Name, 12 + level / 4, Affect.Apply.intelligence, 3, Affect.AFFECT_NONE );
victim.AddAffect(af);
af.ApplyType = Affect.Apply.constitution;
af.Amount = 8;
victim.AddAffect(af);
af.ApplyType = Affect.Apply.dexterity;
af.Amount = -5;
victim.AddAffect(af);

You’ll notice that the target has 3 separate affects added just for one spell.  That’s because each affect could only handle a single modifier.

After making the modifiers into a list that can have a variable length, here’s what the same code looks like:

Affect af = new Affect( Affect.AffectType.spell, spell.Name, 12 + level / 4, Affect.Apply.intelligence, 3, Affect.AFFECT_NONE );
af.AddModifier( Affect.Apply.constitution, 8 );
af.AddModifier( Affect.Apply.dexterity, -5 );
victim.AddAffect(af);

Now it takes half as many lines of code to do the same thing and looks a lot cleaner.  The codebase also shrunk by about 300 lines of code in the process.

This also means that some spells or skills that used to show up multiple times on the score screen will only show up once.