/// <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;
        }
        /// <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;           
        }
Exemple #3
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);
 }