예제 #1
0
  /**
   * Check to see if an ability can be activated.
   *
   * @param skill The skill the ability is based on
   */
  public void checkAbilityActivation(SkillType skill) {
    ToolType tool = skill.getTool();
    AbilityType ability = skill.getAbility();

    setToolPreparationMode(tool, false);

    if (getAbilityMode(ability)) {
      return;
    }

    int timeRemaining = calculateTimeRemaining(ability);

    if (timeRemaining > 0) {
      /*
       * Axes and Woodcutting are odd because they share the same tool.
       * We show them the too tired message when they take action.
       */
      if (skill == SkillType.WOODCUTTING || skill == SkillType.AXES) {
        player.sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining));
      }

      return;
    }

    if (EventUtils.callPlayerAbilityActivateEvent(player, skill).isCancelled()) {
      return;
    }

    int ticks =
        PerksUtils.handleActivationPerks(
            player,
            2 + (getSkillLevel(skill) / AdvancedConfig.getInstance().getAbilityLength()),
            ability.getMaxLength());

    // Notify people that ability has been activated
    ParticleEffectUtils.playAbilityEnabledEffect(player);

    if (useChatNotifications()) {
      player.sendMessage(ability.getAbilityOn());
    }

    SkillUtils.sendSkillMessage(player, ability.getAbilityPlayer(player));

    // Enable the ability
    profile.setAbilityDATS(
        ability, System.currentTimeMillis() + (ticks * Misc.TIME_CONVERSION_FACTOR));
    setAbilityMode(ability, true);

    if (ability == AbilityType.SUPER_BREAKER || ability == AbilityType.GIGA_DRILL_BREAKER) {
      SkillUtils.handleAbilitySpeedIncrease(player);
    }

    new AbilityDisableTask(this, ability)
        .runTaskLater(mcMMO.p, ticks * Misc.TICK_CONVERSION_FACTOR);
  }
예제 #2
0
  /**
   * Process the Shroom Thumb ability.
   *
   * @param blockState The {@link BlockState} to check ability activation for
   * @return true if the ability was successful, false otherwise
   */
  public boolean processShroomThumb(BlockState blockState) {
    Player player = getPlayer();
    PlayerInventory playerInventory = player.getInventory();

    if (!playerInventory.contains(Material.BROWN_MUSHROOM)) {
      player.sendMessage(
          LocaleLoader.getString(
              "Skills.NeedMore", StringUtils.getPrettyItemString(Material.BROWN_MUSHROOM)));
      return false;
    }

    if (!playerInventory.contains(Material.RED_MUSHROOM)) {
      player.sendMessage(
          LocaleLoader.getString(
              "Skills.NeedMore", StringUtils.getPrettyItemString(Material.RED_MUSHROOM)));
      return false;
    }

    playerInventory.removeItem(new ItemStack(Material.BROWN_MUSHROOM));
    playerInventory.removeItem(new ItemStack(Material.RED_MUSHROOM));
    player.updateInventory();

    if (!SkillUtils.activationSuccessful(
        SecondaryAbility.SHROOM_THUMB, getPlayer(), getSkillLevel(), activationChance)) {
      player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Fail"));
      return false;
    }

    return Herbalism.convertShroomThumb(blockState);
  }
예제 #3
0
 /**
  * Handle the Farmer's Diet ability
  *
  * @param rankChange The # of levels to change rank for the food
  * @param eventFoodLevel The initial change in hunger from the event
  * @return the modified change in hunger for the event
  */
 public int farmersDiet(int rankChange, int eventFoodLevel) {
   return SkillUtils.handleFoodSkills(
       getPlayer(),
       skill,
       eventFoodLevel,
       Herbalism.farmersDietRankLevel1,
       Herbalism.farmersDietMaxLevel,
       rankChange);
 }
예제 #4
0
  /**
   * Process the Green Thumb ability for blocks.
   *
   * @param blockState The {@link BlockState} to check ability activation for
   * @return true if the ability was successful, false otherwise
   */
  public boolean processGreenThumbBlocks(BlockState blockState) {
    if (!SkillUtils.activationSuccessful(
        SecondaryAbility.GREEN_THUMB_BLOCK, getPlayer(), getSkillLevel(), activationChance)) {
      getPlayer().sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Fail"));
      return false;
    }

    return Herbalism.convertGreenTerraBlocks(blockState);
  }
