Пример #1
0
        public bool Destroy(IEntityHandle handle)
        {
            if (handle == null)
            {
                throw new ArgumentNullException(nameof(handle));
            }
            if (IsDead(handle))
            {
                return(false);
            }

            Debug.Assert(_generationTracker.ContainsKey(handle.Id));

            // don't destroy entities that dont exist
            if (!_entities.TryGetValue(handle, out var ent))
            {
                return(false);
            }

            // dont destroy entities that are already in the destroy queue
            // .Add will return false if we failed to add an element
            if (!_deleteQueue.Add(handle))
            {
                return(false);
            }

            // ent is queued for death, send the notif
            ent.SendMessage(NotificationMessage.QueuedForDeath);

            return(true);
        }
Пример #2
0
 public void Init(IEntityHandle handle)
 {
     this.handle = handle;
     handle.RegisterUpdateHandler();
     handle.Static    = false;
     handle.Kinematic = true;
 }
Пример #3
0
 public ReconnectPlayerLogin([NotNull] IEntityHandle existing, [NotNull] Socket newConnection, int signlinkUid)
 {
     NewConnection = newConnection ?? throw new ArgumentNullException(nameof(newConnection));
     Existing      = existing ?? throw new ArgumentNullException(nameof(existing));
     SignlinkUid   = signlinkUid;
     Log           = existing.System.Server.Services.ThrowOrGet <ILogger>();
 }
        protected override bool IsHandleableEntity(IEntityHandle h)
        {
            if (h.IsDead())
            {
                return(false);
            }

            return(h.Get().GetPlayer() != null);
        }
Пример #5
0
        public bool IsDead(IEntityHandle handle)
        {
            if (_generationTracker.ContainsKey(handle.Id))
            {
                return(_generationTracker[handle.Id] != handle.Generation);
            }

            return(true);
        }
        protected override bool IsHandleableEntity(IEntityHandle h)
        {
            if (h.IsDead())
            {
                return(false);
            }

            return(h.Get().Components.Get <NpcComponent>() != null);
        }
        private bool TryDeleteEntityFromSeeables(IEntityHandle handle)
        {
            if (!_seeableEntities.Remove(handle))
            {
                return(false);
            }

            Parent.SendMessage(EntityMessage.LeftViewRange(handle));
            return(true);
        }
        private void RemoveEntity([NotNull] IEntityHandle ent)
        {
            if (ent == null)
            {
                throw new ArgumentNullException(nameof(ent));
            }

            Debug.Assert(SyncEntities.Contains(ent));
            Debug.Assert(!InitEntities.Contains(ent));

            LeaveEntities.Add(ent);
        }
Пример #9
0
 public bool Equals(IEntityHandle other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Handle.Equals(other));
 }
Пример #10
0
        public IEntity Get(IEntityHandle entityHandle)
        {
            if (entityHandle == null)
            {
                throw new ArgumentNullException(nameof(entityHandle));
            }
            if (IsDead(entityHandle))
            {
                throw new DestroyedEntityDereference(entityHandle);
            }

            return(_entities[entityHandle]);
        }
Пример #11
0
        private void RemoveEntityIntenally([NotNull] IEntityHandle handle)
        {
            if (handle == null)
            {
                throw new ArgumentNullException(nameof(handle));
            }
            Debug.Assert(_entities.ContainsKey(handle));

            // advance the generation
            _generationTracker[handle.Id] += 1;

            // remove ent
            _entities = _entities.Remove(handle);
        }
        private bool TryAddEntityToSeeables(IEntityHandle handle)
        {
            if (handle.IsDead() || handle.IsQueuedForDeath())
            {
                return(false);
            }

            if (!_seeableEntities.Add(handle))
            {
                return(false);
            }

            Parent.SendMessage(EntityMessage.EnteredViewRange(handle));
            return(true);
        }
Пример #13
0
        public Entity(
            [NotNull] string name,
            [NotNull] IEntityHandle handle,
            [NotNull] IServiceProvider services)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }
            Name   = name ?? throw new ArgumentNullException(nameof(name));
            Handle = handle ?? throw new ArgumentNullException(nameof(handle));

            Components = new EntityComponentContainer();
            _log       = services.GetLazy <ILogger>();
            _server    = services.GetLazy <IGameServer>();
        }
Пример #14
0
 public bool Equals(IEntityHandle other)
 {
     return(Generation == other.Generation && Id == other.Id);
 }
Пример #15
0
 public static bool Destroy(this IEntityHandle handle) => handle.System.Destroy(handle);
Пример #16
0
 public static IEntity Get(this IEntityHandle handle) => handle.System.Get(handle);
Пример #17
0
 public static bool IsDead(this IEntityHandle handle) => handle.System.IsDead(handle);
Пример #18
0
 public FollowDirectionProvider(IEntityHandle target)
 {
     Target = target;
 }
Пример #19
0
 public void Init(IEntityHandle handle)
 {
     handle.RegisterUseHandler(onPlayerUse);
 }
Пример #20
0
 public static EntityMessage PlayerFollowTarget([NotNull] IEntityHandle entity)
 => new EntityMessage(entity, MessageId.NewPlayerFollowTarget);
Пример #21
0
 public static EntityMessage LeftViewRange([NotNull] IEntityHandle entity)
 => new EntityMessage(entity, MessageId.EntityLeftViewRange);
Пример #22
0
 public static EntityMessage NearbyEntityQueuedForDeath([NotNull] IEntityHandle entity)
 => new EntityMessage(entity, MessageId.NearbyEntityQueuedForDeath);
Пример #23
0
 private EntityMessage([NotNull] IEntityHandle entity, MessageId eventId)
 {
     Entity  = entity ?? throw new ArgumentNullException(nameof(entity));
     EventId = (int)eventId;
 }
Пример #24
0
 public PickupItemAction(IEntityHandle who, IEntityHandle item)
 {
     _who  = who;
     _item = item;
 }
 protected abstract bool IsHandleableEntity(IEntityHandle h);
 public PlayerInteractingEntity([NotNull] IPlayerComponent player)
 {
     Entity = player.Parent.Handle;
     Id     = (short)(player.InstanceId + 32769);
 }
 public DestroyedEntityDereference(IEntityHandle handle)
 {
     Handle = handle;
 }
Пример #28
0
 public bool Equals(IEntityHandle other)
 {
     throw new NotImplementedException();
 }
Пример #29
0
 public void Init(IEntityHandle handle)
 {
     this.handle = handle;
     handle.RegisterUseHandler(onUse);
 }
Пример #30
0
 public TalkToNpcAction(IEntityHandle requestee, IEntityHandle target)
 {
     Requestee  = requestee;
     TalkTarget = target;
 }