Debug profession & chance stat

This commit is contained in:
Ka0rX 2022-07-25 10:19:13 +02:00
parent 5e808d48d0
commit e502960a13
4 changed files with 24 additions and 5 deletions

View File

@ -81,6 +81,10 @@
</build>
<repositories>
<repository>
<id>phoenix</id>
<url>http://la-grange-evasion.pro.dns-orange.fr:8081/</url>
</repository>
<repository>
<id>lumine</id>
@ -143,7 +147,7 @@
<dependency>
<groupId>io.lumine</groupId>
<artifactId>MythicLib-dist</artifactId>
<version>1.3.4</version>
<version> 1.3.4</version>
<scope>provided</scope>
</dependency>

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.experience.source;
import com.guillaumevdn.questcreator.lib.event.PlayerKillEntityEvent;
import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.mythic.lib.api.event.PlayerKillEntityEvent;
import net.Indyuce.mmocore.MMOCore;
@ -9,10 +10,12 @@ import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import net.Indyuce.mmocore.api.player.PlayerData;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.persistence.PersistentDataType;
public class KillMobExperienceSource extends SpecificExperienceSource<Entity> {
public final EntityType type;
@ -30,12 +33,12 @@ public class KillMobExperienceSource extends SpecificExperienceSource<Entity> {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void a(PlayerKillEntityEvent event) {
Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> {
if (event.getTarget().isDead() && !event.getTarget().hasMetadata("spawner_spawned")) {
if (event.getKilled().isDead() && !event.getKilled().getPersistentDataContainer().has(new NamespacedKey(MMOCore.plugin,"spawner_spawned"),PersistentDataType.STRING)) {
PlayerData data = PlayerData.get(event.getPlayer());
for (KillMobExperienceSource source : getSources())
if (source.matches(data, event.getTarget()))
source.giveExperience(data, 1, MMOCoreUtils.getCenterLocation(event.getTarget()));
if (source.matches(data, event.getKilled()))
source.giveExperience(data, 1, MMOCoreUtils.getCenterLocation(event.getKilled()));
}
}, 2);
}

View File

@ -1,16 +1,19 @@
package net.Indyuce.mmocore.listener.option;
import net.Indyuce.mmocore.MMOCore;
import org.bukkit.NamespacedKey;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.persistence.PersistentDataType;
public class NoSpawnerEXP implements Listener {
@EventHandler
public void a(CreatureSpawnEvent event) {
if(event.getSpawnReason() == SpawnReason.SPAWNER)
event.getEntity().getPersistentDataContainer().set(new NamespacedKey(MMOCore.plugin,"spawner_spawned"), PersistentDataType.STRING,"true");
event.getEntity().setMetadata("spawner_spawned", new FixedMetadataValue(MMOCore.plugin, true));
}
}

View File

@ -10,6 +10,7 @@ import io.lumine.mythic.lib.api.MMOLineConfig;
public abstract class DropItem {
protected static final Random random = new Random();
private static final double CHANCE_COEFFICIENT = 7. / 100;
private final double chance, weight;
private final RandomAmount amount;
@ -35,11 +36,19 @@ public abstract class DropItem {
return amount.calculateInt();
}
/**
* CHANCE stat = 0 | tier chances are unchanged
* CHANCE stat = +inf | uniform law for any drop item
* CHANCE stat = 100 | all tier chances are taken their square root
*
* @return The real weight of an item considering the player's CHANCE stat.
*/
/**
* 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("CHANCE"))) < chance;
double value=random.nextDouble();
return value< Math.pow(chance, 1 / Math.pow(1 + CHANCE_COEFFICIENT * player.getStats().getStat("CHANCE"), 1.0 / 3.0));
}
public abstract void collect(LootBuilder builder);