Exemple #1
0
        public virtual void ProcessDelta()
        {
            Mobile m = this;
            MobileDelta delta;
            MobileDelta attrs;

            delta = m.m_DeltaFlags;

            if ( delta == MobileDelta.None )
                return;

            attrs = delta & MobileDelta.Attributes;

            m.m_DeltaFlags = MobileDelta.None;
            m.m_InDeltaQueue = false;

            bool sendHits = false, sendStam = false, sendMana = false, sendAll = false, sendAny = false;
            bool sendIncoming = false, sendNonlocalIncoming = false;
            bool sendUpdate = false, sendRemove = false;
            bool sendPublicStats = false, sendPrivateStats = false;
            bool sendMoving = false, sendNonlocalMoving = false;
            bool sendOPLUpdate = Core.AOS && (delta & MobileDelta.Properties) != 0;

            if ( attrs != MobileDelta.None )
            {
                sendAny = true;

                if ( attrs == MobileDelta.Attributes )
                {
                    sendAll = true;
                }
                else
                {
                    sendHits = ( (attrs & MobileDelta.Hits) != 0 );
                    sendStam = ( (attrs & MobileDelta.Stam) != 0 );
                    sendMana = ( (attrs & MobileDelta.Mana) != 0 );
                }
            }

            if ( (delta & MobileDelta.GhostUpdate) != 0 )
            {
                sendNonlocalIncoming = true;
            }

            if ( (delta & MobileDelta.Hue) != 0 )
            {
                sendNonlocalIncoming = true;
                sendUpdate = true;
                sendRemove = true;
            }

            if ( (delta & MobileDelta.Direction) != 0 )
            {
                sendNonlocalMoving = true;
                sendUpdate = true;
            }

            if ( (delta & MobileDelta.Body) != 0 )
            {
                sendUpdate = true;
                sendIncoming = true;
            }

            /*if ( (delta & MobileDelta.Hue) != 0 )
                {
                    sendNonlocalIncoming = true;
                    sendUpdate = true;
                }
                else if ( (delta & (MobileDelta.Direction | MobileDelta.Body)) != 0 )
                {
                    sendNonlocalMoving = true;
                    sendUpdate = true;
                }
                else*/ if ( (delta & (MobileDelta.Flags | MobileDelta.Noto)) != 0 )
                       {
                           sendMoving = true;
                       }

            if ( (delta & MobileDelta.Name) != 0 )
            {
                sendAll = false;
                sendHits = false;
                sendAny = sendStam || sendMana;
                sendPublicStats = true;
            }

            if ( (delta & (MobileDelta.WeaponDamage | MobileDelta.Resistances | MobileDelta.Stat | MobileDelta.Weight | MobileDelta.Gold | MobileDelta.Armor | MobileDelta.StatCap | MobileDelta.Followers | MobileDelta.TithingPoints)) != 0 )
            {
                sendPrivateStats = true;
            }

            IRecyclablePacket[] cache = m_MovingPacketCache;

            if ( sendMoving || sendNonlocalMoving )
            {
                for ( int i = 0; i < cache.Length; ++i )
                    cache[i] = null;
            }

            NetState ourState = m.m_NetState;

            if ( ourState != null )
            {
                if ( sendUpdate )
                {
                    ourState.Sequence = 0;
                    ourState.Send( new MobileUpdate( m ) );
                    ClearFastwalkStack();
                }

                if ( sendIncoming )
                    ourState.Send( new MobileIncoming( m, m ) );

                if ( sendMoving )
                {
                    int noto = Notoriety.Compute( m, m );

                    using (IRecyclablePacket packet = MobileMoving.GetInstance(m, noto)) {
                        ourState.Send(packet);
                    }
                }

                if ( sendPublicStats || sendPrivateStats )
                {
                    ourState.Send( new MobileStatusExtended( m ) );
                }
                else if ( sendAll )
                {
                    ourState.Send( new MobileAttributes( m ) );
                }
                else if ( sendAny )
                {
                    if ( sendHits )
                        ourState.Send( new MobileHits( m ) );

                    if ( sendStam )
                        ourState.Send( new MobileStam( m ) );

                    if ( sendMana )
                        ourState.Send( new MobileMana( m ) );
                }

                if ( sendStam || sendMana )
                {
                    IParty ip = m_Party as IParty;

                    if ( ip != null && sendStam )
                        ip.OnStamChanged( this );

                    if ( ip != null && sendMana )
                        ip.OnManaChanged( this );
                }

                if ( sendOPLUpdate )
                    ourState.Send( OPLPacket );
            }

            sendMoving = sendMoving || sendNonlocalMoving;
            sendIncoming = sendIncoming || sendNonlocalIncoming;
            sendHits = sendHits || sendAll;

            if ( m.m_Map != null && (sendRemove || sendIncoming || sendPublicStats || sendHits || sendMoving || sendOPLUpdate) )
            {
                Mobile beholder;

                IPooledEnumerable eable = m.Map.GetClientsInRange( m.m_Location );

                Packet hitsPacket = null;
                Packet statPacketTrue = null, statPacketFalse = null;
                Packet deadPacket = null;

                foreach ( NetState state in eable )
                {
                    beholder = state.Mobile;

                    if ( beholder != m && beholder.CanSee( m ) )
                    {
                        if ( sendRemove )
                            state.Send( m.RemovePacket );

                        if ( sendIncoming )
                        {
                            state.Send( new MobileIncoming( beholder, m ) );

                            if ( m.IsDeadBondedPet )
                            {
                                if ( deadPacket == null )
                                    deadPacket = new BondedStatus( 0, m.m_Serial, 1 );

                                state.Send( deadPacket );
                            }
                        }

                        if ( sendMoving )
                        {
                            int noto = Notoriety.Compute( beholder, m );

                            IRecyclablePacket p = cache[noto];

                            if ( p == null )
                                cache[noto] = p = MobileMoving.GetInstance(m, noto);

                            state.Send( p );
                        }

                        if ( sendPublicStats )
                        {
                            if ( m.CanBeRenamedBy( beholder ) )
                            {
                                if ( statPacketTrue == null )
                                    statPacketTrue = new MobileStatusCompact( true, m );

                                state.Send( statPacketTrue );
                            }
                            else
                            {
                                if ( statPacketFalse == null )
                                    statPacketFalse = new MobileStatusCompact( false, m );

                                state.Send( statPacketFalse );
                            }
                        }
                        else if ( sendHits )
                        {
                            if ( hitsPacket == null )
                                hitsPacket = new MobileHitsN( m );

                            state.Send( hitsPacket );
                        }

                        if ( sendOPLUpdate )
                            state.Send( OPLPacket );
                    }
                }

                eable.Free();

                for (int i = 0; i < cache.Length; ++i) {
                    if (cache[i] != null) {
                        cache[i].Dispose();
                        cache[i] = null;
                    }
                }
            }
        }