Ejemplo n.º 1
0
        public void Setup()
        {
            PacketFactory.Initialize <NoS0575Packet>();
            var builder = new ConfigurationBuilder();
            var databaseConfiguration = new SqlConnectionConfiguration();

            builder.SetBasePath(Directory.GetCurrentDirectory() + ConfigurationPath);
            builder.AddJsonFile("database.json", false);
            builder.Build().Bind(databaseConfiguration);
            databaseConfiguration.Database = "postgresunittest";
            var sqlconnect = databaseConfiguration;

            DataAccessHelper.Instance.EnsureDeleted(sqlconnect);
            var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());

            XmlConfigurator.Configure(logRepository, new FileInfo(ConfigurationPath + "/log4net.config"));
            Logger.InitializeLogger(LogManager.GetLogger(typeof(LoginPacketController)));
            DataAccessHelper.Instance.Initialize(sqlconnect);
            DAOFactory.RegisterMapping(typeof(GameObject.Character).Assembly);
            var map = new MapDTO {
                MapId = 1
            };

            DAOFactory.MapDAO.InsertOrUpdate(ref map);
            _acc = new AccountDTO {
                Name = Name, Password = EncryptionHelper.Sha512("test")
            };
            DAOFactory.AccountDAO.InsertOrUpdate(ref _acc);
            _session.InitializeAccount(_acc);
            _handler = new LoginPacketController(new LoginConfiguration());
            _handler.RegisterSession(_session);
            WebApiAccess.RegisterBaseAdress();
            WebApiAccess.Instance.MockValues = new Dictionary <string, object>();
        }
Ejemplo n.º 2
0
        public MapDTO Insert(MapDTO map)
        {
            try
            {
                using (OpenNosContext context = DataAccessHelper.CreateContext())
                {
                    if (context.Map.FirstOrDefault(c => c.MapId.Equals(map.MapId)) == null)
                    {
                        Map entity = new Map();
                        Mapper.Mappers.MapMapper.ToMap(map, entity);
                        context.Map.Add(entity);
                        context.SaveChanges();
                        if (Mapper.Mappers.MapMapper.ToMapDTO(entity, map))
                        {
                            return(map);
                        }

                        return(null);
                    }
                    return(new MapDTO());
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(null);
            }
        }
        public void Setup()
        {
            PacketFactory.Initialize <NoS0575Packet>();
            var builder        = new ConfigurationBuilder();
            var contextBuilder = new DbContextOptionsBuilder <NosCoreContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString());

            DataAccessHelper.Instance.InitializeForTest(contextBuilder.Options);
            var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());

            XmlConfigurator.Configure(logRepository, new FileInfo(ConfigurationPath + "/log4net.config"));
            Logger.InitializeLogger(LogManager.GetLogger(typeof(CharacterScreenControllerTests)));
            var map = new MapDTO {
                MapId = 1
            };

            DAOFactory.MapDAO.InsertOrUpdate(ref map);
            _acc = new AccountDTO {
                Name = "AccountTest", Password = EncryptionHelper.Sha512("test")
            };
            DAOFactory.AccountDAO.InsertOrUpdate(ref _acc);
            _chara = new CharacterDTO
            {
                Name      = "TestExistingCharacter",
                Slot      = 1,
                AccountId = _acc.AccountId,
                MapId     = 1,
                State     = CharacterState.Active
            };
            DAOFactory.CharacterDAO.InsertOrUpdate(ref _chara);
            _session.InitializeAccount(_acc);
            _handler = new CharacterScreenPacketController();
            _handler.RegisterSession(_session);
        }
Ejemplo n.º 4
0
    public override ActionResult PerformAction(MapDTO mapData)
    {
        // Do Nothing
        result.Success = true;

        return(result);
    }
