private static uint[] GetExpTable(GrowthRates growth_rate) { switch (growth_rate) { case GrowthRates.Fast: return(fast_exp_table); case GrowthRates.Medium: return(medium_fast_exp_table); case GrowthRates.Slow: return(slow_exp_table); case GrowthRates.Parabolic: return(medium_slow_exp_table); case GrowthRates.Erratic: return(erratic_exp_table); case GrowthRates.Fluctuating: return(fluctuating_exp_table); default: return(null); } }
public static int ExperienceAt(int level, GrowthRates gr) { if (level > 100 || level < 1) { throw new ArgumentOutOfRangeException("level"); } if (level == 1) { return(0); } switch (gr) { case GrowthRates.Slow: return(ExperienceAt_Slow(level)); case GrowthRates.Medium: return(ExperienceAt_Medium(level)); case GrowthRates.Fast: return(ExperienceAt_Fast(level)); case GrowthRates.MediumSlow: return(ExperienceAt_MediumSlow(level)); case GrowthRates.Erratic: return(ExperienceAt_Erratic(level)); case GrowthRates.Fluctuating: return(ExperienceAt_Fluctuating(level)); } throw new ArgumentException("gr"); }
public Species(Pokedex pokedex, int national_dex, int family_id, LocalizedString name, GrowthRates growth_rate, byte gender_ratio, EggGroups egg_group_1, EggGroups egg_group_2, int egg_steps, bool gender_variations) { m_pokedex = pokedex; NationalDex = national_dex; FamilyID = family_id; Name = name; GrowthRate = growth_rate; GenderRatio = gender_ratio; EggGroup1 = egg_group_1; EggGroup2 = egg_group_2; EggSteps = egg_steps; GenderVariations = gender_variations; //if (pokedex != null && pokedex.Eager) { // Retrieve foreign information like Family and Formes. // Otherwise, this information will be lazily evaluated // from the Pokedex instance. // If pokedex is null, this information is unavailable. // todo: database ownership/lazy stuff can go in a base class. } }
public static async Task CreateGts(Client c, string offer, string request, string index) { //If user is banned, return if (await Database.DbUserChecks.UserBanned(c.Username)) { await c.SendMessage($"<GTSCREATE result=0 index={index}>"); return; } //If user has more than max amount of allowed GTS trades, return if (await Database.Dbgts.GetNumberOfTrades(c.UserId) >= Data.MaximumGtsTradesPerUser) { await c.SendMessage($"<GTSCREATE result=1 index={index}>"); return; } //Decode data var decodeOffer = Utilities.Encoding.Base64Decode(offer); var decodeRequest = Utilities.Encoding.Base64Decode(request); int level; try { //Turn data into objects var pokemon = JsonConvert.DeserializeObject <GamePokemon>(decodeOffer); if (!await TradeValidator.IsPokemonValid(pokemon, c.UserId)) { await c.SendMessage($"<GTSCREATE result=0 index={index}>"); return; } //Get Pokemon Level level = GrowthRates.CalculateLevel(pokemon.species, pokemon.exp); } catch (InvalidCastException) { await c.SendMessage($"<GTSCREATE result=2 index={index}>"); return; } //Input in database try { await Database.Dbgts.Add(c.UserId, decodeOffer, decodeRequest, level, c.Username); await c.SendMessage($"<GTSCREATE result=3 index={index}>"); } catch (Exception e) { Console.WriteLine(e); await c.SendMessage($"<GTSCREATE result=2 index={index}>"); } }
public static uint GetLevelTotalExp(uint level, GrowthRates growth_rate) { uint[] exp_table = GetExpTable(growth_rate); if (level < 1 || level > Constants.MAX_LEVEL || exp_table == null) { return(uint.MaxValue); } return(exp_table[level - 1]); }
public static uint GetExpToNextLevel(uint current_exp, GrowthRates growth_rate) { uint[] exp_table = GetExpTable(growth_rate); uint current_level = GetLevelFromExp(current_exp, growth_rate); if (exp_table == null || current_level == Constants.MAX_LEVEL) { return(0); } uint next_level_exp = GetLevelTotalExp((uint)current_level + 1, growth_rate); return(next_level_exp - current_exp); }
public Stats(Stats stats, GrowthRates growthRates) { strength = stats.strength; magic = stats.magic; skill = stats.skill; speed = stats.speed; luck = stats.luck; defense = stats.defense; resistance = stats.resistance; constitution = stats.constitution; movement = stats.movement; aid = stats.aid; pursuitCriticalCoefficient = stats.pursuitCriticalCoefficient; this.growthRates = growthRates; }
public Stats(int strength, int magic, int skill, int speed, int luck, int defense, int resistance, int constitution, int movement, int aid, float pcc, GrowthRates growthRates) { this.strength = strength; this.magic = magic; this.skill = skill; this.speed = speed; this.luck = luck; this.defense = defense; this.resistance = resistance; this.constitution = constitution; this.movement = movement; this.aid = aid; pursuitCriticalCoefficient = pcc; this.growthRates = growthRates; }
public static float GetExpToNextLevelPercent(uint current_exp, GrowthRates growth_rate) { uint[] exp_table = GetExpTable(growth_rate); uint current_level = GetLevelFromExp(current_exp, growth_rate); if (exp_table == null || current_level == Constants.MAX_LEVEL) { return(0); } uint this_level_total_exp = GetLevelTotalExp(current_level, growth_rate); uint next_level_total_exp = GetLevelTotalExp(current_level + 1, growth_rate); uint level_up_total_exp = next_level_total_exp - this_level_total_exp; uint this_level_exp_progress = current_exp - this_level_total_exp; return((float)this_level_exp_progress / (float)level_up_total_exp); }
public Species(Pokedex pokedex, int national_dex, int family_id, LocalizedString name, GrowthRates growth_rate, byte gender_ratio, EggGroups egg_group_1, EggGroups egg_group_2, int egg_steps, bool gender_variations) : base(pokedex) { m_family_pair = Family.CreatePair(m_pokedex); m_lazy_pairs.Add(m_family_pair); NationalDex = national_dex; m_family_pair.Key = family_id; Name = name; GrowthRate = growth_rate; GenderRatio = gender_ratio; EggGroup1 = egg_group_1; EggGroup2 = egg_group_2; EggSteps = egg_steps; GenderVariations = gender_variations; }
public static uint GetLevelFromExp(uint current_exp, GrowthRates growth_rate) { uint[] exp_table = GetExpTable(growth_rate); if (exp_table == null) { return(0); } uint highest_level_found = 0; for (uint i = 0; i < Constants.MAX_LEVEL; i++) { if (current_exp >= exp_table[i]) { highest_level_found = i + 1; } else { break; } } return(highest_level_found); }
public static byte LevelAt(int experience, GrowthRates gr) { if (experience < 0) { throw new ArgumentOutOfRangeException("experience"); } int minLevel = 1, maxLevel = 100; int minExp = ExperienceAt(1, gr), maxExp = ExperienceAt(100, gr); while (1 < 2) { if (maxExp <= experience) { return((byte)maxLevel); } if (minLevel + 1 >= maxLevel) { return((byte)minLevel); } int midLevel = (minLevel + maxLevel) >> 1; int midExp = ExperienceAt(midLevel, gr); if (experience >= midExp) { minLevel = midLevel; minExp = midExp; } else { maxLevel = midLevel; maxExp = midExp; } } }
public static void Initialize(string CacheFolder = "") { if (Connector.isInitialized) { throw new Exception("PokeAPI is initialized and can only be initialized once"); //May seems a bit over kill but this is nessecery for corrent usage. } #region "Structure" Connector.Berries = new Berries(); Connector.BerryFirmnesses = new BerryFirmnesses(); Connector.BerryFlavors = new BerryFlavors(); Connector.ContestNames = new ContestNames(); Connector.ContestEffects = new ContestEffects(); Connector.SuperContestEffects = new SuperContestEffects(); Connector.EncounterMethods = new EncounterMethods(); Connector.EncounterConditions = new EncounterConditions(); Connector.EncounterConditionValues = new EncounterConditionValues(); Connector.EvolutionChains = new EvolutionChains(); Connector.EvolutionTrigger = new EvolutionTrigger(); Connector.Generations = new Generations(); Connector.Pokedexes = new Pokedexes(); Connector.Versions = new Versions(); Connector.VersionGroups = new VersionGroups(); Connector.Items = new Items(); Connector.ItemAttributes = new ItemAttributes(); Connector.ItemCategories = new ItemCategories(); Connector.ItemFlingEffects = new ItemFlingEffects(); Connector.ItemPockets = new ItemPockets(); Connector.Locations = new Locations(); Connector.LocationAreas = new LocationAreas(); Connector.PalParkAreas = new PalParkAreas(); Connector.Regions = new Regions(); Connector.Machines = new Machines(); Connector.Moves = new Moves(); Connector.MoveAilments = new MoveAilments(); Connector.MoveBattleStyles = new MoveBattleStyles(); Connector.MoveCategories = new MoveCategories(); Connector.MoveDamageClasses = new MoveDamageClasses(); Connector.MoveLearnMethods = new MoveLearnMethods(); Connector.MoveTargets = new MoveTargets(); Connector.Abilities = new Abilities(); Connector.Characteristics = new Characteristics(); Connector.EggGroups = new EggGroups(); Connector.Genders = new Genders(); Connector.GrowthRates = new GrowthRates(); Connector.Natures = new Natures(); Connector.PokeathlonStats = new PokeathlonStats(); Connector.Pokemons = new Pokemons(); Connector.PokemonColors = new PokemonColors(); Connector.PokemonForms = new PokemonForms(); Connector.PokemonHabitats = new PokemonHabitats(); Connector.PokemonShapes = new PokemonShapes(); Connector.PokemonSpecies = new PokemonSpecies(); Connector.Stats = new Stats(); Connector.Types = new Types(); Connector.Languages = new Languages(); #endregion if (CacheFolder == "") { Connector.CacheFolder = AppDomain.CurrentDomain.BaseDirectory + "pokeAPI//"; } else { if (!System.IO.Directory.Exists(CacheFolder)) { throw new Exception("Directory : " + CacheFolder + " was not found"); } Connector.CacheFolder = CacheFolder; } Cacher.Initialize(); Connector.isInitialized = true; }
public static byte LevelAt(int experience, GrowthRates gr) { if (experience < 0) throw new ArgumentOutOfRangeException("experience"); int minLevel = 1, maxLevel = 100; int minExp = ExperienceAt(1, gr), maxExp = ExperienceAt(100, gr); while (1 < 2) { if (maxExp <= experience) return (byte)maxLevel; if (minLevel + 1 >= maxLevel) return (byte)minLevel; int midLevel = (minLevel + maxLevel) >> 1; int midExp = ExperienceAt(midLevel, gr); if (experience >= midExp) { minLevel = midLevel; minExp = midExp; } else { maxLevel = midLevel; maxExp = midExp; } } }
public static int ExperienceAt(int level, GrowthRates gr) { if (level > 100 || level < 1) throw new ArgumentOutOfRangeException("level"); if (level == 1) return 0; switch (gr) { case GrowthRates.Slow: return ExperienceAt_Slow(level); case GrowthRates.Medium: return ExperienceAt_Medium(level); case GrowthRates.Fast: return ExperienceAt_Fast(level); case GrowthRates.MediumSlow: return ExperienceAt_MediumSlow(level); case GrowthRates.Erratic: return ExperienceAt_Erratic(level); case GrowthRates.Fluctuating: return ExperienceAt_Fluctuating(level); } throw new ArgumentException("gr"); }