Exemplo n.º 1
0
        private int getAmountOfUnitsToBuy(SubCellType subCellType, Cell dwellingCheck)
        {
            if (subCellType == SubCellType.DwellingMilitia)
            {
                var amountOfUnitsToBuy = SensorData.MyTreasury[Resource.Gold] / UnitsConstants.Current.UnitCost[UnitType.Militia][Resource.Gold];
                return(dwellingCheck.ResourcesValue >= amountOfUnitsToBuy ? amountOfUnitsToBuy : dwellingCheck.ResourcesValue);
            }

            if (subCellType == SubCellType.DwellingCavalry)
            {
                var maxAmountGold      = SensorData.MyTreasury[Resource.Gold] / UnitsConstants.Current.UnitCost[UnitType.Cavalry][Resource.Gold];
                var maxAmountEbony     = SensorData.MyTreasury[Resource.Ebony] / UnitsConstants.Current.UnitCost[UnitType.Cavalry][Resource.Ebony];
                var amountOfUnitsToBuy = maxAmountGold < maxAmountEbony ? maxAmountGold : maxAmountEbony;

                return(dwellingCheck.ResourcesValue >= amountOfUnitsToBuy ? amountOfUnitsToBuy : dwellingCheck.ResourcesValue);
            }

            if (subCellType == SubCellType.DwellingInfantry)
            {
                var maxAmountGold      = SensorData.MyTreasury[Resource.Gold] / UnitsConstants.Current.UnitCost[UnitType.Infantry][Resource.Gold];
                var maxAmountIron      = SensorData.MyTreasury[Resource.Iron] / UnitsConstants.Current.UnitCost[UnitType.Infantry][Resource.Iron];
                var amountOfUnitsToBuy = maxAmountGold < maxAmountIron ? maxAmountGold : maxAmountIron;

                return(dwellingCheck.ResourcesValue >= amountOfUnitsToBuy ? amountOfUnitsToBuy : dwellingCheck.ResourcesValue);
            }

            if (subCellType == SubCellType.DwellingRanged)
            {
                var maxAmountGold      = SensorData.MyTreasury[Resource.Gold] / UnitsConstants.Current.UnitCost[UnitType.Ranged][Resource.Gold];
                var maxAmountGlass     = SensorData.MyTreasury[Resource.Glass] / UnitsConstants.Current.UnitCost[UnitType.Ranged][Resource.Glass];
                var amountOfUnitsToBuy = maxAmountGold < maxAmountGlass ? maxAmountGold : maxAmountGlass;

                return(dwellingCheck.ResourcesValue >= amountOfUnitsToBuy ? amountOfUnitsToBuy : dwellingCheck.ResourcesValue);
            }

            return(0);
        }
Exemplo n.º 2
0
        private List <Cell> findResourcesForDwelling(Dictionary <Resource, int> missingTreasury,
                                                     Cell dwelling, Resource resource, List <Cell> finderCells)
        {
            var subCellType = new SubCellType();

            switch (resource)
            {
            case Resource.Ebony:
                subCellType = SubCellType.ResourceEbony;
                break;

            case Resource.Iron:
                subCellType = SubCellType.ResourceIron;
                break;

            case Resource.Glass:
                subCellType = SubCellType.ResourceGlass;
                break;
            }

            var resultCellsList = new List <Cell>();
            var foundedCells    = finderCells.Where(o => (o.CellType.SubCellType == SubCellType.ResourceGold && o.ResourcesValue > 0) &&
                                                    !o.Value.Equals(Single.MaxValue) && !resultCellsList.Contains(o)).OrderBy(o => o.Value).ToList();

            for (int i = 0; i < foundedCells.Count && missingTreasury[Resource.Gold] > 0; i++)
            {
                var cell = foundedCells.ElementAt(i);
                resultCellsList.Add(cell);
                missingTreasury[Resource.Gold] = missingTreasury[Resource.Gold] - cell.ResourcesValue;
            }

            if (resource != Resource.Gold)
            {
                foundedCells = finderCells.Where(o => (o.CellType.SubCellType == subCellType || o.ResourcesValue > 0) &&
                                                 !o.Value.Equals(Single.MaxValue) && !resultCellsList.Contains(o)).OrderBy(o => o.Value).ToList();

                for (int i = 0; i < foundedCells.Count && missingTreasury[resource] > 0; i++)
                {
                    var cell = foundedCells.ElementAt(i);
                    resultCellsList.Add(cell);
                    missingTreasury[resource] = missingTreasury[resource] - cell.ResourcesValue;
                }
            }

            var cellPath = new List <Cell>();

            if (resultCellsList.Count <= 0)
            {
                return(cellPath);
            }
            cellPath.AddRange(_finder.GetSmartPath(SensorData.Location.CreateCell(), resultCellsList[0]));

            for (int y = 1; y < resultCellsList.Count; y++)
            {
                var finderNew = new Finder(finderCells, resultCellsList[y]);
                cellPath.AddRange(finderNew.GetSmartPath(resultCellsList[y - 1], resultCellsList[y]));
            }
            var finderToEnd = new Finder(finderCells, resultCellsList[resultCellsList.Count - 1]);

            cellPath.AddRange(finderToEnd.GetSmartPath(resultCellsList[resultCellsList.Count - 1], dwelling));
            return(cellPath);
        }
Exemplo n.º 3
0
 public ObjectCellType()
 {
     MainType    = MainCellType.None;
     SubCellType = SubCellType.None;
 }