Advertisement
VinceOrlando90

Untitled

Jan 23rd, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. public class PokedexSeen {
  2.  
  3. /* onGameInitialization
  4. *
  5. * This method will register this object/mod to the event bus so it can have listeners
  6. */
  7. @Listener
  8. public void onGameInitialization(GameInitializationEvent event) {
  9. Pixelmon.EVENT_BUS.register(this);
  10. }
  11.  
  12. /* updateDex method
  13. *
  14. * This method takes in a BattleControllerBase
  15. * which contains information about participants in order
  16. * to implement the seen functionality for pokedex.
  17. *
  18. * This works for both wild and trainer battle. This supports single battles,
  19. * one player double battles, and two player double battles.
  20. *
  21. * @playersDex Stores pokedex object of each player participant
  22. * @opponents Store pixelmon of each opponents
  23. */
  24. private void updateDex(BattleControllerBase event) {
  25. List<Pokedex> playersDex = new LinkedList<Pokedex>();
  26. List<PixelmonWrapper> opponents = new LinkedList<PixelmonWrapper>();
  27. event.participants.forEach((participant) -> {
  28. if (participant instanceof PlayerParticipant) {
  29. playersDex.add(((PlayerParticipant)participant).party.pokedex);
  30. }
  31. else {
  32. opponents.addAll(participant.controlledPokemon);
  33. }
  34. });
  35. for (Pokedex playerDex : playersDex) {
  36. for (PixelmonWrapper opponent : opponents) {
  37. int pokemonID = opponent.pokemon.getSpecies().getNationalPokedexInteger();
  38. if (playerDex.isUnknown(pokemonID)) {
  39. Pixelmon.EVENT_BUS.post(new PokedexEvent(playerDex.uuid, opponent.pokemon, EnumPokedexRegisterStatus.seen, PokedexEvent.POKEDEX_KEY));
  40. playerDex.set(pokemonID, EnumPokedexRegisterStatus.seen);
  41. playerDex.update();
  42. }
  43. }
  44. }
  45. }
  46.  
  47. /* onTurnEnd method
  48. *
  49. * This method will listen to when a turn ends in battle.
  50. */
  51. @SubscribeEvent
  52. public void onTurnEnd(TurnEndEvent event) {
  53. this.updateDex(event.bcb);
  54. }
  55.  
  56. /* onBattleEnd method
  57. *
  58. * This method will listen to when a battle ends (via forfeit, run, etc.)
  59. */
  60. @SubscribeEvent
  61. public void onBattleEnd(BattleEndEvent event) {
  62. this.updateDex(event.bc);
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement