@Subscribe public void handleDailyUpdate(ClockTickDayChange event) { for (IGuild guild : guildList) { for (IAuction auction : guild.getAuctions()) { if (dateService.isToday(auction.getAuctionDate())) { handleAuction(auction, guild); guild.resetAuction(auction); } } } }
public LocalDateTime cleanUpAuctionAndDetermineAuctionDate(LocalDateTime auctionDate, IGuild guild) { if (!guild.getAuctions().isEmpty()) { for (IAuction nextAuction : guild.getAuctions()) { if (dateService.isPast(nextAuction.getAuctionDate())) { nextAuction.setAuctionDate(date.getCurrentDate().plusDays(1)); } while (dateService.isSameDay(nextAuction.getAuctionDate(), auctionDate) ) { auctionDate = auctionDate.plusDays(1); } } } return auctionDate; } }
@Subscribe public void handleBlockadeConvoyReturns(ShipEntersPortEvent event) { // disolve the convoy and remove blockade from blockade state INavigableVessel vessel = event.getShip(); if (vessel instanceof IConvoy) { LocalDateTime now = date.getCurrentDate(); ICity aldermanCity = mapService.getAldermanCity(); for (Entry<ICity, IBlockade> blockadeEntry : blockadeState.entrySet()) { IBlockade blockade = blockadeEntry.getValue(); if (blockade.getEndBlockade().isBefore(now)) { IConvoy convoy = blockade.getBlockadeConvoy(); if (convoy.equals(vessel) && event.getCity().equals(aldermanCity)) { final ICity blockadedCity = blockadeEntry.getKey(); dissolveConvoy(blockade, aldermanCity, blockadedCity); blockadeState.finishBlockade(blockadedCity); IGuild guild = guildList.findGuild(aldermanCity).get(); for (IShip ship : blockade.getShipsToAuction()) { LocalDateTime auctionDate = now.plusDays(10); auctionDate = guildService.cleanUpAuctionAndDetermineAuctionDate(auctionDate, guild); IShipAuction auction = modelFactory.createAnonymousShipAuction(auctionDate, ship.getValue(), ship); guild.getAuctions().add(auction); } return; } } } } }
private EventHandler<MouseEvent> createAuctionShipAction(final VBox container, IGuild guild, DecoratedText text, ItemNavigator<IShip> itemNavigator, Group centerPane, Pane action) { return event -> { try { // The elements are split up on two components, make sure they are gone from both. container.getChildren().removeAll(text, centerPane, action); getContent().removeAll(text, centerPane, action); LocalDateTime auctionDate = date.getCurrentDate().plusDays(10); auctionDate = guildService.cleanUpAuctionAndDetermineAuctionDate(auctionDate, guild); IShip ship = itemNavigator.getCurrent(); IShipAuction auction = modelFactory.createShipAuction(auctionDate, ship.getValue(), city.getPlayer(), ship); city.getPlayer().removeShip(ship); guild.getAuctions().add(auction); } catch (RuntimeException e) { logger.error("Failed to set ship for auctioning", e); } }; }
@VisibleForTesting void pawnFromHumanDebitor(final IDebt debt, final ICity city) { // pawn a ship and auction it int sum = (int) (debt.getAmount() * debt.getInterest()); final IPlayer debitor = (IPlayer) debt.getDebitor(); IShip shipMatch = null; int maxDelta = Integer.MAX_VALUE; for (IShip ship : debitor.getFleet()) { int shipValue = ship.getValue(); if (Math.abs(shipValue - sum) < maxDelta) { maxDelta = Math.abs(shipValue - sum); shipMatch = ship; } } if (shipMatch != null) { LocalDateTime auctionDate = date.getCurrentDate().plusDays(10); // Add auction to guild IGuild guild = guildList.findGuild(city).get(); auctionDate = guildService.cleanUpAuctionAndDetermineAuctionDate(auctionDate, guild); IShipAuction auction = modelFactory.createShipAuction(auctionDate, shipMatch.getValue(), debitor, shipMatch); guild.getAuctions().add(auction); final LocalDateTime dateCollectMoney = auctionDate.plusDays(1); TimedTask collectMoney = taskFactory.getLoanerCollectMoneyAfterAuctionTask(debt, dateCollectMoney); taskList.add(collectMoney); } else { final LocalDateTime dateCollectMoney = date.getCurrentDate(); TimedTask collectMoney = taskFactory.getLoanerCollectMoneyTask(debt, debitor, dateCollectMoney); taskList.add(collectMoney); } }
new Object[]{}, locale.getCurrentLocal())); IGuild guild = guildList.findGuild(city.getCity()).get(); List<IAuction> auctions = guild.getAuctions();