Exemple #1
0
        public int AddEntity(Entity en, Position at)
        {
#if DEBUG
            if (en == null)
            {
                throw new Exception("Entity is null.");
            }
            if (en.Id != 0)
            {
                throw new Exception("Entity has already been added.");
            }
#endif

            if (GetTileF(at.X, at.Y) == null)
            {
                return(-1);
            }

            en.Id       = ++NextObjectId;
            en.Parent   = this;
            en.Position = at;
            MoveEntity(en, en.Position);

            if (en is StaticObject)
            {
                Statics.Add(en.Id, en as StaticObject);
                return(en.Id);
            }

            if (en is Player)
            {
                Players.Add(en.Id, en as Player);
                PlayerChunks.Insert(en);
            }
            else if (en is Decoy)
            {
                Entities.Add(en.Id, en);
                PlayerChunks.Insert(en);
            }
            else
            {
                Entities.Add(en.Id, en);
                EntityChunks.Insert(en);

                if (en.Desc.Quest)
                {
                    Quests.Add(en.Id, en);
                }
            }

            if (en.Constant)
            {
                Constants.Add(en.Id, en);
            }

            en.Init();
            return(en.Id);
        }
Exemple #2
0
        public void MoveEntity(Entity en, Position to)
        {
#if DEBUG
            if (en == null)
            {
                throw new Exception("Undefined entity.");
            }
#endif
            if (en.Position != to)
            {
                en.Position = to;
                en.UpdateCount++;

                if (en is StaticObject)
                {
                    return;
                }

                ChunkController controller = (en is Player || en is Decoy)
                    ? PlayerChunks : EntityChunks;
                controller.Insert(en);
            }
        }