Пример #1
0
        //public GameObject(string id, MmoWorld world, Vector position, byte itemType, Race race, byte subType, string name, IEvent worldEvent = null, object worldEventTag = null)
        //    : base(position, new Hashtable(), id, itemType, world, null, true, new Dictionary<byte, object>())
        //{
        //    mEvent = AddComponent<EventedObject>();
        //    mRace = AddComponent<RaceableObject>();
        //    mRace.SetRace(race);
        //    mBot = AddComponent<BotObject>();
        //    mBot.SetSubType(subType);
        //    mEvent.SetEvent(worldEvent);
        //    mEvent.SetEventTag(worldEventTag);
        //    mMessage = AddComponent<MmoMessageComponent>();
        //    this.name = name;

        //}

        public bool AddToWorld()
        {
            try {
                if (world.AddObject(this))
                {
                    StartFiber();
                    this.interestArea = new InterestArea(0, (IWorld)world);
                    this.interestArea.AttachToItem(this);
                    this.interestArea.ViewDistanceEnter = new Vector {
                        X = 0, Y = 0, Z = 0
                    };
                    this.interestArea.ViewDistanceExit = new Vector {
                        X = 0, Y = 0, Z = 0
                    };
                    transform.SetPosition(new Vector {
                        X = transform.position.X, Y = transform.position.Y, Z = transform.position.Z
                    });
                    UpdateInterestManagement();
                    //log.InfoFormat("GameObject {0} added to world successfully", name);
                    return(true);
                }
                else
                {
                    log.Error("Error of adding to world");
                    Destroy();
                    return(false);
                }
            } catch (Exception exception) {
                log.Error(exception);
                log.Error(exception.StackTrace);
            }
            return(false);
        }
Пример #2
0
 public bool AddArea(InterestArea area)
 {
     try
     {
         _objectContext.InterestAreas.Add(area);
         _objectContext.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Пример #3
0
    /// <summary>
    /// The initialize.
    /// </summary>
    /// <param name="game">
    /// The game.
    /// </param>
    /// <param name="cameraId">
    /// The camera Id.
    /// </param>
    /// <param name="position">
    /// The position.
    /// </param>
    /// <param name="moveDirection">
    /// The direction of movement
    /// </param>
    public void Initialize(Game game, byte cameraId, Vector3 position, Vector3 moveDirection)
    {
        this.interestArea = new InterestArea(cameraId, game, Player.GetPosition(position));
        this.interestArea.ResetViewDistance();
        this.direction    = moveDirection;
        this.nextMoveTime = Time.time + 0.05f;
        this.interestArea.Create();
        this.transform.position = position;

        float terrainHeight = Terrain.activeTerrain.SampleHeight(position);

        this.height = position.y - terrainHeight;
    }
Пример #4
0
 public MmoItem(PeerBase peer, InterestArea interest, IWorld world, GameApplication app, float[] coordinate, float[] rotation,
                Hashtable properties, string gameRefId, Dictionary <byte, object> inTags, float size, int subZone, BehaviourCollection collection)
     : base(coordinate.ToVector(false), properties, gameRefId, (byte)ItemType.Avatar, world, peer.RequestFiber, false, inTags, size, subZone, collection)
 {
     owner = GetComponent <MmoActor>();
     owner.SetApplication(app);
     owner.SetPeer(peer);
     owner.SetAvatar(this);
     owner.AddInterestArea(interest);
     owner.SetWorld(world);
     transform.SetPosition(coordinate);
     transform.SetRotation(rotation);
 }
Пример #5
0
        /// <summary>
        ///   Increments <see cref = "MessageCounters.CounterReceive" /> and subscribes the <see cref = "InterestArea" /> to the <see cref = "Source" /> item if it not already subscribed or attached.
        ///   Called by the <see cref = "InterestArea" /> when received.
        /// </summary>
        /// <param name = "interestArea">
        ///   The calling interest area.
        /// </param>
        public override void OnInterestAreaReceive(InterestArea interestArea)
        {
            MessageCounters.CounterReceive.Increment();

            interestArea.ReceiveItemSnapshot(this);
#if MissingSubscribeDebug
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("{1} received snap shot from item {0} - region {2}",
                                this.source.Id,
                                interestArea.GetHashCode(),
                                this.WorldRegion.Coordinate);
            }
#endif
        }
Пример #6
0
        public async Task <ActionResult> ConfirmAddOrEdit(InterestArea model)
        {
            if (ModelState.IsValid == false)
            {
                return(View("AddOrEdit", model));
            }
            if (model.InterestAreaId > 0)
            {
                var offe = await db.InterestAreas.FirstOrDefaultAsync(x => x.InterestAreaName == model.InterestAreaName && x.InterestAreaId != model.InterestAreaId);

                if (offe == null)
                {
                    var interestArea = await db.InterestAreas.FindAsync(model.InterestAreaId);

                    if (interestArea != null)
                    {
                        interestArea.InterestAreaName   = model.InterestAreaName;
                        interestArea.InterestAreaActive = model.InterestAreaActive;
                        interestArea.MailCollection     = model.MailCollection;
                        db.Entry(interestArea).State    = EntityState.Modified;
                        await db.SaveChangesAsync();
                    }
                }
            }
            else
            {
                var area = await db.InterestAreas.FirstOrDefaultAsync(a => a.InterestAreaName == model.InterestAreaName);

                if (area == null)
                {
                    area = new InterestArea()
                    {
                        CreationDate       = DateTime.Now,
                        InterestAreaName   = model.InterestAreaName,
                        InterestAreaActive = model.InterestAreaActive,
                        MailCollection     = model.MailCollection
                    };
                    db.InterestAreas.Add(area);
                    await db.SaveChangesAsync();
                }
                else
                {
                    ModelState.AddModelError("", "Ya existe un área con el nombre " + model.InterestAreaName);
                    return(View("AddOrEdit", model));
                }
            }
            return(RedirectToAction("Index"));
        }
Пример #7
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (interestArea != null)
                {
                    this.interestArea.Dispose();
                    interestArea = null;
                }

                this.Fiber.Dispose();

                world.RemoveObject(Type, Id);
            }

            base.Dispose(disposing);
        }
