[Accepted] Improvement of ScoutMobBrain

A place to submit .patch fixes for the DOL SVN

Moderator: Developer Team

[Accepted] Improvement of ScoutMobBrain

Postby Ferro » Fri Apr 02, 2010 2:44 pm

Hi, like in another thread announced I post my improvement of the scoutmobbrain here. The ScoutMobBrain has no method to scout a second time (IsScouting=true;) in the older version. I've made a comment which lines were added.
Code: Select all
/*
 * DAWN OF LIGHT - The first free open source DAoC server emulator
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Ferro added line 81-85 to bring brain back to scouting (IsScouting=true;) 01.04.2010
 */
using System;
using System.Collections.Generic;
using System.Text;
using DOL.GS;
using System.Collections;
using DOL.Events;
using log4net;
using System.Reflection;

namespace DOL.AI.Brain
{
   /// <summary>
   /// Brain for scout mobs. Scout mobs are NPCs that will not aggro
   /// on a player of their own accord, instead, they'll go searching
   /// for adds around the area and make those aggro on a player.
   /// </summary>
   /// <author>Aredhel</author>
   class ScoutMobBrain : StandardMobBrain
   {
      /// <summary>
      /// Defines a logger for this class.
      /// </summary>
      private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

      /// <summary>
      /// Mob brain main loop.
      /// </summary>
      public override void Think()
      {
         if (IsGettingHelp) return;      // Ignore everyone while running for help.
         base.Think();
      }

      private bool m_scouting = true;

      /// <summary>
      /// Whether this mob is scouting or not; if a mob is scouting it
      /// means the mob is still looking for players.
      /// </summary>
      public virtual bool IsScouting
      {
         get { return m_scouting; }
         set { m_scouting = value; }
      }

      private ArrayList m_targetList = new ArrayList();

      /// <summary>
      /// Check if there are any players around.
      /// </summary>
      protected override void CheckPlayerAggro()
      {
         // If mob is not scouting anymore, it is either still on its way to
         // get help or it has finished doing that, in which case it will
         // behave like an ordinary mob and aggro players.

         if (!IsScouting)
         {
            if (!IsGettingHelp)
            {
               base.CheckPlayerAggro();
               m_targetList.Clear();
               foreach (GamePlayer player in Body.GetPlayersInRadius((ushort)AggroRange))
                  if (!m_targetList.Contains(player))
                  IsScouting=true;//if there is no player in AggroRange Start Scouting
            }
            return;
         }

         // Add all players in range to this scout's target list. The scout
         // will report all these players to any potential adds.

         m_targetList.Clear();
         foreach (GamePlayer player in Body.GetPlayersInRadius((ushort)AggroRange))
            if (!m_targetList.Contains(player))
               m_targetList.Add(player);

         // Once we got at least one player we stop scouting and run for help.

         if (m_targetList.Count > 0)
         {
            IsScouting = false;
            GetHelp();
         }
      }

      private ushort m_scoutRange = 3000;

      /// <summary>
      /// The range the scout will look for adds in.
      /// </summary>
      public ushort ScoutRange
      {
         get { return m_scoutRange; }
         set { m_scoutRange = value; }
      }

      private bool m_gettingHelp = false;

      /// <summary>
      /// Whether or not this mob is on its way to get help.
      /// </summary>
      public bool IsGettingHelp
      {
         get { return m_gettingHelp; }
         set { m_gettingHelp = value; }
      }

      /// <summary>
      /// The NPC this scout has picked to help.
      /// </summary>
      private GameNPC m_helperNPC = null;

      /// <summary>
      /// Look for potential adds in the area and be on your way.
      /// </summary>
      /// <returns></returns>
      protected void GetHelp()
      {
         // Nothing to get help for.

         if (m_targetList.Count == 0) return;

         // Find all mobs in scout range.

         ArrayList addList = new ArrayList();
         foreach (GameNPC npc in Body.GetNPCsInRadius(ScoutRange))
            if (npc.IsFriend(Body) && npc.IsAggressive && npc.IsAvailable)
               addList.Add(npc);

         // If there is no help available, fall back on standard mob
         // behaviour.

         if (addList.Count == 0)
         {
            ReportTargets(Body);
            m_targetList.Clear();
            IsGettingHelp = false;
            return;
         }

         // Pick a random NPC from the list and go for it.

         IsGettingHelp = true;
         m_helperNPC = (GameNPC) addList[Util.Random(1, addList.Count)-1];
         Body.Follow(m_helperNPC, 90, ScoutRange);
      }

      /// <summary>
      /// Add targets to an NPC's aggro table.
      /// </summary>
      /// <param name="npc">The NPC to aggro on the targets.</param>
      private void ReportTargets(GameNPC npc)
      {
         if (npc == null) return;

         // Assign a random amount of aggro for each target, that way
         // different NPCs will attack different targets first.

         StandardMobBrain brain = npc.Brain as StandardMobBrain;
         foreach (GameLiving target in m_targetList)
            brain.AddToAggroList(target, Util.Random(1, m_targetList.Count));
      }

