Esempio n. 1
0
        /// <summary>
        /// An object moved on the map.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="movedObject">The moved object.</param>
        /// <param name="moveType">Type of the move.</param>
        public void ObjectMoved(WorldObserverToHubAdapter sender, ILocateable movedObject, MoveType moveType)
        {
            byte   x, y;
            object steps     = null;
            int    walkDelay = 0;

            if (movedObject is ISupportWalk walkable && moveType == MoveType.Walk)
            {
                x         = walkable.WalkTarget.X;
                y         = walkable.WalkTarget.Y;
                walkDelay = (int)walkable.StepDelay.TotalMilliseconds;
                var walkSteps = walkable.NextDirections.Select(step => new { x = step.To.Y, y = step.To.Y, direction = step.Direction }).ToList();

                // TODO: Can errors happen here when NextDirection changes in the meantime?
                var lastStep = walkable.NextDirections.LastOrDefault();
                if (!Equals(lastStep, default(WalkingStep)))
                {
                    var lastDirection = lastStep.To.GetDirectionTo(walkable.WalkTarget);
                    if (lastDirection != Direction.Undefined)
                    {
                        walkSteps.Add(new { x, y, direction = lastDirection });
                    }
                }

                steps = walkSteps;
            }
Esempio n. 2
0
        /// <summary>
        /// Registers the connected client to listen on the events on the specified map. Is called from the client.
        /// </summary>
        /// <param name="serverId">The server identifier.</param>
        /// <param name="mapId">The map identifier.</param>
        /// <remarks>
        /// This is a bit dirty... the AdminPanel should not have the reference to  GameLogic.
        /// Instead we need to extract some interfaces.
        /// TODO: It should also be possible to observe multiple maps through one connection.
        /// </remarks>
        public void Subscribe(byte serverId, ushort mapId)
        {
            IGameServer gameServer = this.servers.OfType <IGameServer>().FirstOrDefault(g => g.Id == serverId);

            if (gameServer == null)
            {
                throw new ArgumentException($"unknown server id {serverId}", nameof(serverId));
            }

            if (!FreeIds.TryDequeue(out ushort observerKey))
            {
                throw new Exception("no free observer keys available");
            }

            WorldObserverToHubAdapter observer = new WorldObserverToHubAdapter(observerKey, serverId, mapId, this, this.Context.ConnectionId);

            Observers.Add(this.Context.ConnectionId, observer);

            try
            {
                gameServer.RegisterMapObserver(mapId, observer);
            }
            catch (ArgumentException)
            {
                Observers.Remove(this.Context.ConnectionId);
                observer.Dispose();
                throw;
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Shows the new players in scope.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="newObjects">The new objects.</param>
 public void NewPlayersInScope(WorldObserverToHubAdapter sender, IEnumerable <Player> newObjects)
 {
     this.Clients.Client(sender.ConnectionId).NewPlayersInScope(newObjects.Select(o => new
     {
         id = o.Id, name = o.Name, x = o.X, y = o.Y, rotation = o.Rotation, serverId = sender.ServerId, mapId = sender.MapId
     }));
 }
Esempio n. 4
0
 /// <summary>
 /// An object got killed by another object.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="killedObject">The killed object.</param>
 /// <param name="killerObject">The object which killed the object.</param>
 public void ObjectGotKilled(WorldObserverToHubAdapter sender, IAttackable killedObject, IAttackable killerObject)
 {
     this.Clients.Client(sender.ConnectionId).ObjectGotKilled(killedObject.Id, killerObject.Id);
 }
Esempio n. 5
0
 /// <summary>
 /// Shows the new npcs in scope.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="newObjects">The new objects.</param>
 public void NewNpcsInScope(WorldObserverToHubAdapter sender, IEnumerable <NonPlayerCharacter> newObjects)
 {
     this.Clients.Client(sender.ConnectionId).NewNPCsInScope(newObjects.Select(o => new { id = o.Id, name = o.Definition.Designation, x = o.X, y = o.Y, rotation = o.Rotation, serverId = sender.ServerId, mapId = sender.MapId, isMonster = o is Monster }));
 }
Esempio n. 6
0
 /// <summary>
 /// The item drops disappeared from the ground.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="disappearedItemIds">The ids of the disappeared items.</param>
 public void DroppedItemsDisappeared(WorldObserverToHubAdapter sender, IEnumerable <ushort> disappearedItemIds)
 {
     this.Clients.Client(sender.ConnectionId).DroppedItemsDisappeared(disappearedItemIds);
 }
Esempio n. 7
0
 /// <summary>
 /// Shows the new players in scope.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="newObjects">The new objects.</param>
 public void NewPlayersInScope(WorldObserverToHubAdapter sender, IEnumerable <Player> newObjects)
 {
     this.Clients.Client(sender.ConnectionId).NewPlayersInScope(newObjects.Select(o => new { Id = o.Id, Name = o.Name, X = o.X, Y = o.Y, Rotation = o.Rotation }));
 }