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 handleBid(AuctionBid bid) { Preconditions.checkArgument(!bid.getBidder().equals(bid.getAuction().getBiddingPlayer()), "The bidder has to change"); IAuction auction = bid.getAuction(); auction.getCurrentTask().cancel(); auction.setBidLevel(EBidLevel.INITIAL); auction.setBiddingPlayer(bid.getBidder()); auction.setCurrentBid(bid.getAmount()); clientServerEventBus.post(new AuctionBidLevel(auction.getBidLevel(), EBidLevel.INITIAL, bid.getBidder(), auction)); CancelableRunnable task = factory.createNextBidTask(auction); auction.setCurrentTask(task); timer.schedule(task, 30, TimeUnit.SECONDS); }
@Override public void run() { if (run) { // Chose if an AI player should place a bid or the level should change int nextBid = auction.getCurrentBid() + AuctionEngine.BID_DELTA; EBidLevel bidLevel = auction.getBidLevel(); List<IAIPlayer> biddingPlayers = new ArrayList<>(auction.getBiddingPlayers()); biddingPlayers.remove(auction.getBiddingPlayer()); boolean aiBid = rnd.nextInt(2) % 2 == 0 || bidLevel == EBidLevel.INITIAL; if (aiBid && !biddingPlayers.isEmpty()) { Collections.shuffle(biddingPlayers); IAIPlayer bidder = biddingPlayers.get(0); clientServerEventBus.post(new AuctionBid(bidder, nextBid, auction)); } else { EBidLevel nextLevel; switch (bidLevel) { case ONE: nextLevel = EBidLevel.TWO; break; case TWO: nextLevel = EBidLevel.DONE; break; default: throw new IllegalStateException("Levels "+EBidLevel.INITIAL+" and "+EBidLevel.DONE + " are not valid"); } clientServerEventBus.post(new AuctionBidLevel(bidLevel, nextLevel, auction.getBiddingPlayer(), auction)); } } }
public void startAuction(IAuction auction, List<IAIPlayer> players) { auction.setCurrentBid(auction.getStartingBid() - BID_DELTA); for (Iterator<IAIPlayer> iterator = players.iterator(); iterator.hasNext(); ) { IAIPlayer player = iterator.next(); ICompany company = player.getCompany(); if (company.getCash() < auction.getStartingBid() * 3) { iterator.remove(); auction.setBiddingPlayers(players); if (players.isEmpty()) { auction.setCurrentTask(task); timer.schedule(task, 2, TimeUnit.MINUTES); } else { CancelableRunnable task = factory.createNextBidTask(auction); auction.setCurrentTask(task); timer.schedule(task, 30, TimeUnit.SECONDS);
box.getChildren().add(text); } else { LocalDateTime date = auctions.get(0).getAuctionDate(); String template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.AuctionGuildDialog.nextAuction", new Object[]{modelTranslations.toDisplayString(date)}, locale.getCurrentLocal()); if (dateService.isToday(nextAuction.getAuctionDate())) { currentBidLevel = new SimpleObjectProperty<>(nextAuction.getBidLevel()); new Object[]{nextAuction.getCurrentBid() + AuctionEngine.BID_DELTA}, locale.getCurrentLocal()); auctionBtn = new OpenPatricianLargeWaxButton(s); auctionBtn.getStyleClass().add("actionButton"); auctionBtn.setDisable(true); EBidLevel current = currentBidLevel.get(); EBidLevel next = nextAuction.getBiddingPlayer() == null ? EBidLevel.INITIAL : calculateNextBidLevel(current); clientEventBus.post(new AuctionBidLevel(current, next, city.getPlayer(), nextAuction)); } catch (RuntimeException e) {
@Subscribe public void handleBidLevelChange(AuctionBidLevel change) { IAuction auction = change.getAuction(); auction.setBidLevel(change.getNewLevel()); auction.setBiddingPlayer(change.getBidder()); if (change.getNewLevel() == EBidLevel.DONE) { IPlayer newOwner = auction.getBiddingPlayer(); int amount = auction.getCurrentBid(); if (auction.getOwner().isPresent() && auction.getOwner().get() instanceof IPlayer) { if (auction.getOwner().get() instanceof IHumanPlayer) { ((IPlayer) auction.getOwner().get()).getCompany().updateCash(amount); } else { ((IPlayer) auction.getOwner().get()).getCompany().updateCashDirectly(amount);
private void addCurrentBidInformation(VBox box, IAuction nextAuction, int index) { if (nextAuction.getBiddingPlayer() == null) { // no bid String template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.AuctionGuildDialog.noBid", new Object[]{}, locale.getCurrentLocal()); DecoratedText dt = textFactory.createDecoratedText(template, new HashMap<>()); dt.setId("noBid"); box.getChildren().add(index, dt); } else { // current bid IPlayer bidder = nextAuction.getBiddingPlayer(); String template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.AuctionGuildDialog.currentBid", new Object[]{nextAuction.getCurrentBid(), bidder.getName(), bidder.getLastName()}, locale.getCurrentLocal()); DecoratedText dt = textFactory.createDecoratedText(template, new HashMap<>()); dt.setId("currentBid"); box.getChildren().add(index, dt); } box.getChildren().add(dialogHelper.createVerticalSpacer(20)); }
@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); } } } }
@Override public void run() { if (run) { if (auction instanceof IShipAuction) { if (auction.getOwner().isPresent()) { IShipAuction shipAuction = (IShipAuction) auction; clientServerEventBus.post(new ShipNotAuctioned(shipAuction.getAuctionedShip(), shipAuction.getOwner().get())); } } else { IBuildingAuction buildingAuction = (IBuildingAuction) auction; clientServerEventBus.post(new BuildingNotAuctioned(buildingAuction.getAuctionedBuilding(), buildingAuction.getOwner().get())); } } } };
private String getBidLevelTemplate(IAuction auction) { switch (currentBidLevel.get()) { case INITIAL: return messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.AuctionGuildDialog.noBid", new Object[]{}, locale.getCurrentLocal()); case ONE: return messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.AuctionGuildDialog.first", new Object[]{}, locale.getCurrentLocal()); case TWO: return messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.AuctionGuildDialog.second", new Object[]{}, locale.getCurrentLocal()); case DONE: IPlayer newOwner = auction.getBiddingPlayer(); return messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.AuctionGuildDialog.sold", new Object[]{newOwner.getName(), newOwner.getLastName()}, locale.getCurrentLocal()); default: throw new IllegalStateException("Unhandled state: "+currentBidLevel.get()); } }
@Subscribe public void handleBidLevelChange(AuctionBidLevel change) { currentBidLevel.setValue(change.getNewLevel()); if (!change.getBidder().equals(city.getPlayer())) { auctionBtn.setDisable(false); } // update bid labels int index = dialogHelper.removeById(box, "noBid"); if (index < 0) { index = dialogHelper.removeById(box, "currentBid"); } addCurrentBidInformation(box, change.getAuction(), index); index = dialogHelper.removeById(box, "bidLevel-"+change.getOldLevel()); box.getChildren().remove(index); addBidLevelCountDown(box, change.getAuction(), index); if (change.getNewLevel() == EBidLevel.DONE) { auctionBtn.setVisible(false); clientEventBus.unregister(this); } else { String label = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.AuctionGuildDialog.nextBid", new Object[]{change.getAuction().getCurrentBid() + AuctionEngine.BID_DELTA}, locale.getCurrentLocal()); auctionBtn.setText(label); } }
private void addAuctionDescription(VBox box, IAuction nextAuction) { if (nextAuction instanceof IBuildingAuction) { IBuilding building = ((IBuildingAuction) nextAuction).getAuctionedBuilding(); IPlayer owner = nextAuction.getOwner().get(); String name = owner.getName()+" "+owner.getLastName(); String template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.AuctionGuildDialog.buildingAuction", new Object[]{modelTranslations.getLocalDisplayName(building), name}, locale.getCurrentLocal()); DecoratedText dt = textFactory.createDecoratedText(template, new HashMap<>()); dt.setId("buildingAuction"); box.getChildren().add(dt); } else { IShip ship = ((IShipAuction)nextAuction).getAuctionedShip(); String name = ship.getOwner().getName()+" "+ship.getOwner().getLastName(); String template = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.guild.AuctionGuildDialog.shipAuction", new Object[]{ship.getName(), name}, locale.getCurrentLocal()); DecoratedText dt = textFactory.createDecoratedText(template, new HashMap<>()); dt.setId("shipAuction"); box.getChildren().add(dt); } box.getChildren().add(dialogHelper.createVerticalSpacer(20)); }