RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Improved MageAI

sub-xero

Wanderer
Improved MageAI

Hello,

I decided to reprogram the MageAI, as the default mages were behaving pretty stupid. The new mage now has the following features:

- Improved pathfinding (keeps distance to enemy, tries to return to home zone)
- Improved spells (casts higher level spells, more intelligent casting)
- Intelligent self medication (curing and healing)

My main goal was to improve the mage's walking and pathfinding during combat, so it doesn't stand next to the enemy and gets beaten up. I took out the teleporting and the custom Flee procedure. When I find out how it works, I may add a Flee procedure that actually makes the mage run one screen away when health is low, before he starts healing back up.

I tested the script thoroughly and let the mage fight against all kinds and numbers of creatures. Seems to work pretty well.
As this is my first RunUO project, please feel free to post improvements of the code. I'd be happy to receive some hints from more experienced people.

To install and use the script, do the following:
  • Add the new AIType to the list in ChangeAIType( AIType NewAI ) in BaseCreature.cs
  • Add the new AIType to the namespace Server.Mobiles in BaseAI.cs
  • Assign the AIType to the class of the creature (e.g. public OrcishMage() : base(AIType.AI_Mage, ...)
  • Enter into the Spawner, for example, "OrcishMage/ai/AI_Mage2"
  • Have fun!
 

Attachments

  • Mage2AI.cs
    23.3 KB · Views: 195

M_0_h

Page
This sounds very interesting and promising :) I already thought about that myself, but had no time to do it yet... I'll test it and maybe can help you to improve it further

Greetings
 

M_0_h

Page
Hmm I didn't test it that much but from the things i noticed the mobiles are too much concentrated on keeping their distance to their enemies... I would rather prefer if they had "running phases" and "casting phases" always switching, which means they stop and cast their spell, then continue running if the enemy has come too near :)

Greetings
 

Bujinsho

Page
After a brief initial assessment I have to say I like this ... it may not be perfect but it's a lot better than the standard AI.

It was on my To-Do list, so thanks for the leg-up sub-xero ;) This will be part of my shard in some form.
 

sub-xero

Wanderer
You are welcome to send me some code suggestions to further improve the AI. I then will try to build it in and test it thoroughly. I think it is top priority for a mage to keep the distance (any player would do that), and it doesn't stop him from casting. I still haven't figured out how teleporting works, but I'm not sure either that it makes sense to use it at all.
 

Lord_Velius

Sorceror
I must say I find this script rather humorous.
Great work in it, my players were shocked in how it acted, they said it didn't act like a normal mage AI at all.

Can we look forward to other releases by you for AI upgrades?
 

sub-xero

Wanderer
I'm trying to look at a few other things, plainly out of interest. Some people have really cool stuff running on their freeshards, and I wish they'd share their code, too.
 

Christos81

Wanderer
could I just replace the old mageai with this by renaming namescaces to match the default one or would that cause trouble do you think??
 

Bujinsho

Page
Christos81;827640 said:
could I just replace the old mageai with this by renaming namescaces to match the default one or would that cause trouble do you think??

That worked fine for me
 

sub-xero

Wanderer
Yes, you can either replace the original MageAI.cs by this file (make sure you make a backup of the old file), and change the class name in the script from "Mage2AI" to "MageAI".
 

JamzeMcC

Squire
ft2085267;827719 said:
ArcherAI how to do do this?
To maintain a fixed distance.:confused:

Forgive me if I am wrong, I have read somewhere that this line:
Code:
 base( AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4
The "1" after the "10" is the distance the mob tries to keep. Without changing the AI of the archer, changing that 1 to say, 4 or 8 or something "should" make him try to keep a larger distance. However, you may have an issue with him not shooting as I am not sure they have the moving shot available but you could try.
 

seraph035

Sorceror
Forgive me if I am wrong, I have read somewhere that this line:
Code:
 base( AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4
The "1" after the "10" is the distance the mob tries to keep. Without changing the AI of the archer, changing that 1 to say, 4 or 8 or something "should" make him try to keep a larger distance. However, you may have an issue with him not shooting as I am not sure they have the moving shot available but you could try.
That will cause the mob to engage in combat at that distance, but will not make the mob 'back away' In the same way a player archer or mage would. In any case, it is a good idea to make this alteration in any mob that is intended to fight at range, as it will prevent them from closing to melee range automatically.
Cheers!

***EDIT**
In order to simply make the archer maintain a distance from it's focus, set the rangefight to a good average value, say 5, and make this alteration to ArcherAI.cs:

//From original ArcherAI.cs


if ( (m_Mobile.LastMoveTime + TimeSpan.FromSeconds( 1.0 )) < DateTime.Now )
{
if (WalkMobileRange(m_Mobile.Combatant, 1, true, m_Mobile.RangeFight, m_Mobile.Weapon.MaxRange))


//Change to:


if ( (m_Mobile.LastMoveTime + TimeSpan.FromSeconds( 1.0 )) < DateTime.Now )
{
if (WalkMobileRange(m_Mobile.Combatant, 2, true, 9, 12))
if (WalkMobileRange(m_Mobile.Combatant, 1, true, m_Mobile.RangeFight, m_Mobile.Weapon.MaxRange))
 
Top