예제 #5
0
  /**
   * 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;
  }
예제 #6
0
  /**
   * Apply the Gore ability.
   *
   * @param target The LivingEntity to apply Gore on
   * @param damage The initial damage
   */
  public double gore(LivingEntity target, double damage) {
    if (!SkillUtils.activationSuccessful(
        SecondaryAbility.GORE, getPlayer(), getSkillLevel(), activationChance)) {
      return 0;
    }

    BleedTimerTask.add(target, Taming.goreBleedTicks);

    if (target instanceof Player) {
      ((Player) target).sendMessage(LocaleLoader.getString("Combat.StruckByGore"));
    }

    getPlayer().sendMessage(LocaleLoader.getString("Combat.Gore"));

    damage = (damage * Taming.goreModifier) - damage;
    return damage;
  }
예제 #7
0
  /**
   * Apply the Fast Food Service ability.
   *
   * @param wolf The wolf using the ability
   * @param damage The damage being absorbed by the wolf
   */
  public void fastFoodService(Wolf wolf, double damage) {
    if (!SkillUtils.activationSuccessful(
        SecondaryAbility.FAST_FOOD,
        getPlayer(),
        Taming.fastFoodServiceActivationChance,
        activationChance)) {
      return;
    }

    double health = wolf.getHealth();
    double maxHealth = wolf.getMaxHealth();

    if (health < maxHealth) {
      double newHealth = health + damage;
      wolf.setHealth(Math.min(newHealth, maxHealth));
    }
  }
예제 #8
0
  /**
   * Process the Green Thumb ability for plants.
   *
   * @param blockState The {@link BlockState} to check ability activation for
   * @param greenTerra boolean to determine if greenTerra is active or not
   */
  private void processGreenThumbPlants(BlockState blockState, boolean greenTerra) {
    Player player = getPlayer();
    PlayerInventory playerInventory = player.getInventory();
    ItemStack seed = null;

    switch (blockState.getType()) {
      case CARROT:
        seed = new ItemStack(Material.CARROT_ITEM);
        break;

      case CROPS:
        seed = new ItemStack(Material.SEEDS);
        break;

      case NETHER_WARTS:
        seed = new ItemStack(Material.NETHER_STALK);
        break;

      case POTATO:
        seed = new ItemStack(Material.POTATO_ITEM);
        break;

      default:
        break;
    }

    if (!playerInventory.containsAtLeast(seed, 1)) {
      return;
    }

    if (!greenTerra
        && !SkillUtils.activationSuccessful(
            SecondaryAbility.GREEN_THUMB_PLANT, getPlayer(), getSkillLevel(), activationChance)) {
      return;
    }

    if (!handleBlockState(blockState, greenTerra)) {
      return;
    }

    playerInventory.removeItem(seed);
    player.updateInventory(); // Needed until replacement available
    new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0);
  }
예제 #9
0
  /** @param blockState The {@link BlockState} to check ability activation for */
  public void herbalismBlockCheck(BlockState blockState) {
    Player player = getPlayer();
    Material material = blockState.getType();
    boolean oneBlockPlant = !(material == Material.CACTUS || material == Material.SUGAR_CANE_BLOCK);

    if (oneBlockPlant && mcMMO.getPlaceStore().isTrue(blockState)) {
      return;
    }

    if (!canBlockCheck()) {
      return;
    }

    Collection<ItemStack> drops = null;
    int amount = 1;
    int xp;
    boolean greenTerra = mcMMOPlayer.getAbilityMode(skill.getAbility());

    if (mcMMO.getModManager().isCustomHerbalismBlock(blockState)) {
      CustomBlock customBlock = mcMMO.getModManager().getBlock(blockState);
      xp = customBlock.getXpGain();

      if (Permissions.secondaryAbilityEnabled(player, SecondaryAbility.HERBALISM_DOUBLE_DROPS)
          && customBlock.isDoubleDropEnabled()) {
        drops = blockState.getBlock().getDrops();
      }
    } else {
      if (Permissions.greenThumbPlant(player, material)) {
        processGreenThumbPlants(blockState, greenTerra);
      }

      xp = ExperienceConfig.getInstance().getXp(skill, material);

      if (Config.getInstance().getDoubleDropsEnabled(skill, material)
          && Permissions.secondaryAbilityEnabled(player, SecondaryAbility.HERBALISM_DOUBLE_DROPS)) {
        drops = blockState.getBlock().getDrops();
      }

      if (!oneBlockPlant) {
        amount = Herbalism.calculateCatciAndSugarDrops(blockState);
        xp *= amount;
      }
    }

    applyXpGain(xp);

    if (drops == null) {
      return;
    }

    for (int i = greenTerra ? 2 : 1; i != 0; i--) {
      if (SkillUtils.activationSuccessful(
          SecondaryAbility.HERBALISM_DOUBLE_DROPS,
          getPlayer(),
          getSkillLevel(),
          activationChance)) {
        for (ItemStack item : drops) {
          Misc.dropItems(blockState.getLocation(), item, amount);
        }
      }
    }
  }
