package cactusServer.entities; import java.net.URI; import java.util.HashMap; import java.util.Map; import framework.model3D.Position3D; import net.arnx.jsonic.JSONHint; public class Character { private URI accountURI; private String name; private Position3D position; // private Angle angle; // private Camera cameraState; // private Emote emoteState; // private Model model; private String areaID; private boolean isActive; @JSONHint(ignore = true) HashMap<String, Item> 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 URI getAccountURI() { return accountURI; } public String getName() { return name; } public Position3D getPosition() { return position; } public String getAreaId() { return areaID; } public boolean isActive() { return isActive; } public HashMap<String, Item> getItemMap() { return itemMap; } public Item getItemMap(String itemId) { return itemMap.get(itemId); } public void setPosition(Position3D position) { this.position = position; } public void setActive(boolean isActive) { this.isActive = isActive; } public Map<String, Item> 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<String, Item>() { {put(id, item);} }; } 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) { return itemMap.remove(itemId); } }