Creature Caster AIs

Discuss anything in general about the IceBlink Engine + Toolset project (or anything else) here.
User avatar
slowdive
Site Admin
Posts: 485
Joined: Wed Jan 15, 2020 4:37 am

Creature Caster AIs

Post by slowdive »

UPDATED: Aug 9, 2021
This will be where we work on Creature AIs that will be used in IBbasic and IB:

Aggressive Caster
1. starts with a personal defence spell (stoneskin, mirror image etc).
2. 90% chance that the caster moves straight into a damage spell:
- Will cast AoE spells if player character numbers equal or greater than ally numbers in the area of effect (ie if the caster can drop a fireball on
three pcs and three allies they'll do it; if they would hit three pcs and four allies they won't). They won't cast an AoE spell in an area that would hit
themselves.
- In a round where an AoE attack isn't an option, they focus on single target damage spells instead.
10% chance that instead of a damage spell the caster casts another self defence spell, as long as one is available that would apply a different
protective effect
3. Reactive round
- checks if any self defense effects remain in place, and if not casts a defense spell.
- will "counterspell" a pc debuff only if it affects the caster themself, not allies. 30% chance if they themselves are under a debuff
- If a pc is at <50% health, there is a 30% chance the caster will target them with their highest level single target damage spell, or an AoE if it would
also hit a minimum of two other pcs.
- otherwise, back to 2. (90% chance damage attack, 10% chance personal protection)

Defensive Caster
1. 75% chance casts personal defence spell (stoneskin, mirror image etc)
2. Casts buff on allies - then moves to reactive rounds.
3. Reactive round:
- checks if personal defence spell needs casting/recasting and prioritises this if so
- 80% chance of casting "counterspell" if either self or allies have been debuffed
- if ally <50% HP, 80% chance of targeting them with a heal or buff
- if none of the above trigger, 30% chance of casting aggressive damage/debuff/summons
- otherwise casts further buff

