trop tard
This commit is contained in:
parent
0b841e70a4
commit
e1301f007b
4 changed files with 37 additions and 13 deletions
|
|
@ -9,10 +9,34 @@ public class ItemModel {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
protected Integer id;
|
private Integer id;
|
||||||
|
|
||||||
@Enumerated
|
@Enumerated
|
||||||
public ItemType type;
|
private ItemType type;
|
||||||
|
|
||||||
public Integer quantity;
|
private Integer quantity;
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(ItemType type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getQuantity() {
|
||||||
|
return quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuantity(Integer quantity) {
|
||||||
|
this.quantity = quantity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,8 +59,8 @@ public class GameService {
|
||||||
|
|
||||||
// Initialize player inventory
|
// Initialize player inventory
|
||||||
ItemModel yakaballs = new ItemModel();
|
ItemModel yakaballs = new ItemModel();
|
||||||
yakaballs.type = ItemType.YAKABALL;
|
yakaballs.setType(ItemType.YAKABALL);
|
||||||
yakaballs.quantity = 5;
|
yakaballs.setQuantity(5);
|
||||||
|
|
||||||
// Store
|
// Store
|
||||||
playerRepository.persist(player);
|
playerRepository.persist(player);
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,7 @@ public class PlayerService {
|
||||||
ItemModel yakaballItem = itemRepository
|
ItemModel yakaballItem = itemRepository
|
||||||
.find("type", ItemType.YAKABALL)
|
.find("type", ItemType.YAKABALL)
|
||||||
.firstResult();
|
.firstResult();
|
||||||
if (yakaballItem == null || yakaballItem.quantity < 1) {
|
if (yakaballItem == null || yakaballItem.getQuantity() < 1) {
|
||||||
throw new WebApplicationException(
|
throw new WebApplicationException(
|
||||||
Response.status(400).entity("Not enough Yakaballs").build()
|
Response.status(400).entity("Not enough Yakaballs").build()
|
||||||
);
|
);
|
||||||
|
|
@ -170,7 +170,7 @@ public class PlayerService {
|
||||||
ErrorCode.BAD_REQUEST.throwException("Yakamon species not found");
|
ErrorCode.BAD_REQUEST.throwException("Yakamon species not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
yakaballItem.quantity -= 1;
|
yakaballItem.setQuantity(yakaballItem.getQuantity() - 1);
|
||||||
itemRepository.persist(yakaballItem);
|
itemRepository.persist(yakaballItem);
|
||||||
|
|
||||||
YakamonModel newYakamon = new YakamonModel();
|
YakamonModel newYakamon = new YakamonModel();
|
||||||
|
|
@ -342,11 +342,11 @@ public class PlayerService {
|
||||||
.firstResult();
|
.firstResult();
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
item = new ItemModel();
|
item = new ItemModel();
|
||||||
item.type = itemType;
|
item.setType(itemType);
|
||||||
item.quantity = 1;
|
item.setQuantity(1);
|
||||||
itemRepository.persist(item);
|
itemRepository.persist(item);
|
||||||
} else {
|
} else {
|
||||||
item.quantity += 1;
|
item.setQuantity(item.getQuantity() + 1);
|
||||||
itemRepository.persist(item);
|
itemRepository.persist(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,10 @@ public class InventoryResource {
|
||||||
for (ItemModel item : items) {
|
for (ItemModel item : items) {
|
||||||
GetInventoryResponse.Items responseItem = temp.new Items();
|
GetInventoryResponse.Items responseItem = temp.new Items();
|
||||||
GetInventoryResponse.ItemType itemType = temp.new ItemType();
|
GetInventoryResponse.ItemType itemType = temp.new ItemType();
|
||||||
itemType.type = item.type.name();
|
itemType.type = item.getType().name();
|
||||||
itemType.value = item.type.name();
|
itemType.value = item.getType().name();
|
||||||
responseItem.itemType = itemType;
|
responseItem.itemType = itemType;
|
||||||
responseItem.quantity = item.quantity;
|
responseItem.quantity = item.getQuantity();
|
||||||
responseItems.add(responseItem);
|
responseItems.add(responseItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue