@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)); } } }
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)); }
int amount = auction.getCurrentBid(); if (auction.getOwner().isPresent() && auction.getOwner().get() instanceof IPlayer) { if (auction.getOwner().get() instanceof IHumanPlayer) {
new Object[]{nextAuction.getCurrentBid() + AuctionEngine.BID_DELTA}, locale.getCurrentLocal()); auctionBtn = new OpenPatricianLargeWaxButton(s); auctionBtn.getStyleClass().add("actionButton");
@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); } }