SteamWar/FightSystem
Archiviert
13
1
Dieser Commit ist enthalten in:
Zeanon 2021-05-18 19:58:31 +02:00
Ursprung 2c981f29ce
Commit 25190098d6

Datei anzeigen

@ -1,3 +1,22 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.event; package de.steamwar.fightsystem.event;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
@ -17,6 +36,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import org.bukkit.scheduler.BukkitTask;
public class HellsBells { public class HellsBells {
@ -66,59 +86,21 @@ public class HellsBells {
public HellsBells() { public HellsBells() {
new StateDependent(Winconditions.HELLS_BELLS, FightState.Running) { new StateDependent(Winconditions.HELLS_BELLS, FightState.Running) {
private HellsBellsEvent event = null; private final World world = Bukkit.getWorlds().get(0);
private final int xLength = Config.RedPasteRegion.getMaxX() - Config.RedPasteRegion.getMinX();
private final int zLength = Config.RedPasteRegion.getMaxZ() - Config.RedPasteRegion.getMinZ();
private State current = State.PRE;
private int currentDrops = 0;
private HellsBellsCountdown currentCountdown;
private BukkitTask currentDropping;
private final List<String> startMessages = Arrays.asList("§c!!Achtung!! Bomber im Anflug, noch ca. eine Minute bis zur Ankunft.",
"§cBomber im Anflug, ca. eine Minute bis zur Ankunft.",
"§cBomber auf dem Radar gesichtet, geschätzte Ankunftszeit: eine Minute.",
"§cUnbekanntes Flugobjekt gesichtet, trifft in ca. einer Minute ein.",
"§cFlugobjekt gesichtet. Ankunft in ca. einer Minute.",
"§cBomber erschienen, Ankunft ca. eine Minute.");
@Override public void startCountdown() {
public void enable() {
if (event != null) {
event.terminate();
}
event = new HellsBellsEvent();
event.init();
}
@Override
public void disable() {
if (event != null) {
event.terminate();
}
event = null;
}
}.register();
}
private static class HellsBellsEvent {
private final World world = Bukkit.getWorlds().get(0);
private final int xLength = Config.RedPasteRegion.getMaxX() - Config.RedPasteRegion.getMinX();
private final int zLength = Config.RedPasteRegion.getMaxZ() - Config.RedPasteRegion.getMinZ();
private State current = State.NONE;
private int currentDrops = 0;
private HellsBellsCountdown currentCountdown;
private static final List<String> startMessages = Arrays.asList("§c!!Achtung!! Bomber im Anflug, noch ca. eine Minute bis zur Ankunft.",
"§cBomber im Anflug, ca. eine Minute bis zur Ankunft.",
"§cBomber auf dem Radar gesichtet, geschätzte Ankunftszeit: eine Minute.",
"§cUnbekanntes Flugobjekt gesichtet, trifft in ca. einer Minute ein.",
"§cFlugobjekt gesichtet. Ankunft in ca. einer Minute.",
"§cBomber erschienen, Ankunft ca. eine Minute.");
public void init() {
current = State.PRE;
currentDrops = 0;
currentCountdown = null;
startCountdown();
}
public void terminate() {
current = State.NONE;
if (currentCountdown != null) {
currentCountdown.disable();
}
}
public void startCountdown() {
if (current != State.NONE) {
if (current == State.PRE) { if (current == State.PRE) {
Bukkit.broadcastMessage(FightSystem.PREFIX + (startMessages.get(random.nextInt(startMessages.size())))); Bukkit.broadcastMessage(FightSystem.PREFIX + (startMessages.get(random.nextInt(startMessages.size()))));
current = current.getNext(); current = current.getNext();
@ -131,31 +113,28 @@ public class HellsBells {
currentCountdown = new HellsBellsCountdown(current.MIN_TIME + random.nextInt(current.MAX_TIME - current.MIN_TIME), SWSound.BLOCK_NOTE_BASS, true); currentCountdown = new HellsBellsCountdown(current.MIN_TIME + random.nextInt(current.MAX_TIME - current.MIN_TIME), SWSound.BLOCK_NOTE_BASS, true);
currentCountdown.enable(); currentCountdown.enable();
} }
}
public void drop() { public void drop() {
Direction direction = Direction.getRandom(); Direction direction = Direction.getRandom();
AtomicInteger length = new AtomicInteger(10 + random.nextInt((direction.zLength ? zLength : xLength) - 10)); AtomicInteger length = new AtomicInteger(10 + random.nextInt((direction.zLength ? zLength : xLength) - 10));
int width = 5 + random.nextInt(5); int width = 5 + random.nextInt(5);
int xOffset = getWidthStart(direction.zLength ? xLength : zLength, direction.zLength ? length.get() : width); int xOffset = getWidthStart(direction.zLength ? xLength : zLength, direction.zLength ? length.get() : width);
int zOffset = getLengthStart(direction.zLength ? zLength : xLength, direction.zLength ? width : length.get()); int zOffset = getLengthStart(direction.zLength ? zLength : xLength, direction.zLength ? width : length.get());
int yOffset = getHeightStart(); int yOffset = getHeightStart();
Point redStart; Point redStart;
Point blueStart; Point blueStart;
if (direction == Direction.NORTH || direction == Direction.WEST) { if (direction == Direction.NORTH || direction == Direction.WEST) {
redStart = new Point(Config.RedPasteRegion.getMaxX() - xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMaxZ() - zOffset); redStart = new Point(Config.RedPasteRegion.getMaxX() - xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMaxZ() - zOffset);
blueStart = new Point(Config.BluePasteRegion.getMinX() + xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMinZ() + zOffset); blueStart = new Point(Config.BluePasteRegion.getMinX() + xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMinZ() + zOffset);
} else { } else {
redStart = new Point(Config.RedPasteRegion.getMinX() + xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMinZ() + zOffset); redStart = new Point(Config.RedPasteRegion.getMinX() + xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMinZ() + zOffset);
blueStart = new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset); blueStart = new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset);
} }
new BukkitRunnable() { currentDropping = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), () -> {
@Override
public void run() {
for (int w = 0; w < width; w++) { for (int w = 0; w < width; w++) {
if (direction == Direction.NORTH || direction == Direction.WEST) { if (direction == Direction.NORTH || direction == Direction.WEST) {
world.spawnEntity(redStart.subtractAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); world.spawnEntity(redStart.subtractAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT);
@ -167,104 +146,113 @@ public class HellsBells {
world.spawnEntity(blueStart.subtractAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); world.spawnEntity(blueStart.subtractAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT);
} }
} }
if (length.addAndGet(-2) <= 0) { if (length.addAndGet(-2) <= 0) {
cancel(); currentDropping.cancel();
} }
}, 0L, 4L);
}
private int getLengthStart(int regionSize, int length) {
return random.nextInt(regionSize - length);
}
private int getWidthStart(int regionSize, int length) {
return random.nextInt(regionSize - length);
}
private int getHeightStart() {
return 5 + random.nextInt(15);
}
class HellsBellsCountdown extends Countdown {
public HellsBellsCountdown(int time, SWSound sound, boolean level) {
super(time, sound, level);
} }
}.runTaskTimer(FightSystem.getPlugin(), 0, 4L);
}
private int getLengthStart(int regionSize, int length) { @Override
return random.nextInt(regionSize - length); public String countdownCounting() {
} return "bis die Bomben fallen";
}
private int getWidthStart(int regionSize, int length) { @Override
return random.nextInt(regionSize - length); public void countdownFinished() {
} drop();
private int getHeightStart() { startCountdown();
return 5 + random.nextInt(15); }
}
private class HellsBellsCountdown extends Countdown {
public HellsBellsCountdown(int time, SWSound sound, boolean level) {
super(time, sound, level);
} }
@Override @Override
public String countdownCounting() { public void enable() {
return "bis die Bomben fallen";
}
@Override
public void countdownFinished() {
drop();
startCountdown(); startCountdown();
} }
@Override
public void disable() {
currentCountdown.disable();
}
}.register();
}
private static class Point {
private final int x;
private final int y;
private final int z;
public Point(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
} }
private static class Point { public Location addAndToLocation(World world, int x, int y, int z) {
return new Location(world, this.x + x, this.y + y, this.z + z); //NOSONAR
private final int x;
private final int y;
private final int z;
public Point(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public Location addAndToLocation(World world, int x, int y, int z) {
return new Location(world, this.x + x, this.y + y, this.z + z); //NOSONAR
}
public Location subtractAndToLocation(World world, int x, int y, int z) {
return new Location(world, this.x - x, this.y - y, this.z - z); //NOSONAR
}
} }
private enum State { public Location subtractAndToLocation(World world, int x, int y, int z) {
return new Location(world, this.x - x, this.y - y, this.z - z); //NOSONAR
}
}
NONE(0, 0, 0), private enum State {
PRE(60, 80, 1),
FIRST(40, 60, 5), NONE(0, 0, 0),
SECOND(30, 40, 6), PRE(60, 80, 1),
THIRD(20, 30, 6), FIRST(40, 60, 5),
FOURTH(10, 20, 7), SECOND(30, 40, 6),
LAST(5, 10, 0); THIRD(20, 30, 6),
FOURTH(10, 20, 7),
LAST(5, 10, 0);
State(int minTime, int maxTime, int switchAfter) { State(int minTime, int maxTime, int switchAfter) {
this.MIN_TIME = minTime; this.MIN_TIME = minTime;
this.MAX_TIME = maxTime; this.MAX_TIME = maxTime;
this.SWITCH_AFTER = switchAfter; this.SWITCH_AFTER = switchAfter;
} }
private final int MIN_TIME; //NOSONAR private final int MIN_TIME; //NOSONAR
private final int MAX_TIME; //NOSONAR private final int MAX_TIME; //NOSONAR
private final int SWITCH_AFTER; //NOSONAR private final int SWITCH_AFTER; //NOSONAR
public State getNext() { public State getNext() {
switch (this) { switch (this) {
case PRE: case PRE:
return FIRST; return FIRST;
case FIRST: case FIRST:
return SECOND; return SECOND;
case SECOND: case SECOND:
return THIRD; return THIRD;
case THIRD: case THIRD:
return FOURTH; return FOURTH;
case FOURTH: case FOURTH:
case LAST: case LAST:
return LAST; return LAST;
default: default:
return NONE; return NONE;
}
} }
} }
} }