//used in the age old method of enslaving creatures int TryToCatchCreature(Creature creature) { //the formula used in pokemon to capture using health, status and luck to try catch it float a = (3 * creature.MaxHp - 2 * creature.HP) * creature.Base.CatchRate * ConditionsDB.GetStatusBonus(creature.Status) / (3 * creature.MaxHp); if (a >= 255) { //on return 4 the creature is captured return(4); } //if the value is not equal to 255 a new value is required and its below.... float b = 1048560 / Mathf.Sqrt(Mathf.Sqrt(16711680 / a)); int shakeCount = 0; //run loop 4 times while (shakeCount < 4) { if (UnityEngine.Random.Range(0, 65535) >= b) { break; } ++shakeCount; } return(shakeCount); }
int TryToCatchAnimal(Animal animal) { float a = (3 * animal.MaxHP - 2 * animal.HP) * animal.Base.CatchRate * ConditionsDB.GetStatusBonus(animal.Status) / (3 * animal.MaxHP); if (a >= 255) { return(4); } float b = 1048560 / Mathf.Sqrt(Mathf.Sqrt(16711680 / a)); int shakeCount = 0; while (shakeCount < 4) { if (UnityEngine.Random.Range(0, 65535) >= b) { break; } ++shakeCount; } return(shakeCount); }
int TryToCatchPokemon(Pokemon pokemon) //Number of shake the ball will do, and know if the pokemon is captured or not { //a is a value we'll use in the calculation of the number of shake the ball have to do float a = (3 * pokemon.MaxHp - 2 * pokemon.HP) * pokemon.Base.CatchRate * ConditionsDB.GetStatusBonus(pokemon.Status) / (3 * pokemon.MaxHp); if (a >= 255) //If a is enough (the pokemon already has 255, or by the calculus it's up to this value { return(4); } float b = 1048560 / Mathf.Sqrt(Mathf.Sqrt(16711680 / a)); //We'll use be to determine how many counts we have to do int shakeCount = 0; while (shakeCount < 4) { if (UnityEngine.Random.Range(0, 65535) >= b) { break; } ++shakeCount; } return(shakeCount); }