It's never too late to fix old code boys! (#268)

* It's never too late to fix old code boys!

Cache items so the array isn't returned multiple times and cache Gachapon.values() for maximum performance and stability

* Java 7 memes
This commit is contained in:
Alan Morel
2018-11-03 20:52:51 -04:00
committed by Ronan Lana
parent 9c7763be8c
commit 00675ab95d
2 changed files with 25 additions and 13 deletions

View File

@@ -33,13 +33,23 @@ public abstract class GachaponItems {
public abstract int [] getUncommonItems();
public abstract int [] getRareItems();
public int[] getItems(int tier) {
if (tier == 0){
return getCommonItems();
} else if (tier == 1){
return getUncommonItems();
} else if (tier == 2){
return getRareItems();
private final int [] commonItems;
private final int [] uncommonItems;
private final int [] rareItems;
public GachaponItems() {
this.commonItems = getCommonItems();
this.uncommonItems = getUncommonItems();
this.rareItems = getRareItems();
}
public final int[] getItems(int tier) {
if (tier == 0) {
return commonItems;
} else if (tier == 1) {
return uncommonItems;
} else if (tier == 2) {
return rareItems;
}
return null;
}

View File

@@ -49,6 +49,8 @@ public class MapleGachapon {
NEW_LEAF_CITY(9100109, 90, 8, 2, new NewLeafCity()),
NAUTILUS_HARBOR(9100117, 90, 8, 2, new NautilusHarbor());
private static final Gachapon[] values = Gachapon.values();
private GachaponItems gachapon;
private int npcId;
private int common;
@@ -56,11 +58,11 @@ public class MapleGachapon {
private int rare;
private Gachapon(int npcid, int c, int u, int r, GachaponItems g) {
npcId = npcid;
gachapon = g;
common = c;
uncommon = u;
rare = r;
this.npcId = npcid;
this.gachapon = g;
this.common = c;
this.uncommon = u;
this.rare = r;
}
private int getTier() {
@@ -85,7 +87,7 @@ public class MapleGachapon {
}
public static Gachapon getByNpcId(int npcId) {
for (Gachapon gacha : Gachapon.values()) {
for (Gachapon gacha : values) {
if (npcId == gacha.npcId) {
return gacha;
}