From fe9e24332083cb5f1151fcb7f8aced1326a807e9 Mon Sep 17 00:00:00 2001 From: sickoe Date: Thu, 21 Jul 2016 11:58:05 +0800 Subject: [PATCH] Trainer pokemon level modifier --- src/com/dabomstew/pkrandom/Randomizer.java | 2 +- src/com/dabomstew/pkrandom/Settings.java | 32 ++++++++- .../dabomstew/pkrandom/gui/Bundle.properties | 3 + .../dabomstew/pkrandom/gui/RandomizerGUI.form | 30 +++++++++ .../dabomstew/pkrandom/gui/RandomizerGUI.java | 67 +++++++++++++++++-- .../romhandlers/AbstractRomHandler.java | 3 +- .../pkrandom/romhandlers/RomHandler.java | 2 +- 7 files changed, 129 insertions(+), 10 deletions(-) diff --git a/src/com/dabomstew/pkrandom/Randomizer.java b/src/com/dabomstew/pkrandom/Randomizer.java index 6775c4739..c7d395ed3 100644 --- a/src/com/dabomstew/pkrandom/Randomizer.java +++ b/src/com/dabomstew/pkrandom/Randomizer.java @@ -290,7 +290,7 @@ public int randomize(final String filename, final PrintStream log, long seed) { // Trainer Pokemon if (settings.getTrainersMod() == Settings.TrainersMod.RANDOM) { romHandler.randomizeTrainerPokes(settings.isTrainersUsePokemonOfSimilarStrength(), - settings.isTrainersBlockLegendaries(), settings.isTrainersBlockEarlyWonderGuard()); + settings.isTrainersBlockLegendaries(), settings.isTrainersBlockEarlyWonderGuard(),settings.isTrainersLevelModified() ? settings.getTrainersLevelModifier() : 0); } else if (settings.getTrainersMod() == Settings.TrainersMod.TYPE_THEMED) { romHandler.typeThemeTrainerPokes(settings.isTrainersUsePokemonOfSimilarStrength(), settings.isTrainersMatchTypingDistribution(), settings.isTrainersBlockLegendaries(), diff --git a/src/com/dabomstew/pkrandom/Settings.java b/src/com/dabomstew/pkrandom/Settings.java index e34e37400..c9ec0454d 100644 --- a/src/com/dabomstew/pkrandom/Settings.java +++ b/src/com/dabomstew/pkrandom/Settings.java @@ -48,7 +48,7 @@ public class Settings { public static final int VERSION = 172; - public static final int LENGTH_OF_SETTINGS_DATA = 35; + public static final int LENGTH_OF_SETTINGS_DATA = 36; private CustomNamesSet customNames; @@ -144,7 +144,10 @@ public enum TrainersMod { private boolean randomizeTrainerClassNames; private boolean trainersForceFullyEvolved; private int trainersForceFullyEvolvedLevel = 30; - + private boolean trainersLevelModified; + private int trainersLevelModifier = 0; + + public enum WildPokemonMod { UNCHANGED, RANDOM, AREA_MAPPING, GLOBAL_MAPPING } @@ -378,6 +381,9 @@ public String toString() { } catch (IOException e) { } + + // @ 35 trainer pokemon level modifier + out.write((trainersLevelModified ? 0x80 : 0) | trainersLevelModifier); try { byte[] romName = this.romName.getBytes("US-ASCII"); @@ -388,6 +394,8 @@ public String toString() { } catch (IOException e) { out.write(0); } + + byte[] current = out.toByteArray(); CRC32 checksum = new CRC32(); @@ -571,6 +579,9 @@ public static Settings fromString(String settingsString) throws UnsupportedEncod int codeTweaks = FileFunctions.readFullInt(data, 31); settings.setCurrentMiscTweaks(codeTweaks); + + settings.setTrainersLevelModified(restoreState(data[35], 7)); + settings.setTrainersLevelModifier(data[35] & 0x7F); int romNameLength = data[LENGTH_OF_SETTINGS_DATA] & 0xFF; String romName = new String(data, LENGTH_OF_SETTINGS_DATA + 1, romNameLength, "US-ASCII"); @@ -1186,6 +1197,23 @@ public Settings setTrainersForceFullyEvolvedLevel(int trainersForceFullyEvolvedL this.trainersForceFullyEvolvedLevel = trainersForceFullyEvolvedLevel; return this; } + public boolean isTrainersLevelModified() { + return trainersLevelModified; + } + + public Settings setTrainersLevelModified(boolean trainersLevelModified) { + this.trainersLevelModified = trainersLevelModified; + return this; + } + + public int getTrainersLevelModifier() { + return trainersLevelModifier; + } + + public Settings setTrainersLevelModifier(int trainersLevelModifier) { + this.trainersLevelModifier = trainersLevelModifier; + return this; + } public WildPokemonMod getWildPokemonMod() { return wildPokemonMod; diff --git a/src/com/dabomstew/pkrandom/gui/Bundle.properties b/src/com/dabomstew/pkrandom/gui/Bundle.properties index 59581ab7c..c740c6471 100755 --- a/src/com/dabomstew/pkrandom/gui/Bundle.properties +++ b/src/com/dabomstew/pkrandom/gui/Bundle.properties @@ -393,6 +393,9 @@ RandomizerGUI.tpForceFullyEvolvedCB.text=Force Fully Evolved at Level: RandomizerGUI.tpForceFullyEvolvedCB.toolTipText=Checking this will force all trainer Pokemon at or above the level you select below to be fully evolved regardless of other settings.
Pokemon below the selected level will be randomly picked like normal. RandomizerGUI.wpCatchRateSlider.toolTipText=If Minimum Catch Rate is selected, allows you to set the level used.\n
Level 1: "Normal" minimum catch rate from old versions (normal Pokemon 30% at low HP, legendaries 15%)\n
Level 2: "Buffed" minimum catch rate (normal Pokemon 50% at low HP, legendaries 25%)\n
Level 3: "Super" minimum catch rate (normal Pokemon 80% at low HP, legendaries 40%)\n
Level 4: "Maximum" minimum catch rate (everything 255 catch rate, the highest available without changing game code) RandomizerGUI.tpForceFullyEvolvedSlider.toolTipText=Use this slider to select the minimum level to force fully evolved Pokemon at if said option is checked above. +RandomizerGUI.tpLevelModifierCB.text=Level Modifier +RandomizerGUI.tpLevelModifierCB.toolTipText=Modify trainer pokemon's level +RandomizerGUI.tpLevelModifierSlider.toolTipText=Use this slider to select the modifier for trainer pokemon's level RandomizerGUI.pmsReorderDamagingMovesCB.text=Reorder Damaging Moves RandomizerGUI.pmsReorderDamagingMovesCB.toolTipText=Reorders the randomized movesets so that less powerful damaging moves are learnt before those with high power.\n
The positions of non-damaging moves will not change. RandomizerGUI.pmsForceGoodDamagingCB.text=Force % of Good Damaging Moves diff --git a/src/com/dabomstew/pkrandom/gui/RandomizerGUI.form b/src/com/dabomstew/pkrandom/gui/RandomizerGUI.form index bc4245908..1b54a9ad3 100755 --- a/src/com/dabomstew/pkrandom/gui/RandomizerGUI.form +++ b/src/com/dabomstew/pkrandom/gui/RandomizerGUI.form @@ -1931,6 +1931,8 @@ + + @@ -1957,6 +1959,7 @@ + @@ -2120,6 +2123,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/dabomstew/pkrandom/gui/RandomizerGUI.java b/src/com/dabomstew/pkrandom/gui/RandomizerGUI.java index 6c0080598..ffc81957b 100755 --- a/src/com/dabomstew/pkrandom/gui/RandomizerGUI.java +++ b/src/com/dabomstew/pkrandom/gui/RandomizerGUI.java @@ -795,6 +795,9 @@ private void initialFormState() { this.tpUnchangedRB.setEnabled(false); this.tpForceFullyEvolvedCB.setEnabled(false); this.tpForceFullyEvolvedSlider.setEnabled(false); + this.tpLevelModifierCB.setEnabled(false); + this.tpLevelModifierSlider.setEnabled(false); + this.tpUnchangedRB.setSelected(true); this.tpPowerLevelsCB.setSelected(false); this.tpRivalCarriesStarterCB.setSelected(false); @@ -803,6 +806,8 @@ private void initialFormState() { this.tpNoEarlyShedinjaCB.setSelected(false); this.tpForceFullyEvolvedCB.setSelected(false); this.tpForceFullyEvolvedSlider.setValue(this.tpForceFullyEvolvedSlider.getMinimum()); + this.tpLevelModifierCB.setSelected(false); + this.tpLevelModifierSlider.setValue(0); this.tnRandomizeCB.setEnabled(false); this.tcnRandomizeCB.setEnabled(false); @@ -1345,11 +1350,14 @@ private void enableOrDisableSubControls() { this.tpNoEarlyShedinjaCB.setSelected(false); this.tpForceFullyEvolvedCB.setEnabled(false); this.tpForceFullyEvolvedCB.setSelected(false); + this.tpLevelModifierCB.setEnabled(false); + this.tpLevelModifierCB.setSelected(false); } else { this.tpPowerLevelsCB.setEnabled(true); this.tpNoLegendariesCB.setEnabled(true); this.tpNoEarlyShedinjaCB.setEnabled(true); this.tpForceFullyEvolvedCB.setEnabled(true); + this.tpLevelModifierCB.setEnabled(true); } if (this.tpForceFullyEvolvedCB.isSelected()) { @@ -1358,6 +1366,13 @@ private void enableOrDisableSubControls() { this.tpForceFullyEvolvedSlider.setEnabled(false); this.tpForceFullyEvolvedSlider.setValue(this.tpForceFullyEvolvedSlider.getMinimum()); } + + if (this.tpLevelModifierCB.isSelected()) { + this.tpLevelModifierSlider.setEnabled(true); + } else { + this.tpLevelModifierSlider.setEnabled(false); + this.tpLevelModifierSlider.setValue(0); + } if (!this.spUnchangedRB.isSelected() || !this.tpUnchangedRB.isSelected()) { this.tpRivalCarriesStarterCB.setEnabled(true); @@ -1692,6 +1707,8 @@ private void restoreStateFromSettings(Settings settings) { this.tpNoEarlyShedinjaCB.setSelected(settings.isTrainersBlockEarlyWonderGuard()); this.tpForceFullyEvolvedCB.setSelected(settings.isTrainersForceFullyEvolved()); this.tpForceFullyEvolvedSlider.setValue(settings.getTrainersForceFullyEvolvedLevel()); + this.tpLevelModifierCB.setSelected(settings.isTrainersLevelModified()); + this.tpLevelModifierSlider.setValue(settings.getTrainersLevelModifier()); this.wpARCatchEmAllRB .setSelected(settings.getWildPokemonRestrictionMod() == Settings.WildPokemonRestrictionMod.CATCH_EM_ALL); @@ -1844,6 +1861,8 @@ private Settings createSettingsFromState(CustomNamesSet customNames) { settings.setTrainersBlockEarlyWonderGuard(tpNoEarlyShedinjaCB.isSelected()); settings.setTrainersForceFullyEvolved(tpForceFullyEvolvedCB.isSelected()); settings.setTrainersForceFullyEvolvedLevel(tpForceFullyEvolvedSlider.getValue()); + settings.setTrainersLevelModified(tpLevelModifierCB.isSelected()); + settings.setTrainersLevelModifier(tpLevelModifierSlider.getValue()); settings.setWildPokemonMod(wpUnchangedRB.isSelected(), wpRandomRB.isSelected(), wpArea11RB.isSelected(), wpGlobalRB.isSelected()); @@ -2477,6 +2496,9 @@ private void pbsChangesRandomRBActionPerformed(java.awt.event.ActionEvent evt) { private void tpForceFullyEvolvedCBActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_tpForceFullyEvolvedCBActionPerformed this.enableOrDisableSubControls(); }// GEN-LAST:event_tpForceFullyEvolvedCBActionPerformed + private void tpLevelModifierCBActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_tpForceFullyEvolvedCBActionPerformed + this.enableOrDisableSubControls(); + } private void wpCatchRateCBActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_wpCatchRateCBActionPerformed this.enableOrDisableSubControls(); @@ -2654,6 +2676,8 @@ public void approveSelection() { tpNoEarlyShedinjaCB = new javax.swing.JCheckBox(); tpForceFullyEvolvedCB = new javax.swing.JCheckBox(); tpForceFullyEvolvedSlider = new javax.swing.JSlider(); + tpLevelModifierCB = new javax.swing.JCheckBox(); + tpLevelModifierSlider = new javax.swing.JSlider(); wildsInnerPanel = new javax.swing.JPanel(); wildPokemonPanel = new javax.swing.JPanel(); wpUnchangedRB = new javax.swing.JRadioButton(); @@ -3716,6 +3740,23 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { tpForceFullyEvolvedSlider.setPaintTicks(true); tpForceFullyEvolvedSlider.setToolTipText(bundle.getString("RandomizerGUI.tpForceFullyEvolvedSlider.toolTipText")); // NOI18N tpForceFullyEvolvedSlider.setValue(30); + + tpLevelModifierCB.setText(bundle.getString("RandomizerGUI.tpLevelModifierCB.text")); // NOI18N + tpLevelModifierCB.setToolTipText(bundle.getString("RandomizerGUI.tpLevelModifierCB.toolTipText")); // NOI18N + tpLevelModifierCB.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + tpLevelModifierCBActionPerformed(evt); + } + }); + + tpLevelModifierSlider.setMajorTickSpacing(10); + tpLevelModifierSlider.setMaximum(50); + tpLevelModifierSlider.setMinimum(-50); + tpLevelModifierSlider.setMinorTickSpacing(5); + tpLevelModifierSlider.setPaintLabels(true); + tpLevelModifierSlider.setPaintTicks(true); + tpLevelModifierSlider.setToolTipText(bundle.getString("RandomizerGUI.tpLevelModifierSlider.toolTipText")); // NOI18N + tpLevelModifierSlider.setValue(0); javax.swing.GroupLayout trainersPokemonPanelLayout = new javax.swing.GroupLayout(trainersPokemonPanel); trainersPokemonPanel.setLayout(trainersPokemonPanelLayout); @@ -3742,7 +3783,12 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(tnRandomizeCB) .addComponent(tcnRandomizeCB) .addComponent(tpForceFullyEvolvedCB) - .addComponent(tpForceFullyEvolvedSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) + .addComponent(tpForceFullyEvolvedSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(18, 18, 18) + .addGroup(trainersPokemonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(tpLevelModifierCB) + .addComponent(tpLevelModifierSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + )) .addContainerGap(143, Short.MAX_VALUE)) ); trainersPokemonPanelLayout.setVerticalGroup( @@ -3751,24 +3797,32 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(trainersPokemonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(tpUnchangedRB) .addComponent(tpRivalCarriesStarterCB) - .addComponent(tnRandomizeCB)) + .addComponent(tnRandomizeCB) + .addComponent(tpLevelModifierCB) + ) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(trainersPokemonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(tpRandomRB) .addComponent(tpPowerLevelsCB) - .addComponent(tcnRandomizeCB)) + .addComponent(tcnRandomizeCB) + .addComponent(tpLevelModifierSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + ) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(trainersPokemonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(tpTypeThemedRB) .addComponent(tpTypeWeightingCB) - .addComponent(tpForceFullyEvolvedCB)) + .addComponent(tpForceFullyEvolvedCB) + ) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(trainersPokemonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(trainersPokemonPanelLayout.createSequentialGroup() .addComponent(tpNoLegendariesCB) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(tpNoEarlyShedinjaCB)) - .addComponent(tpForceFullyEvolvedSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(tpForceFullyEvolvedSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + + ) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); @@ -4726,6 +4780,9 @@ public void mouseClicked(java.awt.event.MouseEvent evt) { private javax.swing.JMenuItem toggleScrollPaneMenuItem; private javax.swing.JCheckBox tpForceFullyEvolvedCB; private javax.swing.JSlider tpForceFullyEvolvedSlider; + private javax.swing.JCheckBox tpLevelModifierCB; + private javax.swing.JSlider tpLevelModifierSlider; + private javax.swing.JCheckBox tpNoEarlyShedinjaCB; private javax.swing.JCheckBox tpNoLegendariesCB; private javax.swing.JCheckBox tpPowerLevelsCB; diff --git a/src/com/dabomstew/pkrandom/romhandlers/AbstractRomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/AbstractRomHandler.java index 5e74f330f..2d1339bfb 100755 --- a/src/com/dabomstew/pkrandom/romhandlers/AbstractRomHandler.java +++ b/src/com/dabomstew/pkrandom/romhandlers/AbstractRomHandler.java @@ -909,7 +909,7 @@ public void game1to1Encounters(boolean useTimeOfDay, boolean usePowerLevels, boo } @Override - public void randomizeTrainerPokes(boolean usePowerLevels, boolean noLegendaries, boolean noEarlyWonderGuard) { + public void randomizeTrainerPokes(boolean usePowerLevels, boolean noLegendaries, boolean noEarlyWonderGuard,int levelModifier) { checkPokemonRestrictions(); List currentTrainers = this.getTrainers(); @@ -933,6 +933,7 @@ public void randomizeTrainerPokes(boolean usePowerLevels, boolean noLegendaries, boolean wgAllowed = (!noEarlyWonderGuard) || tp.level >= 20; tp.pokemon = pickReplacement(tp.pokemon, usePowerLevels, null, noLegendaries, wgAllowed); tp.resetMoves = true; + tp.level = Math.min(100 , (int)(tp.level * (1 + levelModifier/ 100f))); } } diff --git a/src/com/dabomstew/pkrandom/romhandlers/RomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/RomHandler.java index 9340310f9..f9889784e 100755 --- a/src/com/dabomstew/pkrandom/romhandlers/RomHandler.java +++ b/src/com/dabomstew/pkrandom/romhandlers/RomHandler.java @@ -162,7 +162,7 @@ public void area1to1Encounters(boolean useTimeOfDay, boolean catchEmAll, boolean public void setTrainers(List trainerData); - public void randomizeTrainerPokes(boolean usePowerLevels, boolean noLegendaries, boolean noEarlyWonderGuard); + public void randomizeTrainerPokes(boolean usePowerLevels, boolean noLegendaries, boolean noEarlyWonderGuard,int levelModifier); public void typeThemeTrainerPokes(boolean usePowerLevels, boolean weightByFrequency, boolean noLegendaries, boolean noEarlyWonderGuard);