public void Set(SecondaryMove move) { _curSecondaryMove = move; _moveNameText.text = _curSecondaryMove.Name; _moveTypeLabel.SetType(_curSecondaryMove.Type); }
public void Set(SecondaryMove move) { Set((PrimaryMove)move); _otherStatsCountText.text = (move.CritChance * 100) + UIManager.GetFormattedText(" %", TextColorType.GreyLight, false, 12) + UIManager.NewLine(1) + move.DidgeWindow + UIManager.GetFormattedText(" " + TextManager.GetText(TextType.Element, 16), TextColorType.GreyLight, false, 12) + UIManager.NewLine(1) + (100 / move.ChargeCount) + UIManager.GetFormattedText(" / 100 ", TextColorType.GreyLight, false, 12); SetChargeCount(move.ChargeCount); }
public void ShowSecondaryMovePage(SecondaryMove move) { if (State == UIState.BlockInput) { return; } SetState(UIState.BlockInput); _pokemonPage.Hide(() => {}); _chargeMovePage.Show(() => SetState(UIState.ChargeMovePage)); _chargeMovePage.Set(move); AppManager.RegisterUserEvent(UserEventType.PokemonMoveOpened); }
static void LoadPokeInfoFromJson() { try { PokeData pokeData = (PokeData)AssetDatabase.LoadAssetAtPath(PokeDataObjPath, typeof(PokeData)); #region Fill Type Chart TextAsset typeChartJsonString = (TextAsset)AssetDatabase.LoadAssetAtPath(JsonPath + TypeChartJsonName, typeof(TextAsset)); PokeTypeChartJson typeChartJson = JsonUtility.FromJson <PokeTypeChartJson>(typeChartJsonString.text); TypeChart typeChart = pokeData.TypeChart = new TypeChart(typeChartJson.TypeChart.Length); for (int i = 0; i < typeChart.TypeParameters.Length; i++) { TypeParameter typeParam = typeChart.TypeParameters[i] = new TypeParameter(); typeParam.BaseType = (PokeType)Enum.Parse(typeof(PokeType), typeChartJson.TypeChart[i].Type); if (!string.IsNullOrEmpty(typeChartJson.TypeChart[i].Strenghts)) { string[] strenghtsString = typeChartJson.TypeChart[i].Strenghts.Split(new[] { ", " }, StringSplitOptions.None); typeParam.StrenghtsTypes = new PokeType[strenghtsString.Length]; for (int j = 0; j < typeParam.StrenghtsTypes.Length; j++) { typeParam.StrenghtsTypes[j] = (PokeType)Enum.Parse(typeof(PokeType), strenghtsString[j]); } } if (!string.IsNullOrEmpty(typeChartJson.TypeChart[i].Weaknesses)) { string[] weaksString = typeChartJson.TypeChart[i].Weaknesses.Split(new[] { ", " }, StringSplitOptions.None); typeParam.WeaknessesTypes = new PokeType[weaksString.Length]; for (int j = 0; j < typeParam.WeaknessesTypes.Length; j++) { typeParam.WeaknessesTypes[j] = (PokeType)Enum.Parse(typeof(PokeType), weaksString[j]); } } } #endregion #region Load Primary Moves TextAsset primaryMovesJsonString = (TextAsset)AssetDatabase.LoadAssetAtPath(JsonPath + PrimaryMovesJsonName, typeof(TextAsset)); PrimaryMovesDataJson primaryMovesDataJson = JsonUtility.FromJson <PrimaryMovesDataJson>(primaryMovesJsonString.text); pokeData.PrimaryMoves = new PrimaryMove[primaryMovesDataJson.PrimaryMoves.Length]; for (int i = 0; i < primaryMovesDataJson.PrimaryMoves.Length; i++) { PrimaryMove primaryMove = pokeData.PrimaryMoves[i] = new PrimaryMove(); PrimaryMovesJson primaryMovesJson = primaryMovesDataJson.PrimaryMoves[i]; primaryMove.Name = primaryMovesJson.Name; primaryMove.Type = (PokeType)Enum.Parse(typeof(PokeType), primaryMovesJson.Type); primaryMove.Attack = primaryMovesJson.Atk; primaryMove.Cooldown = primaryMovesJson.Cooldown; primaryMove.Dps = primaryMovesJson.DPS; primaryMove.EnergyGain = primaryMovesJson.EnergyGain; primaryMove.StrongAgaints = pokeData.TypeChart.GetStrenghts(primaryMove.Type); primaryMove.WeakAgains = pokeData.TypeChart.GetWeaknesses(primaryMove.Type); } #endregion #region Load Secondary Moves TextAsset secondaryMovesJsonString = (TextAsset)AssetDatabase.LoadAssetAtPath(JsonPath + SecondaryMovesJsonName, typeof(TextAsset)); SecondaryMovesDataJson secondaryMovesDataJson = JsonUtility.FromJson <SecondaryMovesDataJson>(secondaryMovesJsonString.text); pokeData.SecondaryMoves = new SecondaryMove[secondaryMovesDataJson.SecondaryMoves.Length]; for (int i = 0; i < secondaryMovesDataJson.SecondaryMoves.Length; i++) { SecondaryMove secMove = pokeData.SecondaryMoves[i] = new SecondaryMove(); SecondaryMovesJson secMoveJson = secondaryMovesDataJson.SecondaryMoves[i]; secMove.Name = secMoveJson.Name; secMove.Type = (PokeType)Enum.Parse(typeof(PokeType), secMoveJson.Type); secMove.ChargeCount = Mathf.Clamp(secMoveJson.ChargeCount, 1, 5); secMove.Attack = secMoveJson.Atk; secMove.Cooldown = secMoveJson.Cooldown; secMove.Dps = secMoveJson.DPS; secMove.CritChance = secMoveJson.CritChance; secMove.DidgeWindow = secMoveJson.DodgeWindow; secMove.StrongAgaints = pokeData.TypeChart.GetStrenghts(secMove.Type); secMove.WeakAgains = pokeData.TypeChart.GetWeaknesses(secMove.Type); } #endregion #region Load Pokemons TextAsset pokemonsJsonString = (TextAsset)AssetDatabase.LoadAssetAtPath(JsonPath + PokemonsJsonName, typeof(TextAsset)); PokeDataJson pokeDataJson = JsonUtility.FromJson <PokeDataJson>(pokemonsJsonString.text); pokeData.PokeInfos = new PokeInfo[pokeDataJson.Pokemons.Length]; for (int i = 0; i < pokeDataJson.Pokemons.Length; i++) { PokeInfo pokeInfo = pokeData.PokeInfos[i] = new PokeInfo(); PokeInfoJson pokeInfoJson = pokeDataJson.Pokemons[i]; pokeInfoJson.Name = Regex.Replace(pokeInfoJson.Name, @"\p{Z}", ""); pokeInfo.Name = pokeInfoJson.Name; pokeInfo.Id = i + 1; #region Fill Type string[] pokeTypesJson = pokeInfoJson.Type.Split(new[] { ", " }, StringSplitOptions.None); pokeInfo.Type = new PokeType[pokeTypesJson.Length]; for (int j = 0; j < pokeTypesJson.Length; j++) { pokeTypesJson[j] = pokeTypesJson[j].Replace(" ", string.Empty); pokeInfo.Type[j] = (PokeType)Enum.Parse(typeof(PokeType), pokeTypesJson[j]); } #endregion pokeInfo.Weight = pokeInfoJson.Weight; pokeInfo.Height = pokeInfoJson.Height; pokeInfo.MaxCp = pokeInfoJson.MaxCp; pokeInfo.CpMultiFromEvo = pokeInfoJson.EvoCpMulti; pokeInfo.BaseAttack = pokeInfoJson.BaseAttack; pokeInfo.BaseDefense = pokeInfoJson.BaseDefense; pokeInfo.BaseStamina = pokeInfoJson.BaseStamina; pokeInfo.BaseHp = pokeInfoJson.BaseHP; pokeInfo.Rarity = pokeInfoJson.Rarity; pokeInfo.CaptureRate = pokeInfoJson.CaptureRate; pokeInfo.FleeRate = pokeInfoJson.FleeRate; pokeInfo.Class = (PokeClass)Enum.Parse(typeof(PokeClass), pokeInfoJson.Class); pokeInfo.CandyToEvolve = pokeInfoJson.CandyToEvolve; int eggDistance = 0; if (int.TryParse(pokeInfoJson.EggDistanceToHatch.Replace("km", string.Empty), out eggDistance)) { pokeInfo.EggDistanceType = (EggType)eggDistance; } #region Fill Primary Moves string[] primaryMovesString = pokeInfoJson.PossiblePrimaryMoves.Split(new[] { ", " }, StringSplitOptions.None); pokeInfo.PrimaryMovesIds = new int[primaryMovesString.Length]; for (int j = 0; j < pokeInfo.PrimaryMovesIds.Length; j++) { pokeInfo.PrimaryMovesIds[j] = pokeData.GetPrimaryMoveId(primaryMovesString[j]); } #endregion #region Fill Secondary Moves string[] secondaryMovesString = pokeInfoJson.PossibleSecondaryMoves.Split(new[] { ", " }, StringSplitOptions.None); pokeInfo.SecondaryMovesIds = new int[secondaryMovesString.Length]; for (int j = 0; j < pokeInfo.SecondaryMovesIds.Length; j++) { pokeInfo.SecondaryMovesIds[j] = pokeData.GetSecondaryMoveId(secondaryMovesString[j]); } #endregion pokeInfo.Resistance = pokeData.TypeChart.GetResistance(pokeInfo.Type); pokeInfo.Weaknesses = pokeData.TypeChart.GetWeaknesses(pokeInfo.Type); } #region Fill Evo FromTo for (int i = 0; i < pokeData.PokeInfos.Length; i++) { PokeInfo pokeInfo = pokeData.PokeInfos[i]; PokeInfoJson pokeInfoJson = pokeDataJson.Pokemons[i]; if (!string.IsNullOrEmpty(pokeInfoJson.EvoFrom)) { pokeInfo.EvoFromId = pokeData.GetPokeInfoIdByName(Regex.Replace(pokeInfoJson.EvoFrom, @"\p{Z}", "")); } else { pokeInfo.EvoFromId = -1; } if (!string.IsNullOrEmpty(pokeInfoJson.EvoTo)) { pokeInfo.EvoToId = pokeData.GetPokeInfoIdByName(Regex.Replace(pokeInfoJson.EvoTo, @"\p{Z}", "")); } else { pokeInfo.EvoToId = -1; } } #endregion Debug.Log("Loading complete!"); #endregion #region Fill Pokemon stats Rates Vector3 maxStatsRates = Vector3.zero; //x-Attack, y-Defense, z-Hp for (int i = 0; i < pokeData.PokeInfos.Length; i++) { PokeInfo pInfo = pokeData.PokeInfos[i]; if (pInfo.BaseAttack > maxStatsRates.x) { maxStatsRates.x = pInfo.BaseAttack; } if (pInfo.BaseDefense > maxStatsRates.y) { maxStatsRates.y = pInfo.BaseDefense; } if (pInfo.BaseStamina > maxStatsRates.z) { maxStatsRates.z = pInfo.BaseStamina; } } for (int i = 0; i < pokeData.PokeInfos.Length; i++) { PokeInfo pInfo = pokeData.PokeInfos[i]; pInfo.AttackRate = (float)pInfo.BaseAttack / maxStatsRates.x; pInfo.DefenseRate = (float)pInfo.BaseDefense / maxStatsRates.y; pInfo.StaminaRate = (float)pInfo.BaseStamina / maxStatsRates.z; } #endregion #region Fill Move stats Rates Vector3 maxMoveRates = Vector3.zero; //x-Attack, y-Cooldown, z-DPS //Primary for (int i = 0; i < pokeData.PrimaryMoves.Length; i++) { PrimaryMove move = pokeData.PrimaryMoves[i]; if (move.Attack > maxMoveRates.x) { maxMoveRates.x = move.Attack; } if (move.Cooldown > maxMoveRates.y) { maxMoveRates.y = move.Cooldown; } if (move.Dps > maxMoveRates.z) { maxMoveRates.z = move.Dps; } } for (int i = 0; i < pokeData.PrimaryMoves.Length; i++) { PrimaryMove move = pokeData.PrimaryMoves[i]; move.AttackRate = (float)move.Attack / maxMoveRates.x; move.CooldownRate = (float)move.Cooldown / maxMoveRates.y; move.DpsRate = (float)move.Dps / maxMoveRates.z; } //Secondary maxMoveRates = Vector3.zero; for (int i = 0; i < pokeData.SecondaryMoves.Length; i++) { SecondaryMove move = pokeData.SecondaryMoves[i]; if (move.Attack > maxMoveRates.x) { maxMoveRates.x = move.Attack; } if (move.Cooldown > maxMoveRates.y) { maxMoveRates.y = move.Cooldown; } if (move.Dps > maxMoveRates.z) { maxMoveRates.z = move.Dps; } } for (int i = 0; i < pokeData.SecondaryMoves.Length; i++) { SecondaryMove move = pokeData.SecondaryMoves[i]; move.AttackRate = (float)move.Attack / maxMoveRates.x; move.CooldownRate = (float)move.Cooldown / maxMoveRates.y; move.DpsRate = (float)move.Dps / maxMoveRates.z; } #endregion EditorUtility.SetDirty(pokeData); Debug.Log("Loading Poke info complete!"); } catch (Exception) { Debug.LogError("Error while loading data from json"); throw; } }