public void counterAttackChecks(LivingEntity attacker, int damage) { if (player == null) return; if (!Permissions.counterAttack(player)) { return; } CounterAttackEventHandler eventHandler = new CounterAttackEventHandler(this, attacker, damage); if (eventHandler.isHoldingSword()) { eventHandler.calculateSkillModifier(); int randomChance = 100; if (Permissions.luckySwords(player)) { randomChance = (int) (randomChance * 0.75); } float chance = (float) (((double) Swords.COUNTER_ATTACK_CHANCE_MAX / (double) Swords.COUNTER_ATTACK_MAX_BONUS_LEVEL) * skillLevel); if (chance > Swords.COUNTER_ATTACK_CHANCE_MAX) chance = Swords.COUNTER_ATTACK_CHANCE_MAX; if (chance > Misc.getRandom().nextInt(randomChance)) { eventHandler.dealDamage(); eventHandler.sendAbilityMessages(); } } }
/** * Check for Bleed effect. * * @param defender The defending entity */ public void bleedCheck(LivingEntity defender) { if (player == null) return; if (!Permissions.swordsBleed(player)) { return; } if (Combat.shouldBeAffected(player, defender)) { BleedEventHandler eventHandler = new BleedEventHandler(this, defender); int randomChance = 100; if (Permissions.luckySwords(player)) { randomChance = (int) (randomChance * 0.75); } float chance = (float) (((double) Swords.BLEED_CHANCE_MAX / (double) Swords.BLEED_MAX_BONUS_LEVEL) * skillLevel); if (chance > Swords.BLEED_CHANCE_MAX) chance = Swords.BLEED_CHANCE_MAX; if (chance > Misc.getRandom().nextInt(randomChance)) { eventHandler.addBleedTicks(); eventHandler.sendAbilityMessages(); } } }
/** * Randomly chooses a drop among the list * * @param possibleDrops List of ItemStack that can be dropped * @return Chosen ItemStack */ private static ItemStack chooseDrop(Map<ItemStack, Integer> possibleDrops) { int dropProbability = Misc.getRandom().nextInt(100); int cumulatedProbability = 0; for (Entry<ItemStack, Integer> entry : possibleDrops.entrySet()) { cumulatedProbability += entry.getValue(); if (dropProbability < cumulatedProbability) { return entry.getKey(); } } return null; }
/** * Process the Hylian Luck ability. * * @param blockState The {@link BlockState} to check ability activation for * @return true if the ability was successful, false otherwise */ public boolean processHylianLuck(BlockState blockState) { if (!SkillUtils.activationSuccessful( SecondaryAbility.HYLIAN_LUCK, getPlayer(), getSkillLevel(), activationChance)) { return false; } List<HylianTreasure> treasures; switch (blockState.getType()) { case DEAD_BUSH: case LONG_GRASS: case SAPLING: treasures = TreasureConfig.getInstance().hylianFromBushes; break; case RED_ROSE: case YELLOW_FLOWER: if (mcMMO.getPlaceStore().isTrue(blockState)) { mcMMO.getPlaceStore().setFalse(blockState); return false; } treasures = TreasureConfig.getInstance().hylianFromFlowers; break; case FLOWER_POT: treasures = TreasureConfig.getInstance().hylianFromPots; break; default: return false; } Player player = getPlayer(); if (treasures.isEmpty() || !EventUtils.simulateBlockBreak(blockState.getBlock(), player, false)) { return false; } blockState.setType(Material.AIR); Misc.dropItem( blockState.getLocation(), treasures.get(Misc.getRandom().nextInt(treasures.size())).getDrop()); player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck")); return true; }
/** * Check for Daze. * * @param defender Defending player * @param event The event to modify */ public void dazeCheck(Player defender, EntityDamageEvent event) { if (Misc.isNPC(player) || !Permissions.daze(player)) { return; } DazeEventHandler eventHandler = new DazeEventHandler(this, event, defender); int randomChance = 100; if (Permissions.luckyArchery(player)) { randomChance = (int) (randomChance * 0.75); } double chance = (Archery.dazeMaxBonus / Archery.dazeMaxBonusLevel) * eventHandler.skillModifier; if (chance > Misc.getRandom().nextInt(randomChance)) { eventHandler.handleDazeEffect(); eventHandler.sendAbilityMessages(); } }
/** * Track arrows fired for later retrieval. * * @param livingEntity Entity damaged by the arrow */ public void trackArrows(LivingEntity livingEntity) { if (Misc.isNPC(player) || !Permissions.trackArrows(player)) { return; } ArrowTrackingEventHandler eventHandler = new ArrowTrackingEventHandler(this, livingEntity); int randomChance = 100; if (Permissions.luckyArchery(player)) { randomChance = (int) (randomChance * 0.75); } double chance = (Archery.retrieveMaxChance / Archery.retrieveMaxBonusLevel) * eventHandler.skillModifier; if (chance > Misc.getRandom().nextInt(randomChance)) { eventHandler.addToTracker(); } }
public void pummel(LivingEntity target, Wolf wolf) { double chance = 10 / activationChance; SecondaryAbilityWeightedActivationCheckEvent event = new SecondaryAbilityWeightedActivationCheckEvent( getPlayer(), SecondaryAbility.PUMMEL, chance); mcMMO.p.getServer().getPluginManager().callEvent(event); if ((event.getChance() * activationChance) <= Misc.getRandom().nextInt(activationChance)) { return; } ParticleEffectUtils.playGreaterImpactEffect(target); target.setVelocity(wolf.getLocation().getDirection().normalize().multiply(1.5D)); if (target instanceof Player) { Player defender = (Player) target; if (UserManager.getPlayer(defender).useChatNotifications()) { defender.sendMessage("Wolf pummeled at you"); } } }
/** * Begins Tree Feller * * @param player Player using Shake Mob * @param mob Targeted entity * @param skillLevel Fishing level of the player */ public static void process(Player player, LivingEntity mob, int skillLevel) { int activationChance = Misc.calculateActivationChance(Permissions.luckyFishing(player)); if (getShakeProbability(skillLevel) <= Misc.getRandom().nextInt(activationChance)) { return; } Map<ItemStack, Integer> possibleDrops = new HashMap<ItemStack, Integer>(); findPossibleDrops(mob, possibleDrops); if (possibleDrops.isEmpty()) { return; } ItemStack drop = chooseDrop(possibleDrops); // It's possible that chooseDrop returns null if the sum of probability in possibleDrops is // inferior than 100 if (drop == null) { return; } // Extra processing depending on the mob and drop type switch (mob.getType()) { case SHEEP: Sheep sheep = (Sheep) mob; if (drop.getType() == Material.WOOL) { if (sheep.isSheared()) { return; } // TODO: Find a cleaner way to do this, maybe by using Sheep.getColor().getWoolData() // (available since 1.4.7-R0.1) Wool wool = (Wool) drop.getData(); wool.setColor(sheep.getColor()); drop.setDurability(wool.getData()); sheep.setSheared(true); } break; case SKELETON: Skeleton skeleton = (Skeleton) mob; if (skeleton.getSkeletonType() == SkeletonType.WITHER) { switch (drop.getType()) { case SKULL_ITEM: drop.setDurability((short) 1); break; case ARROW: drop.setType(Material.COAL); break; default: break; } } default: break; } Misc.dropItem(mob.getLocation(), drop); CombatTools.dealDamage(mob, 1); // We may want to base the damage on the entity max health }
/** * Finds the possible drops of an entity * * @param mob Targeted entity * @param possibleDrops List of ItemStack that can be dropped */ private static void findPossibleDrops(LivingEntity mob, Map<ItemStack, Integer> possibleDrops) { switch (mob.getType()) { case BLAZE: possibleDrops.put(new ItemStack(Material.BLAZE_ROD), 100); break; case CAVE_SPIDER: case SPIDER: possibleDrops.put(new ItemStack(Material.SPIDER_EYE), 50); possibleDrops.put(new ItemStack(Material.STRING), 50); break; case CHICKEN: possibleDrops.put(new ItemStack(Material.FEATHER), 34); possibleDrops.put(new ItemStack(Material.RAW_CHICKEN), 33); possibleDrops.put(new ItemStack(Material.EGG), 33); break; case COW: possibleDrops.put(new ItemStack(Material.MILK_BUCKET), 2); possibleDrops.put(new ItemStack(Material.LEATHER), 49); possibleDrops.put(new ItemStack(Material.RAW_BEEF), 49); break; case CREEPER: possibleDrops.put(new ItemStack(Material.SKULL_ITEM, 1, (short) 4), 1); possibleDrops.put(new ItemStack(Material.SULPHUR), 99); break; case ENDERMAN: possibleDrops.put(new ItemStack(Material.ENDER_PEARL), 100); break; case GHAST: possibleDrops.put(new ItemStack(Material.SULPHUR), 50); possibleDrops.put(new ItemStack(Material.GHAST_TEAR), 50); break; case IRON_GOLEM: possibleDrops.put(new ItemStack(Material.PUMPKIN), 3); possibleDrops.put(new ItemStack(Material.IRON_INGOT), 12); possibleDrops.put(new ItemStack(Material.RED_ROSE), 85); break; case MAGMA_CUBE: possibleDrops.put(new ItemStack(Material.MAGMA_CREAM), 3); break; case MUSHROOM_COW: possibleDrops.put(new ItemStack(Material.MILK_BUCKET), 5); possibleDrops.put(new ItemStack(Material.MUSHROOM_SOUP), 5); possibleDrops.put(new ItemStack(Material.LEATHER), 30); possibleDrops.put(new ItemStack(Material.RAW_BEEF), 30); possibleDrops.put( new ItemStack(Material.RED_MUSHROOM, Misc.getRandom().nextInt(3) + 1), 30); break; case PIG: possibleDrops.put(new ItemStack(Material.PORK), 3); break; case PIG_ZOMBIE: possibleDrops.put(new ItemStack(Material.ROTTEN_FLESH), 50); possibleDrops.put(new ItemStack(Material.GOLD_NUGGET), 50); break; case SHEEP: possibleDrops.put(new ItemStack(Material.WOOL, Misc.getRandom().nextInt(6) + 1), 100); break; case SKELETON: possibleDrops.put(new ItemStack(Material.SKULL_ITEM, 1, (short) 0), 2); possibleDrops.put(new ItemStack(Material.BONE), 49); possibleDrops.put(new ItemStack(Material.ARROW, Misc.getRandom().nextInt(3) + 1), 49); break; case SLIME: possibleDrops.put(new ItemStack(Material.SLIME_BALL), 100); break; case SNOWMAN: possibleDrops.put(new ItemStack(Material.PUMPKIN), 3); possibleDrops.put(new ItemStack(Material.SNOW_BALL, Misc.getRandom().nextInt(4) + 1), 97); break; case SQUID: possibleDrops.put( new ItemStack(Material.INK_SACK), 100); // TODO: Add DyeColor.BLACK.getDyeData() to make it more explicit (available since // 1.4.7-R0.1) break; case WITCH: possibleDrops.put(new Potion(PotionType.INSTANT_HEAL).toItemStack(1), 1); possibleDrops.put(new Potion(PotionType.FIRE_RESISTANCE).toItemStack(1), 1); possibleDrops.put(new Potion(PotionType.SPEED).toItemStack(1), 1); possibleDrops.put(new ItemStack(Material.GLASS_BOTTLE), 9); possibleDrops.put(new ItemStack(Material.GLOWSTONE_DUST), 13); possibleDrops.put(new ItemStack(Material.SULPHUR), 12); possibleDrops.put(new ItemStack(Material.REDSTONE), 13); possibleDrops.put(new ItemStack(Material.SPIDER_EYE), 12); possibleDrops.put(new ItemStack(Material.STICK), 13); possibleDrops.put(new ItemStack(Material.SUGAR), 12); possibleDrops.put(new ItemStack(Material.POTION), 13); break; case ZOMBIE: possibleDrops.put(new ItemStack(Material.SKULL_ITEM, 1, (short) 2), 2); possibleDrops.put(new ItemStack(Material.ROTTEN_FLESH), 98); break; default: return; } }
/** * Handle the Call of the Wild ability. * * @param type The type of entity to summon. * @param summonAmount The amount of material needed to summon the entity */ private void callOfTheWild(EntityType type, int summonAmount) { Player player = getPlayer(); ItemStack heldItem = player.getInventory().getItemInMainHand(); int heldItemAmount = heldItem.getAmount(); Location location = player.getLocation(); if (heldItemAmount < summonAmount) { player.sendMessage( LocaleLoader.getString( "Skills.NeedMore", StringUtils.getPrettyItemString(heldItem.getType()))); return; } if (!rangeCheck(type)) { return; } int amount = Config.getInstance().getTamingCOTWAmount(type); int tamingCOTWLength = Config.getInstance().getTamingCOTWLength(type); for (int i = 0; i < amount; i++) { if (!summonAmountCheck(type)) { return; } location = Misc.getLocationOffset(location, 1); LivingEntity entity = (LivingEntity) player.getWorld().spawnEntity(location, type); FakeEntityTameEvent event = new FakeEntityTameEvent(entity, player); mcMMO.p.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { continue; } entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue); ((Tameable) entity).setOwner(player); entity.setRemoveWhenFarAway(false); addToTracker(entity); switch (type) { case OCELOT: ((Ocelot) entity).setCatType(Ocelot.Type.values()[1 + Misc.getRandom().nextInt(3)]); break; case WOLF: entity.setMaxHealth(20.0); entity.setHealth(entity.getMaxHealth()); break; case HORSE: Horse horse = (Horse) entity; entity.setMaxHealth(15.0 + (Misc.getRandom().nextDouble() * 15)); entity.setHealth(entity.getMaxHealth()); horse.setColor( Horse.Color.values()[Misc.getRandom().nextInt(Horse.Color.values().length)]); horse.setStyle( Horse.Style.values()[Misc.getRandom().nextInt(Horse.Style.values().length)]); horse.setJumpStrength( Math.max( AdvancedConfig.getInstance().getMinHorseJumpStrength(), Math.min( Math.min(Misc.getRandom().nextDouble(), Misc.getRandom().nextDouble()) * 2, AdvancedConfig.getInstance().getMaxHorseJumpStrength()))); // TODO: setSpeed, once available break; default: break; } if (Permissions.renamePets(player)) { entity.setCustomName( LocaleLoader.getString( "Taming.Summon.Name.Format", player.getName(), StringUtils.getPrettyEntityTypeString(type))); } ParticleEffectUtils.playCallOfTheWildEffect(entity); } player .getInventory() .setItemInMainHand( heldItemAmount == summonAmount ? null : new ItemStack(heldItem.getType(), heldItemAmount - summonAmount)); String lifeSpan = ""; if (tamingCOTWLength > 0) { lifeSpan = LocaleLoader.getString("Taming.Summon.Lifespan", tamingCOTWLength); } player.sendMessage(LocaleLoader.getString("Taming.Summon.Complete") + lifeSpan); player.playSound(location, SoundAdapter.FIREWORK_BLAST_FAR, 1F, 0.5F); }