From 255bc064adc6addd0377817f4fcf15c96b826b77 Mon Sep 17 00:00:00 2001 From: xavier Date: Sat, 19 Jan 2013 21:52:09 +0000 Subject: [PATCH] range check mobiles, return home. On OSI they just delete and respawn. We will try to be a little more graceful, and see if we can walk back. --- .../TreasureChests/TreasureChestLevel4.cs | 2 +- Scripts/Mobiles/BaseCreature.cs | 34 +++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Scripts/Items/TreasureChests/TreasureChestLevel4.cs b/Scripts/Items/TreasureChests/TreasureChestLevel4.cs index d90776eb1..e88e15b40 100644 --- a/Scripts/Items/TreasureChests/TreasureChestLevel4.cs +++ b/Scripts/Items/TreasureChests/TreasureChestLevel4.cs @@ -33,7 +33,7 @@ namespace Server.Items this.GumpID = 0x42; break; - case 4:// Keg + case 3:// Keg this.ItemID = 0xe7f; this.GumpID = 0x3e; break; diff --git a/Scripts/Mobiles/BaseCreature.cs b/Scripts/Mobiles/BaseCreature.cs index 880f92ea5..3b41e853b 100644 --- a/Scripts/Mobiles/BaseCreature.cs +++ b/Scripts/Mobiles/BaseCreature.cs @@ -246,6 +246,9 @@ namespace Server.Mobiles private bool m_IsPrisoner; private string m_CorpseNameOverride; + + private int m_FailedReturnHome; /* return to home failure counter */ + #endregion public virtual InhumanSpeech SpeechType{ get{ return null; } } @@ -5234,6 +5237,22 @@ namespace Server.Mobiles m_NextHealTime = DateTime.Now + TimeSpan.FromSeconds( HealInterval ); } } + else if( ( this.FightMode != FightMode.None ) && ( Home != Point3D.Zero ) && ( RangeHome >= 0 ) && !InRange( Home, ( RangeHome ) ) ) + { + if( Utility.RandomDouble() < .05 ) /* some throttling */ + { + m_FailedReturnHome = !this.Move( GetDirectionTo( Home.X, Home.Y ) ) ? m_FailedReturnHome + 1 : 0; + + if( m_FailedReturnHome > 5 ) + { + this.SetLocation( this.Home, true ); + } + } + } + else + { + m_FailedReturnHome = 0; + } if ( HasAura && DateTime.Now >= m_NextAura ) { @@ -5462,18 +5481,29 @@ namespace Server.Mobiles public virtual bool PlayerRangeSensitive{ get{ return (this.CurrentWayPoint == null); } } //If they are following a waypoint, they'll continue to follow it even if players aren't around + /* until we are sure about who should be getting deleted, move them instead */ + /* On OSI, they despawn */ + public override void OnSectorDeactivate() { - if ( PlayerRangeSensitive && m_AI != null ) + if( ( this.FightMode != FightMode.None ) && ( Home != Point3D.Zero ) && ( RangeHome >= 0 ) && !this.InRange( Home, ( RangeHome + 10 ) ) ) + { + this.SetLocation( Home, true ); + } + else if( PlayerRangeSensitive && m_AI != null ) + { m_AI.Deactivate(); + } base.OnSectorDeactivate(); } public override void OnSectorActivate() { - if ( PlayerRangeSensitive && m_AI != null ) + if( PlayerRangeSensitive && m_AI != null ) + { m_AI.Activate(); + } base.OnSectorActivate(); }