示例#1
0
        public void UpdateObject(ISimpleGameObject sender, uint origX, uint origY)
        {
            if (!sender.InWorld)
            {
                throw new Exception(string.Format("Received update for obj that is not in world: eventOrigX[{1}] eventOrigY[{2}] {0}",
                                                  sender.ToString(),
                                                  origX,
                                                  origY));
            }

            var miniMapRegionObject = sender as IMiniMapRegionObject;

            if (miniMapRegionObject != null)
            {
                MiniMapRegions.UpdateObjectRegion(miniMapRegionObject, origX, origY);
            }

            // Lock regions from both old and new positions
            var lockedRegions = LockRegions(GetMultitileRegionIds(sender.PrimaryPosition.X, sender.PrimaryPosition.Y, sender.Size)
                                            .Concat(GetMultitileRegionIds(origX, origY, sender.Size)));

            ushort previousPrimaryRegionId = regionLocator.GetRegionIndex(origX, origY);
            ushort newPrimaryRegionId      = regionLocator.GetRegionIndex(sender);

            RemoveFromPrimaryRegionAndAllTiles(sender, origX, origY);
            AddToPrimaryRegionAndTiles(sender);

            if (previousPrimaryRegionId == newPrimaryRegionId)
            {
                var packet = new Packet(Command.ObjectUpdate);
                packet.AddUInt16(newPrimaryRegionId);
                PacketHelper.AddToPacket(sender, packet);
                channel.Post("/WORLD/" + newPrimaryRegionId, packet);
            }
            else
            {
                var packet = new Packet(Command.ObjectMove);
                packet.AddUInt16(previousPrimaryRegionId);
                packet.AddUInt16(newPrimaryRegionId);
                PacketHelper.AddToPacket(sender, packet);
                channel.Post("/WORLD/" + previousPrimaryRegionId, packet);

                packet = new Packet(Command.ObjectAdd);
                packet.AddUInt16(newPrimaryRegionId);
                PacketHelper.AddToPacket(sender, packet);
                channel.Post("/WORLD/" + newPrimaryRegionId, packet);
            }

            UnlockRegions(lockedRegions);
        }
示例#2
0
        public void Remove(ISimpleGameObject obj)
        {
            if (!obj.InWorld)
            {
                return;
            }

            var lockedRegions = LockMultitileRegions(obj.PrimaryPosition.X, obj.PrimaryPosition.Y, obj.Size);

            if (RemoveFromPrimaryRegionAndAllTiles(obj, obj.PrimaryPosition.X, obj.PrimaryPosition.Y))
            {
                obj.InWorld = false;

                DeregisterObjectEventListeners(obj);

                IMiniMapRegionObject miniMapRegionObject = obj as IMiniMapRegionObject;
                if (miniMapRegionObject != null)
                {
                    MiniMapRegions.Remove(miniMapRegionObject);
                }

                ushort regionId = regionLocator.GetRegionIndex(obj);
                channel.Post("/WORLD/" + regionId, () =>
                {
                    var packet = new Packet(Command.ObjectRemove);
                    packet.AddUInt16(regionId);
                    packet.AddUInt32(obj.GroupId);
                    packet.AddUInt32(obj.ObjectId);
                    return(packet);
                });
            }

            UnlockRegions(lockedRegions);

            // Raise event
            ObjectRemoved.Raise(this, new ObjectEvent(obj));
        }
示例#3
0
        public bool Add(ISimpleGameObject obj)
        {
            if (!AddToPrimaryRegionAndTiles(obj))
            {
                return(false);
            }

            // Keeps track of objects that exist in the map
            obj.InWorld = true;

            RegisterObjectEventListeners(obj);

            // Add appropriate objects to the minimap
            IMiniMapRegionObject miniMapRegionObject = obj as IMiniMapRegionObject;

            if (miniMapRegionObject != null)
            {
                MiniMapRegions.Add(miniMapRegionObject);
            }

            // Post to channel
            ushort regionId = regionLocator.GetRegionIndex(obj);

            channel.Post("/WORLD/" + regionId, () =>
            {
                var packet = new Packet(Command.ObjectAdd);
                packet.AddUInt16(regionId);
                PacketHelper.AddToPacket(obj, packet);
                return(packet);
            });

            // Raise event
            ObjectAdded.Raise(this, new ObjectEvent(obj));

            return(true);
        }