From f806705d8f4f7eb51850feb95037771d88cf4229 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Mon, 9 May 2022 09:07:35 +0200 Subject: [PATCH] Debug for all the experience source. Added VanillaExperience & Resource ExperienceSource and added inCombat for Playing Experience Source. --- .../condition/BiomeCondition.java | 2 +- .../condition/Condition.java | 2 +- .../condition/ConditionInstance.java | 2 +- .../condition/DistanceCondition.java | 7 +-- .../condition/LevelCondition.java | 2 +- .../condition/PermissionCondition.java | 2 +- .../condition/WorldCondition.java | 2 +- .../api/event/PlayerExperienceGainEvent.java | 8 +-- .../mmocore/api/load/DefaultMMOLoader.java | 2 +- .../Indyuce/mmocore/api/load/MMOLoader.java | 2 +- .../mmocore/api/player/PlayerData.java | 7 +-- .../mmocore/comp/region/RegionCondition.java | 4 +- .../comp/region/WorldGuardMMOLoader.java | 2 +- .../mmocore/experience/PlayerProfessions.java | 23 ++++---- .../source/ClimbExperienceSource.java | 8 +-- .../source/DamageDealtExperienceSource.java | 26 ++++----- .../source/MoveExperienceSource.java | 23 ++++---- .../source/ProjectileExperienceSource.java | 24 ++++----- .../source/ResourceExperienceSource.java | 1 - .../source/RideExperienceSource.java | 40 ++++++++------ .../source/type/SpecificExperienceSource.java | 6 +-- .../mmocore/listener/BlockListener.java | 2 +- .../listener/profession/FishingListener.java | 2 +- .../mmocore/loot/chest/LootChestRegion.java | 9 ++-- .../mmocore/loot/droptable/DropTable.java | 6 +-- .../loot/droptable/dropitem/DropItem.java | 53 ++++++++++--------- .../droptable/dropitem/DropTableDropItem.java | 2 +- .../mmocore/manager/MMOLoadManager.java | 2 +- .../profession/CustomBlockManager.java | 5 +- .../manager/profession/FishingManager.java | 25 ++++++--- .../Indyuce/mmocore/waypoint/Waypoint.java | 6 +-- 31 files changed, 163 insertions(+), 144 deletions(-) rename src/main/java/net/Indyuce/mmocore/{loot/droptable => api}/condition/BiomeCondition.java (91%) rename src/main/java/net/Indyuce/mmocore/{loot/droptable => api}/condition/Condition.java (84%) rename src/main/java/net/Indyuce/mmocore/{loot/droptable => api}/condition/ConditionInstance.java (93%) rename src/main/java/net/Indyuce/mmocore/{loot/droptable => api}/condition/DistanceCondition.java (88%) rename src/main/java/net/Indyuce/mmocore/{loot/droptable => api}/condition/LevelCondition.java (93%) rename src/main/java/net/Indyuce/mmocore/{loot/droptable => api}/condition/PermissionCondition.java (90%) rename src/main/java/net/Indyuce/mmocore/{loot/droptable => api}/condition/WorldCondition.java (90%) diff --git a/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/BiomeCondition.java b/src/main/java/net/Indyuce/mmocore/api/condition/BiomeCondition.java similarity index 91% rename from src/main/java/net/Indyuce/mmocore/loot/droptable/condition/BiomeCondition.java rename to src/main/java/net/Indyuce/mmocore/api/condition/BiomeCondition.java index 7da08703..a90cbbac 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/BiomeCondition.java +++ b/src/main/java/net/Indyuce/mmocore/api/condition/BiomeCondition.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmocore.loot.droptable.condition; +package net.Indyuce.mmocore.api.condition; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/Condition.java b/src/main/java/net/Indyuce/mmocore/api/condition/Condition.java similarity index 84% rename from src/main/java/net/Indyuce/mmocore/loot/droptable/condition/Condition.java rename to src/main/java/net/Indyuce/mmocore/api/condition/Condition.java index d1445364..8f302a9a 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/Condition.java +++ b/src/main/java/net/Indyuce/mmocore/api/condition/Condition.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmocore.loot.droptable.condition; +package net.Indyuce.mmocore.api.condition; import io.lumine.mythic.lib.api.MMOLineConfig; diff --git a/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/ConditionInstance.java b/src/main/java/net/Indyuce/mmocore/api/condition/ConditionInstance.java similarity index 93% rename from src/main/java/net/Indyuce/mmocore/loot/droptable/condition/ConditionInstance.java rename to src/main/java/net/Indyuce/mmocore/api/condition/ConditionInstance.java index 937b9475..93a9688f 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/ConditionInstance.java +++ b/src/main/java/net/Indyuce/mmocore/api/condition/ConditionInstance.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmocore.loot.droptable.condition; +package net.Indyuce.mmocore.api.condition; import java.util.List; import java.util.stream.Stream; diff --git a/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/DistanceCondition.java b/src/main/java/net/Indyuce/mmocore/api/condition/DistanceCondition.java similarity index 88% rename from src/main/java/net/Indyuce/mmocore/loot/droptable/condition/DistanceCondition.java rename to src/main/java/net/Indyuce/mmocore/api/condition/DistanceCondition.java index 486ce977..9b52203e 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/DistanceCondition.java +++ b/src/main/java/net/Indyuce/mmocore/api/condition/DistanceCondition.java @@ -1,15 +1,10 @@ -package net.Indyuce.mmocore.loot.droptable.condition; +package net.Indyuce.mmocore.api.condition; import io.lumine.mythic.lib.api.MMOLineConfig; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.World; import org.bukkit.entity.Entity; -import org.bukkit.generator.WorldInfo; - - -import java.util.stream.Collectors; public class DistanceCondition extends Condition{ private final Location location; diff --git a/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/LevelCondition.java b/src/main/java/net/Indyuce/mmocore/api/condition/LevelCondition.java similarity index 93% rename from src/main/java/net/Indyuce/mmocore/loot/droptable/condition/LevelCondition.java rename to src/main/java/net/Indyuce/mmocore/api/condition/LevelCondition.java index e3fe2a0d..9d121e7b 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/LevelCondition.java +++ b/src/main/java/net/Indyuce/mmocore/api/condition/LevelCondition.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmocore.loot.droptable.condition; +package net.Indyuce.mmocore.api.condition; import net.Indyuce.mmocore.api.player.PlayerData; import io.lumine.mythic.lib.api.MMOLineConfig; diff --git a/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/PermissionCondition.java b/src/main/java/net/Indyuce/mmocore/api/condition/PermissionCondition.java similarity index 90% rename from src/main/java/net/Indyuce/mmocore/loot/droptable/condition/PermissionCondition.java rename to src/main/java/net/Indyuce/mmocore/api/condition/PermissionCondition.java index 0d009b44..f6bd9f58 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/PermissionCondition.java +++ b/src/main/java/net/Indyuce/mmocore/api/condition/PermissionCondition.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmocore.loot.droptable.condition; +package net.Indyuce.mmocore.api.condition; import io.lumine.mythic.lib.api.MMOLineConfig; import org.bukkit.entity.Player; diff --git a/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/WorldCondition.java b/src/main/java/net/Indyuce/mmocore/api/condition/WorldCondition.java similarity index 90% rename from src/main/java/net/Indyuce/mmocore/loot/droptable/condition/WorldCondition.java rename to src/main/java/net/Indyuce/mmocore/api/condition/WorldCondition.java index 35e6341d..1985f732 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/WorldCondition.java +++ b/src/main/java/net/Indyuce/mmocore/api/condition/WorldCondition.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmocore.loot.droptable.condition; +package net.Indyuce.mmocore.api.condition; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/net/Indyuce/mmocore/api/event/PlayerExperienceGainEvent.java b/src/main/java/net/Indyuce/mmocore/api/event/PlayerExperienceGainEvent.java index 72ed5928..bd48b40d 100644 --- a/src/main/java/net/Indyuce/mmocore/api/event/PlayerExperienceGainEvent.java +++ b/src/main/java/net/Indyuce/mmocore/api/event/PlayerExperienceGainEvent.java @@ -16,14 +16,14 @@ public class PlayerExperienceGainEvent extends PlayerDataEvent implements Cancel private final Profession profession; private final EXPSource source; - private int experience; + private double experience; private boolean cancelled; - public PlayerExperienceGainEvent(PlayerData player, int experience, EXPSource source) { + public PlayerExperienceGainEvent(PlayerData player, double experience, EXPSource source) { this(player, null, experience, source); } - public PlayerExperienceGainEvent(PlayerData player, @Nullable Profession profession, int experience, EXPSource source) { + public PlayerExperienceGainEvent(PlayerData player, @Nullable Profession profession, double experience, EXPSource source) { super(player); this.profession = profession; @@ -31,7 +31,7 @@ public class PlayerExperienceGainEvent extends PlayerDataEvent implements Cancel this.source = source; } - public int getExperience() { + public double getExperience() { return experience; } diff --git a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java index 970c2c09..09524a8c 100644 --- a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java @@ -2,7 +2,7 @@ package net.Indyuce.mmocore.api.load; import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser; import net.Indyuce.mmocore.experience.source.*; -import net.Indyuce.mmocore.loot.droptable.condition.*; +import net.Indyuce.mmocore.api.condition.*; import org.bukkit.configuration.ConfigurationSection; import net.Indyuce.mmocore.api.block.BlockType; diff --git a/src/main/java/net/Indyuce/mmocore/api/load/MMOLoader.java b/src/main/java/net/Indyuce/mmocore/api/load/MMOLoader.java index c3065e0e..91489e44 100644 --- a/src/main/java/net/Indyuce/mmocore/api/load/MMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/api/load/MMOLoader.java @@ -2,7 +2,7 @@ package net.Indyuce.mmocore.api.load; import io.lumine.mythic.lib.api.MMOLineConfig; import net.Indyuce.mmocore.api.block.BlockType; -import net.Indyuce.mmocore.loot.droptable.condition.Condition; +import net.Indyuce.mmocore.api.condition.Condition; import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem; import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser; import net.Indyuce.mmocore.experience.source.type.ExperienceSource; diff --git a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 75c9d6bc..13a84cf9 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -70,7 +70,8 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc */ @Nullable private PlayerClass profess; - private int level, experience, classPoints, skillPoints, attributePoints, attributeReallocationPoints;// skillReallocationPoints, + private int level, classPoints, skillPoints, attributePoints, attributeReallocationPoints;// skillReallocationPoints, + private double experience; private double mana, stamina, stellium; private Guild guild; private SkillCastingHandler skillCasting; @@ -547,7 +548,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc member.giveExperience(value, EXPSource.PARTY_SHARING, null, false); } - PlayerExperienceGainEvent event = new PlayerExperienceGainEvent(this, (int) value, source); + PlayerExperienceGainEvent event = new PlayerExperienceGainEvent(this, value, source); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) return; @@ -588,7 +589,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc refreshVanillaExp(); } - public int getExperience() { + public double getExperience() { return experience; } diff --git a/src/main/java/net/Indyuce/mmocore/comp/region/RegionCondition.java b/src/main/java/net/Indyuce/mmocore/comp/region/RegionCondition.java index dbe80a15..21e9bd7a 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/region/RegionCondition.java +++ b/src/main/java/net/Indyuce/mmocore/comp/region/RegionCondition.java @@ -3,8 +3,8 @@ package net.Indyuce.mmocore.comp.region; import java.util.Arrays; import java.util.List; -import net.Indyuce.mmocore.loot.droptable.condition.Condition; -import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance; +import net.Indyuce.mmocore.api.condition.Condition; +import net.Indyuce.mmocore.api.condition.ConditionInstance; import io.lumine.mythic.lib.api.MMOLineConfig; public class RegionCondition extends Condition { diff --git a/src/main/java/net/Indyuce/mmocore/comp/region/WorldGuardMMOLoader.java b/src/main/java/net/Indyuce/mmocore/comp/region/WorldGuardMMOLoader.java index 0c771cf7..949f2335 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/region/WorldGuardMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/comp/region/WorldGuardMMOLoader.java @@ -1,6 +1,6 @@ package net.Indyuce.mmocore.comp.region; -import net.Indyuce.mmocore.loot.droptable.condition.Condition; +import net.Indyuce.mmocore.api.condition.Condition; import net.Indyuce.mmocore.api.load.MMOLoader; import io.lumine.mythic.lib.api.MMOLineConfig; diff --git a/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java b/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java index f7dd9963..887e45b0 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java +++ b/src/main/java/net/Indyuce/mmocore/experience/PlayerProfessions.java @@ -26,7 +26,7 @@ import java.util.Map; import java.util.Map.Entry; public class PlayerProfessions { - private final Map exp = new HashMap<>(); + private final Map exp = new HashMap<>(); private final Map level = new HashMap<>(); private final PlayerData playerData; @@ -41,7 +41,7 @@ public class PlayerProfessions { public PlayerProfessions load(ConfigurationSection config) { for (String key : config.getKeys(false)) if (MMOCore.plugin.professionManager.has(key)) { - exp.put(key, config.getInt(key + ".exp")); + exp.put(key, config.getDouble(key + ".exp")); level.put(key, config.getInt(key + ".level")); } @@ -89,7 +89,7 @@ public class PlayerProfessions { for (Entry entry : obj.entrySet()) if (MMOCore.plugin.professionManager.has(entry.getKey())) { JsonObject value = entry.getValue().getAsJsonObject(); - exp.put(entry.getKey(), value.get("exp").getAsInt()); + exp.put(entry.getKey(), value.get("exp").getAsDouble()); level.put(entry.getKey(), value.get("level").getAsInt()); } @@ -111,11 +111,11 @@ public class PlayerProfessions { return getLevel(profession.getId()); } - public int getExperience(String id) { - return exp.getOrDefault(id, 0); + public double getExperience(String id) { + return exp.getOrDefault(id, 0.); } - public int getExperience(Profession profession) { + public double getExperience(Profession profession) { return getExperience(profession.getId()); } @@ -136,7 +136,7 @@ public class PlayerProfessions { level.put(profession.getId(), Math.max(1, current - value)); } - public void setExperience(Profession profession, int value) { + public void setExperience(Profession profession, double value) { exp.put(profession.getId(), value); } @@ -147,7 +147,7 @@ public class PlayerProfessions { giveExperience(profession, total, source); } - public void giveExperience(Profession profession, int value, EXPSource source) { + public void giveExperience(Profession profession, double value, EXPSource source) { giveExperience(profession, value, source, null); } @@ -172,13 +172,14 @@ public class PlayerProfessions { if (hologramLocation != null) MMOCoreUtils.displayIndicator(hologramLocation.add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message()); - PlayerExperienceGainEvent event = new PlayerExperienceGainEvent(playerData, profession, (int) value, source); + PlayerExperienceGainEvent event = new PlayerExperienceGainEvent(playerData, profession, value, source); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) return; - exp.put(profession.getId(), Math.max(0, exp.getOrDefault(profession.getId(), 0) + event.getExperience())); - int needed, exp, level, oldLevel = getLevel(profession); + exp.put(profession.getId(), Math.max(0, exp.getOrDefault(profession.getId(), 0.) + event.getExperience())); + int level, oldLevel = getLevel(profession); + double needed,exp; /* * Loop for exp overload when leveling up, will continue diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/ClimbExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/ClimbExperienceSource.java index 5e0c79c6..c26ebd0a 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/source/ClimbExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/experience/source/ClimbExperienceSource.java @@ -45,11 +45,11 @@ public class ClimbExperienceSource extends SpecificExperienceSource { return new ExperienceSourceManager() { @EventHandler public void onClimb(PlayerMoveEvent e) { - if (e.getPlayer().hasMetadata("NPC")) - return; - PlayerData playerData = PlayerData.get(e.getPlayer()); - double delta = e.getTo().getY() - e.getFrom().getY(); + double delta=e.getTo().getBlockY()-e.getFrom().getBlockY(); if (delta > 0) { + if (e.getPlayer().hasMetadata("NPC")) + return; + PlayerData playerData = PlayerData.get(e.getPlayer()); for (ClimbExperienceSource source : getSources()) { if (source.matchesParameter(playerData, e.getFrom().getBlock().getType())) source.giveExperience(playerData, delta, null); diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/DamageDealtExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/DamageDealtExperienceSource.java index 8ebd1363..7e1c91ac 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/source/DamageDealtExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/experience/source/DamageDealtExperienceSource.java @@ -20,7 +20,7 @@ public class DamageDealtExperienceSource extends SpecificExperienceSource newManager() { return new ExperienceSourceManager() { @EventHandler public void onDamageDealt(PlayerAttackEvent e) { - if(e.getPlayer().hasMetadata("NPC")) - return; - PlayerData playerData=PlayerData.get(e.getPlayer()); - for(DamagePacket packet:e.getDamage().getPackets()) { - for(DamageType damageType:packet.getTypes()) { - - for(DamageDealtExperienceSource source: getSources()) { - if(source.matchesParameter(playerData,damageType)) - source.giveExperience(playerData, packet.getFinalValue(), null); + PlayerData playerData = PlayerData.get(e.getPlayer()); + for (DamageDealtExperienceSource source : getSources()) { + double value = 0; + for (DamagePacket packet : e.getDamage().getPackets()) { + for (DamageType damageType : packet.getTypes()) { + if (source.matchesParameter(playerData, damageType)) + value += packet.getFinalValue(); } - } + } + source.giveExperience(playerData, value, null); } } @@ -63,7 +63,7 @@ public class DamageDealtExperienceSource extends SpecificExperienceSource() { @EventHandler public void onMove(PlayerMoveEvent e) { - if(e.getPlayer().hasMetadata("NPC")) - return; - Player player=e.getPlayer(); - - PlayerData playerData =PlayerData.get(player); - for(MoveExperienceSource source:getSources()) { - if(source.matchesParameter(playerData,null)) { - giveExperience(playerData,e.getTo().distance(e.getFrom()),null); + double deltax=e.getTo().getBlockX()-e.getFrom().getBlockX(); + double deltay=e.getTo().getBlockY()-e.getFrom().getBlockY(); + double deltaz=e.getTo().getBlockZ()-e.getFrom().getBlockZ(); + if(deltax!=0&&deltay!=0&&deltaz!=0) { + double delta=Math.sqrt(deltax*deltax+deltay*deltay+deltaz*deltaz); + if(e.getPlayer().hasMetadata("NPC")) + return; + Player player=e.getPlayer(); + PlayerData playerData =PlayerData.get(player); + for(MoveExperienceSource source:getSources()) { + if(source.matchesParameter(playerData,null)) { + giveExperience(playerData,delta,null); + } } } } @@ -58,7 +63,7 @@ public class MoveExperienceSource extends SpecificExperienceSource { @Override public boolean matchesParameter(PlayerData player, Object obj) { - return type.matches(player.getPlayer()); + return type==null||type.matches(player.getPlayer()); } public enum MovingType { diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/ProjectileExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/ProjectileExperienceSource.java index ac2029bd..6a2960c6 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/source/ProjectileExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/experience/source/ProjectileExperienceSource.java @@ -31,10 +31,10 @@ public class ProjectileExperienceSource extends SpecificExperienceSource p instanceof Arrow), - TRIDENT((p)-> p instanceof Trident), - FIREBALL((p)-> p instanceof Fireball), - FISH_HOOK((p)-> p instanceof FishHook), - ; + ARROW((p) -> p instanceof Arrow), + TRIDENT((p) -> p instanceof Trident); - private final Function matching; + private final Function matching; - ProjectileType(Function matching) { - this.matching=matching; + ProjectileType(Function matching) { + this.matching = matching; } diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/ResourceExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/ResourceExperienceSource.java index 5b615af9..7b9463d3 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/source/ResourceExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/experience/source/ResourceExperienceSource.java @@ -43,7 +43,6 @@ public class ResourceExperienceSource extends SpecificExperienceSource> { +public class RideExperienceSource extends SpecificExperienceSource { private final EntityType type; /** - *Gives experience when a player moves riding a certain entity. If no entity type is given it will give xp if you move - *while riding an entity whatever it is. - *The random value you give correspond to the xp you get per block travelled while riding. + * Gives experience when a player moves riding a certain entity. If no entity type is given it will give xp if you move + * while riding an entity whatever it is. + * The random value you give correspond to the xp you get per block travelled while riding. */ public RideExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { super(dispenser, config); @@ -32,7 +32,7 @@ public class RideExperienceSource extends SpecificExperienceSource() { @EventHandler public void onRide(PlayerMoveEvent e) { - if (e.getPlayer().hasMetadata("NPC")) - return; - PlayerData playerData=PlayerData.get(e.getPlayer()); - if(e.getPlayer().isInsideVehicle()) { - Entity vehicle=e.getPlayer().getVehicle(); - for(RideExperienceSource source:getSources()) { - if(source.matchesParameter(playerData,vehicle.getClass())) - giveExperience(playerData,e.getFrom().distance(e.getTo()),null); + + if (e.getPlayer().isInsideVehicle()) { + double deltax = e.getTo().getBlockX() - e.getFrom().getBlockX(); + double deltay = e.getTo().getBlockY() - e.getFrom().getBlockY(); + double deltaz = e.getTo().getBlockZ() - e.getFrom().getBlockZ(); + if (deltax != 0 && deltay != 0 && deltaz != 0) { + double delta = Math.sqrt(deltax * deltax + deltay * deltay + deltaz * deltaz); + if (e.getPlayer().hasMetadata("NPC")) + return; + PlayerData playerData = PlayerData.get(e.getPlayer()); + Entity vehicle = e.getPlayer().getVehicle(); + for (RideExperienceSource source : getSources()) { + if (source.matchesParameter(playerData, vehicle.getType())) + giveExperience(playerData, e.getFrom().distance(e.getTo()), null); + } } } } + }; } @Override - public boolean matchesParameter(PlayerData player, Class obj) { - if(type==null) + public boolean matchesParameter(PlayerData player, EntityType obj) { + if (type == null) return true; - return type.getEntityClass().isAssignableFrom(obj); + return type.equals(obj); } } diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/type/SpecificExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/type/SpecificExperienceSource.java index b6b0dd9a..05cf0b3d 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/source/type/SpecificExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/experience/source/type/SpecificExperienceSource.java @@ -29,8 +29,8 @@ public abstract class SpecificExperienceSource extends ExperienceSource { return amount; } - public int rollAmount() { - return amount.calculateInt(); + public double rollAmount() { + return amount.calculate(); } /** @@ -44,8 +44,6 @@ public abstract class SpecificExperienceSource extends ExperienceSource { * @param hologramLocation Location used to display the exp hologram */ public void giveExperience(PlayerData player, double multiplier, @Nullable Location hologramLocation) { - counter+=rollAmount() * multiplier; - Bukkit.broadcastMessage("Gave xp " + counter+ " from " + this.getClass().getSimpleName()); getDispenser().giveExperience(player, rollAmount() * multiplier, hologramLocation, EXPSource.SOURCE); } } diff --git a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java index 3553deca..e9dc299b 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/BlockListener.java @@ -11,7 +11,7 @@ import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.experience.source.MineBlockExperienceSource; import net.Indyuce.mmocore.loot.LootBuilder; -import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance; +import net.Indyuce.mmocore.api.condition.ConditionInstance; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; diff --git a/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java b/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java index 19ec3c4f..fe678f07 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java @@ -80,7 +80,7 @@ public class FishingListener implements Listener { public FishingData(Player player, FishHook hook, FishingDropTable table) { this.location = hook.getLocation(); - this.caught = table.getRandomItem(); + this.caught = table.getRandomItem(PlayerData.get(player)); this.playerData = PlayerData.get(this.player = player); this.hook = hook; diff --git a/src/main/java/net/Indyuce/mmocore/loot/chest/LootChestRegion.java b/src/main/java/net/Indyuce/mmocore/loot/chest/LootChestRegion.java index 6e265a3b..99773f8a 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/chest/LootChestRegion.java +++ b/src/main/java/net/Indyuce/mmocore/loot/chest/LootChestRegion.java @@ -125,17 +125,18 @@ public class LootChestRegion { //chance=8-> tierChance=sqrt(tierChance) double sum = 0; for (ChestTier tier : tiers) { - sum += Math.pow(tier.chance, 1 / Math.pow((1 + chance),1/3)); + sum += Math.pow(tier.chance, 1 / Math.log(1 + chance)); } - + double randomCoefficient=random.nextDouble(); double s=0; for (ChestTier tier : tiers) { s+=Math.pow(tier.chance, 1 / Math.pow((1 + chance),1/3))/sum; - if (random.nextDouble() < s) + if (randomCoefficient < s) return tier; } - return tiers.stream().findAny().orElse(null); + + throw new NullPointerException("Could not find item in the tier list"); } public Location getRandomLocation(Location center) { diff --git a/src/main/java/net/Indyuce/mmocore/loot/droptable/DropTable.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/DropTable.java index 1cce3177..dd8e4db2 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/droptable/DropTable.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/DropTable.java @@ -5,8 +5,8 @@ import java.util.List; import java.util.Set; import java.util.logging.Level; -import net.Indyuce.mmocore.loot.droptable.condition.Condition; -import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance; +import net.Indyuce.mmocore.api.condition.Condition; +import net.Indyuce.mmocore.api.condition.ConditionInstance; import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem; import org.apache.commons.lang.Validate; import org.bukkit.configuration.ConfigurationSection; @@ -73,7 +73,7 @@ public class DropTable extends PostLoadObject { public List collect(LootBuilder builder) { for (DropItem item : drops) - if (item.rollChance() && builder.getCapacity() >= item.getWeight()) { + if (item.rollChance(builder.getEntity()) && builder.getCapacity() >= item.getWeight()) { item.collect(builder); builder.reduceCapacity(item.getWeight()); } diff --git a/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropItem.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropItem.java index 05d99b44..143ebbca 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropItem.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropItem.java @@ -2,41 +2,46 @@ package net.Indyuce.mmocore.loot.droptable.dropitem; import java.util.Random; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.api.player.stats.StatType; import net.Indyuce.mmocore.loot.LootBuilder; import net.Indyuce.mmocore.api.util.math.formula.RandomAmount; import io.lumine.mythic.lib.api.MMOLineConfig; public abstract class DropItem { - protected static final Random random = new Random(); + protected static final Random random = new Random(); - private final double chance, weight; - private final RandomAmount amount; + private final double chance, weight; + private final RandomAmount amount; - public DropItem(MMOLineConfig config) { - chance = config.args().length > 0 ? Double.parseDouble(config.args()[0]) : 1; - amount = config.args().length > 1 ? new RandomAmount(config.args()[1]) : new RandomAmount(1, 1); - weight = config.args().length > 2 ? Double.parseDouble(config.args()[2]) : 0; - } + public DropItem(MMOLineConfig config) { + chance = config.args().length > 0 ? Double.parseDouble(config.args()[0]) : 1; + amount = config.args().length > 1 ? new RandomAmount(config.args()[1]) : new RandomAmount(1, 1); + weight = config.args().length > 2 ? Double.parseDouble(config.args()[2]) : 0; + } - public RandomAmount getAmount() { - return amount; - } + public RandomAmount getAmount() { + return amount; + } - public double getChance() { - return chance; - } + public double getChance() { + return chance; + } - public double getWeight() { - return weight; - } + public double getWeight() { + return weight; + } - public int rollAmount() { - return amount.calculateInt(); - } + public int rollAmount() { + return amount.calculateInt(); + } - public boolean rollChance() { - return random.nextDouble() < chance; - } + /** + * If the player chance is 0 the random value will remain the same. When he get lucks the chance gets closer to one. + */ + public boolean rollChance(PlayerData player) { + return Math.pow(random.nextDouble(), 1 / Math.log(1 + player.getStats().getStat(StatType.CHANCE))) < chance; + } - public abstract void collect(LootBuilder builder); + public abstract void collect(LootBuilder builder); } diff --git a/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropTableDropItem.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropTableDropItem.java index 02123b38..5b52a5a5 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropTableDropItem.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropTableDropItem.java @@ -3,7 +3,7 @@ package net.Indyuce.mmocore.loot.droptable.dropitem; import io.lumine.mythic.lib.api.MMOLineConfig; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.loot.droptable.DropTable; -import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance; +import net.Indyuce.mmocore.api.condition.ConditionInstance; import net.Indyuce.mmocore.loot.LootBuilder; import net.Indyuce.mmocore.api.player.PlayerData; import org.apache.commons.lang.Validate; diff --git a/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java b/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java index 67f7c279..6f397d4f 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/MMOLoadManager.java @@ -11,7 +11,7 @@ import org.bukkit.configuration.ConfigurationSection; import com.google.gson.JsonParseException; import net.Indyuce.mmocore.api.block.BlockType; -import net.Indyuce.mmocore.loot.droptable.condition.Condition; +import net.Indyuce.mmocore.api.condition.Condition; import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem; import net.Indyuce.mmocore.experience.source.type.ExperienceSource; import net.Indyuce.mmocore.api.load.DefaultMMOLoader; diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/CustomBlockManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/CustomBlockManager.java index c6e72d9e..8264da46 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/CustomBlockManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/CustomBlockManager.java @@ -7,11 +7,10 @@ import net.Indyuce.mmocore.api.block.BlockInfo.RegeneratingBlock; import net.Indyuce.mmocore.api.block.BlockType; import net.Indyuce.mmocore.api.block.SkullBlockType; import net.Indyuce.mmocore.api.block.VanillaBlockType; -import net.Indyuce.mmocore.loot.droptable.condition.Condition; -import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance; +import net.Indyuce.mmocore.api.condition.Condition; +import net.Indyuce.mmocore.api.condition.ConditionInstance; import net.Indyuce.mmocore.api.util.MMOCoreUtils; import io.lumine.mythic.lib.api.MMOLineConfig; -import net.Indyuce.mmocore.manager.profession.SpecificProfessionManager; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java index aa9e1738..d2d94a37 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java @@ -2,8 +2,10 @@ package net.Indyuce.mmocore.manager.profession; import io.lumine.mythic.lib.api.MMOLineConfig; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.loot.droptable.condition.Condition; -import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.api.player.stats.StatType; +import net.Indyuce.mmocore.api.condition.Condition; +import net.Indyuce.mmocore.api.condition.ConditionInstance; import net.Indyuce.mmocore.loot.droptable.dropitem.fishing.FishingDropItem; import org.apache.commons.lang.Validate; import org.bukkit.configuration.ConfigurationSection; @@ -90,12 +92,23 @@ public class FishingManager extends SpecificProfessionManager { return conditions; } - public FishingDropItem getRandomItem() { - double randomCoefficient = RANDOM.nextDouble() * maxWeight; + /** + * The Fishing Drop Item is calculated randomly bu the chance stat will make + * low weight items more likely to be caught. + */ + public FishingDropItem getRandomItem(PlayerData player) { + double chance = player.getStats().getStat(StatType.CHANCE); - for (FishingDropItem item : items) - if ((randomCoefficient -= item.getItem().getWeight()) <= 0) + //chance=0 ->the tier.chance remains the same + //chance ->+inf -> the tier.chance becomes the same for everyone, uniform law + //chance=8-> tierChance=sqrt(tierChance) + double sum = 0; + double randomCoefficient=RANDOM.nextDouble(); + for (FishingDropItem item : items) { + sum += Math.pow(item.getItem().getWeight(), 1 / Math.log(1 + chance)); + if(sum