Debug for all the experience source.

Added VanillaExperience & Resource ExperienceSource and added inCombat for Playing Experience Source.
This commit is contained in:
Guillaume 2022-05-09 09:07:35 +02:00
parent 2411dae631
commit f806705d8f
31 changed files with 163 additions and 144 deletions

View File

@ -1,4 +1,4 @@
package net.Indyuce.mmocore.loot.droptable.condition; package net.Indyuce.mmocore.api.condition;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;

View File

@ -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 io.lumine.mythic.lib.api.MMOLineConfig;

View File

@ -1,4 +1,4 @@
package net.Indyuce.mmocore.loot.droptable.condition; package net.Indyuce.mmocore.api.condition;
import java.util.List; import java.util.List;
import java.util.stream.Stream; import java.util.stream.Stream;

View File

@ -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 io.lumine.mythic.lib.api.MMOLineConfig;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.generator.WorldInfo;
import java.util.stream.Collectors;
public class DistanceCondition extends Condition{ public class DistanceCondition extends Condition{
private final Location location; private final Location location;

View File

@ -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 net.Indyuce.mmocore.api.player.PlayerData;
import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.MMOLineConfig;

View File

@ -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 io.lumine.mythic.lib.api.MMOLineConfig;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -1,4 +1,4 @@
package net.Indyuce.mmocore.loot.droptable.condition; package net.Indyuce.mmocore.api.condition;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;

View File

@ -16,14 +16,14 @@ public class PlayerExperienceGainEvent extends PlayerDataEvent implements Cancel
private final Profession profession; private final Profession profession;
private final EXPSource source; private final EXPSource source;
private int experience; private double experience;
private boolean cancelled; private boolean cancelled;
public PlayerExperienceGainEvent(PlayerData player, int experience, EXPSource source) { public PlayerExperienceGainEvent(PlayerData player, double experience, EXPSource source) {
this(player, null, experience, 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); super(player);
this.profession = profession; this.profession = profession;
@ -31,7 +31,7 @@ public class PlayerExperienceGainEvent extends PlayerDataEvent implements Cancel
this.source = source; this.source = source;
} }
public int getExperience() { public double getExperience() {
return experience; return experience;
} }

View File

@ -2,7 +2,7 @@ package net.Indyuce.mmocore.api.load;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser; import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.*; 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 org.bukkit.configuration.ConfigurationSection;
import net.Indyuce.mmocore.api.block.BlockType; import net.Indyuce.mmocore.api.block.BlockType;

View File

@ -2,7 +2,7 @@ package net.Indyuce.mmocore.api.load;
import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.api.block.BlockType; 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.loot.droptable.dropitem.DropItem;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser; import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource; import net.Indyuce.mmocore.experience.source.type.ExperienceSource;

View File

@ -70,7 +70,8 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
*/ */
@Nullable @Nullable
private PlayerClass profess; 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 double mana, stamina, stellium;
private Guild guild; private Guild guild;
private SkillCastingHandler skillCasting; private SkillCastingHandler skillCasting;
@ -547,7 +548,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
member.giveExperience(value, EXPSource.PARTY_SHARING, null, false); 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); Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) if (event.isCancelled())
return; return;
@ -588,7 +589,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
refreshVanillaExp(); refreshVanillaExp();
} }
public int getExperience() { public double getExperience() {
return experience; return experience;
} }

View File

