/// <summary>
 /// Loads the entities async to the regions around the surrender center region and add the entities to these regions.
 /// </summary>
 /// <returns>The task async.</returns>
 /// <param name="regionPosition">region position.</param>
 public async Task LoadEntitiesAsync(RegionPosition regionPosition)
 {
     var listRegions = new RegionPosition[1];
     listRegions[0] = regionPosition;
    
     await LoadEntitiesAsync(listRegions);
 }
Example #2
0
 /// <summary>
 /// Converts a region position to a world space position
 /// </summary>
 /// <returns>The world space position of the given region position.</returns>
 /// <param name="regionPosition">region position.</param>
 public static CCPoint RegionToWorldspace(RegionPosition regionPosition)
 {
     var firstRegion = Geolocation.Instance.FirstGamePosition.RegionPosition;
     return new CCPoint(
         (regionPosition.RegionX - firstRegion.RegionX) * ClientConstants.TILEMAP_HEX_CONTENTSIZE_WIDTH,
         -(regionPosition.RegionY - firstRegion.RegionY) * ClientConstants.TILEMAP_HEX_CONTENTSIZE_HEIGHT);
 }
        /// <summary>
        /// Tries to get the Region.
        /// </summary>
        /// <returns>The region. If it couldn't be loaded, region.exist is false.</returns>
        /// <param name="regionPosition">Region position.</param>
        public override Region GetRegion(RegionPosition regionPosition)
        {
            var regionManager = World.Instance.RegionManager;
            var region = regionManager.GetRegion(regionPosition);
            if (!region.Exist)
            {
                var path = Core.Helper.LoadHelper.ReplacePath(ServerConstants.REGION_FILE, regionPosition);
                try
                {
                    string json = System.IO.File.ReadAllText(path);
                    region.AddTerrain(Core.Helper.LoadHelper.JsonToTerrain(json));
                    regionManager.AddRegion(region);
                }
                catch (System.IO.DirectoryNotFoundException exception)
                {
                    Console.WriteLine(exception.ToString());
                }
                catch (System.IO.FileNotFoundException exception)
                {
                    Console.WriteLine(exception.ToString());
                }
            }

            return region;
        }
Example #4
0
        /// <summary>
        /// Replaces parts of the path with MajorRegion and MinorRegion of the given Region Position
        /// </summary>
        /// <returns>Path with replaced $MajorRegion and $MinorRegion </returns>
        /// <param name="path">Template Path</param>
        /// <param name="regionPosition">Region Position.</param>
        public static string ReplacePath(string path, Core.Models.RegionPosition regionPosition)
        {
            path = path.Replace("$MajorRegionX", regionPosition.MajorX.ToString());
            path = path.Replace("$MajorRegionY", regionPosition.MajorY.ToString());
            path = path.Replace("$MinorRegionX", regionPosition.RegionX.ToString());
            path = path.Replace("$MinorRegionY", regionPosition.RegionY.ToString());

            return(path);
        }
        /// <summary>
        /// Gets the region.If needed loads the region.
        /// </summary>
        /// <returns>The region.</returns>
        /// <param name="regionPosition">Region position.</param>
        public override Region GetRegion(RegionPosition regionPosition)
        {
            var region = World.Instance.RegionManager.GetRegion(regionPosition);

            if (!region.Exist)
            {
                LoadTerrainAsync(region);
            }
            return region;
        }
