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

View File

@ -34,7 +34,7 @@ public class PlayerSkillData {
* up to 3 digits)
*/
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) {
@ -57,7 +57,7 @@ public class PlayerSkillData {
// ambers = 0;
// }
public int getCachedModifier(String name) {
public double getCachedModifier(String name) {
return cache.containsKey(name) ? cache.get(name).getValue() : 0;
}
@ -68,7 +68,7 @@ public class PlayerSkillData {
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));
}
@ -80,9 +80,9 @@ public class PlayerSkillData {
public class CachedModifier {
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;
}
@ -90,7 +90,7 @@ public class PlayerSkillData {
return date + 1000 * 60 < System.currentTimeMillis();
}
public int getValue() {
public double getValue() {
return value;
}
}

View File

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

View File

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