예제 #1
0
        public static ItemBase FromSnapshot(ItemSnapshot snapshot)
        {
            var item = (ItemBase)GameState.Instance.ItemsByName[snapshot.Name].Clone();

            item.UpdateLevel(snapshot.Level);
            return(item);
        }
예제 #2
0
        /// <summary>
        ///   Receives the <see cref = "ItemSnapshot" />.
        ///   auto subscribes item if necessary.
        /// </summary>
        /// <param name = "message">
        ///   The message.
        /// </param>
        internal void ReceiveItemSnapshot(ItemSnapshot message)
        {
            lock (this.SyncRoot)
            {
                //ConsoleLogging.Get.Print("received snapshot: {0} {1}", message.Source.Id.Substring(0, 3), (ItemType)message.Source.Type);
                // auto subscribe item?
                if (this.AutoSubscribeItem(message.Source) == false)
                {
                    //ConsoleLogging.Get.Print("THIS IS NOT AUTO SUBSCRIBED ITEM, EXIT");
                    return;
                }

                ItemAutoSubscription subscription;

                // already subscribed
                if (this.autoManagedItemSubscriptions.TryGetValue(message.Source, out subscription))
                {
                    //ConsoleLogging.Get.Print("ALREADY AUTOSUBSCRIBED, EXIT");
                    // dropped out of world, unsubscribe
                    if (message.WorldRegion == null)
                    {
                        this.AutoUnsubscribeItem(subscription);
                        return;
                    }

                    // update position
                    subscription.ItemPosition = message.Position;
                    subscription.WorldRegion  = message.WorldRegion;
                    return;
                }

                // already subscribed
                if (this.manualManagedItemSubscriptions.ContainsKey(message.Source))
                {
                    //ConsoleLogging.Get.Print("ALREADY MANUAL SUBSCRIBED,EXIT");
                    return;
                }

                // item not in view
                if (message.WorldRegion == null || this.subscribedWorldRegions.ContainsKey(message.WorldRegion) == false)
                {
                    //ConsoleLogging.Get.Print("ITEM NOT VIEW");
                    return;
                }

                // unsubscribe if item is disposed
                IDisposable disposeListener = message.Source.DisposeChannel.Subscribe(this.subscriptionManagementFiber, this.AutoSubscribedItem_OnItemDisposed);

                // unsubscribe if item moves out of range
                IDisposable itemPositionEvaluator = message.Source.PositionUpdateChannel.SubscribeToLast(
                    this.subscriptionManagementFiber, this.AutoSubscribedItem_OnItemPosition, ItemAutoUnsubcribeDelayMilliseconds);

                var itemSubscription = new ItemAutoSubscription(
                    message.Source, message.Position, message.WorldRegion, new UnsubscriberCollection(disposeListener, itemPositionEvaluator));
                this.autoManagedItemSubscriptions.Add(message.Source, itemSubscription);

                this.OnItemSubscribed(message);
            }
        }
예제 #3
0
        protected override void OnItemSubscribed(ItemSnapshot itemSnapshot)
        {
            Item item = itemSnapshot.Source;

            // publish event messages
            IDisposable messageReceiver = item.EventChannel.Subscribe(this.fiber, this.SubscribedItem_OnItemEvent);

            this.eventChannelSubscriptions.Add(item, messageReceiver);
        }