Ejemplo n.º 5
0
        private static void CreateServerMaps()
        {
            MapDTO testingMap = new MapDTO()
            {
                MapId       = 1,
                Music       = 1,
                Name        = "Testing-Map",
                ShopAllowed = true
            };
            List <byte> mapData = new List <byte>();

            mapData.Add(255); // x length
            mapData.Add(0);   // x length
            mapData.Add(255); // y length
            mapData.Add(0);   // y length

            // create map grid
            for (int i = 0; i < 255; i++)
            {
                for (int j = 0; j < 255; j++)
                {
                    // we can go everywhere
                    mapData.Add(0);
                }
            }
            testingMap.Data = mapData.ToArray();
            DAOFactory.MapDAO.Insert(testingMap);
        }
Ejemplo n.º 6
0
 public MapDTO Insert(MapDTO map)
 {
     try
     {
         using (var context = DataAccessHelper.CreateContext())
         {
             if (context.Map.FirstOrDefault(c => c.MapId.Equals(map.MapId)) == null)
             {
                 Map entity = _mapper.Map <Map>(map);
                 context.Map.Add(entity);
                 context.SaveChanges();
                 return(_mapper.Map <MapDTO>(entity));
             }
             else
             {
                 return(new MapDTO());
             }
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
         return(null);
     }
 }
Ejemplo n.º 7
0
        public void GetMapInfo(int id, string type)
        {
            try
            {
                var mapInfo = new MapDTO();
                var service = new MapService();
                switch (type)
                {
                case "scenic":    //类似是景区
                    mapInfo = service.GetMapInfo(id);
                    break;

                case "catering":    //类似是餐饮
                    mapInfo = service.GetShop(id);
                    break;

                case "hotel":    //类似是酒店
                    mapInfo = service.GetHotel(id);
                    break;
                }
                Context.Response.Write(AjaxResult.Success(mapInfo));
            }
            catch (JsonException jsEx)
            {
                Context.Response.Write(AjaxResult.Error(jsEx.Message, jsEx.ErrorType));
            }
            catch (Exception ex)
            {
                Context.Response.Write(AjaxResult.Error(ex.Message));
            }
        }
Ejemplo n.º 8
0
    public override ActionResult PerformAction(MapDTO mapData)
    {
        // validate components
        var inventoryComponent = actor.entity.gameObject.GetComponent <Inventory>();

        if (inventoryComponent != null)
        {
            if (inventoryComponent.HasRoom())
            {
                // Well this is interesting... Do we delete the game object?  Disable it?  Store the entire Entity?
                // For now, lets just disable it.  Maybe if we drop an item we want to enable it again and teleport to where it was dropped
                item.owner.gameObject.SetActive(false);
                item.owner.position = new CellPosition(100000, 100000); // Teleport item to far away square.  So it can't be picked up while disabled!

                var addItemResult = inventoryComponent.AddItem(item);
                result.AppendMessage(new Message($"{actor.entity.GetColoredName()} picks up {item.owner.GetColoredName()}.", null));
                result.Append(addItemResult);
                result.Success = true;
            }
            else
            {
                // Inventory is full
                result.AppendMessage(new Message($"{actor.entity.GetColoredName()} cannot hold any more items.", null));
            }
        }
        else
        {
            result.AppendMessage(new Message($"{actor.entity.GetColoredName()} can not carry things.", null));
        }

        return(result);
    }
Ejemplo n.º 9
0
    public override ActionResult PerformAction(MapDTO mapData)
    {
        foreach (var operation in _item.Operations)
        {
            var operationResult = operation.Occur(actor.entity, mapData, _targetEntity, _targetPosition);

            SetTargetsFromOperationResult(operationResult);

            result.Append(operationResult.ActionResult);
            result.AppendMessages(operationResult.GetMessages());
        }

        var consumed = !_item.Use();

        if (consumed)
        {
            // Is there an inventory on the actor?
            var actorInventory = actor.entity.gameObject.GetComponent <Inventory>();
            if (actorInventory != null)
            {
                actorInventory.RemoveItem(_item);
            }

            mapData.EntityFloorMap.RemoveEntity(_item.owner);
            GameObject.Destroy(_item.gameObject);
        }

        result.Success = true;
        result.TransitionToStateOnSuccess = GameState.Global_LevelScene;

        return(result);
    }
Ejemplo n.º 10
0
        public void Setup()
        {
            PacketFactory.Initialize <NoS0575Packet>();
            var builder        = new ConfigurationBuilder();
            var contextBuilder = new DbContextOptionsBuilder <NosCoreContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString());

            DataAccessHelper.Instance.InitializeForTest(contextBuilder.Options);
            var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());

            XmlConfigurator.Configure(logRepository, new FileInfo(ConfigurationPath + "/log4net.config"));
            Logger.InitializeLogger(LogManager.GetLogger(typeof(LoginPacketController)));
            var map = new MapDTO {
                MapId = 1
            };

            DAOFactory.MapDAO.InsertOrUpdate(ref map);
            _acc = new AccountDTO {
                Name = Name, Password = EncryptionHelper.Sha512("test")
            };
            DAOFactory.AccountDAO.InsertOrUpdate(ref _acc);
            _session.InitializeAccount(_acc);
            _handler = new LoginPacketController(new LoginConfiguration());
            _handler.RegisterSession(_session);
            WebApiAccess.RegisterBaseAdress();
            WebApiAccess.Instance.MockValues = new Dictionary <string, object>();
        }
