public virtual void SendDamageToAll( int amount ) { if ( amount < 0 ) return; Map map = m_Map; if ( map == null ) return; IPooledEnumerable eable = map.GetClientsInRange( m_Location ); Packet pNew = null; Packet pOld = null; foreach ( NetState ns in eable ) { if ( ns.Mobile.CanSee( this ) ) { bool newPacket = ( ns.Version != null && ns.Version >= DamagePacket.Version ); Packet p; if ( newPacket ) { if ( pNew == null ) pNew = new DamagePacket( this, amount ); p = pNew; } else { if ( pOld == null ) pOld = new DamagePacketOld( this, amount ); p = pOld; } ns.Send( p ); } } eable.Free(); }
public virtual void Damage( int amount, Mobile from ) { if ( !CanBeDamaged() ) return; if ( !Region.OnDamage( this, ref amount ) ) return; if ( amount > 0 ) { int oldHits = Hits; int newHits = oldHits - amount; if ( m_Spell != null ) m_Spell.OnCasterHurt(); //if ( m_Spell != null && m_Spell.State == SpellState.Casting ) // m_Spell.Disturb( DisturbType.Hurt, false, true ); if ( from != null ) RegisterDamage( amount, from ); DisruptiveAction(); Paralyzed = false; switch ( m_VisibleDamageType ) { case VisibleDamageType.Related: { NetState ourState = m_NetState, theirState = ( from == null ? null : from.m_NetState ); if ( ourState == null ) { Mobile master = GetDamageMaster( from ); if ( master != null ) ourState = master.m_NetState; } if ( theirState == null && from != null ) { Mobile master = from.GetDamageMaster( this ); if ( master != null ) theirState = master.m_NetState; } if ( amount > 0 && (ourState != null || theirState != null) ) { Packet p = null;// = new DamagePacket( this, amount ); if ( ourState != null ) { bool newPacket = ( ourState.Version != null && ourState.Version >= DamagePacket.Version ); if ( newPacket ) p = new DamagePacket( this, amount ); else p = new DamagePacketOld( this, amount ); ourState.Send( p ); } if ( theirState != null && theirState != ourState ) { bool newPacket = ( theirState.Version != null && theirState.Version >= DamagePacket.Version ); if ( newPacket && ( p == null || !(p is DamagePacket) ) ) p = new DamagePacket( this, amount ); else if ( !newPacket && ( p == null || !(p is DamagePacketOld) ) ) p = new DamagePacketOld( this, amount ); theirState.Send( p ); } } break; } case VisibleDamageType.Everyone: { SendDamageToAll( amount ); break; } } OnDamage( amount, from, newHits < 0 ); if ( newHits < 0 ) { m_LastKiller = from; Hits = 0; if ( oldHits >= 0 ) Kill(); } else { Hits = newHits; } } }