feat: Send message to chat when item is used
This commit is contained in:
parent
89d9799ae2
commit
143c4761f5
@ -1,6 +1,9 @@
|
||||
package cz.jzitnik.chronos.controllers;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import cz.jzitnik.chronos.entities.Item;
|
||||
import cz.jzitnik.chronos.entities.Message;
|
||||
import cz.jzitnik.chronos.entities.MessageType;
|
||||
import cz.jzitnik.chronos.entities.Player;
|
||||
import cz.jzitnik.chronos.payload.errors.ItemNotUsableException;
|
||||
import cz.jzitnik.chronos.payload.errors.NotFoundError;
|
||||
@ -91,9 +94,13 @@ public class PlayerController {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(UnifiedResponse.failure(e.toError()));
|
||||
}
|
||||
|
||||
player.getMessages().add(new Message(player, String.valueOf(item.getId()), MessageType.ITEM_USED));
|
||||
|
||||
playerRepository.save(player);
|
||||
|
||||
itemRepository.delete(item);
|
||||
item.setOwner(null);
|
||||
|
||||
itemRepository.save(item);
|
||||
|
||||
return ResponseEntity.ok(UnifiedResponse.success(null));
|
||||
}
|
||||
|
@ -5,5 +5,6 @@ public enum MessageType {
|
||||
MOVE_TO_ROOM,
|
||||
GOT_ITEM,
|
||||
LOST_ITEM,
|
||||
ITEM_USED,
|
||||
JOINED,
|
||||
}
|
||||
|
@ -68,6 +68,23 @@ public class Message {
|
||||
yield "Hráč " + author.getName() + " sice získal item, ale měl plný inventář a tím pádem ho navždy ztratil.";
|
||||
}
|
||||
}
|
||||
case ITEM_USED -> {
|
||||
try {
|
||||
var response = apiService.getItemInfo(playerKey, Long.valueOf(content)).execute();
|
||||
|
||||
var body = response.body();
|
||||
|
||||
if (!body.getSuccess()) {
|
||||
yield "Hráč " + Cli.Colors.BLUE + author.getName() + Cli.Colors.RESET + " využil item unknown.";
|
||||
}
|
||||
|
||||
var item = body.getData().get();
|
||||
|
||||
yield "Hráč " + Cli.Colors.BLUE + author.getName() + Cli.Colors.RESET + " využil item " + Cli.Colors.BLUE + item + Cli.Colors.RESET + ".";
|
||||
} catch (IOException e) {
|
||||
yield "Hráč " + Cli.Colors.BLUE + author.getName() + Cli.Colors.RESET + " využil item unknown.";
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -5,5 +5,6 @@ public enum MessageType {
|
||||
MOVE_TO_ROOM,
|
||||
GOT_ITEM,
|
||||
LOST_ITEM,
|
||||
ITEM_USED,
|
||||
JOINED,
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ public class CommandPalette {
|
||||
return switch (command.getCommandType()) {
|
||||
case CUSTOM -> selectedOption;
|
||||
case EXIT -> {
|
||||
System.out.println("Exiting game...");
|
||||
Cli.info("Odpojuji se ze hry...");
|
||||
System.exit(0);
|
||||
|
||||
yield 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user