예제 #10
0
  @Override
  protected void loadKeys() {
    repairables = new ArrayList<Repairable>();

    ConfigurationSection section = config.getConfigurationSection("Repairables");
    Set<String> keys = section.getKeys(false);

    for (String key : keys) {
      if (config.contains("Repairables." + key + ".ItemId")) {
        backup();
        return;
      }

      // Validate all the things!
      List<String> reason = new ArrayList<String>();

      // Item Material
      Material itemMaterial = Material.matchMaterial(key);

      if (itemMaterial == null) {
        reason.add("Invalid material: " + key);
      }

      // Repair Material Type
      MaterialType repairMaterialType = MaterialType.OTHER;
      String repairMaterialTypeString =
          config.getString("Repairables." + key + ".MaterialType", "OTHER");

      if (!config.contains("Repairables." + key + ".MaterialType") && itemMaterial != null) {
        ItemStack repairItem = new ItemStack(itemMaterial);

        if (ItemUtils.isWoodTool(repairItem)) {
          repairMaterialType = MaterialType.WOOD;
        } else if (ItemUtils.isStoneTool(repairItem)) {
          repairMaterialType = MaterialType.STONE;
        } else if (ItemUtils.isStringTool(repairItem)) {
          repairMaterialType = MaterialType.STRING;
        } else if (ItemUtils.isLeatherArmor(repairItem)) {
          repairMaterialType = MaterialType.LEATHER;
        } else if (ItemUtils.isIronArmor(repairItem) || ItemUtils.isIronTool(repairItem)) {
          repairMaterialType = MaterialType.IRON;
        } else if (ItemUtils.isGoldArmor(repairItem) || ItemUtils.isGoldTool(repairItem)) {
          repairMaterialType = MaterialType.GOLD;
        } else if (ItemUtils.isDiamondArmor(repairItem) || ItemUtils.isDiamondTool(repairItem)) {
          repairMaterialType = MaterialType.DIAMOND;
        }
      } else {
        try {
          repairMaterialType = MaterialType.valueOf(repairMaterialTypeString);
        } catch (IllegalArgumentException ex) {
          reason.add(key + " has an invalid MaterialType of " + repairMaterialTypeString);
        }
      }

      // Repair Material
      String repairMaterialName = config.getString("Repairables." + key + ".RepairMaterial");
      Material repairMaterial =
          (repairMaterialName == null
              ? repairMaterialType.getDefaultMaterial()
              : Material.matchMaterial(repairMaterialName));

      if (repairMaterial == null) {
        reason.add(key + " has an invalid repair material: " + repairMaterialName);
      }

      // Maximum Durability
      short maximumDurability =
          (itemMaterial != null
              ? itemMaterial.getMaxDurability()
              : (short) config.getInt("Repairables." + key + ".MaximumDurability"));

      if (maximumDurability <= 0) {
        maximumDurability = (short) config.getInt("Repairables." + key + ".MaximumDurability");
      }

      if (maximumDurability <= 0) {
        reason.add("Maximum durability of " + key + " must be greater than 0!");
      }

      // Item Type
      ItemType repairItemType = ItemType.OTHER;
      String repairItemTypeString = config.getString("Repairables." + key + ".ItemType", "OTHER");

      if (!config.contains("Repairables." + key + ".ItemType") && itemMaterial != null) {
        ItemStack repairItem = new ItemStack(itemMaterial);

        if (ItemUtils.isMinecraftTool(repairItem)) {
          repairItemType = ItemType.TOOL;
        } else if (ItemUtils.isArmor(repairItem)) {
          repairItemType = ItemType.ARMOR;
        }
      } else {
        try {
          repairItemType = ItemType.valueOf(repairItemTypeString);
        } catch (IllegalArgumentException ex) {
          reason.add(key + " has an invalid ItemType of " + repairItemTypeString);
        }
      }

      byte repairMetadata =
          (byte) config.getInt("Repairables." + key + ".RepairMaterialMetadata", -1);
      int minimumLevel = config.getInt("Repairables." + key + ".MinimumLevel");
      double xpMultiplier = config.getDouble("Repairables." + key + ".XpMultiplier", 1);

      if (minimumLevel < 0) {
        reason.add(key + " has an invalid MinimumLevel of " + minimumLevel);
      }

      // Minimum Quantity
      int minimumQuantity =
          (itemMaterial != null
              ? SkillUtils.getRepairAndSalvageQuantities(
                  new ItemStack(itemMaterial), repairMaterial, repairMetadata)
              : config.getInt("Repairables." + key + ".MinimumQuantity", 2));

      if (minimumQuantity <= 0 && itemMaterial != null) {
        minimumQuantity = config.getInt("Repairables." + key + ".MinimumQuantity", 2);
      }

      if (minimumQuantity <= 0) {
        reason.add("Minimum quantity of " + key + " must be greater than 0!");
      }

      if (noErrorsInRepairable(reason)) {
        Repairable repairable =
            RepairableFactory.getRepairable(
                itemMaterial,
                repairMaterial,
                repairMetadata,
                minimumLevel,
                minimumQuantity,
                maximumDurability,
                repairItemType,
                repairMaterialType,
                xpMultiplier);
        repairables.add(repairable);
      }
    }
  }