Example #6
0
        /// <summary>
        /// Gets the region depending on the region position.
        /// </summary>
        /// <returns>The region.</returns>
        /// <param name="regionPosition">Region position.</param>
        public Region GetRegion(RegionPosition regionPosition)
        {
            if (Regions.ContainsKey(regionPosition))
            {
                return Regions[regionPosition];
            }
            var region = new Region(regionPosition);

            return region;
        }
        /// <summary>
        /// Gets the region depending on the region position.
        /// </summary>
        /// <returns>The region.</returns>
        /// <param name="regionPosition">Region position.</param>
        public Region GetRegion(RegionPosition regionPosition)
        {
            if (Regions.ContainsKey(regionPosition))
            {
                return(Regions[regionPosition]);
            }
            var region = new Region(regionPosition);

            return(region);
        }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Models.Region"/> class.
 /// </summary>
 /// <param name="regionPosition">Region position.</param>
 /// <param name="terrains">Terrains of the region.</param>
 public Region(RegionPosition regionPosition, TerrainDefinition[,] terrains)
 {
     m_regionPosition = regionPosition;
     m_terrains       = terrains;
     m_entities       = new DatedEntities();
     m_territory      = new Dictionary <PositionI, Account>();
     throw new Exception("Territory need to be load");
     m_actions = new DatedActions();
     m_exist   = true;
     m_mutex   = new ReaderWriterLockSlim();
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Models.Region"/> class.
 /// </summary>
 /// <param name="region">Region which should be copied.</param>
 public Region(Region region)
 {
     m_regionPosition = region.m_regionPosition;
     m_terrains = region.m_terrains;
     m_entities = region.m_entities;
     m_territory = region.m_territory;
     m_actions = new DatedActions();
     m_actions.Actions = new LinkedList<Core.Models.Action>();
     m_exist = region.m_exist;
     m_mutex = region.m_mutex;
 }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Models.Region"/> class.
 /// Use Only when there are not data. It will create an empty region where nothing can be changed.
 /// </summary>
 /// <param name="regionPosition">Region position.</param>
 public Region(RegionPosition regionPosition)
 {
     m_regionPosition    = regionPosition;
     m_terrains          = new TerrainDefinition[Constants.REGION_SIZE_X, Constants.REGION_SIZE_Y];
     m_entities          = new DatedEntities();
     m_entities.Entities = new LinkedList <Entity>();
     m_territory         = new Dictionary <PositionI, Account>();
     m_actions           = new DatedActions();
     m_actions.Actions   = new LinkedList <Core.Models.Action>();
     m_exist             = Cheats.DONT_LOAD_REGIONS_MODE;
     m_mutex             = new ReaderWriterLockSlim();
 }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Models.Region"/> class.
 /// Use Only when there are not data. It will create an empty region where nothing can be changed.
 /// </summary>
 /// <param name="regionPosition">Region position.</param>
 public Region(RegionPosition regionPosition)
 {
     m_regionPosition = regionPosition;
     m_terrains = new TerrainDefinition[Constants.REGION_SIZE_X, Constants.REGION_SIZE_Y];
     m_entities = new DatedEntities();
     m_entities.Entities = new LinkedList<Entity>();
     m_territory = new Dictionary<PositionI, Account>();
     m_actions = new DatedActions();
     m_actions.Actions = new LinkedList<Core.Models.Action>();
     m_exist = Cheats.DONT_LOAD_REGIONS_MODE;
     m_mutex = new ReaderWriterLockSlim();
 }
        public void LoadRegion()
        {
            var testLoginRequest = new Core.Connections.LoginRequest(
                new Core.Models.Position(100, 100),
                "Maria",
                "Musterfrau");
            var testJson = JsonConvert.SerializeObject(testLoginRequest);

            var testPackage = new Packet();

            testPackage.Content    = testJson;
            testPackage.MethodType = MethodType.Login;

            var testStream = this.GetStream();

            testPackage.Send(testStream);

            var testPackageIn = Packet.Receive(testStream);

            var loginData = JsonConvert.DeserializeObject <Core.Connections.LoginResponse>(testPackageIn.Content);

            var testRegion = new Core.Models.RegionPosition[]
            {
                new Core.Models.RegionPosition(100, 100),
            };

            var testRequest = new Core.Connections.LoadRegionsRequest(
                loginData.SessionID,
                new Core.Models.Position(100, 100),
                testRegion);

            testJson = JsonConvert.SerializeObject(testRequest);

            testPackage = new Packet();

            testPackage.Content    = testJson;
            testPackage.MethodType = MethodType.LoadEntities;

            testStream = this.GetStream();

            testPackage.Send(testStream);

            testPackageIn = Packet.Receive(testStream);

            var data = JsonConvert.DeserializeObject <Core.Connections.Response>(testPackageIn.Content);

            Assert.AreEqual(Core.Connections.Response.ReponseStatus.OK, data.Status);
        }
        /// <summary>
        /// Gets the world near the region position. Around 5x5 regions at the region position.
        /// </summary>
        /// <returns>The regions around the positions.</returns>
        /// <param name="regionPosition">Region position.</param>
        public HashSet<RegionPosition> GetWorldNearRegionPositions(RegionPosition regionPosition)
        {
            var regions = new HashSet<RegionPosition>();

            int halfX = Common.Constants.ClientConstants.DRAW_REGIONS_X / 2;
            int halfY = Common.Constants.ClientConstants.DRAW_REGIONS_Y / 2;

            for (int x = -halfX; x <= halfX; x++)
            {
                for (int y = -halfY; y <= halfY; y++)
                {
                    var regPos = new RegionPosition(regionPosition.RegionX + x, regionPosition.RegionY + y);
                    regions.Add(regPos);
                }
            }

            return regions;
        }
Example #14
0
        public void MapRegion()
        {
            // Test with a RegionPosition as Input
            var regionPosition = new RegionPosition(new Position(new LatLon(50.97695325, 11.02396488)));
            var region = new Core.Models.Region(regionPosition);

            Assert.IsNotNull(region);
            Assert.IsInstanceOf<Core.Models.Region>(region);

            // Test with a Region as Input
            var region2 = new Region(region);

            Assert.IsNotNull(region2);
            Assert.IsInstanceOf<Core.Models.Region>(region2);
            Assert.AreEqual(region.RegionPosition, region2.RegionPosition);

            // Test with a RegionPosition and an TerrainDefinition as Input
            int[] res = { 0, 0, 0, 0, 0 };
            var terDef = new Core.Models.Definitions.TerrainDefinition(Core.Models.Definitions.EntityType.Grassland, res, true, true, 4, 5, 6);
            // var region3 = new Region(regionPosition, TerDef);
        }
        /// <summary>
        /// Loads the entities async from the list of regions and add the entities to these regions.
        /// Also add the loaded actions to the view worker queue.
        /// </summary>
        /// <returns>The task async.</returns>
        /// <param name="listRegions">List of all regions which should be loaded.</param>
        public async Task LoadEntitiesAsync(RegionPosition[] listRegions)
        {
            var response = await NetworkController.Instance.LoadEntitiesAsync(Geolocation.Instance.CurrentGamePosition, listRegions);
           
            if (response.Actions != null)
            {
                var actions = new HashSet<Core.Models.Action>();
                foreach (var regions in response.Actions)
                {
                    foreach (var action in regions)
                    {
                        actions.Add(action);
                    }   
                }

                var sortedActions = new SortedSet<Core.Models.Action>(actions, new Core.Models.Action.ActionComparer());

                foreach (var action in sortedActions)
                {
                    Views.Worker.Instance.Queue.Enqueue(action);
                }
            }
        }
 /// <summary>
 /// Gets the region.
 /// </summary>
 /// <returns>The region.</returns>
 /// <param name="regionPosition">Region position.</param>
 public virtual Region GetRegion(RegionPosition regionPosition)
 {
     throw new NotImplementedException();
 }
Example #17
0
 /// <summary>
 /// Claims the territory.
 /// </summary>
 /// <param name="territoryList">Territory list.</param>
 /// <param name="account">Current Account.</param>
 /// <param name="entityRegionPos">Entity region position.</param>
 /// <param name="regionMan">Region man.</param>
 public void ClaimTerritory(HashSet<PositionI> territoryList, Account account, RegionPosition entityRegionPos, RegionManager regionMan)
 {
     foreach (var position in territoryList)
     {
         if (!regionMan.GetRegion(position.RegionPosition).m_territory.ContainsKey(position))
         {
             regionMan.GetRegion(position.RegionPosition).m_territory.Add(position, account);
         }
     }
 }
Example #18
0
        public void LoadRegion()
        {
            var testLoginRequest = new Core.Connections.LoginRequest(
                                        new Core.Models.Position(100, 100),
                                        "Maria",
                                        "Musterfrau");
            var testJson = JsonConvert.SerializeObject(testLoginRequest);

            var testPackage = new Packet();

            testPackage.Content = testJson;
            testPackage.MethodType = MethodType.Login;

            var testStream = this.GetStream();

            testPackage.Send(testStream);

            var testPackageIn = Packet.Receive(testStream);

            var loginData = JsonConvert.DeserializeObject<Core.Connections.LoginResponse>(testPackageIn.Content);

            var testRegion = new Core.Models.RegionPosition[]
            {
                    new Core.Models.RegionPosition(100, 100),
            };

            var testRequest = new Core.Connections.LoadRegionsRequest(
                                  loginData.SessionID,
                                  new Core.Models.Position(100, 100),
                                  testRegion);

            testJson = JsonConvert.SerializeObject(testRequest);

            testPackage = new Packet();

            testPackage.Content = testJson;
            testPackage.MethodType = MethodType.LoadEntities;

            testStream = this.GetStream();

            testPackage.Send(testStream);

            testPackageIn = Packet.Receive(testStream);

            var data = JsonConvert.DeserializeObject<Core.Connections.Response>(testPackageIn.Content);

            Assert.AreEqual(Core.Connections.Response.ReponseStatus.OK, data.Status);
        }
Example #19
0
 /// <summary>
 /// Loads the terrains async and returns it.
 /// </summary>
 /// <returns>The terrains async.</returns>
 /// <param name="regionPosition">Region position.</param>
 public async Task<TerrainDefinition[,]> LoadTerrainsAsync(RegionPosition regionPosition)
 {            
     var path = Core.Helper.LoadHelper.ReplacePath(Common.Constants.ClientConstants.REGION_SERVER_PATH, regionPosition);
     var json = await RequestAsync(path);
     return Core.Helper.LoadHelper.JsonToTerrain(json);
 }
Example #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Models.Position"/> class.
 /// </summary>
 /// <param name="regionPosition">Region position.</param>
 /// <param name="cellPosition">Cell position.</param>
 public Position(RegionPosition regionPosition, CellPosition cellPosition)
 {
     X = (regionPosition.RegionX * Constants.REGION_SIZE_X) + cellPosition.CellX;
     Y = (regionPosition.RegionY * Constants.REGION_SIZE_Y) + cellPosition.CellY;
 }
Example #21
0
        /// <summary>
        /// Converts the world spaces position to a game position.
        /// WARNING: Do not convert the position to an PositionI or similar - it is not guaranteed to be equal.
        /// If you need PositionI, better use the World space to PositionI converter
        /// </summary>
        /// <returns>The game position.</returns>
        /// <param name="point">world space position.</param>
        public static Position WorldspaceToPosition(CCPoint point)
        {
            var firstRegion = Geolocation.Instance.FirstGamePosition.RegionPosition;

            var positionX = point.X / ClientConstants.TILEMAP_HEX_CONTENTSIZE_WIDTH;
            var positionY = -point.Y / ClientConstants.TILEMAP_HEX_CONTENTSIZE_HEIGHT;
            var regionPos = new RegionPosition((int)positionX + firstRegion.RegionX, (int)positionY + firstRegion.RegionY);
            var cellPosX = (positionX - (int)positionX) * (ClientConstants.TILEMAP_HEX_WIDTH - 1);
            var cellPosY = (positionY - (int)positionY) * (ClientConstants.TILEMAP_HEX_HEIGHT - 1);
            return new Position(regionPos.RegionX, regionPos.RegionY, cellPosX, cellPosY);
        }
Example #22
0
        /// <summary>
        /// Gets the adjacent regions, which can be affected.
        /// </summary>
        /// <returns>The adjacent regions.</returns>
        /// <param name="regionManagerC">Region manager c.</param>
        /// <param name="position">Current Position od the selected building.</param>
        /// <param name="buildpoint">PositionI from the new unit.</param>
        private ConcurrentBag<RegionPosition> GetAdjacentRegions(RegionManagerController regionManagerC, RegionPosition position, PositionI buildpoint)
        {
            var list = new ConcurrentBag<RegionPosition>();
            var surlist = LogicRules.SurroundRegions;
            var regionSizeX = Constants.REGION_SIZE_X;
            var regionSizeY = Constants.REGION_SIZE_Y;

            var currentpos = LogicRules.GetSurroundedFields(buildpoint);
            var currentregion = regionManagerC.RegionManager.GetRegion(buildpoint.RegionPosition);

            foreach (var checkingpos in currentpos)
            {
                if (regionManagerC.GetRegion(checkingpos.RegionPosition) != currentregion)
                {
                    list.Add(regionManagerC.RegionManager.GetRegion(checkingpos.RegionPosition).RegionPosition);
                }
            }
            return list;
        }
Example #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Models.Position"/> class.
 /// </summary>
 /// <param name="regionPosition">Region position.</param>
 /// <param name="cellPosition">Cell position.</param>
 public Position(RegionPosition regionPosition, CellPosition cellPosition)
 {
     X = (regionPosition.RegionX * Constants.REGION_SIZE_X) + cellPosition.CellX;
     Y = (regionPosition.RegionY * Constants.REGION_SIZE_Y) + cellPosition.CellY;
 }
Example #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Models.Position"/> class.
 /// </summary>
 /// <param name="regionPosition">Region position.</param>
 public Position(RegionPosition regionPosition)
 {
     X = regionPosition.RegionX * Constants.REGION_SIZE_X;
     Y = regionPosition.RegionY * Constants.REGION_SIZE_Y;
 }
Example #25
0
 /// <summary>
 /// Claims the territory.
 /// </summary>
 /// <param name="territoryList">Territory list.</param>
 /// <param name="account">Current Account.</param>
 /// <param name="entityRegionPos">Entity region position.</param>
 /// <param name="regionMan">Region man.</param>
 public void ClaimTerritory(HashSet <PositionI> territoryList, Account account, RegionPosition entityRegionPos, RegionManager regionMan)
 {
     foreach (var position in territoryList)
     {
         if (!regionMan.GetRegion(position.RegionPosition).m_territory.ContainsKey(position))
         {
             regionMan.GetRegion(position.RegionPosition).m_territory.Add(position, account);
         }
     }
 }
Example #26
0
        /// <summary>
        /// Gets the region view hex.
        /// </summary>
        /// <returns>The region view hex.</returns>
        /// <param name="regionPosition">Region position.</param>
        public RegionViewHex GetRegionViewHex(RegionPosition regionPosition)
        {
            RegionViewHex viewRegionHex = null;
            m_regionViewHexDic.TryGetValue(regionPosition, out viewRegionHex);

            return viewRegionHex;
        }
 /// <summary>
 /// Gets the region by game position.
 /// </summary>
 /// <returns>The region by game position.</returns>
 /// <param name="gameWorldPosition">Game world position.</param>
 public Region GetRegionByGamePosition(Position gameWorldPosition)
 {
     RegionPosition regionPosition = new RegionPosition(gameWorldPosition);
     return GetRegion(regionPosition);
 }
Example #28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Models.Region"/> class.
 /// </summary>
 /// <param name="regionPosition">Region position.</param>
 /// <param name="terrains">Terrains of the region.</param>
 public Region(RegionPosition regionPosition, TerrainDefinition[,] terrains)
 {
     m_regionPosition = regionPosition;
     m_terrains = terrains;
     m_entities = new DatedEntities();
     m_territory = new Dictionary<PositionI, Account>();
     throw new Exception("Territory need to be load");
     m_actions = new DatedActions();
     m_exist = true;
     m_mutex = new ReaderWriterLockSlim();
 }
Example #29
0
        /// <summary>
        /// Converts a JSON String to a Region.
        /// </summary>
        /// <returns>Region which was created by the JSON String.</returns>
        /// <param name="json">JSON loaded from the server</param>
        /// <param name="regionPosition">Region position.</param>
        public static Core.Models.Region JsonToRegion(string json, Core.Models.RegionPosition regionPosition)
        {
            var terrains = JsonToTerrain(json);

            return(new Region(regionPosition, terrains));
        }
Example #30
0
        /// <summary>
        /// Creates the action view.
        /// </summary>
        /// <returns>The action view.</returns>
        /// <param name="action">The action.</param>
        /// <param name="regionPosition">The regionposition.</param>
        private Client.Common.Views.Actions.Action CreateActionView(Core.Models.Action action, RegionPosition regionPosition)
        {
            switch (action.Type)
            {
                case Core.Models.Action.ActionType.CreateUnit:
                    return new Client.Common.Views.Actions.CreateUnit(action);

                case Core.Models.Action.ActionType.MoveUnit:
                    return new Client.Common.Views.Actions.MoveUnit(action, WorldLayerHex);

                case Core.Models.Action.ActionType.CreateTerritoryBuilding:
                    return new Client.Common.Views.Actions.CreateTerritoryBuilding(action, WorldLayerHex);

                case Core.Models.Action.ActionType.CreateBuilding:
                    return new Client.Common.Views.Actions.CreateBuilding(action, WorldLayerHex.GetRegionViewHex(regionPosition));
            }
            return new Client.Common.Views.Actions.Action(action);
        }
Example #31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Models.Position"/> class.
 /// </summary>
 /// <param name="regionPosition">Region position.</param>
 public Position(RegionPosition regionPosition)
 {
     X = regionPosition.RegionX * Constants.REGION_SIZE_X;
     Y = regionPosition.RegionY * Constants.REGION_SIZE_Y;
 }
Example #32
0
        /// <summary>
        /// Check all possible regions around the start region of a unit and add them to a ConcurrentBag.
        /// </summary>
        /// <returns>The adjacent regions.</returns>
        /// <param name="regionManagerC">Region manager c.</param>
        /// <param name="position">PositionI of the region.</param>
        private ConcurrentBag<RegionPosition> GetAdjacentRegions(RegionManagerController regionManagerC, RegionPosition position)
        {
            var list = new ConcurrentBag<RegionPosition>();
            var surlist = LogicRules.SurroundRegions;
            var regionSizeX = Constants.REGION_SIZE_X / 2;
            var regionSizeY = Constants.REGION_SIZE_Y / 2;

            if (position.RegionX <= regionSizeX && position.RegionY <= regionSizeY)
            {
                var tempReg = position + surlist[LogicRules.SurroundRegions.Length];
                if (regionManagerC.GetRegion(tempReg).Exist)
                {
                    list.Add(tempReg);
                }

                for (int index = 0; index < 2; ++index)
                {
                    tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            else if (position.RegionX > regionSizeX && position.RegionY <= regionSizeY)
            {
                for (int index = 1; index < 4; ++index)
                {
                    var tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            else if (position.RegionX > regionSizeX && position.RegionY > regionSizeY)
            {
                for (int index = 3; index < 7; ++index)
                {
                    var tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            else
            {
                for (int index = 5; index < 8; ++index)
                {
                    var tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            return list;
        }
        /// <summary>
        /// Gets the adjacent regions, which can be affected.
        /// </summary>
        /// <returns>The adjacent regions.</returns>
        /// <param name="regionManagerC">Region manager c.</param>
        /// <param name="position">Current Position od the selected building.</param>
        /// <param name="buildpoint">PositionI from the new unit.</param>
        private ConcurrentBag<RegionPosition> GetAdjacentRegions(RegionManagerController regionManagerC, RegionPosition position, PositionI buildpoint)
        {
            var list = new ConcurrentBag<RegionPosition>();
            var surlist = LogicRules.SurroundRegions;
            var regionSizeX = Constants.REGION_SIZE_X;
            var regionSizeY = Constants.REGION_SIZE_Y;

            if (buildpoint.CellPosition.CellX <= m_drawArea)
            {
                var tempReg = position + surlist[LogicRules.SurroundRegions.Length - 1];
                if (regionManagerC.GetRegion(tempReg).Exist)
                {
                    list.Add(tempReg);
                }

                for (int index = 0; index < 4; ++index)
                {
                    tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            else if (buildpoint.CellPosition.CellY <= m_drawArea)
            {
                for (int index = 5; index < LogicRules.SurroundRegions.Length; ++index)
                {
                    var tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }

                var reg = position + surlist[0];
                if (regionManagerC.GetRegion(reg).Exist)
                {
                    list.Add(reg);
                }
                reg = position + surlist[1];
                if (regionManagerC.GetRegion(reg).Exist)
                {
                    list.Add(reg);
                }
            }
            else if (buildpoint.CellPosition.CellX >= regionSizeX - m_drawArea)
            {
                for (int index = 1; index < 6; ++index)
                {
                    var tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            else if (buildpoint.CellPosition.CellY >= regionSizeY - m_drawArea)
            {
                for (int index = 3; index < LogicRules.SurroundRegions.Length; ++index)
                {
                    var tempReg = position + surlist[index];
                    if (regionManagerC.GetRegion(tempReg).Exist)
                    {
                        list.Add(tempReg);
                    }
                }
            }
            return list;
        }
Example #34
0
        /// <summary>
        /// Loads the entities and actions async from the server.
        /// </summary>
        /// <returns>The entities response from the server.</returns>
        /// <param name="currentGamePosition">Current game position.</param>
        /// <param name="regionPositions">Region positions.</param>
        public async Task<Core.Connections.Response> LoadEntitiesAsync(Core.Models.Position currentGamePosition, RegionPosition[] regionPositions)
        {            
            try
            {
                var request = new Core.Connections.LoadRegionsRequest(m_sessionID, currentGamePosition, regionPositions);
                var json = JsonConvert.SerializeObject(request);

                var jsonFromServer = await TcpConnection.Connector.SendAsync(Core.Connection.MethodType.LoadEntities, json);
                var entitiesResponse = JsonConvert.DeserializeObject<Core.Connections.Response>(jsonFromServer);

                if (entitiesResponse.Status == Core.Connections.Response.ReponseStatus.OK)
                {
                    return entitiesResponse;
                }
            }
            catch (Exception error)
            {
                Logging.Error(error.StackTrace);
                Logging.Error(error.Message);
            }

            return new Core.Connections.Response();
        }