Exemple #1
0
 /// <summary>
 /// Creates the action which creates the unit.
 /// </summary>
 /// <returns>The create unit action.</returns>
 /// <param name="positionI">Position where the unit should be created.</param>
 /// <param name="definition">Definition which unit should be created.</param>
 /// <param name="account">Which account creates the action.</param>
 private static Core.Models.Action CreateUnit(PositionI positionI, Definition definition, Account account)
 {
     var dictParam = new System.Collections.Generic.Dictionary<string, object>();
     dictParam[Core.Controllers.Actions.CreateUnit.CREATE_POSITION] = positionI;
     dictParam[Core.Controllers.Actions.CreateUnit.CREATION_TYPE] = (long)definition.SubType;
     return new Core.Models.Action(account, Core.Models.Action.ActionType.CreateUnit, dictParam, GameAppDelegate.ServerTime);
 }
Exemple #2
0
 /// <summary>
 /// Creates the action to move a unit.
 /// </summary>
 /// <returns>The move unit action.</returns>
 /// <param name="start">Start position of move.</param>
 /// <param name="end">End position of move.</param>
 public static Core.Models.Action MoveUnit(PositionI start, PositionI end)
 {
     var dictParam = new System.Collections.Generic.Dictionary<string, object>();
     dictParam[Core.Controllers.Actions.MoveUnit.START_POSITION] = start;
     dictParam[Core.Controllers.Actions.MoveUnit.END_POSITION] = end;
     return new Core.Models.Action(GameAppDelegate.Account, Core.Models.Action.ActionType.MoveUnit, dictParam, GameAppDelegate.ServerTime);
 }
Exemple #3
0
        /// <summary>
        /// Apply action-related changes to the world.
        /// Returns set of changed Regions if everything worked, otherwise null
        /// </summary>
        /// <returns>all affected (changed) regions</returns>
        public override ConcurrentBag<Core.Models.Region> Do()
        {
            var regionManagerC = Controller.Instance.RegionManagerController;

            var action = (Core.Models.Action)Model;
            var positionI = (PositionI)action.Parameters[CREATE_POSITION];
            var type = (long)action.Parameters[CREATION_TYPE];
            RealCreatePosition = GetFreeField(positionI, regionManagerC);

            positionI = RealCreatePosition;
            var region = regionManagerC.GetRegion(positionI.RegionPosition);
            var entityDef = Controller.Instance.DefinitionManagerController.DefinitionManager.GetDefinition((EntityType)type);
            var unitHealth = ((UnitDefinition)entityDef).Health;
            var unitMoves = ((UnitDefinition)entityDef).Moves;

            // create the new entity and link to the correct account
            var entity = new Core.Models.Entity(
                             IdGenerator.GetId(),
                             entityDef,
                             action.Account,
                             positionI,
                             unitHealth,
                             unitMoves);

            entity.Position = positionI;
            region.AddEntity(action.ActionTime, entity);

            if (action.Account != null)
            {
                action.Account.Units.AddLast(entity.Position);
                LogicRules.ConsumeResource(action.Account, action.ActionTime, entityDef);
            }
            return new ConcurrentBag<Core.Models.Region>() { region };
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Controllers.AStar.Node"/> class. 
 /// It set the positionI of the Node, set the node state to open and calculate the travel cost to the destination tile.
 /// </summary>
 /// <param name="location">Current PositionI of the Node.</param>
 /// <param name="endLocation">PositionI of the destination tile.</param>
 public Node(PositionI location, PositionI endLocation)
 {
     Location = location;
     State = NodeState.Open;
     H = GetTraversalCost(Location, endLocation);
     G = 0;
 }
        /// <summary>
        /// Gets the surrounded territory around a given Position.
        /// </summary>
        /// <returns>The surrounded positions.</returns>
        /// <param name="entity">Current Entity.</param>
        /// <param name="range">Range around the position.</param>
        public static HashSet<PositionI> GetSurroundedPositions(PositionI entity, int range)
        {
            var fieldSet = new HashSet<PositionI>();
            var fieldSetHelper = new HashSet<PositionI>();

            fieldSet.Add(entity);
            fieldSetHelper.Add(entity);

            for (int index = 0; index != range; ++index)
            {
                var tempfieldSet = new HashSet<PositionI>();
                foreach (var item in fieldSetHelper)
                {
                    var surroundedTiles = GetSurroundedFields(item);
                    foreach (var tile in surroundedTiles)
                    {
                        if (!fieldSet.Contains(tile))
                        {
                            fieldSet.Add(tile);
                            tempfieldSet.Add(tile);
                        }
                    }
                }
                fieldSetHelper = tempfieldSet;
            }
            return fieldSet;
        }
Exemple #6
0
        public void GetSurroundedPositions()
        {
            var startPosition = new Core.Models.PositionI(0, 0);
            int range         = 1;
            var positions     = Core.Models.LogicRules.GetSurroundedPositions(startPosition, range);

            Assert.AreEqual(positions.Count, 7);

            range     = 2;
            positions = Core.Models.LogicRules.GetSurroundedPositions(startPosition, range);

            Assert.AreEqual(positions.Count, 19);

            range     = 3;
            positions = Core.Models.LogicRules.GetSurroundedPositions(startPosition, range);

            Assert.AreEqual(positions.Count, 37);

            range     = 4;
            positions = Core.Models.LogicRules.GetSurroundedPositions(startPosition, range);

            Assert.AreEqual(positions.Count, 61);

            range     = 5;
            positions = Core.Models.LogicRules.GetSurroundedPositions(startPosition, range);

            Assert.AreEqual(positions.Count, 91);
        }
Exemple #7
0
        /// <summary>
        /// Distance from this to the specific position
        /// Warning: NOT ROOTED.
        /// </summary>
        /// <returns>Distance from this to the specific position.</returns>
        /// <param name="position">Other Position.</param>
        public double Distance(PositionI position)
        {
            var distanceX = position.X - X;
            var distanceY = position.Y - Y;

            return((distanceX * distanceX) + (distanceY * distanceY));
        }
Exemple #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Controllers.AStar_Indicator.Indicator"/> class.
 /// </summary>
 /// <param name="startPosition">Start position.</param>
 /// <param name="moves">Moves of the entity.</param>
 /// <param name="accountID">Account ID.</param>
 public Indicator(PositionI startPosition, int moves, int accountID)
 {
     m_startPoint = startPosition;
     m_moves = moves;
     m_accountID = accountID;
     m_indicatorPoints = new HashSet<PositionI>();
 }
Exemple #9
0
        /// <summary>
        /// Gets the claimed territory.
        /// </summary>
        /// <returns>The claimed territory.</returns>
        /// <param name="position">Current Position.</param>
        public Account GetClaimedTerritory(PositionI position)
        {
            Account result;

            if (m_territory.TryGetValue(position, out result))
            {
                return(result);
            }
            return(null);
        }
Exemple #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Core.Controllers.Actions.CreateUnit"/> class.
        /// </summary>
        /// <param name="model">action model.</param>
        public CreateUnit(Core.Models.ModelEntity model)
            : base(model)
        {
            var action = (Core.Models.Action)Model;
            var param = action.Parameters;

            if (param[CREATE_POSITION].GetType() != typeof(PositionI))
            {
                param[CREATE_POSITION] = new PositionI((Newtonsoft.Json.Linq.JContainer)param[CREATE_POSITION]);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Core.Controllers.Actions.CreateBuilding"/> class.
        /// </summary>
        /// <param name="model">action model.</param>
        public CreateBuilding(Core.Models.ModelEntity model)
            : base(model)
        {
            var action = (Core.Models.Action)Model;
            var param  = action.Parameters;

            if (param[CREATE_POSITION].GetType() != typeof(PositionI))
            {
                param[CREATE_POSITION] = new Core.Models.PositionI((Newtonsoft.Json.Linq.JContainer)param[CREATE_POSITION]);
            }
        }
Exemple #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Models.Entity"/> class.
 /// </summary>
 /// <param name="id">Identifier of the entity.</param>
 /// <param name="definition">Definition of the entity.</param>
 /// <param name="owner">Owner of the entity.</param>
 /// <param name="position">Position of the entity.</param>
 /// <param name="health">Health of the entity.</param>
 /// <param name="move">Move of the entity.</param>
 public Entity(int id, Definition definition, Account owner, PositionI position, int health, int move)
     : base()
 {
     ID = id;
     Definition = definition;
     Position = position;
     Owner = owner;
     Health = health;
     Move = move;
     ModifiedDefenseValue = ((UnitDefinition)definition).Attack;
     ModfiedAttackValue = ((UnitDefinition)definition).Defense;
 }
Exemple #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Models.Entity"/> class.
 /// </summary>
 /// <param name="id">Identifier of the entity.</param>
 /// <param name="definition">Definition of the entity.</param>
 /// <param name="owner">Owner of the entity.</param>
 /// <param name="position">Position of the entity.</param>
 /// <param name="health">Health of the entity.</param>
 /// <param name="move">Move of the entity.</param>
 public Entity(int id, Definition definition, Account owner, PositionI position, int health, int move)
     : base()
 {
     ID                   = id;
     Definition           = definition;
     Position             = position;
     Owner                = owner;
     Health               = health;
     Move                 = move;
     ModifiedDefenseValue = ((UnitDefinition)definition).Attack;
     ModfiedAttackValue   = ((UnitDefinition)definition).Defense;
 }
        /// <summary>
        /// Gets the surrounded fields.
        /// </summary>
        /// <returns>The surrounded fields.</returns>
        /// <param name="pos">Center Position.</param>
        public static PositionI[] GetSurroundedFields(PositionI pos)
        {
            var surroundedFields = SurroundTilesEven;
            if (pos.X % 2 == 0)
            {
                surroundedFields = SurroundTilesOdd;
            }

            var surrounded = new PositionI[6];
            for (var index = 0; index < surroundedFields.Length; ++index)
            {
                surrounded[index] = pos + surroundedFields[index];
            }
            return surrounded;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Core.Controllers.Actions.MoveUnit"/> class.
        /// </summary>
        /// <param name="model">action model.</param>
        public MoveUnit(Core.Models.ModelEntity model)
            : base(model)
        {
            var action = (Core.Models.Action)Model;
            var param  = action.Parameters;

            if (param[START_POSITION].GetType() != typeof(PositionI))
            {
                param[START_POSITION] = new Core.Models.PositionI((Newtonsoft.Json.Linq.JContainer)param[START_POSITION]);
            }

            if (param[END_POSITION].GetType() != typeof(PositionI))
            {
                param[END_POSITION] = new Core.Models.PositionI((Newtonsoft.Json.Linq.JContainer)param[END_POSITION]);
            }
        }
        public void DoAction()
        {
            var user = this.GetLogin();

            var testAccount = new Core.Models.Account(user.AccountId);

            var testDefinition = new Core.Models.Definitions.Definition(276);

            var testPositionI = new Core.Models.PositionI(this.TestPosition());

            var dictParam = new System.Collections.Generic.Dictionary <string, object>();

            dictParam[Core.Controllers.Actions.CreateUnit.CREATE_POSITION] = testPositionI;
            dictParam[Core.Controllers.Actions.CreateUnit.CREATION_TYPE]   = (long)testDefinition.SubType;

            var testAction = new Core.Models.Action(testAccount, Core.Models.Action.ActionType.CreateBuilding, dictParam);

            var testActions = new Core.Models.Action[] { testAction, };

            var testActionRequest = new Core.Connections.DoActionsRequest(
                user.SessionID,
                this.TestPosition(),
                testActions);

            var testJson = JsonConvert.SerializeObject(testActionRequest);

            var testPackage = new Packet();

            testPackage.Content    = testJson;
            testPackage.MethodType = MethodType.DoActions;

            var testStream = this.GetStream();

            testPackage.Send(testStream);

            var data = JsonConvert.DeserializeObject <Core.Connections.Response>(Packet.Receive(testStream).Content);

            Assert.AreEqual(Core.Connections.Response.ReponseStatus.OK, data.Status);
        }
Exemple #17
0
        public void DoAction()
        {
            var user = this.GetLogin();

            var testAccount = new Core.Models.Account(user.AccountId);

            var testDefinition = new Core.Models.Definitions.Definition(276);

            var testPositionI = new Core.Models.PositionI(this.TestPosition());

            var dictParam = new System.Collections.Generic.Dictionary<string, object>();
            dictParam[Core.Controllers.Actions.CreateUnit.CREATE_POSITION] = testPositionI;
            dictParam[Core.Controllers.Actions.CreateUnit.CREATION_TYPE] = (long)testDefinition.SubType;

            var testAction = new Core.Models.Action(testAccount, Core.Models.Action.ActionType.CreateBuilding, dictParam);

            var testActions = new Core.Models.Action[] { testAction, };

            var testActionRequest = new Core.Connections.DoActionsRequest(
                                    user.SessionID,
                                    this.TestPosition(),
                                    testActions);

            var testJson = JsonConvert.SerializeObject(testActionRequest);

            var testPackage = new Packet();

            testPackage.Content = testJson;
            testPackage.MethodType = MethodType.DoActions;

            var testStream = this.GetStream();

            testPackage.Send(testStream);

            var data = JsonConvert.DeserializeObject<Core.Connections.Response>(Packet.Receive(testStream).Content);

            Assert.AreEqual(Core.Connections.Response.ReponseStatus.OK, data.Status);
        }
Exemple #18
0
 /// <summary>
 /// Creates the action which creates the unit
 /// </summary>
 /// <returns>The entity create action.</returns>
 /// <param name="positionI">Position where the entity should be created.</param>
 /// <param name="definition">Definition which entity should be created.</param>
 /// <param name="account">Which account creates the action.</param>
 public static Core.Models.Action CreateEntity(PositionI positionI, Core.Models.Definitions.Definition definition, Account account)
 {
     switch (definition.Category)
     {
         // TODO: add more sub categorys and better check
         case Category.Building:
             if (definition.SubType == EntityType.Headquarter)
             {
                 return CreatTerritoryBuilding(positionI, definition, account);
             }
             else if (definition.SubType == EntityType.GuardTower)
             {
                 return CreatTerritoryBuilding(positionI, definition, account);
             }
             else
             {
                 return CreateBuilding(positionI, definition, account);
             }
         case Category.Unit:
             return CreateUnit(positionI, definition, account);
     }
     return null;
 }
Exemple #19
0
        public void GetSurroundedFields()
        {
            // Test for Even x Coordinate
            var startPosition = new Core.Models.PositionI(0, 0);
            var positions     = Core.Models.LogicRules.GetSurroundedFields(startPosition);

            var expectedPos = new Core.Models.PositionI[]
            {
                startPosition + SurroundTilesOdd[0],
                startPosition + SurroundTilesOdd[1],
                startPosition + SurroundTilesOdd[2],
                startPosition + SurroundTilesOdd[3],
                startPosition + SurroundTilesOdd[4],
                startPosition + SurroundTilesOdd[5]
            };

            Assert.IsNotEmpty(positions);
            Assert.AreEqual(6, positions.Length);
            Assert.AreEqual(positions, expectedPos);

            // Test For uneven x Coordinate
            startPosition = new Core.Models.PositionI(1, 0);
            positions     = Core.Models.LogicRules.GetSurroundedFields(startPosition);

            expectedPos = new Core.Models.PositionI[]
            {
                startPosition + SurroundTilesEven[0],
                startPosition + SurroundTilesEven[1],
                startPosition + SurroundTilesEven[2],
                startPosition + SurroundTilesEven[3],
                startPosition + SurroundTilesEven[4],
                startPosition + SurroundTilesEven[5]
            };

            Assert.AreEqual(positions, expectedPos);
        }
Exemple #20
0
        /// <summary>
        /// Gets the surrounded positions.
        /// </summary>
        /// <returns>The surrounded positions.</returns>
        /// <param name="startPoint">Start point.</param>
        /// <param name="accountID">Account ID.</param>
        /// <param name="moves">Moves of the entity.</param>
        private HashSet<PositionI> GetSurroundedPositions(PositionI startPoint, int accountID, int moves)
        {
            var fieldSet = new HashSet<PositionI>();
            var fieldSetHelper = new HashSet<PositionI>();

            fieldSet.Add(startPoint);
            fieldSetHelper.Add(startPoint);

            for (int index = 0; index != moves; ++index)
            {
                var tempfieldSet = new HashSet<PositionI>();
                foreach (var item in fieldSetHelper)
                {
                    var surroundedTiles = LogicRules.GetSurroundedFields(item);
                    foreach (var tile in surroundedTiles)
                    {
                        if (!fieldSet.Contains(tile))
                        {
                            var region = World.Instance.RegionManager.GetRegion(tile.RegionPosition);
                            var terrainDefinition = region.GetTerrain(tile.CellPosition);
                            if (terrainDefinition.Walkable)
                            {
                                var unit = region.GetEntity(tile.CellPosition);
                                if (unit == null)
                                {
                                    fieldSet.Add(tile);
                                    tempfieldSet.Add(tile);
                                }
                            }
                        }
                    }
                }
                fieldSetHelper = tempfieldSet;
            }
            return fieldSet;
        }
Exemple #21
0
 public Entity(int id, int definitonID, int ownerID, PositionI position, int health, int move)
     : this(id, World.Instance.DefinitionManager.GetDefinition((EntityType)definitonID), World.Instance.AccountManager.GetAccountOrEmpty(ownerID), position, health, move)
 {
 }
Exemple #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Models.CellPosition"/> class.
 /// </summary>
 /// <param name="position">GameWorld Integer Position.</param>
 public CellPosition(PositionI position)
     : this(position.X,
         position.Y)
 {
 }
Exemple #23
0
        /// <summary>
        /// Increases the resource generation.
        /// </summary>
        /// <param name="account">Current account.</param>
        /// <param name="actionTime">Action time.</param>
        /// <param name="entitypos">Entity position.</param>
        /// <param name="regionManagerC">Region manager controller.</param>
        public static void IncreaseResourceGeneration(Account account, DateTime actionTime, PositionI entitypos, Controllers.RegionManagerController regionManagerC)
        {
            switch (regionManagerC.GetRegion(entitypos.RegionPosition).GetEntity(entitypos.CellPosition).DefinitionID)
              {
              case (int)Core.Models.Definitions.EntityType.Lab:
                    account.Technology.Set(actionTime, account.Technology.GetValue(actionTime), Constants.TECHNOLOGY_INCREMENT_VALUE);
                    break;

              case (int)Core.Models.Definitions.EntityType.Furnace:
                    account.Scrap.Set(actionTime, account.Scrap.GetValue(actionTime), Constants.SCRAP_INCREMENT_VALUE);
                    break;
              }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Models.RegionPosition"/> class.
 /// </summary>
 /// <param name="position">Game Position Integer.</param>
 public RegionPosition(PositionI position)
 {
     RegionX = (int)(position.X / Constants.REGION_SIZE_X);
     RegionY = (int)(position.Y / Constants.REGION_SIZE_Y);
 }
Exemple #25
0
        /// <summary>
        /// Check all possible spawn locations around a building.
        /// Check surrounding area around the building for units, if there is a free location this will be returned.
        /// </summary>
        /// <returns>The free field.</returns>
        /// <param name="position">IPosition of the current selected building..</param>
        /// <param name="regionManagerC">Region manager c.</param>
        private PositionI GetFreeField(PositionI position, RegionManagerController regionManagerC)
        {
            foreach (var surpos in LogicRules.GetSurroundedFields(position))
            {
                var td = regionManagerC.GetRegion(surpos.RegionPosition).GetTerrain(surpos.CellPosition);
                var ed = regionManagerC.GetRegion(surpos.RegionPosition).GetEntity(surpos.CellPosition);

                if (td.Walkable && ed == null)
                {
                    return surpos;
                }
            }
            return null;
        }
Exemple #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Models.CellPosition"/> class.
 /// </summary>
 /// <param name="position">GameWorld Integer Position.</param>
 public CellPosition(PositionI position)
     : this(
         position.X,
         position.Y)
 {
 }
Exemple #27
0
        /// <summary>
        /// Returns if the action is even possible.
        /// </summary>
        /// <returns> True if the Building is buildable at the current position, otherwise false.</returns>
        public override bool Possible()
        {
            var regionManagerC = Controller.Instance.RegionManagerController;

            var action = (Core.Models.Action)Model;
            var positionI = (PositionI)action.Parameters[CREATE_POSITION];
            var type = (long)action.Parameters[CREATION_TYPE];
            var entity = Controller.Instance.RegionManagerController.GetRegion(positionI.RegionPosition).GetEntity(positionI.CellPosition);
            var list = new List<long>();

            if (entity != null)
            {
                action.Account.BuildableBuildings.TryGetValue(entity.DefinitionID, out list);

                if (list != null)
                {
                    if (action.AccountID == entity.OwnerID && list.Contains(type))
                    {
                        RealCreatePosition = GetFreeField(positionI, regionManagerC);

                        return RealCreatePosition != null && LogicRules.CheckResource(action.Account, action.ActionTime, Controller.Instance.DefinitionManagerController.DefinitionManager.GetDefinition((EntityType)type));
                    }
                }
            }
            return false;
        }
Exemple #28
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;
        }
        /// <summary>
        /// Decreases the resource generation.
        /// </summary>
        /// <param name="account">Current account.</param>
        /// <param name="actionTime">Action time.</param>
        /// <param name="entitypos">Entity position.</param>
        /// <param name="regionManagerC">Region manager controller.</param>
        public static void DecreaseResourceGeneration(Account account, DateTime actionTime, PositionI entitypos, Controllers.RegionManagerController regionManagerC)
        {
            switch (regionManagerC.GetRegion(entitypos.RegionPosition).GetEntity(entitypos.CellPosition).DefinitionID)
            {
                case (int)Core.Models.Definitions.EntityType.Lab:                         
                    account.Technology.Set(actionTime, account.Technology.GetValue(actionTime), -Constants.TECHNOLOGY_INCREMENT_VALUE);                   
                    break;

                case (int)Core.Models.Definitions.EntityType.Furnace:
                    account.Scrap.Set(actionTime, account.Scrap.GetValue(actionTime), -Constants.SCRAP_INCREMENT_VALUE);
                    break;
            }
        }
Exemple #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Models.Position"/> class.
 /// </summary>
 /// <param name="position">Position in X and Y.</param>
 public Position(PositionI position)
 {
     X = position.X;
     Y = position.Y;
 }
Exemple #31
0
 /// <summary>
 /// Determines whether this instance is possible to create the specified type on the position.
 /// </summary>
 /// <returns><c>true</c> if this instance is possible to create the specified type on the position; otherwise, <c>false</c>.</returns>
 /// <param name="positionI">The position to create.</param>
 /// <param name="type">The type to create.</param>
 private bool IsPossibleToCreate(PositionI positionI, Core.Models.Definitions.Definition type)
 {
     var action = ActionHelper.CreateEntity(positionI, type, GameAppDelegate.Account);
     var actionC = (Core.Controllers.Actions.Action)action.Control;
     return actionC.Possible();
 }
Exemple #32
0
 /// <summary>
 /// Gets one iteration of the expanding menu with the coordinate and the old coordinate as needed parameters to calculate the direction.
 /// </summary>
 /// <param name="coord">The new Coordinate.</param>
 /// <param name="oldcoord">The old Coordinate.</param>
 /// <returns>Returns the second coordinate of the expanding menu.</returns>
 public Core.Models.PositionI GetTiles(PositionI coord, PositionI oldcoord)
 {
     var extMenu = Even[0];
     var tmp = Odd;
     if (coord.X % 2 == 0)
     {
         tmp = Even;
     }
     var vector = new PositionI(coord.X - oldcoord.X, coord.Y - oldcoord.Y);
     if (vector.X == 0)
     {
         if (vector.Y == -1)
         {
             extMenu = tmp[0];
         }
         else
         {
             extMenu = tmp[1];
         }
     }
     // right
     if (vector.X == 1)
     {
         if ((vector.Y > 0) || (coord.X % 2 != 0 && vector.Y == 0))
         {
             extMenu = tmp[5]; // down
         }
         else
         {
             extMenu = tmp[3]; // up
         }
     }
     if (vector.X == -1)
     {
         if ((vector.Y > 0) || (coord.X % 2 != 0 && vector.Y == 0))
         {
             extMenu = tmp[4]; // down
         }
         else
         {
             extMenu = tmp[2]; // up
         }
     }
     foreach (var item in extMenu)
     {
         m_extendedMenuPositions[coord + item] = null;
     }
     return extMenu[1];
 }
Exemple #33
0
        /// <summary>
        /// Draws the indicator on the Map
        /// </summary>
        /// <param name="coord">The Center Position.</param>
        /// <param name="range">The Range.</param>
        /// <param name="area">The Area Type.</param>
        public void ShowUnitIndicator(PositionI coord, int range, TileTouchHandler.Area area)
        {
            var gid = new CCTileGidAndFlags(Client.Common.Constants.HelperSpritesGid.GREENINDICATOR);

            m_areaIndicators.TryGetValue(area, out gid);

            if (area == TileTouchHandler.Area.Movement)
            {
                var indi = new Core.Controllers.AStar_Indicator.Indicator(coord, range, GameAppDelegate.Account.ID);
                m_surroundedPositions = indi.FindPossiblePositions();
            }

            AddSprites(gid);
        }
Exemple #34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Models.Position"/> class.
 /// </summary>
 /// <param name="position">Position in X and Y.</param>
 public Position(PositionI position)
 {
     X = position.X;
     Y = position.Y;
 }
Exemple #35
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Controllers.AStar.SearchParameters"/> class.
 /// Set start and end point for the AStar algorithm.
 /// </summary>
 /// <param name="startLocation">PositionI from the start for the algorithm.</param>
 /// <param name="endLocation">PositionI from the end for the algorithm.</param>
 /// <param name="accountID">Account ID.</param>
 public SearchParameters(PositionI startLocation, PositionI endLocation, int accountID)
 {
     this.StartLocation = startLocation;
     this.EndLocation = endLocation;
     this.AccountID = accountID;
 }
Exemple #36
0
 /// <summary>
 /// Gets the claimed territory.
 /// </summary>
 /// <returns>The claimed territory.</returns>
 /// <param name="position">Current Position.</param>
 public Account GetClaimedTerritory(PositionI position)
 {
     Account result;
     if (m_territory.TryGetValue(position, out result))
     {
         return result;
     }
     return null;
 }
Exemple #37
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Client.Common.Views.MenuView"/> class.
 /// </summary>
 /// <param name="worldlayer">The worldlayer.</param>
 /// <param name="center">The menu center position.</param>
 /// <param name="menuType">The menu type.</param>
 public MenuView(WorldLayerHex worldlayer, PositionI center, MenuType menuType)
 {
     m_center = center;
     var defM = Core.Models.World.Instance.DefinitionManager;
     if (menuType == MenuType.Headquarter)
     {
         m_types = new Core.Models.Definitions.Definition[6];
         m_types[0] = defM.GetDefinition(EntityType.Headquarter);
         m_types[1] = defM.GetDefinition(EntityType.Headquarter);
         m_types[2] = defM.GetDefinition(EntityType.Headquarter);
         m_types[3] = defM.GetDefinition(EntityType.Headquarter);
         m_types[4] = defM.GetDefinition(EntityType.Headquarter);
         m_types[5] = defM.GetDefinition(EntityType.Headquarter);
     }
     else if (menuType == MenuType.Major)
     {
         m_types = new Core.Models.Definitions.Definition[0];
     }
     else if (menuType == MenuType.Unity)
     {
         m_types = new Core.Models.Definitions.Definition[6];
         m_types[0] = defM.GetDefinition(EntityType.Mage);
         m_types[1] = defM.GetDefinition(EntityType.Fencer);
         m_types[2] = defM.GetDefinition(EntityType.Warrior);
         m_types[3] = defM.GetDefinition(EntityType.Scout);
         m_types[4] = defM.GetDefinition(EntityType.Archer);
         m_types[5] = defM.GetDefinition(EntityType.Archer);
     }
     else if (menuType == MenuType.Empty)
     {
         m_types = new Core.Models.Definitions.Definition[6];
     }
     else
     {
         m_types = new Core.Models.Definitions.Definition[0];
     }
     m_worldLayer = worldlayer;
     m_extendedMenuPositions = new Dictionary<PositionI, Core.Models.Definitions.Definition>();
     m_baseMenuPositions = new Dictionary<PositionI, CCTileGidAndFlags>();
     m_sprites = new Dictionary<PositionI, CCSprite>();
 }
Exemple #38
0
        /// <summary>
        /// Shows the building indicator.
        /// </summary>
        /// <param name="coord">The positionI.</param>
        /// <param name="area">The ownership of the area.</param>
        public void ShowBuildingIndicator(PositionI coord, TileTouchHandler.Area area)
        {
            var gid = new CCTileGidAndFlags(Client.Common.Constants.HelperSpritesGid.GREENINDICATOR);

            m_areaIndicators.TryGetValue(area, out gid);

            var buildings = Core.Controllers.Controller.Instance.RegionManagerController.GetRegion(coord.RegionPosition)
                                .GetEntity(coord.CellPosition).Owner.TerritoryBuildings.Keys;

            int range;
            foreach (var building in buildings)
            {
                var entity = Core.Controllers.Controller.Instance.RegionManagerController.GetRegion(building.RegionPosition).GetEntity(building.CellPosition);
                if (entity.Definition.SubType == Core.Models.Definitions.EntityType.Headquarter)
                {
                    range = Core.Models.Constants.HEADQUARTER_TERRITORY_RANGE;
                }
                else
                {
                    range = Core.Models.Constants.GUARDTOWER_TERRITORY_RANGE;
                }

                var surroundedPositions = LogicRules.GetSurroundedPositions(building, range);
                m_surroundedPositions.UnionWith(surroundedPositions);
            }

            AddSprites(gid);
        }
Exemple #39
0
 /// <summary>
 /// Extends the menu.
 /// </summary>
 /// <param name="gid">GID to switch between Military, Storage buildings etc..</param>
 /// <param name="coord">Coordinate to get the direction.</param>
 public void ExtendMenu(short gid, PositionI coord)
 {
     // clear the menu to enable a cleaner experience
     if (m_extendedMenuPositions.Count != 0)
     {
         ClearExtendedMenu();
     }
     var types = new Core.Models.Definitions.Definition[0];
     var defM = Core.Models.World.Instance.DefinitionManager;
     switch (gid)
     {
         case Common.Constants.BuildingMenuGid.MILITARY:
             types = new Core.Models.Definitions.Definition[4];
             types[0] = defM.GetDefinition(EntityType.Barracks);
             types[1] = defM.GetDefinition(EntityType.Attachment);
             types[2] = defM.GetDefinition(EntityType.Factory);
             types[3] = defM.GetDefinition(EntityType.GuardTower);
             break;
         case Common.Constants.BuildingMenuGid.CIVIL:
             types = new Core.Models.Definitions.Definition[3];
             types[0] = defM.GetDefinition(EntityType.Hospital);
             types[1] = defM.GetDefinition(EntityType.Tent);
             types[2] = defM.GetDefinition(EntityType.TradingPost);
             break;
         case Common.Constants.BuildingMenuGid.RESOURCES:
             types = new Core.Models.Definitions.Definition[3];
             types[0] = defM.GetDefinition(EntityType.Lab);
             types[1] = defM.GetDefinition(EntityType.Furnace);
             types[2] = defM.GetDefinition(EntityType.Transformer);
             break;
         case Common.Constants.BuildingMenuGid.STORAGE:
             types = new Core.Models.Definitions.Definition[1];
             types[0] = defM.GetDefinition(EntityType.Scrapyard);
             break;
     }
     GetExtendedCoords(coord, types);
     DrawMenu(MenuType.Extended);
 }
Exemple #40
0
 public Entity(int id, int definitonID, int ownerID, PositionI position, int health, int move)
     : this(id, World.Instance.DefinitionManager.GetDefinition((EntityType)definitonID), World.Instance.AccountManager.GetAccountOrEmpty(ownerID), position, health, move)
 {
 }
Exemple #41
0
        /// <summary>
        /// Gets the extended coords.
        /// </summary>
        /// <param name="coord">The positionI.</param>
        /// <param name="definitions">The definitions.</param>
        public void GetExtendedCoords(PositionI coord, Core.Models.Definitions.Definition[] definitions)
        {
            var tmpcoord1 = coord;
            var tmpcoord2 = m_center;
            var counter = definitions.Length;
            while (counter > 0)
            {
                var newCenterAdd = GetTiles(tmpcoord1, tmpcoord2);
                tmpcoord2 = tmpcoord1;
                tmpcoord1 = tmpcoord1 + newCenterAdd;
                counter -= 3;
            }

            var keys = new List<PositionI>(m_extendedMenuPositions.Keys);
            for (var index = 0; index < definitions.Length; ++index)
            {
                m_extendedMenuPositions[keys[index]] = definitions[index];
            }
        }
Exemple #42
0
 /// <summary>
 /// Distance from this to the specific position
 /// Warning: NOT ROOTED.
 /// </summary>
 /// <returns>Distance from this to the specific position.</returns>
 /// <param name="position">Other Position.</param>
 public double Distance(PositionI position)
 {
     var distanceX = position.X - X;
     var distanceY = position.Y - Y;
     return (distanceX * distanceX) + (distanceY * distanceY);
 }
Exemple #43
0
 /// <summary>
 /// Gets the selected definition on a position.
 /// </summary>
 /// <returns>The selected definition.</returns>
 /// <param name="pos">The positionI.</param>
 public Core.Models.Definitions.Definition GetSelectedDefinition(PositionI pos)
 {
     Core.Models.Definitions.Definition def = null;
     m_extendedMenuPositions.TryGetValue(pos, out def);
     return def;
 }
Exemple #44
0
 /// <summary>
 /// Sets the menu tile.
 /// </summary>
 /// <returns>The menu tile.</returns>
 /// <param name="posI">The positionI.</param>
 /// <param name="gid">The gid.</param>
 /// <param name="isPossible">If set to <c>true</c> is possible.</param>
 public CCSprite SetMenuTile(PositionI posI, CCTileGidAndFlags gid, bool isPossible = true)
 {
     m_menueLayer.SetTileGID(gid, new CCTileMapCoordinates(posI.CellPosition.CellX, posI.CellPosition.CellY));
     var sprite = m_menueLayer.ExtractTile(new CCTileMapCoordinates(posI.CellPosition.CellX, posI.CellPosition.CellY), true);
     if (!isPossible)
     {
         sprite.Color = CCColor3B.DarkGray;
     }
     return sprite;
 }
Exemple #45
0
 /// <summary>
 /// Gets the selected kategory gid on a position.
 /// </summary>
 /// <returns>The selected CCTileGidAndFlags.</returns>
 /// <param name="pos">The position.</param>
 public CCTileGidAndFlags GetSelectedKategory(PositionI pos)
 {
     CCTileGidAndFlags gid = CCTileGidAndFlags.EmptyTile;
     m_baseMenuPositions.TryGetValue(pos, out gid);
     return gid;
 }