private static OperationResponse ItemOperationRaiseGenericEvent(Item item, RaiseGenericEvent operation, SendParameters sendParameters)
        {
            if (item.Disposed)
            {
                return(operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound"));
            }

            var eventInstance = new ItemGeneric
            {
                ItemId          = item.Id,
                CustomEventCode = operation.CustomEventCode,
                EventData       = operation.EventData
            };

            var eventData = new EventData((byte)EventCode.ItemGeneric, eventInstance);

            sendParameters.Unreliable = (Reliability)operation.EventReliability == Reliability.Unreliable;
            sendParameters.ChannelId  = Settings.ItemEventChannel;
            switch (operation.EventReceiver)
            {
            case (byte)EventReceiver.ItemOwner:
            {
                item.Owner.Peer.SendEvent(eventData, sendParameters);
                break;
            }

            case (byte)EventReceiver.ItemSubscriber:
            {
                var message = new ItemEventMessage(item, eventData, sendParameters);
                item.EventChannel.Publish(message);
                break;
            }

            default:
            {
                return(operation.GetOperationResponse((int)ReturnCode.ParameterOutOfRange, "Invalid EventReceiver " + operation.EventReceiver));
            }
            }

            // no response
            operation.OnComplete();
            return(null);
        }
        private static OperationResponse ItemOperationRaiseGenericEvent(Item item, RaiseGenericEvent operation, SendParameters sendParameters)
        {
            try {
                if (item.Disposed)
                {
                    return(operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound"));
                }

                var eventInstance = new ItemGeneric {
                    ItemId          = item.Id,
                    ItemType        = item.Type,
                    CustomEventCode = operation.CustomEventCode,
                    EventData       = operation.EventData,
                };

                var eventData = new EventData((byte)EventCode.ItemGeneric, eventInstance);
                sendParameters.Unreliable = (Reliability)operation.EventReliability == Reliability.Unreliable;
                sendParameters.ChannelId  = Settings.ItemEventChannel;



                //switch ((CustomEventCode)operation.CustomEventCode) {
                //    case CustomEventCode.Fire:
                //        {
                //            Hashtable hashSource = eventInstance.EventData as Hashtable;
                //            //ShotType shotType = (ShotType)hashSource.Value<byte>((int)SPC.ShotType, (byte)ShotType.Light);
                //            WeaponHitInfo hit;
                //            Hashtable shotInfo = item.GetComponent<BaseWeapon>().Fire(out hit);
                //            item.GetComponent<MmoMessageComponent>().SendShot(EventReceiver.OwnerAndSubscriber, shotInfo);


                //            if (hit.hitAllowed && !hit.IsWeaponBlocked && hit.isHitted) {
                //                var damagable = item.GetComponent<ShipBasedDamagableObject>();
                //                var bonus = item.GetComponent<PlayerBonuses>();
                //            }
                //        }

                //        break;
                //}

                if ((CustomEventCode)operation.CustomEventCode != CustomEventCode.Fire)
                {
                    switch (operation.EventReceiver)
                    {
                    case (byte)EventReceiver.ItemOwner:
                    {
                        if (((IMmoItem)item).ReceiveEvent(eventData, sendParameters) == false)
                        {
                            string debugMessage = string.Format("Target item {0}/{1} could not receive event", item.Type, item.Id);
                            operation.OnComplete();
                            return(operation.GetOperationResponse((int)ReturnCode.InvalidOperation, debugMessage));
                        }

                        break;
                    }

                    case (byte)EventReceiver.ItemSubscriber:
                    {
                        var message = new ItemEventMessage(item, eventData, sendParameters);
                        item.EventChannel.Publish(message);
                        break;
                    }

                    case (byte)EventReceiver.OwnerAndSubscriber:
                    {
                        ((IMmoItem)item).ReceiveEvent(eventData, sendParameters);
                        var message = new ItemEventMessage(item, eventData, sendParameters);
                        item.EventChannel.Publish(message);
                        break;
                    }

                    default:
                    {
                        operation.OnComplete();
                        return(operation.GetOperationResponse((int)ReturnCode.ParameterOutOfRange, "Invalid EventReceiver " + operation.EventReceiver));
                    }
                    }
                }

                // no response

                return(null);
            } catch (Exception ex) {
                log.Error(ex);
            }
            operation.OnComplete();
            return(null);
        }