!Fixed skill cooldown

This commit is contained in:
Indyuce 2020-04-04 12:02:58 +02:00
parent 6b2cd4d954
commit df24d47c93
4 changed files with 27 additions and 42 deletions

View File

@ -54,8 +54,9 @@ import net.mmogroup.mmolib.version.VersionSound;
public class PlayerData extends OfflinePlayerData { public class PlayerData extends OfflinePlayerData {
/* /*
* is updated everytime the player joins the server. it is kept when the player * is updated everytime the player joins the server. it is kept when the
* is offline so the plugin can use #isOnline to check if the player is online * player is offline so the plugin can use #isOnline to check if the player
* is online
*/ */
private Player player; private Player player;
@ -108,8 +109,7 @@ public class PlayerData extends OfflinePlayerData {
try { try {
profess = profess == null ? null : MMOCore.plugin.classManager.get(profess.getId()); profess = profess == null ? null : MMOCore.plugin.classManager.get(profess.getId());
} catch (NullPointerException exception) { } catch (NullPointerException exception) {
MMOCore.log(Level.SEVERE, MMOCore.log(Level.SEVERE, "[Userdata] Could not find class " + getProfess().getId() + " while refreshing player data.");
"[Userdata] Could not find class " + getProfess().getId() + " while refreshing player data.");
} }
int j = 0; int j = 0;
@ -119,8 +119,7 @@ public class PlayerData extends OfflinePlayerData {
j++; j++;
} catch (NullPointerException notFound) { } catch (NullPointerException notFound) {
boundSkills.remove(j); boundSkills.remove(j);
MMOCore.log(Level.SEVERE, "[Userdata] Could not find skill " + boundSkills.get(j).getSkill().getId() MMOCore.log(Level.SEVERE, "[Userdata] Could not find skill " + boundSkills.get(j).getSkill().getId() + " in class " + getProfess().getId() + " while refreshing player data.");
+ " in class " + getProfess().getId() + " while refreshing player data.");
} }
} }
@ -301,8 +300,7 @@ public class PlayerData extends OfflinePlayerData {
} }
public void heal(double heal) { public void heal(double heal) {
double newest = Math.max(0, double newest = Math.max(0, Math.min(player.getHealth() + heal, player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
Math.min(player.getHealth() + heal, player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
if (player.getHealth() == newest) if (player.getHealth() == newest)
return; return;
@ -348,9 +346,7 @@ public class PlayerData extends OfflinePlayerData {
setLastFriendRequest(System.currentTimeMillis()); setLastFriendRequest(System.currentTimeMillis());
FriendRequest request = new FriendRequest(this, target); FriendRequest request = new FriendRequest(this, target);
new ConfigMessage("friend-request") new ConfigMessage("friend-request").addPlaceholders("player", getPlayer().getName(), "uuid", request.getUniqueId().toString()).sendAsJSon(target.getPlayer());
.addPlaceholders("player", getPlayer().getName(), "uuid", request.getUniqueId().toString())
.sendAsJSon(target.getPlayer());
MMOCore.plugin.requestManager.registerRequest(request); MMOCore.plugin.requestManager.registerRequest(request);
} }
@ -359,12 +355,10 @@ public class PlayerData extends OfflinePlayerData {
giveStellium(-waypoint.getStelliumCost()); giveStellium(-waypoint.getStelliumCost());
new BukkitRunnable() { new BukkitRunnable() {
int x = player.getLocation().getBlockX(), y = player.getLocation().getBlockY(), int x = player.getLocation().getBlockX(), y = player.getLocation().getBlockY(), z = player.getLocation().getBlockZ(), t;
z = player.getLocation().getBlockZ(), t;
public void run() { public void run() {
if (player.getLocation().getBlockX() != x || player.getLocation().getBlockY() != y if (player.getLocation().getBlockX() != x || player.getLocation().getBlockY() != y || player.getLocation().getBlockZ() != z) {
|| player.getLocation().getBlockZ() != z) {
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, .5f); player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, .5f);
MMOCore.plugin.configManager.getSimpleMessage("warping-canceled").send(player); MMOCore.plugin.configManager.getSimpleMessage("warping-canceled").send(player);
giveStellium(waypoint.getStelliumCost()); giveStellium(waypoint.getStelliumCost());
@ -372,8 +366,7 @@ public class PlayerData extends OfflinePlayerData {
return; return;
} }
MMOCore.plugin.configManager.getSimpleMessage("warping-comencing", "left", "" + ((120 - t) / 20)) MMOCore.plugin.configManager.getSimpleMessage("warping-comencing", "left", "" + ((120 - t) / 20)).send(player);
.send(player);
if (t++ >= 100) { if (t++ >= 100) {
player.teleport(waypoint.getLocation()); player.teleport(waypoint.getLocation());
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20, 1, false, false)); player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20, 1, false, false));
@ -382,13 +375,10 @@ public class PlayerData extends OfflinePlayerData {
return; return;
} }
player.playSound(player.getLocation(), VersionSound.BLOCK_NOTE_BLOCK_BELL.toSound(), 1, player.playSound(player.getLocation(), VersionSound.BLOCK_NOTE_BLOCK_BELL.toSound(), 1, (float) (t / Math.PI * .015 + .5));
(float) (t / Math.PI * .015 + .5));
double r = Math.sin((double) t / 100 * Math.PI); double r = Math.sin((double) t / 100 * Math.PI);
for (double j = 0; j < Math.PI * 2; j += Math.PI / 4) for (double j = 0; j < Math.PI * 2; j += Math.PI / 4)
MMOLib.plugin.getVersion().getWrapper().spawnParticle(Particle.REDSTONE, player.getLocation() MMOLib.plugin.getVersion().getWrapper().spawnParticle(Particle.REDSTONE, player.getLocation().add(Math.cos((double) t / 20 + j) * r, (double) t / 50, Math.sin((double) t / 20 + j) * r), 1.25f, Color.PURPLE);
.add(Math.cos((double) t / 20 + j) * r, (double) t / 50, Math.sin((double) t / 20 + j) * r),
1.25f, Color.PURPLE);
} }
}.runTaskTimer(MMOCore.plugin, 0, 1); }.runTaskTimer(MMOCore.plugin, 0, 1);
} }
@ -410,9 +400,7 @@ public class PlayerData extends OfflinePlayerData {
// display hologram // display hologram
if (MMOCore.plugin.getConfig().getBoolean("display-exp-holograms")) if (MMOCore.plugin.getConfig().getBoolean("display-exp-holograms"))
if (loc != null && MMOCore.plugin.hologramSupport != null) if (loc != null && MMOCore.plugin.hologramSupport != null)
MMOCore.plugin.hologramSupport.displayIndicator(loc.add(.5, 1.5, .5), MMOCore.plugin.hologramSupport.displayIndicator(loc.add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message(), getPlayer());
MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message(),
getPlayer());
value = MMOCore.plugin.boosterManager.calculateExp(null, value); value = MMOCore.plugin.boosterManager.calculateExp(null, value);
value *= 1 + getStats().getStat(StatType.ADDITIONAL_EXPERIENCE) / 100; value *= 1 + getStats().getStat(StatType.ADDITIONAL_EXPERIENCE) / 100;
@ -534,8 +522,8 @@ public class PlayerData extends OfflinePlayerData {
} }
/* /*
* returns if the action bar is not being used to display anything else and if * returns if the action bar is not being used to display anything else and
* the general info action bar can be displayed * if the general info action bar can be displayed
*/ */
public boolean canSeeActionBar() { public boolean canSeeActionBar() {
return actionBarTimeOut < System.currentTimeMillis(); return actionBarTimeOut < System.currentTimeMillis();
@ -699,13 +687,10 @@ public class PlayerData extends OfflinePlayerData {
} }
if (!nocd) { if (!nocd) {
double flatCooldownReduction = Math.max(0, Math.min(1, getStats().getStat(StatType.COOLDOWN_REDUCTION) / 100));
flatCooldownReduction *= flatCooldownReduction > 0 ? skill.getModifier("cooldown", getSkillLevel(skill.getSkill())) * 1000 : 0;
// calculate skill cooldown reduction only if stat is higher than 0 skillData.setLastCast(cast.getSkill(), System.currentTimeMillis() - (long) flatCooldownReduction);
// to save performance
double red = getStats().getStat(StatType.COOLDOWN_REDUCTION) * 10;
red *= red > 0 ? skill.getModifier("cooldown", getSkillLevel(skill.getSkill())) : 0;
skillData.setLastCast(cast.getSkill(), System.currentTimeMillis() - (long) red);
giveMana(-cast.getManaCost()); giveMana(-cast.getManaCost());
} }

View File

@ -34,7 +34,7 @@ public class PlayerSkillData {
* up to 3 digits) * up to 3 digits)
*/ */
public long getCooldown(SkillInfo skill) { public long getCooldown(SkillInfo skill) {
return Math.max(0, lastCast(skill.getSkill()) + 1000 * (long) skill.getModifier("cooldown", data.getSkillLevel(skill.getSkill())) - System.currentTimeMillis()); return Math.max(0, lastCast(skill.getSkill()) - System.currentTimeMillis() + (long) (1000. * skill.getModifier("cooldown", data.getSkillLevel(skill.getSkill()))));
} }
public long lastCast(Skill skill) { public long lastCast(Skill skill) {
@ -57,7 +57,7 @@ public class PlayerSkillData {
// ambers = 0; // ambers = 0;
// } // }
public int getCachedModifier(String name) { public double getCachedModifier(String name) {
return cache.containsKey(name) ? cache.get(name).getValue() : 0; return cache.containsKey(name) ? cache.get(name).getValue() : 0;
} }
@ -68,7 +68,7 @@ public class PlayerSkillData {
cacheModifier(mmSkill, "level", cast.getLevel()); cacheModifier(mmSkill, "level", cast.getLevel());
} }
public void cacheModifier(MythicMobSkill skill, String name, int value) { public void cacheModifier(MythicMobSkill skill, String name, double value) {
cache.put(skill.getInternalName() + "." + name, new CachedModifier(value)); cache.put(skill.getInternalName() + "." + name, new CachedModifier(value));
} }
@ -80,9 +80,9 @@ public class PlayerSkillData {
public class CachedModifier { public class CachedModifier {
private final long date = System.currentTimeMillis(); private final long date = System.currentTimeMillis();
private final int value; private final double value;
public CachedModifier(int value) { public CachedModifier(double value) {
this.value = value; this.value = value;
} }
@ -90,7 +90,7 @@ public class PlayerSkillData {
return date + 1000 * 60 < System.currentTimeMillis(); return date + 1000 * 60 < System.currentTimeMillis();
} }
public int getValue() { public double getValue() {
return value; return value;
} }
} }

View File

@ -190,8 +190,8 @@ public abstract class Skill {
modifiers.put(modifier, linear); modifiers.put(modifier, linear);
} }
public int getModifier(String modifier, int level) { public double getModifier(String modifier, int level) {
return (int) modifiers.get(modifier).calculate(level); return modifiers.get(modifier).calculate(level);
} }
public boolean isUnlocked(PlayerData profess) { public boolean isUnlocked(PlayerData profess) {

View File

@ -64,7 +64,7 @@ public class SkillResult {
cancelReason = reason; cancelReason = reason;
} }
public int getModifier(String modifier) { public double getModifier(String modifier) {
return skill.getModifier(modifier, level); return skill.getModifier(modifier, level);
} }