Beispiel #1
0
        /// <summary>
        /// Handles operation <see cref="Animate"/>: Animate the items and ultimately sends event <see cref="ItemAnimate"/> to other clients
        /// </summary>
        /// <param name="peer">The client peer</param>
        /// <param name="request">The request</param>
        /// <returns>Null or an <see cref="OperationResponse"/> with error code <see cref="ErrorCode.ItemNotFound"/></returns>
        public OperationResponse OperationAnimate(PeerBase peer, OperationRequest request, SendParameters sendParameters)
        {
            var operation = new Animate(peer.Protocol, request);
            if (!operation.IsValid)
            {
                return new OperationResponse(request.OperationCode) { ReturnCode = (int)ReturnCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage() };
            }

            Item item;
            if (false == operation.ItemType.HasValue || string.IsNullOrEmpty(operation.ItemId))
            {
                item = this.Avatar;
            }
            else if (this.TryGetItem(operation.ItemType.Value, operation.ItemId, out item) == false)
            {
                return new OperationResponse(request.OperationCode) { ReturnCode = (int)ReturnCode.ItemNotFound, DebugMessage = "ItemNotFound" };
            }

            return this.ItemOperationAnimate((MmoItem)item, operation, operation.Animation, operation.AnimationAction, operation.AnimationWrap, operation.AnimationSpeed, operation.AnimationLayer, sendParameters);
        }
Beispiel #2
0
        /// <summary>
        /// The Animate Operation
        /// </summary>
        /// <param name="item">The mmo item</param>
        /// <param name="operation">The operation</param>
        /// <returns>error code OK</returns>
        private OperationResponse ItemOperationAnimate(MmoItem item, Animate operation, string animation, byte action, byte animationWrap, float animationSpeed, int animationLayer, SendParameters sendParameters)
        {
            MethodReturnValue result = this.CheckAccess(item);
            if (result)
            {
                item.Animation = animation;
                item.AnimationWrap = animationWrap;
                item.AnimationSpeed = animationSpeed;

                var eventInstance = new ItemAnimate
                {
                    ItemId = item.Id,
                    ItemType = item.Type,
                    Animation = animation,
                    AnimationAction = action,
                    AnimationWrap = animationWrap,
                    AnimationSpeed = animationSpeed,
                    AnimationLayer = animationLayer
                };

                EventData eventData = new EventData((byte)EventCode.ItemAnimate, eventInstance);
                sendParameters.ChannelId = Settings.ItemEventChannel;
                var message = new ItemEventMessage(item, eventData, sendParameters);
                item.EventChannel.Publish(message);

                operation.OnComplete();

                return null;
            }

            return operation.GetOperationResponse(result);
        }