Example #1
0
 /// <summary>
 ///   Adds an <see cref = "InterestArea" />.
 /// </summary>
 /// <param name = "interestArea">
 ///   The <see cref = "InterestArea" /> to add.
 /// </param>
 public void AddInterestArea(InterestArea interestArea)
 {
     this.interestAreas.Add(interestArea.Id, interestArea);
 }
Example #2
0
 /// <summary>
 ///   Tries to get an <see cref = "InterestArea" />.
 /// </summary>
 /// <param name = "interestAreaId">
 ///   The interest area id.
 /// </param>
 /// <param name = "interestArea">
 ///   The result <see cref = "InterestArea" />.
 /// </param>
 /// <returns>
 ///   true if the <see cref = "InterestArea" /> with the <paramref name = "interestAreaId" /> was found.
 /// </returns>
 public bool TryGetInterestArea(byte interestAreaId, out InterestArea interestArea)
 {
     return(this.interestAreas.TryGetValue(interestAreaId, out interestArea));
 }
Example #3
0
        /// <summary>
        ///   Subscribes an item.
        /// </summary>
        /// <param name = "item">
        ///   The mmo item.
        /// </param>
        /// <param name = "operation">
        ///   The operation.
        /// </param>
        /// <param name = "interestArea">
        ///   The interestArea.
        /// </param>
        /// <returns>
        ///   Ok or ItemNotFound
        /// </returns>
        private OperationResponse ItemOperationSubscribeItem(Item item, SubscribeItem operation, InterestArea interestArea)
        {
            if (item.Disposed)
            {
                return operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound");
            }

            lock (interestArea.SyncRoot)
            {
                interestArea.SubscribeItem(item);
            }

            if (operation.PropertiesRevision.HasValue == false || operation.PropertiesRevision.Value != item.PropertiesRevision)
            {
                var properties = new ItemPropertiesSet
                    {
                       ItemId = item.Id, ItemType = item.Type, PropertiesRevision = item.PropertiesRevision, PropertiesSet = new Hashtable(item.Properties)
                    };
                var eventData = new EventData((byte)EventCode.ItemPropertiesSet, properties);
                this.Peer.SendEvent(eventData, new SendParameters { ChannelId = Settings.ItemEventChannel });
            }

            // don't send response
            operation.OnComplete();
            return null;
        }
Example #4
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "MmoActor" /> class.
 /// </summary>
 /// <param name = "peer">
 ///   The peer State.
 /// </param>
 /// <param name = "world">
 ///   The world.
 /// </param>
 /// <param name = "interestArea">
 ///   The interestArea.
 /// </param>
 public MmoActor(PeerBase peer, IWorld world, InterestArea interestArea)
     : base(peer, world)
 {
     this.AddInterestArea(interestArea);
 }
Example #5
0
        /// <summary>
        ///   Spawns an item.
        /// </summary>
        /// <param name = "item">
        ///   The mmo item.
        /// </param>
        /// <param name = "operation">
        ///   The operation.
        /// </param>
        /// <param name = "interestArea">
        ///   The interest Area.
        /// </param>
        /// <returns>
        ///   error code ok
        /// </returns>
        private OperationResponse ItemOperationSpawn(MmoItem item, SpawnItem operation, InterestArea interestArea)
        {
            // this should always return Ok
            MethodReturnValue result = this.CheckAccess(item);

            if (result)
            {
                item.Rotation = operation.Rotation;
                item.Spawn(operation.Position);
                ((MmoWorld)this.World).Radar.AddItem(item, operation.Position);

                if (interestArea != null)
                {
                    lock (interestArea.SyncRoot)
                    {
                        interestArea.SubscribeItem(item);
                    }
                }
            }

            operation.OnComplete();
            return operation.GetOperationResponse(result);
        }
Example #6
0
        /// <summary>
        ///   The operation attach interest area.
        /// </summary>
        /// <param name = "item">
        ///   The mmo item.
        /// </param>
        /// <param name = "operation">
        ///   The operation.
        /// </param>
        /// <param name = "interestArea">
        ///   The interestArea.
        /// </param>
        /// <param name = "sendParameters">
        ///   The send Parameters.
        /// </param>
        /// <returns>
        ///   Ok or ItemNotFound
        /// </returns>
        private OperationResponse ItemOperationAttachInterestArea(
            Item item, AttachInterestArea operation, InterestArea interestArea, SendParameters sendParameters)
        {
            if (item.Disposed)
            {
                return operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound");
            }

            lock (interestArea.SyncRoot)
            {
                interestArea.Detach();
                interestArea.AttachToItem(item);
                interestArea.UpdateInterestManagement();
            }

            // use item channel to ensure that this event arrives before any move or subscribe events
            OperationResponse response = operation.GetOperationResponse(MethodReturnValue.Ok);
            sendParameters.ChannelId = Settings.ItemEventChannel;
            this.Peer.SendOperationResponse(response, sendParameters);

            operation.OnComplete();
            return null;
        }
Example #7
0
        /// <summary>
        ///   The operation add interest area.
        /// </summary>
        /// <param name = "item">
        ///   The mmo item.
        /// </param>
        /// <param name = "operation">
        ///   The operation.
        /// </param>
        /// <param name = "interestArea">
        ///   The interestArea.
        /// </param>
        /// <returns>
        ///   Ok or ItemNotFound
        /// </returns>
        private static OperationResponse ItemOperationAddInterestArea(Item item, AddInterestArea operation, InterestArea interestArea)
        {
            if (item.Disposed)
            {
                return operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound");
            }

            lock (interestArea.SyncRoot)
            {
                interestArea.AttachToItem(item);
                interestArea.ViewDistanceEnter = operation.ViewDistanceEnter.ToVector();
                interestArea.ViewDistanceExit = operation.ViewDistanceExit.ToVector();
                interestArea.UpdateInterestManagement();
            }

            operation.OnComplete();
            return operation.GetOperationResponse(MethodReturnValue.Ok);
        }
Example #8
0
 /// <summary>
 ///   Tries to get an <see cref = "InterestArea" />.
 /// </summary>
 /// <param name = "interestAreaId">
 ///   The interest area id.
 /// </param>
 /// <param name = "interestArea">
 ///   The result <see cref = "InterestArea" />.
 /// </param>
 /// <returns>
 ///   true if the <see cref = "InterestArea" /> with the <paramref name = "interestAreaId" /> was found.
 /// </returns>
 public bool TryGetInterestArea(byte interestAreaId, out InterestArea interestArea)
 {
     return this.interestAreas.TryGetValue(interestAreaId, out interestArea);
 }
Example #9
0
 /// <summary>
 ///   Adds an <see cref = "InterestArea" />.
 /// </summary>
 /// <param name = "interestArea">
 ///   The <see cref = "InterestArea" /> to add.
 /// </param>
 public void AddInterestArea(InterestArea interestArea)
 {
     this.interestAreas.Add(interestArea.Id, interestArea);
 }