Пример #8
0
        public async Task <ActionResult> Delete(int?id)
        {
            try
            {
                InterestArea interestArea = await db.InterestAreas.FindAsync(id);

                db.InterestAreas.Remove(interestArea);
                await db.SaveChangesAsync();

                //return Json(new AjaxResponse { Success = true, Message = "La Categoría se eliminó correctamente." }, JsonRequestBehavior.AllowGet);
                return(RedirectToAction("Index"));
            }
            catch (Exception)
            {
                //return Json(new AjaxResponse { Success = false, Message = "No se puede eliminar la categoría, está siendo utilizada por otra instancia." }, JsonRequestBehavior.AllowGet);
            }
            return(RedirectToAction("NotFound", "Error"));
        }
        private OperationResponse ItemOperationAttachInterestArea(MmoActor actor, Item item, AttachInterestArea operation, InterestArea interestArea, SendParameters sendParameters)
        {
            if (item.Disposed)
            {
                return(operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound"));
            }

            lock (interestArea.SyncRoot) {
                interestArea.Detach();
                interestArea.AttachToItem(item);
                interestArea.UpdateInterestManagement();
            }

            // use item channel to ensure that this event arrives before any move or subscribe events
            OperationResponse response = operation.GetOperationResponse(MethodReturnValue.Ok);

            sendParameters.ChannelId = Settings.ItemEventChannel;
            actor.Peer.SendOperationResponse(response, sendParameters);

            operation.OnComplete();
            return(null);
        }
        private OperationResponse ItemOperationAttachInterestArea(
            Item item, AttachInterestArea operation, InterestArea interestArea, SendParameters sendParameters)
        {
            if (item.Disposed)
            {
                return operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound");
            }

            lock (interestArea.SyncRoot)
            {
                interestArea.Detach();
                interestArea.AttachToItem(item);
                interestArea.UpdateInterestManagement();
            }

            // use item channel to ensure that this event arrives before any move or subscribe events
            OperationResponse response = operation.GetOperationResponse(MethodReturnValue.Ok);
            sendParameters.ChannelId = Settings.ItemEventChannel;
            this.Peer.SendOperationResponse(response, sendParameters);

            operation.OnComplete();
            return null;
        }
 public MmoActorOperationHandler(PeerBase peer, World world, InterestArea interestArea)
     : base(peer, world)
 {
     this.AddInterestArea(interestArea);
 }
Пример #12
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "MmoObjectSnapshotRequest" /> class.
 /// </summary>
 public MmoObjectSnapshotRequest(InterestArea source)
 {
     this.source = source;
 }
Пример #13
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "ItemSnapshotRequest" /> class.
 /// </summary>
 /// <param name = "source">
 ///   The source.
 /// </param>
 public ItemSnapshotRequest(InterestArea source)
 {
     this.source = source;
 }
Пример #14
0
 /// <summary>
 ///   Called by the <see cref = "InterestArea" /> when received.
 /// </summary>
 /// <param name = "interestArea">
 ///   The calling interest area.
 /// </param>
 public abstract void OnInterestAreaReceive(InterestArea interestArea);
Пример #15
0
        private OperationResponse ItemOperationSubscribeItem(Item item, SubscribeItem operation, InterestArea interestArea, MmoActor actor)
        {
            if (item.Disposed)
            {
                return(operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound"));
            }

            lock (interestArea.SyncRoot) {
                interestArea.SubscribeItem(item);
            }

            if (operation.PropertiesRevision.HasValue == false || operation.PropertiesRevision.Value != item.properties.propertiesRevision)
            {
                var properties = new ItemPropertiesSet {
                    ItemId             = item.Id,
                    ItemType           = item.Type,
                    PropertiesRevision = item.properties.propertiesRevision,
                    PropertiesSet      = item.properties.raw
                };
                var eventData = new EventData((byte)EventCode.ItemPropertiesSet, properties);
                actor.Peer.SendEvent(eventData, new SendParameters {
                    ChannelId = Settings.ItemEventChannel
                });
            }

            // don't send response
            operation.OnComplete();
            return(null);
        }
Пример #16
0
 public void AddInterestArea(InterestArea interestArea)
 {
     this.interestAreas.Add(interestArea.Id, interestArea);
 }
Пример #17
0
 public bool TryGetInterestArea(byte interestAreaId, out InterestArea interestArea)
 {
     return this.interestAreas.TryGetValue(interestAreaId, out interestArea);
 }
 /// <summary>
 ///   Called by the <see cref = "InterestArea" /> when received.
 ///   Increments <see cref = "MessageCounters.CounterReceive" />.
 /// </summary>
 /// <param name = "interestArea">
 ///   The calling interest area.
 /// </param>
 public override void OnInterestAreaReceive(InterestArea interestArea)
 {
     MessageCounters.CounterReceive.Increment();
 }
 /// <summary>
 ///   Initializes a new instance of the <see cref = "ItemSnapshotRequest" /> class.
 /// </summary>
 /// <param name = "source">
 ///   The source.
 /// </param>
 public ItemSnapshotRequest(InterestArea source)
 {
     this.source = source;
 }
Пример #20
0
        private static void PaintCamera(Game game, Graphics graphics, int[] boardSize, InterestArea camera)
        {
            Color color = Color.FromArgb(game.Avatar.Color);
            var   pen   = new Pen(color);

            WorldData world = game.WorldData;

            float width  = world.Width;
            float height = world.Height;
            float w      = boardSize[0] / width;
            float h      = boardSize[1] / height;

            float x = (camera.Position.X * w) - 1;
            float y = ((world.BoundingBox.Max.Y - camera.Position.Y) * h) - 1;

            // draw view distance
            graphics.DrawRectangle(
                pen,
                x - (camera.ViewDistanceEnter.X * w),
                y - (camera.ViewDistanceEnter.Y * h),
                w * 2 * camera.ViewDistanceEnter.X,
                h * 2 * camera.ViewDistanceEnter.Y);

            // draw view distance exit
            graphics.DrawRectangle(
                pen,
                x - (camera.ViewDistanceExit.X * w),
                y - (camera.ViewDistanceExit.Y * h),
                w * 2 * camera.ViewDistanceExit.X,
                h * 2 * camera.ViewDistanceExit.Y);

            // make view distance distance thicker
            graphics.DrawRectangle(
                pen,
                x - (camera.ViewDistanceEnter.X * w) + 1,
                y - (camera.ViewDistanceEnter.Y * h) + 1,
                (w * camera.ViewDistanceEnter.X * 2) - 2,
                (h * camera.ViewDistanceEnter.Y * 2) - 2);

            // make view distance distance thicker
            graphics.DrawRectangle(
                pen,
                x - (camera.ViewDistanceExit.X * w) + 1,
                y - (camera.ViewDistanceExit.Y * h) + 1,
                (w * camera.ViewDistanceExit.X * 2) - 2,
                (h * camera.ViewDistanceExit.Y * 2) - 2);
        }
Пример #21
0
 public RequestItemExitMessage(InterestArea interestArea)
 {
     this.InterestArea = interestArea;
 }
Пример #22
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));
        }
