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.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;

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.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 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;

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 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 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.List;

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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 {

View File

@ -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;

View File

@ -26,7 +26,7 @@ import java.util.Map;
import java.util.Map.Entry;
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 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<String, JsonElement> 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

View File

@ -45,11 +45,11 @@ public class ClimbExperienceSource extends SpecificExperienceSource<Material> {
return new ExperienceSourceManager<ClimbExperienceSource>() {
@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);

View File

@ -20,7 +20,7 @@ public class DamageDealtExperienceSource extends SpecificExperienceSource<Damage
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.
*/
@ -36,25 +36,25 @@ public class DamageDealtExperienceSource extends SpecificExperienceSource<Damage
" unarmed, on-hit, minion, dot.");
type = DamageType.valueOf(str);
}}
}
}
@Override
public ExperienceSourceManager<DamageDealtExperienceSource> newManager() {
return new ExperienceSourceManager<DamageDealtExperienceSource>() {
@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<Damage
@Override
public boolean matchesParameter(PlayerData player, DamageType damageType) {
if(type==null)
if (type == null)
return true;
else
return type.equals(damageType);

View File

@ -42,14 +42,19 @@ public class MoveExperienceSource extends SpecificExperienceSource {
return new ExperienceSourceManager<MoveExperienceSource>() {
@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 {

View File

@ -31,10 +31,10 @@ public class ProjectileExperienceSource extends SpecificExperienceSource<Project
public ProjectileExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
super(dispenser, config);
if(!config.contains("type"))
projectileType=null;
if (!config.contains("type"))
projectileType = null;
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));
projectileType = ProjectileType.valueOf(str);
}
@ -54,7 +54,6 @@ public class ProjectileExperienceSource extends SpecificExperienceSource<Project
if (projectile.getShooter() instanceof Player && !((Player) projectile.getShooter()).hasMetadata("NPC")) {
Player player = (Player) projectile.getShooter();
PlayerData playerData = PlayerData.get(player);
Validate.isTrue(projectiles.containsKey(projectile));
double distance = projectiles.get(projectile).distance(e.getDamager().getLocation());
for (ProjectileExperienceSource source : getSources()) {
if (source.matchesParameter(playerData, projectile))
@ -83,7 +82,7 @@ public class ProjectileExperienceSource extends SpecificExperienceSource<Project
public void run() {
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
public boolean matchesParameter(PlayerData player, Projectile projectile) {
if(projectileType==null)
if (projectileType == null)
return true;
return projectileType.matches(projectile);
}
public enum ProjectileType {
ARROW((p)-> 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<Projectile,Boolean> matching;
private final Function<Projectile, Boolean> matching;
ProjectileType(Function<Projectile,Boolean> matching) {
this.matching=matching;
ProjectileType(Function<Projectile, Boolean> matching) {
this.matching = matching;
}

View File

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

View File

@ -16,13 +16,13 @@ import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;
public class RideExperienceSource extends SpecificExperienceSource<Class<? extends Entity>> {
public class RideExperienceSource extends SpecificExperienceSource<EntityType> {
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<Class<? exten
String str = config.getString("type").toUpperCase().replace("-", "_");
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.");
type=EntityType.valueOf(str);
type = EntityType.valueOf(str);
}
}
@ -42,25 +42,33 @@ public class RideExperienceSource extends SpecificExperienceSource<Class<? exten
return new ExperienceSourceManager<RideExperienceSource>() {
@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<? extends Entity> 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);
}
}

View File

@ -29,8 +29,8 @@ public abstract class SpecificExperienceSource<T> extends ExperienceSource<T> {
return amount;
}
public int rollAmount() {
return amount.calculateInt();
public double rollAmount() {
return amount.calculate();
}
/**
@ -44,8 +44,6 @@ public abstract class SpecificExperienceSource<T> extends ExperienceSource<T> {
* @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);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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) {

View File

@ -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<ItemStack> 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());
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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;

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.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;

View File

@ -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<randomCoefficient)
return item;
}
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 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.condition.Condition;
import net.Indyuce.mmocore.api.condition.ConditionInstance;
import net.Indyuce.mmocore.player.Unlockable;
import org.apache.commons.lang.Validate;
import org.apache.logging.log4j.Logger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
@ -15,7 +14,6 @@ import org.bukkit.craftbukkit.libs.jline.internal.Nullable;
import org.bukkit.entity.Player;
import java.util.*;
import java.util.logging.Level;
public class Waypoint implements Unlockable {
private final String id, name;