Skip to content

Commit

Permalink
Merge pull request #310 from lushen124/feature/0170-min-max-crit-control
Browse files Browse the repository at this point in the history
[Feature #170] Critical Ranges for High Critical weapon trait
  • Loading branch information
lushen124 committed Nov 1, 2020
2 parents 6a765ba + 9a777c3 commit 5f26435
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 17 deletions.
4 changes: 3 additions & 1 deletion Universal FE Randomizer/src/fedata/gba/fe6/FE6Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import random.gba.loader.ItemDataLoader;
import random.gba.loader.TextLoader;
import random.gba.loader.ItemDataLoader.AdditionalData;
import ui.model.MinMaxOption;
import util.ByteArrayBuilder;
import util.DebugPrinter;
import util.FreeSpaceManager;
Expand Down Expand Up @@ -379,8 +380,9 @@ private void applyEffect(WeaponEffects effect, ItemDataLoader itemData, GBAFESpe
setEffectivenessPointer(selectedEffectivenessAddress);
break;
case HIGH_CRITICAL:
MinMaxOption range = (MinMaxOption)effect.additionalInfo.get(WeaponEffects.InfoKeys.CRITICAL_RANGE);
int currentCritical = getCritical();
int newCritical = currentCritical + 5 * (4 + rng.nextInt(7));
int newCritical = currentCritical + 5 * ((range.minValue / 5) + rng.nextInt(((range.maxValue - range.minValue) / 5) + 1));
setCritical(newCritical);
break;
case EXTEND_RANGE:
Expand Down
4 changes: 3 additions & 1 deletion Universal FE Randomizer/src/fedata/gba/fe7/FE7Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import random.gba.loader.ItemDataLoader;
import random.gba.loader.TextLoader;
import random.gba.loader.ItemDataLoader.AdditionalData;
import ui.model.MinMaxOption;
import util.ByteArrayBuilder;
import util.DebugPrinter;
import util.FreeSpaceManager;
Expand Down Expand Up @@ -388,8 +389,9 @@ private void applyEffect(WeaponEffects effect, ItemDataLoader itemData, GBAFESpe
setEffectivenessPointer(selectedEffectivenessAddress);
break;
case HIGH_CRITICAL:
MinMaxOption range = (MinMaxOption)effect.additionalInfo.get(WeaponEffects.InfoKeys.CRITICAL_RANGE);
int currentCritical = getCritical();
int newCritical = currentCritical + 5 * (4 + rng.nextInt(7));
int newCritical = currentCritical + 5 * ((range.minValue / 5) + rng.nextInt(((range.maxValue - range.minValue) / 5) + 1));
setCritical(newCritical);
break;
case EXTEND_RANGE:
Expand Down
4 changes: 3 additions & 1 deletion Universal FE Randomizer/src/fedata/gba/fe8/FE8Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import random.gba.loader.ItemDataLoader;
import random.gba.loader.TextLoader;
import random.gba.loader.ItemDataLoader.AdditionalData;
import ui.model.MinMaxOption;
import util.ByteArrayBuilder;
import util.DebugPrinter;
import util.FreeSpaceManager;
Expand Down Expand Up @@ -385,8 +386,9 @@ private void applyEffect(WeaponEffects effect, ItemDataLoader itemData, GBAFESpe
setEffectivenessPointer(selectedEffectivenessAddress);
break;
case HIGH_CRITICAL:
MinMaxOption range = (MinMaxOption)effect.additionalInfo.get(WeaponEffects.InfoKeys.CRITICAL_RANGE);
int currentCritical = getCritical();
int newCritical = currentCritical + 5 * (4 + rng.nextInt(7));
int newCritical = currentCritical + 5 * ((range.minValue / 5) + rng.nextInt(((range.maxValue - range.minValue) / 5) + 1));
setCritical(newCritical);
break;
case EXTEND_RANGE:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
package fedata.gba.general;

import java.util.HashMap;
import java.util.Map;

public enum WeaponEffects {
NONE, STAT_BOOSTS, EFFECTIVENESS, UNBREAKABLE, BRAVE, REVERSE_TRIANGLE, EXTEND_RANGE, HIGH_CRITICAL, MAGIC_DAMAGE, POISON, HALF_HP, DEVIL

NONE, STAT_BOOSTS, EFFECTIVENESS, UNBREAKABLE, BRAVE, REVERSE_TRIANGLE, EXTEND_RANGE, HIGH_CRITICAL, MAGIC_DAMAGE, POISON, HALF_HP, DEVIL;

public enum InfoKeys {
CRITICAL_RANGE
}

public Map<InfoKeys, Object> additionalInfo;

private WeaponEffects() {
additionalInfo = new HashMap<InfoKeys, Object>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ private void makeFinalAdjustments(String seed) {
}
}

if (classes.createPrfs || recruitOptions.createPrfs) {
if ((classes != null && classes.createPrfs) || (recruitOptions != null && recruitOptions.createPrfs)) {
// Create new PRF weapons.
if (gameType == GameType.FE6) {
GBAFECharacterData roy = charData.characterWithID(FE6Data.Character.ROY.ID);
Expand Down Expand Up @@ -2091,7 +2091,11 @@ public RecordKeeper initializeRecordKeeper() {
if (weapons.effectsList.brave) { sb.append("<li>Brave</li>\n"); }
if (weapons.effectsList.reverseTriangle) { sb.append("<li>Reverse Triangle</li>\n"); }
if (weapons.effectsList.extendedRange) { sb.append("<li>Extended Range</li>\n"); }
if (weapons.effectsList.highCritical) { sb.append("<li>Critical</li>\n"); }
if (weapons.effectsList.highCritical) {
sb.append("<li>Critical");
sb.append(" (" + weapons.effectsList.criticalRange.minValue + "% ~ " + weapons.effectsList.criticalRange.maxValue + "%)");
sb.append("</li>\n");
}
if (weapons.effectsList.magicDamage) { sb.append("<li>Magic Damage</li>\n"); }
if (weapons.effectsList.poison) { sb.append("<li>Poison</li>\n"); }
if (weapons.effectsList.eclipse) { sb.append("<li>Eclipse</li>\n"); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ public static void randomizeEffects(WeaponEffectOptions effectOptions, ItemDataL
if (effectOptions.brave) { enabledEffects.add(WeaponEffects.BRAVE); }
if (effectOptions.reverseTriangle) { enabledEffects.add(WeaponEffects.REVERSE_TRIANGLE); }
if (effectOptions.extendedRange) { enabledEffects.add(WeaponEffects.EXTEND_RANGE); }
if (effectOptions.highCritical) { enabledEffects.add(WeaponEffects.HIGH_CRITICAL); }
if (effectOptions.highCritical) {
WeaponEffects effect = WeaponEffects.HIGH_CRITICAL;
effect.additionalInfo.put(WeaponEffects.InfoKeys.CRITICAL_RANGE, effectOptions.criticalRange);
enabledEffects.add(effect);
}
if (effectOptions.magicDamage) { enabledEffects.add(WeaponEffects.MAGIC_DAMAGE); }
if (effectOptions.poison) { enabledEffects.add(WeaponEffects.POISON); }
if (effectOptions.eclipse) { enabledEffects.add(WeaponEffects.HALF_HP); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.gcn.GCNFileHandler;
import io.gcn.GCNISOException;
import io.gcn.GCNISOHandler;
import ui.model.MinMaxOption;
import util.DebugPrinter;
import util.Diff;
import util.WhyDoesJavaNotHaveThese;
Expand Down Expand Up @@ -106,6 +107,16 @@ public int compare(WeaponType arg0, WeaponType arg1) {

public enum WeaponEffect {
NONE, STAT_BOOST, EFFECTIVENESS, UNBREAKABLE, BRAVE, REVERSE_TRIANGLE, EXTEND_RANGE, CRITICAL, MAGIC_DAMAGE, POISON, STEAL_HP, CRIT_IMMUNE, NO_CRIT;

public enum InfoKey {
CRITICAL_RANGE;
}

public Map<InfoKey, Object> additionalInfo;

private WeaponEffect() {
additionalInfo = new HashMap<InfoKey, Object>();
}
}

List<FE9Item> allItems;
Expand Down Expand Up @@ -603,7 +614,8 @@ public boolean applyEffectToWeapon(WeaponEffect effect, FE9Item item, GCNISOHand
break;
case CRITICAL:
if (item.getItemCritical() >= 25) { return false; }
int bonusCrit = (rng.nextInt(6) + 5) * 5;
MinMaxOption range = (MinMaxOption)effect.additionalInfo.get(WeaponEffect.InfoKey.CRITICAL_RANGE);
int bonusCrit = 5 * ((range.minValue / 5) + rng.nextInt(((range.maxValue - range.minValue) / 5) + 1));
item.setItemCritical(item.getItemCritical() + bonusCrit);
break;
case MAGIC_DAMAGE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ public static void addRandomEffects(int effectChance, boolean safeBasicWeapons,
if (effectOptions.brave) { effects.add(WeaponEffect.BRAVE); }
if (effectOptions.reverseTriangle) { effects.add(WeaponEffect.REVERSE_TRIANGLE); }
if (effectOptions.extendedRange) { effects.add(WeaponEffect.EXTEND_RANGE); }
if (effectOptions.highCritical) { effects.add(WeaponEffect.CRITICAL); }
if (effectOptions.highCritical) {
WeaponEffect effect = WeaponEffect.CRITICAL;
effect.additionalInfo.put(WeaponEffect.InfoKey.CRITICAL_RANGE, effectOptions.criticalRange);
effects.add(effect);
}
if (effectOptions.magicDamage) { effects.add(WeaponEffect.MAGIC_DAMAGE); }
if (effectOptions.poison) { effects.add(WeaponEffect.POISON); }
if (effectOptions.stealHP) { effects.add(WeaponEffect.STEAL_HP); }
Expand Down
19 changes: 17 additions & 2 deletions Universal FE Randomizer/src/ui/WeaponEffectSelectionView.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.eclipse.swt.widgets.Listener;

import fedata.general.FEBase.GameType;
import ui.general.MinMaxControl;
import ui.model.WeaponEffectOptions;

public class WeaponEffectSelectionView extends Composite {
Expand All @@ -23,6 +24,7 @@ public interface WeaponEffectSelectionViewListener {
private Button reverseTriangleCheckBox;
private Button extendedRangeCheckBox;
private Button highCriticalCheckBox;
private MinMaxControl criticalControl;
private Button magicDamageCheckBox;
private Button poisonCheckBox;
private Button stealHPCheckBox;
Expand Down Expand Up @@ -128,14 +130,20 @@ public void handleEvent(Event event) {

highCriticalCheckBox = new Button(this, SWT.CHECK);
highCriticalCheckBox.setText("Critical");
highCriticalCheckBox.setToolTipText("Allows random weapons to gain a large critical bonus (between 20% and 50%)");
highCriticalCheckBox.setToolTipText("Allows random weapons to gain a large critical bonus.");
highCriticalCheckBox.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
notifySelectionChange();
criticalControl.setEnabled(highCriticalCheckBox.getSelection());
}
});

criticalControl = new MinMaxControl(this, SWT.NONE, "", "~");
criticalControl.getMinSpinner().setValues(20, 5, 50, 0, 5, 5);
criticalControl.getMaxSpinner().setValues(50, 20, 100, 0, 5, 5);
criticalControl.setEnabled(false);

magicDamageCheckBox = new Button(this, SWT.CHECK);
magicDamageCheckBox.setText("Magic Damage");
if (type == GameType.FE9) {
Expand Down Expand Up @@ -256,6 +264,7 @@ public void selectAll() {
reverseTriangleCheckBox.setSelection(true);
extendedRangeCheckBox.setSelection(true);
highCriticalCheckBox.setSelection(true);
criticalControl.setEnabled(true);
magicDamageCheckBox.setSelection(true);
poisonCheckBox.setSelection(true);
if (stealHPCheckBox != null) { stealHPCheckBox.setSelection(true); }
Expand All @@ -278,6 +287,7 @@ public void deselectAll() {
reverseTriangleCheckBox.setSelection(false);
extendedRangeCheckBox.setSelection(false);
highCriticalCheckBox.setSelection(false);
criticalControl.setEnabled(false);
magicDamageCheckBox.setSelection(false);
poisonCheckBox.setSelection(false);
if (stealHPCheckBox != null) { stealHPCheckBox.setSelection(false); }
Expand All @@ -295,7 +305,7 @@ public Boolean isAllDisabled() {
}

public WeaponEffectOptions getOptions() {
return new WeaponEffectOptions(statBoostsEnabled, effectivenessEnabled, unbreakableEnabled, braveEnabled, reverseEnabled, rangeEnabled, criticalEnabled, magicEnabled, poisonEnabled, stealHPEnabled, critImmuneEnabled, noCritEnabled, eclipseEnabled, devilEnabled);
return new WeaponEffectOptions(statBoostsEnabled, effectivenessEnabled, unbreakableEnabled, braveEnabled, reverseEnabled, rangeEnabled, criticalEnabled, criticalControl.getMinMaxOption(), magicEnabled, poisonEnabled, stealHPEnabled, critImmuneEnabled, noCritEnabled, eclipseEnabled, devilEnabled);
}

public void setOptions(WeaponEffectOptions options) {
Expand All @@ -308,6 +318,11 @@ public void setOptions(WeaponEffectOptions options) {
reverseTriangleCheckBox.setSelection(options.reverseTriangle != null ? options.reverseTriangle : false);
extendedRangeCheckBox.setSelection(options.extendedRange != null ? options.extendedRange : false);
highCriticalCheckBox.setSelection(options.highCritical != null ? options.highCritical : false);
if (options.highCritical != null) {
criticalControl.setMin(options.criticalRange.minValue);
criticalControl.setMax(options.criticalRange.maxValue);
criticalControl.setEnabled(options.highCritical);
}
magicDamageCheckBox.setSelection(options.magicDamage != null ? options.magicDamage : false);
poisonCheckBox.setSelection(options.poison != null ? options.poison : false);
if (stealHPCheckBox != null) { stealHPCheckBox.setSelection(options.stealHP != null ? options.stealHP : false); }
Expand Down
5 changes: 3 additions & 2 deletions Universal FE Randomizer/src/ui/general/MinMaxControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Spinner;

Expand Down Expand Up @@ -70,13 +72,12 @@ public void modifyText(ModifyEvent e) {
maxSpinner.setLayoutData(spinnerData);

FormData labelData = new FormData();
labelData.left = new FormAttachment(50, 5);
labelData.right = new FormAttachment(maxSpinner, -5);
labelData.top = new FormAttachment(maxSpinner, 0, SWT.CENTER);
maxLabel.setLayoutData(labelData);

spinnerData = new FormData();
spinnerData.right = new FormAttachment(50, -5);
spinnerData.right = new FormAttachment(maxLabel, -5);
minSpinner.setLayoutData(spinnerData);

labelData = new FormData();
Expand Down
6 changes: 4 additions & 2 deletions Universal FE Randomizer/src/ui/model/WeaponEffectOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class WeaponEffectOptions {
public final Boolean reverseTriangle;
public final Boolean extendedRange;
public final Boolean highCritical;
public final MinMaxOption criticalRange;
public final Boolean magicDamage;
public final Boolean poison;
public final Boolean stealHP;
Expand All @@ -18,8 +19,8 @@ public class WeaponEffectOptions {
public final Boolean devil;

public WeaponEffectOptions(Boolean statBoosts, Boolean effectiveness, Boolean unbreakable, Boolean brave,
Boolean reverseTriangle, Boolean extendedRange, Boolean highCritical, Boolean magicDamage, Boolean poison,
Boolean stealHP, Boolean critImmune, Boolean noCrit,
Boolean reverseTriangle, Boolean extendedRange, Boolean highCritical, MinMaxOption critRange,
Boolean magicDamage, Boolean poison, Boolean stealHP, Boolean critImmune, Boolean noCrit,
Boolean eclipse, Boolean devil) {
super();
this.statBoosts = statBoosts;
Expand All @@ -29,6 +30,7 @@ public WeaponEffectOptions(Boolean statBoosts, Boolean effectiveness, Boolean un
this.reverseTriangle = reverseTriangle;
this.extendedRange = extendedRange;
this.highCritical = highCritical;
this.criticalRange = critRange;
this.magicDamage = magicDamage;
this.poison = poison;
this.stealHP = stealHP;
Expand Down
4 changes: 2 additions & 2 deletions Universal FE Randomizer/src/util/OptionRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

public class OptionRecorder {
private static final Integer FE4OptionBundleVersion = 3;
private static final Integer GBAOptionBundleVersion = 6;
private static final Integer FE9OptionBundleVersion = 5;
private static final Integer GBAOptionBundleVersion = 7;
private static final Integer FE9OptionBundleVersion = 6;

public static class AllOptions {
public FE4OptionBundle fe4;
Expand Down

0 comments on commit 5f26435

Please sign in to comment.