Exemplo n.º 1
0
  /**
   * Updates the player's max health and mana using class data.
   *
   * @param player player to update the health and mana for
   */
  public void updateHealthAndMana(Player player) {
    if (player == null) {
      return;
    }

    // Update maxes
    double health = bonusHealth;
    maxMana = bonusMana;
    for (PlayerClass c : classes.values()) {
      health += c.getHealth();
      maxMana += c.getMana();
    }
    if (health == bonusHealth) {
      health += SkillAPI.getSettings().getDefaultHealth();
    }
    if (health == 0) {
      health = 20;
    }
    if (SkillAPI.getSettings().isModifyHealth()) VersionManager.setMaxHealth(player, health);
    mana = Math.min(mana, maxMana);

    // Health scaling is available starting with 1.6.2
    if (SkillAPI.getSettings().isModifyHealth()
        && VersionManager.isVersionAtLeast(VersionManager.V1_6_2)) {
      if (SkillAPI.getSettings().isOldHealth()) {
        player.setHealthScaled(true);
        player.setHealthScale(20);
      } else {
        player.setHealthScaled(false);
      }
    }
  }
Exemplo n.º 2
0
  /**
   * Resets the class data for the owner under the given group. This will remove the profession
   * entirely, leaving no remaining data until the player professes again to a starting class.
   *
   * @param group group to reset
   */
  public void reset(String group) {
    stopPassives(getPlayer());
    clearBonuses();
    PlayerClass playerClass = classes.remove(group);
    if (playerClass != null) {
      // Remove skills
      RPGClass data = playerClass.getData();
      for (Skill skill : data.getSkills()) {
        skills.remove(skill.getName());
        combos.removeSkill(skill);
      }

      // Update GUI features
      if (getPlayer() != null) {
        ClassBoardManager.clear(new VersionPlayer(getPlayer()));
      }

      // Call the event
      Bukkit.getPluginManager().callEvent(new PlayerClassChangeEvent(playerClass, data, null));
    }

    // Restore default class if applicable
    GroupSettings settings = SkillAPI.getSettings().getGroupSettings(group);
    RPGClass rpgClass = settings.getDefault();
    if (rpgClass != null && settings.getPermission() == null) {
      setClass(rpgClass);
    }
    updateHealthAndMana(player.getPlayer());
  }
Exemplo n.º 3
0
 /**
  * Gives skill points to the player for all classes matching the experience source
  *
  * @param amount amount of levels to give
  * @param source source of the levels
  */
 public void givePoints(int amount, ExpSource source) {
   for (PlayerClass playerClass : classes.values()) {
     if (playerClass.getData().receivesExp(source)) {
       playerClass.givePoints(amount);
     }
   }
 }
Exemplo n.º 4
0
  /**
   * Shows the skill tree for the player. If the player has multiple trees, this will show the list
   * of skill trees they can view.
   *
   * @param player player to show the skill tree for
   * @return true if able to show the player, false otherwise
   */
  public boolean showSkills(Player player) {
    // Cannot show an invalid player, and cannot show no skills
    if (player == null || classes.size() == 0 || skills.size() == 0) {
      return false;
    }

    // Show skill tree of only class
    if (classes.size() == 1) {
      PlayerClass playerClass = classes.get(classes.keySet().toArray(new String[1])[0]);
      if (playerClass.getData().getSkills().size() == 0) {
        return false;
      }

      player.openInventory(
          ((InventoryTree) playerClass.getData().getSkillTree()).getInventory(this));
      return true;
    }

    // Show list of classes that have skill trees
    else {
      Inventory inv =
          InventoryManager.createInventory(
              TreeListener.CLASS_LIST_KEY, (classes.size() + 8) / 9, player.getName());
      for (PlayerClass c : classes.values()) {
        inv.addItem(c.getData().getIcon());
      }
      player.openInventory(inv);
      return true;
    }
  }
Exemplo n.º 5
0
 /** Causes the player to lose experience as a penalty (generally for dying) */
 public void loseExp() {
   for (PlayerClass playerClass : classes.values()) {
     double penalty = playerClass.getData().getGroupSettings().getDeathPenalty();
     if (penalty > 0) {
       playerClass.loseExp(penalty);
     }
   }
 }
Exemplo n.º 6
0
 /** Regenerates mana for the player based on the regen amounts of professed classes */
 public void regenMana() {
   double amount = 0;
   for (PlayerClass c : classes.values()) {
     if (c.getData().hasManaRegen()) {
       amount += c.getData().getManaRegen();
     }
   }
   if (amount > 0) {
     giveMana(amount, ManaSource.REGEN);
   }
 }
Exemplo n.º 7
0
 /**
  * Gives levels to the player for all classes matching the experience source
  *
  * @param amount amount of levels to give
  * @param source source of the levels
  */
 public void giveLevels(int amount, ExpSource source) {
   for (PlayerClass playerClass : classes.values()) {
     RPGClass data = playerClass.getData();
     if (data.receivesExp(source)) {
       int exp = 0;
       int count = 0;
       int temp = amount;
       while (temp > 0) {
         temp--;
         exp += data.getRequiredExp(playerClass.getLevel() + count++);
       }
       playerClass.giveExp(exp, source);
     }
   }
   updateHealthAndMana(getPlayer());
 }
Exemplo n.º 8
0
 /**
  * Checks whether or not the player can profess into the given class. This checks to make sure the
  * player is currently professed as the parent of the given class and is high enough of a level to
  * do so.
  *
  * @param rpgClass class to check
  * @return true if can profess, false otherwise
  */
 public boolean canProfess(RPGClass rpgClass) {
   if (rpgClass.isNeedsPermission()) {
     Player p = getPlayer();
     if (p == null
         || (!p.hasPermission(Permissions.CLASS)
             && !p.hasPermission(
                 Permissions.CLASS + "." + rpgClass.getName().toLowerCase().replace(" ", "-")))) {
       return false;
     }
   }
   if (classes.containsKey(rpgClass.getGroup())) {
     PlayerClass current = classes.get(rpgClass.getGroup());
     return rpgClass.getParent() == current.getData()
         && current.getData().getMaxLevel() <= current.getLevel();
   } else {
     return !rpgClass.hasParent();
   }
 }
Exemplo n.º 9
0
  /**
   * Checks whether or not the player is professed as the class or any of its children.
   *
   * @param rpgClass class to check
   * @return true if professed as the class or one of its children, false otherwise
   */
  public boolean isClass(RPGClass rpgClass) {
    if (rpgClass == null) {
      return false;
    }

    PlayerClass pc = classes.get(rpgClass.getGroup());
    if (pc == null) return false;

    RPGClass temp = pc.getData();
    while (temp != null) {
      if (temp == rpgClass) {
        return true;
      }
      temp = temp.getParent();
    }

    return false;
  }
Exemplo n.º 10
0
  /**
   * Sets the professed class for the player for the corresponding group. This will not save any
   * skills, experience, or levels of the previous class if there was any. The new class will start
   * at level 1 with 0 experience.
   *
   * @param rpgClass class to assign to the player
   * @return the player-specific data for the new class
   */
  public PlayerClass setClass(RPGClass rpgClass) {
    PlayerClass c = classes.remove(rpgClass.getGroup());
    if (c != null) {
      for (Skill skill : c.getData().getSkills()) {
        skills.remove(skill.getName().toLowerCase());
        combos.removeSkill(skill);
      }
    }

    PlayerClass classData = new PlayerClass(this, rpgClass);
    classes.put(rpgClass.getGroup(), classData);

    // Add in missing skills
    for (Skill skill : rpgClass.getSkills()) {
      giveSkill(skill, classData);
    }

    updateHealthAndMana(getPlayer());
    updateScoreboard();
    return classes.get(rpgClass.getGroup());
  }
Exemplo n.º 11
0
  /**
   * Professes the player into the class if they are able to. This will reset the class data if the
   * group options are set to reset upon profession. Otherwise, all skills, experience, and levels
   * of the current class under the group will be retained and carried over into the new profession.
   *
   * @param rpgClass class to profess into
   * @return true if successfully professed, false otherwise
   */
  public boolean profess(RPGClass rpgClass) {
    if (rpgClass != null && canProfess(rpgClass)) {
      // Reset data if applicable
      if (SkillAPI.getSettings().getGroupSettings(rpgClass.getGroup()).isProfessReset()) {
        reset(rpgClass.getGroup());
      }

      // Inherit previous class data if any
      PlayerClass current = classes.get(rpgClass.getGroup());
      RPGClass previous;
      if (current == null) {
        previous = null;
        current = new PlayerClass(this, rpgClass);
        classes.put(rpgClass.getGroup(), current);
      } else {
        previous = current.getData();
        current.setClassData(rpgClass);
      }

      // Add skills
      for (Skill skill : rpgClass.getSkills()) {
        if (!skills.containsKey(skill.getKey())) {
          skills.put(skill.getKey(), new PlayerSkill(this, skill, current));
          combos.addSkill(skill);
        }
      }

      Bukkit.getPluginManager()
          .callEvent(new PlayerClassChangeEvent(current, previous, current.getData()));
      updateHealthAndMana(getPlayer());
      updateScoreboard();
      return true;
    } else {
      return false;
    }
  }
Exemplo n.º 12
0
 /**
  * Gives experience to the player from the given source
  *
  * @param amount amount of experience to give
  * @param source source of the experience
  */
 public void giveExp(double amount, ExpSource source) {
   for (PlayerClass playerClass : classes.values()) {
     playerClass.giveExp(amount, source);
   }
 }
Exemplo n.º 13
0
 /**
  * Checks whether or not the player is professed as the class without checking child classes.
  *
  * @param rpgClass class to check
  * @return true if professed as the specific class, false otherwise
  */
 public boolean isExactClass(RPGClass rpgClass) {
   if (rpgClass == null) return false;
   PlayerClass c = classes.get(rpgClass.getGroup());
   return (c != null) && (c.getData() == rpgClass);
 }
Exemplo n.º 14
0
 /**
  * Updates the scoreboard with the player's current class. This is already done by the API and
  * doesn't need to be done by other plugins.
  */
 public void updateScoreboard() {
   PlayerClass main = getMainClass();
   if (main != null && !init) {
     ClassBoardManager.update(this, main.getData().getPrefix(), main.getData().getPrefixColor());
   }
 }