예제 #1
0
        private NonPlayerEntity _locateMatch(NonPlayerEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            var matches = _npeRepository.GetByRomId(entity.RomId);

            double          distance       = _maxDistanceForNPEMatch;
            NonPlayerEntity result         = null;
            Vector3         entityLocation = new Vector3(entity.X, entity.Y, entity.Z);

            //locate closest
            foreach (NonPlayerEntity npe in matches)
            {
                Vector3 loc  = new Vector3(npe.X, npe.Y, npe.Z);
                double  dist = entityLocation.Distance(loc);
                if (dist < distance)
                {
                    distance = dist;
                    result   = npe;
                }
            }

            return(result);
        }
예제 #2
0
        public void ImportFile()
        {
            var npcs = LoadNPCs("data\\_npcs.xml");

            ISessionFactory fac     = RomViewContainer.Container.GetInstance <ISessionFactory>();
            ISession        session = fac.OpenSession();
            ITransaction    tx      = session.BeginTransaction();

            CallSessionContext.Bind(session);

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

                foreach (NPCRecord npc in npcs)
                {
                    //if (addedIdList.Contains(npc.id)) continue;
                    NonPlayerEntity test = repository.GetByRomId(npc.id, npc.guid);
                    //session.CreateCriteria<NonPlayerEntity>()
                    //.Add(Restrictions.Eq("RomId", npc.id))
                    //.Add(Restrictions.Eq("UniqueId", npc.guid))
                    //.UniqueResult<NonPlayerEntity>();

                    if (test != null)
                    {
                        continue;
                    }

                    test = repository.GetAll().FirstOrDefault(m => ((m.RomId == npc.id) && (m.ZoneId == npc.zoneid)));
                    if (test == null)
                    {
                        NonPlayerEntity entity = new NonPlayerEntity();
                        entity.RomId    = npc.id;
                        entity.UniqueId = npc.guid;
                        entity.Name     = npc.name;
                        entity.X        = npc.x;
                        entity.Y        = npc.y;
                        entity.Z        = npc.z;
                        entity.ZoneId   = npc.zoneid;

                        repository.Add(entity);
                    }
                    else
                    {
                        test.UniqueId = npc.guid;
                        repository.Update(test);
                    }

                    addedIdList.Add(npc.id);
                    ;
                }
                tx.Commit();
            }
            finally
            {
                session.Close();
            }
        }
예제 #3
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();
            }
        }
예제 #4
0
        public void Chart(int maxDistanceFromNode)
        {
            _maxDistanceFromNode = maxDistanceFromNode;

            foreach (DictionaryEntry entry in MappedPoints)
            {
                (entry.Value as PlottedMapPoint).NonPlayerEntities.Clear();
            }

            //locate all npcs
            foreach (var npc in _npcs)
            {
                NonPlayerEntity entity = npc;
                _npcLocations.Remove(entity);

                Vector3         coords = new Vector3(entity.X, entity.Y, entity.Z);
                PlottedMapPoint pt     = FindNearest(coords, entity.ZoneId);
                if ((pt != null) && (pt.Location.Distance(coords) < maxDistanceFromNode))
                {
                    pt.AddNPC(entity);
                    _npcLocations.Add(entity, pt);
                }
            }

            //find shortest routes for each type (caching here so faster when playing game).
        }
