コード例 #1
0
 public virtual void OnLocationChanged(Mobile m, Point3D oldLocation)
 {
     if (m_Parent != null)
     {
         m_Parent.OnLocationChanged(m, oldLocation);
     }
 }
コード例 #2
0
ファイル: Mobile.cs プロジェクト: BackupTheBerlios/sunuo-svn
        public virtual void SetLocation( Point3D newLocation, bool isTeleport )
        {
            if ( m_Deleted )
                return;

            Point3D oldLocation = m_Location;
            Region oldRegion = m_Region;

            if ( oldLocation != newLocation )
            {
                m_Location = newLocation;

                BankBox box = FindBankNoCreate();

                if ( box != null && box.Opened )
                    box.Close();

                if ( m_NetState != null )
                    m_NetState.ValidateAllTrades();

                if ( m_Map != null )
                    m_Map.OnMove( oldLocation, this );

                if ( isTeleport && m_NetState != null )
                {
                    m_NetState.Sequence = 0;
                    m_NetState.Send( new MobileUpdate( this ) );
                    ClearFastwalkStack();
                }

                Map map = m_Map;

                if ( map != null )
                {
                    // First, send a remove message to everyone who can no longer see us. (inOldRange && !inNewRange)
                    Packet removeThis = null;

                    IPooledEnumerable eable = map.GetClientsInRange( oldLocation );

                    foreach ( NetState ns in eable )
                    {
                        if ( ns != m_NetState && !Utility.InUpdateRange( newLocation, ns.Mobile.Location ) )
                        {
                            if ( removeThis == null )
                                removeThis = this.RemovePacket;

                            ns.Send( removeThis );
                        }
                    }

                    eable.Free();

                    NetState ourState = m_NetState;

                    // Check to see if we are attached to a client
                    if ( ourState != null )
                    {
                        eable = map.GetObjectsInRange( newLocation, Core.GlobalMaxUpdateRange );

                        // We are attached to a client, so it's a bit more complex. We need to send new items and people to ourself, and ourself to other clients
                        foreach ( object o in eable )
                        {
                            if ( o is Item )
                            {
                                Item item = (Item)o;

                                int range = item.GetUpdateRange( this );
                                Point3D loc = item.Location;

                                if ( !Utility.InRange( oldLocation, loc, range ) && Utility.InRange( newLocation, loc, range ) && CanSee( item ) )
                                    item.SendInfoTo( ourState );
                            }
                            else if ( o != this && o is Mobile )
                            {
                                Mobile m = (Mobile)o;

                                if ( !Utility.InUpdateRange( newLocation, m.m_Location ) )
                                    continue;

                                bool inOldRange = Utility.InUpdateRange( oldLocation, m.m_Location );

                                if ( (isTeleport || !inOldRange) && m.m_NetState != null && m.CanSee( this ) )
                                {
                                    m.m_NetState.Send( new MobileIncoming( m, this ) );

                                    if ( IsDeadBondedPet )
                                        m.m_NetState.Send( new BondedStatus( 0, m_Serial, 1 ) );

                                    if ( ObjectPropertyList.Enabled )
                                    {
                                        m.m_NetState.Send( OPLPacket );

                                        //foreach ( Item item in m_Items )
                                        //	m.m_NetState.Send( item.OPLPacket );
                                    }
                                }

                                if ( !inOldRange && CanSee( m ) )
                                {
                                    ourState.Send( new MobileIncoming( this, m ) );

                                    if ( m.IsDeadBondedPet )
                                        ourState.Send( new BondedStatus( 0, m.m_Serial, 1 ) );

                                    if ( ObjectPropertyList.Enabled )
                                    {
                                        ourState.Send( m.OPLPacket );

                                        //foreach ( Item item in m.m_Items )
                                        //	ourState.Send( item.OPLPacket );
                                    }
                                }
                            }
                        }

                        eable.Free();
                    }
                    else
                    {
                        eable = map.GetClientsInRange( newLocation );

                        // We're not attached to a client, so simply send an Incoming
                        foreach ( NetState ns in eable )
                        {
                            if ( (isTeleport || !Utility.InUpdateRange( oldLocation, ns.Mobile.Location )) && ns.Mobile.CanSee( this ) )
                            {
                                ns.Send( new MobileIncoming( ns.Mobile, this ) );

                                if ( IsDeadBondedPet )
                                    ns.Send( new BondedStatus( 0, m_Serial, 1 ) );

                                if ( ObjectPropertyList.Enabled )
                                {
                                    ns.Send( OPLPacket );

                                    //foreach ( Item item in m_Items )
                                    //	ns.Send( item.OPLPacket );
                                }
                            }
                        }

                        eable.Free();
                    }
                }

                m_Region = Region.Find( m_Location, m_Map );

                if ( oldRegion != m_Region )
                {
                    oldRegion.InternalExit( this );
                    m_Region.InternalEnter( this );
                    OnRegionChange( oldRegion, m_Region );
                }

                OnLocationChange( oldLocation );

                CheckLightLevels( false );

                m_Region.OnLocationChanged( this, oldLocation );
            }
        }