diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/DisconnectSegment.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/DisconnectSegment.java index e687130..3138dfc 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/DisconnectSegment.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/DisconnectSegment.java @@ -1,11 +1,8 @@ package uulm.teamname.marvelous.server.lobby.pipelining; -import uulm.teamname.marvelous.gamelibrary.entities.Entity; -import uulm.teamname.marvelous.gamelibrary.events.EntityEvent; import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.events.EventBuilder; import uulm.teamname.marvelous.gamelibrary.events.EventType; -import uulm.teamname.marvelous.gamelibrary.requests.Request; import uulm.teamname.marvelous.gamelibrary.requests.RequestBuilder; import uulm.teamname.marvelous.gamelibrary.requests.RequestType; import uulm.teamname.marvelous.server.lobby.Lobby; @@ -24,7 +21,7 @@ public class DisconnectSegment implements Segment { @Override - public void processRequests(List packet, List carrier, AtomicBoolean abort) { + public void processRequests(Packet packet, List carrier, AtomicBoolean abort) { if (packet.contains(new RequestBuilder(RequestType.DisconnectRequest).buildGameRequest())) { carrier.add(new EventBuilder(EventType.DisconnectEvent).buildGameEvent()); parent.connection.removePlayer(player); diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/GameStateSegment.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/GameStateSegment.java index dd1cde1..17be751 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/GameStateSegment.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/GameStateSegment.java @@ -1,17 +1,13 @@ package uulm.teamname.marvelous.server.lobby.pipelining; import uulm.teamname.marvelous.gamelibrary.events.Event; -import uulm.teamname.marvelous.gamelibrary.events.EventBuilder; -import uulm.teamname.marvelous.gamelibrary.events.EventType; import uulm.teamname.marvelous.gamelibrary.requests.Request; -import uulm.teamname.marvelous.gamelibrary.requests.RequestBuilder; -import uulm.teamname.marvelous.gamelibrary.requests.RequestType; import uulm.teamname.marvelous.server.lobby.Lobby; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; -public class GameStateSegment implements Segment{ +public class GameStateSegment implements Segment { private Lobby parent; public GameStateSegment(Lobby parent){ @@ -19,25 +15,28 @@ public class GameStateSegment implements Segment{ } @Override - public void processRequests(List packet, List carrier, AtomicBoolean abort) { - if (packet.contains(new RequestBuilder(RequestType.MeleeAttackRequest).buildGameRequest())) { - carrier.add(new EventBuilder(EventType.MeleeAttackEvent).buildGameEvent()); - } - if (packet.contains(new RequestBuilder(RequestType.RangedAttackRequest).buildGameRequest())) { - carrier.add(new EventBuilder(EventType.RangedAttackEvent).buildGameEvent()); - } - if (packet.contains(new RequestBuilder(RequestType.MoveRequest).buildGameRequest())) { - carrier.add(new EventBuilder(EventType.MoveEvent).buildGameEvent()); - } - if (packet.contains(new RequestBuilder(RequestType.ExchangeInfinityStoneRequest).buildGameRequest())) { - carrier.add(new EventBuilder(EventType.ExchangeInfinityStoneEvent).buildGameEvent()); - } - if (packet.contains(new RequestBuilder(RequestType.UseInfinityStoneRequest).buildGameRequest())) { - carrier.add(new EventBuilder(EventType.UseInfinityStoneEvent).buildGameEvent()); - } - if (packet.contains(new RequestBuilder(RequestType.EndRoundRequest).buildGameRequest())) { - //TODO what to do after EndRoundRequest - //carrier.add(new EventBuilder(EventType.EndRoundEvent).buildGameEvent()); - } + public void processRequests(Packet packet, List carrier, AtomicBoolean abort) { + + parent.game.checkRequestsAndApply(packet.toArray(new Request[0])); + +// if (packet.contains(new RequestBuilder(RequestType.MeleeAttackRequest).buildGameRequest())) { +// carrier.add(new EventBuilder(EventType.MeleeAttackEvent).buildGameEvent()); +// } +// if (packet.contains(new RequestBuilder(RequestType.RangedAttackRequest).buildGameRequest())) { +// carrier.add(new EventBuilder(EventType.RangedAttackEvent).buildGameEvent()); +// } +// if (packet.contains(new RequestBuilder(RequestType.MoveRequest).buildGameRequest())) { +// carrier.add(new EventBuilder(EventType.MoveEvent).buildGameEvent()); +// } +// if (packet.contains(new RequestBuilder(RequestType.ExchangeInfinityStoneRequest).buildGameRequest())) { +// carrier.add(new EventBuilder(EventType.ExchangeInfinityStoneEvent).buildGameEvent()); +// } +// if (packet.contains(new RequestBuilder(RequestType.UseInfinityStoneRequest).buildGameRequest())) { +// carrier.add(new EventBuilder(EventType.UseInfinityStoneEvent).buildGameEvent()); +// } +// if (packet.contains(new RequestBuilder(RequestType.EndRoundRequest).buildGameRequest())) { +// //TODO what to do after EndRoundRequest +// //carrier.add(new EventBuilder(EventType.EndRoundEvent).buildGameEvent()); +// } } } diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/Packet.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/Packet.java new file mode 100644 index 0000000..12a6e68 --- /dev/null +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/Packet.java @@ -0,0 +1,26 @@ +package uulm.teamname.marvelous.server.lobby.pipelining; + +import uulm.teamname.marvelous.gamelibrary.requests.Request; +import uulm.teamname.marvelous.gamelibrary.requests.RequestType; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +public class Packet extends ArrayList { + + public Packet (Request[] requests) { + addAll(Arrays.asList(requests)); + } + + public boolean containsRequestOfType(RequestType requiredType) { + for (Request request : this) { + if (request.type == requiredType) { + return true; + } + } + return false; + } + +} diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/PauseSegment.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/PauseSegment.java index e2c5077..3bc11aa 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/PauseSegment.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/PauseSegment.java @@ -53,7 +53,7 @@ public class PauseSegment implements Segment { * @param packet */ @Override - public void processRequests(List packet, List carrier, AtomicBoolean abort) { + public void processRequests(Packet packet, List carrier, AtomicBoolean abort) { // check if there is a pause request (either start or stop) if (packet.contains(new RequestBuilder(RequestType.PauseStartRequest).buildGameRequest())) { if (!paused) { diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/Pipeline.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/Pipeline.java index c344b20..37c0d34 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/Pipeline.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/Pipeline.java @@ -3,10 +3,7 @@ package uulm.teamname.marvelous.server.lobby.pipelining; import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.requests.Request; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; +import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; /** @@ -40,7 +37,7 @@ public class Pipeline { */ public Optional processRequests(Request[] requests) { // The packet carries the requests, and gets smaller per segment - List packet = Arrays.asList(requests); + Packet packet = new Packet(requests); // The packet is filled by the requests resulting from events per segment List carrier = new ArrayList<>(); // The abort boolean describes whether an abort happened in a segment diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/RequestGameStateSegment.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/RequestGameStateSegment.java index d1946d3..df550bf 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/RequestGameStateSegment.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/RequestGameStateSegment.java @@ -1,7 +1,6 @@ package uulm.teamname.marvelous.server.lobby.pipelining; import uulm.teamname.marvelous.gamelibrary.events.Event; -import uulm.teamname.marvelous.gamelibrary.requests.Request; import uulm.teamname.marvelous.gamelibrary.requests.RequestBuilder; import uulm.teamname.marvelous.gamelibrary.requests.RequestType; import uulm.teamname.marvelous.server.lobby.Lobby; @@ -18,7 +17,7 @@ public class RequestGameStateSegment implements Segment { } @Override - public void processRequests(List packet, List carrier, AtomicBoolean abort) { + public void processRequests(Packet packet, List carrier, AtomicBoolean abort) { if (packet.contains(new RequestBuilder(RequestType.Req).buildGameRequest())) { carrier.add(parent.game.getGameStateEvent()); } diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/Segment.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/Segment.java index 202899e..9fb2df2 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/Segment.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/pipelining/Segment.java @@ -17,9 +17,9 @@ public interface Segment { * @param carrier is a {@link List} of {@link Event Events} that is appended to * if new requests are generated from the execution of the {@link Segment} * @param abort is an {@link AtomicBoolean} describing whether an error has occurred during the execution of - * the {@link Segment} Note that error here does not describe an execution error - * of the segment, but instead an error in the events passed to it, like for example moving into a Rock. - * The conventional way of setting this boolean is to write {@code abort.set(true); return;} + * the {@link Segment} Note that error here does not describe an execution error + * of the segment, but instead an error in the events passed to it, like for example moving into a Rock. + * The conventional way of setting this boolean is to write {@code abort.set(true); return;} */ - public void processRequests(List packet, List carrier, AtomicBoolean abort); + public void processRequests(Packet packet, List carrier, AtomicBoolean abort); }