Ejemplo n.º 11
0
    public override ActionResult PerformAction(MapDTO mapData)
    {
        // validate components
        var inventoryComponent = actor.entity.gameObject.GetComponent <Inventory>();

        if (inventoryComponent != null)
        {
            var targets = mapData.EntityFloorMap.GetEntities(actor.entity.position).Where(e => e.gameObject.GetComponent <Item>() != null).Select(e => e.gameObject.GetComponent <Item>());
            if (targets.Count() == 0)
            {
                // Nothing there!
                result.AppendMessage(new Message($"There is nothing on the ground.", null));
            }
            else
            {
                var item   = targets.FirstOrDefault();
                var action = new AddItemToInventoryAction(actor, item);
                result.NextAction = action;
            }
        }
        else
        {
            result.AppendMessage(new Message($"{actor.entity.GetColoredName()} can not carry things.", null));
        }


        return(result);
    }
        public static MapDTO LoadToMap(MapNames mapName)
        {
            IEnumerable <string> lines       = Helpers.Maps.GetFileLines(mapName);
            List <ICell>         cells       = new List <ICell>();
            List <Vector2>       lighthouses = new List <Vector2>();

            int counter = 0;

            foreach (string line in lines)
            {
                //TODO: Convendría refactorizar en una única función para evitar ciclos redundantes
                //No se prioriza al no formar parte del reto
                lighthouses.AddRange(LineToLighthouses(line, counter));
                cells.AddRange(LineToCells(line, counter));
                counter++;
            }

            int    sizeX   = lines.First().Length;
            int    sizeY   = lines.Count();
            MapDTO mapData = new MapDTO()
            {
                Map         = new Map(new Vector2(sizeX, sizeY), cells),
                Lighthouses = lighthouses
            };

            return(mapData);
        }
 public GameInitMessage(MapDTO mapDTO, int minX, int maxX, List <GameCharacterDTO> playerDTOs)
 {
     this._mapDTO     = mapDTO;
     this._minX       = minX;
     this._maxX       = maxX;
     this._playerDTOs = playerDTOs;
 }
Ejemplo n.º 14
0
        private void Setup(IEnumerable <IPlayer> players)
        {
            MapDTO mapData = MapParser.LoadToMap(selectedMap);

            SetupMap(mapData.Map);
            SetupLighthouses(mapData.Lighthouses);
            SetupPlayers(players);
        }
