package space.m0e.quga.oop.lab56maven.decisions; import javafx.application.Platform; import space.m0e.quga.oop.lab56maven.entities.common.Coordinates; import space.m0e.quga.oop.lab56maven.entities.macro.Workstation; import space.m0e.quga.oop.lab56maven.entities.micro.Dwarf; import space.m0e.quga.oop.lab56maven.handlers.DwarfHandler; public class GoToWorkstationDecision extends Decision { private Dwarf dwarf; public GoToWorkstationDecision(int executeWhen, Dwarf dwarf) { super(executeWhen); this.dwarf = dwarf; } @Override public void cycle() { Workstation near = dwarf.findNearestWorkstation(); if (near != null) { Platform.runLater(dwarf::updateItemLabel); dwarf.getFortress().removeFromContainer(dwarf); Coordinates nearCoordinates = dwarf.getCoordinatesToWorkstation(near); dwarf.move(nearCoordinates); if (nearCoordinates.isThere(dwarf)) { dwarf.setWorkstation(near); DwarfHandler dwarfHandler = (DwarfHandler) dwarf.getHandler(); dwarfHandler.setDecision(new WorkAtWorkstationDecision(dwarfHandler.getTimer() + 1, dwarf)); near.getCountLabel().setText(String.valueOf(near.getDwarves().size())); setComplete(true); } } } }