feat: Winnable and some minor changes
This commit is contained in:
parent
c47df0d609
commit
b6596c7303
@ -81,4 +81,13 @@ public class GameController {
|
||||
|
||||
return ResponseEntity.ok(UnifiedResponse.success(TestGameKeyResponse.WORKING));
|
||||
}
|
||||
|
||||
@GetMapping("/winnable")
|
||||
@CheckUser
|
||||
public ResponseEntity<UnifiedResponse<Boolean, Error>> winnable(@RequestParam String playerKey) {
|
||||
var player = playerRepository.findByPlayerKey(playerKey).get();
|
||||
var game = player.getGame();
|
||||
|
||||
return ResponseEntity.ok(UnifiedResponse.success(game.winnable()));
|
||||
}
|
||||
}
|
||||
|
@ -44,4 +44,33 @@ public class Game {
|
||||
public void addPlayer(Player player) {
|
||||
this.players.add(player);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public boolean winnable() {
|
||||
var ownedFragments = 0;
|
||||
for (Player player : players) {
|
||||
for (Item item : player.getInventory()) {
|
||||
if (item.getItemType() == ItemType.KEY_FRAGMENT) {
|
||||
ownedFragments++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var roomItems = 0;
|
||||
var characters = new ArrayList<Character>();
|
||||
|
||||
for (Room room : rooms) {
|
||||
characters.addAll(room.getCharacters());
|
||||
for (Item item : room.getItems()) {
|
||||
if (item.getItemType() == ItemType.KEY_FRAGMENT) {
|
||||
roomItems++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var unplayedCharacters = characters.stream().filter(character -> !character.isInteractedWith()).toList().size();
|
||||
|
||||
return roomItems + unplayedCharacters + ownedFragments >= 5;
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ public class Hangman implements InteractionPlayer {
|
||||
var incorrectGuessesSet = interactionMemory.getIncorrectGuessesSet();
|
||||
StringBuilder currentProgress = new StringBuilder(interactionMemory.getCurrentProgress());
|
||||
|
||||
if (data == null || data.isEmpty()) {
|
||||
if (data.isEmpty()) {
|
||||
return new InteractionResponse(false, "invalid_input", new ArrayList<>());
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import cz.jzitnik.chronos.entities.Player;
|
||||
import cz.jzitnik.chronos.interactions.InteractionPlayer;
|
||||
import cz.jzitnik.chronos.payload.responses.InteractionResponse;
|
||||
import cz.jzitnik.chronos.repository.CharacterRepository;
|
||||
import cz.jzitnik.chronos.repository.ItemRepository;
|
||||
import cz.jzitnik.chronos.services.ItemService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -19,6 +20,8 @@ public class Mayor implements InteractionPlayer {
|
||||
private ItemService itemService;
|
||||
@Autowired
|
||||
private CharacterRepository characterRepository;
|
||||
@Autowired
|
||||
private ItemRepository itemRepository;
|
||||
|
||||
@Override
|
||||
public InteractionResponse play(Player player, Character character, String data) {
|
||||
@ -30,10 +33,12 @@ public class Mayor implements InteractionPlayer {
|
||||
}
|
||||
|
||||
var golderWatch = golderWatches.getFirst();
|
||||
golderWatch.setOwner(null);
|
||||
itemRepository.save(golderWatch);
|
||||
playerItems.remove(golderWatch);
|
||||
|
||||
var item = new Item(ItemType.KEY_FRAGMENT, player);
|
||||
itemService.addItem(player, item); // itemRepository.save is ran by this function so we don't need to save the player when we removed the item from his inv
|
||||
itemService.addItem(player, item);
|
||||
|
||||
character.setInteractedWith(true);
|
||||
characterRepository.save(character);
|
||||
|
@ -22,6 +22,11 @@ public interface ApiService {
|
||||
@POST("game/new")
|
||||
Call<UnifiedResponse<Game, Error>> newGame();
|
||||
|
||||
@GET("game/winnable")
|
||||
Call<UnifiedResponse<Boolean, Error>> winnable(
|
||||
@Query("playerKey") String playerKey
|
||||
);
|
||||
|
||||
@POST("game/players/new")
|
||||
Call<UnifiedResponse<String, Error>> newPlayer(
|
||||
@Query("gameKey") String gameKey,
|
||||
|
@ -237,9 +237,8 @@ public class Chronos {
|
||||
var characters = room.getCharacters();
|
||||
if (characters.isEmpty()) {
|
||||
Cli.type("V místnosti se nenachází jediná duše...");
|
||||
} else {
|
||||
talk(characters);
|
||||
}
|
||||
talk(characters);
|
||||
|
||||
var responseRooms = apiService.getAllRooms(localData.getUserSecret()).execute();
|
||||
var rooms = responseRooms.body().getData().get().stream().filter(rm -> !rm.getId().equals(room.getId())).toList();
|
||||
|
@ -19,6 +19,7 @@ public class CommandPalette {
|
||||
USER_PROFILE,
|
||||
CHAT_OPEN,
|
||||
CHAT_SEND,
|
||||
CHECK_WINNABLE,
|
||||
EXIT,
|
||||
}
|
||||
|
||||
@ -62,6 +63,7 @@ public class CommandPalette {
|
||||
allCommands.add(new Command("Otevřít profil uživatele", CommandType.USER_PROFILE));
|
||||
allCommands.add(new Command("Otevřít chat", CommandType.CHAT_OPEN));
|
||||
allCommands.add(new Command("Odeslat zprávu do chatu", CommandType.CHAT_SEND));
|
||||
allCommands.add(new Command("Zkontrolovat vyhratelnost hry", CommandType.CHECK_WINNABLE));
|
||||
allCommands.add(new Command("Odejít ze hry", CommandType.EXIT));
|
||||
|
||||
var responseInvFull = apiService.inventoryIsFull(playerKey).execute();
|
||||
@ -115,6 +117,19 @@ public class CommandPalette {
|
||||
var chat = new Chat(apiService, playerKey);
|
||||
chat.sendMessage();
|
||||
|
||||
yield displayIndex();
|
||||
}
|
||||
case CHECK_WINNABLE -> {
|
||||
var response = apiService.winnable(playerKey).execute();
|
||||
var winnable = response.body().getData().get();
|
||||
|
||||
System.out.println(Cli.Colors.RED + "Experimentální!!!" + Cli.Colors.RESET + " Toto není 100% jestli je hra vyhratelná.");
|
||||
if (winnable) {
|
||||
Cli.info("Hra je dost možná vyhratelná!");
|
||||
} else {
|
||||
Cli.info("Hra je dost možná nevyhratelná!");
|
||||
}
|
||||
|
||||
yield displayIndex();
|
||||
}
|
||||
};
|
||||
|
@ -169,7 +169,7 @@ public class Cli {
|
||||
if (choice >= 1 && choice <= options.size()) {
|
||||
return choice - 1;
|
||||
} else {
|
||||
System.out.println("Neplatní možnost, vyberte číslo mezi 1 a " + options.size());
|
||||
System.out.println("Neplatná možnost, vyberte číslo mezi 1 a " + options.size());
|
||||
}
|
||||
} else {
|
||||
System.out.println("Neplatný vstup, vložte číslo.");
|
||||
|
Loading…
x
Reference in New Issue
Block a user