// validates that item has no position and private void validateForPlacing(EcsEntity item) { if (item.hasPos()) { Debug.LogWarning("Item " + item + " already has position."); } }
public static Vector3Int pos(this EcsEntity entity) { if (entity.hasPos()) { return(entity.Get <PositionComponent>().position); } throw new ArgumentException("entity has no PositionComponent!"); }
// public void addItem(EcsEntity item) { // objects.add(item); // } // // public void removeItem(EcsEntity item) { // if (!objects.contains(item)) { // Logger.ITEMS.logWarn("Removing not present item " + item.type.name); // } else { // Logger.ITEMS.logDebug("Removing item " + item.type.name); // } // if (isItemOnMap(item)) onMapItemsSystem.removeItemFromMap(item); // if (isItemInContainer(item)) containedItemsSystem.removeItemFromContainer(item); // if (isItemEquipped(item)) equippedItemsSystem.removeItemFromEquipment(item); // item.destroyed = true; // objects.remove(item); // } // // public void removeItems(List<EcsEntity> items) { // items.forEach(this::removeItem); // } // // public List<EcsEntity> getItemsInPosition(IntVector3 position) { // return new ArrayList<>(itemMap.getOrDefault(position, Collections.emptyList())); // } // // public List<EcsEntity> getItemsInPosition(int x, int y, int z) { // return getItemsInPosition(cachePosition.set(x, y, z)); // } // // public boolean itemAccessible(EcsEntity item, IntVector3 position) { // //TODO handle items in containers // if (isItemInContainer(item)) { // IntVector3 containerPosition = contained.get(item).entity.position; // LocalMap map = map(); // byte area = map.passageMap.area.get(position); // return PositionUtil.allNeighbour.stream() // .map(pos->IntVector3.add(pos, containerPosition)) // .filter(map::inMap) // .map(map.passageMap.area::get) // .anyMatch(area1->area1 == area); // } // return item.position != null && map().passageMap.area.get(position) == map().passageMap.area.get(item.position); // } // // private LocalMap map() { // return map == null ? map = GameMvc.model().get(LocalMap.class) : map; // } // // public boolean isItemOnMap(EcsEntity item) { // return onMapItemsSet.contains(item); // } // // public boolean isItemInContainer(EcsEntity item) { // return contained.containsKey(item); // } // // public boolean isItemEquipped(EcsEntity item) { // return equipped.containsKey(item); // } public void registerItem(EcsEntity item) { // TODO handle equipped and contained items if (item.hasPos()) { onMapItems.registerItem(item); } }
// validate that item is registered on its position private void validateForTaking(EcsEntity item) { if (!item.hasPos()) { Debug.LogWarning("Item " + item + " has no position."); } Vector3Int position = item.pos(); if (!itemsOnMap.ContainsKey(position)) { Debug.LogWarning("Tile on " + item + " position is empty."); } if (!itemsOnMap[position].Contains(item)) { Debug.LogWarning("Item " + item + " is not registered by its position."); } }