Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Make one of the battling Pokémon perform a move.
- */
- public void pickMove(User user, int position) {
- if (position < 0 || position > 4) { return; }
- if (user.getId() == user1) {
- battler1PerformingMove = battler1.getMove(position);
- }
- else if (user.getId() == user2) {
- battler2PerformingMove = battler2.getMove(position);
- } else {
- return;
- }
- if (battler1PerformingMove != null && battler2PerformingMove != null) {
- performTurn();
- }
- }
- private StringJoiner performMove(int battler, Move move) {
- StringJoiner result = new StringJoiner("\n");
- Optional<User> user;
- BattlePokemon pokemon;
- Optional<User> opposingUser;
- BattlePokemon opposingPokemon;
- if (battler == 1) {
- user = Pokebot.bot.getCachedUserById(user1);
- pokemon = battler1;
- opposingUser = Pokebot.bot.getCachedUserById(user2);
- opposingPokemon = battler2;
- } else {
- user = Pokebot.bot.getCachedUserById(user2);
- pokemon = battler2;
- opposingPokemon = battler1;
- opposingUser = Pokebot.bot.getCachedUserById(user1);
- }
- Target moveTarget = move.getTarget();
- double damage;
- Map<Effect, Object> effects = move.getEffects().getAsMap();
- // Determine damage
- if (move.isDamagingMove()) {
- // Determine type matchup multiplier
- TypeMatchup matchup;
- if (opposingPokemon.getSpecies().hasSecondaryTyping()) {
- matchup = TypeMatchup.getTypeMatchup(move.getType(), opposingPokemon.getSpecies().getPrimaryTyping(), opposingPokemon.getSpecies().getSecondaryTyping());
- } else {
- matchup = TypeMatchup.getTypeMatchup(move.getType(), opposingPokemon.getSpecies().getPrimaryTyping());
- }
- double type = matchup.getMultiplier();
- if (matchup == TypeMatchup.IMMUNE) {
- result.add("It had no effect.");
- return result;
- }
- Random r = new Random();
- // Determine crit chance
- double crit;
- if (effects.containsKey(Effect.ALWAYS_CRIT)) {
- crit = 1.5;
- }
- else {
- float critChance;
- if (effects.containsKey(Effect.HIGH_CRIT_CHANCE)) {
- critChance = (float) effects.get(Effect.HIGH_CRIT_CHANCE);
- } else {
- critChance = 0.0625f;
- }
- float f = r.nextFloat();
- if (f < critChance) {
- crit = 1.5;
- } else {
- crit = 1;
- }
- }
- // Determine STAB bonus
- double stab;
- if (pokemon.hasTyping(move.getType())) {
- stab = 1.5;
- } else {
- stab = 1;
- }
- // Generate random multiplier
- double random = 0.85 + (1 - 0.85) * r.nextDouble();
- // Determine acting move power
- int power;
- if (effects.containsKey(Effect.SUBSEQUENT_USE_POWER_DOUBLE)) {
- if (battler == 1) {
- power = move.getPower() * battler1SubsequentUsePowerDouble;
- battler1SubsequentUsePowerDouble++;
- } else {
- power = move.getPower() * battler2SubsequentUsePowerDouble;
- battler2SubsequentUsePowerDouble++;
- }
- }
- else if (effects.containsKey(Effect.POWER_DOUBLE_AFTER_MOVE)) {
- Move previousMove = (Move) effects.get(Effect.POWER_DOUBLE_AFTER_MOVE);
- if (battler == 1) {
- if (battler1PreviousMove == previousMove) {
- power = move.getPower() * 2;
- } else {
- power = move.getPower();
- }
- } else {
- if (battler2PreviousMove == previousMove) {
- power = move.getPower() * 2;
- } else {
- power = move.getPower();
- }
- }
- }
- else if (effects.containsKey(Effect.DOUBLE_POWER_BURN)) {
- if (battler == 1) {
- if (battler2.getNonVolatileStatusCondition() == StatusCondition.BURN) {
- power = move.getPower() * 2;
- } else {
- power = move.getPower();
- }
- } else {
- if (battler1.getNonVolatileStatusCondition() == StatusCondition.BURN) {
- power = move.getPower() * 2;
- } else {
- power = move.getPower();
- }
- }
- }
- else if (effects.containsKey(Effect.DOUBLE_POWER_POISON)) {
- if (battler == 1) {
- if (battler2.getNonVolatileStatusCondition() == StatusCondition.POISON || battler2.getNonVolatileStatusCondition() == StatusCondition.BADLY_POISONED) {
- power = move.getPower() * 2;
- } else {
- power = move.getPower();
- }
- } else {
- if (battler1.getNonVolatileStatusCondition() == StatusCondition.POISON || battler1.getNonVolatileStatusCondition() == StatusCondition.BADLY_POISONED) {
- power = move.getPower() * 2;
- } else {
- power = move.getPower();
- }
- }
- }
- else if (effects.containsKey(Effect.DOUBLE_POWER_PARALYSIS)) {
- if (battler == 1) {
- if (battler2.getNonVolatileStatusCondition() == StatusCondition.PARALYSIS) {
- power = move.getPower() * 2;
- } else {
- power = move.getPower();
- }
- } else {
- if (battler1.getNonVolatileStatusCondition() == StatusCondition.PARALYSIS) {
- power = move.getPower() * 2;
- } else {
- power = move.getPower();
- }
- }
- }
- else if (effects.containsKey(Effect.DOUBLE_POWER_SLEEP)) {
- if (battler == 1) {
- if (battler2.getNonVolatileStatusCondition() == StatusCondition.SLEEP) {
- power = move.getPower() * 2;
- } else {
- power = move.getPower();
- }
- } else {
- if (battler1.getNonVolatileStatusCondition() == StatusCondition.SLEEP) {
- power = move.getPower() * 2;
- } else {
- power = move.getPower();
- }
- }
- }
- else if (effects.containsKey(Effect.DOUBLE_POWER_FREEZE)) {
- if (battler == 1) {
- if (battler2.getNonVolatileStatusCondition() == StatusCondition.FREEZE) {
- power = move.getPower() * 2;
- } else {
- power = move.getPower();
- }
- } else {
- if (battler1.getNonVolatileStatusCondition() == StatusCondition.FREEZE) {
- power = move.getPower() * 2;
- } else {
- power = move.getPower();
- }
- }
- }
- else {
- power = move.getPower();
- }
- // IMPORTANT Calculate and subtract final damage output
- double modifier = crit * random * stab * type;
- if (move.getCategory() == MoveCategory.PHYSICAL) {
- if (effects.containsKey(Effect.IGNORE_STAT_CHANGES)) {
- damage = ((((2 * pokemon.getLevel() / 5f) + 2) * power * pokemon.getAttack() / opposingPokemon.getInitDefense()) / 50 + 2) * modifier;
- } else {
- damage = ((((2 * pokemon.getLevel() / 5f) + 2) * power * pokemon.getAttack() / opposingPokemon.getDefense()) / 50 + 2) * modifier;
- }
- } else {
- if (effects.containsKey(Effect.IGNORE_STAT_CHANGES)) {
- damage = ((((2 * pokemon.getLevel() / 5f) + 2) * power * pokemon.getSpAttack() / opposingPokemon.getInitSpDefense()) / 50 + 2) * modifier;
- } else {
- damage = ((((2 * pokemon.getLevel() / 5f) + 2) * power * pokemon.getSpAttack() / opposingPokemon.getSpDefense()) / 50 + 2) * modifier;
- }
- }
- boolean fainted = opposingPokemon.dealDamage((int) Math.floor(damage));
- if (matchup == TypeMatchup.HYPER_EFFECTIVE || matchup == TypeMatchup.SUPER_EFFECTIVE) {
- result.add("It's super effective!");
- result.add("**-" + damage + "**");
- } else if (matchup == TypeMatchup.RESISTANT || matchup == TypeMatchup.SUPER_RESISTANT) {
- result.add("It's not very effective...");
- result.add("**-" + damage + "**");
- }
- if (fainted) {
- result.add(opposingPokemon.getDisplayName() + " fainted!");
- return result;
- }
- } else {
- damage = 0;
- }
- // Execute all special effects
- for (Map.Entry<Effect, Object> entry : effects.entrySet()) {
- Effect effect = entry.getKey();
- Object value = entry.getValue();
- if (effect.toString().startsWith("RAISE_")) {
- Statistic stat = Statistic.fromString(effects.toString().substring(6));
- int stages = (int) value;
- if (moveTarget == Target.SELF || moveTarget == Target.SINGLE_ADJACENT_ALLY || moveTarget == Target.ALL_ADJACENT_ALLIES || moveTarget == Target.ALL_ALLIES || effect.toString().contains("SELF")) {
- pokemon.raiseStat(stat, stages);
- if (stages == 1) {
- result.add(pokemon.getDisplayName() + "'s " + stat.getName() + " rose!");
- } else if (stages == 2) {
- result.add(pokemon.getDisplayName() + "'s " + stat.getName() + " rose sharply!");
- } else {
- result.add(pokemon.getDisplayName() + "'s " + stat.getName() + " rose drastically!");
- }
- }
- else if (moveTarget == Target.SINGLE_ADJACENT_FOE || moveTarget == Target.ALL_ADJACENT_FOES || moveTarget == Target.ALL_FOES) {
- opposingPokemon.raiseStat(stat, stages);
- if (stages == 1) {
- result.add(opposingPokemon.getDisplayName() + "'s " + stat.getName() + " rose!");
- } else if (stages == 2) {
- result.add(opposingPokemon.getDisplayName() + "'s " + stat.getName() + " rose sharply!");
- } else {
- result.add(opposingPokemon.getDisplayName() + "'s " + stat.getName() + " rose drastically!");
- }
- }
- }
- else if (effect.toString().startsWith("LOWER_")) {
- Statistic stat = Statistic.fromString(effects.toString().substring(6));
- int stages = (int) value;
- if (moveTarget == Target.SELF || moveTarget == Target.SINGLE_ADJACENT_ALLY || moveTarget == Target.ALL_ADJACENT_ALLIES || moveTarget == Target.ALL_ALLIES || effect.toString().contains("SELF")) {
- pokemon.lowerStat(stat, stages);
- if (stages == 1) {
- result.add(pokemon.getDisplayName() + "'s " + stat.getName() + " fell!");
- } else if (stages == 2) {
- result.add(pokemon.getDisplayName() + "'s " + stat.getName() + " harshly fell!");
- } else {
- result.add(pokemon.getDisplayName() + "'s " + stat.getName() + " severely fell!");
- }
- }
- else if (moveTarget == Target.SINGLE_ADJACENT_FOE || moveTarget == Target.ALL_ADJACENT_FOES || moveTarget == Target.ALL_FOES) {
- opposingPokemon.lowerStat(stat, stages);
- if (stages == 1) {
- result.add(opposingPokemon.getDisplayName() + "'s " + stat.getName() + " fell!");
- } else if (stages == 2) {
- result.add(opposingPokemon.getDisplayName() + "'s " + stat.getName() + " harshly fell!");
- } else {
- result.add(opposingPokemon.getDisplayName() + "'s " + stat.getName() + " severely fell!");
- }
- }
- }
- else if (effect == Effect.ABSORB) {
- int percentage = (int) value;
- int absorb = (int) Math.floor(damage / (percentage / 100f));
- boolean fullyHealed = pokemon.heal(absorb);
- if (fullyHealed) {
- result.add(pokemon.getDisplayName() + "'s HP was fully restored!");
- } else {
- result.add(pokemon.getDisplayName() + " was healed for " + absorb + " HP!");
- }
- }
- else if (effect == Effect.HEAL) {
- int percentage = (int) value;
- if (moveTarget == Target.SELF || moveTarget == Target.SINGLE_ADJACENT_ALLY || moveTarget == Target.ALL_ADJACENT_ALLIES || moveTarget == Target.ALL_ALLIES) {
- int heal = (int) Math.floor(pokemon.getMaxHp() / (percentage / 100f));
- pokemon.heal(heal);
- result.add(pokemon.getDisplayName() + " was healed for " + heal + " HP!");
- }
- else if(moveTarget == Target.SINGLE_ADJACENT_FOE || moveTarget == Target.ALL_ADJACENT_FOES || moveTarget == Target.ALL_FOES) {
- int heal = (int) Math.floor(opposingPokemon.getMaxHp() / (percentage / 100f));
- opposingPokemon.heal(heal);
- result.add(opposingPokemon.getDisplayName() + " was healed for " + heal + " HP!");
- }
- }
- else if (effect == Effect.HEAL_SELF) {
- int percentage = (int) value;
- int heal = (int) Math.floor(pokemon.getMaxHp() / (percentage / 100f));
- pokemon.heal(heal);
- result.add(pokemon.getDisplayName() + " was healed for " + heal + " HP!");
- }
- else if (effect == Effect.HEAL_EVERY_TURN) {
- if (battler1HealEveryTurn != 0) {
- result.add("A move like this is already active!");
- } else {
- battler1HealEveryTurn = (double) effects.get(Effect.HEAL_EVERY_TURN);
- }
- }
- else if (effect == Effect.HEAL_STATUS_CONDITION) {
- StatusCondition condition = (StatusCondition) effects.get(effect);
- if (moveTarget == Target.SELF || moveTarget == Target.SINGLE_ADJACENT_ALLY || moveTarget == Target.ALL_ADJACENT_ALLIES || moveTarget == Target.ALL_ALLIES) {
- if (pokemon.hasStatusCondition(condition)) {
- pokemon.cureStatusCondition(condition);
- result.add(pokemon.getDisplayName() + "'s " + condition.getName() + " has been cured!");
- }
- }
- else if(moveTarget == Target.SINGLE_ADJACENT_FOE || moveTarget == Target.ALL_ADJACENT_FOES || moveTarget == Target.ALL_FOES) {
- if (opposingPokemon.hasStatusCondition(condition)) {
- opposingPokemon.cureStatusCondition(condition);
- result.add(opposingPokemon.getDisplayName() + "'s " + condition.getName() + " has been cured!");
- }
- }
- }
- else if (effect == Effect.HEAL_ALL_STATUS_CONDITIONS) {
- if (moveTarget == Target.SELF || moveTarget == Target.SINGLE_ADJACENT_ALLY || moveTarget == Target.ALL_ADJACENT_ALLIES || moveTarget == Target.ALL_ALLIES) {
- pokemon.cureAllStatusConditions();
- result.add("All of " + pokemon.getDisplayName() + "'s status conditions have been cured!");
- }
- else if(moveTarget == Target.SINGLE_ADJACENT_FOE || moveTarget == Target.ALL_ADJACENT_FOES || moveTarget == Target.ALL_FOES) {
- opposingPokemon.cureAllStatusConditions();
- result.add("All of " + opposingPokemon.getDisplayName() + "'s status conditions have been cured!");
- }
- }
- else if (effect == Effect.DAMAGE_SELF) {
- int percentage = (int) effects.get(effect);
- pokemon.dealDamage((int) Math.floor(battler1.getMaxHp() / (percentage / 100f)));
- }
- else if (effect == Effect.RECOIL_DAMAGE) {
- int percentage = (int) effects.get(effect);
- pokemon.dealDamage((int) Math.floor(damage / (percentage / 100f)));
- }
- else if (effect == Effect.CLEAR_STAT_CHANGES) {
- if (moveTarget == Target.SELF || moveTarget == Target.SINGLE_ADJACENT_ALLY || moveTarget == Target.ALL_ADJACENT_ALLIES || moveTarget == Target.ALL_ALLIES) {
- pokemon.clearAllStatChanges();
- result.add(pokemon.getDisplayName() + "'s stat changes have been cleared!");
- }
- else if(moveTarget == Target.SINGLE_ADJACENT_FOE || moveTarget == Target.ALL_ADJACENT_FOES || moveTarget == Target.ALL_FOES) {
- opposingPokemon.clearAllStatChanges();
- result.add(opposingPokemon.getDisplayName() + "'s stat changes have been cleared!");
- }
- else {
- pokemon.clearAllStatChanges();
- opposingPokemon.clearAllStatChanges();
- result.add(opposingPokemon.getDisplayName() + "'s stat changes have been cleared!");
- }
- }
- else if (effect == Effect.CLEAR_ALL_STAT_CHANGES) {
- pokemon.clearAllStatChanges();
- opposingPokemon.clearAllStatChanges();
- result.add(opposingPokemon.getDisplayName() + "'s stat changes have been cleared!");
- }
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment