示例#1
0
        /// <summary>
        /// Apply action-related changes to the world.
        /// </summary>
        /// <returns> Returns <see cref="System.Collections.Concurrent.ConcurrentBag"/> class with the affected region./></returns>
        public override ConcurrentBag<Core.Models.Region> Do()
        {
            var action = (Core.Models.Action)Model;
            var entityPosition = (PositionI)action.Parameters[CREATE_POSITION];
            var region = Controller.Instance.RegionManagerController.GetRegion(entityPosition.RegionPosition);
            var entityCellPostion = entityPosition.CellPosition;
            var type = (long)action.Parameters[CREATION_TYPE];

            var entityDef = Controller.Instance.DefinitionManagerController.DefinitionManager.GetDefinition((EntityType)type);
            var entityHealth = ((UnitDefinition)entityDef).Health;
            var entityMoves = ((UnitDefinition)entityDef).Moves;

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

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

            action.Account.Buildings.Add(entity.Position, type);
            LogicRules.IncreaseResourceGeneration(action.Account, action.ActionTime, entity.Position, Controller.Instance.RegionManagerController);
            LogicRules.EnableBuildOptions(type, action.Account);
            LogicRules.IncreaseStorage(action.Account, entity);
            LogicRules.ConsumeResource(action.Account, action.ActionTime, entityDef);

            return new ConcurrentBag<Core.Models.Region>() { region };
        }
示例#2
0
        /// <summary>
        /// Apply action-related changes to the world.
        /// </summary>
        /// <returns> Returns <see cref="System.Collections.Concurrent.ConcurrentBag"/> class with the affected region./></returns>
        public override ConcurrentBag <Core.Models.Region> Do()
        {
            var action            = (Core.Models.Action)Model;
            var entityPosition    = (PositionI)action.Parameters[CREATE_POSITION];
            var region            = Controller.Instance.RegionManagerController.GetRegion(entityPosition.RegionPosition);
            var entityCellPostion = entityPosition.CellPosition;
            var type = (long)action.Parameters[CREATION_TYPE];

            var entityDef    = Controller.Instance.DefinitionManagerController.DefinitionManager.GetDefinition((EntityType)type);
            var entityHealth = ((UnitDefinition)entityDef).Health;
            var entityMoves  = ((UnitDefinition)entityDef).Moves;

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

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

            // link the headquarter to the current account and claim territory, , enable build options
            if (m_type.SubType == EntityType.Headquarter &&
                action.Account != null)
            {
                action.Account.TerritoryBuildings.Add(entity.Position, type);
                LogicRules.EnableBuildOptions(type, action.Account);
                region.ClaimTerritory(LogicRules.GetSurroundedPositions(entityPosition, m_drawArea), action.Account, region.RegionPosition, Controller.Instance.RegionManagerController.RegionManager);
                LogicRules.IncreaseWholeStorage(action.Account);
                LogicRules.GatherResources(action.Account, action.ActionTime, Controller.Instance.RegionManagerController, Constants.HEADQUARTER_TERRITORY_RANGE);
                LogicRules.SetCurrentMaxPopulation(action.Account);
                LogicRules.SetCurrentMaxEnergy(action.Account);
            }
            else if (action.Account != null)
            {
                action.Account.TerritoryBuildings.Add(entity.Position, type);
                region.ClaimTerritory(LogicRules.GetSurroundedPositions(entityPosition, m_drawArea), action.Account, region.RegionPosition, Controller.Instance.RegionManagerController.RegionManager);
            }

            LogicRules.ConsumeResource(action.Account, action.ActionTime, entityDef);
            return(new ConcurrentBag <Core.Models.Region>()
            {
                region
            });
        }
示例#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
            });
        }
示例#4
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 };
        }
        /// <summary>
        /// Apply action-related changes to the world.
        /// </summary>
        /// <returns> Returns <see cref="System.Collections.Concurrent.ConcurrentBag"/> class with the affected region./></returns>
        public override ConcurrentBag<Core.Models.Region> Do()
        {
            var action = (Core.Models.Action)Model;
            var entityPosition = (PositionI)action.Parameters[CREATE_POSITION];
            var region = Controller.Instance.RegionManagerController.GetRegion(entityPosition.RegionPosition);
            var entityCellPostion = entityPosition.CellPosition;
            var type = (long)action.Parameters[CREATION_TYPE];

            var entityDef = Controller.Instance.DefinitionManagerController.DefinitionManager.GetDefinition((EntityType)type);
            var entityHealth = ((UnitDefinition)entityDef).Health;
            var entityMoves = ((UnitDefinition)entityDef).Moves;

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

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

            // link the headquarter to the current account and claim territory, , enable build options
            if (m_type.SubType == EntityType.Headquarter &&
                action.Account != null)
            {
                action.Account.TerritoryBuildings.Add(entity.Position, type);
                LogicRules.EnableBuildOptions(type, action.Account);
                region.ClaimTerritory(LogicRules.GetSurroundedPositions(entityPosition, m_drawArea), action.Account, region.RegionPosition, Controller.Instance.RegionManagerController.RegionManager);
                LogicRules.IncreaseWholeStorage(action.Account);
                LogicRules.GatherResources(action.Account, action.ActionTime, Controller.Instance.RegionManagerController, Constants.HEADQUARTER_TERRITORY_RANGE);
                LogicRules.SetCurrentMaxPopulation(action.Account);
                LogicRules.SetCurrentMaxEnergy(action.Account);
            }
            else if (action.Account != null)
            {
                action.Account.TerritoryBuildings.Add(entity.Position, type);
                region.ClaimTerritory(LogicRules.GetSurroundedPositions(entityPosition, m_drawArea), action.Account, region.RegionPosition, Controller.Instance.RegionManagerController.RegionManager);
            }

            LogicRules.ConsumeResource(action.Account, action.ActionTime, entityDef);
            return new ConcurrentBag<Core.Models.Region>() { region };
        }