예제 #1
0
  /**
   * Updates the stats of a player based on their current attributes
   *
   * @param data player to update
   */
  public static void updatePlayer(PlayerData data) {
    Player player = data.getPlayer();
    if (player != null) {
      double change = updateStat(data, AttributeManager.HEALTH, player.getMaxHealth());
      data.addMaxHealth(change);

      change = updateStat(data, AttributeManager.MANA, data.getMaxMana());
      data.addMaxMana(change);
    }
  }
예제 #2
0
 private static double updateStat(PlayerData data, String key, double value) {
   Player player = data.getPlayer();
   if (player != null) {
     String mapKey = player.getName() + ":" + key;
     double current = bonuses.containsKey(mapKey) ? bonuses.remove(mapKey) : 0;
     double updated = data.scaleStat(key, value - current) - value + current;
     bonuses.put(mapKey, updated);
     return updated - current;
   }
   return 0;
 }