      /// <summary>
      /// Called whenever the NPC's body sends something to its brain.
      /// </summary>
      /// <param name="e">The event that occured.</param>
      /// <param name="sender">The source of the event.</param>
      /// <param name="args">The event details.</param>
      public override void Notify(DOLEvent e, object sender, EventArgs args)
      {
         base.Notify(e, sender, args);
         if (e == GameNPCEvent.ArriveAtTarget && IsGettingHelp && m_targetList.Count > 0)
         {
            // We arrived at our target mob, let's have a look around
            // and see if we can get multiple adds.

            foreach (GameNPC npc in Body.GetNPCsInRadius(500))
               if (npc.IsFriend(Body) && npc.IsAggressive && npc.IsAvailable)
                  ReportTargets(npc);

            // Once that's done, aggro on targets ourselves and run back.

            ReportTargets(Body);
            m_targetList.Clear();
            IsGettingHelp = false;
            AttackMostWanted();
         }
         else if (e == GameNPCEvent.TakeDamage)
         {
            // If we are attacked at any point we'll stop scouting or
            // running for help.

            IsScouting = false;
            IsGettingHelp = false;
            m_targetList.Clear();
         }
      }
   }
}
Rock me!

Admin of the RP Freeshard Abendwind
User avatar
Ferro
Contributor
 
Posts: 136
Joined: Wed Sep 06, 2006 5:47 am
Website: http://www.abendwind.org
Location: Germany

Re: Improvement of ScoutMobBrain

Postby Graveen » Fri Apr 02, 2010 7:51 pm

Thank you Ferro. Can you provide a patch please ?
Image
* pm me to contribute in Dawn of Light: code, database *
User avatar
Graveen
Project Leader
 
Posts: 12660
Joined: Fri Oct 19, 2007 9:22 pm
Location: France

Re: Improvement of ScoutMobBrain

Postby Ferro » Sat Apr 03, 2010 10:44 am

OK, I try. It's the first time for me to make it this way.
Here is the patch:
Attachments
ScoutMobBrain.patch
the improved scotmobbrain patch
(981 Bytes) Downloaded 15 times
Rock me!

Admin of the RP Freeshard Abendwind
User avatar
Ferro
Contributor
 
Posts: 136
Joined: Wed Sep 06, 2006 5:47 am
Website: http://www.abendwind.org
Location: Germany

Re: Improvement of ScoutMobBrain

Postby Graveen » Sat Apr 03, 2010 11:35 am

Excellent Ferro

Accepted, soon in SVN, thank you
Image
* pm me to contribute in Dawn of Light: code, database *
User avatar
Graveen
Project Leader
 
Posts: 12660
Joined: Fri Oct 19, 2007 9:22 pm
Location: France

Re: Improvement of ScoutMobBrain

Postby Aredhel » Tue Apr 06, 2010 9:29 pm

I might resume work on the NPC brain rewrite, if people are still interested in it, that is.
User avatar
Aredhel
Inactive Staff Member
 
Posts: 1024
Joined: Sat Apr 14, 2007 1:49 pm
Location: Germany

Re: Improvement of ScoutMobBrain

Postby Graveen » Tue Apr 06, 2010 9:41 pm

thumbs up ! !!
Image
* pm me to contribute in Dawn of Light: code, database *
User avatar
Graveen
Project Leader
 
Posts: 12660
Joined: Fri Oct 19, 2007 9:22 pm
Location: France

Re: Improvement of ScoutMobBrain

Postby bluraven » Thu Apr 08, 2010 10:36 pm

Aredhel! I'm glad your still around :)
Image
bluraven
Support Team
 
Posts: 1484
Joined: Mon Mar 19, 2007 8:18 am
Location: Las Vegas, NV

Re: Improvement of ScoutMobBrain

Postby Aredhel » Fri Apr 09, 2010 8:39 am

bluraven wrote:Aredhel! I'm glad your still around :)


Hiya bluraven, nice to meet each other again, awesome work with the Atlantis encounters :D
User avatar
Aredhel
Inactive Staff Member
 
Posts: 1024
Joined: Sat Apr 14, 2007 1:49 pm
Location: Germany

Re: [Accepted] Improvement of ScoutMobBrain

Postby bluraven » Tue Apr 13, 2010 11:55 pm

Thanks! :D I still want to continue my work on them but am currently taking a break. I was going to try to make some games for iphone/ipad but am finding that to be way too difficult and haven't gotten anything done with it. I'll probably be resuming the encounter work soon as I'm starting to feel the itch again :D
Image
bluraven
Support Team
 
Posts: 1484
Joined: Mon Mar 19, 2007 8:18 am
Location: Las Vegas, NV


Return to “%s” DOL Code Contributions

Who is online

Users browsing this forum: No registered users and 1 guest