public static float Effectiveness(PokemonTypeData attackingType, PokemonTypeData defendingType) { if (defendingType.weaknesses.Contains(attackingType)) { return(2.0f); } else if (defendingType.immunities.Contains(attackingType)) { return(0.0f); } else if (defendingType.resistances.Contains(attackingType)) { return(.5f); } return(1.0f); }
public PokemonTypeData[] GenerateTypes() { pokemonTypeDataDictionary = new Dictionary <string, PokemonTypeData>(); IniFileAccessor.SetPath("/Data/Text Files/types.ini"); for (int i = 0; i <= NUMBER_OF_TYPES; i++) { string indexStr = (i).ToString(); PokemonTypeData typeData = ScriptableObject.CreateInstance <PokemonTypeData>(); typeData.Init(); typeData.name = IniFileAccessor.ReadValue(indexStr, "Name"); typeData.internalName = IniFileAccessor.ReadValue(indexStr, "InternalName"); typeData.isSpecial = IniFileAccessor.ReadValue(indexStr, "IsSpecialType").Equals("true"); Color color; if (ColorUtility.TryParseHtmlString(IniFileAccessor.ReadValue(indexStr, "Color"), out color)) { typeData.color = color; } pokemonTypeDataDictionary.Add(typeData.internalName, typeData); } for (int i = 0; i <= NUMBER_OF_TYPES; i++) { string indexStr = i + ""; string pInternalName = IniFileAccessor.ReadValue(indexStr, "InternalName"); PokemonTypeData typeData; if (pokemonTypeDataDictionary.TryGetValue(pInternalName, out typeData)) { string[] pWeaknesses = IniFileAccessor.ReadValue(indexStr, "Weaknesses").Split(','); string[] pResistances = IniFileAccessor.ReadValue(indexStr, "Resistances").Split(','); string[] pImmunities = IniFileAccessor.ReadValue(indexStr, "Immunities").Split(','); foreach (string weakness in pWeaknesses) { if (weakness == "") { break; } PokemonTypeData weaknessTypeData; if (pokemonTypeDataDictionary.TryGetValue(weakness, out weaknessTypeData)) { typeData.weaknesses.Add(weaknessTypeData); } } foreach (string resistance in pResistances) { if (resistance == "") { break; } PokemonTypeData resistanceTypeData; if (pokemonTypeDataDictionary.TryGetValue(resistance, out resistanceTypeData)) { typeData.resistances.Add(resistanceTypeData); } } foreach (string immunity in pImmunities) { if (immunity == "") { break; } PokemonTypeData immunityTypeData; if (pokemonTypeDataDictionary.TryGetValue(immunity, out immunityTypeData)) { typeData.immunities.Add(immunityTypeData); } } } } pokemonTypeDataSerializationArray = new PokemonTypeData[pokemonTypeDataDictionary.Count]; pokemonTypeDataDictionary.Values.CopyTo(pokemonTypeDataSerializationArray, 0); return(pokemonTypeDataSerializationArray); }
public void OnEnable() { comp = (PokemonTypeData)target; }
public static float Effectiveness(PokemonTypeData attackingType, PokemonData defendingPokemon) { return(Effectiveness(attackingType, defendingPokemon.type1) * Effectiveness(attackingType, defendingPokemon.type2)); }
public bool Equals(PokemonTypeData other) { return(internalName.Equals(other.internalName)); }
public bool IsType(PokemonTypeData type) { return(type.Equals(pokemonData.type1) || type.Equals(pokemonData.type2)); }
public IEnumerator SingleAttack(Pokemon attacker, Pokemon defender, MoveInSet moveInSet) { float accuracyCheck = Random.Range(0, 100f); MoveData move = moveInSet.move; dialogueManager.AddDialogue(attacker.GetName() + " used " + move.name + "!"); yield return(StartCoroutine(dialogueManager.WaitForCaughtUpText())); if (move.accuracy > 0 && accuracyCheck > move.accuracy) { yield return(StartCoroutine(dialogueManager.WaitForCaughtUpTextAndInput())); dialogueManager.AddDialogue("But it missed!"); yield break; } float level = attacker.level; float power = move.basePower; float ratingMultiplier; float burn; if (move.isSpecial) { burn = 1.0f; ratingMultiplier = (float)attacker.specialAttack / defender.specialDefense; } else { burn = attacker.status.Equals(Status.BURN) ? .5f : 1.0f; ratingMultiplier = (float)attacker.attack / defender.defense; } float targets = 1.0f; float weather = 1.0f; float badge = 1.0f; float criticalChance = 1f / 16.0f; bool criticalHappened = Random.Range(0f, 1f) < criticalChance; float critical = (criticalHappened? 2.0f : 1.0f); float randomVariation = Random.Range(.85f, 1.0f); float STAB = (attacker.IsType(move.type) ? 1.5f : 1.0f); float typeEffectiveness = PokemonTypeData.Effectiveness(move.type, defender); float other = 1.0f; float modifier = targets * weather * badge * critical * randomVariation * STAB * typeEffectiveness * burn * other; int damage = Mathf.CeilToInt((2f + ((2f + (2f * level) / 5f) * power * ratingMultiplier) / 50f) * modifier); if (damage <= 0) { yield return(StartCoroutine(dialogueManager.WaitForCaughtUpTextAndInput())); dialogueManager.AddDialogue("It didn't effect " + defender.GetName() + "..."); yield break; } defender.ModHP(-damage); yield return(StartCoroutine(WaitForBarsToLoad())); if (criticalHappened) { yield return(StartCoroutine(dialogueManager.WaitForCaughtUpTextAndInput())); dialogueManager.AddDialogue("Critical hit!"); } if (typeEffectiveness > 1.0f) { yield return(StartCoroutine(dialogueManager.WaitForCaughtUpTextAndInput())); dialogueManager.AddDialogue("It was super effective!"); } if (typeEffectiveness < 1.0f) { yield return(StartCoroutine(dialogueManager.WaitForCaughtUpTextAndInput())); dialogueManager.AddDialogue("It wasn't very effective..."); } dialogueManager.DisplayNextSentence(); }