Skip to content

Commit

Permalink
added search item to shop
Browse files Browse the repository at this point in the history
  • Loading branch information
TiagoFar78 committed Jun 19, 2024
1 parent 9cb4d85 commit f06afd2
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
24 changes: 22 additions & 2 deletions src/main/java/net/tiagofar78/prisonescape/game/Guard.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ public class Guard extends PEPlayer {

private static final int BALANCE_LINE_INDEX = 1;
private static final int SOUND_DETECTORS_FIRST_LINE_INDEX = 3;
private static final int INITIAL_SEARCHES = 1;

private int _balance;

private int _numOfCamerasBought = 0;
private int _numOfSensorsBought = 0;
private int _numOfTrapsBought = 0;
private int _searchesAmount = INITIAL_SEARCHES;

private Location _locationBeforeWatchingCameras = null;

Expand Down Expand Up @@ -57,15 +59,15 @@ public void decreaseBalance(int amount) {
updateBalanceLine();
}

public int buyItem(Item item, int price) {
public int buyItem(Item item, int price, boolean isGivableItem) {
if (!canBuyItem(item)) {
return -1;
}
if (price > _balance) {
return -2;
}

if (giveItem(item) == -1) {
if (isGivableItem && giveItem(item) == -1) {
return -3;
}

Expand Down Expand Up @@ -95,6 +97,24 @@ private void updateItemCount(Item item) {
}
}

// #########################################
// # Searches #
// #########################################

public int countSearches() {
return _searchesAmount;
}

public void usedSearch() {
_searchesAmount--;
getKit().update(getName());
}

public void boughtSearch() {
_searchesAmount++;
getKit().update(getName());
}

// ########################################
// # Camera #
// ########################################
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/net/tiagofar78/prisonescape/game/PEGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ public void policeHandcuffedPrisoner(String policeName, String prisonerName) {
arrestPlayer(prisoner, guard);
} else {
MessageLanguageManager messages = MessageLanguageManager.getInstanceByPlayer(policeName);
BukkitMessageSender.sendChatMessage(prisonerName, messages.getNotWantedPlayerMessage());
BukkitMessageSender.sendChatMessage(policeName, messages.getNotWantedPlayerMessage());
}
}

Expand All @@ -1032,6 +1032,12 @@ public void policeInspectedPrisoner(String policeName, String prisonerName) {
return;
}

Guard guard = (Guard) playerGuard;
if (guard.countSearches() == 0) {
// TODO send message
return;
}

Prisoner prisoner = (Prisoner) playerPrisoner;

if (prisoner.hasIllegalItems()) {
Expand All @@ -1042,6 +1048,8 @@ public void policeInspectedPrisoner(String policeName, String prisonerName) {

MessageLanguageManager policeMessages = MessageLanguageManager.getInstanceByPlayer(policeName);
BukkitMessageSender.sendChatMessage(policeName, policeMessages.getPoliceInspectedMessage(prisonerName));

guard.usedSearch();
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/main/java/net/tiagofar78/prisonescape/items/SearchItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerInteractEntityEvent;

public class SearchItem extends FunctionalItem {
public class SearchItem extends FunctionalItem implements Buyable {

@Override
public boolean isMetalic() {
Expand Down Expand Up @@ -40,4 +40,14 @@ public void use(PlayerInteractEntityEvent e) {
game.policeInspectedPrisoner(e.getPlayer().getName(), prisioner.getName());
}

@Override
public int getPrice() {
return 5; // TODO
}

@Override
public int getLimit() {
return 0; // TODO
}

}
7 changes: 7 additions & 0 deletions src/main/java/net/tiagofar78/prisonescape/kits/PoliceKit.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package net.tiagofar78.prisonescape.kits;

import net.tiagofar78.prisonescape.game.Guard;
import net.tiagofar78.prisonescape.items.GlassItem;
import net.tiagofar78.prisonescape.items.HandcuffsItem;
import net.tiagofar78.prisonescape.items.Item;
import net.tiagofar78.prisonescape.items.MissionsItem;
import net.tiagofar78.prisonescape.items.OpenCamerasItem;
import net.tiagofar78.prisonescape.items.SearchItem;
import net.tiagofar78.prisonescape.items.ShopItem;
import net.tiagofar78.prisonescape.managers.GameManager;
import net.tiagofar78.prisonescape.managers.MessageLanguageManager;

import org.bukkit.Bukkit;
Expand Down Expand Up @@ -84,8 +86,13 @@ public void update(String playerName) {

MessageLanguageManager messages = MessageLanguageManager.getInstanceByPlayer(playerName);

int searchesAmount = ((Guard) GameManager.getGame().getPEPlayer(playerName)).countSearches();
ItemStack searchItem = getItemAt(SEARCH_ITEM_INDEX).toItemStack(messages);
searchItem.setAmount(searchesAmount);

Inventory inv = bukkitPlayer.getInventory();
inv.setItem(CAMERA_ITEM_INDEX, getItemAt(CAMERA_ITEM_INDEX).toItemStack(messages));
inv.setItem(SEARCH_ITEM_INDEX, searchItem);
}

}
13 changes: 11 additions & 2 deletions src/main/java/net/tiagofar78/prisonescape/menus/Shop.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.tiagofar78.prisonescape.items.Item;
import net.tiagofar78.prisonescape.items.NullItem;
import net.tiagofar78.prisonescape.items.RadarItem;
import net.tiagofar78.prisonescape.items.SearchItem;
import net.tiagofar78.prisonescape.items.SoundDetectorItem;
import net.tiagofar78.prisonescape.items.TrapItem;
import net.tiagofar78.prisonescape.managers.MessageLanguageManager;
Expand All @@ -22,7 +23,7 @@

public class Shop implements Clickable {

private static final int NUM_OF_ITEMS_FOR_SALE = 5;
private static final int NUM_OF_ITEMS_FOR_SALE = 6;

private List<Item> _contents;

Expand All @@ -37,6 +38,7 @@ private List<Item> createContentsList() {
list.add(new SoundDetectorItem());
list.add(new CameraItem());
list.add(new RadarItem());
list.add(new SearchItem());
return list;
}

Expand All @@ -61,7 +63,9 @@ public ClickReturnAction click(PEPlayer player, int slot, boolean isPlayerInv, C
Buyable buyableItem = (Buyable) item;
MessageLanguageManager messages = MessageLanguageManager.getInstanceByPlayer(player.getName());

int returnCode = guard.buyItem(item, buyableItem.getPrice());
boolean isGivableItem = !(item instanceof SearchItem);

int returnCode = guard.buyItem(item, buyableItem.getPrice(), isGivableItem);
if (returnCode == -1) {
BukkitMessageSender.sendChatMessage(player, messages.getReachedItemLimitMessage());
return ClickReturnAction.NOTHING;
Expand All @@ -73,6 +77,10 @@ public ClickReturnAction click(PEPlayer player, int slot, boolean isPlayerInv, C
return ClickReturnAction.NOTHING;
}

if (!isGivableItem) {
guard.boughtSearch();
}

BukkitMessageSender.sendChatMessage(player, messages.getSuccessfullyBoughtItemMessage(guard.getBalance()));
return ClickReturnAction.NOTHING;
}
Expand All @@ -86,6 +94,7 @@ public Inventory toInventory(MessageLanguageManager messages) {
shopMenu.setItem(2, new SoundDetectorItem().toItemStack(messages));
shopMenu.setItem(3, new CameraItem().toItemStack(messages));
shopMenu.setItem(4, new RadarItem().toItemStack(messages));
shopMenu.setItem(5, new SearchItem().toItemStack(messages));

return shopMenu;
}
Expand Down

0 comments on commit f06afd2

Please sign in to comment.