Exemple #1
0
		public virtual bool DoOrderRelease()
		{
			m_Mobile.DebugSay("I have been released");

			m_Mobile.PlaySound(m_Mobile.GetAngerSound());

		    if (m_Mobile is MetaDragon)
		    {
                m_Mobile.Say("*Turns back into a dragon egg*");
		        var egg = new EvolutionEgg(m_Mobile.Hue);
		        if (m_Mobile.ControlMaster.Backpack != null)
		        {
		            m_Mobile.ControlMaster.Backpack.DropItem(egg);
		        }
		        else
		        {
		            egg.MoveToWorld(m_Mobile.Location, m_Mobile.Map);
		        }
                m_Mobile.Delete();
		        return true;
		    }

			m_Mobile.SetControlMaster(null);
			m_Mobile.SummonMaster = null;

			m_Mobile.BondingBegin = DateTime.MinValue;
			m_Mobile.OwnerAbandonTime = DateTime.MinValue;
			m_Mobile.IsBonded = false;

			var se = m_Mobile.Spawner as SpawnEntry;
			if (se != null && se.HomeLocation != Point3D.Zero)
			{
				m_Mobile.Home = se.HomeLocation;
				m_Mobile.HomeMap = m_Mobile.Map;
				m_Mobile.RangeHome = se.HomeRange;
			}

			if (m_Mobile.DeleteOnRelease || m_Mobile.IsDeadPet)
			{
				m_Mobile.Delete();
			}

			m_Mobile.BeginDeleteTimer();
			m_Mobile.DropBackpack();

			return true;
		}
		protected override void OnTick()
		{
			if ( DateTime.UtcNow >= m_NextHourlyCheck )
			{
				m_NextHourlyCheck = DateTime.UtcNow + TimeSpan.FromHours( 1.0 );

				List<BaseCreature> toRelease = new List<BaseCreature>();

				// added array for wild creatures in house regions to be removed
				List<BaseCreature> toRemove = new List<BaseCreature>();

				foreach ( Mobile m in World.Mobiles.Values )
				{
					if ( m is BaseMount && ((BaseMount)m).Rider != null )
					{
						((BaseCreature)m).OwnerAbandonTime = DateTime.MinValue;
						continue;
					}

					if ( m is BaseCreature )
					{
						BaseCreature c = (BaseCreature)m;
                        if (c is SkeletalMount)
                        {
                            c.Loyalty = BaseCreature.MaxLoyalty;
                            continue; // skeletal mounts don't go untame
                        }

						if ( c.IsDeadPet )
						{
							Mobile owner = c.ControlMaster;

							if ( owner == null || owner.Deleted || owner.Map != c.Map || !owner.InRange( c, 12 ) || !c.CanSee( owner ) || !c.InLOS( owner ) )
							{
								if ( c.OwnerAbandonTime == DateTime.MinValue )
									c.OwnerAbandonTime = DateTime.UtcNow;
								else if ( (c.OwnerAbandonTime + c.BondingAbandonDelay) <= DateTime.UtcNow )
									toRemove.Add( c );
							}
							else
								c.OwnerAbandonTime = DateTime.MinValue;
						}
						else if ( c.Controlled && c.Commandable )
						{
							c.OwnerAbandonTime = DateTime.MinValue;

							if ( c.Map != Map.Internal && !c.IsStabled )
							{
								c.Loyalty -= (BaseCreature.MaxLoyalty / 10);

								if( c.Loyalty < (BaseCreature.MaxLoyalty / 10) )
								{
									c.Say( 1043270, c.Name ); // * ~1_NAME~ looks around desperately *
									c.PlaySound( c.GetIdleSound() );
								}

								if ( c.Loyalty <= 0)
									toRelease.Add( c );
							}
						}

						// added lines to check if a wild creature in a house region has to be removed or not
						if ( !c.Controlled && !c.IsStabled && ( (c.Region.IsPartOf( typeof(HouseRegion) ) && c.CanBeDamaged()) || (c.RemoveIfUntamed && c.Spawner == null) ) )
						{
							c.RemoveStep++;

							if ( c.RemoveStep >= 48 )
								toRemove.Add( c );
						}
						else
							c.RemoveStep = 0;
					}
				}

				foreach ( BaseCreature c in toRelease )
				{
                    try
                    {
                        string toWrite = DateTime.Now + "\t" + c + "\t" + this.GetType() + "\tBonded=" + c.IsBonded + "\tOwner=" + c.ControlMaster + "\tLoyalty:" + c.Loyalty + "\tIsStabled:" + c.IsStabled + "\tStabledDate:" + c.StabledDate;
                        toWrite += "\n" + (new System.Diagnostics.StackTrace()).ToString();
                        LoggingCustom.Log("LOG_PetLoyaltyRelease.txt", toWrite);
                    }
                    catch { }
                    c.Say( 1043255, c.Name ); // ~1_NAME~ appears to have decided that is better off without a master!
					c.Loyalty = BaseCreature.MaxLoyalty; // Wonderfully Happy
					c.IsBonded = false;
					c.BondingBegin = DateTime.MinValue;
					c.OwnerAbandonTime = DateTime.UtcNow;
					c.ControlTarget = null;
					//c.ControlOrder = OrderType.Release;
                    if (c is MetaDragon)
                    {
                        c.Say("The evolution dragon reverts back to its egg form.");
                        var egg = new EvolutionEgg(c.Hue);
                        egg.MoveToWorld(c.Location, c.Map);
                        c.Delete();
                    }
                    else
					    c.AIObject.DoOrderRelease(); // this will prevent no release of creatures left alone with AI disabled (and consequent bug of Followers)
				}

				// added code to handle removing of wild creatures in house regions
			    foreach (BaseCreature c in toRemove)
			    {
			        if (!c.IsStabled)
			        {
                        if (c is EvolutionDragon)
                        {
                            c.Say("The evolution dragon reverts back to its egg form.");
                            var egg = new BaseMetaPet();
                            egg.MoveToWorld(c.Location, c.Map);
                        }
			            c.Delete();
			        }
			    }

			}
		}