Skip to content

Commit

Permalink
style: 整理部分方法代码
Browse files Browse the repository at this point in the history
  • Loading branch information
babyw1nter committed Jul 18, 2021
1 parent 3214557 commit efefcc6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,36 +139,6 @@ public static void close() {
}
}

/**
* 获取宝当前宝可梦的 IVStore 实例
* (此方法会在绘制时一直被调用,所以应该不用手动触发更新缓存)
*
* @return IVStore
*/
public IVStore getCurrentPokemonIVStore() {
if (this.pokemon != null) {
// 获取当前宝可梦自身的本地 IVStore
IVStore localIVStore = this.pokemon.getIVs();
// 尝试根据 Pokemon UUID 从缓存处获取 IVStore
IVStore remoteIVStore = PartyCache.getPokemonIVStore(this.pokemon);
return Arrays.stream(localIVStore.getArray()).sum() == 0 ? remoteIVStore : localIVStore;
}
return new IVStore(new int[]{0, 0, 0, 0, 0, 0});
}


/**
* 获取宝当前宝可梦的 EVStore 实例
*
* @return EVStore
*/
public EVStore getCurrentPokemonEVStore() {
if (this.pokemon != null) {
return this.pokemon.getEVs();
}
return new EVStore(new int[]{0, 0, 0, 0, 0, 0});
}

/**
* 绘制背景层
* <p>
Expand Down Expand Up @@ -210,8 +180,8 @@ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, i
public void drawProgress() {
int offsetX = this.getOffsetXY()[0], offsetY = this.getOffsetXY()[1];

IVStore ivs = this.getCurrentPokemonIVStore();
EVStore evs = this.getCurrentPokemonEVStore();
IVStore ivs = PartyApi.getCurrentPokemonIVStore(this.pokemon);
EVStore evs = PartyApi.getCurrentPokemonEVStore(this.pokemon);

int ivsProgressWidth = Math.toIntExact(Math.round(115 * ivs.getPercentage(0) / 100));
double evsPercentage = Arrays.stream(evs.getArray()).sum() / 510.0 * 100.0;
Expand All @@ -228,8 +198,8 @@ public void drawProgressText() {
int offsetX = this.getOffsetXY()[0], offsetY = this.getOffsetXY()[1];

if (this.pokemon != null) {
IVStore ivs = this.getCurrentPokemonIVStore();
EVStore evs = this.getCurrentPokemonEVStore();
IVStore ivs = PartyApi.getCurrentPokemonIVStore(this.pokemon);
EVStore evs = PartyApi.getCurrentPokemonEVStore(this.pokemon);
double evsPercentage = Arrays.stream(evs.getArray()).sum() / 510.0 * 100.0;

String strIVs = this.pokemon.isEgg() ? "???/??? (???%)" : Arrays.stream(ivs.getArray()).sum() + "/186 (" + Math.round(ivs.getPercentage(0)) + "%)";
Expand Down Expand Up @@ -339,8 +309,8 @@ public void drawPokemonStatsText() {
int x = offsetX + 104;

if (this.pokemon != null) {
IVStore ivs = this.getCurrentPokemonIVStore();
EVStore evs = this.getCurrentPokemonEVStore();
IVStore ivs = PartyApi.getCurrentPokemonIVStore(this.pokemon);
EVStore evs = PartyApi.getCurrentPokemonEVStore(this.pokemon);

String IVsHp = this.pokemon.isEgg() ? "???" : ivs.isHyperTrained(StatsType.HP) ? "31(" + ivs.getStat(StatsType.HP) + ")" : String.valueOf(ivs.getStat(StatsType.HP));
String IVsAtk = this.pokemon.isEgg() ? "???" : ivs.isHyperTrained(StatsType.Attack) ? "31(" + ivs.getStat(StatsType.Attack) + ")" : String.valueOf(ivs.getStat(StatsType.Attack));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import com.pixelmonmod.pixelmon.api.pokemon.Pokemon;
import com.pixelmonmod.pixelmon.client.storage.ClientStorageManager;
import com.pixelmonmod.pixelmon.client.gui.GuiPixelmonOverlay;
import com.pixelmonmod.pixelmon.entities.pixelmon.stats.EVStore;
import com.pixelmonmod.pixelmon.entities.pixelmon.stats.IVStore;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;

public class PartyApi {
Expand Down Expand Up @@ -51,4 +55,37 @@ public static String[] getTeamStringUUID() {
public static Pokemon getSelectedPokemon() {
return ClientStorageManager.party.get(GuiPixelmonOverlay.selectedPixelmon);
}

/**
* 获取宝当前宝可梦的 IVStore 实例
*
* @param pokemonIn 指定的 {@link Pokemon},如为 null 则自动获取当前队伍中选择的宝可梦
* @return {@link IVStore}
*/
public static IVStore getCurrentPokemonIVStore(@Nullable Pokemon pokemonIn) {
Pokemon pokemon = pokemonIn != null ? pokemonIn : PartyApi.getSelectedPokemon();
if (pokemon != null) {
// 获取当前宝可梦自身的本地 IVStore
IVStore localIVStore = pokemon.getIVs();
// 尝试根据 Pokemon UUID 从缓存处获取 IVStore
IVStore remoteIVStore = PartyCache.getPokemonIVStore(pokemon);
return Arrays.stream(localIVStore.getArray()).sum() == 0 ? remoteIVStore : localIVStore;
}
return new IVStore(new int[]{0, 0, 0, 0, 0, 0});
}


/**
* 获取宝当前宝可梦的 EVStore 实例
*
* @param pokemonIn 指定的 {@link Pokemon},如为 null 则自动获取当前队伍中选择的宝可梦
* @return {@link EVStore}
*/
public static EVStore getCurrentPokemonEVStore(@Nullable Pokemon pokemonIn) {
Pokemon pokemon = pokemonIn != null ? pokemonIn : PartyApi.getSelectedPokemon();
if (pokemon != null) {
return pokemon.getEVs();
}
return new EVStore(new int[]{0, 0, 0, 0, 0, 0});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,25 @@ public static void cleanCache() {
*/
public static void updateCache(boolean forceUpdate) {
String[] localPartyPokemonsUUID = PartyApi.getTeamStringUUID();
List<String> nonExistentPokemonUUID = new ArrayList<>();

if (forceUpdate) {
PixelmonInfoPlusPacketHandler.sendGetIVSMessageRequestToServer(String.join(":", localPartyPokemonsUUID));
} else {
if (localPartyPokemonsUUID.length == 0) {
return;
}

if (!forceUpdate) {
List<String> nonExistentPokemonUUID = new ArrayList<>();

for (String uuid : localPartyPokemonsUUID) {
if (!PartyCache.pokemonsIVStore.containsKey(uuid)) {
if (!PartyCache.hasPokemonIVStore(uuid)) {
nonExistentPokemonUUID.add(uuid);
}
}

if (nonExistentPokemonUUID.size() > 0) {
PixelmonInfoPlusPacketHandler.sendGetIVSMessageRequestToServer(String.join(":", nonExistentPokemonUUID));
}
} else {
PixelmonInfoPlusPacketHandler.sendGetIVSMessageRequestToServer(String.join(":", localPartyPokemonsUUID));
}
}

Expand Down

0 comments on commit efefcc6

Please sign in to comment.