@ -3,8 +3,8 @@ package net.Indyuce.mmocore.comp.region;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import net.Indyuce.mmocore.loot.droptable.condition.Condition; import net.Indyuce.mmocore.api.condition.Condition;
import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance; import net.Indyuce.mmocore.api.condition.ConditionInstance;
import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.MMOLineConfig;
public class RegionCondition extends Condition { public class RegionCondition extends Condition {

View File

@ -1,6 +1,6 @@
package net.Indyuce.mmocore.comp.region; 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 net.Indyuce.mmocore.api.load.MMOLoader;
import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.MMOLineConfig;

View File

@ -26,7 +26,7 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
public class PlayerProfessions { public class PlayerProfessions {
private final Map<String, Integer> exp = new HashMap<>(); private final Map<String, Double> exp = new HashMap<>();
private final Map<String, Integer> level = new HashMap<>(); private final Map<String, Integer> level = new HashMap<>();
private final PlayerData playerData; private final PlayerData playerData;
@ -41,7 +41,7 @@ public class PlayerProfessions {
public PlayerProfessions load(ConfigurationSection config) { public PlayerProfessions load(ConfigurationSection config) {
for (String key : config.getKeys(false)) for (String key : config.getKeys(false))
if (MMOCore.plugin.professionManager.has(key)) { 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")); level.put(key, config.getInt(key + ".level"));
} }
@ -89,7 +89,7 @@ public class PlayerProfessions {
for (Entry<String, JsonElement> entry : obj.entrySet()) for (Entry<String, JsonElement> entry : obj.entrySet())
if (MMOCore.plugin.professionManager.has(entry.getKey())) { if (MMOCore.plugin.professionManager.has(entry.getKey())) {
JsonObject value = entry.getValue().getAsJsonObject(); 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()); level.put(entry.getKey(), value.get("level").getAsInt());
} }
@ -111,11 +111,11 @@ public class PlayerProfessions {
return getLevel(profession.getId()); return getLevel(profession.getId());
} }
public int getExperience(String id) { public double getExperience(String id) {
return exp.getOrDefault(id, 0); return exp.getOrDefault(id, 0.);
} }
public int getExperience(Profession profession) { public double getExperience(Profession profession) {
return getExperience(profession.getId()); return getExperience(profession.getId());
} }
@ -136,7 +136,7 @@ public class PlayerProfessions {
level.put(profession.getId(), Math.max(1, current - value)); 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); exp.put(profession.getId(), value);
} }
@ -147,7 +147,7 @@ public class PlayerProfessions {
giveExperience(profession, total, source); 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); giveExperience(profession, value, source, null);
} }
@ -172,13 +172,14 @@ public class PlayerProfessions {
if (hologramLocation != null) if (hologramLocation != null)
MMOCoreUtils.displayIndicator(hologramLocation.add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message()); 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); Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) if (event.isCancelled())
return; return;
exp.put(profession.getId(), Math.max(0, exp.getOrDefault(profession.getId(), 0) + event.getExperience())); exp.put(profession.getId(), Math.max(0, exp.getOrDefault(profession.getId(), 0.) + event.getExperience()));
int needed, exp, level, oldLevel = getLevel(profession); int level, oldLevel = getLevel(profession);
double needed,exp;
/* /*
* Loop for exp overload when leveling up, will continue * Loop for exp overload when leveling up, will continue

View File

@ -45,11 +45,11 @@ public class ClimbExperienceSource extends SpecificExperienceSource<Material> {
return new ExperienceSourceManager<ClimbExperienceSource>() { return new ExperienceSourceManager<ClimbExperienceSource>() {
@EventHandler @EventHandler
public void onClimb(PlayerMoveEvent e) { public void onClimb(PlayerMoveEvent e) {
if (e.getPlayer().hasMetadata("NPC")) double delta=e.getTo().getBlockY()-e.getFrom().getBlockY();
return;
PlayerData playerData = PlayerData.get(e.getPlayer());
double delta = e.getTo().getY() - e.getFrom().getY();
if (delta > 0) { if (delta > 0) {
if (e.getPlayer().hasMetadata("NPC"))
return;
PlayerData playerData = PlayerData.get(e.getPlayer());
for (ClimbExperienceSource source : getSources()) { for (ClimbExperienceSource source : getSources()) {
if (source.matchesParameter(playerData, e.getFrom().getBlock().getType())) if (source.matchesParameter(playerData, e.getFrom().getBlock().getType()))
source.giveExperience(playerData, delta, null); source.giveExperience(playerData, delta, null);

View File

@ -20,7 +20,7 @@ public class DamageDealtExperienceSource extends SpecificExperienceSource<Damage
private final DamageType type; private final DamageType type;
/** /**
*Gives experience when a player deals damage of a certain type. If no type is given it will give xp for all * Gives experience when a player deals damage of a certain type. If no type is given it will give xp for all
* the damage type. The random value you give correspond to the xp you get per damage dealt. * the damage type. The random value you give correspond to the xp you get per damage dealt.
*/ */
@ -36,25 +36,25 @@ public class DamageDealtExperienceSource extends SpecificExperienceSource<Damage
" unarmed, on-hit, minion, dot."); " unarmed, on-hit, minion, dot.");
type = DamageType.valueOf(str); type = DamageType.valueOf(str);
}} }
}
@Override @Override
public ExperienceSourceManager<DamageDealtExperienceSource> newManager() { public ExperienceSourceManager<DamageDealtExperienceSource> newManager() {
return new ExperienceSourceManager<DamageDealtExperienceSource>() { return new ExperienceSourceManager<DamageDealtExperienceSource>() {
@EventHandler @EventHandler
public void onDamageDealt(PlayerAttackEvent e) { public void onDamageDealt(PlayerAttackEvent e) {
if(e.getPlayer().hasMetadata("NPC")) PlayerData playerData = PlayerData.get(e.getPlayer());
return; for (DamageDealtExperienceSource source : getSources()) {
PlayerData playerData=PlayerData.get(e.getPlayer()); double value = 0;
for(DamagePacket packet:e.getDamage().getPackets()) { for (DamagePacket packet : e.getDamage().getPackets()) {
for(DamageType damageType:packet.getTypes()) { for (DamageType damageType : packet.getTypes()) {
if (source.matchesParameter(playerData, damageType))
for(DamageDealtExperienceSource source: getSources()) { value += packet.getFinalValue();
if(source.matchesParameter(playerData,damageType))
source.giveExperience(playerData, packet.getFinalValue(), null);
} }
}
}
source.giveExperience(playerData, value, null);
} }
} }
@ -63,7 +63,7 @@ public class DamageDealtExperienceSource extends SpecificExperienceSource<Damage
@Override @Override
public boolean matchesParameter(PlayerData player, DamageType damageType) { public boolean matchesParameter(PlayerData player, DamageType damageType) {
if(type==null) if (type == null)
return true; return true;
else else
return type.equals(damageType); return type.equals(damageType);

View File

@ -42,14 +42,19 @@ public class MoveExperienceSource extends SpecificExperienceSource {
return new ExperienceSourceManager<MoveExperienceSource>() { return new ExperienceSourceManager<MoveExperienceSource>() {
@EventHandler @EventHandler
public void onMove(PlayerMoveEvent e) { public void onMove(PlayerMoveEvent e) {
if(e.getPlayer().hasMetadata("NPC")) double deltax=e.getTo().getBlockX()-e.getFrom().getBlockX();
return; double deltay=e.getTo().getBlockY()-e.getFrom().getBlockY();
Player player=e.getPlayer(); double deltaz=e.getTo().getBlockZ()-e.getFrom().getBlockZ();
if(deltax!=0&&deltay!=0&&deltaz!=0) {
PlayerData playerData =PlayerData.get(player); double delta=Math.sqrt(deltax*deltax+deltay*deltay+deltaz*deltaz);
for(MoveExperienceSource source:getSources()) { if(e.getPlayer().hasMetadata("NPC"))
if(source.matchesParameter(playerData,null)) { return;
giveExperience(playerData,e.getTo().distance(e.getFrom()),null); 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 @Override
public boolean matchesParameter(PlayerData player, Object obj) { public boolean matchesParameter(PlayerData player, Object obj) {
return type.matches(player.getPlayer()); return type==null||type.matches(player.getPlayer());
} }
public enum MovingType { public enum MovingType {

View File

@ -31,10 +31,10 @@ public class ProjectileExperienceSource extends SpecificExperienceSource<Project
public ProjectileExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { public ProjectileExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
super(dispenser, config); super(dispenser, config);
if(!config.contains("type")) if (!config.contains("type"))
projectileType=null; projectileType = null;
else { else {
String str=config.getString("type").toUpperCase().replace("-", "_"); String str = config.getString("type").toUpperCase().replace("-", "_");
Validate.isTrue(Arrays.stream(ProjectileType.values()).map(ProjectileType::toString).collect(Collectors.toList()).contains(str)); Validate.isTrue(Arrays.stream(ProjectileType.values()).map(ProjectileType::toString).collect(Collectors.toList()).contains(str));
projectileType = ProjectileType.valueOf(str); projectileType = ProjectileType.valueOf(str);
} }
@ -54,7 +54,6 @@ public class ProjectileExperienceSource extends SpecificExperienceSource<Project
if (projectile.getShooter() instanceof Player && !((Player) projectile.getShooter()).hasMetadata("NPC")) { if (projectile.getShooter() instanceof Player && !((Player) projectile.getShooter()).hasMetadata("NPC")) {
Player player = (Player) projectile.getShooter(); Player player = (Player) projectile.getShooter();
PlayerData playerData = PlayerData.get(player); PlayerData playerData = PlayerData.get(player);
Validate.isTrue(projectiles.containsKey(projectile));
double distance = projectiles.get(projectile).distance(e.getDamager().getLocation()); double distance = projectiles.get(projectile).distance(e.getDamager().getLocation());
for (ProjectileExperienceSource source : getSources()) { for (ProjectileExperienceSource source : getSources()) {
if (source.matchesParameter(playerData, projectile)) if (source.matchesParameter(playerData, projectile))
@ -83,7 +82,7 @@ public class ProjectileExperienceSource extends SpecificExperienceSource<Project
public void run() { public void run() {
projectiles.remove(e.getEntity()); projectiles.remove(e.getEntity());
} }
}.runTaskLater(MMOCore.plugin, 15 * 20L); }.runTaskLater(MMOCore.plugin, 60 * 20L);
} }
@ -94,23 +93,20 @@ public class ProjectileExperienceSource extends SpecificExperienceSource<Project
@Override @Override
public boolean matchesParameter(PlayerData player, Projectile projectile) { public boolean matchesParameter(PlayerData player, Projectile projectile) {
if(projectileType==null) if (projectileType == null)
return true; return true;
return projectileType.matches(projectile); return projectileType.matches(projectile);
} }
public enum ProjectileType { public enum ProjectileType {
ARROW((p)-> p instanceof Arrow), ARROW((p) -> p instanceof Arrow),
TRIDENT((p)-> p instanceof Trident), TRIDENT((p) -> p instanceof Trident);
FIREBALL((p)-> p instanceof Fireball),
FISH_HOOK((p)-> p instanceof FishHook),
;
private final Function<Projectile,Boolean> matching; private final Function<Projectile, Boolean> matching;
ProjectileType(Function<Projectile,Boolean> matching) { ProjectileType(Function<Projectile, Boolean> matching) {
this.matching=matching; this.matching = matching;
} }

View File

@ -43,7 +43,6 @@ public class ResourceExperienceSource extends SpecificExperienceSource<PlayerRes
public void onResource(PlayerResourceUpdateEvent e) { public void onResource(PlayerResourceUpdateEvent e) {
if (e.getPlayer().hasMetadata("NPC")) if (e.getPlayer().hasMetadata("NPC"))
return; return;
PlayerData playerData = PlayerData.get(e.getPlayer()); PlayerData playerData = PlayerData.get(e.getPlayer());
if(e.getAmount()<0) if(e.getAmount()<0)
for (ResourceExperienceSource source : getSources()) { for (ResourceExperienceSource source : getSources()) {

View File

@ -16,13 +16,13 @@ import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class RideExperienceSource extends SpecificExperienceSource<Class<? extends Entity>> { public class RideExperienceSource extends SpecificExperienceSource<EntityType> {
private final EntityType type; 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 * 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. * while riding an entity whatever it is.
*The random value you give correspond to the xp you get per block travelled while riding. * The random value you give correspond to the xp you get per block travelled while riding.
*/ */
public RideExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { public RideExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
super(dispenser, config); super(dispenser, config);
@ -32,7 +32,7 @@ public class RideExperienceSource extends SpecificExperienceSource<Class<? exten
String str = config.getString("type").toUpperCase().replace("-", "_"); String str = config.getString("type").toUpperCase().replace("-", "_");
Validate.isTrue(Arrays.stream(EntityType.values()).map(Objects::toString).collect(Collectors.toList()).contains(str), Validate.isTrue(Arrays.stream(EntityType.values()).map(Objects::toString).collect(Collectors.toList()).contains(str),
"The type must correspond to an entity that exist in the game."); "The type must correspond to an entity that exist in the game.");
type=EntityType.valueOf(str); type = EntityType.valueOf(str);
} }
} }
@ -42,25 +42,33 @@ public class RideExperienceSource extends SpecificExperienceSource<Class<? exten
return new ExperienceSourceManager<RideExperienceSource>() { return new ExperienceSourceManager<RideExperienceSource>() {
@EventHandler @EventHandler
public void onRide(PlayerMoveEvent e) { public void onRide(PlayerMoveEvent e) {
if (e.getPlayer().hasMetadata("NPC"))
return; if (e.getPlayer().isInsideVehicle()) {
PlayerData playerData=PlayerData.get(e.getPlayer()); double deltax = e.getTo().getBlockX() - e.getFrom().getBlockX();
if(e.getPlayer().isInsideVehicle()) { double deltay = e.getTo().getBlockY() - e.getFrom().getBlockY();
Entity vehicle=e.getPlayer().getVehicle(); double deltaz = e.getTo().getBlockZ() - e.getFrom().getBlockZ();
for(RideExperienceSource source:getSources()) { if (deltax != 0 && deltay != 0 && deltaz != 0) {
if(source.matchesParameter(playerData,vehicle.getClass())) double delta = Math.sqrt(deltax * deltax + deltay * deltay + deltaz * deltaz);
giveExperience(playerData,e.getFrom().distance(e.getTo()),null); 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 @Override
public boolean matchesParameter(PlayerData player, Class<? extends Entity> obj) { public boolean matchesParameter(PlayerData player, EntityType obj) {
if(type==null) if (type == null)
return true; return true;
return type.getEntityClass().isAssignableFrom(obj); return type.equals(obj);
} }
} }

View File

@ -29,8 +29,8 @@ public abstract class SpecificExperienceSource<T> extends ExperienceSource<T> {
return amount; return amount;
} }
public int rollAmount() { public double rollAmount() {
return amount.calculateInt(); return amount.calculate();
} }
/** /**
@ -44,8 +44,6 @@ public abstract class SpecificExperienceSource<T> extends ExperienceSource<T> {
* @param hologramLocation Location used to display the exp hologram * @param hologramLocation Location used to display the exp hologram
*/ */
public void giveExperience(PlayerData player, double multiplier, @Nullable Location hologramLocation) { 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); getDispenser().giveExperience(player, rollAmount() * multiplier, hologramLocation, EXPSource.SOURCE);
} }
} }

View File

@ -11,7 +11,7 @@ import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.experience.source.MineBlockExperienceSource; import net.Indyuce.mmocore.experience.source.MineBlockExperienceSource;
import net.Indyuce.mmocore.loot.LootBuilder; 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.*;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;

View File

@ -80,7 +80,7 @@ public class FishingListener implements Listener {
public FishingData(Player player, FishHook hook, FishingDropTable table) { public FishingData(Player player, FishHook hook, FishingDropTable table) {
this.location = hook.getLocation(); this.location = hook.getLocation();
this.caught = table.getRandomItem(); this.caught = table.getRandomItem(PlayerData.get(player));
this.playerData = PlayerData.get(this.player = player); this.playerData = PlayerData.get(this.player = player);
this.hook = hook; this.hook = hook;

View File

@ -125,17 +125,18 @@ public class LootChestRegion {
//chance=8-> tierChance=sqrt(tierChance) //chance=8-> tierChance=sqrt(tierChance)
double sum = 0; double sum = 0;
for (ChestTier tier : tiers) { 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; double s=0;
for (ChestTier tier : tiers) { for (ChestTier tier : tiers) {
s+=Math.pow(tier.chance, 1 / Math.pow((1 + chance),1/3))/sum; s+=Math.pow(tier.chance, 1 / Math.pow((1 + chance),1/3))/sum;
if (random.nextDouble() < s) if (randomCoefficient < s)
return tier; return tier;
} }
return tiers.stream().findAny().orElse(null);
throw new NullPointerException("Could not find item in the tier list");
} }
public Location getRandomLocation(Location center) { public Location getRandomLocation(Location center) {

View File

@ -5,8 +5,8 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import net.Indyuce.mmocore.loot.droptable.condition.Condition; import net.Indyuce.mmocore.api.condition.Condition;
import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance; import net.Indyuce.mmocore.api.condition.ConditionInstance;
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem; import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -73,7 +73,7 @@ public class DropTable extends PostLoadObject {
public List<ItemStack> collect(LootBuilder builder) { public List<ItemStack> collect(LootBuilder builder) {
for (DropItem item : drops) for (DropItem item : drops)
if (item.rollChance() && builder.getCapacity() >= item.getWeight()) { if (item.rollChance(builder.getEntity()) && builder.getCapacity() >= item.getWeight()) {
item.collect(builder); item.collect(builder);
builder.reduceCapacity(item.getWeight()); builder.reduceCapacity(item.getWeight());
} }

View File

@ -2,41 +2,46 @@ package net.Indyuce.mmocore.loot.droptable.dropitem;
import java.util.Random; 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.loot.LootBuilder;
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount; import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.MMOLineConfig;
public abstract class DropItem { 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 double chance, weight;
private final RandomAmount amount; private final RandomAmount amount;
public DropItem(MMOLineConfig config) { public DropItem(MMOLineConfig config) {
chance = config.args().length > 0 ? Double.parseDouble(config.args()[0]) : 1; 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); 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; weight = config.args().length > 2 ? Double.parseDouble(config.args()[2]) : 0;
} }
public RandomAmount getAmount() { public RandomAmount getAmount() {
return amount; return amount;
} }
public double getChance() { public double getChance() {
return chance; return chance;
} }
public double getWeight() { public double getWeight() {
return weight; return weight;
} }
public int rollAmount() { public int rollAmount() {
return amount.calculateInt(); 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);
} }

View File

@ -3,7 +3,7 @@ package net.Indyuce.mmocore.loot.droptable.dropitem;
import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.loot.droptable.DropTable; 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.loot.LootBuilder;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;

View File

@ -11,7 +11,7 @@ import org.bukkit.configuration.ConfigurationSection;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import net.Indyuce.mmocore.api.block.BlockType; 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.loot.droptable.dropitem.DropItem;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource; import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.api.load.DefaultMMOLoader; import net.Indyuce.mmocore.api.load.DefaultMMOLoader;

View File

@ -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.BlockType;
import net.Indyuce.mmocore.api.block.SkullBlockType; import net.Indyuce.mmocore.api.block.SkullBlockType;
import net.Indyuce.mmocore.api.block.VanillaBlockType; import net.Indyuce.mmocore.api.block.VanillaBlockType;
import net.Indyuce.mmocore.loot.droptable.condition.Condition; import net.Indyuce.mmocore.api.condition.Condition;
import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance; import net.Indyuce.mmocore.api.condition.ConditionInstance;
import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.manager.profession.SpecificProfessionManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;

View File

@ -2,8 +2,10 @@ package net.Indyuce.mmocore.manager.profession;
import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.loot.droptable.condition.Condition; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance; 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 net.Indyuce.mmocore.loot.droptable.dropitem.fishing.FishingDropItem;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -90,12 +92,23 @@ public class FishingManager extends SpecificProfessionManager {
return conditions; 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) //chance=0 ->the tier.chance remains the same
if ((randomCoefficient -= item.getItem().getWeight()) <= 0) //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<randomCoefficient)
return item; return item;
}
throw new NullPointerException("Could not find item in drop table"); throw new NullPointerException("Could not find item in drop table");
} }

View File

@ -2,11 +2,10 @@ package net.Indyuce.mmocore.waypoint;
import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.loot.droptable.condition.Condition; import net.Indyuce.mmocore.api.condition.Condition;
import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance; import net.Indyuce.mmocore.api.condition.ConditionInstance;
import net.Indyuce.mmocore.player.Unlockable; import net.Indyuce.mmocore.player.Unlockable;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.apache.logging.log4j.Logger;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -15,7 +14,6 @@ import org.bukkit.craftbukkit.libs.jline.internal.Nullable;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.*; import java.util.*;
import java.util.logging.Level;
public class Waypoint implements Unlockable { public class Waypoint implements Unlockable {
private final String id, name; private final String id, name;