예제 #4
0
        /// <summary>
        ///   Receives the <see cref = "ItemSnapshot" />.
        ///   auto subscribes item if necessary.
        /// </summary>
        /// <param name = "message">
        ///   The message.
        /// </param>
        internal void ReceiveItemSnapshot(ItemSnapshot message)
        {
            lock (this.SyncRoot)
            {
                // auto subscribe item?
                if (this.AutoSubscribeItem(message.Source) == false)
                {
                    return;
                }

                ItemAutoSubscription subscription;

                // already subscribed
                if (this.autoManagedItemSubscriptions.TryGetValue(message.Source, out subscription))
                {
                    // dropped out of world, unsubscribe
                    if (message.WorldRegion == null)
                    {
                        this.AutoUnsubscribeItem(subscription);
                        return;
                    }

                    // update position
                    subscription.ItemPosition = message.Position;
                    subscription.WorldRegion  = message.WorldRegion;
                    return;
                }

                // already subscribed
                if (this.manualManagedItemSubscriptions.ContainsKey(message.Source))
                {
                    return;
                }

                // item not in view
                if (message.WorldRegion == null || this.subscribedWorldRegions.ContainsKey(message.WorldRegion) == false)
                {
                    return;
                }

                // unsubscribe if item is disposed
                IDisposable disposeListener = message.Source.DisposeChannel.Subscribe(this.subscriptionManagementFiber, this.AutoSubscribedItem_OnItemDisposed);

                // unsubscribe if item moves out of range
                IDisposable itemPositionEvaluator = message.Source.PositionUpdateChannel.SubscribeToLast(
                    this.subscriptionManagementFiber, this.AutoSubscribedItem_OnItemPosition, ItemAutoUnsubcribeDelayMilliseconds);

                var itemSubscription = new ItemAutoSubscription(
                    message.Source, message.Position, message.WorldRegion, new UnsubscriberCollection(disposeListener, itemPositionEvaluator));
                this.autoManagedItemSubscriptions.Add(message.Source, itemSubscription);

                this.OnItemSubscribed(message);
            }
        }
예제 #5
0
        /// <summary>
        ///   Publishes a <see cref = "ItemPositionMessage" /> in the <see cref = "PositionUpdateChannel" />
        ///   and in the current <see cref = "Region" /> if it changes
        ///   and then updates the <see cref = "CurrentWorldRegion" />.
        /// </summary>
        public void UpdateInterestManagement()
        {
            Region newRegion = world.GetRegion(transform.position.ToVector());

            // inform attached and auto subscribed (delayed) interest areas
            ItemPositionMessage message = this.GetPositionUpdateMessage(transform.position.ToVector(), newRegion);

            this.positionUpdateChannel.Publish(message);
            //ConsoleLogging.Get.Print("position update channel count {0} on item {1}", positionUpdateChannel.NumSubscribers, (ItemType)Type);

            if (this.SetCurrentWorldRegion(newRegion))
            {
                // inform unsubscribed interest areas in new region
                ItemSnapshot snapshot = this.GetItemSnapshot();
                newRegion.Publish(snapshot);
            }
        }
예제 #6
0
        protected override void OnItemSubscribed(ItemSnapshot snapshot)
        {
            //ConsoleLogging.Get.Print("ON PLAYER ITEM SUBSSCRIBED: {0}, {1}", snapshot.Source.Id.Substring(0, 3), (ItemType)snapshot.Source.Type);
            base.OnItemSubscribed(snapshot);
            var mmoSnapshot = (MmoItemSnapshot)snapshot;
            var item        = snapshot.Source;

            if ((bool)item == false)
            {
                return;
            }

            byte subType = (byte)0;

            if (item.GetComponent <BotObject>())
            {
                subType = item.GetComponent <BotObject>().botSubType;
            }

            string displayName = item.name;

            //log.InfoFormat("item subscribed position: {0},{1},{2}", item.transform.position.X, item.transform.position.Y, item.transform.position.Z);

            var subscribeEvent = new ItemSubscribed
            {
                ItemId             = item.Id,
                ItemType           = item.Type,
                Position           = item.transform.position.ToArray(), //mmoSnapshot.Coordinate,
                PropertiesRevision = snapshot.PropertiesRevision,
                InterestAreaId     = this.Id,
                Rotation           = mmoSnapshot.Rotation,
                SubType            = subType,
                Properties         = item.properties.raw,
                DisplayName        = displayName,
                Components         = item.componentIds,
                size    = item.size,
                subZone = item.subZone
            };
            var eventData = new EventData((byte)EventCode.ItemSubscribed, subscribeEvent);

            this.Peer.SendEvent(eventData, new SendParameters {
                ChannelId = Settings.ItemEventChannel
            });
            //log.InfoFormat("SEND ITEM SUBSCRIBE {0}:{1}  ITEM VALID: {2}", (ItemType)item.Type, item.Id, (bool)item);
        }
