Exemplo n.º 1
0
        public void TestCanAddSingleItem()
        {
            ISessionFactory fac     = RomViewContainer.Container.GetInstance <ISessionFactory>();
            ISession        session = fac.OpenSession();
            ITransaction    tx      = session.BeginTransaction();

            LazySessionContext.Bind(new Lazy <ISession>(() => session), fac);

            try
            {
                IRepository <NonPlayerEntity> rep        = RomViewContainer.Container.GetInstance <IRepository <NonPlayerEntity> >();
                INonPlayerEntityRepository    repository = new NonPlayerEntityRespository(rep);

                NonPlayerEntity def = new NonPlayerEntity
                {
                    RomId = 225932,
                    Name  = "MyNPC",
                };

                string expected = def.ToDelimitedString(1);

                repository.Add(def);

                //NonPlayerEntity result = repository.GetByRomId(def.RomId);
                //Assert.AreEqual(expected, result.ToDelimitedString(1));
            }
            finally
            {
                tx.Rollback();
                session.Close();
            }
        }
Exemplo n.º 2
0
        private string _handleNPEMessage(string[] sections)
        {
            string response = null;

            NonPlayerEntity entity;
            int             romId;
            NonPlayerEntity match;

            switch (sections[1])
            {
            case "SAVE":
                entity = new NonPlayerEntity(sections[2], 2);

                match = _locateMatch(entity);

                if (match != null)
                {
                    match.Name   = entity.Name;
                    match.ZoneId = entity.ZoneId;
                    match.X      = entity.X;
                    match.Y      = entity.Y;
                    match.Z      = entity.Z;
                    if (entity.EntityTypes > 0)
                    {
                        match.EntityTypes = entity.EntityTypes;
                    }
                    match.RomType  = entity.RomType;
                    match.UniqueId = entity.UniqueId;

                    _npeRepository.Update(match);
                }
                else
                {
                    _npeRepository.Add(entity);
                }
                break;

            case "BOTUPDATE":
                entity = new NonPlayerEntity(sections[2], 2);
                match  = _locateMatch(entity);

                if (match != null)
                {
                    if (entity.Name.Length > 0)
                    {
                        match.Name = entity.Name;
                    }
                    if (entity.ZoneId > 0)
                    {
                        match.ZoneId = entity.ZoneId;
                    }
                    match.X        = entity.X;
                    match.Y        = entity.Y;
                    match.Z        = entity.Z;
                    match.UniqueId = entity.UniqueId;

                    _npeRepository.Update(match);
                }
                else
                {
                    _npeRepository.Add(entity);
                }
                break;

            case "DELETE":
                romId = Convert.ToInt32(sections[2]);
                //_npeRepository.Delete(romId);
                break;

            case "GET":
                romId = Convert.ToInt32(sections[2]);
                int uniqueId = Convert.ToInt32(sections[2]);
                entity = _npeRepository.GetByRomId(romId, uniqueId);
                if (entity != null)
                {
                    response = entity.ToDelimitedString(1);
                }
                else
                {
                    response = NonPlayerEntity.GetNullDefinitionString(1);
                }
                break;
            }

            return(response);
        }