feat: properly handle movement requests
This commit is contained in:
parent
d06ac91ef8
commit
05f4751a2c
@ -13,12 +13,15 @@ import java.util.ArrayList;
|
|||||||
/** Contains game logic handling. */
|
/** Contains game logic handling. */
|
||||||
class GameLogic {
|
class GameLogic {
|
||||||
/**
|
/**
|
||||||
* Produces resulting {@link Event}s from a given {@link Request} independently of any {@link GameState}.
|
* Produces resulting {@link Event}s from a given {@link Request}.
|
||||||
|
* @param state The game state to execute on
|
||||||
|
* @param request The request to execute
|
||||||
* @return The list of resulting events
|
* @return The list of resulting events
|
||||||
*/
|
*/
|
||||||
public static ArrayList<Event> executeRequest(Request request) {
|
public static ArrayList<Event> executeRequest(GameState state, Request request) {
|
||||||
ArrayList<Event> result = new ArrayList<>();
|
ArrayList<Event> result = new ArrayList<>();
|
||||||
|
|
||||||
|
//TODO: refactor for EventBuilder in GameLogic.executeRequest
|
||||||
switch(request.type) {
|
switch(request.type) {
|
||||||
case MeleeAttackRequest, RangedAttackRequest -> {
|
case MeleeAttackRequest, RangedAttackRequest -> {
|
||||||
CharacterRequest data = (CharacterRequest)request;
|
CharacterRequest data = (CharacterRequest)request;
|
||||||
@ -52,7 +55,16 @@ class GameLogic {
|
|||||||
.setTargetField(data.targetField) //when this event gets handled, the character already moved to the target field
|
.setTargetField(data.targetField) //when this event gets handled, the character already moved to the target field
|
||||||
.setAmount(1)
|
.setAmount(1)
|
||||||
.type(EventType.ConsumedMPEvent));
|
.type(EventType.ConsumedMPEvent));
|
||||||
//TODO: execute character swap in GameLogic.executeRequest
|
for(Entity entity: state.entities.findByPosition(data.targetField)) {
|
||||||
|
if(entity instanceof Character) {
|
||||||
|
result.add(new CharacterEvent()
|
||||||
|
.setOriginEntity(entity.id)
|
||||||
|
.setOriginField(data.targetField)
|
||||||
|
.setTargetField(data.originField)
|
||||||
|
.type(EventType.MoveEvent));
|
||||||
|
break; //we should only have one character per field anyways
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case ExchangeInfinityStoneRequest, UseInfinityStoneRequest -> {
|
case ExchangeInfinityStoneRequest, UseInfinityStoneRequest -> {
|
||||||
CharacterRequest data = (CharacterRequest)request;
|
CharacterRequest data = (CharacterRequest)request;
|
||||||
@ -68,6 +80,7 @@ class GameLogic {
|
|||||||
.setTargetField(data.originField)
|
.setTargetField(data.originField)
|
||||||
.setAmount(1)
|
.setAmount(1)
|
||||||
.type(EventType.ConsumedAPEvent));
|
.type(EventType.ConsumedAPEvent));
|
||||||
|
//TODO: add infinity stone use effect in GameLogic.executeRequest
|
||||||
|
|
||||||
}
|
}
|
||||||
case DisconnectRequest -> {
|
case DisconnectRequest -> {
|
||||||
|
@ -32,7 +32,7 @@ class GameStateManager {
|
|||||||
|
|
||||||
for(Request request: requests) {
|
for(Request request: requests) {
|
||||||
if (GameLogic.checkRequest(snapshot, request)) {
|
if (GameLogic.checkRequest(snapshot, request)) {
|
||||||
ArrayList<Event> result = GameLogic.executeRequest(request);
|
ArrayList<Event> result = GameLogic.executeRequest(snapshot, request);
|
||||||
if(apply) {
|
if(apply) {
|
||||||
queue.addAll(result);
|
queue.addAll(result);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user