package cactusServer.entities; import java.net.URI; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import cactusServer.utils.RandomStringGenerator; import framework.model3D.Position3D; import net.arnx.jsonic.JSONHint; public class Character extends Entity{ private String accountURI; private String name; private Position3D position; private Angle angle; private Model model; private String areaURI; private HashMap<String, Item> itemMap = new HashMap<>(); private static final int UNIQUE_ID_LENGTH = 12; public Character(String accountURI, String name, Position3D position, Angle angle, Model model) { this.accountURI = accountURI; this.name = name; this.position = position; this.angle = angle; this.model = model; updateAreaURI(); } public String getAccountURI() { return accountURI; } public String getName() { return name; } public Position3D getPosition() { return position; } public Angle getAngle() { return angle; } public Model getModel() { return model; } public String getAreaURI() { return areaURI; } public Item getItem(String itemId) { return itemMap.get(itemId); } public List<Item> getItems() { List<Item> itemList = new ArrayList<>(); for (Item item : itemMap.values()) { itemList.add(item); } return itemList; } public void setName(String name) { this.name = name; } public void setPosition(Position3D position) { this.position = position; } public void setAreaID(String areaID) { this.areaURI = areaID; } public Map<String, Item> createItem(String name, int amount) { Item item = new Item(name, amount); if (!hasItem(item)) { String id = RandomStringGenerator.generateUniqueString(UNIQUE_ID_LENGTH, RandomStringGenerator.ALPHA_NUMERIC, itemMap.keySet()); itemMap.put(id, item); return new HashMap<String, Item>() { {put(id, item);} }; } return null; } public boolean hasItem(Item item) { for (Map.Entry<String, Item> 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; } private void updateAreaURI() { } public Item destroyItem(String itemId) { return itemMap.remove(itemId); } }