Custom AI question

Anything regarding UO or Age of Valor
Locked
User avatar
Dumples
Posts: 484
Joined: Fri Jan 05, 2007 4:57 pm

Custom AI question

Post by Dumples »

Ok... So I've figured out how to copy a standard AI and edit enough to use additional spells like non-areaeffect necro and chivalry spells. Easy enough. What I'm trying to figure out now is the simplest or best way to make archers and casters to keep distance. An example would be the stormtroopers. would that be in the MageAI.cs or the BaseCreature.cs.

It seems it could be in either, but more likely a keep your distance section in the BaseCreature.cs that multiple AI's can take advantage of.

Archived topic from AOV, old topic ID:1190, old post ID:7576
Image
User avatar
Dumples
Posts: 484
Joined: Fri Jan 05, 2007 4:57 pm

Custom AI question

Post by Dumples »

Sort of figured out one way to do it. In the actual monster mobiel files there is a line that looks like this:

Code: Select all

public RatmanArcher() : base( AIType.AI_Archer, FightMode.Closest, 10, 6, 0.2, 0.4 )
The numbers at the end of that line are as follows:
10 = How far it looks for targets (maybe)
6 = The range it tries to stay at while fighting (this is what I was looking for)
0.2 and 0.4 = Seem to be speed related as to how far it walks in certain modes.

Anyway, I could set it to 6 and it attempts to stay at 6 tiles away and shoot from that distance.

Archived topic from AOV, old topic ID:1190, old post ID:7602
Image
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

Custom AI question

Post by Red Squirrel »

Yeah fight distance is one way of doing it. Here it works differently as its global to all mobs. If I get 0 wrestling to a hiryu it will keep distance, for example. But an easy way to do it on a per mob basis is fight distance. I remember accidentally setting it to 18 on demitels and wondered why they were sitting ducks lol

Archived topic from AOV, old topic ID:1190, old post ID:7603
Honk if you love Jesus, text if you want to meet Him!
User avatar
Dumples
Posts: 484
Joined: Fri Jan 05, 2007 4:57 pm

Custom AI question

Post by Dumples »

The other way I haven't figure out yet that kind of makes sense though would be to add it to the ArcherAI, MageAI, and any other custom ones made. That way anything that used ArcherAI would always try to keep a certain distance. That way it would not be as tedious to edit each and every single monster everytime you want to change how the AI worked.

Archived topic from AOV, old topic ID:1190, old post ID:7604
Image
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

Custom AI question

Post by Red Squirrel »

Yeah the way I made the AI is technically nearly all mob types could have it. The AI affects lot of stuff such as behavior and its based off their skills. If a mob has 50 mage, then it only tries to use mage spells that require 40 or lower, if it has low mana, it uses lower mana consuming ones, and puts more delays between spells, and so on.

Archived topic from AOV, old topic ID:1190, old post ID:7606
Honk if you love Jesus, text if you want to meet Him!
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

Custom AI question

Post by Red Squirrel »

This is the code that controls the distance stuff in the AI:


Code: Select all

private void CheckRun(Mobile c)
		{		
		if(c==null)return;
		if(NextRunCheck>DateTime.Now)return;
		if(!c.InLOS(m_Mobile))return;
		
		if(m_Mobile.Hidden && m_Mobile.Skills[SkillName.Stealth].Value>0.1 && 0.9>Utility.RandomDouble())return;
		
			//don't get close if we have no melee capabilities - assuming we have a combatant in range
			if(m_Mobile.InRange(c,4) && !CanMelee())
			{
				if(!RunFrom(c))
				{
				WalkRandom(0,0,1);
				NextRunCheck=DateTime.Now+TimeSpan.FromSeconds(5+Utility.Random(4));
				}			
			}
			else if(!m_Mobile.InRange(c,7) && !CanMelee())RunTo(c);
			else if(CanMelee() && !m_Mobile.InRange(c,1)) RunTo(c);
		}
		
		
		//used for curse wep and consecrate mostly
		public bool CanWeaponFight()
		{		
		//if(CanMelee())return true;
		
		if(m_Mobile.Skills[SkillName.Archery].Value>0.1 && m_Mobile.HasLongRangeWep())return true;		
		
		if((m_Mobile.Skills[SkillName.Swords].Value+m_Mobile.Skills[SkillName.Fencing].Value+m_Mobile.Skills[SkillName.Macing].Value)>=10 && m_Mobile.HasWep())return true;
		
		return false;
		}
		
		public bool CanMelee()
		{
		bool haswep=m_Mobile.HasWep();
		
		if(m_Mobile.Skills[SkillName.Wrestling].Value>=10 && !haswep)return true;
		
		if(m_Mobile.HasLongRangeWep())return false;
		
		if((m_Mobile.Skills[SkillName.Swords].Value+m_Mobile.Skills[SkillName.Fencing].Value+m_Mobile.Skills[SkillName.Macing].Value)>=10 && haswep)return true;
		
		return false;
		}
		
		public override bool CanDistanceFight()
		{
		if(m_Mobile.Skills[SkillName.Magery].Value>0.1 || (m_Mobile.Skills[SkillName.Archery].Value>0.1 && m_Mobile.HasLongRangeWep())) return true;		
		
		return false;
		}	


This is directly inside the class for the super AI. It may depend on custom baseai stuff though, can't recall.

Archived topic from AOV, old topic ID:1190, old post ID:7634
Honk if you love Jesus, text if you want to meet Him!
Locked