CombatManager luck and critical
This commit is contained in:
parent
64b79663ef
commit
241feba114
1 changed files with 90 additions and 11 deletions
|
@ -2,7 +2,10 @@ package me.unurled.sacredrealms.sr.components.combat;
|
||||||
|
|
||||||
import static me.unurled.sacredrealms.sr.utils.Component.comp;
|
import static me.unurled.sacredrealms.sr.utils.Component.comp;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
import me.unurled.sacredrealms.sr.components.attributes.Attribute;
|
import me.unurled.sacredrealms.sr.components.attributes.Attribute;
|
||||||
|
import me.unurled.sacredrealms.sr.components.player.PlayerManager;
|
||||||
|
import me.unurled.sacredrealms.sr.components.player.SRPlayer;
|
||||||
import me.unurled.sacredrealms.sr.managers.Manager;
|
import me.unurled.sacredrealms.sr.managers.Manager;
|
||||||
import me.unurled.sacredrealms.sr.utils.Items;
|
import me.unurled.sacredrealms.sr.utils.Items;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
|
@ -21,6 +24,9 @@ public class CombatManager extends Manager {
|
||||||
public void onDamage(EntityDamageByBlockEvent e) {
|
public void onDamage(EntityDamageByBlockEvent e) {
|
||||||
// TODO: Implement
|
// TODO: Implement
|
||||||
// blast enchant :shrug:
|
// blast enchant :shrug:
|
||||||
|
// fall damage, fire damage, etc
|
||||||
|
e.setDamage(0.0);
|
||||||
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Finish this
|
// TODO: Finish this
|
||||||
|
@ -28,12 +34,13 @@ public class CombatManager extends Manager {
|
||||||
public void onDamage(EntityDamageByEntityEvent e) {
|
public void onDamage(EntityDamageByEntityEvent e) {
|
||||||
e.setDamage(0.0);
|
e.setDamage(0.0);
|
||||||
|
|
||||||
if (!(e.getDamager() instanceof LivingEntity) || !(e.getEntity() instanceof LivingEntity)) {
|
if (!(e.getDamager() instanceof LivingEntity damager) || !(e.getEntity() instanceof LivingEntity entity)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PlayerManager pm = (PlayerManager) PlayerManager.getInstance(PlayerManager.class);
|
||||||
|
if (pm == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LivingEntity damager = (LivingEntity) e.getDamager();
|
|
||||||
LivingEntity entity = (LivingEntity) e.getEntity();
|
|
||||||
|
|
||||||
if (damager instanceof Player d) {
|
if (damager instanceof Player d) {
|
||||||
if (entity instanceof Player) {
|
if (entity instanceof Player) {
|
||||||
|
@ -45,9 +52,15 @@ public class CombatManager extends Manager {
|
||||||
}
|
}
|
||||||
if (entity instanceof Mob) {
|
if (entity instanceof Mob) {
|
||||||
Double dStrength = Items.getTotalAttribute(d, Attribute.STRENGTH);
|
Double dStrength = Items.getTotalAttribute(d, Attribute.STRENGTH);
|
||||||
|
SRPlayer player = pm.getPlayer(d.getUniqueId());
|
||||||
|
if (player != null) {
|
||||||
|
dStrength += player.getAttribute(Attribute.STRENGTH);
|
||||||
|
}
|
||||||
EntityEquipment equipment = ((Mob) entity).getEquipment();
|
EntityEquipment equipment = ((Mob) entity).getEquipment();
|
||||||
Double eDefense = Items.getTotalAttribute(equipment, Attribute.DEFENSE);
|
Double eDefense = Items.getTotalAttribute(equipment, Attribute.DEFENSE);
|
||||||
|
|
||||||
|
Double damage = dStrength - eDefense;
|
||||||
|
|
||||||
Double dLuck = Items.getTotalAttribute(d, Attribute.LUCK);
|
Double dLuck = Items.getTotalAttribute(d, Attribute.LUCK);
|
||||||
Double eLuck = Items.getTotalAttribute(equipment, Attribute.LUCK);
|
Double eLuck = Items.getTotalAttribute(equipment, Attribute.LUCK);
|
||||||
|
|
||||||
|
@ -56,26 +69,92 @@ public class CombatManager extends Manager {
|
||||||
// 100% chance of miss
|
// 100% chance of miss
|
||||||
luck = -10000d;
|
luck = -10000d;
|
||||||
d.sendMessage(comp("<red>You missed!"));
|
d.sendMessage(comp("<red>You missed!"));
|
||||||
// TODO: play miss sound
|
d.playSound(d, Sound.ENTITY_ARROW_SHOOT, 1.0f, 1.0f);
|
||||||
// d.playSound();
|
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
} else if (luck > 1000) {
|
} else if (luck > 1000) {
|
||||||
// 100% chance of critical hit
|
// 100% chance of critical hit
|
||||||
luck = 10000d;
|
luck = 10000d;
|
||||||
|
d.playSound(d, Sound.ENTITY_PLAYER_ATTACK_CRIT, 1.0f, 1.0f);
|
||||||
|
damage = damage * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (luck < 0) {
|
if (luck < 0) {
|
||||||
// chances of miss
|
// chances of miss
|
||||||
|
Random r = new Random();
|
||||||
} else if (luck > 0) {
|
if (r.nextBoolean()) {
|
||||||
|
d.playSound(d, Sound.ENTITY_ARROW_SHOOT, 1.0f, 1.0f);
|
||||||
|
e.setCancelled(true);
|
||||||
|
d.sendMessage(comp("<red>You missed!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (luck > 0 && luck < 1000) {
|
||||||
// chance of critical hit
|
// chance of critical hit
|
||||||
} else {
|
Random r = new Random();
|
||||||
|
if (r.nextBoolean()) {
|
||||||
|
d.playSound(d, Sound.ENTITY_PLAYER_ATTACK_CRIT, 1.0f, 1.0f);
|
||||||
|
// damage * 2
|
||||||
|
damage = damage * 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// apply damage
|
||||||
|
|
||||||
|
entity.damage(damage);
|
||||||
|
// TODO: check for status effects (apply status effects depending item of damager)
|
||||||
|
}
|
||||||
|
} else if (entity instanceof Player player) {
|
||||||
|
// damager is not player
|
||||||
|
if (damager instanceof Mob) {
|
||||||
|
// get equipment of damager
|
||||||
|
EntityEquipment equipment = ((Mob) damager).getEquipment();
|
||||||
|
Double dStrength = Items.getTotalAttribute(equipment, Attribute.STRENGTH);
|
||||||
|
Double eDefense = Items.getTotalAttribute(player, Attribute.DEFENSE);
|
||||||
|
|
||||||
|
Double damage = dStrength - eDefense;
|
||||||
|
|
||||||
|
Double dLuck = Items.getTotalAttribute(equipment, Attribute.LUCK);
|
||||||
|
Double eLuck = Items.getTotalAttribute(player, Attribute.LUCK);
|
||||||
|
|
||||||
|
Double luck = dLuck - eLuck;
|
||||||
|
|
||||||
|
if (luck < -1000) {
|
||||||
|
// 100% chance of miss
|
||||||
|
luck = -10000d;
|
||||||
|
player.sendMessage(comp("<red>You dodged!"));
|
||||||
|
player.playSound(player, Sound.ENTITY_ARROW_SHOOT, 1.0f, 1.0f);
|
||||||
|
e.setCancelled(true);
|
||||||
|
return;
|
||||||
|
} else if (luck > 1000) {
|
||||||
|
// 100% chance of critical hit
|
||||||
|
luck = 10000d;
|
||||||
|
player.playSound(player, Sound.ENTITY_PLAYER_ATTACK_CRIT, 1.0f, 1.0f);
|
||||||
|
damage = damage * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (luck < 0) {
|
||||||
|
// chances of miss
|
||||||
|
Random r = new Random();
|
||||||
|
if (r.nextBoolean()) {
|
||||||
|
player.playSound(player, Sound.ENTITY_ARROW_SHOOT, 1.0f, 1.0f);
|
||||||
|
e.setCancelled(true);
|
||||||
|
player.sendMessage(comp("<red>You dodged!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (luck > 0 && luck < 1000) {
|
||||||
|
// chance of critical hit
|
||||||
|
Random r = new Random();
|
||||||
|
if (r.nextBoolean()) {
|
||||||
|
player.playSound(player, Sound.ENTITY_PLAYER_ATTACK_CRIT, 1.0f, 1.0f);
|
||||||
|
// damage * 2
|
||||||
|
damage = damage * 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (entity instanceof Player) {
|
|
||||||
|
|
||||||
|
// apply damage
|
||||||
|
player.damage(damage);
|
||||||
|
|
||||||
|
// TODO: check for status effects (apply status effects depending item of damager)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue