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); }
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 }); } }
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); }
public static bool IsUpgradeTroopContractValid(Contract contract) { TroopTypeVO upgradeable = Service.Get <IDataController>().Get <TroopTypeVO>(contract.ProductUid); TroopUpgradeCatalog troopUpgradeCatalog = Service.Get <TroopUpgradeCatalog>(); CurrentPlayer currentPlayer = Service.Get <CurrentPlayer>(); return(troopUpgradeCatalog.CanUpgradeTo(currentPlayer.UnlockedLevels.Troops, upgradeable)); }
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); }
public TroopUpgradeScreen(SmartEntity trainingBuilding) : base("gui_upgrade_troops", trainingBuilding) { this.dataController = Service.StaticDataController; this.troopUpgradeCatalog = Service.TroopUpgradeCatalog; this.starshipUpgradeCatalog = Service.StarshipUpgradeCatalog; this.accumulatedUpdateDt = 0f; this.timerActive = false; this.eligibleDeployables = new List <TroopUpgradeScreen.DeployableUpgradeData>(); this.eligibleTroopTypes = new HashSet <TroopType>(); this.hasStarships = false; this.equipmentToDisplay = new List <EquipmentVO>(); this.RefreshDeployableData(); }
private void AddTroops(List <UXElement> list) { TroopUpgradeCatalog troopUpgradeCatalog = Service.TroopUpgradeCatalog; foreach (KeyValuePair <string, int> current in this.cp.Prizes.Troops) { if (current.Value > 0) { PrizeType prizeType = PrizeType.Infantry; TroopTypeVO minLevel = troopUpgradeCatalog.GetMinLevel(current.Key); TroopType type = minLevel.Type; if (type != TroopType.Vehicle) { if (type != TroopType.Mercenary) { if (type == TroopType.Hero) { prizeType = PrizeType.Hero; } } else { prizeType = PrizeType.Mercenary; } } else { prizeType = PrizeType.Vehicle; } UXElement item = this.CreateTileWithPrizeInfo(current.Key, current.Value, prizeType); list.Add(item); } } foreach (KeyValuePair <string, int> current2 in this.cp.Prizes.SpecialAttacks) { if (current2.Value > 0) { UXElement item2 = this.CreateTileWithPrizeInfo(current2.Key, current2.Value, PrizeType.SpecialAttack); list.Add(item2); } } }
private void AddTroops(List <UXElement> list) { TroopUpgradeCatalog troopUpgradeCatalog = Service.Get <TroopUpgradeCatalog>(); foreach (KeyValuePair <string, int> current in this.cp.Prizes.Troops) { if (current.get_Value() > 0) { PrizeType prizeType = PrizeType.Infantry; TroopTypeVO minLevel = troopUpgradeCatalog.GetMinLevel(current.get_Key()); switch (minLevel.Type) { case TroopType.Vehicle: prizeType = PrizeType.Vehicle; break; case TroopType.Mercenary: prizeType = PrizeType.Mercenary; break; case TroopType.Hero: prizeType = PrizeType.Hero; break; } UXElement item = this.CreateTileWithPrizeInfo(current.get_Key(), current.get_Value(), prizeType); list.Add(item); } } foreach (KeyValuePair <string, int> current2 in this.cp.Prizes.SpecialAttacks) { if (current2.get_Value() > 0) { UXElement item2 = this.CreateTileWithPrizeInfo(current2.get_Key(), current2.get_Value(), PrizeType.SpecialAttack); list.Add(item2); } } }
public List <TroopTypeVO> GetTroopsUnlockedByBuilding(string reqBuildingUid) { TroopUpgradeCatalog troopUpgradeCatalog = Service.TroopUpgradeCatalog; return(this.GetItemsUnlockedByBuilding <TroopTypeVO>(reqBuildingUid, troopUpgradeCatalog)); }
public bool IsEquipmentValidForTab(EquipmentVO vo, EquipmentTab selectedTab) { if (selectedTab == EquipmentTab.All) { return(true); } TroopUpgradeCatalog troopUpgradeCatalog = Service.Get <TroopUpgradeCatalog>(); IDataController dataController = Service.Get <IDataController>(); if (vo.EffectUids == null) { return(false); } int i = 0; int num = vo.EffectUids.Length; while (i < num) { EquipmentEffectVO optional = dataController.GetOptional <EquipmentEffectVO>(vo.EffectUids[i]); if (optional == null) { Service.Get <StaRTSLogger>().Error("CMS Error: EffectUids is empty for EquipmentEffectVO " + optional.Uid); return(false); } switch (selectedTab) { case EquipmentTab.Troops: if (optional.AffectedTroopIds != null && optional.AffectedTroopIds.Length != 0) { int j = 0; int num2 = optional.AffectedTroopIds.Length; while (j < num2) { if (troopUpgradeCatalog.GetMinLevel(optional.AffectedTroopIds[j]).Type != TroopType.Hero) { return(true); } j++; } } break; case EquipmentTab.Heroes: if (optional.AffectedTroopIds != null && optional.AffectedTroopIds.Length != 0) { int k = 0; int num3 = optional.AffectedTroopIds.Length; while (k < num3) { if (troopUpgradeCatalog.GetMinLevel(optional.AffectedTroopIds[k]).Type == TroopType.Hero) { return(true); } k++; } } break; case EquipmentTab.Structures: if (optional.AffectedBuildingIds != null && optional.AffectedBuildingIds.Length != 0) { return(true); } break; } i++; } return(false); }
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); }
public bool IsEquipmentValidForTab(EquipmentVO vo, EquipmentTab selectedTab) { if (selectedTab == EquipmentTab.All) { return(true); } TroopUpgradeCatalog troopUpgradeCatalog = Service.TroopUpgradeCatalog; StaticDataController staticDataController = Service.StaticDataController; if (vo.EffectUids == null) { return(false); } int i = 0; int num = vo.EffectUids.Length; while (i < num) { EquipmentEffectVO optional = staticDataController.GetOptional <EquipmentEffectVO>(vo.EffectUids[i]); if (optional == null) { Service.Logger.Error("CMS Error: EffectUids is empty for EquipmentEffectVO " + optional.Uid); return(false); } if (selectedTab != EquipmentTab.Structures) { if (selectedTab != EquipmentTab.Troops) { if (selectedTab == EquipmentTab.Heroes) { if (optional.AffectedTroopIds != null && optional.AffectedTroopIds.Length > 0) { int j = 0; int num2 = optional.AffectedTroopIds.Length; while (j < num2) { if (troopUpgradeCatalog.GetMinLevel(optional.AffectedTroopIds[j]).Type == TroopType.Hero) { return(true); } j++; } } } } else if (optional.AffectedTroopIds != null && optional.AffectedTroopIds.Length > 0) { int k = 0; int num3 = optional.AffectedTroopIds.Length; while (k < num3) { if (troopUpgradeCatalog.GetMinLevel(optional.AffectedTroopIds[k]).Type != TroopType.Hero) { return(true); } k++; } } } else if (optional.AffectedBuildingIds != null && optional.AffectedBuildingIds.Length > 0) { return(true); } i++; } return(false); }