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); }
public void Init(IEntityHandle handle) { this.handle = handle; handle.RegisterUpdateHandler(); handle.Static = false; handle.Kinematic = true; }
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); }
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); }
public bool Equals(IEntityHandle other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Handle.Equals(other)); }
public IEntity Get(IEntityHandle entityHandle) { if (entityHandle == null) { throw new ArgumentNullException(nameof(entityHandle)); } if (IsDead(entityHandle)) { throw new DestroyedEntityDereference(entityHandle); } return(_entities[entityHandle]); }
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); }
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>(); }
public bool Equals(IEntityHandle other) { return(Generation == other.Generation && Id == other.Id); }
public static bool Destroy(this IEntityHandle handle) => handle.System.Destroy(handle);
public static IEntity Get(this IEntityHandle handle) => handle.System.Get(handle);
public static bool IsDead(this IEntityHandle handle) => handle.System.IsDead(handle);
public FollowDirectionProvider(IEntityHandle target) { Target = target; }
public void Init(IEntityHandle handle) { handle.RegisterUseHandler(onPlayerUse); }
public static EntityMessage PlayerFollowTarget([NotNull] IEntityHandle entity) => new EntityMessage(entity, MessageId.NewPlayerFollowTarget);
public static EntityMessage LeftViewRange([NotNull] IEntityHandle entity) => new EntityMessage(entity, MessageId.EntityLeftViewRange);
public static EntityMessage NearbyEntityQueuedForDeath([NotNull] IEntityHandle entity) => new EntityMessage(entity, MessageId.NearbyEntityQueuedForDeath);
private EntityMessage([NotNull] IEntityHandle entity, MessageId eventId) { Entity = entity ?? throw new ArgumentNullException(nameof(entity)); EventId = (int)eventId; }
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; }
public bool Equals(IEntityHandle other) { throw new NotImplementedException(); }
public void Init(IEntityHandle handle) { this.handle = handle; handle.RegisterUseHandler(onUse); }
public TalkToNpcAction(IEntityHandle requestee, IEntityHandle target) { Requestee = requestee; TalkTarget = target; }