Cakewalk.Server.Zones.Zone.PushNearbyEntities C# (CSharp) Метод

PushNearbyEntities() публичный Метод

Sends states of nearby enemies to each other
public PushNearbyEntities ( ServerEntity entity ) : void
entity ServerEntity
Результат void
        public void PushNearbyEntities(ServerEntity entity)
        {
            foreach (ServerEntity e in m_entities.Values)
            {
                if (e.AuthState != EntityAuthState.Authorised || e.WorldID == entity.WorldID)
                {
                    //Skip unauthorised entities and don't send to self
                    continue;
                }

                float xDiff = entity.LastState.X - e.LastState.X;
                float yDiff = entity.LastState.Y - e.LastState.Y;

                float sqrdistance = (xDiff * xDiff) + (yDiff * yDiff);

                if (sqrdistance < 768*768)
                {
                    //Add a push state into the coalesced data packet for this entity
                    PushState state = PacketFactory.CreatePacket<PushState>();
                    state.WorldID = e.WorldID;
                    state.State = e.LastState;

                    entity.DeferredSendPacket(state);
                }
            }
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Tells all zones to push states to entities that are near to each other.
        /// </summary>
        public void PushNearbyEntities(ServerEntity entity)
        {
            Zone zone = null;

            m_userZones.TryGetValue(entity, out zone);
            if (zone != null)
            {
                zone.PushNearbyEntities(entity);
            }
        }