private void SetupDeployableShardProgress(string itemUID, ShardVO shard)
        {
            CurrentPlayer          currentPlayer          = Service.Get <CurrentPlayer>();
            TroopUpgradeCatalog    troopUpgradeCatalog    = Service.Get <TroopUpgradeCatalog>();
            StarshipUpgradeCatalog starshipUpgradeCatalog = Service.Get <StarshipUpgradeCatalog>();
            UXSlider subElement  = this.rewardsGrid.GetSubElement <UXSlider>(itemUID, "pBarRewardItemFrag");
            UXSprite subElement2 = this.rewardsGrid.GetSubElement <UXSprite>(itemUID, "SpriteRewardItempBarFrag");

            subElement.Visible = true;
            UXLabel       subElement3 = this.rewardsGrid.GetSubElement <UXLabel>(itemUID, "LabelFragProgress");
            UXElement     subElement4 = this.rewardsGrid.GetSubElement <UXElement>(itemUID, "IconUpgrade");
            IDeployableVO deployableVO;
            IDeployableVO byLevel;

            if (shard.TargetType == "specialAttack")
            {
                int nextLevel = currentPlayer.UnlockedLevels.Starships.GetNextLevel(shard.TargetGroupId);
                deployableVO = starshipUpgradeCatalog.GetByLevel(shard.TargetGroupId, nextLevel);
                byLevel      = starshipUpgradeCatalog.GetByLevel(shard.TargetGroupId, nextLevel - 1);
            }
            else
            {
                int nextLevel = currentPlayer.UnlockedLevels.Troops.GetNextLevel(shard.TargetGroupId);
                deployableVO = troopUpgradeCatalog.GetByLevel(shard.TargetGroupId, nextLevel);
                byLevel      = troopUpgradeCatalog.GetByLevel(shard.TargetGroupId, nextLevel - 1);
            }
            if (deployableVO == null)
            {
                subElement3.Text = this.lang.Get("MAX_LEVEL", new object[0]);
                subElement.Value = 1f;
                return;
            }
            bool flag = Service.Get <UnlockController>().IsMinLevelUnlocked(deployableVO);

            if (!flag)
            {
                deployableVO = byLevel;
            }
            int shardAmount       = Service.Get <DeployableShardUnlockController>().GetShardAmount(deployableVO.UpgradeShardUid);
            int upgradeShardCount = deployableVO.UpgradeShardCount;

            subElement3.Text = this.lang.Get("FRACTION", new object[]
            {
                shardAmount,
                upgradeShardCount
            });
            if (upgradeShardCount == 0)
            {
                Service.Get <StaRTSLogger>().ErrorFormat("CMS Error: Shards required for {0} is zero", new object[]
                {
                    deployableVO.Uid
                });
                return;
            }
            float sliderValue = (float)shardAmount / (float)upgradeShardCount;

            UXUtils.SetShardProgressBarValue(subElement, subElement2, sliderValue);
            subElement4.Visible = (flag && shardAmount >= upgradeShardCount);
        }