Ejemplo n.º 15
0
        public MapDTO GetHotel(int id)
        {
            MapDTO result = null;

            var hotel = new BLL.wx_hotels_info().GetModel(id);

            result = Mapper.Map <Model.wx_hotels_info, MapDTO>(hotel);

            return(result);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 获取景点实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public MapDTO GetMapInfo(int id)
        {
            MapDTO result = null;

            var marker = new BLL.wx_travel_marker().GetModel(id);

            result = Mapper.Map <Model.wx_travel_marker, MapDTO>(marker);

            return(result);
        }
Ejemplo n.º 17
0
        public MapDTO GetShop(int id)
        {
            MapDTO result = null;

            var hotel = new BLL.wx_diancai_shopinfo().GetModel(id);

            result = Mapper.Map <Model.wx_diancai_shopinfo, MapDTO>(hotel);

            return(result);
        }
Ejemplo n.º 18
0
 public MapInstance(MapDTO map, Guid guid, bool shopAllowed, MapInstanceType type)
 {
     XpRate          = 1;
     DropRate        = 1;
     ShopAllowed     = shopAllowed;
     MapInstanceType = type;
     Map             = map;
     MapInstanceId   = guid;
     _monsters       = new ConcurrentDictionary <long, MapMonster>();
     _npcs           = new ConcurrentDictionary <long, MapNpcDTO>();
 }
Ejemplo n.º 19
0
        public ActionResult AddMap(MapDTO map) {

            if (ModelState.IsValid)
            {
                var latestOrder = db.Map.Where(m => m.AplicacionId == map.AplicacionId).OrderByDescending(m => m.Order).FirstOrDefault();
                int order = 1;

                if (latestOrder != null)
                {
                    order = (int)latestOrder.Order + 1;

                }
                var newMap = new Map();
                newMap.AplicacionId = map.AplicacionId;
                newMap.CssModelMap = new CssModel();
                newMap.CssModelMap.BorderColor = map.BorderColor;
                newMap.Lat = map.Lat;
                newMap.Lng = map.Lng;
                newMap.Order = order;
                newMap.Title = map.Title;
                db.Database.Connection.Open();
                db.CssModel.Add(newMap.CssModelMap);
                db.Map.Add(newMap);
                try
                {

                    db.SaveChanges();
                   
                    appCtrl.UpdateVersion(map.AplicacionId);

                }
                catch (Exception ex)
                {
                    return JavaScript("Alert(" + ex.InnerException.ToString() + ")");

                  
                }

                db.Database.Connection.Close();

                db.Database.Connection.Open();

                var listMaps = (from m in db.Map where m.AplicacionId == map.AplicacionId select m).OrderBy(m=>m.Order).ToList();
                db.Database.Connection.Close();

                return PartialView("_ListMapas", listMaps);

            }


            return null;
        }
Ejemplo n.º 20
0
 public static bool ToMapDTO(Map input, MapDTO output)
 {
     if (input == null)
     {
         return(false);
     }
     output.Data        = input.Data;
     output.MapId       = input.MapId;
     output.Music       = input.Music;
     output.Name        = input.Name;
     output.ShopAllowed = input.ShopAllowed;
     return(true);
 }
Ejemplo n.º 21
0
        private void ExecuteHandler(ClientSession session)
        {
            void SendMapStats(MapDTO map, MapInstance mapInstance)
            {
                if (map != null && mapInstance != null)
                {
                    session.SendPacket(session.Character.GenerateSay("-------------MapData-------------", 10));
                    session.SendPacket(session.Character.GenerateSay(
                                           $"MapId: {map.MapId}\n" +
                                           $"MapMusic: {map.Music}\n" +
                                           $"MapName: {map.Name}\n" +
                                           $"MapShopAllowed: {map.ShopAllowed}", 10));
                    session.SendPacket(session.Character.GenerateSay("---------------------------------", 10));
                    session.SendPacket(session.Character.GenerateSay("---------MapInstanceData---------", 10));
                    session.SendPacket(session.Character.GenerateSay(
                                           $"MapInstanceId: {mapInstance.MapInstanceId}\n" +
                                           $"MapInstanceType: {mapInstance.MapInstanceType}\n" +
                                           $"MapMonsterCount: {mapInstance.Monsters.Count}\n" +
                                           $"MapNpcCount: {mapInstance.Npcs.Count}\n" +
                                           $"MapPortalsCount: {mapInstance.Portals.Count}\n" +
                                           $"MapInstanceUserShopCount: {mapInstance.UserShops.Count}\n" +
                                           $"SessionCount: {mapInstance.Sessions.Count()}\n" +
                                           $"MapInstanceXpRate: {mapInstance.XpRate}\n" +
                                           $"MapInstanceDropRate: {mapInstance.DropRate}\n" +
                                           $"MapInstanceMusic: {mapInstance.InstanceMusic}\n" +
                                           $"ShopsAllowed: {mapInstance.ShopAllowed}\n" +
                                           $"IsPVP: {mapInstance.IsPvp}\n" +
                                           $"IsSleeping: {mapInstance.IsSleeping}\n" +
                                           $"Dance: {mapInstance.IsDancing}", 10));
                    session.SendPacket(session.Character.GenerateSay("---------------------------------", 10));
                }
            }

            if (MapId.HasValue)
            {
                MapDTO      map         = DAOFactory.MapDAO.LoadById(MapId.Value);
                MapInstance mapInstance = ServerManager.GetMapInstanceByMapId(MapId.Value);
                if (map != null && mapInstance != null)
                {
                    SendMapStats(map, mapInstance);
                }
            }
            else if (session.HasCurrentMapInstance)
            {
                MapDTO map = DAOFactory.MapDAO.LoadById(session.CurrentMapInstance.Map.MapId);
                if (map != null)
                {
                    SendMapStats(map, session.CurrentMapInstance);
                }
            }
        }
Ejemplo n.º 22
0
        public MapInstance GenerateMapInstance(short mapId, MapInstanceType type)
        {
            MapDTO map = _maps.FirstOrDefault(m => m.MapId.Equals(mapId));

            if (map == null)
            {
                return(null);
            }
            Guid        guid        = Guid.NewGuid();
            MapInstance mapInstance = new MapInstance(map, guid, false, type);

            _mapinstances.TryAdd(guid, mapInstance);
            return(mapInstance);
        }
Ejemplo n.º 23
0
 public IEnumerable <MapDTO> FindByName(string name)
 {
     using (OpenNosContext context = DataAccessHelper.CreateContext())
     {
         List <MapDTO> result = new List <MapDTO>();
         foreach (Map map in context.Map.Where(s => string.IsNullOrEmpty(name) ? s.Name.Equals("") : s.Name.Contains(name)))
         {
             MapDTO dto = new MapDTO();
             Mapper.Mappers.MapMapper.ToMapDTO(map, dto);
             result.Add(dto);
         }
         return(result);
     }
 }
Ejemplo n.º 24
0
 public IEnumerable <MapDTO> LoadAll()
 {
     using (OpenNosContext context = DataAccessHelper.CreateContext())
     {
         List <MapDTO> result = new List <MapDTO>();
         foreach (Map Map in context.Map)
         {
             MapDTO dto = new MapDTO();
             Mapper.Mappers.MapMapper.ToMapDTO(Map, dto);
             result.Add(dto);
         }
         return(result);
     }
 }
Ejemplo n.º 25
0
    public override ActionResult PerformAction(MapDTO mapData)
    {
        // Trigger operations off a given Entity, like an item?
        if (_targetEntity != null)
        {
            var itemComponent = _targetEntity.gameObject.GetComponent <Item>();
            if (itemComponent != null)
            {
                result.NextAction = new UseItemAction(actor, itemComponent);
                result.Success    = false;
            }
        }

        return(result);
    }
Ejemplo n.º 26
0
    ActionResult ProcessTurn()
    {
        var actionResult = new ActionResult();
        var actor        = _actors.ElementAt(_currentActorId);
        var action       = actor.GetAction(_entityMap, _groundMap);
        var actionToTake = action;

        if (action == null)
        {
            return(new ActionResult());
        }

        do
        {
            var mapData = new MapDTO {
                EntityMap = _entityMap, EntityFloorMap = _entityMapBackground, GroundMap = _groundMap
            };
            actionResult = actionToTake.PerformAction(mapData);

            // Cleanup to handle after player potentially changes position
            var adjustment =
                Camera.main.transform.position = new Vector3(_player.position.x + CalculateCameraAdjustment(), _player.position.y, Camera.main.transform.position.z);

            if (actionResult.Success)
            {
                TransitionFrom(_gameState);
                TransitionTo(actionResult.TransitionToStateOnSuccess);
            }

            actionToTake = actionResult.NextAction;
        }while (actionResult.NextAction != null);


        if (actionResult.Success)
        {
            _currentActorId = (_currentActorId + 1) % _actors.Count();
            if (actor.entity == _player)
            {
                fovSystem.Run(new Vector2Int(_player.position.x, _player.position.y), playerViewDistance);
                _groundMap.UpdateTiles();
            }
        }

        ProcessNewState();

        return(actionResult);
    }
Ejemplo n.º 27
0
 public MapDTO Insert(MapDTO map)
 {
     using (var context = DataAccessHelper.CreateContext())
     {
         if (context.map.SingleOrDefault(c => c.MapId.Equals(map.MapId)) == null)
         {
             Map entity = Mapper.Map <Map>(map);
             context.map.Add(entity);
             context.SaveChanges();
             return(Mapper.Map <MapDTO>(entity));
         }
         else
         {
             return(new MapDTO());
         }
     }
 }
Ejemplo n.º 28
0
        public void Initialize()
        {
            // parse rates
            try
            {
                int i            = 0;
                int monstercount = 0;
                OrderablePartitioner <MapDTO>        mapPartitioner = Partitioner.Create(DAOFactory.MapDAO.LoadAll(), EnumerablePartitionerOptions.NoBuffering);
                ConcurrentDictionary <short, MapDTO> _mapList       = new ConcurrentDictionary <short, MapDTO>();
                Parallel.ForEach(mapPartitioner, new ParallelOptions {
                    MaxDegreeOfParallelism = 8
                }, map =>
                {
                    Guid guid      = Guid.NewGuid();
                    MapDTO mapinfo = new MapDTO()
                    {
                        Music = map.Music,
                        Data  = map.Data,
                        MapId = map.MapId
                    };
                    _mapList[map.MapId] = mapinfo;
                    MapInstance newMap  = new MapInstance(mapinfo, guid, map.ShopAllowed, MapInstanceType.BaseMapInstance);
                    _mapinstances.TryAdd(guid, newMap);

                    monstercount += newMap.Monsters.Count;
                    i++;
                });
                _maps.AddRange(_mapList.Select(s => s.Value));
                if (i != 0)
                {
                    Logger.Log.Info(string.Format(Language.Instance.GetMessageFromKey("MAPS_LOADED"), i));
                }
                else
                {
                    Logger.Log.Error(Language.Instance.GetMessageFromKey("NO_MAP"));
                }
                Logger.Log.Info(string.Format(Language.Instance.GetMessageFromKey("MAPMONSTERS_LOADED"), monstercount));
            }
            catch (Exception ex)
            {
                Logger.Log.Error("General Error", ex);
            }
        }
Ejemplo n.º 29
0
    public override ActionResult PerformAction(MapDTO mapData)
    {
        // validate components
        var inventoryComponent = actor.entity.gameObject.GetComponent <Inventory>();

        if (inventoryComponent != null)
        {
            _item.owner.gameObject.SetActive(true);
            _item.owner.SetPosition(actor.entity.position.Clone());

            inventoryComponent.RemoveItem(_item);

            result.AppendMessage(new Message($"{actor.entity.GetColoredName()} drops {_item.owner.GetColoredName()}.", null));
            result.Success = true;
        }

        result.TransitionToStateOnSuccess = GameState.Global_LevelScene;

        return(result);
    }
Ejemplo n.º 30
0
    public override ActionResult PerformAction(MapDTO mapData)
    {
        // validate components
        var fighterComponent = actor.entity.gameObject.GetComponent <Fighter>();
        var inMeleeDistance  = actor.entity.DistanceTo(targetPos) <= 1; // If this was an attribute could allow for 2+ tile melee weapons

        if (fighterComponent != null && inMeleeDistance)
        {
            var targets = mapData.EntityMap.GetEntities(targetPos).Where(e => e.gameObject.GetComponent <Fighter>() != null);

            result.Append(fighterComponent.Attack(targets.FirstOrDefault()));
            result.Success = true;
        }
        else
        {
            result.Success = false;
        }

        return(result);
    }