Пример #23
0
        /// <summary>
        /// The paint camera.
        /// </summary>
        /// <param name="game">
        /// The mmo game.
        /// </param>
        /// <param name="graphics">
        /// The graphics.
        /// </param>
        /// <param name="boardSize">
        /// The board size.
        /// </param>
        /// <param name="camera">
        /// The camera.
        /// </param>
        private static void PaintCamera(Game game, Graphics graphics, int[] boardSize, InterestArea camera)
        {
            Color color = Color.FromArgb(game.Avatar.Color);
            var pen = new Pen(color);

            WorldData world = game.WorldData;

            float width = world.Width;
            float height = world.Height;
            float w = boardSize[0] / width;
            float h = boardSize[1] / height;

            float x = ((world.BottomRightCorner[0] - camera.Position[0]) * w) - 1;
            float y = (camera.Position[1] * h) - 1;

            // draw view distance
            graphics.DrawRectangle(
                pen, 
                x - (camera.ViewDistanceEnter[0] * w), 
                y - (camera.ViewDistanceEnter[1] * h), 
                w * 2 * camera.ViewDistanceEnter[0], 
                h * 2 * camera.ViewDistanceEnter[1]);

            // draw view distance exit
            graphics.DrawRectangle(
                pen, 
                x - (camera.ViewDistanceExit[0] * w), 
                y - (camera.ViewDistanceExit[1] * h), 
                w * 2 * camera.ViewDistanceExit[0], 
                h * 2 * camera.ViewDistanceExit[1]);

            // make view distance distance thicker 
            graphics.DrawRectangle(
                pen, 
                x - (camera.ViewDistanceEnter[0] * w) + 1, 
                y - (camera.ViewDistanceEnter[1] * h) + 1, 
                (w * camera.ViewDistanceEnter[0] * 2) - 2, 
                (h * camera.ViewDistanceEnter[1] * 2) - 2);

            // make view distance distance thicker 
            graphics.DrawRectangle(
                pen, 
                x - (camera.ViewDistanceExit[0] * w) + 1, 
                y - (camera.ViewDistanceExit[1] * h) + 1, 
                (w * camera.ViewDistanceExit[0] * 2) - 2, 
                (h * camera.ViewDistanceExit[1] * 2) - 2);
        }
