/// <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); }
/// <summary> /// Gets the account or empty account. /// </summary> /// <returns>The account or empty account.</returns> /// <param name="id">Account Identifier.</param> public Account GetAccountOrEmpty(int id) { var account = GetAccount(id); if (account == null) { account = new Account(id); } return account; }
/// <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; }
public async Task <Domain.History> AddAsync( Domain.Account account, string userName, string accessibleAccountNamem, DateTime loginDateTime) { var newHistory = new Data.History { AccountId = account.Id, LoginDateTime = loginDateTime, UserName = userName, AccessibleAccountName = accessibleAccountNamem, }; await this.repository.AddAsync(newHistory); return(mapDataToDomain(newHistory)); }
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); }
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); }
/// <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; }
/// <summary> /// Checks the resource cost of the entity. /// </summary> /// <returns><c>true</c>, if resource was checked, <c>false</c> otherwise.</returns> /// <param name="account">Current account.</param> /// <param name="serverTime">Server time.</param> /// <param name="entityDef">Entity definition.</param> public static bool CheckResource(Account account, DateTime serverTime, Definitions.Definition entityDef) { var definition = (Definitions.UnitDefinition)entityDef; return account.Scrap.GetValue(serverTime) >= definition.Scrapecost && account.Plutonium.GetValue(serverTime) >= definition.Plutoniumcost && account.Technology.GetValue(serverTime) >= definition.Techcost && account.Population.Value >= definition.Population && account.Energy.Value >= definition.Energycost; }
/// <summary> /// Consumes the resource for an entity. /// </summary> /// <param name="account">Current account.</param> /// <param name="actionTime">Action time.</param> /// <param name="entityDef">Entity definition.</param> public static void ConsumeResource(Account account, DateTime actionTime, Definitions.Definition entityDef) { var definition = (Definitions.UnitDefinition)entityDef; account.Scrap.Set(actionTime, account.Scrap.GetValue(actionTime) - definition.Scrapecost, 0); account.Plutonium.Set(actionTime, account.Plutonium.GetValue(actionTime) - definition.Plutoniumcost, 0); account.Technology.Set(actionTime, account.Technology.GetValue(actionTime) - definition.Techcost, 0); account.Population.Value -= definition.Population; account.Energy.Value -= definition.Energycost; }
public async Task UpdateLastLogoutTimeAsync(Domain.Account account, DateTime logoutDateTime) { await this.UpdateLastLogoutTimeForAccountAsync(account.Id, logoutDateTime); }
/// <summary> /// Destroy all buildings without territory. /// </summary> /// <param name="account">Current account.</param> /// <param name="action">Action which is in use.</param> /// <param name="regionManagerC">Region manager controller.</param> public static void DestroyAllBuildingsWithoutTerritory(Account account, Action action, Controllers.RegionManagerController regionManagerC) { Dictionary<PositionI, long> copylist = new Dictionary<PositionI, long>(account.Buildings); foreach (var building in copylist) { var region = regionManagerC.GetRegion(building.Key.RegionPosition); if (region.GetClaimedTerritory(building.Key) == null) { DestroyBuilding(region.GetEntity(building.Key.CellPosition), region, action, regionManagerC); region.RemoveEntity(action.ActionTime, region.GetEntity(building.Key.CellPosition)); } } account.Buildings.Clear(); foreach (var test in copylist) { account.Buildings.Add(test.Key, test.Value); } }
/// <summary> /// Draws the borders. /// </summary> /// <param name="owner">The owner.</param> public void DrawBorders(Account owner) { // alle Gebäude des entity owners var buildings = owner.TerritoryBuildings.Keys; var color = new CCColor4B(); color = CCColor4B.Green; if (GameAppDelegate.Account != owner) { color = CCColor4B.Red; } var surroundedPositionsAll = new HashSet<PositionI>(); int range; // alle Felder finden die zu der entity gehören foreach (var building in buildings) { var buildingEntity = Core.Controllers.Controller.Instance.RegionManagerController .GetRegion(building.RegionPosition).GetEntity(building.CellPosition); if (buildingEntity.Definition.SubType == Core.Models.Definitions.EntityType.Headquarter) { range = Core.Models.Constants.HEADQUARTER_TERRITORY_RANGE; } else { range = Core.Models.Constants.GUARDTOWER_TERRITORY_RANGE; } var surroundedPositionsBuilding = LogicRules.GetSurroundedPositions(building, range); surroundedPositionsAll.UnionWith(surroundedPositionsBuilding); } if (surroundedPositionsAll.Count > 0) { // alle Grenzfelder finden und nach Region sortieren var regionBorders = new Dictionary<RegionPosition, HashSet<PositionI>>(); foreach (var pos in surroundedPositionsAll) { var posOwner = Core.Controllers.Controller.Instance.RegionManagerController.GetRegion(pos.RegionPosition).GetClaimedTerritory(pos); var surroundedFields = LogicRules.GetSurroundedFields(pos); foreach (var field in surroundedFields) { var fieldOwner = Core.Controllers.Controller.Instance.RegionManagerController.GetRegion(field.RegionPosition).GetClaimedTerritory(field); if (posOwner != fieldOwner) { if (!regionBorders.ContainsKey(pos.RegionPosition)) { regionBorders.Add(pos.RegionPosition, new HashSet<PositionI>()); } HashSet<PositionI> position; regionBorders.TryGetValue(pos.RegionPosition, out position); position.Add(pos); break; } } } // zeichne Grenzen in den regionen HashSet<PositionI> borderPositions; foreach (var regionPosition in regionBorders.Keys) { regionBorders.TryGetValue(regionPosition, out borderPositions); this.GetRegionViewHex(regionPosition).DrawBorder(borderPositions, color, owner); } } else { foreach (var regionPosition in m_regionViewHexDic.Keys) { this.GetRegionViewHex(regionPosition).DrawBorder(null, color, owner); } } }
/// <summary> /// Calculates and returns the diplomatic states between the owner of the unit and the given account /// </summary> /// <returns>The diplomacy.</returns> /// <param name="account">Other Account.</param> public Diplomatic GetDiplomacy(Account account) { if (account.ID == Owner.ID) { return Diplomatic.own; } return Diplomatic.enemy; }
/// <summary> /// Gathers the resources. /// </summary> /// <param name="account">Current account.</param> /// <param name="actionTime">Action time.</param> /// <param name="regionManagerC">Region manager controller.</param> /// <param name="range">Range of the building.</param> public static void GatherResources(Account account, DateTime actionTime, Controllers.RegionManagerController regionManagerC, int range) { foreach (var element in account.TerritoryBuildings) { var list = LogicRules.GetSurroundedPositions(element.Key, range); float scrapAmount = 0; float plutoniumAmount = 0; foreach (var item in list) { // TODO: add ressources in Terrain var resources = regionManagerC.GetRegion(item.RegionPosition).GetTerrain(item.CellPosition); scrapAmount += 0.5f; plutoniumAmount += 0.3f; } account.Scrap.Set(actionTime, account.Scrap.GetValue(actionTime), Constants.SCRAP_INCREMENT_VALUE); account.Plutonium.Set(actionTime, account.Plutonium.GetValue(actionTime), Constants.PLUTONIUM_INCREMENT_VALUE); } }
/// <summary> /// Disables the build options. /// </summary> /// <param name="entityType">Entity type.</param> /// <param name="account">Current account.</param> public static void DisableBuildOptions(long entityType, Account account) { if (account.BuildableBuildings.ContainsKey(entityType)) { switch (entityType) { case (long)Models.Definitions.EntityType.Headquarter: account.BuildableBuildings.Remove(entityType); break; case (long)Models.Definitions.EntityType.Barracks: account.BuildableBuildings.Remove(entityType); break; } } }
/// <summary> /// Sets the current energy. /// </summary> /// <param name="account">Current account.</param> public static void SetCurrentMaxEnergy(Account account) { account.Energy.Value = account.Energy.MaximumValue; }
/// <summary> /// Increases the scrap. /// </summary> /// <param name="account">Current Account.</param> /// <param name="entity">Current Entity.</param> public static void IncreaseScrap(Account account, Entity entity) { if (entity.DefinitionID == (long)Core.Models.Definitions.EntityType.Scrapyard) { account.Scrap.MaximumValue += Constants.SCRAP_STORAGE_VALUE; } }
/// <summary> /// Draws the border. /// </summary> /// <param name="borderPositions">The border positions.</param> /// <param name="color">The border color.</param> /// <param name="owner">The area owner.</param> public void DrawBorder(HashSet<PositionI> borderPositions, CCColor4B color, Account owner) { RemoveBorder(owner); if (borderPositions != null) { var border = new CCDrawNode(); m_tileMap.TileLayersContainer.AddChild(border); m_drawNodes.Add(owner, border); var halfwidth = ClientConstants.TILE_HEX_IMAGE_WIDTH / 2.0f; var halfhight = ClientConstants.TILE_HEX_IMAGE_HEIGHT / 2.0f; // zentrieren der Grenzpunkte und zeichnen dieser foreach (var positionI in borderPositions) { var centerPos = PositionHelper.CellToTile(positionI.CellPosition); centerPos.X += halfwidth; centerPos.Y -= halfhight; border.DrawSolidCircle(centerPos, ClientConstants.TERRATORRY_BUILDING_BORDER_SIZE, color); } } }
/// <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> /// Increases the population. /// </summary> /// <param name="account">Current Account.</param> /// <param name="entity">Current Entity.</param> public static void IncreaseMaxPopulation(Account account, Entity entity) { if (entity.DefinitionID == (long)Core.Models.Definitions.EntityType.Tent) { account.Population.MaximumValue += Constants.POPULATION_STORAGE_VALUE; account.Population.Value += Constants.POPULATION_STORAGE_VALUE; } }
/// <summary> /// Increases the max energy. /// </summary> /// <param name="account">Current account.</param> /// <param name="entity">Current entity.</param> public static void IncreaseMaxEnergy(Account account, Entity entity) { if (entity.DefinitionID == (long)Core.Models.Definitions.EntityType.Transformer) { account.Energy.MaximumValue += Constants.ENERGY_MAX_VALUE; account.Energy.Value += Constants.ENERGY_MAX_VALUE; } }
/// <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); } } }
/// <summary> /// Sets the current max population. /// </summary> /// <param name="account">Current account.</param> public static void SetCurrentMaxPopulation(Account account) { account.Population.Value = account.Population.MaximumValue; }
/// <summary> /// Frees the claimed territory. /// </summary> /// <param name="territoryList">Territory list.</param> /// <param name="account">Current Account.</param> public void FreeClaimedTerritory(HashSet<PositionI> territoryList, Account account) { foreach (var position in territoryList) { if (World.Instance.RegionManager.GetRegion(position.RegionPosition).m_territory.ContainsKey(position)) { World.Instance.RegionManager.GetRegion(position.RegionPosition).m_territory.Remove(position); } } }
/// <summary> /// Adds an account. /// </summary> /// <param name="account">Account which should be added.</param> public void AddAccount(Account account) { Accounts.TryAdd(account.ID, account); }
/// <summary> /// Increases the storage. /// </summary> /// <param name="account">Current Account.</param> /// <param name="entity">Current Entity.</param> public static void IncreaseStorage(Account account, Entity entity) { IncreaseMaxPopulation(account, entity); IncreaseScrap(account, entity); IncreaseMaxEnergy(account, entity); }
/// <summary> /// Enables the build options. /// </summary> /// <param name="entityType">Entity type.</param> /// <param name="account">Current Account.</param> public static void EnableBuildOptions(long entityType, Account account) { if (!account.BuildableBuildings.ContainsKey(entityType)) { switch (entityType) { case (long)Models.Definitions.EntityType.Headquarter: account.BuildableBuildings.Add(entityType, EnableHeadquarterBuildOptions()); break; case (long)Models.Definitions.EntityType.Barracks: account.BuildableBuildings.Add(entityType, EnableBarracksBuildOptions()); break; } } }
/// <summary> /// Removes the border. /// </summary> /// <param name="owner">The area owner.</param> public void RemoveBorder(Account owner) { CCDrawNode border; if (m_drawNodes.TryGetValue(owner, out border)) { m_tileMap.TileLayersContainer.RemoveChild(border); m_drawNodes.Remove(owner); } }
/// <summary> /// Increases the hole storage. /// </summary> /// <param name="account">Current Account.</param> public static void IncreaseWholeStorage(Account account) { account.Scrap.MaximumValue += Constants.HEADQUARTER_STORAGE_VALUE; account.Population.MaximumValue += Constants.POPULATION_STORAGE_VALUE; account.Technology.MaximumValue += Constants.TECHNOLOGY_MAX_VALUE; account.Energy.MaximumValue += Constants.ENERGY_MAX_VALUE; account.Plutonium.MaximumValue += Constants.HEADQUARTER_STORAGE_VALUE; }