Summoner
1. 60% chance casts personal defence spell (stoneskin, mirror image etc), otherwise goes straight to 2.
2. Casts summon spell.
3. Casts buff on summoned creatures.
4. Checks how many total allies remain.
- If three or fewer, casts summon spell; then follows with a buff etc as above.
- If four or more, spends a round being reactive, and then repeats the check on how many allies remain, etc.
5. Reactive rounds
- Checks if personal defense spell needs casting/recasting, if so prioritises this.
- 30% chance of casting "counterspell" if self or allies are under a negative effect
- 30% will cast damage or debuff spell on pcs (AoE if can hit pcs only - won't hit allies)
- otherwise casts another buff spell on allies

General Caster
1. 50% chance personal defence spell (stoneskin, mirror image etc) if no current defence effect in place (or runs out, is dispelled etc). If defence
effect in place, will not cast a second defense spell.
2. Generally an equal chance of buff, debuff, damage, or summons spells.
- Will only cast AoE spells if can hit two or more pcs and one or fewer allies. Won't cast an AoE spell in an area that would hit themselves.
3. Medium responsive caster
- 30% chance will "counterspell" a pc debuff if it affects the caster or its allies
- If ally is at <50% health, there is a 40% chance the caster will target them with a buff or healing.
- if two or fewer allies remaining, 40% chance of casting a summoning spell

Melee Caster (eg cleric)
- Same as general caster but if pc is next to caster, and casting a spell would trigger an AoO, the caster attacks with its melee weapon instead.
- In the reactive round there is a 50% chance the caster will actively move closer to the PCs to engage in melee combat instead of casting a spell.

Squishy Caster
- Same as general caster, but if the PCs are within two tiles of the caster it will retreat to a safer location before casting its next spell.
- if PC occupies a tile next to the squishy caster, the caster checks whether it needs a self protection effect and prioritises that immediately before
casting further spells

Reckless Caster (similar to aggressive, but will not be too concerned with harming its own allies, it just wants max impact to the PCs at any cost)


Frugal Caster (will use its normal ranged/melee almost as much as spells, may conserve SP just in case it needs it later, not that there will be a later if we beat them :lol: )



Any additions, suggest them in this thread and I'll edit this top post
Pongo
Posts: 142
Joined: Fri Jan 22, 2021 8:39 am

Re: Creature Caster AIs

Post by Pongo »

Great stuff!

Some further thoughts on the aggressive caster ai (I'll think about the others as well - reckless caster sounds like total carnage fun!)

Aggressive caster

1. starts with a personal defence spell (stoneskin, mirror image etc).

2. 90% chance that the caster moves straight into a damage spell:
- Will cast AoE spells if player character numbers equal or greater than ally numbers in the area of effect (ie if the caster can drop a fireball on three pcs and three allies they'll do it; if they would hit three pcs and four allies they won't). They won't cast an AoE spell in an area that would hit themselves.
- In a round where an AoE attack isn't an option, they focus on single target damage spells instead.
10% chance that instead of a damage spell the caster casts another self defence spell, as long as one is available that would apply a different protective effect

3. Reactive round
- checks if any self defense effects remain in place, and if not casts a defense spell.
- will "counterspell" a pc debuff only if it affects the caster themself, not allies. 30% chance if they themselves are under a debuff
- If a pc is at <50% health, there is a 30% chance the caster will target them with their highest level single target damage spell, or an AoE if it would also hit a minimum of two other pcs.
- otherwise, back to 2. (90% chance damage attack, 10% chance personal protection)
Pongo
Posts: 142
Joined: Fri Jan 22, 2021 8:39 am

Re: Creature Caster AIs

Post by Pongo »

General caster

1. 50% chance personal defence spell (stoneskin, mirror image etc) if no current defence effect in place (or runs out, is dispelled etc). If defence effect in place, will not cast a second defense spell.

2. Generally an equal chance of buff, debuff, damage, or summons spells.
- Will only cast AoE spells if can hit two or more pcs and one or fewer allies. Won't cast an AoE spell in an area that would hit themselves.


3. Medium responsive caster
- 30% chance will "counterspell" a pc debuff if it affects the caster or its allies
- If ally is at <50% health, there is a 40% chance the caster will target them with a buff or healing.
- if two or fewer allies remaining, 40% chance of casting a summoning spell


(I'm seeing the %s as a process - eg, if an ally is at <50% AND two or fewer allies remaining, the 40% chance of heal or debuff is checked first, then 40% summons, and if neither happen the caster goes to a random spell)
Pongo
Posts: 142
Joined: Fri Jan 22, 2021 8:39 am

Re: Creature Caster AIs

Post by Pongo »

Summoner

1. 60% chance casts personal defence spell (stoneskin, mirror image etc), otherwise goes straight to 2.

2. Casts summon spell.

3. Casts buff on summoned creatures.

4. Checks how many total allies remain.
- If three or fewer, casts summon spell; then follows with a buff etc as above.
- If four or more, spends a round being reactive, and then repeats the check on how many allies remain, etc.

5. Reactive rounds
- Checks if personal defense spell needs casting/recasting, if so prioritises this.
- 30% chance of casting "counterspell" if self or allies are under a negative effect
- 30% will cast damage or debuff spell on pcs (AoE if can hit pcs only - won't hit allies)
- otherwise casts another buff spell on allies
Pongo
Posts: 142
Joined: Fri Jan 22, 2021 8:39 am

Re: Creature Caster AIs

Post by Pongo »

Defensive Caster

1. 75% chance casts personal defence spell (stoneskin, mirror image etc)

2. Casts buff on allies - then moves to reactive rounds.

3. Reactive round:
- checks if personal defence spell needs casting/recasting and prioritises this if so
- 80% chance of casting "counterspell" if either self or allies have been debuffed
- if ally <50% HP, 80% chance of targeting them with a heal or buff
- if none of the above trigger, 30% chance of casting aggressive damage/debuff/summons
- otherwise casts further buff
Pongo
Posts: 142
Joined: Fri Jan 22, 2021 8:39 am

Re: Creature Caster AIs

Post by Pongo »

Melee Caster (eg cleric)
- Same as general caster but if pc is next to caster, and casting a spell would trigger an AoO, the caster attacks with its melee weapon instead.
- In the reactive round there is a 50% chance the caster will actively move closer to the PCs to engage in melee combat instead of casting a spell.

Squishy Caster
- Same as general caster, but if the PCs are within two tiles of the caster it will retreat to a safer location before casting its next spell.
- if PC occupies a tile next to the squishy caster, the caster checks whether it needs a self protection effect and prioritises that immediately before casting further spells

(I wonder if all casters not considered melee should follow these rules? Maybe we need to differentiate melee casters and squishies in all the AIs?)
User avatar
slowdive
Site Admin
Posts: 485
Joined: Wed Jan 15, 2020 4:37 am

Re: Creature Caster AIs

Post by slowdive »

These are great Pongo! Added them to the top post.

I started working on some of the utility functions for checking existing effects:

Code: Select all

        public bool hasDefenceEffectCurrentlyActive(Creature crt)
        {
            foreach (Effect ef in crt.cr_effectsList)
            {
                if (ef.acModifier > 0)
                {
                    return true;
                }
                else if (ef.modifyDex > 0)
                {
                    return true;
                }
                else if (ef.numberOfHitPointDamageAbsorptionLeft > 0)
                {
                    return true;
                }
                else if (ef.numberOfMirrorImagesLeft > 0)
                {
                    return true;
                }
            }
            return false;
        }
        public bool hasMirrorImageOrDamageAbsorptionEffectCurrentlyActive(Creature crt)
        {
            foreach (Effect ef in crt.cr_effectsList)
            {
                if (ef.numberOfHitPointDamageAbsorptionLeft > 0)
                {
                    return true;
                }
                else if (ef.numberOfMirrorImagesLeft > 0)
                {
                    return true;
                }
            }
            return false;
        }
Pongo
Posts: 142
Joined: Fri Jan 22, 2021 8:39 am

Re: Creature Caster AIs

Post by Pongo »

I was reflecting on how to determine which spell the caster chooses to use.

In a Vancian system I guess you just start with the highest level spells and work your way down to lower level spells as they run out (I think this is how Baldurs Gate does it). I don't think that translates well to a SP system though.

I guess the aim should be for casters to lead with and generally choose their most powerful spells, but with an element of unpredictability built in that means they don't get totally stuck on spamming fireballs until their SP runs out.

Perhaps:
- when at >50% SP, the caster chooses highest level spell of the type (buff, debuff etc) called by the AI;
- when at <50% SP, the caster has a 50% chance of choosing the highest level available spell and a 50% chance of choosing a random lower level spell of the called type;
- if the caster no longer has sufficient SP to cast the spell chosen, it looks for a spell at the next level down.

So for example:
A Summoner with access to Level 5 spells starts combat.
Round 1: casts his highest level personal defence spell, which happens to be a level 4 spell;
Round 2: casts his highest level summons spell at level 5;
Round 3: casts highest level buff, level 5 - at this point, the caster drops below 50% SP;
Round 4: there are 5 allies remaining, and the AI calls for a damage spell this round. The caster has level 4, 3 and 2 spells available. There is a 50% chance it will pick a level 4 damage spell, and a 50% chance it will randomly pick a damage spell from levels 3 and 2;
Round 5: number of allies has now dropped to 3, so the AI requires the caster to cast a summons spell. It has summons spells at levels 1-5. There is a 50% chance it will pick a level 5 summons spell, or 50% that it will randomly pick a spell from levels 1-4. It chooses a level 4 spell, but the caster doesn't have enough SP - it therefore checks whether the caster could instead cast a level 3 summons spell.

What do you think?
User avatar
slowdive
Site Admin
Posts: 485
Joined: Wed Jan 15, 2020 4:37 am

Re: Creature Caster AIs

Post by slowdive »

I think that sounds like a great approach. I'll have a bunch of helper functions checking for all the types of situations, available spells and SP, and current status effects. Then in the if-then code we can call on these functions to help with the decision making like you have laid out. Each caster type will have their own routine/function with the decision tree we come up with. We'll have a few memory variables for keeping track of previous decisions that should apply to future decisions. for example, if the caster decides to cast a fireball, but needs to move a few squares to get to that optimal location, we can store the decision that we are going to cast fireball at a specific location after we finish moving to a square. The moving part happens in a seperate part of the code and when we come back to the AI part again we can recall this previous decision to cast a fireball.
Pongo
Posts: 142
Joined: Fri Jan 22, 2021 8:39 am

Re: Creature Caster AIs

Post by Pongo »

That sounds brilliant - and the fireball example is a really good one. Combat is going to be a lot of fun with these ai casters causing problems!
Post Reply