Пример #24
0
 /// <summary>
 ///   Increments <see cref = "MessageCounters.CounterReceive" /> and subscribes the <see cref = "InterestArea" /> to the <see cref = "Source" /> item if it not already subscribed or attached.
 ///   Called by the <see cref = "InterestArea" /> when received.
 /// </summary>
 public override void OnInterestAreaReceive(InterestArea interestArea)
 {
     interestArea.ReceiveMmoObjectSnapshot(this);
 }
Пример #25
0
 /// <summary>
 ///   Called by the <see cref = "InterestArea" /> when received.
 ///   Increments <see cref = "MessageCounters.CounterReceive" />.
 /// </summary>
 public override void OnInterestAreaReceive(InterestArea interestArea)
 {
 }
        private static OperationResponse ItemOperationAddInterestArea(Item item, AddInterestArea operation, InterestArea interestArea)
        {
            if (item.Disposed)
            {
                return(operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound"));
            }

            lock (interestArea.SyncRoot) {
                interestArea.AttachToItem(item);
                interestArea.ViewDistanceEnter = operation.ViewDistanceEnter.ToVector(true);
                interestArea.ViewDistanceExit  = operation.ViewDistanceExit.ToVector(true);
                interestArea.UpdateInterestManagement();
            }

            operation.OnComplete();
            return(operation.GetOperationResponse(MethodReturnValue.Ok));
        }
        private static OperationResponse ItemOperationAddInterestArea(Item item, AddInterestArea operation, InterestArea interestArea)
        {
            if (item.Disposed)
            {
                return operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound");
            }

            lock (interestArea.SyncRoot)
            {
                interestArea.AttachToItem(item);
                interestArea.ViewDistanceEnter = operation.ViewDistanceEnter;
                interestArea.ViewDistanceExit = operation.ViewDistanceExit;
                interestArea.UpdateInterestManagement();
            }

            operation.OnComplete();
            return operation.GetOperationResponse(MethodReturnValue.Ok);
        }
Пример #28
0
        /// <summary>
        ///   Increments <see cref = "MessageCounters.CounterReceive" /> and subscribes the <see cref = "InterestArea" /> to the <see cref = "Source" /> item if it not already subscribed or attached.
        ///   Called by the <see cref = "InterestArea" /> when received.
        /// </summary>
        /// <param name = "interestArea">
        ///   The calling interest area.
        /// </param>
        public override void OnInterestAreaReceive(InterestArea interestArea)
        {
            MessageCounters.CounterReceive.Increment();

            interestArea.ReceiveItemSnapshot(this);
            #if MissingSubscribeDebug
                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("{1} received snap shot from item {0} - region {2}",
                        this.source.Id,
                        interestArea.GetHashCode(),
                        this.WorldRegion.Coordinate);
                }
            #endif
        }
Пример #29
0
 /// <summary>
 ///   Called by the <see cref = "InterestArea" /> when received.
 ///   Increments <see cref = "MessageCounters.CounterReceive" />.
 /// </summary>
 /// <param name = "interestArea">
 ///   The calling interest area.
 /// </param>
 public override void OnInterestAreaReceive(InterestArea interestArea)
 {
     MessageCounters.CounterReceive.Increment();
 }
Пример #30
0
 /// <summary>
 ///   Called by the <see cref = "InterestArea" /> when received.
 /// </summary>
 /// <param name = "interestArea">
 ///   The calling interest area.
 /// </param>
 public abstract void OnInterestAreaReceive(InterestArea interestArea);