Update Fighter
This commit is contained in:
parent
a3c8087ebe
commit
576daeb445
@ -1,7 +1,10 @@
|
||||
package de.leafbla.meinkraft.roleplay;
|
||||
|
||||
import de.leafbla.meinkraft.Main;
|
||||
import de.leafbla.meinkraft.roleplay.bomber.BomberRole;
|
||||
import de.leafbla.meinkraft.roleplay.fighter.FighterRole;
|
||||
import de.leafbla.meinkraft.roleplay.ninja.NinjaRole;
|
||||
import de.leafbla.meinkraft.roleplay.wizard.WizardRole;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
@ -1,6 +1,8 @@
|
||||
package de.leafbla.meinkraft.roleplay;
|
||||
package de.leafbla.meinkraft.roleplay.bomber;
|
||||
|
||||
import de.leafbla.meinkraft.Main;
|
||||
import de.leafbla.meinkraft.roleplay.PlayerRole;
|
||||
import de.leafbla.meinkraft.roleplay.Role;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BomberRole extends PlayerRole {
|
@ -23,7 +23,7 @@ public class FighterListener extends RoleListener<FighterRole> {
|
||||
FighterRole role = this.getRole(player);
|
||||
if (event.getCause() != EntityDamageEvent.DamageCause.ENTITY_ATTACK) return;
|
||||
|
||||
role.attackEntity(event.getEntity());
|
||||
role.attackEntity(event.getEntity(), event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -3,103 +3,99 @@ package de.leafbla.meinkraft.roleplay.fighter;
|
||||
import de.leafbla.meinkraft.Main;
|
||||
import de.leafbla.meinkraft.roleplay.PlayerRole;
|
||||
import de.leafbla.meinkraft.roleplay.Role;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class FighterRole extends PlayerRole {
|
||||
|
||||
private int mana;
|
||||
private boolean powerfist;
|
||||
|
||||
public FighterRole(Main plugin, Player player) {
|
||||
super(plugin, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
player.setExp(1);
|
||||
this.setMana(0);
|
||||
this.player.setWalkSpeed(0.3f);
|
||||
this.powerfist = false;
|
||||
this.player.setGravity(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end() {
|
||||
player.setExp(0.5f);
|
||||
this.player.setWalkSpeed(0.2f);
|
||||
|
||||
}
|
||||
|
||||
public void addMana(int mana) {
|
||||
this.setMana(this.mana + mana);
|
||||
}
|
||||
|
||||
private void setMana(int mana) {
|
||||
mana = Math.min(Math.max(0, mana), 100);
|
||||
this.mana = mana;
|
||||
this.updateExp();
|
||||
}
|
||||
|
||||
private void updateExp() {
|
||||
player.setExp((this.mana * 1.0f) / 100f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Role getRole() {
|
||||
return Role.FIGHTER;
|
||||
}
|
||||
|
||||
public void attackEntity(Entity entity) {
|
||||
boolean inAir = false;
|
||||
|
||||
public void attackEntity(Entity entity, EntityDamageByEntityEvent event) {
|
||||
if (!(entity instanceof LivingEntity)) return;
|
||||
LivingEntity len = ((LivingEntity) entity);
|
||||
if (inAir) {
|
||||
event.setCancelled(true);
|
||||
len.damage(event.getDamage());
|
||||
}
|
||||
|
||||
this.player.playSound(player.getLocation(), Sound.BLOCK_ANVIL_LAND, 1, 1);
|
||||
entity.getWorld().dropItem(entity.getLocation(),new ItemStack(Material.STONE));
|
||||
|
||||
if (powerfist) {
|
||||
event.setDamage(event.getDamage() * 4);
|
||||
entity.getWorld().createExplosion(entity.getLocation(), 0f, false, false, player);
|
||||
this.powerfist = false;
|
||||
} else
|
||||
this.addMana(10);
|
||||
}
|
||||
|
||||
public void onInteract(PlayerInteractEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
if (p.isSneaking()) {
|
||||
if (p.getItemInHand().getType() == Material.AIR) {
|
||||
p.setVelocity(new Vector(0, 1, 0));
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
p.setGravity(false);
|
||||
Location loc = p.getLocation();
|
||||
loc.setPitch(0);
|
||||
p.teleport(loc);
|
||||
new BukkitRunnable() {
|
||||
int i = 0;
|
||||
final int MAX = 15;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (++i == MAX) {
|
||||
this.cancel();
|
||||
new BukkitRunnable() {
|
||||
boolean once = true;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (once) {
|
||||
loc.setPitch(38);
|
||||
p.teleport(loc);
|
||||
p.setGravity(true);
|
||||
p.setFallDistance(0);
|
||||
p.setNoDamageTicks(40);
|
||||
p.setVelocity(new Vector(0, -2, 0));
|
||||
once = false;
|
||||
}
|
||||
if (((LivingEntity) p).isOnGround()) {
|
||||
p.getWorld().createExplosion(p.getLocation(), 0f, false, false, p);
|
||||
for (Entity en : p.getNearbyEntities(2, 1, 2)) {
|
||||
if (en instanceof LivingEntity) {
|
||||
LivingEntity len = ((LivingEntity) en);
|
||||
Vector dir = len.getLocation().toVector().subtract(p.getLocation().toVector()).normalize();
|
||||
len.setVelocity(dir.multiply(2).add(new Vector(0, 1, 0)));
|
||||
}
|
||||
}
|
||||
this.cancel();
|
||||
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(plugin, 2, 1);
|
||||
return;
|
||||
}
|
||||
loc.setYaw(((loc.getYaw() + 180 + 360 / MAX) % 360) - 180);
|
||||
p.teleport(loc);
|
||||
}
|
||||
}.runTaskTimer(plugin, 0, 1);
|
||||
}
|
||||
}.runTaskLater(plugin, 15);
|
||||
}
|
||||
} else if (p.getItemInHand().getType() == Material.BLAZE_ROD) {
|
||||
if (p.getItemInHand().getType() == Material.AIR && (event.getAction() == Action.RIGHT_CLICK_BLOCK) && !this.powerfist) {
|
||||
if (this.mana < 30) return;
|
||||
this.addMana(-30);
|
||||
this.powerfist = true;
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_STONE_BREAK, 1f, 1f);
|
||||
p.sendMessage("§eYou ready your fists.");
|
||||
} else if (p.getItemInHand().getType() == Material.CLAY_BALL) {
|
||||
roundHouseKick();
|
||||
}
|
||||
if (p.getItemInHand().getType() == Material.BLAZE_ROD) {
|
||||
for (Entity en : p.getNearbyEntities(5, 5, 5)) {
|
||||
if (en instanceof LivingEntity) {
|
||||
LivingEntity len = ((LivingEntity) en);
|
||||
@ -109,6 +105,143 @@ public class FighterRole extends PlayerRole {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!((LivingEntity) p).isOnGround()) {
|
||||
if (this.player.getLocation().getPitch() < 80) return;
|
||||
groundPound();
|
||||
}
|
||||
if (this.player.getLocation().getPitch() > -80) return;
|
||||
upPunch();
|
||||
}
|
||||
|
||||
private void oldUpDown360Kick() {
|
||||
player.setVelocity(new Vector(0, 1, 0));
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
player.setGravity(false);
|
||||
Location loc = player.getLocation();
|
||||
loc.setPitch(0);
|
||||
player.teleport(loc);
|
||||
new BukkitRunnable() {
|
||||
int i = 0;
|
||||
final int MAX = 15;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (++i == MAX) {
|
||||
this.cancel();
|
||||
new BukkitRunnable() {
|
||||
boolean once = true;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (once) {
|
||||
loc.setPitch(38);
|
||||
player.teleport(loc);
|
||||
player.setGravity(true);
|
||||
player.setFallDistance(0);
|
||||
player.setNoDamageTicks(40);
|
||||
player.setVelocity(new Vector(0, -2, 0));
|
||||
once = false;
|
||||
}
|
||||
if (((LivingEntity) player).isOnGround()) {
|
||||
player.getWorld().createExplosion(player.getLocation(), 0f, false, false, player);
|
||||
for (Entity en : player.getNearbyEntities(2, 1, 2)) {
|
||||
if (en instanceof LivingEntity) {
|
||||
LivingEntity len = ((LivingEntity) en);
|
||||
Vector dir = len.getLocation().toVector().subtract(player.getLocation().toVector()).normalize();
|
||||
len.setVelocity(dir.multiply(2).add(new Vector(0, 1, 0)));
|
||||
}
|
||||
}
|
||||
this.cancel();
|
||||
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(plugin, 2, 1);
|
||||
return;
|
||||
}
|
||||
loc.setYaw(((loc.getYaw() + 180 + 360 / MAX) % 360) - 180);
|
||||
player.teleport(loc);
|
||||
}
|
||||
}.runTaskTimer(plugin, 0, 1);
|
||||
}
|
||||
}.runTaskLater(plugin, 15);
|
||||
}
|
||||
|
||||
private void groundPound() {
|
||||
double startpos = this.player.getLocation().getY();
|
||||
player.setVelocity(new Vector(0, -2, 0));
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
player.setFallDistance(0);
|
||||
|
||||
if (((LivingEntity) player).isOnGround()) {
|
||||
double falldistance = startpos - player.getLocation().getY();
|
||||
if (falldistance > 7)
|
||||
player.getWorld().createExplosion(player.getLocation(), 2f, false, false, player);
|
||||
//for (Entity en : p.getNearbyEntities(2, 1, 2)) {
|
||||
// if (en instanceof LivingEntity) {
|
||||
// LivingEntity len = ((LivingEntity) en);
|
||||
// Vector dir = len.getLocation().toVector().subtract(p.getLocation().toVector()).normalize();
|
||||
// len.setVelocity(dir.multiply(2).add(new Vector(0, 1, 0)));
|
||||
// }
|
||||
//}
|
||||
this.cancel();
|
||||
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(plugin, 0, 1);
|
||||
}
|
||||
|
||||
private void upPunch() {
|
||||
List<LivingEntity> affected = player.getNearbyEntities(1, 1, 1).stream().filter(en -> en instanceof LivingEntity).map(en -> (LivingEntity) en).collect(Collectors.toList());
|
||||
affected.add(player);
|
||||
|
||||
inAir = true;
|
||||
affected.forEach(e -> e.setVelocity(new Vector(0, 2, 0)));
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//player.setGravity(false);
|
||||
affected.forEach(e -> e.setGravity(false));
|
||||
affected.forEach(e -> e.setVelocity(new Vector(0, 0, 0)));
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
affected.forEach(e -> e.setGravity(true));
|
||||
inAir = false;
|
||||
}
|
||||
}.runTaskLater(plugin, 20);
|
||||
}
|
||||
}.runTaskLater(plugin, 12);
|
||||
}
|
||||
|
||||
private void roundHouseKick() {
|
||||
Location loc = player.getLocation();
|
||||
new BukkitRunnable() {
|
||||
int i = 0;
|
||||
final int MAX = 10;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (++i == MAX) {
|
||||
this.cancel();
|
||||
}
|
||||
loc.setYaw(((loc.getYaw() + 180 + 360 / MAX) % 360) - 180);
|
||||
player.teleport(loc);
|
||||
for (Entity en : player.getNearbyEntities(3, 2, 3)) {
|
||||
if (en instanceof LivingEntity) {
|
||||
LivingEntity len = ((LivingEntity) en);
|
||||
Vector dir = len.getLocation().toVector().subtract(player.getLocation().toVector()).normalize();
|
||||
if (Math.abs(dir.angle(player.getLocation().getDirection())) < (2 * Math.PI / MAX)) {
|
||||
len.setVelocity(dir.multiply(2));
|
||||
len.damage(3, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(plugin, 0, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package de.leafbla.meinkraft.roleplay;
|
||||
package de.leafbla.meinkraft.roleplay.ninja;
|
||||
|
||||
import de.leafbla.meinkraft.Main;
|
||||
import de.leafbla.meinkraft.roleplay.PlayerRole;
|
||||
import de.leafbla.meinkraft.roleplay.Role;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class NinjaRole extends PlayerRole {
|
@ -1,6 +1,8 @@
|
||||
package de.leafbla.meinkraft.roleplay;
|
||||
package de.leafbla.meinkraft.roleplay.wizard;
|
||||
|
||||
import de.leafbla.meinkraft.Main;
|
||||
import de.leafbla.meinkraft.roleplay.PlayerRole;
|
||||
import de.leafbla.meinkraft.roleplay.Role;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
Loading…
Reference in New Issue
Block a user