Esempio n. 1
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());
  }
Esempio n. 2
0
  /**
   * Downgrades a skill owned by the player. The player must own the skill and it must not currently
   * be level 0 for the player to downgrade the skill. This will refund the skill point cost when
   * downgrading the skill.
   *
   * @param skill skill to downgrade
   * @return true if successfully downgraded, false otherwise
   */
  public boolean downgradeSkill(Skill skill) {
    // Cannot be null
    if (skill == null) {
      return false;
    }

    // Must be a valid available skill
    PlayerSkill data = skills.get(skill.getName().toLowerCase());
    if (data == null) {
      return false;
    }

    // Must not be a free skill
    if (data.getCost() == 0) {
      return false;
    }

    // Must not be required by another skill
    for (PlayerSkill s : skills.values()) {
      if (s.getData().getSkillReq() != null
          && s.getData().getSkillReq().equalsIgnoreCase(skill.getName())
          && data.getLevel() <= s.getData().getSkillReqLevel()) {
        return false;
      }
    }

    int cost = skill.getCost(data.getLevel() - 1);
    if (data.getLevel() > 0) {
      // Upgrade event
      PlayerSkillDowngradeEvent event = new PlayerSkillDowngradeEvent(this, data, cost);
      Bukkit.getPluginManager().callEvent(event);
      if (event.isCancelled()) {
        return false;
      }

      // Apply upgrade
      data.getPlayerClass().givePoints(cost, PointSource.REFUND);
      data.addLevels(-1);

      // Passive calls
      Player player = getPlayer();
      if (player != null && skill instanceof PassiveSkill) {
        if (data.getLevel() == 0) {
          ((PassiveSkill) skill).stopEffects(player, 1);
        } else {
          ((PassiveSkill) skill).update(player, data.getLevel() + 1, data.getLevel());
        }
      }

      // Clear bindings
      if (data.getLevel() == 0) {
        clearBinds(skill);
      }

      return true;
    } else {
      return false;
    }
  }
Esempio n. 3
0
  /**
   * Upgrades a skill owned by the player. The player must own the skill, have enough skill points,
   * meet the level and skill requirements, and not have maxed out the skill already in order to
   * upgrade the skill. This will consume the skill point cost while upgrading the skill.
   *
   * @param skill skill to upgrade
   * @return true if successfully was upgraded, false otherwise
   */
  public boolean upgradeSkill(Skill skill) {
    // Cannot be null
    if (skill == null) {
      return false;
    }

    // Must be a valid available skill
    PlayerSkill data = skills.get(skill.getName().toLowerCase());
    if (data == null) {
      return false;
    }

    // Must meet any skill requirements
    if (skill.getSkillReq() != null) {
      PlayerSkill req = skills.get(skill.getSkillReq().toLowerCase());
      if (req != null && req.getLevel() < skill.getSkillReqLevel()) {
        return false;
      }
    }

    int level = data.getPlayerClass().getLevel();
    int points = data.getPlayerClass().getPoints();
    int cost = data.getCost();
    if (!data.isMaxed() && level >= data.getLevelReq() && points >= cost) {
      // Upgrade event
      PlayerSkillUpgradeEvent event = new PlayerSkillUpgradeEvent(this, data, cost);
      Bukkit.getPluginManager().callEvent(event);
      if (event.isCancelled()) {
        return false;
      }

      // Apply upgrade
      data.getPlayerClass().usePoints(cost);
      data.addLevels(1);

      // Passive calls
      Player player = getPlayer();
      if (player != null && skill instanceof PassiveSkill) {
        if (data.getLevel() == 1) {
          ((PassiveSkill) skill).initialize(player, data.getLevel());
        } else {
          ((PassiveSkill) skill).update(player, data.getLevel() - 1, data.getLevel());
        }
      }

      // Unlock event
      if (data.getLevel() == 1) {
        Bukkit.getPluginManager().callEvent(new PlayerSkillUnlockEvent(this, data));
        this.autoLevel();
      }

      return true;
    } else {
      return false;
    }
  }
Esempio n. 4
0
 /**
  * Gives the player a skill using the class data as a parent. This skill will not show up in a
  * skill tree.
  *
  * @param skill skill to give the player
  * @param parent parent class data
  */
 public void giveSkill(Skill skill, PlayerClass parent) {
   String key = skill.getKey();
   if (!skills.containsKey(key)) {
     PlayerSkill data = new PlayerSkill(this, skill, parent);
     combos.addSkill(skill);
     skills.put(key, data);
     autoLevel(skill);
   }
 }
Esempio n. 5
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());
  }
Esempio n. 6
0
 /**
  * Compares skills based on their stats for skill tree arrangement -> Skills with lower
  * level requirements come first -> Then its skills with lower costs -> Then its skills
  * alphabetically
  *
  * @param skill1 skill being compared
  * @param skill2 skill to compare to
  * @return -1, 0, or 1
  */
 @Override
 public int compare(Skill skill1, Skill skill2) {
   return skill1.getLevelReq(0) > skill2.getLevelReq(0)
       ? 1
       : skill1.getLevelReq(0) < skill2.getLevelReq(0)
           ? -1
           : skill1.getName().compareTo(skill2.getName());
 }
Esempio n. 7
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;
    }
  }
Esempio n. 8
0
  private void autoLevel(Skill skill) {
    PlayerSkill data = skills.get(skill.getKey());
    if (data == null) return;

    if (!SkillAPI.isLoaded()) return;

    int lastLevel = data.getLevel();
    while (data.getData().canAutoLevel()
        && !data.isMaxed()
        && data.getLevelReq() <= data.getPlayerClass().getLevel()) {
      upgradeSkill(skill);
      if (lastLevel == data.getLevel()) {
        break;
      }
      lastLevel++;
    }
  }