コード例 #1
0
ファイル: WeaponManager.java プロジェクト: Senmori/Hunted
  /*
   * Used by non-ascented weapons, has a max enchantment level of 2
   */
  private Map<Enchantment, Integer> getRandomEnchantments(
      WeaponType type, int maxEnchants, int maxLevel, int minLevel) {
    // return empty map in case you cannot add null enchantments to
    // itemstacks
    Map<Enchantment, Integer> possible = new HashMap<>();
    if (maxEnchants < 1) {
      return possible;
    }

    for (WeaponEnchant we : weaponEnchants) {
      if (we.getAssociatedTypes().contains(type) && !possible.containsKey(we.getEnchant())) {
        int level = rand.nextInt(maxLevel - minLevel) + minLevel;
        possible.put(we.getEnchant(), level);
      }
    }
    // shuffle K,V in `possible`
    List<Enchantment> ench = new ArrayList<>();
    ench.addAll(possible.keySet());
    Collections.shuffle(ench);
    Map<Enchantment, Integer> enchants = new HashMap<>();
    for (int i = 0; i < maxEnchants; i++) {
      Enchantment current = ench.get(i);
      // handle if the map already has that enchantment in it
      if (enchants.containsKey(current)) {
        // max level is 2, so handle that
        if (enchants.get(current) >= maxLevel) {
          continue;
        }
        enchants.put(current, enchants.get(current) + 1);
        continue;
      }
      enchants.put(current, possible.get(current));
    }
    return enchants;
  }
コード例 #2
0
ファイル: WeaponManager.java プロジェクト: Senmori/Hunted
  public WeaponManager(Hunted plugin) {
    this.plugin = plugin;
    weaponTypes = Arrays.asList(WeaponType.values());

    swordNames = Arrays.asList(SwordName.values());
    swordTitles = Arrays.asList(SwordTitle.values());

    bowNames = Arrays.asList(BowName.values());
    bowTitles = Arrays.asList(BowTitle.values());

    weaponEnchants = Arrays.asList(WeaponEnchant.values());
    rand = new Random();
  }