/// <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 }); }
/// <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 }); }
public void BuildOptions() { var acc = GetTestAcc(); Assert.IsNotNull(acc.BuildableBuildings); var buildOpt = acc.BuildableBuildings; LogicRules.EnableBuildOptions((long)Core.Models.Definitions.EntityType.Headquarter, acc); Assert.AreNotEqual(buildOpt, acc.BuildableBuildings); Assert.Contains((long)Core.Models.Definitions.EntityType.Headquarter, (System.Collections.ICollection)acc.BuildableBuildings); LogicRules.DisableBuildOptions((long)Core.Models.Definitions.EntityType.Headquarter, acc); Assert.AreEqual(buildOpt, acc.BuildableBuildings); }