예제 #7
0
        /// <summary>
        ///   Subscribes the <see cref = "PeerBase" /> to the item's <see cref = "Item.EventChannel" />.
        /// </summary>
        /// <param name = "itemSnapshot">
        ///   The item snapshot message.
        /// </param>
        protected override void OnItemSubscribed(ItemSnapshot itemSnapshot)
        {
            Item item = itemSnapshot.Source;

            // publish event messages
            IDisposable messageReceiver = item.EventChannel.Subscribe(this.fiber, this.SubscribedItem_OnItemEvent);

            this.eventChannelSubscriptions.Add(item, messageReceiver);


            /*
             * if (item.Type == (byte)ItemType.Bot) {
             *  if (!this.positionChannelSubscriptions.ContainsKey(item))
             *  {
             *      IDisposable posMessageReceiver = item.PositionUpdateChannel.Subscribe(this.fiber, SubscribedItem_OnItemPosition);
             *      this.positionChannelSubscriptions.Add(item, posMessageReceiver);
             *  }
             * }*/
        }
예제 #8
0
        /// <summary>
        ///   Called by the <see cref = "Item" /> when received.
        ///   Increments <see cref = "MessageCounters.CounterReceive" /> and publishes an <see cref = "ItemPositionMessage" /> in the <paramref name = "item" />'s <see cref = "Item.CurrentWorldRegion" />.
        /// </summary>
        /// <param name = "item">
        ///   The calling item.
        /// </param>
        public override void OnItemReceive(Item item)
        {
            MessageCounters.CounterReceive.Increment();

            ItemSnapshot itemSnapshot = item.GetItemSnapshot();

            this.source.ReceiveItemSnapshot(itemSnapshot);

#if MissingSubscribeDebug
            if (log.IsDebugEnabled)
            {
                log.DebugFormat(
                    "{0} sent snap shot to interest area {1} - region {2}",
                    item.Id,
                    this.source.GetHashCode(),
                    itemSnapshot.WorldRegion.Coordinate);
            }
#endif
        }
예제 #9
0
        /// <summary>
        ///   Publishes a <see cref = "ItemPositionMessage" /> in the <see cref = "PositionUpdateChannel" />
        ///   and in the current <see cref = "Region" /> if it changes
        ///   and then updates the <see cref = "CurrentWorldRegion" />.
        /// </summary>
        public void UpdateInterestManagement()
        {
            Region newRegion = this.World.GetRegion(this.Position);

            // inform attached and auto subscribed (delayed) interest areas
            ItemPositionMessage message = this.GetPositionUpdateMessage(this.Position, newRegion);

            this.positionUpdateChannel.Publish(message);

            if (this.SetCurrentWorldRegion(newRegion))
            {
                // inform unsubscribed interest areas in new region
                ItemSnapshot snapshot = this.GetItemSnapshot();
                newRegion.Publish(snapshot);

#if MissingSubscribeDebug
                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("{0} sent snap shot to region {1}", this.id, newRegion.Coordinate);
                }
#endif
            }
        }
예제 #10
0
 /// <summary>
 ///   Does nothing.
 ///   Called after subscribing an <see cref = "Item" />, either manually (<see cref = "SubscribeItem">SubscribeItem</see>) or automatically.
 /// </summary>
 /// <param name = "itemSnapshot">
 ///   The hearbeat message from the subscribed item.
 /// </param>
 /// <remarks>
 ///   Thread Safety: This method does not provide thread safe access to the <see cref = "Item" />.
 ///   Instead of accessing the item directly override <see cref = "Item.GetItemSnapshot" /> subsclass that contains a copy of the required values.
 /// </remarks>
 /// <remarks>
 ///   Thread Safety: This method is executed while having an exclusive lock on <see cref = "SyncRoot" />.
 /// </remarks>
 protected virtual void OnItemSubscribed(ItemSnapshot itemSnapshot)
 {
 }