/// <summary>
        /// Handles operation SpawnItem: Creates a new Item and optionally subscribes an InterestArea to it.
        /// </summary>
        public OperationResponse OperationSpawnItem(PeerBase peer, OperationRequest request)
        {
            log.InfoFormat("Spawn item operation started for peer: {0}", this.Peer.ToString());
            var operation = new SpawnItem(peer.Protocol, request);

            if (!operation.IsValid)
            {
                log.InfoFormat("Spawn item operation invalid");
                return(new OperationResponse(request.OperationCode)
                {
                    ReturnCode = (int)ReturnCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage()
                });
            }

            operation.OnStart();
            var item = new Item(operation.Position, operation.Rotation, operation.Properties, this, operation.ItemId, operation.ItemType, this.World);

            if (this.World.ItemCache.AddItem(item))
            {
                log.InfoFormat("adding item");
                this.AddItem(item);
                return(this.ItemOperationSpawn(item, operation));
            }
            log.InfoFormat("Spawn item operation for peer: {0}", this.Peer.ToString());
            item.Dispose();
            return(operation.GetOperationResponse((int)ReturnCode.ItemAlreadyExists, "ItemAlreadyExists"));
        }
        private OperationResponse ItemOperationSpawn(Item item, SpawnItem operation)
        {
            // this should always return Ok
            MethodReturnValue result = this.CheckAccess(item);

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

            operation.OnComplete();
            return(operation.GetOperationResponse(result));
        }
예제 #3
0
        private OperationResponse ItemOperationSpawn(MmoItem item, SpawnItem operation, InterestArea interestArea, MmoActor actor)
        {
            // this should always return Ok
            //MethodReturnValue result = this.CheckAccess(item, actor);

            //if (result) {
            //    item.Rotation = operation.Rotation;
            //    item.Spawn(operation.Position);

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

            //operation.OnComplete();
            //return operation.GetOperationResponse(result);
            return(operation.GetOperationResponse(MethodReturnValue.Ok));
        }
        /// <summary>
        /// Handles operation SpawnItem: Creates a new Item and optionally subscribes an InterestArea to it.
        /// </summary>
        public OperationResponse OperationSpawnItem(PeerBase peer, OperationRequest request)
        {
            var operation = new SpawnItem(peer.Protocol, request);

            if (!operation.IsValid)
            {
                return(new OperationResponse(request.OperationCode)
                {
                    ReturnCode = (int)ReturnCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage()
                });
            }

            operation.OnStart();
            var item = new Item(operation.Position, operation.Rotation, operation.Properties, this, operation.ItemId, operation.ItemType, this.World);

            if (this.World.ItemCache.AddItem(item))
            {
                this.AddItem(item);
                return(this.ItemOperationSpawn(item, operation));
            }

            item.Dispose();
            return(operation.GetOperationResponse((int)ReturnCode.ItemAlreadyExists, "ItemAlreadyExists"));
        }