diff --git a/src/main/java/cactusServer/entities/Character.java b/src/main/java/cactusServer/entities/Character.java index d4328f7..40dfe65 100644 --- a/src/main/java/cactusServer/entities/Character.java +++ b/src/main/java/cactusServer/entities/Character.java @@ -1,14 +1,12 @@ package cactusServer.entities; import java.net.URI; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; -import java.util.Set; -import java.util.UUID; import framework.model3D.Position3D; -import framework.physics.AngularVelocity3D; -import framework.physics.Velocity3D; import net.arnx.jsonic.JSONHint; public class Character { @@ -24,14 +22,14 @@ @JSONHint(ignore = true) HashMap itemMap = new HashMap<>(); @JSONHint(ignore = true) private static final int UNIQUE_ID_LENGTH = 12; - public Character(URI accountURI, String name, Position3D position, String areaId, boolean isActive) { - this.accountURI = accountURI; - this.name = name; - this.position = position; - this.areaID = areaId; - this.isActive = isActive; - } - +// public Character(URI accountURI, String name, Position3D position, String areaId, boolean isActive) { +// this.accountURI = accountURI; +// this.name = name; +// this.position = position; +// this.areaID = areaId; +// this.isActive = isActive; +// } + public URI getAccountURI() { return accountURI; } @@ -48,18 +46,22 @@ return areaID; } - public boolean isAactive() { + public boolean isActive() { return isActive; } - - public HashMap getItemMap() { - return itemMap; - } - public Item getItemMap(String itemId) { + public Item getItem(String itemId) { return itemMap.get(itemId); } + public List getItems() { + List itemList = new ArrayList<>(); + for (Item item : itemMap.values()) { + itemList.add(item); + } + return itemList; + } + public void setAccountURI(URI accountURI) { this.accountURI = accountURI; } @@ -71,22 +73,42 @@ public void setPosition(Position3D position) { this.position = position; } + + public void setAreaID(String areaID) { + this.areaID = areaID; + } public void setActive(boolean isActive) { this.isActive = isActive; } public Map createItem(String name, int amount) { - String id = new RandomStringGenerator().createUniqueString(UNIQUE_ID_LENGTH, RandomStringGenerator.ALPHA_NUMERIC, itemMap.keySet()); Item item = new Item(name, amount); - itemMap.put(id, item); - return new HashMap() { - {put(id, item);} - }; + if (!hasItem(item)) { + String id = new RandomStringGenerator().createUniqueString(UNIQUE_ID_LENGTH, RandomStringGenerator.ALPHA_NUMERIC, itemMap.keySet()); + itemMap.put(id, item); + return new HashMap() { + {put(id, item);} + }; + } + return null; } - public Item addItem(String itemId, int num) { - return itemMap.get(itemId).addAmount(num); + public boolean hasItem(Item item) { + for (Map.Entry entry : itemMap.entrySet()) { + if (entry.getValue().equals(item)) { + return true; + } + } + return false; + } + + public Item changeAmountOfItem(String itemId, int amountOfChange) { + Item item = itemMap.get(itemId).changeAmount(amountOfChange); + if (item.isEmpty()) { + destroyItem(itemId); + } + return item; } public Item destroyItem(String itemId) {