Exemplo n.º 2
0
        public static IUpgradeableVO GetFinalUnitFromPrize(PrizeType prizeType, string prizeID)
        {
            BuildingLookupController buildingLookupController = Service.Get <BuildingLookupController>();
            IUpgradeableVO           result = null;
            TroopUpgradeCatalog      troopUpgradeCatalog = Service.Get <TroopUpgradeCatalog>();

            switch (prizeType)
            {
            case PrizeType.Infantry:
            {
                int val   = buildingLookupController.GetHighestLevelForBarracks();
                int lvl   = troopUpgradeCatalog.GetMaxRewardableLevel(prizeID).Lvl;
                int level = Math.Min(val, lvl);
                result = troopUpgradeCatalog.GetByLevel(prizeID, level);
                break;
            }

            case PrizeType.Hero:
            {
                int val   = buildingLookupController.GetHighestLevelForHeroCommands();
                int lvl   = troopUpgradeCatalog.GetMaxRewardableLevel(prizeID).Lvl;
                int level = Math.Min(val, lvl);
                result = troopUpgradeCatalog.GetByLevel(prizeID, level);
                break;
            }

            case PrizeType.SpecialAttack:
            {
                StarshipUpgradeCatalog starshipUpgradeCatalog = Service.Get <StarshipUpgradeCatalog>();
                int val   = buildingLookupController.GetHighestLevelForStarshipCommands();
                int lvl   = starshipUpgradeCatalog.GetMaxRewardableLevel(prizeID).Lvl;
                int level = Math.Min(val, lvl);
                result = starshipUpgradeCatalog.GetByLevel(prizeID, level);
                break;
            }

            case PrizeType.Vehicle:
            {
                int val   = buildingLookupController.GetHighestLevelForFactories();
                int lvl   = troopUpgradeCatalog.GetMaxRewardableLevel(prizeID).Lvl;
                int level = Math.Min(val, lvl);
                result = troopUpgradeCatalog.GetByLevel(prizeID, level);
                break;
            }

            case PrizeType.Mercenary:
            {
                int val   = buildingLookupController.GetHighestLevelForCantinas();
                int lvl   = troopUpgradeCatalog.GetMaxRewardableLevel(prizeID).Lvl;
                int level = Math.Min(val, lvl);
                result = troopUpgradeCatalog.GetByLevel(prizeID, level);
                break;
            }
            }
            return(result);
        }
Exemplo n.º 3
0
        public static void GrantInstantTroopHeroUpgrade(string rewardString)
        {
            IDataController   dataController = Service.Get <IDataController>();
            UnlockedLevelData unlockedLevels = Service.Get <CurrentPlayer>().UnlockedLevels;

            string[]    array    = RewardUtils.ParsePairedStrings(rewardString, ':');
            string      uid      = array[0];
            int         level    = Convert.ToInt32(array[1], CultureInfo.InvariantCulture);
            TroopTypeVO optional = dataController.GetOptional <TroopTypeVO>(uid);

            if (optional != null)
            {
                TroopUpgradeCatalog troopUpgradeCatalog = Service.Get <TroopUpgradeCatalog>();
                TroopTypeVO         byLevel             = troopUpgradeCatalog.GetByLevel(optional, level);
                if (byLevel != null)
                {
                    unlockedLevels.Troops.SetLevel(byLevel);
                    return;
                }
            }
            else
            {
                Service.Get <StaRTSLogger>().WarnFormat("Instant unit upgrade {0} does not exist", new object[]
                {
                    rewardString
                });
            }
        }
Exemplo n.º 4
0
        public bool DoesUserHaveAnyUpgradeableShardUnits()
        {
            CurrentPlayer          currentPlayer          = Service.Get <CurrentPlayer>();
            TroopUpgradeCatalog    troopUpgradeCatalog    = Service.Get <TroopUpgradeCatalog>();
            StarshipUpgradeCatalog starshipUpgradeCatalog = Service.Get <StarshipUpgradeCatalog>();

            foreach (string current in troopUpgradeCatalog.AllUpgradeGroups())
            {
                int         nextLevel = currentPlayer.UnlockedLevels.Troops.GetNextLevel(current);
                TroopTypeVO byLevel   = troopUpgradeCatalog.GetByLevel(current, nextLevel);
                if (byLevel != null && byLevel.PlayerFacing && byLevel.Type != TroopType.Champion && byLevel.Faction == currentPlayer.Faction && !string.IsNullOrEmpty(byLevel.UpgradeShardUid) && this.DoesUserHaveUpgradeShardRequirement(byLevel))
                {
                    bool result = true;
                    return(result);
                }
            }
            foreach (string current2 in starshipUpgradeCatalog.AllUpgradeGroups())
            {
                int nextLevel2 = currentPlayer.UnlockedLevels.Starships.GetNextLevel(current2);
                SpecialAttackTypeVO byLevel2 = starshipUpgradeCatalog.GetByLevel(current2, nextLevel2);
                if (byLevel2 != null && byLevel2.PlayerFacing && byLevel2.Faction == currentPlayer.Faction && !string.IsNullOrEmpty(byLevel2.UpgradeShardUid) && this.DoesUserHaveUpgradeShardRequirement(byLevel2))
                {
                    bool result = true;
                    return(result);
                }
            }
            return(false);
        }
Exemplo n.º 5
0
        public ShardShopViewTO GenerateViewTO(int index, CurrentPlayer player, ShardShopData data)
        {
            StaticDataController staticDataController = Service.StaticDataController;
            int             playerHQLevel             = player.Map.FindHighestHqLevel();
            ShardShopViewTO shardShopViewTO           = new ShardShopViewTO();
            string          shardSlotId = GameUtils.GetShardSlotId(index);
            int             num         = 0;

            foreach (int current in data.Purchases[index].Values)
            {
                num += current;
            }
            int num2 = this.adjustedOfferQuantity[index] - num;

            shardShopViewTO.SlotIndex = index;
            shardShopViewTO.SupplyVO  = data.ShardOffers[shardSlotId];
            shardShopViewTO.RemainingShardsForSale = num2;
            if (num2 > 0)
            {
                shardShopViewTO.CostOfNextShard = ShardShopController.CalculateCost(index, 1, data);
                shardShopViewTO.CostOfAllShards = ShardShopController.CalculateCost(index, num2, data);
            }
            shardShopViewTO.CanAffordSingle       = CostUtils.HasRequiredCurrency(player, shardShopViewTO.CostOfNextShard);
            shardShopViewTO.CanAffordAll          = CostUtils.HasRequiredCurrency(player, shardShopViewTO.CostOfAllShards);
            shardShopViewTO.PlayerHQLevel         = playerHQLevel;
            shardShopViewTO.ItemName              = GameUtils.GetShardShopNameWithoutQuantity(shardShopViewTO.SupplyVO, staticDataController);
            shardShopViewTO.Quality               = GameUtils.GetShardQualityNumeric(shardShopViewTO.SupplyVO);
            shardShopViewTO.UpgradeShardsEarned   = GameUtils.GetUpgradeShardsOwned(shardShopViewTO.SupplyVO, player);
            shardShopViewTO.UpgradeShardsRequired = GameUtils.GetUpgradeShardsRequired(shardShopViewTO.SupplyVO, player, staticDataController);
            shardShopViewTO.State = "unlocked";
            SupplyType type = shardShopViewTO.SupplyVO.Type;

            if (this.adjustedOfferQuantity[index] < 1)
            {
                shardShopViewTO.State = "maxedOut";
            }
            else if (num2 < 1)
            {
                shardShopViewTO.State = "soldOut";
            }
            else if (type == SupplyType.Shard && !ArmoryUtils.PlayerHasArmory())
            {
                shardShopViewTO.State = "requiresArmory";
            }
            else if (type == SupplyType.ShardTroop)
            {
                ShardVO             shardVO             = staticDataController.Get <ShardVO>(shardShopViewTO.SupplyVO.RewardUid);
                TroopUpgradeCatalog troopUpgradeCatalog = Service.TroopUpgradeCatalog;
                TroopTypeVO         byLevel             = troopUpgradeCatalog.GetByLevel(shardVO.TargetGroupId, 1);
                if (byLevel != null && byLevel.Type == TroopType.Mercenary && !Service.BuildingLookupController.HasCantina())
                {
                    shardShopViewTO.State = "requiresCantina";
                }
            }
            if (type == SupplyType.Shard)
            {
                EquipmentUpgradeCatalog equipmentUpgradeCatalog  = Service.EquipmentUpgradeCatalog;
                EquipmentVO             currentEquipmentDataByID = ArmoryUtils.GetCurrentEquipmentDataByID(shardShopViewTO.SupplyVO.RewardUid);
                int shards = player.GetShards(shardShopViewTO.SupplyVO.RewardUid);
                int shardsRequiredForNextUpgrade = ArmoryUtils.GetShardsRequiredForNextUpgrade(player, equipmentUpgradeCatalog, currentEquipmentDataByID);
                shardShopViewTO.Upgradeable = (shards >= shardsRequiredForNextUpgrade && shardsRequiredForNextUpgrade > 0);
            }
            else if (type == SupplyType.ShardTroop || type == SupplyType.ShardSpecialAttack)
            {
                shardShopViewTO.Upgradeable = Service.DeployableShardUnlockController.IsShardDeployableReadyToUpgrade(shardShopViewTO.SupplyVO.RewardUid);
            }
            return(shardShopViewTO);
        }