Added class GameData::GrowthRate

This commit is contained in:
Maruno17
2021-02-23 22:20:34 +00:00
parent f302d8346a
commit eda534f3be
24 changed files with 245 additions and 261 deletions

View File

@@ -118,7 +118,7 @@ module GameData
else
ret["InternalName"] = [0, "n"]
ret["Name"] = [0, "s"]
ret["GrowthRate"] = [0, "e", :PBGrowthRates]
ret["GrowthRate"] = [0, "e", :GrowthRate]
ret["GenderRate"] = [0, "e", :GenderRatio]
ret["Incense"] = [0, "e", :Item]
ret["Evolutions"] = [0, "*ses", nil, :PBEvolution, nil]
@@ -141,7 +141,7 @@ module GameData
@base_stats = hash[:base_stats] || [1, 1, 1, 1, 1, 1]
@evs = hash[:evs] || [0, 0, 0, 0, 0, 0]
@base_exp = hash[:base_exp] || 100
@growth_rate = hash[:growth_rate] || PBGrowthRates::Medium
@growth_rate = hash[:growth_rate] || :Medium
@gender_ratio = hash[:gender_ratio] || :Female50Percent
@catch_rate = hash[:catch_rate] || 255
@happiness = hash[:happiness] || 70

View File

@@ -0,0 +1,188 @@
module GameData
class GrowthRate
attr_reader :id
attr_reader :real_name
attr_reader :exp_values
attr_reader :exp_formula
DATA = {}
extend ClassMethodsSymbols
include InstanceMethods
def self.load; end
def self.save; end
# Calculates the maximum level a Pokémon can attain. This can vary during a
# game, and here is where you would make it do so. Note that this method is
# called by the Compiler, which happens before anything (e.g. Game Switches/
# Variables, the player's data) is loaded, so code in this method should
# check whether the needed variables exist before using them; if they don't,
# this method should return the maximum possible level ever.
# @return [Integer] the maximum level attainable by a Pokémon
def self.max_level
return Settings::MAXIMUM_LEVEL
end
def initialize(hash)
@id = hash[:id]
@real_name = hash[:name] || "Unnamed"
@exp_values = hash[:exp_values]
@exp_formula = hash[:exp_formula]
end
# @return [String] the translated name of this growth rate
def name
return _INTL(@real_name)
end
# @param level [Integer] a level number
# @return [Integer] the minimum Exp needed to be at the given level
def minimum_exp_for_level(level)
return ArgumentError.new("Level #{level} is invalid.") if !level || level <= 0
level = [level, GrowthRate.max_level].min
return @exp_values[level] if level < @exp_values.length
raise "No Exp formula is defined for growth rate #{name}" if !@exp_formula
return @exp_formula.call(level)
end
# @return [Integer] the maximum Exp a Pokémon with this growth rate can have
def maximum_exp
return minimum_exp_for_level(GrowthRate.max_level)
end
# @param exp1 [Integer] an Exp amount
# @param exp2 [Integer] an Exp amount
# @return [Integer] the sum of the two given Exp amounts
def add_exp(exp1, exp2)
return (exp1 + exp2).clamp(0, maximum_exp)
end
# @param exp [Integer] an Exp amount
# @return [Integer] the level of a Pokémon that has the given Exp amount
def level_from_exp(exp)
return ArgumentError.new("Exp amount #{level} is invalid.") if !exp || exp < 0
max = GrowthRate.max_level
return max if exp >= maximum_exp
for level in 1..max
return level - 1 if exp < minimum_exp_for_level(level)
end
return max
end
end
end
GameData::GrowthRate.register({
:id => :Medium, # Also known as Medium Fast
:name => _INTL("Medium"),
:exp_values => [-1,
0, 8, 27, 64, 125, 216, 343, 512, 729, 1000,
1331, 1728, 2197, 2744, 3375, 4096, 4913, 5832, 6859, 8000,
9261, 10648, 12167, 13824, 15625, 17576, 19683, 21952, 24389, 27000,
29791, 32768, 35937, 39304, 42875, 46656, 50653, 54872, 59319, 64000,
68921, 74088, 79507, 85184, 91125, 97336, 103823, 110592, 117649, 125000,
132651, 140608, 148877, 157464, 166375, 175616, 185193, 195112, 205379, 216000,
226981, 238328, 250047, 262144, 274625, 287496, 300763, 314432, 328509, 343000,
357911, 373248, 389017, 405224, 421875, 438976, 456533, 474552, 493039, 512000,
531441, 551368, 571787, 592704, 614125, 636056, 658503, 681472, 704969, 729000,
753571, 778688, 804357, 830584, 857375, 884736, 912673, 941192, 970299, 1000000],
:exp_formula => proc { |level| next level ** 3 }
})
# Erratic (600000):
# For levels 0-50: n**3 * (100 - n) / 50
# For levels 51-68: n**3 * (150 - n) / 100
# For levels 69-98: n**3 * 1.274 - (n / 150) - p(n mod 3)
# where p(x) = array(0.000, 0.008, 0.014)[x]
# For levels 99-100: n**3 * (160 - n) / 100
GameData::GrowthRate.register({
:id => :Erratic,
:name => _INTL("Erratic"),
:exp_values => [-1,
0, 15, 52, 122, 237, 406, 637, 942, 1326, 1800,
2369, 3041, 3822, 4719, 5737, 6881, 8155, 9564, 11111, 12800,
14632, 16610, 18737, 21012, 23437, 26012, 28737, 31610, 34632, 37800,
41111, 44564, 48155, 51881, 55737, 59719, 63822, 68041, 72369, 76800,
81326, 85942, 90637, 95406, 100237, 105122, 110052, 115015, 120001, 125000,
131324, 137795, 144410, 151165, 158056, 165079, 172229, 179503, 186894, 194400,
202013, 209728, 217540, 225443, 233431, 241496, 249633, 257834, 267406, 276458,
286328, 296358, 305767, 316074, 326531, 336255, 346965, 357812, 367807, 378880,
390077, 400293, 411686, 423190, 433572, 445239, 457001, 467489, 479378, 491346,
501878, 513934, 526049, 536557, 548720, 560922, 571333, 583539, 591882, 600000],
:exp_formula => proc { |level| next (level ** 4) * 3 / 500
})
# Fluctuating (1640000):
# For levels 0-15 : n**3 * (24 + ((n + 1) / 3)) / 50
# For levels 16-35: n**3 * (14 + n) / 50
# For levels 36-100: n**3 * (32 + (n / 2)) / 50
GameData::GrowthRate.register({
:id => :Fluctuating,
:name => _INTL("Fluctuating"),
:exp_values => [-1,
0, 4, 13, 32, 65, 112, 178, 276, 393, 540,
745, 967, 1230, 1591, 1957, 2457, 3046, 3732, 4526, 5440,
6482, 7666, 9003, 10506, 12187, 14060, 16140, 18439, 20974, 23760,
26811, 30146, 33780, 37731, 42017, 46656, 50653, 55969, 60505, 66560,
71677, 78533, 84277, 91998, 98415, 107069, 114205, 123863, 131766, 142500,
151222, 163105, 172697, 185807, 196322, 210739, 222231, 238036, 250562, 267840,
281456, 300293, 315059, 335544, 351520, 373744, 390991, 415050, 433631, 459620,
479600, 507617, 529063, 559209, 582187, 614566, 639146, 673863, 700115, 737280,
765275, 804997, 834809, 877201, 908905, 954084, 987754, 1035837, 1071552, 1122660,
1160499, 1214753, 1254796, 1312322, 1354652, 1415577, 1460276, 1524731, 1571884, 1640000],
:exp_formula => proc { |level|
rate = [82 - (level - 100) / 2.0, 40].max
next (level ** 4) * rate / 5000
}
})
GameData::GrowthRate.register({
:id => :Parabolic, # Also known as Medium Slow
:name => _INTL("Parabolic"),
:exp_values => [-1,
0, 9, 57, 96, 135, 179, 236, 314, 419, 560,
742, 973, 1261, 1612, 2035, 2535, 3120, 3798, 4575, 5460,
6458, 7577, 8825, 10208, 11735, 13411, 15244, 17242, 19411, 21760,
24294, 27021, 29949, 33084, 36435, 40007, 43808, 47846, 52127, 56660,
61450, 66505, 71833, 77440, 83335, 89523, 96012, 102810, 109923, 117360,
125126, 133229, 141677, 150476, 159635, 169159, 179056, 189334, 199999, 211060,
222522, 234393, 246681, 259392, 272535, 286115, 300140, 314618, 329555, 344960,
360838, 377197, 394045, 411388, 429235, 447591, 466464, 485862, 505791, 526260,
547274, 568841, 590969, 613664, 636935, 660787, 685228, 710266, 735907, 762160,
789030, 816525, 844653, 873420, 902835, 932903, 963632, 995030, 1027103, 1059860],
:exp_formula => proc { |level| next ((level ** 3) * 6 / 5) - 15 * (level ** 2) + 100 * level - 140 }
})
GameData::GrowthRate.register({
:id => :Fast,
:name => _INTL("Fast"),
:exp_values => [-1,
0, 6, 21, 51, 100, 172, 274, 409, 583, 800,
1064, 1382, 1757, 2195, 2700, 3276, 3930, 4665, 5487, 6400,
7408, 8518, 9733, 11059, 12500, 14060, 15746, 17561, 19511, 21600,
23832, 26214, 28749, 31443, 34300, 37324, 40522, 43897, 47455, 51200,
55136, 59270, 63605, 68147, 72900, 77868, 83058, 88473, 94119, 100000,
106120, 112486, 119101, 125971, 133100, 140492, 148154, 156089, 164303, 172800,
181584, 190662, 200037, 209715, 219700, 229996, 240610, 251545, 262807, 274400,
286328, 298598, 311213, 324179, 337500, 351180, 365226, 379641, 394431, 409600,
425152, 441094, 457429, 474163, 491300, 508844, 526802, 545177, 563975, 583200,
602856, 622950, 643485, 664467, 685900, 707788, 730138, 752953, 776239, 800000],
:exp_formula => proc { |level| (level ** 3) * 4 / 5 }
})
GameData::GrowthRate.register({
:id => :Slow,
:name => _INTL("Slow"),
:exp_values => [-1,
0, 10, 33, 80, 156, 270, 428, 640, 911, 1250,
1663, 2160, 2746, 3430, 4218, 5120, 6141, 7290, 8573, 10000,
11576, 13310, 15208, 17280, 19531, 21970, 24603, 27440, 30486, 33750,
37238, 40960, 44921, 49130, 53593, 58320, 63316, 68590, 74148, 80000,
86151, 92610, 99383, 106480, 113906, 121670, 129778, 138240, 147061, 156250,
165813, 175760, 186096, 196830, 207968, 219520, 231491, 243890, 256723, 270000,
283726, 297910, 312558, 327680, 343281, 359370, 375953, 393040, 410636, 428750,
447388, 466560, 486271, 506530, 527343, 548720, 570666, 593190, 616298, 640000,
664301, 689210, 714733, 740880, 767656, 795070, 823128, 851840, 881211, 911250,
941963, 973360, 1005446, 1038230, 1071718, 1105920, 1140841, 1176490, 1212873, 1250000],
:exp_formula => proc { |level| (level ** 3) * 5 / 4 }
})

View File

@@ -1,198 +0,0 @@
module PBGrowthRates
Medium = 0 # MediumFast
Erratic = 1
Fluctuating = 2
Parabolic = 3 # MediumSlow
Fast = 4
Slow = 5
def self.maxValue; return 5; end
end
module PBExperience
@PBExpTable = []
@PBExpTable[PBGrowthRates::Medium] = [
-1, 0, 8, 27, 64, 125, 216, 343, 512, 729,
1000, 1331, 1728, 2197, 2744, 3375, 4096, 4913, 5832, 6859,
8000, 9261, 10648, 12167, 13824, 15625, 17576, 19683, 21952, 24389,
27000, 29791, 32768, 35937, 39304, 42875, 46656, 50653, 54872, 59319,
64000, 68921, 74088, 79507, 85184, 91125, 97336, 103823, 110592, 117649,
125000, 132651, 140608, 148877, 157464, 166375, 175616, 185193, 195112, 205379,
216000, 226981, 238328, 250047, 262144, 274625, 287496, 300763, 314432, 328509,
343000, 357911, 373248, 389017, 405224, 421875, 438976, 456533, 474552, 493039,
512000, 531441, 551368, 571787, 592704, 614125, 636056, 658503, 681472, 704969,
729000, 753571, 778688, 804357, 830584, 857375, 884736, 912673, 941192, 970299,
1000000]
@PBExpTable[PBGrowthRates::Erratic] = [
-1, 0, 15, 52, 122, 237, 406, 637, 942, 1326,
1800, 2369, 3041, 3822, 4719, 5737, 6881, 8155, 9564, 11111,
12800, 14632, 16610, 18737, 21012, 23437, 26012, 28737, 31610, 34632,
37800, 41111, 44564, 48155, 51881, 55737, 59719, 63822, 68041, 72369,
76800, 81326, 85942, 90637, 95406, 100237, 105122, 110052, 115015, 120001,
125000, 131324, 137795, 144410, 151165, 158056, 165079, 172229, 179503, 186894,
194400, 202013, 209728, 217540, 225443, 233431, 241496, 249633, 257834, 267406,
276458, 286328, 296358, 305767, 316074, 326531, 336255, 346965, 357812, 367807,
378880, 390077, 400293, 411686, 423190, 433572, 445239, 457001, 467489, 479378,
491346, 501878, 513934, 526049, 536557, 548720, 560922, 571333, 583539, 591882,
600000]
@PBExpTable[PBGrowthRates::Fluctuating] = [
-1, 0, 4, 13, 32, 65, 112, 178, 276, 393,
540, 745, 967, 1230, 1591, 1957, 2457, 3046, 3732, 4526,
5440, 6482, 7666, 9003, 10506, 12187, 14060, 16140, 18439, 20974,
23760, 26811, 30146, 33780, 37731, 42017, 46656, 50653, 55969, 60505,
66560, 71677, 78533, 84277, 91998, 98415, 107069, 114205, 123863, 131766,
142500, 151222, 163105, 172697, 185807, 196322, 210739, 222231, 238036, 250562,
267840, 281456, 300293, 315059, 335544, 351520, 373744, 390991, 415050, 433631,
459620, 479600, 507617, 529063, 559209, 582187, 614566, 639146, 673863, 700115,
737280, 765275, 804997, 834809, 877201, 908905, 954084, 987754, 1035837, 1071552,
1122660, 1160499, 1214753, 1254796, 1312322, 1354652, 1415577, 1460276, 1524731, 1571884,
1640000]
@PBExpTable[PBGrowthRates::Parabolic] = [
-1, 0, 9, 57, 96, 135, 179, 236, 314, 419,
560, 742, 973, 1261, 1612, 2035, 2535, 3120, 3798, 4575,
5460, 6458, 7577, 8825, 10208, 11735, 13411, 15244, 17242, 19411,
21760, 24294, 27021, 29949, 33084, 36435, 40007, 43808, 47846, 52127,
56660, 61450, 66505, 71833, 77440, 83335, 89523, 96012, 102810, 109923,
117360, 125126, 133229, 141677, 150476, 159635, 169159, 179056, 189334, 199999,
211060, 222522, 234393, 246681, 259392, 272535, 286115, 300140, 314618, 329555,
344960, 360838, 377197, 394045, 411388, 429235, 447591, 466464, 485862, 505791,
526260, 547274, 568841, 590969, 613664, 636935, 660787, 685228, 710266, 735907,
762160, 789030, 816525, 844653, 873420, 902835, 932903, 963632, 995030, 1027103,
1059860]
@PBExpTable[PBGrowthRates::Fast] = [
-1, 0, 6, 21, 51, 100, 172, 274, 409, 583,
800, 1064, 1382, 1757, 2195, 2700, 3276, 3930, 4665, 5487,
6400, 7408, 8518, 9733, 11059, 12500, 14060, 15746, 17561, 19511,
21600, 23832, 26214, 28749, 31443, 34300, 37324, 40522, 43897, 47455,
51200, 55136, 59270, 63605, 68147, 72900, 77868, 83058, 88473, 94119,
100000, 106120, 112486, 119101, 125971, 133100, 140492, 148154, 156089, 164303,
172800, 181584, 190662, 200037, 209715, 219700, 229996, 240610, 251545, 262807,
274400, 286328, 298598, 311213, 324179, 337500, 351180, 365226, 379641, 394431,
409600, 425152, 441094, 457429, 474163, 491300, 508844, 526802, 545177, 563975,
583200, 602856, 622950, 643485, 664467, 685900, 707788, 730138, 752953, 776239,
800000]
@PBExpTable[PBGrowthRates::Slow] = [
-1, 0, 10, 33, 80, 156, 270, 428, 640, 911,
1250, 1663, 2160, 2746, 3430, 4218, 5120, 6141, 7290, 8573,
10000, 11576, 13310, 15208, 17280, 19531, 21970, 24603, 27440, 30486,
33750, 37238, 40960, 44921, 49130, 53593, 58320, 63316, 68590, 74148,
80000, 86151, 92610, 99383, 106480, 113906, 121670, 129778, 138240, 147061,
156250, 165813, 175760, 186096, 196830, 207968, 219520, 231491, 243890, 256723,
270000, 283726, 297910, 312558, 327680, 343281, 359370, 375953, 393040, 410636,
428750, 447388, 466560, 486271, 506530, 527343, 548720, 570666, 593190, 616298,
640000, 664301, 689210, 714733, 740880, 767656, 795070, 823128, 851840, 881211,
911250, 941963, 973360, 1005446, 1038230, 1071718, 1105920, 1140841, 1176490, 1212873,
1250000]
# Returns the maximum level a Pokémon can attain. If you want to make it vary,
# here's where you put your formulae. Note that this is also called by the
# Compiler, which happens before anything (e.g. Game Switches/Variables, the
# player's data) is loaded, so make sure they exist before using them, and
# make this method return the most maximum ever level if they don't.
def self.maxLevel
return Settings::MAXIMUM_LEVEL
end
# Erratic (600000):
# For levels 0-50: n**3 * (100 - n) / 50
# For levels 51-68: n**3 * (150 - n) / 100
# For levels 69-98: n**3 * 1.274 - (n / 150) - p(n mod 3)
# where p(x) = array(0.000, 0.008, 0.014)[x]
# For levels 99-100: n**3 * (160 - n) / 100
# Fluctuating (1640000):
# For levels 0-15 : n**3 * (24 + ((n + 1) / 3)) / 50
# For levels 16-35: n**3 * (14 + n) / 50
# For levels 36-100: n**3 * (32 + (n / 2)) / 50
# @param level [Integer]
# @param growth [Integer] growth rate
def self.pbGetExpInternal(level,growth)
if level <= 100
# Refer to experience table for levels 100 and less
return @PBExpTable[growth][level]
end
# Level 101+, use formulae
case growth
when PBGrowthRates::Medium # 1000000
return level ** 3
when PBGrowthRates::Erratic # 600000
# Different formula that causes 600000 EXP at level 100
return ((level ** 4) * 0.6 / 100).floor
when PBGrowthRates::Fluctuating # 1640000
# Different formula that causes 1640000 EXP at level 100
rate = 82
if level > 100
# Slow rate with increasing level
rate -= (level - 100) / 2
rate = 40 if rate < 40
end
return ((level ** 3) * (level * rate / 100) / 50.0).floor
when PBGrowthRates::Parabolic # 1059860
return ((level ** 3) * 6 / 5) - 15 * (level ** 2) + 100 * level - 140
when PBGrowthRates::Fast # 800000
return (level ** 3) * 4 / 5
when PBGrowthRates::Slow # 1250000
return (level ** 3) * 5 / 4
end
return 0
end
# Gets the maximum Exp Points possible for the given growth rate.
# @param growth [Integer] growth rate
def self.pbGetMaxExperience(growth)
if growth<0 || growth>PBGrowthRates.maxValue
return ArgumentError.new("The growth rate is invalid.")
end
return pbGetExpInternal(maxLevel,growth)
end
# Gets the number of Exp Points needed to reach the given
# level with the given growth rate.
# @param level [Integer]
# @param growth [Integer] growth rate
def self.pbGetStartExperience(level,growth)
if growth<0 || growth>PBGrowthRates.maxValue
return ArgumentError.new("The growth rate is invalid.")
end
if level<0
return ArgumentError.new("The level is invalid.")
end
mLevel = maxLevel
level = mLevel if level>mLevel
return pbGetExpInternal(level,growth)
end
# Adds experience points ensuring that the new total doesn't
# exceed the maximum Exp. Points for the given growth rate.
# @param currexp [Integer] current Exp. points
# @param expgain [Integer] Exp. points to add
# @param growth [Integer] growth rate
def self.pbAddExperience(currexp,expgain,growth)
if growth<0 || growth>PBGrowthRates.maxValue
return ArgumentError.new("The growth rate is invalid.")
end
exp = currexp+expgain
maxexp = pbGetExpInternal(maxLevel,growth)
exp = maxexp if exp>maxexp
return exp
end
# Calculates a level given the number of Exp Points and growth rate.
# @param growth [Integer] growth rate
def self.pbGetLevelFromExperience(exp,growth)
if growth<0 || growth>PBGrowthRates.maxValue
return ArgumentError.new("The growth rate is invalid.")
end
mLevel = maxLevel
maxexp = pbGetExpInternal(mLevel,growth)
exp = maxexp if exp>maxexp
for lvl in 0..mLevel
currentExp = pbGetExpInternal(lvl,growth)
return lvl if exp==currentExp
return lvl-1 if exp<currentExp
end
return mLevel
end
end

View File

@@ -110,7 +110,7 @@ class PokeBattle_Battler
disobedient = false
# Pokémon may be disobedient; calculate if it is
badgeLevel = 10 * (@battle.pbPlayer.badge_count + 1)
badgeLevel = PBExperience.maxLevel if @battle.pbPlayer.badge_count >= 8
badgeLevel = GameData::GrowthRate.max_level if @battle.pbPlayer.badge_count >= 8
if @pokemon.foreign?(@battle.pbPlayer) && @level>badgeLevel
a = ((@level+badgeLevel)*@battle.pbRandom(256)/256).floor
disobedient |= (a>=badgeLevel)

View File

@@ -91,9 +91,9 @@ class PokeBattle_Battle
def pbGainExpOne(idxParty,defeatedBattler,numPartic,expShare,expAll,showMessages=true)
pkmn = pbParty(0)[idxParty] # The Pokémon gaining EVs from defeatedBattler
growthRate = pkmn.growth_rate
growth_rate = pkmn.growth_rate
# Don't bother calculating if gainer is already at max Exp
if pkmn.exp>=PBExperience.pbGetMaxExperience(growthRate)
if pkmn.exp>=growth_rate.maximum_exp
pkmn.calcStats # To ensure new EVs still have an effect
return
end
@@ -151,7 +151,7 @@ class PokeBattle_Battle
end
exp = i if i>=0
# Make sure Exp doesn't exceed the maximum
expFinal = PBExperience.pbAddExperience(pkmn.exp,exp,growthRate)
expFinal = growth_rate.add_exp(pkmn.exp, exp)
expGained = expFinal-pkmn.exp
return if expGained<=0
# "Exp gained" message
@@ -163,7 +163,7 @@ class PokeBattle_Battle
end
end
curLevel = pkmn.level
newLevel = PBExperience.pbGetLevelFromExperience(expFinal,growthRate)
newLevel = growth_rate.level_from_exp(expFinal)
if newLevel<curLevel
debugInfo = "Levels: #{curLevel}->#{newLevel} | Exp: #{pkmn.exp}->#{expFinal} | gain: #{expGained}"
raise RuntimeError.new(
@@ -179,8 +179,8 @@ class PokeBattle_Battle
battler = pbFindBattler(idxParty)
loop do # For each level gained in turn...
# EXP Bar animation
levelMinExp = PBExperience.pbGetStartExperience(curLevel,growthRate)
levelMaxExp = PBExperience.pbGetStartExperience(curLevel+1,growthRate)
levelMinExp = growth_rate.minimum_exp_for_level(curLevel)
levelMaxExp = growth_rate.minimum_exp_for_level(curLevel + 1)
tempExp2 = (levelMaxExp<expFinal) ? levelMaxExp : expFinal
pkmn.exp = tempExp2
@scene.pbEXPBar(battler,levelMinExp,levelMaxExp,tempExp1,tempExp2)

View File

@@ -305,7 +305,7 @@ class PokemonEncounters
# Black Flute and White Flute alter the level of the wild Pokémon
if Settings::FLUTES_CHANGE_WILD_ENCOUNTER_LEVELS
if $PokemonMap.blackFluteUsed
level = [level + rand(1..4), PBExperience.maxLevel].min
level = [level + rand(1..4), GameData::GrowthRate.max_level].min
elsif $PokemonMap.whiteFluteUsed
level = [level - rand(1..4), 1].max
end

View File

@@ -20,10 +20,8 @@ Events.onWildPokemonCreate += proc { |_sender, e|
Events.onWildPokemonCreate += proc { |_sender, e|
pokemon = e[0]
if $game_map.map_id == 51
max_level = PBExperience.maxLevel
new_level = pbBalancedLevel($Trainer.party) - 4 + rand(5) # For variety
new_level = 1 if new_level < 1
new_level = max_level if new_level > max_level
new_level = new_level.clamp(1, GameData::GrowthRate.max_level)
pokemon.level = new_level
pokemon.calcStats
pokemon.resetMoves

View File

@@ -390,7 +390,7 @@ Events.onStepTaken += proc { |_sender,_e|
for i in 0...2
pkmn = $PokemonGlobal.daycare[i][0]
next if !pkmn
maxexp = PBExperience.pbGetMaxExperience(pkmn.growth_rate)
maxexp = pkmn.growth_rate.maximum_exp
next if pkmn.exp>=maxexp
oldlevel = pkmn.level
pkmn.exp += 1 # Gain Exp

View File

@@ -29,9 +29,9 @@ def pbNewTrainer(tr_type, tr_name, tr_version, save_changes = true)
species = pbChooseSpeciesList
if species
params = ChooseNumberParams.new
params.setRange(1, PBExperience.maxLevel)
params.setRange(1, GameData::GrowthRate.max_level)
params.setDefaultValue(10)
level = pbMessageChooseNumber(_INTL("Set the level for {1} (max. #{PBExperience.maxLevel}).",
level = pbMessageChooseNumber(_INTL("Set the level for {1} (max. #{params.maxNumber}).",
GameData::Species.get(species).name), params)
party.push([species, level])
break

View File

@@ -118,9 +118,7 @@ end
# Change a Pokémon's level
#===============================================================================
def pbChangeLevel(pkmn,newlevel,scene)
newlevel = 1 if newlevel<1
mLevel = PBExperience.maxLevel
newlevel = mLevel if newlevel>mLevel
newlevel = newlevel.clamp(1, GameData::GrowthRate.max_level)
if pkmn.level==newlevel
pbMessage(_INTL("{1}'s level remained unchanged.",pkmn.name))
elsif pkmn.level>newlevel

View File

@@ -776,7 +776,7 @@ ItemHandlers::UseOnPokemon.add(:SWIFTWING,proc { |item,pkmn,scene|
})
ItemHandlers::UseOnPokemon.add(:RARECANDY,proc { |item,pkmn,scene|
if pkmn.level>=PBExperience.maxLevel || pkmn.shadowPokemon?
if pkmn.level>=GameData::GrowthRate.max_level || pkmn.shadowPokemon?
scene.pbDisplay(_INTL("It won't have any effect."))
next false
end

View File

@@ -34,9 +34,9 @@ def pbPurify(pkmn, scene)
pkmn.saved_ev = nil
end
if pkmn.saved_exp
newexp = PBExperience.pbAddExperience(pkmn.exp, pkmn.saved_exp || 0, pkmn.growth_rate)
newexp = pkmn.growth_rate.add_exp(pkmn.exp, pkmn.saved_exp || 0)
pkmn.saved_exp = nil
newlevel = PBExperience.pbGetLevelFromExperience(newexp, pkmn.growth_rate)
newlevel = pkmn.growth_rate.level_from_exp(newexp)
curlevel = pkmn.level
if newexp != pkmn.exp
scene.pbDisplay(_INTL("{1} regained {2} Exp. Points!", pkmn.name, newexp - pkmn.exp))

View File

@@ -157,18 +157,18 @@ class Pokemon
# @return [Integer] this Pokémon's level
def level
@level = PBExperience.pbGetLevelFromExperience(@exp, growth_rate) if !@level
@level = growth_rate.level_from_exp(@exp) if !@level
return @level
end
# Sets this Pokémon's level. The given level must be between 1 and the
# maximum level (defined in {PBExperience}).
# maximum level (defined in {GameData::GrowthRate}).
# @param value [Integer] new level (between 1 and the maximum level)
def level=(value)
if value < 1 || value > PBExperience.maxLevel
if value < 1 || value > GameData::GrowthRate.max_level
raise ArgumentError.new(_INTL("The level number ({1}) is invalid.", value))
end
@exp = PBExperience.pbGetStartExperience(value, growth_rate)
@exp = growth_rate.minimum_exp_for_level(value)
@level = value
end
@@ -185,9 +185,9 @@ class Pokemon
end
alias isEgg? egg?
# @return [Integer] this Pokémon's growth rate (from PBGrowthRates)
# @return [GameData::GrowthRate] this Pokémon's growth rate
def growth_rate
return species_data.growth_rate
return GameData::GrowthRate.get(species_data.growth_rate)
end
# @return [Integer] this Pokémon's base Experience value
@@ -199,10 +199,10 @@ class Pokemon
# Exp this Pokémon has
def exp_fraction
lvl = self.level
return 0.0 if lvl >= PBExperience.maxLevel
return 0.0 if lvl >= GameData::GrowthRate.max_level
g_rate = growth_rate
start_exp = PBExperience.pbGetStartExperience(lvl, g_rate)
end_exp = PBExperience.pbGetStartExperience(lvl + 1, g_rate)
start_exp = g_rate.minimum_exp_for_level(lvl)
end_exp = g_rate.minimum_exp_for_level(lvl + 1)
return (@exp - start_exp).to_f / (end_exp - start_exp)
end

View File

@@ -445,7 +445,7 @@ class PokemonSummary_Scene
memo = sprintf("<c3=404040,B0B0B0>%s\n",heartmessage)
drawFormattedTextEx(overlay,234,304,264,memo)
else
endexp = PBExperience.pbGetStartExperience(@pokemon.level+1,@pokemon.growth_rate)
endexp = @pokemon.growth_rate.minimum_exp_for_level(@pokemon.level + 1)
textpos.push([_INTL("Exp. Points"),238,240,0,base,shadow])
textpos.push([@pokemon.exp.to_s_formatted,488,272,1,Color.new(64,64,64),Color.new(176,176,176)])
textpos.push([_INTL("To Next Lv."),238,304,0,base,shadow])
@@ -465,7 +465,7 @@ class PokemonSummary_Scene
overlay.blt(436,146,@typebitmap.bitmap,type2rect)
end
# Draw Exp bar
if @pokemon.level<PBExperience.maxLevel
if @pokemon.level<GameData::GrowthRate.max_level
w = @pokemon.exp_fraction * 128
w = ((w/2).round)*2
pbDrawImagePositions(overlay,[

View File

@@ -452,10 +452,10 @@ class BattleChallenge
rules.setBattleType(BattleTower.new)
end
if mode==1 # Open Level
rules.setRuleset(StandardRules(numPokemon,PBExperience.maxLevel))
rules.setRuleset(StandardRules(numPokemon,GameData::GrowthRate.max_level))
rules.setLevelAdjustment(OpenLevelAdjustment.new(30))
elsif mode==2 # Battle Tent
rules.setRuleset(StandardRules(numPokemon,PBExperience.maxLevel))
rules.setRuleset(StandardRules(numPokemon,GameData::GrowthRate.max_level))
rules.setLevelAdjustment(OpenLevelAdjustment.new(60))
else
rules.setRuleset(StandardRules(numPokemon,50))

View File

@@ -128,7 +128,7 @@ end
class EnemyLevelAdjustment < LevelAdjustment
def initialize(level)
super(LevelAdjustment::EnemyTeam)
@level=[[1,level].max,PBExperience.maxLevel].min
@level = level.clamp(1, GameData::GrowthRate.max_level)
end
def getAdjustment(thisTeam,_otherTeam)
@@ -173,7 +173,7 @@ end
class CappedLevelAdjustment < LevelAdjustment
def initialize(level)
super(LevelAdjustment::BothTeams)
@level=[[1,level].max,PBExperience.maxLevel].min
@level = level.clamp(1, GameData::GrowthRate.max_level)
end
def getAdjustment(thisTeam,_otherTeam)
@@ -190,7 +190,7 @@ end
class FixedLevelAdjustment < LevelAdjustment
def initialize(level)
super(LevelAdjustment::BothTeams)
@level=[[1,level].max,PBExperience.maxLevel].min
@level = level.clamp(1, GameData::GrowthRate.max_level)
end
def getAdjustment(thisTeam,_otherTeam)
@@ -207,9 +207,8 @@ end
class TotalLevelAdjustment < LevelAdjustment
def initialize(minLevel,maxLevel,totalLevel)
super(LevelAdjustment::EnemyTeam)
mLevel = PBExperience.maxLevel
@minLevel=[[1,minLevel].max,mLevel].min
@maxLevel=[[1,maxLevel].max,mLevel].min
@minLevel = minLevel.clamp(1, GameData::GrowthRate.max_level)
@maxLevel = maxLevel.clamp(1, GameData::GrowthRate.max_level)
@totalLevel=totalLevel
end
@@ -707,7 +706,7 @@ class PokemonRuleSet
# Returns a valid level to assign to each member of a valid Pokemon team.
def suggestedLevel
minLevel=1
maxLevel=PBExperience.maxLevel
maxLevel=GameData::GrowthRate.max_level
num=self.suggestedNumber
for rule in @pokemonRules
if rule.is_a?(MinimumLevelRestriction)
@@ -1271,7 +1270,7 @@ end
def pbPrimeCupRules(double)
ret=PokemonChallengeRules.new
ret.setLevelAdjustment(OpenLevelAdjustment.new(PBExperience.maxLevel))
ret.setLevelAdjustment(OpenLevelAdjustment.new(GameData::GrowthRate.max_level))
ret.addTeamRule(SpeciesClause.new)
ret.addTeamRule(ItemClause.new)
ret.addBattleRule(SleepClause.new)

View File

@@ -210,7 +210,7 @@ def pbBalancedLevel(party)
sum = 0
party.each { |p| sum += p.level }
return 1 if sum == 0
mLevel = PBExperience.maxLevel
mLevel = GameData::GrowthRate.max_level
average = sum.to_f / party.length.to_f
# Calculate the standard deviation
varianceTimesN = 0

View File

@@ -195,7 +195,7 @@ DebugMenuCommands.register("testwildbattle", {
species = pbChooseSpeciesList
if species
params = ChooseNumberParams.new
params.setRange(1, PBExperience.maxLevel)
params.setRange(1, GameData::GrowthRate.max_level)
params.setInitialValue(5)
params.setCancelValue(0)
level = pbMessageChooseNumber(_INTL("Set the wild {1}'s level.",
@@ -251,7 +251,7 @@ DebugMenuCommands.register("testwildbattleadvanced", {
species = pbChooseSpeciesList
if species
params = ChooseNumberParams.new
params.setRange(1, PBExperience.maxLevel)
params.setRange(1, GameData::GrowthRate.max_level)
params.setInitialValue(5)
params.setCancelValue(0)
level = pbMessageChooseNumber(_INTL("Set the wild {1}'s level.",
@@ -508,7 +508,7 @@ DebugMenuCommands.register("addpokemon", {
species = pbChooseSpeciesList
if species
params = ChooseNumberParams.new
params.setRange(1, PBExperience.maxLevel)
params.setRange(1, GameData::GrowthRate.max_level)
params.setInitialValue(5)
params.setCancelValue(0)
level = pbMessageChooseNumber(_INTL("Set the Pokémon's level."), params)

View File

@@ -252,7 +252,7 @@ def pbDebugDayCare
textpos.push([_INTL("Genderless"),8+i*Graphics.width/2,y,0,base,shadow])
end
y += 32
if initlevel>=PBExperience.maxLevel
if initlevel>=GameData::GrowthRate.max_level
textpos.push(["Lv. #{initlevel} (max)",8+i*Graphics.width/2,y,0,base,shadow])
elsif leveldiff>0
textpos.push(["Lv. #{initlevel} -> #{pkmn.level} (+#{leveldiff})",
@@ -261,8 +261,8 @@ def pbDebugDayCare
textpos.push(["Lv. #{initlevel} (no change)",8+i*Graphics.width/2,y,0,base,shadow])
end
y += 32
if pkmn.level<PBExperience.maxLevel
endexp = PBExperience.pbGetStartExperience(pkmn.level+1,pkmn.growth_rate)
if pkmn.level<GameData::GrowthRate.max_level
endexp = pkmn.growth_rate.minimum_exp_for_level(pkmn.level + 1)
textpos.push(["To next Lv.: #{endexp-pkmn.exp}",8+i*Graphics.width/2,y,0,base,shadow])
y += 32
end

View File

@@ -196,12 +196,11 @@ PokemonDebugMenuCommands.register("setlevel", {
if pkmn.egg?
screen.pbDisplay(_INTL("{1} is an egg.", pkmn.name))
else
mLevel = PBExperience.maxLevel
params = ChooseNumberParams.new
params.setRange(1, mLevel)
params.setRange(1, GameData::GrowthRate.max_level)
params.setDefaultValue(pkmn.level)
level = pbMessageChooseNumber(
_INTL("Set the Pokémon's level (max. {1}).", mLevel), params) { screen.pbUpdate }
_INTL("Set the Pokémon's level (max. {1}).", params.maxNumber), params) { screen.pbUpdate }
if level != pkmn.level
pkmn.level = level
pkmn.calcStats
@@ -219,8 +218,8 @@ PokemonDebugMenuCommands.register("setexp", {
if pkmn.egg?
screen.pbDisplay(_INTL("{1} is an egg.", pkmn.name))
else
minxp = PBExperience.pbGetStartExperience(pkmn.level, pkmn.growth_rate)
maxxp = PBExperience.pbGetStartExperience(pkmn.level + 1, pkmn.growth_rate)
minxp = pkmn.growth_rate.minimum_exp_for_level(pkmn.level)
maxxp = pkmn.growth_rate.minimum_exp_for_level(pkmn.level + 1)
if minxp == maxxp
screen.pbDisplay(_INTL("{1} is at the maximum level.", pkmn.name))
else

View File

@@ -650,7 +650,7 @@ module TrainerPokemonProperty
initsetting[:happiness],
initsetting[:poke_ball]
])
max_level = PBExperience.maxLevel
max_level = GameData::GrowthRate.max_level
pkmn_properties = [
[_INTL("Species"), SpeciesProperty, _INTL("Species of the Pokémon.")],
[_INTL("Level"), NonzeroLimitProperty.new(max_level), _INTL("Level of the Pokémon (1-{1}).", max_level)],
@@ -956,7 +956,7 @@ def pbPokemonEditor
[_INTL("BaseStats"), BaseStatsProperty, _INTL("Base stats of the Pokémon.")],
[_INTL("EffortPoints"), EffortValuesProperty, _INTL("Effort Value points earned when this species is defeated.")],
[_INTL("BaseEXP"), LimitProperty.new(9999), _INTL("Base experience earned when this species is defeated.")],
[_INTL("GrowthRate"), EnumProperty2.new(PBGrowthRates), _INTL("Pokémon's growth rate.")],
[_INTL("GrowthRate"), GameDataProperty.new(:GrowthRate), _INTL("Pokémon's growth rate.")],
[_INTL("GenderRate"), GameDataProperty.new(:GenderRatio), _INTL("Proportion of males to females for this species.")],
[_INTL("Rareness"), LimitProperty.new(255), _INTL("Catch rate of this species (0-255).")],
[_INTL("Happiness"), LimitProperty.new(255), _INTL("Base happiness of this species (0-255).")],

View File

@@ -945,7 +945,7 @@ module MovePoolProperty
entry = realcmds[cmd[1]]
if entry[0] == -1 # Add new move
params = ChooseNumberParams.new
params.setRange(0, PBExperience.maxLevel)
params.setRange(0, GameData::GrowthRate.max_level)
params.setDefaultValue(1)
params.setCancelValue(-1)
newlevel = pbMessageChooseNumber(_INTL("Choose a level."),params)
@@ -971,7 +971,7 @@ module MovePoolProperty
[_INTL("Change level"), _INTL("Change move"), _INTL("Delete"), _INTL("Cancel")], 4)
when 0 # Change level
params = ChooseNumberParams.new
params.setRange(0, PBExperience.maxLevel)
params.setRange(0, GameData::GrowthRate.max_level)
params.setDefaultValue(entry[0])
newlevel = pbMessageChooseNumber(_INTL("Choose a new level."), params)
if newlevel >= 0 && newlevel != entry[0]
@@ -1405,7 +1405,7 @@ end
module EncounterSlotProperty
def self.set(setting_name, data)
max_level = PBExperience.maxLevel
max_level = GameData::GrowthRate.max_level
if !data
data = [20, nil, 5, 5]
GameData::Species.each do |species_data|

View File

@@ -869,7 +869,7 @@ module Compiler
probabilities = nil
current_type = -1
expected_lines = 0
max_level = PBExperience.maxLevel
max_level = GameData::GrowthRate.max_level
pbCompilerEachPreppedLine("PBS/encounters.txt") { |line, line_no|
next if line.length == 0
if expected_lines > 0 && line[/^\d+,/] && new_format # Species line
@@ -1102,7 +1102,7 @@ module Compiler
#=============================================================================
def compile_trainers
schema = GameData::Trainer::SCHEMA
max_level = PBExperience.maxLevel
max_level = GameData::GrowthRate.max_level
trainer_names = []
trainer_lose_texts = []
trainer_hash = nil

View File

@@ -274,7 +274,7 @@ module Compiler
f.write(sprintf("Type2 = %s\r\n", species.type2)) if species.type2 != species.type1
f.write(sprintf("BaseStats = %s\r\n", species.base_stats.join(",")))
f.write(sprintf("GenderRate = %s\r\n", species.gender_ratio))
f.write(sprintf("GrowthRate = %s\r\n", getConstantName(PBGrowthRates, species.growth_rate)))
f.write(sprintf("GrowthRate = %s\r\n", species.growth_rate))
f.write(sprintf("BaseEXP = %d\r\n", species.base_exp))
f.write(sprintf("EffortPoints = %s\r\n", species.evs.join(",")))
f.write(sprintf("Rareness = %d\r\n", species.catch_rate))