예제 #5
0
        public void AddNPE(NonPlayerEntity entity)
        {
            string key = entity.RomId.ToString() + "." + entity.UniqueId.ToString();

            if (_npcLookup.ContainsKey(key))
            {
                throw new ArgumentException("Entity Id already exists in the map", "entity");
            }

            _npcLookup.Add(key, entity);
            if (_npcByRomId.ContainsKey(entity.RomId))
            {
                throw new ArgumentException("Entity RomId already exists in the map", "entity");
            }
            ;
            _npcByRomId.Add(entity.RomId, entity);

            Vector3         coords = new Vector3(entity.X, entity.Y, entity.Z);
            PlottedMapPoint pt     = FindNearest(coords, entity.ZoneId);

            if ((pt != null) && (pt.Location.Distance(coords) < _maxDistanceFromNode))
            {
                pt.AddNPC(entity);
                _npcLocations.Add(entity, pt);
            }
        }
        public NonPlayerEntity GetByRomId(int romId, int uniqueId)
        {
            NonPlayerEntity result = null;

            try
            {
                result = _repository.GetAll().First(entity => ((entity.RomId == romId) && ((entity.UniqueId == uniqueId))));
            }
            catch
            {
            }

            return(result);
        }
예제 #7
0
        private LocatedQuest _determineBestNearestQuestToDo()
        {
            Dictionary <int, NonPlayerEntity> npcs   = new Dictionary <int, NonPlayerEntity>();
            List <QuestDefinition>            quests = new List <QuestDefinition>(_questRep.FindByLevelRange(_character.PrimaryLevel, _character.PrimaryLevel + 1));
            //determine distance from current location
            SortableList locatedQuests = new SortableList(new LocatedQuestComparer());

            locatedQuests.KeepSorted    = true;
            locatedQuests.AddDuplicates = true;
            foreach (QuestDefinition quest in quests)
            {
                if (_character.CompletedQuests.Count(q => q.Id == quest.Id) > 0)
                {
                    continue;
                }

                if (quest.StarterId > 0)
                {
                    if (!npcs.ContainsKey(quest.StarterId))
                    {
                        NonPlayerEntity npc = _npeRep.GetAll().FirstOrDefault(npe => npe.RomId == quest.StarterId);

                        if (npc != null)
                        {
                            npcs.Add(quest.StarterId, npc);
                        }
                    }
                    if (npcs.ContainsKey(quest.StarterId))
                    {
                        NonPlayerEntity npc = npcs[quest.StarterId];
                        Vector3         loc = new Vector3(npc.X, npc.Y, npc.Z);
                        LocatedQuest    lQ  = new LocatedQuest()
                        {
                            Location = loc,
                            Quest    = quest,
                            Starter  = npc,
                            Distance = _state.Location.Distance(loc)
                        };
                        locatedQuests.Add(lQ); ////////store quest, item +locations.......
                    }
                }
            }

            if (locatedQuests.Count > 0)
            {
                return((LocatedQuest)locatedQuests[0]);
            }
            return(null);
        }
예제 #8
0
 public void AddNPC(NonPlayerEntity entity)
 {
     if (!NonPlayerEntities.Contains(entity))
     {
         foreach (TeleportLink link in entity.Links)
         {
             MapLink l = new MapLink()
             {
                 Start    = MapPoint,
                 End      = link.End,
                 LinkType = LinkType.Teleport,
                 Script   = link.Script
             };
             Links.Add(l);
         }
         EntityTypes = EntityTypes | entity.EntityTypes;
         NonPlayerEntities.Add(entity);
     }
 }
예제 #9
0
        public List <MapLink> BuildRoute(Vector3 start, int startZoneId, int npeId)
        {
            PlottedMapPoint pStart = FindNearest(start, startZoneId);

            //locate npe
            NonPlayerEntity entity = GetEntity(npeId);

            if ((entity == null) || (pStart == null))
            {
                return(new List <MapLink>());
            }

            PlottedMapPoint pEnd = (PlottedMapPoint)_npcLocations[entity];

            if (pEnd == null)
            {
                return(new List <MapLink>());
            }

            return(BuildRoute(pStart.MapPoint, pEnd.MapPoint));
        }
예제 #10
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);
        }
        public void Delete(int entityId)
        {
            NonPlayerEntity entity = Get(entityId);

            _repository.Delete(entity);
        }
 public void Update(NonPlayerEntity entity)
 {
     _repository.SaveOrUpdate(entity);
 }