예제 #11
0
  /**
   * Handle EntityDamage events that involve modifying the event.
   *
   * @param event The event to modify
   */
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onEntityDamage(EntityDamageEvent event) {
    if (event instanceof FakeEntityDamageEvent) {
      return;
    }

    double damage = event.getDamage();

    if (damage <= 0) {
      return;
    }

    Entity entity = event.getEntity();

    if (entity.hasMetadata(mcMMO.customDamageKey)) {
      entity.removeMetadata(mcMMO.customDamageKey, plugin);
      return;
    }

    if (Misc.isNPCEntity(entity) || !entity.isValid() || !(entity instanceof LivingEntity)) {
      return;
    }

    LivingEntity livingEntity = (LivingEntity) entity;

    if (CombatUtils.isInvincible(livingEntity, damage)) {
      return;
    }

    DamageCause cause = event.getCause();

    if (livingEntity instanceof Player) {
      Player player = (Player) entity;
      McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);

      /* Check for invincibility */
      if (mcMMOPlayer.getGodMode()) {
        event.setCancelled(true);
        return;
      }

      switch (cause) {
        case FALL:
          if (Config.getInstance().getPreventXPAfterTeleport()
              && SkillUtils.calculateTimeLeft(
                      (long) mcMMOPlayer.getTeleportATS() * Misc.TIME_CONVERSION_FACTOR, 5, player)
                  > 0) {
            return;
          }

          AcrobaticsManager acrobaticsManager = mcMMOPlayer.getAcrobaticsManager();

          if (acrobaticsManager.canRoll()) {
            event.setDamage(acrobaticsManager.rollCheck(event.getDamage()));

            if (event.getDamage() == 0) {
              event.setCancelled(true);
              return;
            }
          }
          break;

        case BLOCK_EXPLOSION:
          MiningManager miningManager = mcMMOPlayer.getMiningManager();

          if (miningManager.canUseDemolitionsExpertise()) {
            event.setDamage(miningManager.processDemolitionsExpertise(event.getDamage()));

            if (event.getDamage() == 0) {
              event.setCancelled(true);
              return;
            }
          }
          break;

        default:
          break;
      }

      if (event.getDamage() >= 1) {
        mcMMOPlayer.actualizeRecentlyHurt();
      }
    } else if (livingEntity instanceof Tameable) {
      Tameable pet = (Tameable) livingEntity;
      AnimalTamer owner = pet.getOwner();

      if (Taming.canPreventDamage(pet, owner)) {
        Player player = (Player) owner;
        Wolf wolf = (Wolf) pet;

        TamingManager tamingManager = UserManager.getPlayer(player).getTamingManager();

        switch (cause) {
          case CONTACT:
          case FIRE:
          case LAVA:
            if (tamingManager.canUseEnvironmentallyAware()) {
              tamingManager.processEnvironmentallyAware(wolf, event.getDamage());
            }
            return;

          case FALL:
            if (tamingManager.canUseEnvironmentallyAware()) {
              event.setCancelled(true);
            }
            return;

          case ENTITY_ATTACK:
          case PROJECTILE:
            if (tamingManager.canUseThickFur()) {
              event.setDamage(Taming.processThickFur(wolf, event.getDamage()));

              if (event.getDamage() == 0) {
                event.setCancelled(true);
              }
            }
            return;

          case FIRE_TICK:
            if (tamingManager.canUseThickFur()) {
              Taming.processThickFurFire(wolf);
            }
            return;

          case MAGIC:
          case POISON:
          case WITHER:
            if (tamingManager.canUseHolyHound()) {
              Taming.processHolyHound(wolf, event.getDamage());
            }
            return;

          case BLOCK_EXPLOSION:
          case ENTITY_EXPLOSION:
          case LIGHTNING:
            if (tamingManager.canUseShockProof()) {
              event.setDamage(Taming.processShockProof(wolf, event.getDamage()));

              if (event.getDamage() == 0) {
                event.setCancelled(true);
              }
            }
            return;

          default:
            return;
        }
      }
    }
  }