feat: Implemented droping items

This commit is contained in:
2025-01-04 12:11:35 +01:00
parent fc432caa58
commit 5c5058f6c5
5 changed files with 63 additions and 5 deletions

View File

@ -150,4 +150,10 @@ public interface ApiService {
@Query("itemId") Long itemId,
@Query("playerId") Long playerId
);
@POST("game/players/drop_item")
Call<UnifiedResponse<Object, Error>> dropItem(
@Query("playerKey") String playerKey,
@Query("itemId") Long itemId
);
}

View File

@ -1,6 +1,7 @@
package cz.jzitnik.game;
import cz.jzitnik.api.ApiService;
import cz.jzitnik.api.types.Item;
import cz.jzitnik.utils.Cli;
import cz.jzitnik.utils.ConfigPathProvider;
import lombok.AllArgsConstructor;
@ -23,6 +24,7 @@ public class CommandPalette {
CHAT_OPEN,
CHAT_SEND,
PLAYER_LIST_OPEN,
DROP_ITEM,
CHECK_WINNABLE,
EXIT,
}
@ -84,6 +86,7 @@ public class CommandPalette {
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("Zobrazit list všech hráčů", CommandType.PLAYER_LIST_OPEN));
allCommands.add(new Command("Vyhodit item z inventáře", CommandType.DROP_ITEM));
allCommands.add(new Command("Zkontrolovat vyhratelnost hry", CommandType.CHECK_WINNABLE));
allCommands.add(new Command("Odejít ze hry", CommandType.EXIT));
@ -157,6 +160,32 @@ public class CommandPalette {
var playerList = new PlayerList(apiService, playerKey);
playerList.display();
yield displayIndex();
}
case DROP_ITEM -> {
var response = apiService.getMe(playerKey).execute();
var me = response.body().getData().get();
var inventory = me.getInventory();
if (inventory.isEmpty()) {
Cli.error("Máš prázdný inventář!");
yield displayIndex();
}
var options = inventory.stream().map(Item::toString).toList();
var selectedOptionIndex = Cli.selectOptionIndex(options);
var selectedItem = inventory.get(selectedOptionIndex);
var response2 = apiService.dropItem(playerKey, selectedItem.getId()).execute();
if (response2.code() != 200) {
Cli.error("Nastala chyba při vyhazování itemu!");
} else {
Cli.success("Item byl vyhozen!");
}
yield displayIndex();
}
};