forked from SteamWar/SteamWar
Update RandomRotate
This commit is contained in:
@@ -36,6 +36,7 @@ import de.steamwar.sql.SchematicData;
|
|||||||
import de.steamwar.sql.SchematicNode;
|
import de.steamwar.sql.SchematicNode;
|
||||||
import de.steamwar.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@@ -52,7 +53,10 @@ public class FightSchematic extends StateDependent {
|
|||||||
|
|
||||||
private final FightTeam team;
|
private final FightTeam team;
|
||||||
private final Region region;
|
private final Region region;
|
||||||
private final boolean rotate;
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private boolean rotate;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private Clipboard clipboard = null;
|
private Clipboard clipboard = null;
|
||||||
@@ -120,10 +124,13 @@ public class FightSchematic extends StateDependent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(ArenaMode.AntiReplay.contains(Config.mode)) {
|
if(ArenaMode.AntiReplay.contains(Config.mode)) {
|
||||||
|
if (Config.ActiveWinconditions.contains(Winconditions.RANDOM_ROTATE)) {
|
||||||
|
rotate = new Random().nextBoolean();
|
||||||
|
}
|
||||||
if(team.isBlue())
|
if(team.isBlue())
|
||||||
GlobalRecorder.getInstance().blueSchem(schematic);
|
GlobalRecorder.getInstance().blueSchem(schematic, rotate);
|
||||||
else
|
else
|
||||||
GlobalRecorder.getInstance().redSchem(schematic);
|
GlobalRecorder.getInstance().redSchem(schematic, rotate);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::paste);
|
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::paste);
|
||||||
@@ -141,12 +148,6 @@ public class FightSchematic extends StateDependent {
|
|||||||
FreezeWorld freezer = new FreezeWorld();
|
FreezeWorld freezer = new FreezeWorld();
|
||||||
|
|
||||||
team.teleportToSpawn();
|
team.teleportToSpawn();
|
||||||
|
|
||||||
boolean rotate = this.rotate;
|
|
||||||
if (Fight.getRandomSeed().isInitialized() && Config.ActiveWinconditions.contains(Winconditions.RANDOM_ROTATE)) {
|
|
||||||
rotate = Fight.getRandomSeed().getRandom(schematic).nextBoolean();
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector dims = WorldeditWrapper.impl.getDimensions(clipboard);
|
Vector dims = WorldeditWrapper.impl.getDimensions(clipboard);
|
||||||
WorldeditWrapper.impl.pasteClipboard(
|
WorldeditWrapper.impl.pasteClipboard(
|
||||||
clipboard,
|
clipboard,
|
||||||
|
|||||||
@@ -458,6 +458,14 @@ public class FightTeam {
|
|||||||
return schematic.getId();
|
return schematic.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getSchematicRotate() {
|
||||||
|
return schematic.isRotate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSchematicRotate(boolean rotate) {
|
||||||
|
schematic.setRotate(rotate);
|
||||||
|
}
|
||||||
|
|
||||||
public Clipboard getClipboard() {
|
public Clipboard getClipboard() {
|
||||||
return schematic.getClipboard();
|
return schematic.getClipboard();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,6 +143,8 @@ public class PacketProcessor implements Listener {
|
|||||||
packetDecoder[0xb2] = this::teams;
|
packetDecoder[0xb2] = this::teams;
|
||||||
packetDecoder[0xb3] = () -> pasteEmbeddedSchem(Fight.getBlueTeam());
|
packetDecoder[0xb3] = () -> pasteEmbeddedSchem(Fight.getBlueTeam());
|
||||||
packetDecoder[0xb4] = () -> pasteEmbeddedSchem(Fight.getRedTeam());
|
packetDecoder[0xb4] = () -> pasteEmbeddedSchem(Fight.getRedTeam());
|
||||||
|
packetDecoder[0xb5] = () -> rotateSchem(Fight.getBlueTeam());
|
||||||
|
packetDecoder[0xb6] = () -> rotateSchem(Fight.getRedTeam());
|
||||||
packetDecoder[0xc0] = this::scoreboardTitle;
|
packetDecoder[0xc0] = this::scoreboardTitle;
|
||||||
packetDecoder[0xc1] = this::scoreboardData;
|
packetDecoder[0xc1] = this::scoreboardData;
|
||||||
packetDecoder[0xc2] = this::bossBar;
|
packetDecoder[0xc2] = this::bossBar;
|
||||||
@@ -529,6 +531,14 @@ public class PacketProcessor implements Listener {
|
|||||||
execSync(() -> team.pasteSchem(schemId, clipboard));
|
execSync(() -> team.pasteSchem(schemId, clipboard));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void rotateSchem(FightTeam team) throws IOException {
|
||||||
|
boolean rotate = source.readBoolean();
|
||||||
|
|
||||||
|
execSync(() -> {
|
||||||
|
team.setSchematicRotate(rotate);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void teams() throws IOException {
|
private void teams() throws IOException {
|
||||||
int blueId = source.readInt();
|
int blueId = source.readInt();
|
||||||
int redId = source.readInt();
|
int redId = source.readInt();
|
||||||
|
|||||||
@@ -61,9 +61,9 @@ public interface Recorder {
|
|||||||
default void enableTeam(FightTeam team){
|
default void enableTeam(FightTeam team){
|
||||||
if(FightState.Schem.contains(FightState.getFightState())){
|
if(FightState.Schem.contains(FightState.getFightState())){
|
||||||
if(team.isBlue())
|
if(team.isBlue())
|
||||||
blueSchem(team.getSchematic());
|
blueSchem(team.getSchematic(), team.getSchematicRotate());
|
||||||
else
|
else
|
||||||
redSchem(team.getSchematic());
|
redSchem(team.getSchematic(), team.getSchematicRotate());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(FightState.AntiSpectate.contains(FightState.getFightState())){
|
if(FightState.AntiSpectate.contains(FightState.getFightState())){
|
||||||
@@ -123,6 +123,8 @@ public interface Recorder {
|
|||||||
* TeamIDPacket (0xb2) + int blueTeamId, redTeamId
|
* TeamIDPacket (0xb2) + int blueTeamId, redTeamId
|
||||||
* BlueEmbeddedSchemPacket (0xb3) + int blueSchemId + gzipt NBT blob
|
* BlueEmbeddedSchemPacket (0xb3) + int blueSchemId + gzipt NBT blob
|
||||||
* RedEmbeddedSchemPacket (0xb4) + int redSchemId + gzipt NBT blob
|
* RedEmbeddedSchemPacket (0xb4) + int redSchemId + gzipt NBT blob
|
||||||
|
* BlueSchemRotatePacket (0xb5) + boolean rotate
|
||||||
|
* RedSchemRotatePacket (0xb6) + boolean rotate
|
||||||
*
|
*
|
||||||
* DEPRECATED ScoreboardTitlePacket (0xc0) + String scoreboardTitle
|
* DEPRECATED ScoreboardTitlePacket (0xc0) + String scoreboardTitle
|
||||||
* DEPRECATED ScoreboardDataPacket (0xc1) + String key + int value
|
* DEPRECATED ScoreboardDataPacket (0xc1) + String key + int value
|
||||||
@@ -133,7 +135,6 @@ public interface Recorder {
|
|||||||
* WinPacket (0xc6) + byte team + Message subtitle
|
* WinPacket (0xc6) + byte team + Message subtitle
|
||||||
* BossBarPacket (0xc7) + double leftBlueProgress, leftRedProgress + Message leftBlueText, leftRedText
|
* BossBarPacket (0xc7) + double leftBlueProgress, leftRedProgress + Message leftBlueText, leftRedText
|
||||||
*
|
*
|
||||||
* RandomSeed (0xfd) + long seed
|
|
||||||
* CommentPacket (0xfe) + String comment
|
* CommentPacket (0xfe) + String comment
|
||||||
* TickPacket (0xff)
|
* TickPacket (0xff)
|
||||||
*
|
*
|
||||||
@@ -260,14 +261,20 @@ public interface Recorder {
|
|||||||
write(0xb2, blueTeamId, redTeamId);
|
write(0xb2, blueTeamId, redTeamId);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void blueSchem(int schemId) {
|
default void blueSchem(int schemId, boolean rotate) {
|
||||||
|
rotate(0xb5, rotate);
|
||||||
schem(0xb3, 0xb0, schemId);
|
schem(0xb3, 0xb0, schemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void redSchem(int schemId) {
|
default void redSchem(int schemId, boolean rotate) {
|
||||||
|
rotate(0xb6, rotate);
|
||||||
schem(0xb4, 0xb1, schemId);
|
schem(0xb4, 0xb1, schemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default void rotate(int packetId, boolean rotate) {
|
||||||
|
write(packetId, rotate);
|
||||||
|
}
|
||||||
|
|
||||||
default void schem(int embedId, int noEmbedId, int schemId){
|
default void schem(int embedId, int noEmbedId, int schemId){
|
||||||
if(schemId == 0) {
|
if(schemId == 0) {
|
||||||
write(noEmbedId, schemId);
|
write(noEmbedId, schemId);
|
||||||
@@ -311,10 +318,6 @@ public interface Recorder {
|
|||||||
write(0xc6, bTeam, new Message(subtitle, params));
|
write(0xc6, bTeam, new Message(subtitle, params));
|
||||||
}
|
}
|
||||||
|
|
||||||
default void seed(long seed) {
|
|
||||||
write(0xfd, seed);
|
|
||||||
}
|
|
||||||
|
|
||||||
default void tick(){
|
default void tick(){
|
||||||
write(0xff);
|
write(0xff);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.utils;
|
|
||||||
|
|
||||||
import de.steamwar.fightsystem.ArenaMode;
|
|
||||||
import de.steamwar.fightsystem.record.GlobalRecorder;
|
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
|
||||||
import de.steamwar.fightsystem.states.OneShotStateDependent;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class RandomSeed {
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
private boolean initialized = false;
|
|
||||||
private long seed;
|
|
||||||
|
|
||||||
public RandomSeed() {
|
|
||||||
new OneShotStateDependent(ArenaMode.AntiReplay, FightState.PreSchemSetup, () -> {
|
|
||||||
initialized = true;
|
|
||||||
this.seed = System.nanoTime();
|
|
||||||
GlobalRecorder.getInstance().seed(seed);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSeed(long seed) {
|
|
||||||
initialized = true;
|
|
||||||
this.seed = seed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Random getRandom(int derivation) {
|
|
||||||
return new Random(seed ^ new Random(derivation).nextLong());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user